summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-03-28 16:34:30 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-03-28 16:34:30 +0300
commit81ce57622c3166830b23eae534dacc6b008c659d (patch)
tree6d6ac74667f733a20b94fa27cc01c2f45688c533 /include
parentc2bb7727483b9b5620e8cc0ce6adae35ee78d0a4 (diff)
common protocol instance management code went into template
Diffstat (limited to 'include')
-rw-r--r--include/m_plugin.h50
1 files changed, 50 insertions, 0 deletions
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 P> class ACCPROTOPLUGIN : public PLUGIN<CMPlugin>
+{
+ typedef PLUGIN<CMPlugin> 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<P> 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<class P>
+OBJLIST<P> ACCPROTOPLUGIN<P>::g_arInstances(1, PtrKeySortT);