AssistantChannel_server_g.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. #ifndef __ASSISTANTCHANNEL_SERVER_G_H
  2. #define __ASSISTANTCHANNEL_SERVER_G_H
  3. #pragma once
  4. // This code is generated by spgen tool!
  5. #include "AssistantChannel_def_g.h"
  6. namespace AssistantChannel {
  7. class ChannelService_ServerSessionBase : public CServerSessionBase
  8. {
  9. public:
  10. ChannelService_ServerSessionBase()
  11. {
  12. /// override by user
  13. }
  14. virtual ~ChannelService_ServerSessionBase()
  15. {
  16. /// override by user
  17. }
  18. virtual bool IsExclusive() { return false; }
  19. virtual bool IsSessionOverlap() { return true; }
  20. virtual ErrorCodeEnum GetMessageAttr(DWORD dwMessageID, DWORD dwSignature, bool &bOverlap)
  21. {
  22. ErrorCodeEnum Error = Error_Succeed;
  23. switch (dwMessageID) {
  24. case ChannelService_Method_Connect:
  25. if (dwSignature == ChannelService_MethodSignature_Connect) {
  26. bOverlap = true;
  27. } else {
  28. Error = Error_MethodSignatureFailed;
  29. }
  30. break;
  31. case ChannelService_Method_Close:
  32. if (dwSignature == ChannelService_MethodSignature_Close) {
  33. bOverlap = true;
  34. } else {
  35. Error = Error_MethodSignatureFailed;
  36. }
  37. break;
  38. case ChannelService_Method_GetState:
  39. if (dwSignature == ChannelService_MethodSignature_GetState) {
  40. bOverlap = true;
  41. } else {
  42. Error = Error_MethodSignatureFailed;
  43. }
  44. break;
  45. case ChannelService_Method_BeginState:
  46. if (dwSignature == ChannelService_MethodSignature_BeginState) {
  47. bOverlap = false;
  48. } else {
  49. Error = Error_MethodSignatureFailed;
  50. }
  51. break;
  52. case ChannelService_Method_EndState:
  53. if (dwSignature == ChannelService_MethodSignature_EndState) {
  54. bOverlap = true;
  55. } else {
  56. Error = Error_MethodSignatureFailed;
  57. }
  58. break;
  59. case ChannelService_Method_Send:
  60. if (dwSignature == ChannelService_MethodSignature_Send) {
  61. bOverlap = true;
  62. } else {
  63. Error = Error_MethodSignatureFailed;
  64. }
  65. break;
  66. case ChannelService_Method_BeginRecv:
  67. if (dwSignature == ChannelService_MethodSignature_BeginRecv) {
  68. bOverlap = false;
  69. } else {
  70. Error = Error_MethodSignatureFailed;
  71. }
  72. break;
  73. case ChannelService_Method_EndRecv:
  74. if (dwSignature == ChannelService_MethodSignature_EndRecv) {
  75. bOverlap = true;
  76. } else {
  77. Error = Error_MethodSignatureFailed;
  78. }
  79. break;
  80. case ChannelService_Method_GetIpByDomain:
  81. if (dwSignature == ChannelService_MethodSignature_GetIpByDomain) {
  82. bOverlap = true;
  83. } else {
  84. Error = Error_MethodSignatureFailed;
  85. }
  86. break;
  87. default:
  88. Error = Error_MethodNotFound;
  89. break;
  90. }
  91. return Error;
  92. }
  93. int CheckMessageSignature(DWORD dwMessageID, DWORD dwSignature)
  94. {
  95. ErrorCodeEnum Error = Error_Succeed;
  96. switch (dwMessageID) {
  97. case ChannelService_Method_Connect:
  98. if (dwSignature != ChannelService_MethodSignature_Connect) {
  99. Error = Error_MethodSignatureFailed;
  100. }
  101. break;
  102. case ChannelService_Method_Close:
  103. if (dwSignature != ChannelService_MethodSignature_Close) {
  104. Error = Error_MethodSignatureFailed;
  105. }
  106. break;
  107. case ChannelService_Method_GetState:
  108. if (dwSignature != ChannelService_MethodSignature_GetState) {
  109. Error = Error_MethodSignatureFailed;
  110. }
  111. break;
  112. case ChannelService_Method_BeginState:
  113. if (dwSignature != ChannelService_MethodSignature_BeginState) {
  114. Error = Error_MethodSignatureFailed;
  115. }
  116. break;
  117. case ChannelService_Method_EndState:
  118. if (dwSignature != ChannelService_MethodSignature_EndState) {
  119. Error = Error_MethodSignatureFailed;
  120. }
  121. break;
  122. case ChannelService_Method_Send:
  123. if (dwSignature != ChannelService_MethodSignature_Send) {
  124. Error = Error_MethodSignatureFailed;
  125. }
  126. break;
  127. case ChannelService_Method_BeginRecv:
  128. if (dwSignature != ChannelService_MethodSignature_BeginRecv) {
  129. Error = Error_MethodSignatureFailed;
  130. }
  131. break;
  132. case ChannelService_Method_EndRecv:
  133. if (dwSignature != ChannelService_MethodSignature_EndRecv) {
  134. Error = Error_MethodSignatureFailed;
  135. }
  136. break;
  137. case ChannelService_Method_GetIpByDomain:
  138. if (dwSignature != ChannelService_MethodSignature_GetIpByDomain) {
  139. Error = Error_MethodSignatureFailed;
  140. }
  141. break;
  142. default:
  143. Error = Error_MethodNotFound;
  144. break;
  145. }
  146. return Error;
  147. }
  148. virtual void Handle_Connect(SpReqAnsContext<ChannelService_Connect_Req, ChannelService_Connect_Ans>::Pointer ctx)
  149. {
  150. /// override by user
  151. }
  152. virtual void Handle_Close(SpReqAnsContext<ChannelService_Close_Req, ChannelService_Close_Ans>::Pointer ctx)
  153. {
  154. /// override by user
  155. }
  156. virtual void Handle_GetState(SpReqAnsContext<ChannelService_GetState_Req, ChannelService_GetState_Ans>::Pointer ctx)
  157. {
  158. /// override by user
  159. }
  160. virtual void Handle_BeginState(SpSubscribeContext<ChannelService_BeginState_Sub, ChannelService_State_Info>::Pointer ctx)
  161. {
  162. /// override by user
  163. }
  164. virtual void Handle_EndState(SpOnewayCallContext<ChannelService_EndState_Info>::Pointer ctx)
  165. {
  166. /// override by user
  167. }
  168. virtual void Handle_Send(SpOnewayCallContext<ChannelService_Send_Info>::Pointer ctx)
  169. {
  170. /// override by user
  171. }
  172. virtual void Handle_BeginRecv(SpSubscribeContext<ChannelService_BeginRecv_Sub, ChannelService_Packet_Info>::Pointer ctx)
  173. {
  174. /// override by user
  175. }
  176. virtual void Handle_EndRecv(SpOnewayCallContext<ChannelService_EndRecv_Info>::Pointer ctx)
  177. {
  178. /// override by user
  179. }
  180. virtual void Handle_GetIpByDomain(SpReqAnsContext<ChannelService_GetIpByDomain_Req, ChannelService_GetIpByDomain_Ans>::Pointer ctx)
  181. {
  182. /// override by user
  183. }
  184. virtual void OnRequest(CSmartPointer<ITransactionContext> pTransactionContext)
  185. {
  186. CAutoBuffer Buf;
  187. DWORD dwMessageID;
  188. DWORD dwMessageSignature;
  189. ErrorCodeEnum Error = pTransactionContext->GetReceiveBuffer(dwMessageID, dwMessageSignature, Buf);
  190. if (Error == Error_Succeed) {
  191. #ifdef DEBUG
  192. assert(CheckMessageSignature(dwMessageID, dwMessageSignature) == Error_Succeed);
  193. #else
  194. if (CheckMessageSignature(dwMessageID, dwMessageSignature) != Error_Succeed) {
  195. pTransactionContext->SendAnswer(Error_MethodSignatureFailed);
  196. return;
  197. }
  198. #endif
  199. switch (dwMessageID) {
  200. case ChannelService_Method_Connect:
  201. {
  202. SpReqAnsContext<ChannelService_Connect_Req,ChannelService_Connect_Ans>::Pointer ctx;
  203. ctx.Attach(new SpReqAnsContext<ChannelService_Connect_Req,ChannelService_Connect_Ans>(pTransactionContext));
  204. SpBuffer2Object(Buf, ctx->Req);
  205. pTransactionContext->GetLinkContext(ctx->link);
  206. EntityResource::setLink(ctx->link);
  207. Handle_Connect(ctx);
  208. }
  209. break;
  210. case ChannelService_Method_Close:
  211. {
  212. SpReqAnsContext<ChannelService_Close_Req,ChannelService_Close_Ans>::Pointer ctx;
  213. ctx.Attach(new SpReqAnsContext<ChannelService_Close_Req,ChannelService_Close_Ans>(pTransactionContext));
  214. SpBuffer2Object(Buf, ctx->Req);
  215. pTransactionContext->GetLinkContext(ctx->link);
  216. EntityResource::setLink(ctx->link);
  217. Handle_Close(ctx);
  218. }
  219. break;
  220. case ChannelService_Method_GetState:
  221. {
  222. SpReqAnsContext<ChannelService_GetState_Req,ChannelService_GetState_Ans>::Pointer ctx;
  223. ctx.Attach(new SpReqAnsContext<ChannelService_GetState_Req,ChannelService_GetState_Ans>(pTransactionContext));
  224. SpBuffer2Object(Buf, ctx->Req);
  225. pTransactionContext->GetLinkContext(ctx->link);
  226. EntityResource::setLink(ctx->link);
  227. Handle_GetState(ctx);
  228. }
  229. break;
  230. case ChannelService_Method_BeginState:
  231. {
  232. SpSubscribeContext<ChannelService_BeginState_Sub,ChannelService_State_Info>::Pointer ctx;
  233. ctx.Attach(new SpSubscribeContext<ChannelService_BeginState_Sub,ChannelService_State_Info>(pTransactionContext));
  234. SpBuffer2Object(Buf, ctx->Req);
  235. Handle_BeginState(ctx);
  236. }
  237. break;
  238. case ChannelService_Method_EndState:
  239. {
  240. SpOnewayCallContext<ChannelService_EndState_Info>::Pointer ctx;
  241. ctx.Attach(new SpOnewayCallContext<ChannelService_EndState_Info>());
  242. SpBuffer2Object(Buf, ctx->Info);
  243. Handle_EndState(ctx);
  244. }
  245. break;
  246. case ChannelService_Method_Send:
  247. {
  248. SpOnewayCallContext<ChannelService_Send_Info>::Pointer ctx;
  249. ctx.Attach(new SpOnewayCallContext<ChannelService_Send_Info>());
  250. SpBuffer2Object(Buf, ctx->Info);
  251. pTransactionContext->GetLinkContext(ctx->link);
  252. EntityResource::setLink(ctx->link);
  253. Handle_Send(ctx);
  254. }
  255. break;
  256. case ChannelService_Method_BeginRecv:
  257. {
  258. SpSubscribeContext<ChannelService_BeginRecv_Sub,ChannelService_Packet_Info>::Pointer ctx;
  259. ctx.Attach(new SpSubscribeContext<ChannelService_BeginRecv_Sub,ChannelService_Packet_Info>(pTransactionContext));
  260. SpBuffer2Object(Buf, ctx->Req);
  261. Handle_BeginRecv(ctx);
  262. }
  263. break;
  264. case ChannelService_Method_EndRecv:
  265. {
  266. SpOnewayCallContext<ChannelService_EndRecv_Info>::Pointer ctx;
  267. ctx.Attach(new SpOnewayCallContext<ChannelService_EndRecv_Info>());
  268. SpBuffer2Object(Buf, ctx->Info);
  269. Handle_EndRecv(ctx);
  270. }
  271. break;
  272. case ChannelService_Method_GetIpByDomain:
  273. {
  274. SpReqAnsContext<ChannelService_GetIpByDomain_Req,ChannelService_GetIpByDomain_Ans>::Pointer ctx;
  275. ctx.Attach(new SpReqAnsContext<ChannelService_GetIpByDomain_Req,ChannelService_GetIpByDomain_Ans>(pTransactionContext));
  276. SpBuffer2Object(Buf, ctx->Req);
  277. pTransactionContext->GetLinkContext(ctx->link);
  278. EntityResource::setLink(ctx->link);
  279. Handle_GetIpByDomain(ctx);
  280. }
  281. break;
  282. default:
  283. assert(0);
  284. break;
  285. }
  286. } else {
  287. pTransactionContext->SendAnswer(Error);
  288. }
  289. }
  290. };
  291. ///////////////////////////
  292. } // namespace AssistantChannel
  293. #endif // __ASSISTANTCHANNEL_SERVER_G_H