aboutsummaryrefslogtreecommitdiff
path: root/Src/replicant/service
diff options
context:
space:
mode:
authorJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
committerJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
commit20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch)
tree12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/replicant/service
parent537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff)
downloadwinamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz
Initial community commit
Diffstat (limited to 'Src/replicant/service')
-rw-r--r--Src/replicant/service/api_service.h63
-rw-r--r--Src/replicant/service/ifc_servicefactory.h44
-rw-r--r--Src/replicant/service/svccb.h38
-rw-r--r--Src/replicant/service/types.h5
4 files changed, 150 insertions, 0 deletions
diff --git a/Src/replicant/service/api_service.h b/Src/replicant/service/api_service.h
new file mode 100644
index 00000000..9c883f4c
--- /dev/null
+++ b/Src/replicant/service/api_service.h
@@ -0,0 +1,63 @@
+#pragma once
+
+#ifndef _API_SERVICE_H
+#define _API_SERVICE_H
+
+#include "../foundation/dispatch.h"
+#include "../foundation/types.h"
+#include "../foundation/guid.h"
+#include "../foundation/error.h"
+#include "../service/ifc_servicefactory.h"
+
+// ----------------------------------------------------------------------------
+// {6DD93387-6636-4479-B982-9FF5B91CF4B4}
+static const GUID service_api_service_guid =
+{ 0x6dd93387, 0x6636, 0x4479, { 0xb9, 0x82, 0x9f, 0xf5, 0xb9, 0x1c, 0xf4, 0xb4 } };
+
+class NOVTABLE api_service : public Wasabi2::Dispatchable
+{
+protected:
+ api_service() : Dispatchable(DISPATCHABLE_VERSION) {}
+ ~api_service() {}
+public:
+ static GUID GetServiceGUID() { return service_api_service_guid; }
+ int Register(ifc_serviceFactory *svc) { return Service_Register(svc); }
+ int Unregister(ifc_serviceFactory *svc) { return Service_Unregister(svc); }
+ size_t GetServiceCount(GUID svc_type) { return Service_GetServiceCount(svc_type); }
+ ifc_serviceFactory *EnumService(GUID svc_type, size_t n) { return Service_EnumService(svc_type, n); }
+ ifc_serviceFactory *EnumService(size_t n) { return Service_EnumService(n); }
+ ifc_serviceFactory *GetServiceByGUID(GUID guid) { return Service_GetServiceByGUID(guid); }
+
+ /* called by a component when it returns NErr_TryAgain from one of the quit-phase functions */
+ void ComponentDone() { Service_ComponentDone(); }
+
+ template <class _t>
+ int GetService(_t **out_service)
+ {
+ ifc_serviceFactory *sf = Service_GetServiceByGUID(_t::GetServiceGUID());
+ if (!sf)
+ return NErr_ServiceUnavailable;
+
+ _t *service = reinterpret_cast<_t *>(sf->GetInterface());
+ if (!service)
+ return NErr_FailedCreate;
+
+ *out_service = service;
+ return NErr_Success;
+ }
+
+ enum
+ {
+ DISPATCHABLE_VERSION,
+ };
+protected:
+ virtual int WASABICALL Service_Register(ifc_serviceFactory *svc)=0;
+ virtual int WASABICALL Service_Unregister(ifc_serviceFactory *svc)=0;
+ virtual size_t WASABICALL Service_GetServiceCount(GUID svc_type)=0;
+ virtual ifc_serviceFactory * WASABICALL Service_EnumService(GUID svc_type, size_t n)=0;
+ virtual ifc_serviceFactory * WASABICALL Service_EnumService(size_t n)=0;
+ virtual ifc_serviceFactory * WASABICALL Service_GetServiceByGUID(GUID guid)=0;
+ virtual void WASABICALL Service_ComponentDone()=0;
+};
+
+#endif // !_API_SERVICE_H \ No newline at end of file
diff --git a/Src/replicant/service/ifc_servicefactory.h b/Src/replicant/service/ifc_servicefactory.h
new file mode 100644
index 00000000..fa97665d
--- /dev/null
+++ b/Src/replicant/service/ifc_servicefactory.h
@@ -0,0 +1,44 @@
+#pragma once
+
+#include "../foundation/dispatch.h"
+#include "../foundation/guid.h"
+#include "../nx/nxstring.h"
+
+// ----------------------------------------------------------------------------
+
+class NOVTABLE ifc_serviceFactory : public Wasabi2::Dispatchable
+{
+protected:
+ ifc_serviceFactory() : Dispatchable(DISPATCHABLE_VERSION) {}
+ ~ifc_serviceFactory() {}
+
+
+public:
+ GUID GetServiceType() { return ServiceFactory_GetServiceType(); }
+ nx_string_t GetServiceName() { return ServiceFactory_GetServiceName(); }
+ GUID GetGUID() { return ServiceFactory_GetGUID(); }
+ void *GetInterface() { return ServiceFactory_GetInterface(); }
+ int ServiceNotify(int msg, intptr_t param1 = 0, intptr_t param2 = 0) { return ServiceFactory_ServiceNotify(msg, param1, param2); }
+
+ // serviceNotify enums
+ enum
+ {
+ ONREGISTERED=0, // init yourself here -- not all other services are registered yet
+ ONSTARTUP=1, // everyone is initialized, safe to talk to other services
+ ONAPPRUNNING=2, // app is showing and processing events
+ ONBEFORESHUTDOWN=3, // system is about to shutdown, call WASABI2_API_APP->main_cancelShutdown() to cancel
+ ONSHUTDOWN=4, // studio is shutting down, release resources from other services
+ ONUNREGISTERED=5, // bye bye
+ };
+
+ enum
+ {
+ DISPATCHABLE_VERSION,
+ };
+protected:
+ virtual GUID WASABICALL ServiceFactory_GetServiceType()=0;
+ virtual nx_string_t WASABICALL ServiceFactory_GetServiceName()=0;
+ virtual GUID WASABICALL ServiceFactory_GetGUID()=0;
+ virtual void *WASABICALL ServiceFactory_GetInterface()=0;
+ virtual int WASABICALL ServiceFactory_ServiceNotify(int msg, intptr_t param1 = 0, intptr_t param2 = 0)=0;
+};
diff --git a/Src/replicant/service/svccb.h b/Src/replicant/service/svccb.h
new file mode 100644
index 00000000..964c8097
--- /dev/null
+++ b/Src/replicant/service/svccb.h
@@ -0,0 +1,38 @@
+#pragma once
+
+#include "syscb/ifc_syscallback.h"
+#include "foundation/mkncc.h"
+
+namespace Service
+{
+ // {215CDE06-22A6-424F-9C64-DEDC45D84455}
+ static const GUID event_type =
+ { 0x215cde06, 0x22a6, 0x424f, { 0x9c, 0x64, 0xde, 0xdc, 0x45, 0xd8, 0x44, 0x55 } };
+ static const int on_register = 0;
+ static const int on_deregister = 1;
+
+ class SystemCallback : public ifc_sysCallback
+ {
+ protected:
+ GUID WASABICALL SysCallback_GetEventType() { return event_type; }
+ int WASABICALL SysCallback_Notify(int msg, intptr_t param1, intptr_t param2)
+ {
+ const GUID *service_id;
+
+ switch(msg)
+ {
+ case on_register:
+ service_id = (const GUID *)param1;
+ return ServiceSystemCallback_OnRegister(*service_id, (void *)param2);
+ case on_deregister:
+ service_id = (const GUID *)param1;
+ return ServiceSystemCallback_OnDeregister(*service_id, (void *)param2);
+ default:
+ return NErr_Success;
+ }
+ }
+ virtual int WASABICALL ServiceSystemCallback_OnRegister(GUID service_id, void *service) { return NErr_Success; }
+ virtual int WASABICALL ServiceSystemCallback_OnDeregister(GUID service_id, void *service) { return NErr_Success; }
+ };
+
+}
diff --git a/Src/replicant/service/types.h b/Src/replicant/service/types.h
new file mode 100644
index 00000000..7439edab
--- /dev/null
+++ b/Src/replicant/service/types.h
@@ -0,0 +1,5 @@
+#pragma once
+#include "../foundation/guid.h"
+
+static const GUID SVC_TYPE_UNIQUE = { 0x3ffe7079, 0x2467, 0x495e, { 0x88, 0x18, 0x61, 0x64, 0x22, 0xb6, 0x51, 0x20 } };
+static const GUID SVC_TYPE_OBJECT = { 0x175b4de2, 0x8330, 0x48ce, { 0xb2, 0xab, 0xe9, 0x45, 0x49, 0x0b, 0x73, 0x14 } };