123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- #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<typename T>
- static inline ErrorCodeEnum SpObject2Blob(T &t, CBlob& out)
- {
- CAutoBuffer buf = SpObject2Buffer<T>(t);
- SpBuffer spbuf;
- if (!spbuf.OpenRead((const char*)&buf[0], buf.GetCount())) {
- return Error_Unexpect;
- }
- out = spbuf.ToBlob();
- return Error_Succeed;
- }
- template<class T>
- 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<class TReq, class TAns>
- struct SpReqAnsContextNoAnswer : public SpReqAnsContext<TReq, TAns>
- {
- SpReqAnsContextNoAnswer(CSmartPointer<ITransactionContext> &pTransactionContext)
- : SpReqAnsContext<TReq, TAns>(pTransactionContext) {/*empty for sonar. */}
- ErrorCodeEnum Answer(ErrorCodeEnum Error = Error_Succeed)
- {
- //static_assert(Error == Error_Succeed, "Input parameter must be Error_Succeed!");
- Dbg("here has been override? no way bcz it's parent has no virtual statement.");
- return Error_Duplication;
- }
- };
- template<class TInfo>
- struct SpOnewayCallContextNoAnswer : public SpOnewayCallContext<TInfo>
- {
- };
- 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 SendAnswer(ErrorCodeEnum eErrorCode, DWORD dwUserError = 0, CSimpleString str = "") {
- return Error_NotImpl;
- }
- virtual ErrorCodeEnum SetExpireTime(DWORD dwMS){
- return Error_NotImpl;
- }
- virtual ErrorCodeEnum GetExpireTime(DWORD &dwWholeTime,DWORD &dwLeftTime){
- return Error_NotImpl;
- }
- virtual ErrorCodeEnum GetLinkContext(linkContext& curLink)
- {
- return Error_NotImpl;
- }
- };
- #define DEFINE_TEMP_TRANSACTION() \
- CSmartPointer<ITransactionContext> spTmp; \
- SpPuppetTransactionContext *pTransactionContext = new SpPuppetTransactionContext(); \
- spTmp.Attach(pTransactionContext)
- #define DEFINE_PUPPET_CONTEXT_WITH_TYPE(TReq, TAns) \
- DEFINE_TEMP_TRANSACTION(); \
- SpReqAnsContextNoAnswer<TReq, \
- TAns>::Pointer ctx = new SpReqAnsContextNoAnswer<TReq, \
- TAns>(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_
|