From bb952e431866d131bae95c08e579ec8a00f00343 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 8 Jul 2013 22:10:14 +0000 Subject: core protocol helpers for creating protocol evengs, services & threads git-svn-id: http://svn.miranda-ng.org/main/trunk@5286 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- include/m_core.h | 16 ++++++++++++++++ include/m_protoint.h | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) (limited to 'include') diff --git a/include/m_core.h b/include/m_core.h index 4467168395..3a8da096cd 100644 --- a/include/m_core.h +++ b/include/m_core.h @@ -605,6 +605,22 @@ MIR_CORE_DLL(void) ProtoConstructor(struct PROTO_INTERFACE *pThis, const char *p // Call it in the very end of your proto's destructor MIR_CORE_DLL(void) ProtoDestructor(struct PROTO_INTERFACE *pThis); +#if defined( __cplusplus ) +typedef void (__cdecl PROTO_INTERFACE::*ProtoThreadFunc)(void*); +MIR_CORE_DLL(void) ProtoForkThread(PROTO_INTERFACE *pThis, ProtoThreadFunc, void *param); +MIR_CORE_DLL(HANDLE) ProtoForkThreadEx(PROTO_INTERFACE *pThis, ProtoThreadFunc, void *param, UINT* threadID); + +typedef int (__cdecl PROTO_INTERFACE::*ProtoEventFunc)(WPARAM, LPARAM); +MIR_CORE_DLL(void) ProtoHookEvent(PROTO_INTERFACE *pThis, const char* szName, ProtoEventFunc pFunc); +MIR_CORE_DLL(HANDLE) ProtoCreateHookableEvent(PROTO_INTERFACE *pThis, const char* szService); + +typedef INT_PTR (__cdecl PROTO_INTERFACE::*ProtoServiceFunc)(WPARAM, LPARAM); +MIR_CORE_DLL(void) ProtoCreateService(PROTO_INTERFACE *pThis, const char* szService, ProtoServiceFunc); + +typedef INT_PTR (__cdecl PROTO_INTERFACE::*ProtoServiceFuncParam)(WPARAM, LPARAM, LPARAM); +MIR_CORE_DLL(void) ProtoCreateServiceParam(PROTO_INTERFACE *pThis, const char* szService, ProtoServiceFuncParam, LPARAM); +#endif + /////////////////////////////////////////////////////////////////////////////// // sha1 functions diff --git a/include/m_protoint.h b/include/m_protoint.h index ac700dfbad..336a5eecba 100644 --- a/include/m_protoint.h +++ b/include/m_protoint.h @@ -106,4 +106,36 @@ struct PROTO_INTERFACE : public MZeroedObject virtual int __cdecl OnEvent(PROTOEVENTTYPE iEventType, WPARAM wParam, LPARAM lParam) = 0; }; +template class PROTO : public PROTO_INTERFACE +{ + +public: + __forceinline PROTO(const char *szProto, const TCHAR *tszUserName) + { + ::ProtoConstructor(this, szProto, tszUserName); + } + + __forceinline ~PROTO() + { + ::ProtoDestructor(this); + } + + typedef int (__cdecl T::*MyEventFunc)(WPARAM, LPARAM); + void __forceinline HookEvent(const char* name, MyEventFunc pFunc) + { ::ProtoHookEvent(this, name, (ProtoEventFunc)pFunc); } + + typedef void (__cdecl T::*MyThreadFunc)(void*); + void __forceinline ForkThread(MyThreadFunc pFunc, void *param) + { ::ProtoForkThread(this, (ProtoThreadFunc)pFunc, param); } + HANDLE __forceinline ForkThreadEx(MyThreadFunc pFunc, void *param, UINT *pThreadId) + { return ::ProtoForkThreadEx(this, (ProtoThreadFunc)pFunc, param, pThreadId); } + + typedef INT_PTR (__cdecl T::*MyServiceFunc)(WPARAM, LPARAM); + void __forceinline CreateService(const char *name, MyServiceFunc pFunc) + { ::ProtoCreateService(this, name, (ProtoServiceFunc)pFunc); } + + typedef INT_PTR (__cdecl T::*MyServiceFuncParam)(WPARAM, LPARAM, LPARAM); + void __forceinline CreateServiceParam(const char *name, MyServiceFuncParam pFunc, LPARAM param) + { ::ProtoCreateServiceParam(this, name, (ProtoServiceFuncParam)pFunc, param); } +}; #endif // M_PROTOINT_H__ -- cgit v1.2.3