ifc_component.h 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #pragma once
  2. #include "foundation/dispatch.h"
  3. #include "service/api_service.h"
  4. #ifdef _WIN32
  5. #ifndef WIN32_LEAN_AND_MEAN
  6. #define WIN32_LEAN_AND_MEAN
  7. #endif
  8. #include <windows.h>
  9. #endif
  10. #ifdef __APPLE__
  11. #include <CoreFoundation/CoreFoundation.h> /* for CFBundleRef */
  12. #endif
  13. #include "nx/nxapi.h"
  14. #include "nx/nxuri.h"
  15. /* see http://wiki.office.aol.com/wiki/Replicant/Component */
  16. /* in very rare cases, this will get incremented */
  17. const int wasabi2_component_version = 0;
  18. struct WasabiComponentInfo
  19. {
  20. /* these will be filled in by the host application loading your component */
  21. #if defined(_WIN32)
  22. HMODULE hModule;
  23. #elif defined(__APPLE__)
  24. /* depending on whether your component is a bundle or a dylib, one of these will be filled */
  25. CFBundleRef bundle;
  26. void *dl_handle; // pointer returned from dlopen
  27. #else
  28. void *dl_handle; // pointer returned from dlopen
  29. #endif
  30. nx_uri_t filename;
  31. /* these are filled in during ifc_component's constructor. You don't need to change these */
  32. int wasabi_version; /* major breaking changes to Wasabi (ABI changes, Dispatchable definition, etc) will change this. This is used to filter out components that are expecting something completely different than what the host API provides */
  33. int nx_api_version; /* major breaking changes to the NX API will change this. */
  34. GUID nx_platform_guid; /* platform that this is meant to link against. right now this mainly helps avoid loading android components on 'vanilla' linux, and vice-versa */
  35. /* these are defaulted to INVALID_GUID. You can optionally override these in your Component's constructor */
  36. GUID component_guid; /* a unique identifier for your Component */
  37. GUID framework_guid; /* optionally set to the framework that your component is meant to work in. Can optionally be used as a filter by the Component Manager. This avoids loading, e.g., a replicant component on some completely different Wasabi-based framework */
  38. GUID application_guid; /* if your component is meant to work with a specific application, you can define it here. Can optionally be used as a filter by the Component Manager. */
  39. };
  40. class NOVTABLE ifc_component : public Wasabi2::Dispatchable
  41. //public wa::lists::node_ptr /* this is for internal use by the Component Manager! */
  42. {
  43. protected:
  44. ifc_component(GUID component_guid) : Wasabi2::Dispatchable(DISPATCHABLE_VERSION)
  45. {
  46. memset(&component_info, 0, sizeof(component_info)); /* memsetting the whole thing avoids a bunch of ifdef code */
  47. component_info.wasabi_version = wasabi2_component_version;
  48. component_info.nx_api_version = nx_api_version;
  49. component_info.nx_platform_guid = nx_platform_guid;
  50. component_info.component_guid = component_guid;
  51. }
  52. ~ifc_component() {}
  53. public:
  54. WasabiComponentInfo component_info; /* it's unusual for an interface to have data members, but this makes thing convienent */
  55. int Initialize(api_service *_service_manager) { return Component_Initialize(_service_manager); }
  56. int RegisterServices(api_service *_service_manager) { return Component_RegisterServices(_service_manager); }
  57. int OnLoading(api_service *_service_manager) { return Component_OnLoading(_service_manager); }
  58. int OnLoaded(api_service *_service_manager) {return Component_OnLoaded(_service_manager); }
  59. int OnClosing(api_service *_service_manager) { return Component_OnClosing(_service_manager); }
  60. void DeregisterServices(api_service *_service_manager) { Component_DeregisterServices(_service_manager); }
  61. int OnClosed(api_service *_service_manager) { return Component_OnClosed(_service_manager); }
  62. int Quit(api_service *_service_manager) { return Component_Quit(_service_manager); }
  63. enum
  64. {
  65. DISPATCHABLE_VERSION,
  66. };
  67. private:
  68. /* these 4 will get called in sequence during component load, see http://wiki.office.aol.com/wiki/Replicant/Component for details */
  69. // TODO: get rid of default implementations, eventually
  70. virtual int WASABICALL Component_Initialize(api_service *_service_manager) { return NErr_Success; }
  71. virtual int WASABICALL Component_RegisterServices(api_service *_service_manager)=0;
  72. virtual int WASABICALL Component_OnLoading(api_service *_service_manager) { return NErr_Success; }
  73. virtual int WASABICALL Component_OnLoaded(api_service *_service_manager) { return NErr_Success; }
  74. virtual int WASABICALL Component_OnClosing(api_service *_service_manager) { return NErr_Success; }
  75. virtual void WASABICALL Component_DeregisterServices(api_service *_service_manager)=0;
  76. virtual int WASABICALL Component_OnClosed(api_service *_service_manager) { return NErr_Success; }
  77. virtual int WASABICALL Component_Quit(api_service *_service_manager) { return NErr_Success; }
  78. };
  79. extern "C" typedef ifc_component *(*GETCOMPONENT_FUNC)();