#pragma once
#include <egAPI.h>			// RT-edge system API

/*****************************************************************************
*
* FILE NAME:		edgeCommon.h
*
* DESCRIPTION:		僒乕價僗嫟捠掕媊丒娭悢丂僿僢僟僼傽僀儖
*
* 嘇[TODO]:			昁梫偵墳偠偰奺庬掕媊/娭悢偺捛壛丒嶍彍丒曄峏傪峴偭偰偔偩偝偄   
*                   SERVICENAME 偼昁偢曄峏偟偰偔偩偝偄
*
\*****************************************************************************/
//////////////////////////////////////////////////////////////////////////////
/// 奺庬掕媊捛壛
///

/// <summary>
/// 僒乕價僗柤
/// </summary>
#define	SERVICENAME			"ClctSmpl"						// [TODO] : rta奼挘巕傪彍偔僾儘僌儔儉僼傽僀儖柤偵曄峏

/// <summary>
/// 僒乕價僗僀儞僕働乕僞柤
/// </summary>
extern char	IND_MYSERV_STATUS	[EG_MAX_TAGNAME + 1];		// 僒乕價僗婲摦
#define		SERVICE_UP		1								// 婲摦拞
#define		SERVICE_DOWN	0								// 掆巭拞
extern char	IND_MYSERV_ERROR	[EG_MAX_TAGNAME + 1];		// 僒乕價僗僄儔乕敪惗拞
extern char	IND_MYSERV_RUN		[EG_MAX_TAGNAME + 1];		// 僒乕價僗幚峴拞
extern char	ND_MYSERV_LIVE		[EG_MAX_TAGNAME + 1];		// 僒乕價僗幚峴僇僂儞僞

/// <summary>
/// 僒乕價僗僾儘僷僥傿僞僌柤
/// </summary>
extern char PROP_MYSERV_MODE	[EG_MAX_TAGNAME + 1];		// 僒乕價僗摦嶌儌乕僪
#define		MODE_AUTO		1								// 擖弌帺摦僒僀僋儖
#define		MODE_SEMIAUTO	2								// 擖椡僒僀僋儖亄弌椡僨儅儞僪
#define		MODE_MANUAL		3								// 擖弌椡僨儅儞僪
#define		DEFAULT_MODE		MODE_SEMIAUTO
extern char PROP_MYSERV_CYCLE	[EG_MAX_TAGNAME + 1];		// 僒乕價僗摦嶌僒僀僋儖(ms)
#define		DEFAULT_CYCLE		1
extern char PROP_MYSERV_INPRIO	[EG_MAX_TAGNAME + 1];		// Edge僔僗僥儉傊偺擖椡僒乕價僗僗儗僢僪僾儔僀僆儕僥傿
#define		DEFAULT_INPRIO		148
extern char PROP_MYSERV_OUTPRIO	[EG_MAX_TAGNAME + 1];		// Edge僔僗僥儉偐傜偺弌椡僒乕價僗僗儗僢僪僾儔僀僆儕僥傿	
#define		DEFAULT_OUTPRIO		149

/// <summary>
/// 僒乕價僗採嫙僞僌柤
/// </summary>
//[TODO] : 擟堄偺僞僌捛壛 (XML偱掕媊偡傞偙偲傪悇彠)
//#define TAG_MYSERV_XXX 捛壛偑昁梫偺応崌偙偙偵婰嵹

/// <summary>
/// 僒乕價僗屌桳儊僢僙乕僕
/// </summary>
//[TODO] : 擟堄偺儊僢僙乕僕ID捛壛 
//       儐乕僓儊僢僙乕僕(20000乣29999)
//#define	EM_SERVICE_XXX			20000				// 擟堄偺抣愝掕
//
/// <summary>
/// 僒乕價僗撪晹忬懺
/// </summary>
typedef struct MYSTATE
{
	bool		State;			// 僀儞僕働乕僞.僄僢僕僔僗僥儉愙懕忬懺
	bool		Run;			// 僀儞僕働乕僞.僒乕價僗幚峴忬懺
	bool		Error;			// 僀儞僕働乕僞.僒乕價僗堎忢忬懺
	uint32_t	Live;			// 僀儞僕働乕僞.僒乕價僗幚峴僇僂儞僞
	uint64_t	StartTime;		// 僀儞僕働乕僞.僒乕價僗奐巒帪偺僞僀儉僗僞儞僾
	uint8_t		Mode;			// 僾儘僷僥傿.僒乕價僗幚峴儌乕僪
	uint32_t	Cycle;			// 僾儘僷僥傿.僒乕價僗幚峴僒僀僋儖(ms)	[TODO] : 昁梫偵墳偠偰幚憰
	uint8_t		InPriority;		// 僾儘僷僥傿.僒乕價僗(擖椡)僾儔僀僆儕僥傿	[TODO] : 昁梫偵墳偠偰幚憰
	uint8_t		OutPriority;	// 僾儘僷僥傿.僒乕價僗(弌椡)僾儔僀僆儕僥傿	[TODO] : 昁梫偵墳偠偰幚憰
	RTHANDLE	hInTrigSem;		// 擖椡僒乕價僗僩儕僈僙儅僼僅僴儞僪儖	[TODO] : 昁梫偵墳偠偰幚憰
	RTHANDLE	hOutTrigSem;	// 弌椡僒乕價僗僩儕僈僙儅僼僅僴儞僪儖	[TODO] : 昁梫偵墳偠偰幚憰
	//[TODO] : 擟堄偺僗僥乕僞僗捛壛
	RTCDHANDLE	hMbox1;			// 撈帺彂崬傒梡儊乕儖儃僢僋僗
} EgState;

EgState MyState;
/// <summary>
/// 僒乕價僗撪晹娭悢 //[TODO] : 昁梫偵墳偠偰幚憰
/// </summary>
extern void ThreadAutoCycle(struct MYSTATE *state); 	//[TODO]: 昁梫偵墳偠偰幚憰
extern void ThreadInService(struct MYSTATE *state); 	//[TODO]: 昁梫偵墳偠偰幚憰
extern void ThreadOutService(struct MYSTATE *state); 	//[TODO]: 昁梫偵墳偠偰幚憰
extern void KickInput(struct MYSTATE *state); 			//[TODO]: 昁梫偵墳偠偰幚憰
extern void KickOutput(struct MYSTATE *state); 			//[TODO]: 昁梫偵墳偠偰幚憰
extern int32_t CreateServiceTags(struct MYSTATE *state);//[TODO]: 昁梫偵墳偠偰幚憰
extern int32_t UpdateIndicator(struct MYSTATE *state); 	//[TODO]: 昁梫偵墳偠偰幚憰
extern int32_t GetProperty(struct MYSTATE *state); 		//[TODO]: 昁梫偵墳偠偰幚憰
extern int32_t StartService(struct MYSTATE *state); 	//[TODO]: 昁梫偵墳偠偰幚憰
extern int32_t PauseService(struct MYSTATE *state); 	//[TODO]: 昁梫偵墳偠偰幚憰
extern int32_t InitService(struct MYSTATE *state); 		//[TODO]: 昁梫偵墳偠偰幚憰
extern int32_t KillService(struct MYSTATE *state); 		//[TODO]: 昁梫偵墳偠偰幚憰
extern void WarningMsg(int32_t position, int32_t reason);
#define WARN(reason)	WarningMsg(__LINE__,(reason))

///
/// 奺庬掕媊廔椆
//////////////////////////////////////////////////////////////////////////////