#include "stdafx.h" #ifndef _RVC_DEVICE_CROSS_HELPER_H_ #define _RVC_DEVICE_CROSS_HELPER_H_ #include "ListEntry.h" #include "SpHelper.h" #ifndef FIELD_OFFSET // begin_ntoshvp // // Calculate the byte offset of a field in a structure of type type. // #define FIELD_OFFSET(type, field) ((LONG)(LONG_PTR)&(((type *)0)->field)) // // Calculate the size of a field in a structure of type type, without // knowing or stating the type of the field. // #define RTL_FIELD_SIZE(type, field) (sizeof(((type *)0)->field)) // // Calculate the size of a structure of type type up through and // including a field. // #define RTL_SIZEOF_THROUGH_FIELD(type, field) \ (FIELD_OFFSET(type, field) + RTL_FIELD_SIZE(type, field)) // end_ntoshvp #endif // FIELD_OFFSET template static inline ErrorCodeEnum SpObject2Blob(T &t, CBlob& out) { CAutoBuffer buf = SpObject2Buffer(t); SpBuffer spbuf; if (!spbuf.OpenRead((const char*)&buf[0], buf.GetCount())) { return Error_Unexpect; } out = spbuf.ToBlob(); return Error_Succeed; } template static inline ErrorCodeEnum SpBlob2Object(CBlob blob, T &t) { ErrorCodeEnum Error; SpBuffer spbuf; if (spbuf.OpenRead((const char*)blob.m_pData, blob.m_iLength)) { t.Serialize(spbuf); Error = Error_Succeed; } else { Error = Error_Bug; } return Error; } template struct SpReqAnsContextNoAnswer : public SpReqAnsContext { SpReqAnsContextNoAnswer(CSmartPointer &pTransactionContext) : SpReqAnsContext(pTransactionContext) {/*empty for sonar. */} ErrorCodeEnum Answer(ErrorCodeEnum Error = Error_Succeed) { Dbg("here has been override? no way bcz it's parent has no virtual statement."); return Error_Duplication; } }; template struct SpOnewayCallContextNoAnswer : public SpOnewayCallContext { }; class SpPuppetTransactionContext : public ITransactionContext { public: virtual bool IsOneWayCall() { return true; } virtual DWORD GetRequestID() { return 0xFFFFFFFF; } virtual ErrorCodeEnum GetReceiveBuffer(DWORD &dwMessageID, DWORD &dwMessageSignature, CAutoBuffer &Buffer) { return Error_NotImpl; } virtual ErrorCodeEnum SendAnswer(CAutoBuffer Buffer, bool bEnd=true) { return Error_NotImpl; } virtual ErrorCodeEnum SendAnswer(ErrorCodeEnum eErrorCode, DWORD dwUserError = 0){ return Error_NotImpl; } virtual ErrorCodeEnum SetExpireTime(DWORD dwMS){ return Error_NotImpl; } virtual ErrorCodeEnum GetExpireTime(DWORD &dwWholeTime,DWORD &dwLeftTime){ return Error_NotImpl; } }; #define DEFINE_TEMP_TRANSACTION() \ CSmartPointer spTmp; \ SpPuppetTransactionContext *pTransactionContext = new SpPuppetTransactionContext(); \ spTmp.Attach(pTransactionContext) #define DEFINE_PUPPET_CONTEXT_WITH_TYPE(TReq, TAns) \ DEFINE_TEMP_TRANSACTION(); \ SpReqAnsContextNoAnswer::Pointer ctx = new SpReqAnsContextNoAnswer(spTmp) typedef struct _TC_CONTEXT_CALL_ITEM { LIST_ENTRY ListEntry; DWORD dwRequestID; PVOID Context; }TC_CONTEXT_CALL_ITEM, *PTC_CONTEXT_CALL_ITEM; typedef struct _TC_ENTITY_INTERFACE_QUEUE { LIST_ENTRY ContextListHead; DWORD dwMethodSig; DWORD dwSequence; }TC_ENTITY_INTERFACE_QUEUE, *PTC_ENTITY_INTERFACE_QUEUE; #define TWHeapAlloc(x) (HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, x)) #define TWHeapFree(x) (HeapFree(GetProcessHeap(), 0, x)) #endif //_RVC_DEVICE_CROSS_HELPER_H_