dcomProxy.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:11k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* dcomProxy.h - VxWorks DCOM runtime marshaling support */
  2. /* Copyright (c) 1998 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 02i,02aug01,dbs  add [v1_enum] support
  7. 02h,31jul01,dbs  remove obsolete InterfaceProxy class, add p/s registration
  8.                  macro
  9. 02g,28feb01,nel  SPR#35698. Add boolean type.
  10. 02f,19sep00,nel  Change constness of widlMarshal to match T3.
  11. 02e,24aug00,dbs  fix many OPC-related SPRs
  12. 02d,18jul00,dbs  add CV array type and enum type
  13. 02c,02mar00,dbs  add revised VTBL macros
  14. 02b,11feb00,dbs  add void_t() to allow void-pointers in marshaling
  15. 02a,07feb00,dbs  simplify NdrType classes, enhance marshaling of arrays to
  16.                  support all kinds
  17. 01z,02feb00,dbs  change proxy vtbl to be template-based
  18. 01y,14oct99,dbs  make double an explicit typedesc
  19. 01x,22sep99,dbs  add uhyper type
  20. 01w,16sep99,dbs  marshaling enhancements, part 2
  21. 01v,14sep99,dbs  change REFIIDs to const IID& for WIDL compatibility, add
  22.                  VARIANT, pointer and string types
  23. 01u,12aug99,dbs  improve NDR structure support
  24. 01t,05aug99,dbs  remove byte typedef
  25. 01s,30jul99,dbs  tighten up type-safety of NDR types
  26. 01r,25jun99,dbs  add channel-ID to stub-msg
  27. 01q,03jun99,aim  removed BYTE_ORDER and LITTLE_ENDIAN defs
  28. 01p,02jun99,dbs  remove OS-specific macros
  29. 01o,28may99,dbs  make stub disp-tbl a struct
  30. 01n,27may99,dbs  remove DCE-specific stub-function type
  31. 01m,25may99,dbs  remove NDRTYPES::alloc/free methods
  32. 01l,20may99,dbs  move NDR phase into streams
  33. 01k,18may99,dbs  add proxy/stub marshaling phase to NDR-streams
  34. 01j,14may99,dbs  add alignment requirement to NdrType
  35. 01i,14may99,dbs  remove obsolete PFNSTUB type
  36. 01h,14may99,dbs  add new NDR support
  37. 01g,11may99,dbs  simplify proxy remoting architecture
  38. 01f,11may99,dbs  add fwd-decl of IRpcStubBuffer etc, rename symbols
  39.                  like VXCOM_* to VXDCOM_*
  40. 01e,04may99,dbs  remove cplusplus check
  41. 01d,30apr99,dbs  fix up bracketing in vtbl macros
  42. 01c,29apr99,dbs  fix -Wall warnings
  43. 01b,22apr99,dbs  add HRESULT member to RPCOLEMESSAGE
  44. 01a,20apr99,dbs  added mod-hist
  45. */
  46. /* This header is to be included in generated proxy/stub code. */
  47. #ifndef __INCdcomProxy_h
  48. #define __INCdcomProxy_h
  49. #include "dcomLib.h"
  50. #include "comObjLib.h"
  51. //////////////////////////////////////////////////////////////////////////
  52. //
  53. // DATA REPRESENTATION -- we use the NDR format, which is actually
  54. // defined as a vector of 4 bytes, the first of which contains the
  55. // integer ordering field. However, its difficult in C to pass this
  56. // around, so we use an unsigned-long representation instead.
  57. //
  58. #if (_BYTE_ORDER == _LITTLE_ENDIAN)
  59. #define VXDCOM_NDR_CHAR_REP  0x00
  60. #define VXDCOM_NDR_INT_REP   0x01
  61. #define VXDCOM_NDR_FLOAT_REP 0x00
  62. #define VXDCOM_DREP_LITTLE_ENDIAN 0x00000010
  63. #define VXDCOM_DREP_BIG_ENDIAN 0x00000000
  64. #define VXDCOM_DREP_MASK 0x000000FF
  65. #define VXDCOM_DREP_LOCAL VXDCOM_DREP_LITTLE_ENDIAN
  66. #else /* big endian */
  67. #define VXDCOM_NDR_CHAR_REP  0x00
  68. #define VXDCOM_NDR_INT_REP   0x00
  69. #define VXDCOM_NDR_FLOAT_REP 0x00
  70. #define VXDCOM_DREP_LITTLE_ENDIAN 0x10000000
  71. #define VXDCOM_DREP_BIG_ENDIAN 0x00000000
  72. #define VXDCOM_DREP_MASK 0xFF000000
  73. #define VXDCOM_DREP_LOCAL VXDCOM_DREP_BIG_ENDIAN
  74. #endif
  75. #define VXDCOM_NDR_DATAREP0 ((VXDCOM_NDR_INT_REP << 4) | VXDCOM_NDR_CHAR_REP)
  76. #define VXDCOM_NDR_DATAREP1 (VXDCOM_NDR_FLOAT_REP)
  77. #define VXDCOM_NDR_DATAREP2 (0)
  78. #define VXDCOM_NDR_DATAREP3 (0)
  79. typedef unsigned long RPCOLEDATAREP;
  80. //////////////////////////////////////////////////////////////////////////
  81. //
  82. // Forward type declarations...
  83. //
  84. class NdrTypeFactory;
  85. class NdrMarshalStream;
  86. class NdrUnmarshalStream;
  87. class RpcProxyMsg;
  88. class NDRTYPES;
  89. ///////////////////////////////////////////////////////////////////////////
  90. //
  91. // IUnknown proxy functions
  92. //
  93. extern HRESULT IUnknown_QueryInterface_vxproxy (IUnknown*, REFIID, void**);
  94. extern ULONG   IUnknown_AddRef_vxproxy (IUnknown*);
  95. extern ULONG   IUnknown_Release_vxproxy (IUnknown*);
  96. ///////////////////////////////////////////////////////////////////////////
  97. //
  98. // ndr_make_right - re-formats a 2-byte, 4-byte or 8-byte number
  99. // into the format indicated by the dataRep field...
  100. //
  101. template <typename T>
  102. inline void ndr_make_right (T& t, ULONG drepOther)
  103.     {
  104.     if (VXDCOM_DREP_LOCAL == drepOther)
  105.         return;
  106.     char *a = (char*) &t;
  107.     char *b = ((char*) &t) + sizeof (T) - 1;
  108.     char tmp;
  109.     for (size_t n=0; n < (sizeof (T) / 2); ++n)
  110.         {
  111.         tmp = *a;
  112.         *a = *b;
  113.         *b = tmp;
  114.         ++a;
  115.         --b;
  116.         }
  117.     }
  118. //////////////////////////////////////////////////////////////////////////
  119. //
  120. // NDR Utility macros...
  121. //
  122. #define NDR_SIZEOF(type)    ((size_t) ((char*)(((type*)0) + 1)))
  123. #define NDR_OFFSETOF(type,member)    ((size_t) &((type*) 0)->member)
  124. //////////////////////////////////////////////////////////////////////////
  125. //
  126. // Define NDR/IDL types that aren't part of C/C++
  127. //
  128. typedef unsigned long DREP;
  129. //////////////////////////////////////////////////////////////////////////
  130. //
  131. class NdrType
  132.     {
  133.   public:
  134.     enum TypeKind
  135. {
  136. TK_SIMPLE=0,
  137. TK_STRUCT,
  138. TK_ARRAY,
  139. TK_CSTRUCT,
  140. TK_CARRAY,
  141. TK_VARRAY,
  142. TK_CVARRAY,
  143. TK_UNION,
  144. TK_NE_UNION,
  145. TK_PTR,
  146. TK_BSTR,
  147. TK_INTERFACE
  148. };
  149.     void* operator new (size_t, NdrTypeFactory*);
  150.     void  operator delete (void*);
  151.     NdrType (NDRTYPES& n) : m_dwRefCount (0), m_ndrtypes (n) {}
  152.     virtual ~NdrType () {}
  153.     virtual TypeKind kind () const =0;
  154.     virtual size_t size (NdrUnmarshalStream*) =0;
  155.     virtual size_t alignment () const =0;
  156.     virtual void resize (size_t) =0;
  157.     virtual long value () const =0;
  158.     virtual void bind (void*) =0;
  159.     virtual HRESULT marshal1 (NdrMarshalStream*) =0;
  160.     virtual HRESULT marshal2 (NdrMarshalStream*);
  161.     virtual HRESULT unmarshal1 (NdrUnmarshalStream*) =0;
  162.     virtual HRESULT unmarshal2 (NdrUnmarshalStream*);
  163.     virtual HRESULT marshal (NdrMarshalStream*);
  164.     virtual HRESULT unmarshal (NdrUnmarshalStream*);
  165.     ULONG AddRef () { return ++m_dwRefCount; }
  166.     ULONG Release ()
  167. {
  168. ULONG n = --m_dwRefCount;
  169. if (n == 0)
  170.     delete this;
  171. return n;
  172. }
  173.     void arraySizeSet (int n);
  174.     int  arraySizeGet ();
  175.   private:
  176.     DWORD m_dwRefCount;
  177.     NDRTYPES& m_ndrtypes;
  178.     };
  179. //////////////////////////////////////////////////////////////////////////
  180. //
  181. // Define the generic 'type descriptor' as ref-counting pointer to an
  182. // NdrType (subclass) instance.
  183. //
  184. typedef CComPtr<NdrType> NdrTypeDesc;
  185. //////////////////////////////////////////////////////////////////////////
  186. //
  187. // NDR Structure support -- the nSizeIs member indicates the
  188. // associated structure member which provides the dynamic sizing
  189. // information for a particular data member. For fixed-size structure
  190. // elements, this value will be -1 (i.e. there is no sizing info) and
  191. // for those with a size_is attribute the field will hold the index
  192. // (in the range 0..N-1 where N is the number of struct members) of
  193. // the data member that is nominated in the size_is field.
  194. //
  195. // For conformant structures, i.e. those whose last element is a
  196. // conformant-array, they may use the cstruct_t type descriptor, and
  197. // then won't require the last member to have nSizeIs set.
  198. //
  199. struct NdrMemberInfo
  200.     {
  201.     NdrTypeDesc pType;
  202.     size_t nOffset;
  203.     int nSizeIs;
  204.     
  205.     NdrMemberInfo (const NdrTypeDesc& pt, size_t offset, int nsize = -1)
  206. : pType (pt), nOffset (offset), nSizeIs (nsize)
  207. {}
  208.     NdrMemberInfo () : pType (0), nOffset (0), nSizeIs (-1)
  209. {}
  210.     };
  211. #define NDR_MEMBER(sname,mem,typ)     NdrMemberInfo(typ,NDR_OFFSETOF(sname,mem))
  212. #define NDR_MEMBERX(sname,mem,typ,sz) NdrMemberInfo(typ,NDR_OFFSETOF(sname,mem),sz)
  213. //////////////////////////////////////////////////////////////////////////
  214. //
  215. struct RpcMode
  216.     {
  217.     enum Mode_t { OBJECT=0, DCE=1 };
  218.     };
  219. //////////////////////////////////////////////////////////////////////////
  220. //
  221. // RPC proxy message
  222. //
  223. class RPC_PROXY_MSG
  224.     {
  225.   public:
  226.     RPC_PROXY_MSG (const IID& riid, RpcMode::Mode_t mode, ULONG opnum, void*);
  227.     ~RPC_PROXY_MSG ();
  228.     NdrMarshalStream* marshalStreamGet ();
  229.     HRESULT SendReceive ();
  230.     NdrUnmarshalStream* unmarshalStreamGet ();
  231.     RpcProxyMsg* m_pImpl;
  232.     };
  233. //////////////////////////////////////////////////////////////////////////
  234. //
  235. // RPC stub message
  236. //
  237. class RPC_STUB_MSG
  238.     {
  239.   public:
  240.     RPC_STUB_MSG (NdrUnmarshalStream*, NdrMarshalStream*, int =0);
  241.     ~RPC_STUB_MSG () {}
  242.     NdrUnmarshalStream* unmarshalStreamGet ();
  243.     NdrMarshalStream* marshalStreamGet ();
  244.     int channelIdGet ();
  245.     
  246.   private:
  247.     
  248.     NdrUnmarshalStream* m_pUnmshlStrm;
  249.     NdrMarshalStream* m_pMshlStrm;
  250.     int m_channelId;
  251.     };
  252. //////////////////////////////////////////////////////////////////////////
  253. //
  254. // Stub dispatch function type...
  255. //
  256. typedef HRESULT (STDMETHODCALLTYPE * PFN_ORPC_STUB) (IUnknown*, RPC_STUB_MSG&);
  257. ///////////////////////////////////////////////////////////////////////////
  258. //
  259. // Stub dispatch-table type...
  260. //
  261. struct VXDCOM_STUB_DISPTBL
  262.     {
  263.     unsigned int nFuncs;
  264.     const PFN_ORPC_STUB* funcs;
  265.     };
  266. //////////////////////////////////////////////////////////////////////////
  267. //
  268. // autoregistration helper class for proxy/stubs
  269. //
  270. class vxdcom_ps_autoreg
  271.     {
  272.   public:
  273.     vxdcom_ps_autoreg
  274.         (
  275.         const IID&                      iid,
  276.         const void*                     pv,
  277.         const VXDCOM_STUB_DISPTBL*      ps
  278.         );
  279.     };
  280. #define VXDCOM_PS_AUTOREGISTER(itf)     
  281.     static vxdcom_ps_autoreg            
  282.     _the_##itf##_ps_autoreg (IID_##itf, 
  283.         &itf##_vxproxy_vtbl,            
  284.         &itf##_vxstub_disptbl)
  285. //////////////////////////////////////////////////////////////////////////
  286. //
  287. // NDR Types
  288. //
  289. class NDRTYPES
  290.     {
  291.   public:
  292.     int arraySize;
  293.   public:
  294.     NDRTYPES (int hint=256);
  295.     ~NDRTYPES ();
  296.     NdrTypeDesc byte_t ();
  297.     NdrTypeDesc short_t ();
  298.     NdrTypeDesc long_t ();
  299.     NdrTypeDesc enum_t ();
  300.     NdrTypeDesc v1enum_t ();
  301.     NdrTypeDesc hyper_t ();
  302.     NdrTypeDesc float_t ();
  303.     NdrTypeDesc double_t ();
  304.     NdrTypeDesc bstr_t ();
  305.     NdrTypeDesc struct_t (int nelems, const NdrMemberInfo m[], int nSizeIs = -1);
  306.     NdrTypeDesc cstruct_t (int nelems, const NdrMemberInfo m[], int nSizeIs);
  307.     NdrTypeDesc array_t (const NdrTypeDesc& eltype, size_t elsz, size_t nelems=0);
  308.     NdrTypeDesc carray_t (const NdrTypeDesc& eltype, size_t elsz, size_t nelems=0);
  309.     NdrTypeDesc cvarray_t (const NdrTypeDesc& eltype, size_t elsz, size_t nelems=0, size_t nmax=0);
  310.     NdrTypeDesc interfaceptr_t (const IID&);
  311.     NdrTypeDesc variant_t ();
  312.     NdrTypeDesc cstring_t ();
  313.     NdrTypeDesc wstring_t ();
  314.     NdrTypeDesc pointer_t (const NdrTypeDesc& pointeeType);
  315.     NdrTypeDesc refptr_t (const NdrTypeDesc& pointeeType);
  316.     // map C types to IDL types
  317.     NdrTypeDesc void_t () { return byte_t (); }
  318.     NdrTypeDesc boolean_t () { return byte_t (); }
  319.     NdrTypeDesc char_t () { return byte_t (); }
  320.     NdrTypeDesc uchar_t () { return byte_t (); }
  321.     NdrTypeDesc ushort_t () { return short_t (); }
  322.     NdrTypeDesc ulong_t () { return long_t (); }
  323.     NdrTypeDesc uhyper_t () { return hyper_t (); }
  324.     NdrTypeDesc int_t () { return long_t (); }
  325.     NdrTypeDesc uint_t () { return long_t (); }
  326.     NdrTypeDesc hresult_t () { return long_t (); }
  327.     NdrTypeDesc longlong_t () { return hyper_t (); }
  328.     
  329.   private:
  330.     NdrTypeFactory* m_pFactory;
  331.     };
  332. HRESULT widlMarshal (void const*, NdrMarshalStream*, const NdrTypeDesc&);
  333. HRESULT widlUnmarshal (void*, NdrUnmarshalStream*, const NdrTypeDesc&);
  334. #endif