📄 ndrtypes.h
字号:
/* NdrTypes.h - ORPC NDR (un)marshaling types *//* Copyright (c) 1999 Wind River Systems, Inc. *//*modification history--------------------01s,02aug01,dbs add [v1_enum] support01r,08feb01,nel SPR#63885. SAFEARRAYs added. 01q,24aug00,dbs fix many OPC-related SPRs, copied over from T2 VxDCOM01p,18jul00,dbs add enum NDR type01o,29feb00,dbs fix typo and previous unmarshaling bug01n,28feb00,dbs fix nasty bug when unmarshaling arrays of pointers01m,24feb00,dbs add back-ptr to NDRTYPES01l,07feb00,dbs simplify NdrType classes, enhance marshaling of arrays to support all kinds01k,14oct99,dbs apply fix for ARM double format01j,23sep99,dbs add final parts of VARIANT marshaling01i,16sep99,dbs marshaling enhancements, part 201h,14sep99,dbs add VARIANT, pointer and string types - first stage01g,16aug99,dbs add variant and string support01f,12aug99,dbs improve struct support01e,30jul99,dbs tighten up type-safety of NDR types01d,24may99,dbs fix interface-ptr marshaling01c,20may99,dbs add type-kind method to all classes01b,14may99,dbs add alignment requirement to NdrType01a,12may99,dbs created*/#ifndef __INCNdrTypes_h#define __INCNdrTypes_h#include "dcomProxy.h"#include "NdrStreams.h"////////////////////////////////////////////////////////////////////////////// NdrSimple<T> -- an NdrType subclass for all basic C/C++ primitive// types.//template <typename PrimT>class NdrSimple : public NdrType { public: NdrSimple (NDRTYPES& n) : NdrType (n), m_pValue (0) {} TypeKind kind () const { return TK_SIMPLE; } void resize (size_t) {} size_t size (NdrUnmarshalStream*) { return sizeof (PrimT); } size_t alignment () const { return sizeof (PrimT); } long value () const { return (long) *m_pValue; } void bind (void* pv) { m_pValue = (PrimT*) pv; } HRESULT marshal1 (NdrMarshalStream* pStrm) { pStrm->align (sizeof (PrimT)); return pStrm->insert (sizeof (PrimT), m_pValue, true); } HRESULT unmarshal1 (NdrUnmarshalStream* pStrm) { pStrm->align (sizeof (PrimT)); return pStrm->extract (sizeof (PrimT), m_pValue, true); } private: PrimT* m_pValue; };////////////////////////////////////////////////////////////////////////////// NdrEnum -- an NdrType subclass for handling old-style (16-bit)// enumerated values. These are conveyed on the wire as 16-bit values// (if declared as IDL enums) but need to be marshaled from (and// unmarshaled to) true 'enum' types as understood by the local// compiler.//class NdrEnum : public NdrType { enum DUMMY { DUMMY_VALUE0=0, DUMMY_VALUE1=1 }; public: NdrEnum (NDRTYPES& n) : NdrType (n), m_pValue (0), m_bV1Enum (false) {} TypeKind kind () const { return TK_SIMPLE; } void resize (size_t) {} size_t size (NdrUnmarshalStream*) { return sizeof (DUMMY); } size_t alignment () const; long value () const { return (long) *m_pValue; } void bind (void* pv) { m_pValue = (DUMMY*) pv; } void init (bool isV1Enum = false) { m_bV1Enum = isV1Enum; } HRESULT marshal1 (NdrMarshalStream* pStrm); HRESULT unmarshal1 (NdrUnmarshalStream* pStrm); private: DUMMY* m_pValue; bool m_bV1Enum; };////////////////////////////////////////////////////////////////////////////// NdrStruct -- an NdrType subclass that represents 'structures' at// the 'C' or IDL level. The init() method is given an array of// StructMemberInfo items, each of which describes one member of the// structure, in terms of its type (via an NdrType pointer) and its// offset within the structure, plus the index of the 'size_is'// member, i.e. the one holding the array-length.//class NdrStruct : public NdrType { public: NdrStruct (NDRTYPES& n) : NdrType (n), m_nMembers (0), m_pMemberInfo (0), m_pInstance (0), m_nSizeIs (0) {} virtual ~NdrStruct (); void init (size_t nmems, const NdrMemberInfo mems [], int nsize_is); TypeKind kind () const { return TK_STRUCT; } void resize (size_t) {} size_t size (NdrUnmarshalStream*); size_t alignment () const; long value () const { return 0; } void bind (void*); HRESULT marshal1 (NdrMarshalStream* pStrm); HRESULT marshal2 (NdrMarshalStream* pStrm); HRESULT unmarshal1 (NdrUnmarshalStream* pStrm); HRESULT unmarshal2 (NdrUnmarshalStream* pStrm); protected: size_t m_nMembers; // number of members NdrMemberInfo* m_pMemberInfo; // member descriptions void* m_pInstance; // ptr to current instance int m_nSizeIs; // index of 'size_is' member };////////////////////////////////////////////////////////////////////////////// NdrPointer -- an NdrType subclass that represents a [unique] or// [ptr] pointer to some other type...//class NdrPointer : public NdrType { public: NdrPointer (NDRTYPES& n, bool bRefPtr=false) : NdrType (n), m_pPtr (0), m_pointeeType (0), m_refptr (bRefPtr) {} void init (const NdrTypeDesc& pt) { m_pointeeType=pt; } TypeKind kind () const { return TK_PTR; } void resize (size_t); size_t size (NdrUnmarshalStream*) { return sizeof (void*); } size_t alignment () const { return sizeof (long); } long value () const { return 0; } void bind (void* pv) { m_pPtr = (void**) pv; } HRESULT marshal1 (NdrMarshalStream* pStrm); HRESULT marshal2 (NdrMarshalStream* pStrm); HRESULT unmarshal1 (NdrUnmarshalStream* pStrm); HRESULT unmarshal2 (NdrUnmarshalStream* pStrm); protected: void** m_pPtr; // ptr to pointer-variable NdrTypeDesc m_pointeeType; // type of pointee bool m_refptr; // true when [ref] pointer };////////////////////////////////////////////////////////////////////////////// NdrArray -- an NdrType subclass that represents a fixed-size array// at the IDL/C++ level. Its init() method is given the NdrType// representation of each of its elements, the size (in raw memory// bytes) of each element of the array, and the number of elements in// the array.//class NdrArray : public NdrType { public: NdrArray (NDRTYPES& n) : NdrType (n), m_pElementType (0), m_nElementSize (0), m_ptr (0) , m_arraySize (0), m_offset (0), m_max (0) {} void init ( const NdrTypeDesc& elementType, size_t elemSize, size_t max, size_t offset, size_t len ); TypeKind kind () const { return TK_ARRAY; } void resize (size_t n) { m_arraySize = n; } size_t size (NdrUnmarshalStream*); size_t alignment () const; long value () const { return 0; } void bind (void*); HRESULT marshal1 (NdrMarshalStream* pStrm); HRESULT marshal2 (NdrMarshalStream* pStrm); HRESULT unmarshal1 (NdrUnmarshalStream* pStrm); HRESULT unmarshal2 (NdrUnmarshalStream* pStrm); protected: NdrTypeDesc m_pElementType; // type of element size_t m_nElementSize; // size of one element void* m_ptr; // ptr to current element size_t m_arraySize; // (transmitted) size of array size_t m_offset; // offset of mshl data size_t m_max; // max len of array };////////////////////////////////////////////////////////////////////////////// NdrConfArray -- an NdrType subclass that represents a 'conformant// array' at the IDL/C++ level. It sub-classes NdrArray (the// fixed-size array representation) and over-rides the marshal() and// unmarshal() methods. Note that conformant arrays inside structures// (conformant structures) are actual typed by WIDL as plain arrays,// and conformant arrays are only used for method args, or are behind// [unique] pointers if inside structures.//class NdrConfArray : public NdrArray { public: NdrConfArray (NDRTYPES& n) : NdrArray (n) {} TypeKind kind () const { return TK_CARRAY; } size_t size (NdrUnmarshalStream*); HRESULT marshal1 (NdrMarshalStream* pStrm); HRESULT unmarshal1 (NdrUnmarshalStream* pStrm); };////////////////////////////////////////////////////////////////////////////// NdrConfVarArray -- an NdrType subclass that represents a// 'conformant varying array' at the IDL/C++ level. It sub-classes// NdrConfArray and records the 'max' size of the array, which is// different from the transmitted size of the array, and is declared// like:-//// [size_is(max), length_is(num)] FOO* pFoo//// meaning that although the maximum size of the array is 'max' only// 'num' elements are actually transmitted. Thanks DCE!//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -