1
0

dispatch.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #pragma once
  2. #include "guid.h"
  3. #ifdef WIN32
  4. #ifndef NOVTABLE
  5. #define NOVTABLE __declspec(novtable)
  6. #endif
  7. #else
  8. #define NOVTABLE
  9. #endif
  10. #if defined(__GNUC__) && (defined(__x86_32__) || defined(__i386__))
  11. #define WASABICALL __attribute__((stdcall))
  12. #elif defined (_WIN32)
  13. #define WASABICALL __stdcall
  14. #else
  15. #define WASABICALL
  16. #endif
  17. namespace Wasabi2
  18. {
  19. class NOVTABLE Dispatchable
  20. {
  21. protected:
  22. Dispatchable(size_t _dispatchable_version) : dispatchable_version(_dispatchable_version) {}
  23. ~Dispatchable() {}
  24. public:
  25. #define dispatch_call(code, default_return, func) (DispatchValid(code))?(default_return):func
  26. #define dispatch_voidcall(code, func) if (DispatchValid(code)) func
  27. bool DispatchValid(size_t code) const
  28. {
  29. return code < dispatchable_version;
  30. }
  31. size_t Retain()
  32. {
  33. return Dispatchable_Retain();
  34. }
  35. size_t Release()
  36. {
  37. return Dispatchable_Release();
  38. }
  39. int QueryInterface(GUID interface_guid, void **object)
  40. {
  41. return Dispatchable_QueryInterface(interface_guid, object);
  42. }
  43. template <class ifc_t>
  44. int QueryInterface(ifc_t **object)
  45. {
  46. return Dispatchable_QueryInterface(ifc_t::GetInterfaceGUID(), (void **)object);
  47. }
  48. protected:
  49. virtual size_t WASABICALL Dispatchable_Retain() { return 0; }
  50. virtual size_t WASABICALL Dispatchable_Release() { return 0; }
  51. virtual int WASABICALL Dispatchable_QueryInterface(GUID interface_guid, void **object) { return 1; }
  52. size_t dispatchable_version;
  53. };
  54. }
  55. #ifndef DECLARE_EXTERNAL_SERVICE
  56. #define DECLARE_EXTERNAL_SERVICE(_type, _name) extern _type *_name
  57. #endif
  58. #ifndef DEFINE_EXTERNAL_SERVICE
  59. #define DEFINE_EXTERNAL_SERVICE(_type, _name) _type *_name=0
  60. #endif