From d48cbe75ef29a9c67c9d176bf58e56ea6448fb9e Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 21 Oct 2024 20:23:36 +0200 Subject: IMP: Major refactor of header and source files extensions. Signed-off-by: Amlal El Mahrouss --- dev/sci/xpcom_core.h | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 dev/sci/xpcom_core.h (limited to 'dev/sci/xpcom_core.h') diff --git a/dev/sci/xpcom_core.h b/dev/sci/xpcom_core.h new file mode 100644 index 00000000..c86210b5 --- /dev/null +++ b/dev/sci/xpcom_core.h @@ -0,0 +1,99 @@ +/* ------------------------------------------- + +Copyright ZKA Web Services Co. + +File: rt.internal.inl +Purpose: Base code of XPCOM. + +------------------------------------------- */ + +/// @internal Reserved for internal definitions only. + +#ifndef __NDK__ +#define object class +#define protocol class +#define clsid(X) + +#warning ! You may be using the clang compiler, please be cautious that some features mayn't be present. ! +#endif // !__NDK__ + +protocol IUnknown; // Refrenced from an IDB entry. +protocol ICLSID; // From the IDB, the constructor of the object, e.g: TextUCLSID. +object UUID; +object IStr; + +/// @brief Unknown XPCOM interface +protocol clsid("d7c144b6-0792-44b8-b06b-02b227b547df") IUnknown +{ +public: + explicit IUnknown() = default; + virtual ~IUnknown() = default; + + IUnknown& operator=(const IUnknown&) = default; + IUnknown(const IUnknown&) = default; + + virtual SInt32 Release() = 0; + virtual Void RemoveRef() = 0; + virtual IUnknown* AddRef() = 0; + virtual VoidPtr QueryClass(UUID * p_uuid) = 0; +}; + +/// @brief Allocate new XPCOM object. +/// @tparam TCLS the class type. +/// @tparam UCLSID UCLS factory class type. +/// @param uclsidOfCls UCLS factory class +/// @return TCLS interface +template +inline TCLS* XPCOMQueryInterface(UCLSID* uclsidOfCls, Args&&... args) +{ + if (uclsidOfCls == nullptr) + return nullptr; + + uclsidOfCls->AddRef(); + return uclsidOfCls->QueryInterfaceWithArgs(args...); +} + +/// @brief Release XPCOM object. +/// @tparam TCLS the class type. +/// @param cls the class to release. +/// @return status code. +template +inline SInt32 XPCOMReleaseClass(TCLS** cls) +{ + if (!*cls) + return -kErrorInvalidData; + + (*cls)->RemoveRef(); + (*cls)->Release(); + + *cls = nullptr; + + return kErrorSuccess; +} + +/// @brief Event listener interface. +/// @tparam FnSign the event listener function type. +/// @tparam ClsID the event listener class ID. +template +protocol IEventListener : public ClsID +{ + friend ClsID; + + explicit IEventListener() = default; + virtual ~IEventListener() = default; + + IEventListener& operator=(const IEventListener&) = default; + IEventListener(const IEventListener&) = default; + + virtual IEventListener& operator-=(const IStr* event_name) + { + this->RemoveEventListener(event_name); + return *this; + } + + virtual IEventListener& operator+=(FnSign arg) + { + this->AddEventListener(arg); + return *this; + } +}; -- cgit v1.2.3