dispatch.h 28 KB

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