Ups_server_g.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #ifndef __UPS_SERVER_G_H
  2. #define __UPS_SERVER_G_H
  3. #pragma once
  4. // This code is generated by spgen tool!
  5. #include "Ups_def_g.h"
  6. namespace Ups {
  7. class UpsService_ServerSessionBase : public CServerSessionBase
  8. {
  9. public:
  10. UpsService_ServerSessionBase() { }
  11. virtual ~UpsService_ServerSessionBase() { }
  12. virtual bool IsExclusive() { return false; }
  13. virtual bool IsSessionOverlap() { return true; }
  14. virtual ErrorCodeEnum GetMessageAttr(DWORD dwMessageID, DWORD dwSignature, bool &bOverlap)
  15. {
  16. ErrorCodeEnum Error = Error_Succeed;
  17. switch (dwMessageID) {
  18. case UpsService_Method_Open:
  19. if (dwSignature == UpsService_MethodSignature_Open) {
  20. bOverlap = true;
  21. } else {
  22. Error = Error_MethodSignatureFailed;
  23. }
  24. break;
  25. case UpsService_Method_GetStatus:
  26. if (dwSignature == UpsService_MethodSignature_GetStatus) {
  27. bOverlap = true;
  28. } else {
  29. Error = Error_MethodSignatureFailed;
  30. }
  31. break;
  32. case UpsService_Method_Shutdown:
  33. if (dwSignature == UpsService_MethodSignature_Shutdown) {
  34. bOverlap = true;
  35. } else {
  36. Error = Error_MethodSignatureFailed;
  37. }
  38. break;
  39. case UpsService_Method_Close:
  40. if (dwSignature == UpsService_MethodSignature_Close) {
  41. bOverlap = true;
  42. } else {
  43. Error = Error_MethodSignatureFailed;
  44. }
  45. break;
  46. default:
  47. Error = Error_MethodNotFound;
  48. break;
  49. }
  50. return Error;
  51. }
  52. int CheckMessageSignature(DWORD dwMessageID, DWORD dwSignature)
  53. {
  54. ErrorCodeEnum Error = Error_Succeed;
  55. switch (dwMessageID) {
  56. case UpsService_Method_Open:
  57. if (dwSignature != UpsService_MethodSignature_Open) {
  58. Error = Error_MethodSignatureFailed;
  59. }
  60. break;
  61. case UpsService_Method_GetStatus:
  62. if (dwSignature != UpsService_MethodSignature_GetStatus) {
  63. Error = Error_MethodSignatureFailed;
  64. }
  65. break;
  66. case UpsService_Method_Shutdown:
  67. if (dwSignature != UpsService_MethodSignature_Shutdown) {
  68. Error = Error_MethodSignatureFailed;
  69. }
  70. break;
  71. case UpsService_Method_Close:
  72. if (dwSignature != UpsService_MethodSignature_Close) {
  73. Error = Error_MethodSignatureFailed;
  74. }
  75. break;
  76. default:
  77. Error = Error_MethodNotFound;
  78. break;
  79. }
  80. return Error;
  81. }
  82. virtual void Handle_Open(SpReqAnsContext<UpsService_Open_Req, UpsService_Open_Ans>::Pointer ctx)
  83. {
  84. /// override by user
  85. }
  86. virtual void Handle_GetStatus(SpReqAnsContext<UpsService_GetStatus_Req, UpsService_GetStatus_Ans>::Pointer ctx)
  87. {
  88. /// override by user
  89. }
  90. virtual void Handle_Shutdown(SpReqAnsContext<UpsService_Shutdown_Req, UpsService_Shutdown_Ans>::Pointer ctx)
  91. {
  92. /// override by user
  93. }
  94. virtual void Handle_Close(SpReqAnsContext<UpsService_Close_Req, UpsService_Close_Ans>::Pointer ctx)
  95. {
  96. /// override by user
  97. }
  98. virtual void OnRequest(CSmartPointer<ITransactionContext> pTransactionContext)
  99. {
  100. CAutoBuffer Buf;
  101. DWORD dwMessageID;
  102. DWORD dwMessageSignature;
  103. ErrorCodeEnum Error = pTransactionContext->GetReceiveBuffer(dwMessageID, dwMessageSignature, Buf);
  104. if (Error == Error_Succeed) {
  105. #ifdef DEBUG
  106. assert(CheckMessageSignature(dwMessageID, dwMessageSignature) == Error_Succeed);
  107. #else
  108. if (CheckMessageSignature(dwMessageID, dwMessageSignature) != Error_Succeed) {
  109. pTransactionContext->SendAnswer(Error_MethodSignatureFailed);
  110. return;
  111. }
  112. #endif
  113. switch (dwMessageID) {
  114. case UpsService_Method_Open:
  115. {
  116. SpReqAnsContext<UpsService_Open_Req,UpsService_Open_Ans>::Pointer ctx;
  117. ctx.Attach(new SpReqAnsContext<UpsService_Open_Req,UpsService_Open_Ans>(pTransactionContext));
  118. SpBuffer2Object(Buf, ctx->Req);
  119. Handle_Open(ctx);
  120. }
  121. break;
  122. case UpsService_Method_GetStatus:
  123. {
  124. SpReqAnsContext<UpsService_GetStatus_Req,UpsService_GetStatus_Ans>::Pointer ctx;
  125. ctx.Attach(new SpReqAnsContext<UpsService_GetStatus_Req,UpsService_GetStatus_Ans>(pTransactionContext));
  126. SpBuffer2Object(Buf, ctx->Req);
  127. Handle_GetStatus(ctx);
  128. }
  129. break;
  130. case UpsService_Method_Shutdown:
  131. {
  132. SpReqAnsContext<UpsService_Shutdown_Req,UpsService_Shutdown_Ans>::Pointer ctx;
  133. ctx.Attach(new SpReqAnsContext<UpsService_Shutdown_Req,UpsService_Shutdown_Ans>(pTransactionContext));
  134. SpBuffer2Object(Buf, ctx->Req);
  135. Handle_Shutdown(ctx);
  136. }
  137. break;
  138. case UpsService_Method_Close:
  139. {
  140. SpReqAnsContext<UpsService_Close_Req,UpsService_Close_Ans>::Pointer ctx;
  141. ctx.Attach(new SpReqAnsContext<UpsService_Close_Req,UpsService_Close_Ans>(pTransactionContext));
  142. SpBuffer2Object(Buf, ctx->Req);
  143. Handle_Close(ctx);
  144. }
  145. break;
  146. default:
  147. assert(0);
  148. break;
  149. }
  150. } else {
  151. pTransactionContext->SendAnswer(Error);
  152. }
  153. }
  154. };
  155. ///////////////////////////
  156. } // namespace Ups
  157. #endif // __UPS_SERVER_G_H