From 6d1d7cdc32568724e21bc68a4ab3370588a6c30a Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 14 Jun 2020 18:49:20 +0300 Subject: Proto_GetInstance: handy helper to obtain PROTO_INTERFACE for a hContact / szModule --- include/m_gui.h | 55 ------------------------------------------------ include/m_protoint.h | 6 ++++++ include/m_system.h | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 55 deletions(-) (limited to 'include') diff --git a/include/m_gui.h b/include/m_gui.h index 5b92502f0b..a62e706a11 100644 --- a/include/m_gui.h +++ b/include/m_gui.h @@ -234,61 +234,6 @@ private: mir_ptr m_value; }; -///////////////////////////////////////////////////////////////////////////////////////// -// Callbacks - -struct CCallbackImp -{ - struct CDummy - { int foo; - }; - -public: - __inline CCallbackImp(): m_object(nullptr), m_func(nullptr) {} - - __inline CCallbackImp(const CCallbackImp &other): m_object(other.m_object), m_func(other.m_func) {} - __inline CCallbackImp &operator=(const CCallbackImp &other) { m_object = other.m_object; m_func = other.m_func; return *this; } - - __inline bool operator==(const CCallbackImp &other) const { return (m_object == other.m_object) && (m_func == other.m_func); } - __inline bool operator!=(const CCallbackImp &other) const { return (m_object != other.m_object) || (m_func != other.m_func); } - - __inline operator bool() const { return m_object && m_func; } - - __inline bool CheckObject(void *object) const { return (object == m_object) ? true : false; } - -protected: - template - __inline CCallbackImp(TClass *object, void (TClass::*func)(TArgument *argument)): m_object((CDummy*)object), m_func((TFnCallback)func) {} - - __inline void Invoke(void *argument) const { if (m_func && m_object) (m_object->*m_func)(argument); } - -private: - typedef void (CDummy::*TFnCallback)(void *argument); - - CDummy* m_object; - TFnCallback m_func; -}; - -template -struct CCallback: public CCallbackImp -{ - typedef CCallbackImp CSuper; - -public: - __inline CCallback() {} - - template - __inline CCallback(TClass *object, void (TClass::*func)(TArgument *argument)): CCallbackImp(object, func) {} - - __inline CCallback& operator=(const CCallbackImp& x) { CSuper::operator =(x); return *this; } - - __inline void operator()(TArgument *argument) const { Invoke((void*)argument); } -}; - -template -__inline CCallback Callback(TClass *object, void (TClass::*func)(TArgument *argument)) - { return CCallback(object, func); } - ///////////////////////////////////////////////////////////////////////////////////////// // CDbLink diff --git a/include/m_protoint.h b/include/m_protoint.h index 8be0fce7f4..9bc9def714 100644 --- a/include/m_protoint.h +++ b/include/m_protoint.h @@ -288,4 +288,10 @@ template struct PROTO : public PROTO_INTERFACE __forceinline void CreateProtoServiceParam(const char *name, MyServiceFuncParam pFunc, LPARAM param) { ::ProtoCreateServiceParam(this, name, (ProtoServiceFuncParam)pFunc, param); } }; + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(PROTO_INTERFACE *) Proto_GetInstance(const char *szModule); +MIR_APP_DLL(PROTO_INTERFACE *) Proto_GetInstance(MCONTACT hContact); + #endif // M_PROTOINT_H__ diff --git a/include/m_system.h b/include/m_system.h index c48b1fcc13..a2f1dae9b8 100644 --- a/include/m_system.h +++ b/include/m_system.h @@ -559,6 +559,65 @@ struct WCHAR_PARAM : public PARAM } }; +///////////////////////////////////////////////////////////////////////////////////////// +// Callbacks + +class CCallbackImp +{ + struct CDummy + { + int foo; + }; + + typedef void (CDummy:: *TFnCallback)(void *argument); + + CDummy *m_object; + TFnCallback m_func; + +protected: + template + __inline CCallbackImp(TClass *object, void (TClass:: *func)(TArgument *argument)) : + m_object((CDummy *)object), + m_func((TFnCallback)func) + { + } + + __inline void Invoke(void *argument) const { if (m_func && m_object) (m_object->*m_func)(argument); } + +public: + __inline CCallbackImp() : m_object(nullptr), m_func(nullptr) {} + + __inline CCallbackImp(const CCallbackImp &other) : m_object(other.m_object), m_func(other.m_func) {} + __inline CCallbackImp &operator=(const CCallbackImp &other) { m_object = other.m_object; m_func = other.m_func; return *this; } + + __inline bool operator==(const CCallbackImp &other) const { return (m_object == other.m_object) && (m_func == other.m_func); } + __inline bool operator!=(const CCallbackImp &other) const { return (m_object != other.m_object) || (m_func != other.m_func); } + + __inline operator bool() const { return m_object && m_func; } +}; + +template +struct CCallback : public CCallbackImp +{ + typedef CCallbackImp CSuper; + +public: + __inline CCallback() {} + + template + __inline CCallback(TClass *object, void (TClass:: *func)(TArgument *argument)) : CCallbackImp(object, func) {} + + __inline CCallback &operator=(const CCallbackImp &x) { CSuper::operator =(x); return *this; } + + __inline void operator()(TArgument *argument) const { Invoke((void *)argument); } +}; + +template +__inline CCallback Callback(TClass *object, void (TClass:: *func)(TArgument *argument)) +{ + return CCallback(object, func); +} + /////////////////////////////////////////////////////////////////////////////// // http support -- cgit v1.2.3