123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- #ifndef __MOD_SAMPLEENTITY_H__
- #define __MOD_SAMPLEENTITY_H__
- #pragma once
- // This code is generated by spgenex tool!
- #include "SampleEntity_server_g.h"
- #include "SampleFSM.h"
- #include "SpTest.h"
- using namespace SampleEntity;
- class CSampleEntity : public CEntityBase
- {
- public:
- CSampleEntity(){}
- virtual ~CSampleEntity(){}
- virtual const char *GetEntityName() const { return "SampleEntity"; }
- virtual bool IsService() const { return true; }
- virtual bool IsMultiThread() const { return true; }
- virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- ErrorCodeEnum ec = Error_Succeed;
- if(m_sampleFsm.Init(this) != 0) {
- ec = Error_InvalidState;
- }
- pTransactionContext->SendAnswer(ec);
- }
- virtual void OnStarted() override
- {
- CSimpleStringA strValue;
- CHECK(Error_NotExist == GetFunction()->GetSysVar("NoExistSysValue", strValue));
- IFFAILBREAK(GetFunction()->GetSysVar("SampleState", strValue));
- CHECK_FALSE(strValue.IsNullOrEmpty());
- /*set sys val*/
- Dbg("Update sysVal...");
- strValue = strValue.Compare("1") == 0 ? "0" : "1";
- IFFAILBREAK(GetFunction()->SetSysVar("SampleState", strValue, true));
- CSimpleStringA strNewValue;
- IFFAILBREAK(GetFunction()->GetSysVar("SampleState", strNewValue));
- CHECK(strValue.Compare(strNewValue) == 0);
- Dbg("Update sysVal again...");
- strValue = strValue.Compare("1") == 0 ? "0" : "1";
- IFFAILBREAK(GetFunction()->SetSysVar("SampleState", strValue));
- IFFAILBREAK(GetFunction()->GetSysVar("SampleState", strNewValue));
- CHECK(strValue.Compare(strNewValue) == 0);
- //depecrate: assert would happen!
- //IFFAILBREAK(GetFunction()->SetSysVar("SampleState", NULL)); //would clear the sys val value.
- Dbg("test some illegal action.");
- CHECK(Error_NotExist == GetFunction()->SetSysVar("NoExistSysValue", "1", true));
- CHECK(Error_NotExist == GetFunction()->SetSysVar("NoExistSysValue", "1"));
- CHECK(Error_Null == GetFunction()->SetSysVar(NULL, "1", true));
- CHECK(Error_Null == GetFunction()->SetSysVar(NULL, "1"));
- CHECK(Error_NoPrivilege == GetFunction()->SetSysVar("PrivilegeState", "1", true));
- CHECK(Error_NoPrivilege == GetFunction()->SetSysVar("PrivilegeState", "1"));
- }
- ErrorCodeEnum OnewayFuncOverlap(
- SpOnewayCallContext<SampleService_OnewayFuncOverlap_Info>::Pointer ctx)
- {
- ErrorCodeEnum ec = Error_Unexpect;
- // TODO: user should implement the function!
- return ec;
- }
- ErrorCodeEnum OnewayFuncNoOverlap(
- SpOnewayCallContext<SampleService_OnewayFuncNoOverlap_Info>::Pointer ctx)
- {
- ErrorCodeEnum ec = Error_Unexpect;
- // TODO: user should implement the function!
- return ec;
- }
- ErrorCodeEnum OnewayFuncNormal(
- SpOnewayCallContext<SampleService_OnewayFuncNormal_Info>::Pointer ctx)
- {
- ErrorCodeEnum ec = Error_Unexpect;
- // TODO: user should implement the function!
- return ec;
- }
- ErrorCodeEnum TwoWayFuncOverlap(
- SpReqAnsContext<SampleService_TwoWayFuncOverlap_Req, SampleService_TwoWayFuncOverlap_Ans>::Pointer ctx)
- {
- ErrorCodeEnum ec = Error_Succeed;
- // TODO:
- return ec;
- }
- ErrorCodeEnum TwoWayFuncNotOverlap(
- SpReqAnsContext<SampleService_TwoWayFuncNotOverlap_Req, SampleService_TwoWayFuncNotOverlap_Ans>::Pointer ctx)
- {
- ErrorCodeEnum ec = Error_Succeed;
- // TODO:
- return ec;
- }
- ErrorCodeEnum TwoWayFuncWithID(
- SpReqAnsContext<SampleService_TwoWayFuncWithID_Req, SampleService_TwoWayFuncWithID_Ans>::Pointer ctx)
- {
- ErrorCodeEnum ec = Error_Succeed;
- // TODO:
- return ec;
- }
- ErrorCodeEnum TwoWayFuncNormal(
- SpReqAnsContext<SampleService_TwoWayFuncNormal_Req, SampleService_TwoWayFuncNormal_Ans>::Pointer ctx)
- {
- ErrorCodeEnum ec = Error_Succeed;
- // TODO:
- return ec;
- }
- ErrorCodeEnum SubscribeOverlap(
- SpSubscribeContext<SampleService_SubscribeOverlap_Sub, SampleService_SubscribeOverlap_Message_Info>::Pointer ctx)
- {
- ErrorCodeEnum ec = Error_NotImpl;
- // TODO:
- return ec;
- }
- ErrorCodeEnum SubscribeOverlap_Cancel(
- SpOnewayCallContext<SampleService_SubscribeOverlap_Cancel_Info>::Pointer ctx)
- {
- ErrorCodeEnum ec = Error_NotImpl;
- // TODO:
- return ec;
- }
- ///////////////////////////
- private:
- CSampleFSM m_sampleFsm;
- };
- class CSampleServiceSession : public SampleService_ServerSessionBase
- {
- public:
- CSampleServiceSession(CSampleEntity *pEntity) : m_pEntity(pEntity) {}
- virtual ~CSampleServiceSession() {}
- virtual void Handle_OnewayFuncOverlap(
- SpOnewayCallContext<SampleService_OnewayFuncOverlap_Info>::Pointer ctx)
- {
- auto rc = m_pEntity->OnewayFuncOverlap(ctx);
- }
- virtual void Handle_OnewayFuncNoOverlap(
- SpOnewayCallContext<SampleService_OnewayFuncNoOverlap_Info>::Pointer ctx)
- {
- auto rc = m_pEntity->OnewayFuncNoOverlap(ctx);
- }
- virtual void Handle_OnewayFuncNormal(
- SpOnewayCallContext<SampleService_OnewayFuncNormal_Info>::Pointer ctx)
- {
- auto rc = m_pEntity->OnewayFuncNormal(ctx);
- }
- virtual void Handle_TwoWayFuncOverlap(
- SpReqAnsContext<SampleService_TwoWayFuncOverlap_Req, SampleService_TwoWayFuncOverlap_Ans>::Pointer ctx)
- {
- auto rc = m_pEntity->TwoWayFuncOverlap(ctx);
- ctx->Answer(rc);
- }
- virtual void Handle_TwoWayFuncNotOverlap(
- SpReqAnsContext<SampleService_TwoWayFuncNotOverlap_Req, SampleService_TwoWayFuncNotOverlap_Ans>::Pointer ctx)
- {
- auto rc = m_pEntity->TwoWayFuncNotOverlap(ctx);
- ctx->Answer(rc);
- }
- virtual void Handle_TwoWayFuncWithID(
- SpReqAnsContext<SampleService_TwoWayFuncWithID_Req, SampleService_TwoWayFuncWithID_Ans>::Pointer ctx)
- {
- auto rc = m_pEntity->TwoWayFuncWithID(ctx);
- ctx->Answer(rc);
- }
- virtual void Handle_TwoWayFuncNormal(
- SpReqAnsContext<SampleService_TwoWayFuncNormal_Req, SampleService_TwoWayFuncNormal_Ans>::Pointer ctx)
- {
- auto rc = m_pEntity->TwoWayFuncNormal(ctx);
- ctx->Answer(rc);
- }
- virtual void Handle_SubscribeOverlap(
- SpSubscribeContext<SampleService_SubscribeOverlap_Sub, SampleService_SubscribeOverlap_Message_Info>::Pointer ctx)
- {
- auto rc = m_pEntity->SubscribeOverlap(ctx);
- }
- virtual void Handle_SubscribeOverlap_Cancel(
- SpOnewayCallContext<SampleService_SubscribeOverlap_Cancel_Info>::Pointer ctx)
- {
- auto rc = m_pEntity->SubscribeOverlap_Cancel(ctx);
- }
- private:
- CSampleEntity *m_pEntity;
- };
- ///////////////////////////
- #endif // __MOD_SAMPLEENTITY_H__
|