diff options
author | Jean-Francois Mauguit <jfmauguit@mac.com> | 2024-09-24 09:03:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-24 09:03:25 -0400 |
commit | bab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/replicant/foundation/dispatch.h | |
parent | 4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff) | |
parent | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff) | |
download | winamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz |
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/replicant/foundation/dispatch.h')
-rw-r--r-- | Src/replicant/foundation/dispatch.h | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/Src/replicant/foundation/dispatch.h b/Src/replicant/foundation/dispatch.h new file mode 100644 index 00000000..81af541b --- /dev/null +++ b/Src/replicant/foundation/dispatch.h @@ -0,0 +1,74 @@ +#pragma once + +#include "guid.h" + +#ifdef WIN32 +#ifndef NOVTABLE +#define NOVTABLE __declspec(novtable) +#endif +#else +#define NOVTABLE +#endif + + +#if defined(__GNUC__) && (defined(__x86_32__) || defined(__i386__)) +#define WASABICALL __attribute__((stdcall)) +#elif defined (_WIN32) +#define WASABICALL __stdcall +#else +#define WASABICALL +#endif + +namespace Wasabi2 +{ + class NOVTABLE Dispatchable + { + protected: + Dispatchable(size_t _dispatchable_version) : dispatchable_version(_dispatchable_version) {} + ~Dispatchable() {} + public: +#define dispatch_call(code, default_return, func) (DispatchValid(code))?(default_return):func +#define dispatch_voidcall(code, func) if (DispatchValid(code)) func + + bool DispatchValid(size_t code) const + { + return code < dispatchable_version; + } + + size_t Retain() + { + return Dispatchable_Retain(); + } + + size_t Release() + { + return Dispatchable_Release(); + } + + int QueryInterface(GUID interface_guid, void **object) + { + return Dispatchable_QueryInterface(interface_guid, object); + } + + template <class ifc_t> + int QueryInterface(ifc_t **object) + { + return Dispatchable_QueryInterface(ifc_t::GetInterfaceGUID(), (void **)object); + } + + protected: + virtual size_t WASABICALL Dispatchable_Retain() { return 0; } + virtual size_t WASABICALL Dispatchable_Release() { return 0; } + virtual int WASABICALL Dispatchable_QueryInterface(GUID interface_guid, void **object) { return 1; } + + size_t dispatchable_version; + }; +} + +#ifndef DECLARE_EXTERNAL_SERVICE +#define DECLARE_EXTERNAL_SERVICE(_type, _name) extern _type *_name +#endif + +#ifndef DEFINE_EXTERNAL_SERVICE +#define DEFINE_EXTERNAL_SERVICE(_type, _name) _type *_name=0 +#endif |