DeviceCrossHelper.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #include "stdafx.h"
  2. #ifndef _RVC_DEVICE_CROSS_HELPER_H_
  3. #define _RVC_DEVICE_CROSS_HELPER_H_
  4. #include "ListEntry.h"
  5. #include "SpHelper.h"
  6. #ifndef FIELD_OFFSET
  7. // begin_ntoshvp
  8. //
  9. // Calculate the byte offset of a field in a structure of type type.
  10. //
  11. #define FIELD_OFFSET(type, field) ((LONG)(LONG_PTR)&(((type *)0)->field))
  12. //
  13. // Calculate the size of a field in a structure of type type, without
  14. // knowing or stating the type of the field.
  15. //
  16. #define RTL_FIELD_SIZE(type, field) (sizeof(((type *)0)->field))
  17. //
  18. // Calculate the size of a structure of type type up through and
  19. // including a field.
  20. //
  21. #define RTL_SIZEOF_THROUGH_FIELD(type, field) \
  22. (FIELD_OFFSET(type, field) + RTL_FIELD_SIZE(type, field))
  23. // end_ntoshvp
  24. #endif // FIELD_OFFSET
  25. template<typename T>
  26. static inline ErrorCodeEnum SpObject2Blob(T &t, CBlob& out)
  27. {
  28. CAutoBuffer buf = SpObject2Buffer<T>(t);
  29. SpBuffer spbuf;
  30. if (!spbuf.OpenRead((const char*)&buf[0], buf.GetCount())) {
  31. return Error_Unexpect;
  32. }
  33. out = spbuf.ToBlob();
  34. return Error_Succeed;
  35. }
  36. template<class T>
  37. static inline ErrorCodeEnum SpBlob2Object(CBlob blob, T &t)
  38. {
  39. ErrorCodeEnum Error;
  40. SpBuffer spbuf;
  41. if (spbuf.OpenRead((const char*)blob.m_pData, blob.m_iLength)) {
  42. t.Serialize(spbuf);
  43. Error = Error_Succeed;
  44. } else {
  45. Error = Error_Bug;
  46. }
  47. return Error;
  48. }
  49. template<class TReq, class TAns>
  50. struct SpReqAnsContextNoAnswer : public SpReqAnsContext<TReq, TAns>
  51. {
  52. SpReqAnsContextNoAnswer(CSmartPointer<ITransactionContext> &pTransactionContext)
  53. : SpReqAnsContext<TReq, TAns>(pTransactionContext) {/*empty for sonar. */}
  54. ErrorCodeEnum Answer(ErrorCodeEnum Error = Error_Succeed)
  55. {
  56. //static_assert(Error == Error_Succeed, "Input parameter must be Error_Succeed!");
  57. Dbg("here has been override? no way bcz it's parent has no virtual statement.");
  58. return Error_Duplication;
  59. }
  60. };
  61. template<class TInfo>
  62. struct SpOnewayCallContextNoAnswer : public SpOnewayCallContext<TInfo>
  63. {
  64. };
  65. class SpPuppetTransactionContext : public ITransactionContext {
  66. public:
  67. virtual bool IsOneWayCall() { return true; }
  68. virtual DWORD GetRequestID() { return 0xFFFFFFFF; }
  69. virtual ErrorCodeEnum GetReceiveBuffer(DWORD &dwMessageID, DWORD &dwMessageSignature, CAutoBuffer &Buffer) {
  70. return Error_NotImpl;
  71. }
  72. virtual ErrorCodeEnum SendAnswer(CAutoBuffer Buffer, bool bEnd=true) {
  73. return Error_NotImpl;
  74. }
  75. virtual ErrorCodeEnum SendAnswer(ErrorCodeEnum eErrorCode, DWORD dwUserError = 0){
  76. return Error_NotImpl;
  77. }
  78. virtual ErrorCodeEnum SendAnswer(ErrorCodeEnum eErrorCode, DWORD dwUserError = 0, CSimpleString str = "") {
  79. return Error_NotImpl;
  80. }
  81. virtual ErrorCodeEnum SetExpireTime(DWORD dwMS){
  82. return Error_NotImpl;
  83. }
  84. virtual ErrorCodeEnum GetExpireTime(DWORD &dwWholeTime,DWORD &dwLeftTime){
  85. return Error_NotImpl;
  86. }
  87. virtual ErrorCodeEnum GetLinkContext(linkContext& curLink)
  88. {
  89. return Error_NotImpl;
  90. }
  91. };
  92. #define DEFINE_TEMP_TRANSACTION() \
  93. CSmartPointer<ITransactionContext> spTmp; \
  94. SpPuppetTransactionContext *pTransactionContext = new SpPuppetTransactionContext(); \
  95. spTmp.Attach(pTransactionContext)
  96. #define DEFINE_PUPPET_CONTEXT_WITH_TYPE(TReq, TAns) \
  97. DEFINE_TEMP_TRANSACTION(); \
  98. SpReqAnsContextNoAnswer<TReq, \
  99. TAns>::Pointer ctx = new SpReqAnsContextNoAnswer<TReq, \
  100. TAns>(spTmp)
  101. typedef struct _TC_CONTEXT_CALL_ITEM {
  102. LIST_ENTRY ListEntry;
  103. DWORD dwRequestID;
  104. PVOID Context;
  105. }TC_CONTEXT_CALL_ITEM, *PTC_CONTEXT_CALL_ITEM;
  106. typedef struct _TC_ENTITY_INTERFACE_QUEUE {
  107. LIST_ENTRY ContextListHead;
  108. DWORD dwMethodSig;
  109. DWORD dwSequence;
  110. }TC_ENTITY_INTERFACE_QUEUE, *PTC_ENTITY_INTERFACE_QUEUE;
  111. #define TWHeapAlloc(x) (HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, x))
  112. #define TWHeapFree(x) (HeapFree(GetProcessHeap(), 0, x))
  113. #endif //_RVC_DEVICE_CROSS_HELPER_H_