1
0

dispatch.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. #pragma once
  2. //#include <bfc/platform/platform.h>
  3. #include "bfc/platform/types.h"
  4. #include "bfc/platform/guid.h"
  5. #ifdef WIN32
  6. #ifndef NOVTABLE
  7. #define NOVTABLE __declspec(novtable)
  8. #endif
  9. #else
  10. #define NOVTABLE
  11. #endif
  12. class DispatchableCallback;
  13. #pragma warning(disable: 4786)
  14. #pragma warning(disable: 4275)
  15. #pragma warning(disable: 4100)
  16. enum
  17. {
  18. DISPATCH_SUCCESS = 0,
  19. DISPATCH_FAILURE = 1,
  20. };
  21. class NOVTABLE Dispatchable
  22. {
  23. public:
  24. // // fake virtual destructor
  25. // void destruct() { _voidcall(DESTRUCT); }
  26. // this is virtual so it is visible across modules
  27. virtual int _dispatch( int msg, void *retval, void **params = 0, int nparam = 0 ) = 0;
  28. /* added 22 May 2007. these aren't used yet. To be used in the future
  29. in the meantime, don't use negative numbers for your msg values */
  30. int AddRef();
  31. int Release();
  32. int QueryInterface( GUID interface_guid, void **object );
  33. enum
  34. {
  35. ADDREF = -1,
  36. RELEASE = -2,
  37. QUERYINTERFACE = -3,
  38. };
  39. protected:
  40. // // protected real destructor
  41. // ~Dispatchable() {}
  42. // helper templates to implement client-side methods
  43. int _voidcall( int msg )
  44. {
  45. return _dispatch( msg, 0 );
  46. }
  47. template<class PARAM1>
  48. int _voidcall( int msg, PARAM1 param1 )
  49. {
  50. void *params[ 1 ] = { &param1 };
  51. return _dispatch( msg, 0, params, 1 );
  52. }
  53. template<class PARAM1, class PARAM2>
  54. int _voidcall( int msg, PARAM1 param1, PARAM2 param2 )
  55. {
  56. void *params[ 2 ] = { &param1, &param2 };
  57. return _dispatch( msg, 0, params, 2 );
  58. }
  59. template<class PARAM1, class PARAM2, class PARAM3>
  60. int _voidcall( int msg, PARAM1 param1, PARAM2 param2, PARAM3 param3 )
  61. {
  62. void *params[ 3 ] = { &param1, &param2, &param3 };
  63. return _dispatch( msg, 0, params, 3 );
  64. }
  65. template<class PARAM1, class PARAM2, class PARAM3, class PARAM4>
  66. int _voidcall( int msg, PARAM1 param1, PARAM2 param2, PARAM3 param3, PARAM4 param4 )
  67. {
  68. void *params[ 4 ] = { &param1, &param2, &param3, &param4 };
  69. return _dispatch( msg, 0, params, 4 );
  70. }
  71. template<class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5>
  72. int _voidcall( int msg, PARAM1 param1, PARAM2 param2, PARAM3 param3, PARAM4 param4, PARAM5 param5 )
  73. {
  74. // void *params[4] = { &param1, &param2, &param3, &param4, &param5 }; // mig found another bug
  75. void *params[ 5 ] = { &param1, &param2, &param3, &param4, &param5 };
  76. return _dispatch( msg, 0, params, 5 );
  77. }
  78. template<class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6>
  79. int _voidcall( int msg, PARAM1 param1, PARAM2 param2, PARAM3 param3, PARAM4 param4, PARAM5 param5, PARAM6 param6 )
  80. {
  81. // void *params[4] = { &param1, &param2, &param3, &param4, &param5, &param6 }; // mig found another bug
  82. void *params[ 6 ] = { &param1, &param2, &param3, &param4, &param5, &param6 };
  83. return _dispatch( msg, 0, params, 6 );
  84. }
  85. template<class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6, class PARAM7>
  86. int _voidcall( int msg, PARAM1 param1, PARAM2 param2, PARAM3 param3, PARAM4 param4, PARAM5 param5, PARAM6 param6, PARAM7 param7 )
  87. {
  88. void *params[ 7 ] = { &param1, &param2, &param3, &param4, &param5, &param6 , &param7 };
  89. return _dispatch( msg, 0, params, 7 );
  90. }
  91. template<class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6, class PARAM7, class PARAM8>
  92. int _voidcall( int msg, PARAM1 param1, PARAM2 param2, PARAM3 param3, PARAM4 param4, PARAM5 param5, PARAM6 param6, PARAM7 param7, PARAM8 param8 )
  93. {
  94. void *params[ 8 ] = { &param1, &param2, &param3, &param4, &param5, &param6 , &param7 , &param8 };
  95. return _dispatch( msg, 0, params, 8 );
  96. }
  97. template<class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6, class PARAM7, class PARAM8, class PARAM9>
  98. int _voidcall( int msg, PARAM1 param1, PARAM2 param2, PARAM3 param3, PARAM4 param4, PARAM5 param5, PARAM6 param6, PARAM7 param7, PARAM8 param8, PARAM9 param9 )
  99. {
  100. void *params[ 9 ] = { &param1, &param2, &param3, &param4, &param5, &param6 , &param7 , &param8 , &param9 };
  101. return _dispatch( msg, 0, params, 9 );
  102. }
  103. template<class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6, class PARAM7, class PARAM8, class PARAM9, class PARAM10>
  104. int _voidcall( int msg, PARAM1 param1, PARAM2 param2, PARAM3 param3, PARAM4 param4, PARAM5 param5, PARAM6 param6, PARAM7 param7, PARAM8 param8, PARAM9 param9, PARAM10 param10 )
  105. {
  106. void *params[ 10 ] = { &param1, &param2, &param3, &param4, &param5, &param6 , &param7 , &param8 , &param9 , &param10 };
  107. return _dispatch( msg, 0, params, 10 );
  108. }
  109. template<class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6, class PARAM7, class PARAM8, class PARAM9, class PARAM10, class PARAM11, class PARAM12, class PARAM13, class PARAM14>
  110. int _voidcall( int msg, PARAM1 param1, PARAM2 param2, PARAM3 param3, PARAM4 param4, PARAM5 param5, PARAM6 param6, PARAM7 param7, PARAM8 param8, PARAM9 param9, PARAM10 param10, PARAM11 param11, PARAM12 param12, PARAM13 param13, PARAM14 param14 )
  111. {
  112. void *params[ 14 ] = { &param1, &param2, &param3, &param4, &param5, &param6 , &param7 , &param8 , &param9 , &param10 , &param11 , &param12 , &param13 , &param14 };
  113. return _dispatch( msg, 0, params, 14 );
  114. }
  115. template<class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6, class PARAM7, class PARAM8, class PARAM9, class PARAM10, class PARAM11, class PARAM12, class PARAM13, class PARAM14, class PARAM15, class PARAM16>
  116. int _voidcall( int msg, PARAM1 param1, PARAM2 param2, PARAM3 param3, PARAM4 param4, PARAM5 param5, PARAM6 param6, PARAM7 param7, PARAM8 param8, PARAM9 param9, PARAM10 param10, PARAM11 param11, PARAM12 param12, PARAM13 param13, PARAM14 param14, PARAM15 param15, PARAM16 param16 )
  117. {
  118. void *params[ 16 ] = { &param1, &param2, &param3, &param4, &param5, &param6 , &param7 , &param8 , &param9 , &param10 , &param11 , &param12 , &param13 , &param14 , &param15 , &param16 };
  119. return _dispatch( msg, 0, params, 16 );
  120. }
  121. template<class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6, class PARAM7, class PARAM8, class PARAM9, class PARAM10, class PARAM11, class PARAM12, class PARAM13, class PARAM14, class PARAM15, class PARAM16, class PARAM17>
  122. int _voidcall( int msg, PARAM1 param1, PARAM2 param2, PARAM3 param3, PARAM4 param4, PARAM5 param5, PARAM6 param6, PARAM7 param7, PARAM8 param8, PARAM9 param9, PARAM10 param10, PARAM11 param11, PARAM12 param12, PARAM13 param13, PARAM14 param14, PARAM15 param15, PARAM16 param16, PARAM17 param17 )
  123. {
  124. void *params[ 17 ] = { &param1, &param2, &param3, &param4, &param5, &param6 , &param7 , &param8 , &param9 , &param10 , &param11 , &param12 , &param13 , &param14 , &param15 , &param16 , &param17 };
  125. return _dispatch( msg, 0, params, 17 );
  126. }
  127. template<class RETURN_TYPE>
  128. RETURN_TYPE _call( int msg, RETURN_TYPE defval )
  129. {
  130. RETURN_TYPE retval;
  131. if ( _dispatch( msg, &retval ) ) return retval;
  132. return defval;
  133. }
  134. template<class RETURN_TYPE, class PARAM1>
  135. RETURN_TYPE _call( int msg, RETURN_TYPE defval, PARAM1 param1 )
  136. {
  137. void *params[ 1 ] = { &param1 };
  138. RETURN_TYPE retval;
  139. if ( _dispatch( msg, &retval, params, 1 ) ) return retval;
  140. return defval;
  141. }
  142. template<class RETURN_TYPE, class PARAM1, class PARAM2>
  143. RETURN_TYPE _call( int msg, RETURN_TYPE defval, PARAM1 param1, PARAM2 param2 )
  144. {
  145. void *params[ 2 ] = { &param1, &param2 };
  146. RETURN_TYPE retval;
  147. if ( _dispatch( msg, &retval, params, 2 ) ) return retval;
  148. return defval;
  149. }
  150. template<class RETURN_TYPE, class PARAM1, class PARAM2, class PARAM3>
  151. RETURN_TYPE _call( int msg, RETURN_TYPE defval, PARAM1 param1, PARAM2 param2, PARAM3 param3 )
  152. {
  153. void *params[ 3 ] = { &param1, &param2, &param3 };
  154. RETURN_TYPE retval;
  155. if ( _dispatch( msg, &retval, params, 3 ) ) return retval;
  156. return defval;
  157. }
  158. template<class RETURN_TYPE, class PARAM1, class PARAM2, class PARAM3, class PARAM4>
  159. RETURN_TYPE _call( int msg, RETURN_TYPE defval, PARAM1 param1, PARAM2 param2, PARAM3 param3, PARAM4 param4 )
  160. {
  161. void *params[ 4 ] = { &param1, &param2, &param3, &param4 };
  162. RETURN_TYPE retval;
  163. if ( _dispatch( msg, &retval, params, 4 ) ) return retval;
  164. return defval;
  165. }
  166. template<class RETURN_TYPE, class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5>
  167. RETURN_TYPE _call( int msg, RETURN_TYPE defval, PARAM1 param1, PARAM2 param2, PARAM3 param3, PARAM4 param4, PARAM5 param5 )
  168. {
  169. void *params[ 5 ] = { &param1, &param2, &param3, &param4, &param5 };
  170. RETURN_TYPE retval;
  171. if ( _dispatch( msg, &retval, params, 5 ) ) return retval;
  172. return defval;
  173. }
  174. template<class RETURN_TYPE, class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6>
  175. RETURN_TYPE _call( int msg, RETURN_TYPE defval, PARAM1 param1, PARAM2 param2, PARAM3 param3, PARAM4 param4, PARAM5 param5, PARAM6 param6 )
  176. {
  177. void *params[ 6 ] = { &param1, &param2, &param3, &param4, &param5, &param6 };
  178. RETURN_TYPE retval;
  179. if ( _dispatch( msg, &retval, params, 6 ) ) return retval;
  180. return defval;
  181. }
  182. template<class RETURN_TYPE, class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6, class PARAM7>
  183. RETURN_TYPE _call( int msg, RETURN_TYPE defval, PARAM1 param1, PARAM2 param2, PARAM3 param3, PARAM4 param4, PARAM5 param5, PARAM6 param6, PARAM7 param7 )
  184. {
  185. void *params[ 7 ] = { &param1, &param2, &param3, &param4, &param5, &param6, &param7 };
  186. RETURN_TYPE retval;
  187. if ( _dispatch( msg, &retval, params, 7 ) ) return retval;
  188. return defval;
  189. }
  190. template<class RETURN_TYPE, class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6, class PARAM7, class PARAM8>
  191. RETURN_TYPE _call( int msg, RETURN_TYPE defval, PARAM1 param1, PARAM2 param2, PARAM3 param3, PARAM4 param4, PARAM5 param5, PARAM6 param6, PARAM7 param7, PARAM8 param8 )
  192. {
  193. void *params[ 8 ] = { &param1, &param2, &param3, &param4, &param5, &param6, &param7, &param8 };
  194. RETURN_TYPE retval;
  195. if ( _dispatch( msg, &retval, params, 8 ) ) return retval;
  196. return defval;
  197. }
  198. template<class RETURN_TYPE, class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6, class PARAM7, class PARAM8, class PARAM9>
  199. RETURN_TYPE _call( int msg, RETURN_TYPE defval, PARAM1 param1, PARAM2 param2, PARAM3 param3, PARAM4 param4, PARAM5 param5, PARAM6 param6, PARAM7 param7, PARAM8 param8, PARAM9 param9 )
  200. {
  201. void *params[ 9 ] = { &param1, &param2, &param3, &param4, &param5, &param6, &param7, &param8, &param9 };
  202. RETURN_TYPE retval;
  203. if ( _dispatch( msg, &retval, params, 9 ) ) return retval;
  204. return defval;
  205. }
  206. template<class RETURN_TYPE, class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6, class PARAM7, class PARAM8, class PARAM9, class PARAM10>
  207. RETURN_TYPE _call( int msg, RETURN_TYPE defval, PARAM1 param1, PARAM2 param2, PARAM3 param3, PARAM4 param4, PARAM5 param5, PARAM6 param6, PARAM7 param7, PARAM8 param8, PARAM9 param9, PARAM10 param10 )
  208. {
  209. void *params[ 10 ] = { &param1, &param2, &param3, &param4, &param5, &param6, &param7, &param8, &param9, &param10 };
  210. RETURN_TYPE retval;
  211. if ( _dispatch( msg, &retval, params, 10 ) ) return retval;
  212. return defval;
  213. }
  214. template <class CASTNAME, class CLASSNAME, class RETVAL>
  215. void cb( RETVAL( CLASSNAME:: *fn )( ), void *retval, void **params )
  216. {
  217. *static_cast<RETVAL *>( retval ) = ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( );
  218. }
  219. template <class CASTNAME, class CLASSNAME>
  220. void vcb( void ( CLASSNAME:: *fn )( ), void *retval, void **params )
  221. {
  222. ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( );
  223. }
  224. template <class CASTNAME, class CLASSNAME, class RETVAL, class PARAM1>
  225. void cb( RETVAL( CLASSNAME:: *fn )( PARAM1 ), void *retval, void **params )
  226. {
  227. PARAM1 *p1 = static_cast<PARAM1 *>( params[ 0 ] );
  228. *static_cast<RETVAL *>( retval ) = ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( *p1 );
  229. }
  230. template <class CASTNAME, class CLASSNAME, class PARAM1>
  231. void vcb( void ( CLASSNAME:: *fn )( PARAM1 ), void *retval, void **params )
  232. {
  233. PARAM1 *p1 = static_cast<PARAM1 *>( params[ 0 ] );
  234. ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( *p1 );
  235. }
  236. template <class CASTNAME, class CLASSNAME, class PARAM1, class PARAM2>
  237. void vcb( void ( CLASSNAME:: *fn )( PARAM1, PARAM2 ), void *retval, void **params )
  238. {
  239. PARAM1 *p1 = static_cast<PARAM1 *>( params[ 0 ] );
  240. PARAM2 *p2 = static_cast<PARAM2 *>( params[ 1 ] );
  241. ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( *p1, *p2 );
  242. }
  243. template <class CASTNAME, class CLASSNAME, class RETVAL, class PARAM1, class PARAM2>
  244. void cb( RETVAL( CLASSNAME:: *fn )( PARAM1, PARAM2 ), void *retval, void **params )
  245. {
  246. PARAM1 *p1 = static_cast<PARAM1 *>( params[ 0 ] );
  247. PARAM2 *p2 = static_cast<PARAM2 *>( params[ 1 ] );
  248. *static_cast<RETVAL *>( retval ) = ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( *p1, *p2 );
  249. }
  250. // 3 params
  251. template <class CASTNAME, class CLASSNAME, class PARAM1, class PARAM2, class PARAM3>
  252. void vcb( void ( CLASSNAME:: *fn )( PARAM1, PARAM2, PARAM3 ), void *retval, void **params )
  253. {
  254. PARAM1 *p1 = static_cast<PARAM1 *>( params[ 0 ] );
  255. PARAM2 *p2 = static_cast<PARAM2 *>( params[ 1 ] );
  256. PARAM3 *p3 = static_cast<PARAM3 *>( params[ 2 ] );
  257. ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( *p1, *p2, *p3 );
  258. }
  259. template <class CASTNAME, class CLASSNAME, class RETVAL, class PARAM1, class PARAM2, class PARAM3>
  260. void cb( RETVAL( CLASSNAME:: *fn )( PARAM1, PARAM2, PARAM3 ), void *retval, void **params )
  261. {
  262. PARAM1 *p1 = static_cast<PARAM1 *>( params[ 0 ] );
  263. PARAM2 *p2 = static_cast<PARAM2 *>( params[ 1 ] );
  264. PARAM3 *p3 = static_cast<PARAM3 *>( params[ 2 ] );
  265. *static_cast<RETVAL *>( retval ) = ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( *p1, *p2, *p3 );
  266. }
  267. // 4 params
  268. template <class CASTNAME, class CLASSNAME, class PARAM1, class PARAM2, class PARAM3, class PARAM4>
  269. void vcb( void ( CLASSNAME:: *fn )( PARAM1, PARAM2, PARAM3, PARAM4 ), void *retval, void **params )
  270. {
  271. PARAM1 *p1 = static_cast<PARAM1 *>( params[ 0 ] );
  272. PARAM2 *p2 = static_cast<PARAM2 *>( params[ 1 ] );
  273. PARAM3 *p3 = static_cast<PARAM3 *>( params[ 2 ] );
  274. PARAM4 *p4 = static_cast<PARAM4 *>( params[ 3 ] );
  275. ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( *p1, *p2, *p3, *p4 );
  276. }
  277. template <class CASTNAME, class CLASSNAME, class RETVAL, class PARAM1, class PARAM2, class PARAM3, class PARAM4>
  278. void cb( RETVAL( CLASSNAME:: *fn )( PARAM1, PARAM2, PARAM3, PARAM4 ), void *retval, void **params )
  279. {
  280. PARAM1 *p1 = static_cast<PARAM1 *>( params[ 0 ] );
  281. PARAM2 *p2 = static_cast<PARAM2 *>( params[ 1 ] );
  282. PARAM3 *p3 = static_cast<PARAM3 *>( params[ 2 ] );
  283. PARAM4 *p4 = static_cast<PARAM4 *>( params[ 3 ] );
  284. *static_cast<RETVAL *>( retval ) = ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( *p1, *p2, *p3, *p4 );
  285. }
  286. // 5 params
  287. template <class CASTNAME, class CLASSNAME, class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5>
  288. void vcb( void ( CLASSNAME:: *fn )( PARAM1, PARAM2, PARAM3, PARAM4, PARAM5 ), void *retval, void **params )
  289. {
  290. PARAM1 *p1 = static_cast<PARAM1 *>( params[ 0 ] );
  291. PARAM2 *p2 = static_cast<PARAM2 *>( params[ 1 ] );
  292. PARAM3 *p3 = static_cast<PARAM3 *>( params[ 2 ] );
  293. PARAM4 *p4 = static_cast<PARAM4 *>( params[ 3 ] );
  294. PARAM5 *p5 = static_cast<PARAM5 *>( params[ 4 ] );
  295. ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( *p1, *p2, *p3, *p4, *p5 );
  296. }
  297. template <class CASTNAME, class CLASSNAME, class RETVAL, class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5>
  298. void cb( RETVAL( CLASSNAME:: *fn )( PARAM1, PARAM2, PARAM3, PARAM4, PARAM5 ), void *retval, void **params )
  299. {
  300. PARAM1 *p1 = static_cast<PARAM1 *>( params[ 0 ] );
  301. PARAM2 *p2 = static_cast<PARAM2 *>( params[ 1 ] );
  302. PARAM3 *p3 = static_cast<PARAM3 *>( params[ 2 ] );
  303. PARAM4 *p4 = static_cast<PARAM4 *>( params[ 3 ] );
  304. PARAM5 *p5 = static_cast<PARAM5 *>( params[ 4 ] );
  305. *static_cast<RETVAL *>( retval ) = ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( *p1, *p2, *p3, *p4, *p5 );
  306. }
  307. // 6 params
  308. template <class CASTNAME, class CLASSNAME, class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6>
  309. void vcb( void ( CLASSNAME:: *fn )( PARAM1, PARAM2, PARAM3, PARAM4, PARAM5, PARAM6 ), void *retval, void **params )
  310. {
  311. PARAM1 *p1 = static_cast<PARAM1 *>( params[ 0 ] );
  312. PARAM2 *p2 = static_cast<PARAM2 *>( params[ 1 ] );
  313. PARAM3 *p3 = static_cast<PARAM3 *>( params[ 2 ] );
  314. PARAM4 *p4 = static_cast<PARAM4 *>( params[ 3 ] );
  315. PARAM5 *p5 = static_cast<PARAM5 *>( params[ 4 ] );
  316. PARAM6 *p6 = static_cast<PARAM6 *>( params[ 5 ] );
  317. ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( *p1, *p2, *p3, *p4, *p5, *p6 );
  318. }
  319. template <class CASTNAME, class CLASSNAME, class RETVAL, class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6>
  320. void cb( RETVAL( CLASSNAME:: *fn )( PARAM1, PARAM2, PARAM3, PARAM4, PARAM5, PARAM6 ), void *retval, void **params )
  321. {
  322. PARAM1 *p1 = static_cast<PARAM1 *>( params[ 0 ] );
  323. PARAM2 *p2 = static_cast<PARAM2 *>( params[ 1 ] );
  324. PARAM3 *p3 = static_cast<PARAM3 *>( params[ 2 ] );
  325. PARAM4 *p4 = static_cast<PARAM4 *>( params[ 3 ] );
  326. PARAM5 *p5 = static_cast<PARAM5 *>( params[ 4 ] );
  327. PARAM6 *p6 = static_cast<PARAM6 *>( params[ 5 ] );
  328. *static_cast<RETVAL *>( retval ) = ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( *p1, *p2, *p3, *p4, *p5, *p6 );
  329. }
  330. // 7 params
  331. template <class CASTNAME, class CLASSNAME, class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6, class PARAM7>
  332. void vcb( void ( CLASSNAME:: *fn )( PARAM1, PARAM2, PARAM3, PARAM4, PARAM5, PARAM6, PARAM7 ), void *retval, void **params )
  333. {
  334. PARAM1 *p1 = static_cast<PARAM1 *>( params[ 0 ] );
  335. PARAM2 *p2 = static_cast<PARAM2 *>( params[ 1 ] );
  336. PARAM3 *p3 = static_cast<PARAM3 *>( params[ 2 ] );
  337. PARAM4 *p4 = static_cast<PARAM4 *>( params[ 3 ] );
  338. PARAM5 *p5 = static_cast<PARAM5 *>( params[ 4 ] );
  339. PARAM6 *p6 = static_cast<PARAM6 *>( params[ 5 ] );
  340. PARAM7 *p7 = static_cast<PARAM7 *>( params[ 6 ] );
  341. ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( *p1, *p2, *p3, *p4, *p5, *p6, *p7 );
  342. }
  343. template <class CASTNAME, class CLASSNAME, class RETVAL, class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6, class PARAM7>
  344. void cb( RETVAL( CLASSNAME:: *fn )( PARAM1, PARAM2, PARAM3, PARAM4, PARAM5, PARAM6, PARAM7 ), void *retval, void **params )
  345. {
  346. PARAM1 *p1 = static_cast<PARAM1 *>( params[ 0 ] );
  347. PARAM2 *p2 = static_cast<PARAM2 *>( params[ 1 ] );
  348. PARAM3 *p3 = static_cast<PARAM3 *>( params[ 2 ] );
  349. PARAM4 *p4 = static_cast<PARAM4 *>( params[ 3 ] );
  350. PARAM5 *p5 = static_cast<PARAM5 *>( params[ 4 ] );
  351. PARAM6 *p6 = static_cast<PARAM6 *>( params[ 5 ] );
  352. PARAM7 *p7 = static_cast<PARAM7 *>( params[ 6 ] );
  353. *static_cast<RETVAL *>( retval ) = ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( *p1, *p2, *p3, *p4, *p5, *p6, *p7 );
  354. }
  355. // 8 params
  356. template <class CASTNAME, class CLASSNAME, class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6, class PARAM7, class PARAM8>
  357. void vcb( void ( CLASSNAME:: *fn )( PARAM1, PARAM2, PARAM3, PARAM4, PARAM5, PARAM6, PARAM7, PARAM8 ), void *retval, void **params )
  358. {
  359. PARAM1 *p1 = static_cast<PARAM1 *>( params[ 0 ] );
  360. PARAM2 *p2 = static_cast<PARAM2 *>( params[ 1 ] );
  361. PARAM3 *p3 = static_cast<PARAM3 *>( params[ 2 ] );
  362. PARAM4 *p4 = static_cast<PARAM4 *>( params[ 3 ] );
  363. PARAM5 *p5 = static_cast<PARAM5 *>( params[ 4 ] );
  364. PARAM6 *p6 = static_cast<PARAM6 *>( params[ 5 ] );
  365. PARAM7 *p7 = static_cast<PARAM7 *>( params[ 6 ] );
  366. PARAM8 *p8 = static_cast<PARAM8 *>( params[ 7 ] );
  367. ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8 );
  368. }
  369. template <class CASTNAME, class CLASSNAME, class RETVAL, class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6, class PARAM7, class PARAM8>
  370. void cb( RETVAL( CLASSNAME:: *fn )( PARAM1, PARAM2, PARAM3, PARAM4, PARAM5, PARAM6, PARAM7, PARAM8 ), void *retval, void **params )
  371. {
  372. PARAM1 *p1 = static_cast<PARAM1 *>( params[ 0 ] );
  373. PARAM2 *p2 = static_cast<PARAM2 *>( params[ 1 ] );
  374. PARAM3 *p3 = static_cast<PARAM3 *>( params[ 2 ] );
  375. PARAM4 *p4 = static_cast<PARAM4 *>( params[ 3 ] );
  376. PARAM5 *p5 = static_cast<PARAM5 *>( params[ 4 ] );
  377. PARAM6 *p6 = static_cast<PARAM6 *>( params[ 5 ] );
  378. PARAM7 *p7 = static_cast<PARAM7 *>( params[ 6 ] );
  379. PARAM8 *p8 = static_cast<PARAM8 *>( params[ 7 ] );
  380. *static_cast<RETVAL *>( retval ) = ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8 );
  381. }
  382. // 9 params
  383. template <class CASTNAME, class CLASSNAME, class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6, class PARAM7, class PARAM8, class PARAM9>
  384. void vcb( void ( CLASSNAME:: *fn )( PARAM1, PARAM2, PARAM3, PARAM4, PARAM5, PARAM6, PARAM7, PARAM8, PARAM9 ), void *retval, void **params )
  385. {
  386. PARAM1 *p1 = static_cast<PARAM1 *>( params[ 0 ] );
  387. PARAM2 *p2 = static_cast<PARAM2 *>( params[ 1 ] );
  388. PARAM3 *p3 = static_cast<PARAM3 *>( params[ 2 ] );
  389. PARAM4 *p4 = static_cast<PARAM4 *>( params[ 3 ] );
  390. PARAM5 *p5 = static_cast<PARAM5 *>( params[ 4 ] );
  391. PARAM6 *p6 = static_cast<PARAM6 *>( params[ 5 ] );
  392. PARAM7 *p7 = static_cast<PARAM7 *>( params[ 6 ] );
  393. PARAM8 *p8 = static_cast<PARAM8 *>( params[ 7 ] );
  394. PARAM9 *p9 = static_cast<PARAM9 *>( params[ 8 ] );
  395. ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9 );
  396. }
  397. template <class CASTNAME, class CLASSNAME, class RETVAL, class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6, class PARAM7, class PARAM8, class PARAM9>
  398. void cb( RETVAL( CLASSNAME:: *fn )( PARAM1, PARAM2, PARAM3, PARAM4, PARAM5, PARAM6, PARAM7, PARAM8, PARAM9 ), void *retval, void **params )
  399. {
  400. PARAM1 *p1 = static_cast<PARAM1 *>( params[ 0 ] );
  401. PARAM2 *p2 = static_cast<PARAM2 *>( params[ 1 ] );
  402. PARAM3 *p3 = static_cast<PARAM3 *>( params[ 2 ] );
  403. PARAM4 *p4 = static_cast<PARAM4 *>( params[ 3 ] );
  404. PARAM5 *p5 = static_cast<PARAM5 *>( params[ 4 ] );
  405. PARAM6 *p6 = static_cast<PARAM6 *>( params[ 5 ] );
  406. PARAM7 *p7 = static_cast<PARAM7 *>( params[ 6 ] );
  407. PARAM8 *p8 = static_cast<PARAM8 *>( params[ 7 ] );
  408. PARAM9 *p9 = static_cast<PARAM9 *>( params[ 8 ] );
  409. *static_cast<RETVAL *>( retval ) = ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9 );
  410. }
  411. // 10 params
  412. template <class CASTNAME, class CLASSNAME, class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6, class PARAM7, class PARAM8, class PARAM9, class PARAM10>
  413. void vcb( void ( CLASSNAME:: *fn )( PARAM1, PARAM2, PARAM3, PARAM4, PARAM5, PARAM6, PARAM7, PARAM8, PARAM9, PARAM10 ), void *retval, void **params )
  414. {
  415. PARAM1 *p1 = static_cast<PARAM1 *>( params[ 0 ] );
  416. PARAM2 *p2 = static_cast<PARAM2 *>( params[ 1 ] );
  417. PARAM3 *p3 = static_cast<PARAM3 *>( params[ 2 ] );
  418. PARAM4 *p4 = static_cast<PARAM4 *>( params[ 3 ] );
  419. PARAM5 *p5 = static_cast<PARAM5 *>( params[ 4 ] );
  420. PARAM6 *p6 = static_cast<PARAM6 *>( params[ 5 ] );
  421. PARAM7 *p7 = static_cast<PARAM7 *>( params[ 6 ] );
  422. PARAM8 *p8 = static_cast<PARAM8 *>( params[ 7 ] );
  423. PARAM9 *p9 = static_cast<PARAM9 *>( params[ 8 ] );
  424. PARAM10 *p10 = static_cast<PARAM10 *>( params[ 9 ] );
  425. ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9, *p10 );
  426. }
  427. template <class CASTNAME, class CLASSNAME, class RETVAL, class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6, class PARAM7, class PARAM8, class PARAM9, class PARAM10>
  428. void cb( RETVAL( CLASSNAME:: *fn )( PARAM1, PARAM2, PARAM3, PARAM4, PARAM5, PARAM6, PARAM7, PARAM8, PARAM9, PARAM10 ), void *retval, void **params )
  429. {
  430. PARAM1 *p1 = static_cast<PARAM1 *>( params[ 0 ] );
  431. PARAM2 *p2 = static_cast<PARAM2 *>( params[ 1 ] );
  432. PARAM3 *p3 = static_cast<PARAM3 *>( params[ 2 ] );
  433. PARAM4 *p4 = static_cast<PARAM4 *>( params[ 3 ] );
  434. PARAM5 *p5 = static_cast<PARAM5 *>( params[ 4 ] );
  435. PARAM6 *p6 = static_cast<PARAM6 *>( params[ 5 ] );
  436. PARAM7 *p7 = static_cast<PARAM7 *>( params[ 6 ] );
  437. PARAM8 *p8 = static_cast<PARAM8 *>( params[ 7 ] );
  438. PARAM9 *p9 = static_cast<PARAM9 *>( params[ 8 ] );
  439. PARAM10 *p10 = static_cast<PARAM10 *>( params[ 9 ] );
  440. *static_cast<RETVAL *>( retval ) = ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9, *p10 );
  441. }
  442. // 14 params
  443. template <class CASTNAME, class CLASSNAME, class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6, class PARAM7, class PARAM8, class PARAM9, class PARAM10, class PARAM11, class PARAM12, class PARAM13, class PARAM14>
  444. void vcb( void ( CLASSNAME:: *fn )( PARAM1, PARAM2, PARAM3, PARAM4, PARAM5, PARAM6, PARAM7, PARAM8, PARAM9, PARAM10, PARAM11, PARAM12, PARAM13, PARAM14 ), void *retval, void **params )
  445. {
  446. PARAM1 *p1 = static_cast<PARAM1 *>( params[ 0 ] );
  447. PARAM2 *p2 = static_cast<PARAM2 *>( params[ 1 ] );
  448. PARAM3 *p3 = static_cast<PARAM3 *>( params[ 2 ] );
  449. PARAM4 *p4 = static_cast<PARAM4 *>( params[ 3 ] );
  450. PARAM5 *p5 = static_cast<PARAM5 *>( params[ 4 ] );
  451. PARAM6 *p6 = static_cast<PARAM6 *>( params[ 5 ] );
  452. PARAM7 *p7 = static_cast<PARAM7 *>( params[ 6 ] );
  453. PARAM8 *p8 = static_cast<PARAM8 *>( params[ 7 ] );
  454. PARAM9 *p9 = static_cast<PARAM9 *>( params[ 8 ] );
  455. PARAM10 *p10 = static_cast<PARAM10 *>( params[ 9 ] );
  456. PARAM11 *p11 = static_cast<PARAM11 *>( params[ 10 ] );
  457. PARAM12 *p12 = static_cast<PARAM12 *>( params[ 11 ] );
  458. PARAM13 *p13 = static_cast<PARAM13 *>( params[ 12 ] );
  459. PARAM14 *p14 = static_cast<PARAM14 *>( params[ 13 ] );
  460. ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9, *p10, *p11, *p12, *p13, *p14 );
  461. }
  462. // 16 params
  463. template <class CASTNAME, class CLASSNAME, class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6, class PARAM7, class PARAM8, class PARAM9, class PARAM10, class PARAM11, class PARAM12, class PARAM13, class PARAM14, class PARAM15, class PARAM16>
  464. void vcb( void ( CLASSNAME:: *fn )( PARAM1, PARAM2, PARAM3, PARAM4, PARAM5, PARAM6, PARAM7, PARAM8, PARAM9, PARAM10, PARAM11, PARAM12, PARAM13, PARAM14, PARAM15, PARAM16 ), void *retval, void **params )
  465. {
  466. PARAM1 *p1 = static_cast<PARAM1 *>( params[ 0 ] );
  467. PARAM2 *p2 = static_cast<PARAM2 *>( params[ 1 ] );
  468. PARAM3 *p3 = static_cast<PARAM3 *>( params[ 2 ] );
  469. PARAM4 *p4 = static_cast<PARAM4 *>( params[ 3 ] );
  470. PARAM5 *p5 = static_cast<PARAM5 *>( params[ 4 ] );
  471. PARAM6 *p6 = static_cast<PARAM6 *>( params[ 5 ] );
  472. PARAM7 *p7 = static_cast<PARAM7 *>( params[ 6 ] );
  473. PARAM8 *p8 = static_cast<PARAM8 *>( params[ 7 ] );
  474. PARAM9 *p9 = static_cast<PARAM9 *>( params[ 8 ] );
  475. PARAM10 *p10 = static_cast<PARAM10 *>( params[ 9 ] );
  476. PARAM11 *p11 = static_cast<PARAM11 *>( params[ 10 ] );
  477. PARAM12 *p12 = static_cast<PARAM12 *>( params[ 11 ] );
  478. PARAM13 *p13 = static_cast<PARAM13 *>( params[ 12 ] );
  479. PARAM14 *p14 = static_cast<PARAM14 *>( params[ 13 ] );
  480. PARAM15 *p15 = static_cast<PARAM15 *>( params[ 14 ] );
  481. PARAM16 *p16 = static_cast<PARAM16 *>( params[ 15 ] );
  482. ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9, *p10, *p11, *p12, *p13, *p14, *p15, *p16 );
  483. }
  484. // 17 params
  485. template <class CASTNAME, class CLASSNAME, class PARAM1, class PARAM2, class PARAM3, class PARAM4, class PARAM5, class PARAM6, class PARAM7, class PARAM8, class PARAM9, class PARAM10, class PARAM11, class PARAM12, class PARAM13, class PARAM14, class PARAM15, class PARAM16, class PARAM17>
  486. void vcb( void ( CLASSNAME:: *fn )( PARAM1, PARAM2, PARAM3, PARAM4, PARAM5, PARAM6, PARAM7, PARAM8, PARAM9, PARAM10, PARAM11, PARAM12, PARAM13, PARAM14, PARAM15, PARAM16, PARAM17 ), void *retval, void **params )
  487. {
  488. PARAM1 *p1 = static_cast<PARAM1 *>( params[ 0 ] );
  489. PARAM2 *p2 = static_cast<PARAM2 *>( params[ 1 ] );
  490. PARAM3 *p3 = static_cast<PARAM3 *>( params[ 2 ] );
  491. PARAM4 *p4 = static_cast<PARAM4 *>( params[ 3 ] );
  492. PARAM5 *p5 = static_cast<PARAM5 *>( params[ 4 ] );
  493. PARAM6 *p6 = static_cast<PARAM6 *>( params[ 5 ] );
  494. PARAM7 *p7 = static_cast<PARAM7 *>( params[ 6 ] );
  495. PARAM8 *p8 = static_cast<PARAM8 *>( params[ 7 ] );
  496. PARAM9 *p9 = static_cast<PARAM9 *>( params[ 8 ] );
  497. PARAM10 *p10 = static_cast<PARAM10 *>( params[ 9 ] );
  498. PARAM11 *p11 = static_cast<PARAM11 *>( params[ 10 ] );
  499. PARAM12 *p12 = static_cast<PARAM12 *>( params[ 11 ] );
  500. PARAM13 *p13 = static_cast<PARAM13 *>( params[ 12 ] );
  501. PARAM14 *p14 = static_cast<PARAM14 *>( params[ 13 ] );
  502. PARAM15 *p15 = static_cast<PARAM15 *>( params[ 14 ] );
  503. PARAM16 *p16 = static_cast<PARAM16 *>( params[ 15 ] );
  504. PARAM17 *p17 = static_cast<PARAM17 *>( params[ 16 ] );
  505. ( static_cast<CLASSNAME *>( static_cast<CASTNAME *>( this ) )->*fn )( *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9, *p10, *p11, *p12, *p13, *p14, *p15, *p16, *p17 );
  506. }
  507. enum
  508. {
  509. DESTRUCT = 0xffff
  510. };
  511. };
  512. #define CB(x, y) case (x): cb<CBCLASS>(&CBCLASS::y, retval, params); break;
  513. #define CBT(x, y) case (x): cb<CBCLASST>(&CBCLASS::y, retval, params); break;
  514. #define VCB(x, y) case (x): vcb<CBCLASS>(&CBCLASS::y, retval, params); break;
  515. #define VCBT(x, y) case (x): vcb<CBCLASST>(&CBCLASS::y, retval, params); break;
  516. #define RECVS_DISPATCH virtual int _dispatch(int msg, void *retval, void **params=0, int nparam=0)
  517. #define START_DISPATCH \
  518. int CBCLASS::_dispatch(int msg, void *retval, void **params, int nparam) { \
  519. switch (msg) {
  520. #define START_DISPATCH_INLINE \
  521. int _dispatch(int msg, void *retval, void **params, int nparam) { \
  522. switch (msg) {
  523. //FINISH case DESTRUCT: delete this; return 1;
  524. #define END_DISPATCH \
  525. default: return 0; \
  526. } \
  527. return 1; \
  528. }
  529. #define FORWARD_DISPATCH(x) \
  530. default: return x::_dispatch(msg, retval, params, nparam); \
  531. } \
  532. return 1; \
  533. }
  534. #define DISPATCH_CODES enum
  535. inline int Dispatchable::AddRef()
  536. {
  537. return _call( Dispatchable::ADDREF, 0 );
  538. }
  539. inline int Dispatchable::Release()
  540. {
  541. return _call( Dispatchable::RELEASE, 0 );
  542. }
  543. inline int Dispatchable::QueryInterface( GUID interface_guid, void **object )
  544. {
  545. return _call( Dispatchable::QUERYINTERFACE, 0, interface_guid, object );
  546. }
  547. #ifndef DECLARE_EXTERNAL_SERVICE
  548. #define DECLARE_EXTERNAL_SERVICE(_type, _name) extern _type *_name
  549. #endif
  550. #ifndef DEFINE_EXTERNAL_SERVICE
  551. #define DEFINE_EXTERNAL_SERVICE(_type, _name) _type *_name=0
  552. #endif