#pragma once

#include "robbase.h"

//同步对象

#define MAX_GATE_COUNT    127

class ROBBASE_API CGate
{
public:
	CGate(void);
	~CGate(void);
	
	int SetCount(int count);
	int   GetCount();

	void Reset(BOOL bForceUnlock);
	void SetAll(BOOL bForceUnlock);

	BOOL IsOn(int index);
	BOOL IsOff(int index);

	BOOL SetOff(int index);
    BOOL SetOn(int index);

	//设置锁住的gate,被锁的gate在不解除锁的情况下
	//如果同一个action，可以设置gate状态, on 或 off
	BOOL SetOff(int index, DWORD actId);
    BOOL SetOn(int index, DWORD actId);
	 
	BOOL IsAllOff();
	BOOL IsAllOn();

	//如果当前状态为高，尝试锁住
	BOOL Lock( int index, DWORD actId);
	void Unlock( int index, DWORD actId, BOOL bAutoSetOff);
	BOOL IsLocked(int index);
	DWORD GetActionId(int index);
	 
public:
	 TCHAR  m_strName[ROB_MAX_SYNCOBJ_NAME_LEN];

private:
	
	int     m_nCount;
 
	struct __gate_item{
	   DWORD actId;
	   int  state;
	   BOOL bLocked;
	}m_arrState[MAX_GATE_COUNT];
	 
	CRITICAL_SECTION m_cs;
};

