From 81ce57622c3166830b23eae534dacc6b008c659d Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 28 Mar 2018 16:34:30 +0300 Subject: common protocol instance management code went into template --- include/m_plugin.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'include') diff --git a/include/m_plugin.h b/include/m_plugin.h index b54d64aea3..233e03a432 100644 --- a/include/m_plugin.h +++ b/include/m_plugin.h @@ -189,3 +189,53 @@ protected: CreateServiceFunctionObjParam(str, (MIRANDASERVICEOBJPARAM)*(void**)&pFunc, this, param); } }; + +///////////////////////////////////////////////////////////////////////////////////////// +// Basic class for protocols with accounts + +struct CMPlugin; + +template class ACCPROTOPLUGIN : public PLUGIN +{ + typedef PLUGIN CSuper; + +protected: + ACCPROTOPLUGIN(const char *moduleName) : + CSuper(moduleName) + { + CMPluginBase::RegisterProtocol(PROTOTYPE_PROTOCOL, &fnInit, &fnUninit); + } + + static PROTO_INTERFACE* fnInit(const char *szModuleName, const wchar_t *wszAccountName) + { + P *ppro = new P(szModuleName, wszAccountName); + g_arInstances.insert(ppro); + return ppro; + } + + static int fnUninit(PROTO_INTERFACE *ppro) + { + g_arInstances.remove((P*)ppro); + return 0; + } + +public: + static OBJLIST

g_arInstances; + + static P* getInstance(const char *szProto) + { + for (auto &it : g_arInstances) + if (mir_strcmp(szProto, it->m_szModuleName) == 0) + return it; + + return nullptr; + } + + static P* getInstance(MCONTACT hContact) + { + return getInstance(::GetContactProto(hContact)); + } +}; + +template +OBJLIST

ACCPROTOPLUGIN

::g_arInstances(1, PtrKeySortT); -- cgit v1.2.3