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

VxWorks

开发平台:

C/C++

  1. /* comBase.h - VxDCOM Base Definitions */
  2. /* Copyright (c) 1999 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 01l,21dec01,nel  Use offset for DCC instead of adjustment in COM_ADJUST_THIS.
  7. 01k,10dec01,dbs  diab build
  8. 01j,13jul01,dbs  allow multiple vtables to be defined in same file
  9. 01i,02jul01,dbs  fix typo in vtbl formats
  10. 01h,29jun01,dbs  fix vtbl format for T3 compilers
  11. 01g,27jun01,dbs  fix warnings from COM_VTABLE macro
  12. 01f,25jun01,dbs  rename vtbl macros to COM_VTBL_XXX
  13. 01e,22jun01,dbs  add WIDL_ADJUST_THIS macro
  14. 01d,20jun01,dbs  fix C build
  15. 01c,15jun01,dbs  fix vtbl layouts for known compilers
  16. 01b,19jul00,dbs  add basic C support
  17. 01a,21sep99,dbs  created from comLib.h
  18. */
  19. #ifndef __INCcomBase_h
  20. #define __INCcomBase_h
  21. /*
  22.  * Always include vxWorks.h for basic types - IDL will need to define
  23.  * those Win32-like types that aren't present in vxWorks.h but the
  24.  * base OS definitions should always be present.
  25.  */
  26. #include <vxWorks.h>
  27. /* Some common macros... */
  28. #define __RPC_FAR
  29. #define __RPC_USER
  30. #define __RPC_STUB
  31. #ifndef interface
  32. #define interface struct
  33. #endif
  34. #ifndef STDCALL
  35. #define STDCALL
  36. #endif
  37. #ifdef __cplusplus
  38. #define EXTERN_C                extern "C"
  39. #define STDMETHOD(method)       virtual HRESULT STDMETHODCALLTYPE method
  40. #define STDMETHOD_(type,method) virtual type STDMETHODCALLTYPE method
  41. #else
  42. #define EXTERN_C                extern
  43. #define STDMETHOD(method)       HRESULT STDMETHODCALLTYPE (*method)
  44. #define STDMETHOD_(type,method) type STDMETHODCALLTYPE (*method)
  45. #endif
  46. #define DECLSPEC_UUID(x)
  47. #define STDMETHODCALLTYPE       STDCALL
  48. #define STDMETHODIMP HRESULT STDMETHODCALLTYPE
  49. #define STDMETHODIMP_(type) type STDMETHODCALLTYPE
  50. #define __RPC_FAR
  51. #define __RPC_USER
  52. #define __RPC_STUB
  53. #define PRPC_MESSAGE void*
  54. /*
  55.  * WIDL_CPP_REF is defined as a true C++ reference when compiling for 
  56.  * C++, and as a pointer when compiling for plain C. This is used by
  57.  * WIDL when emitting typedefs, etc, generated from IDL.
  58.  */
  59. #ifdef __cplusplus
  60. #define WIDL_CPP_REF &
  61. #else
  62. #define WIDL_CPP_REF *
  63. #endif
  64. /**************************************************************************
  65. *
  66. *               -- VTable Layout --
  67. *
  68. * Whether we're using C++ or plain C, we must generate a vtbl that is
  69. * compatible with the C++ compiler for this architecture. Currently we
  70. * know about the two different versions of 'gcc' where pre-egcs
  71. * versions (as shipped with Tornado 2.0) use the old-style entries
  72. * with this-offsets held in the table itself, but later versions
  73. * (egcs/gcc2.95 and beyond) can use one DWORD per entry, and the
  74. * compiler supplies an inline 'thunk' code-fragment to adjust the
  75. * this-ptr. However, for VxWorks AE 1.x (T3.x) compilers, this feature
  76. * is not enabled, so the vtbl format is gcc2-offsets (i.e. the old
  77. * style).
  78. *
  79. * To define a vtable structure, the usage is:-
  80. *
  81. * typedef struct
  82. *    {
  83. *    COM_VTBL_BEGIN
  84. *    COM_VTBL_ENTRY (HRESULT, Method1, (int x));
  85. *    COM_VTBL_ENTRY (HRESULT, Method2, (long x));
  86. *    COM_VTBL_END
  87. *    } IFooVtbl;
  88. *
  89. * To build a const vtable the usage is:-
  90. *
  91. * COM_VTABLE(IFoo) IFoo_proxy_vtbl = {
  92. *    COM_VTBL_HEADER
  93. *    COM_VTBL_METHOD (&IFoo_Method1_proxy),
  94. *    COM_VTBL_METHOD (&IFoo_Method2_proxy)
  95. * };
  96. *
  97. * Note carefully the use of commas and semicolons at the end of
  98. * the lines.
  99. *
  100. ***************************************************************************
  101. *
  102. * Firstly, enumerate what the possible vtable formats are.
  103. *
  104. **************************************************************************/
  105. #define COM_VTBL_FORMAT_GCC2_OFFSET  1
  106. #define COM_VTBL_FORMAT_GCC2_THUNKS  2
  107. #define COM_VTBL_FORMAT_GCC3         3
  108. /**************************************************************************
  109. *
  110. * Now, we figure out which version of GCC and which platform its
  111. * running on, and then select the appropriate COM_VTBL_FORMAT_XXX
  112. * macro to enforce one (and *only* one) of the vtable formats, for
  113. * VxWorks (AE) targets. Host-builds (Linux, Solaris) must define the
  114. * macro in their repsective makefiles.
  115. *
  116. ***************************************************************************/
  117. #if !defined(unix)
  118. #ifdef __GNUC__
  119. # if (__GNUC__ == 2)
  120. #  define COM_VTBL_FORMAT COM_VTBL_FORMAT_GCC2_OFFSET
  121. # elif (__GNUC__ == 3)
  122. #  define COM_VTBL_FORMAT COM_VTBL_FORMAT_GCC3
  123. # endif
  124. #elif defined (__DCC__)
  125. #  define COM_VTBL_FORMAT COM_VTBL_FORMAT_GCC2_OFFSET
  126. #endif
  127. #endif
  128. /**************************************************************************
  129. *
  130. * Now we take the decision we have just made, and generate the
  131. * correct vtable layout, calling-macros, etc.
  132. *
  133. ***************************************************************************/
  134. #if (COM_VTBL_FORMAT == COM_VTBL_FORMAT_GCC2_OFFSET)
  135. /**************************************************************************
  136. *
  137. * This is the vtable format for gcc WITHOUT THUNKS. This format has an
  138. * adjustment to the 'this' pointer stored at each call-site (vtable
  139. * entry) and the caller has to adjust 'this' before dispatching the
  140. * call.
  141. *
  142. ***************************************************************************/
  143. #define COM_VTBL_BEGIN short __adj; short __pad; void* pRTTI;
  144. #define COM_VTBL_ENTRY(rt, fn, args) 
  145.     short __adj##fn; short __pad##fn; rt (*fn) args
  146. #define COM_VTBL_END
  147. #define COM_VTBL_HEADER 0,0,0,
  148. #define COM_VTBL_METHOD(fn) 0,0,fn
  149. #define COM_ADJUST_THIS(pThis) (void*)(((char*)pThis)+pThis->lpVtbl->__adjQueryInterface)
  150. #define COM_VTBL_SYMBOL com_vtbl_format_gcc2_offset
  151. #elif (COM_VTBL_FORMAT == COM_VTBL_FORMAT_GCC2_THUNKS)
  152. /**************************************************************************
  153. *
  154. * This is the vtable format for gcc2.x WITH THUNKS. This format simply
  155. * stores the pointer at each call-site and the compiler supplies
  156. * inline fragments of code to adjust the 'this' pointer (these are the
  157. * thunks) so each vtable entry is simply a function pointer.
  158. *
  159. ***************************************************************************/
  160. #define COM_VTBL_BEGIN short __adj; short __pad; void* pRTTI;
  161. #define COM_VTBL_ENTRY(rt, fn, args) rt (*fn) args
  162. #define COM_VTBL_END
  163. #define COM_VTBL_HEADER 0,0,0,
  164. #define COM_VTBL_METHOD(fn) fn
  165. #define COM_ADJUST_THIS(pThis) pThis
  166. #define COM_VTBL_SYMBOL com_vtbl_format_gcc2_thunks
  167. #elif (COM_VTBL_FORMAT == COM_VTBL_FORMAT_GCC3)
  168. /**************************************************************************
  169. *
  170. * This is the vtable format for gcc3. This format is the same as the
  171. * 'with thunks' format, but there is no 'header' i.e. the 'this'
  172. * pointer offset is not stored in the vtable at all.
  173. *
  174. ***************************************************************************/
  175. #define COM_VTBL_BEGIN
  176. #define COM_VTBL_ENTRY(rt, fn, args) rt (*fn) args
  177.  
  178. #define COM_VTBL_END
  179. #define COM_VTBL_HEADER
  180. #define COM_VTBL_METHOD(fn) fn
  181. #define COM_ADJUST_THIS(pThis) pThis
  182. #define COM_VTBL_SYMBOL com_vtbl_format_gcc3
  183. #else
  184. #error Unknown GCC vtable format - unable to determine host/compiler.
  185. #endif
  186. #define DECLARE_COM_VTBL_SYMBOL_HERE   int COM_VTBL_SYMBOL = 0;
  187. #define COM_VTABLE(itf)                         
  188.     extern int COM_VTBL_SYMBOL;                 
  189.     static void widlref_##itf(int x)            
  190.         { widlref_##itf (x+COM_VTBL_SYMBOL); }  
  191.     const itf##Vtbl
  192. #endif /* __INCcomBase_h */