#pragma once

#include "robbase.h"
#include "Robot.h"

#define ROB_MAX_TOKEN_SLAVE_COUNT  127

class ROBBASE_API CToken
{
public:
	CToken(void);
	~CToken(void);
	 
	//主线程
	void Reset();
	int  Deliver(DWORD actId, int count );          //发放令牌
	int  Wait( BOOL bWaitAfterFinish, int timeout);  //所有令牌返到手，返回0, 否则返回错误值
		
	//从线程
	int  Get(DWORD actId, int timeout);   //子动作获取令牌
	void Back(DWORD actId );  //子动作返回令牌

	int GetUsedCount(){
	    return m_nUsedCount;
	}

public:	 
	CRobot* m_pRobot;
	 TCHAR  m_strName[ROB_MAX_SYNCOBJ_NAME_LEN];

private:
	DWORD m_masterId;
	 
	int m_nIssueCount;
	int m_nUsedCount;  //已经使用的数量
	DWORD m_slaveId[ROB_MAX_TOKEN_SLAVE_COUNT];
	CRITICAL_SECTION m_cs;
};

