mod_SampleEntity.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. #ifndef __MOD_SAMPLEENTITY_H__
  2. #define __MOD_SAMPLEENTITY_H__
  3. #pragma once
  4. // This code is generated by spgenex tool!
  5. #include "SampleEntity_server_g.h"
  6. #include "SampleFSM.h"
  7. #include "SpTest.h"
  8. using namespace SampleEntity;
  9. class CSampleEntity : public CEntityBase
  10. {
  11. public:
  12. CSampleEntity(){}
  13. virtual ~CSampleEntity(){}
  14. virtual const char *GetEntityName() const { return "SampleEntity"; }
  15. virtual bool IsService() const { return true; }
  16. virtual bool IsMultiThread() const { return true; }
  17. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  18. {
  19. ErrorCodeEnum ec = Error_Succeed;
  20. if(m_sampleFsm.Init(this) != 0) {
  21. ec = Error_InvalidState;
  22. }
  23. pTransactionContext->SendAnswer(ec);
  24. }
  25. virtual void OnStarted() override
  26. {
  27. CSimpleStringA strValue;
  28. CHECK(Error_NotExist == GetFunction()->GetSysVar("NoExistSysValue", strValue));
  29. IFFAILBREAK(GetFunction()->GetSysVar("SampleState", strValue));
  30. CHECK_FALSE(strValue.IsNullOrEmpty());
  31. /*set sys val*/
  32. Dbg("Update sysVal...");
  33. strValue = strValue.Compare("1") == 0 ? "0" : "1";
  34. IFFAILBREAK(GetFunction()->SetSysVar("SampleState", strValue, true));
  35. CSimpleStringA strNewValue;
  36. IFFAILBREAK(GetFunction()->GetSysVar("SampleState", strNewValue));
  37. CHECK(strValue.Compare(strNewValue) == 0);
  38. Dbg("Update sysVal again...");
  39. strValue = strValue.Compare("1") == 0 ? "0" : "1";
  40. IFFAILBREAK(GetFunction()->SetSysVar("SampleState", strValue));
  41. IFFAILBREAK(GetFunction()->GetSysVar("SampleState", strNewValue));
  42. CHECK(strValue.Compare(strNewValue) == 0);
  43. //depecrate: assert would happen!
  44. //IFFAILBREAK(GetFunction()->SetSysVar("SampleState", NULL)); //would clear the sys val value.
  45. Dbg("test some illegal action.");
  46. CHECK(Error_NotExist == GetFunction()->SetSysVar("NoExistSysValue", "1", true));
  47. CHECK(Error_NotExist == GetFunction()->SetSysVar("NoExistSysValue", "1"));
  48. CHECK(Error_Null == GetFunction()->SetSysVar(NULL, "1", true));
  49. CHECK(Error_Null == GetFunction()->SetSysVar(NULL, "1"));
  50. CHECK(Error_NoPrivilege == GetFunction()->SetSysVar("PrivilegeState", "1", true));
  51. CHECK(Error_NoPrivilege == GetFunction()->SetSysVar("PrivilegeState", "1"));
  52. }
  53. ErrorCodeEnum OnewayFuncOverlap(
  54. SpOnewayCallContext<SampleService_OnewayFuncOverlap_Info>::Pointer ctx)
  55. {
  56. ErrorCodeEnum ec = Error_Unexpect;
  57. // TODO: user should implement the function!
  58. return ec;
  59. }
  60. ErrorCodeEnum OnewayFuncNoOverlap(
  61. SpOnewayCallContext<SampleService_OnewayFuncNoOverlap_Info>::Pointer ctx)
  62. {
  63. ErrorCodeEnum ec = Error_Unexpect;
  64. // TODO: user should implement the function!
  65. return ec;
  66. }
  67. ErrorCodeEnum OnewayFuncNormal(
  68. SpOnewayCallContext<SampleService_OnewayFuncNormal_Info>::Pointer ctx)
  69. {
  70. ErrorCodeEnum ec = Error_Unexpect;
  71. // TODO: user should implement the function!
  72. return ec;
  73. }
  74. ErrorCodeEnum TwoWayFuncOverlap(
  75. SpReqAnsContext<SampleService_TwoWayFuncOverlap_Req, SampleService_TwoWayFuncOverlap_Ans>::Pointer ctx)
  76. {
  77. ErrorCodeEnum ec = Error_Succeed;
  78. // TODO:
  79. return ec;
  80. }
  81. ErrorCodeEnum TwoWayFuncNotOverlap(
  82. SpReqAnsContext<SampleService_TwoWayFuncNotOverlap_Req, SampleService_TwoWayFuncNotOverlap_Ans>::Pointer ctx)
  83. {
  84. ErrorCodeEnum ec = Error_Succeed;
  85. // TODO:
  86. return ec;
  87. }
  88. ErrorCodeEnum TwoWayFuncWithID(
  89. SpReqAnsContext<SampleService_TwoWayFuncWithID_Req, SampleService_TwoWayFuncWithID_Ans>::Pointer ctx)
  90. {
  91. ErrorCodeEnum ec = Error_Succeed;
  92. // TODO:
  93. return ec;
  94. }
  95. ErrorCodeEnum TwoWayFuncNormal(
  96. SpReqAnsContext<SampleService_TwoWayFuncNormal_Req, SampleService_TwoWayFuncNormal_Ans>::Pointer ctx)
  97. {
  98. ErrorCodeEnum ec = Error_Succeed;
  99. // TODO:
  100. return ec;
  101. }
  102. ErrorCodeEnum SubscribeOverlap(
  103. SpSubscribeContext<SampleService_SubscribeOverlap_Sub, SampleService_SubscribeOverlap_Message_Info>::Pointer ctx)
  104. {
  105. ErrorCodeEnum ec = Error_NotImpl;
  106. // TODO:
  107. return ec;
  108. }
  109. ErrorCodeEnum SubscribeOverlap_Cancel(
  110. SpOnewayCallContext<SampleService_SubscribeOverlap_Cancel_Info>::Pointer ctx)
  111. {
  112. ErrorCodeEnum ec = Error_NotImpl;
  113. // TODO:
  114. return ec;
  115. }
  116. ///////////////////////////
  117. private:
  118. CSampleFSM m_sampleFsm;
  119. };
  120. class CSampleServiceSession : public SampleService_ServerSessionBase
  121. {
  122. public:
  123. CSampleServiceSession(CSampleEntity *pEntity) : m_pEntity(pEntity) {}
  124. virtual ~CSampleServiceSession() {}
  125. virtual void Handle_OnewayFuncOverlap(
  126. SpOnewayCallContext<SampleService_OnewayFuncOverlap_Info>::Pointer ctx)
  127. {
  128. auto rc = m_pEntity->OnewayFuncOverlap(ctx);
  129. }
  130. virtual void Handle_OnewayFuncNoOverlap(
  131. SpOnewayCallContext<SampleService_OnewayFuncNoOverlap_Info>::Pointer ctx)
  132. {
  133. auto rc = m_pEntity->OnewayFuncNoOverlap(ctx);
  134. }
  135. virtual void Handle_OnewayFuncNormal(
  136. SpOnewayCallContext<SampleService_OnewayFuncNormal_Info>::Pointer ctx)
  137. {
  138. auto rc = m_pEntity->OnewayFuncNormal(ctx);
  139. }
  140. virtual void Handle_TwoWayFuncOverlap(
  141. SpReqAnsContext<SampleService_TwoWayFuncOverlap_Req, SampleService_TwoWayFuncOverlap_Ans>::Pointer ctx)
  142. {
  143. auto rc = m_pEntity->TwoWayFuncOverlap(ctx);
  144. ctx->Answer(rc);
  145. }
  146. virtual void Handle_TwoWayFuncNotOverlap(
  147. SpReqAnsContext<SampleService_TwoWayFuncNotOverlap_Req, SampleService_TwoWayFuncNotOverlap_Ans>::Pointer ctx)
  148. {
  149. auto rc = m_pEntity->TwoWayFuncNotOverlap(ctx);
  150. ctx->Answer(rc);
  151. }
  152. virtual void Handle_TwoWayFuncWithID(
  153. SpReqAnsContext<SampleService_TwoWayFuncWithID_Req, SampleService_TwoWayFuncWithID_Ans>::Pointer ctx)
  154. {
  155. auto rc = m_pEntity->TwoWayFuncWithID(ctx);
  156. ctx->Answer(rc);
  157. }
  158. virtual void Handle_TwoWayFuncNormal(
  159. SpReqAnsContext<SampleService_TwoWayFuncNormal_Req, SampleService_TwoWayFuncNormal_Ans>::Pointer ctx)
  160. {
  161. auto rc = m_pEntity->TwoWayFuncNormal(ctx);
  162. ctx->Answer(rc);
  163. }
  164. virtual void Handle_SubscribeOverlap(
  165. SpSubscribeContext<SampleService_SubscribeOverlap_Sub, SampleService_SubscribeOverlap_Message_Info>::Pointer ctx)
  166. {
  167. auto rc = m_pEntity->SubscribeOverlap(ctx);
  168. }
  169. virtual void Handle_SubscribeOverlap_Cancel(
  170. SpOnewayCallContext<SampleService_SubscribeOverlap_Cancel_Info>::Pointer ctx)
  171. {
  172. auto rc = m_pEntity->SubscribeOverlap_Cancel(ctx);
  173. }
  174. private:
  175. CSampleEntity *m_pEntity;
  176. };
  177. ///////////////////////////
  178. #endif // __MOD_SAMPLEENTITY_H__