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 --- protocols/MSN/src/msn.cpp | 28 +--------------------------- protocols/MSN/src/msn_http.cpp | 10 ++++++---- protocols/MSN/src/msn_links.cpp | 6 +++--- protocols/MSN/src/msn_menu.cpp | 37 ++++++++++++------------------------- protocols/MSN/src/msn_proto.h | 7 ++++++- 5 files changed, 28 insertions(+), 60 deletions(-) (limited to 'protocols/MSN/src') diff --git a/protocols/MSN/src/msn.cpp b/protocols/MSN/src/msn.cpp index 71dc64eb4f..bc2d78b797 100644 --- a/protocols/MSN/src/msn.cpp +++ b/protocols/MSN/src/msn.cpp @@ -24,6 +24,7 @@ along with this program. If not, see . #include "msn_proto.h" #include "version.h" +CMPlugin g_plugin; CLIST_INTERFACE *pcli; HINSTANCE g_hInst, g_hOpenssl = nullptr; int hLangpack; @@ -60,8 +61,6 @@ static int sttCompareProtocols(const CMsnProto *p1, const CMsnProto *p2) return mir_wstrcmp(p1->m_tszUserName, p2->m_tszUserName); } -OBJLIST g_Instances(1, sttCompareProtocols); - // Main DLL function extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID) { @@ -114,28 +113,3 @@ extern "C" __declspec(dllexport) const PLUGININFOEX* MirandaPluginInfoEx(DWORD) // MirandaInterfaces - returns the protocol interface to the core extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PROTOCOL, MIID_LAST }; - -///////////////////////////////////////////////////////////////////////////////////////// - -static PROTO_INTERFACE* msnProtoInit(const char *pszProtoName, const wchar_t *tszUserName) -{ - CMsnProto *ppro = new CMsnProto(pszProtoName, tszUserName); - g_Instances.insert(ppro); - return ppro; -} - -static int msnProtoUninit(PROTO_INTERFACE *ppro) -{ - g_Instances.remove((CMsnProto*)ppro); - return 0; -} - -struct CMPlugin : public CMPluginBase -{ - CMPlugin() : - CMPluginBase("MSN") - { - RegisterProtocol(PROTOTYPE_PROTOCOL, msnProtoInit, msnProtoUninit); - } -} - g_plugin; diff --git a/protocols/MSN/src/msn_http.cpp b/protocols/MSN/src/msn_http.cpp index 6acf97a6d4..5c7fb3079d 100644 --- a/protocols/MSN/src/msn_http.cpp +++ b/protocols/MSN/src/msn_http.cpp @@ -25,11 +25,13 @@ along with this program. If not, see . static ThreadData* FindThreadConn(HNETLIBCONN hConn) { - ThreadData *res = nullptr; - for (int i = 0; i < g_Instances.getCount() && res == nullptr; ++i) - res = g_Instances[i].MSN_GetThreadByConnection(hConn); + for (auto &it : CMPlugin::g_arInstances) { + ThreadData *res = it->MSN_GetThreadByConnection(hConn); + if (res != nullptr) + return res; + } - return res; + return nullptr; } //======================================================================================= diff --git a/protocols/MSN/src/msn_links.cpp b/protocols/MSN/src/msn_links.cpp index efbc79408b..dbfe54c4dc 100644 --- a/protocols/MSN/src/msn_links.cpp +++ b/protocols/MSN/src/msn_links.cpp @@ -68,10 +68,10 @@ static INT_PTR ServiceParseMsnimLink(WPARAM, LPARAM lParam) arg = NEWWSTR_ALLOCA(arg); - if (g_Instances.getCount() == 0) return 0; + if (CMPlugin::g_arInstances.getCount() == 0) return 0; - CMsnProto *proto = &g_Instances[0]; - for (auto &it : g_Instances) + CMsnProto *proto = &CMPlugin::g_arInstances[0]; + for (auto &it : CMPlugin::g_arInstances) if (it->m_iStatus > ID_STATUS_OFFLINE) { proto = it; break; diff --git a/protocols/MSN/src/msn_menu.cpp b/protocols/MSN/src/msn_menu.cpp index 65807adcc6..397fabc8ec 100644 --- a/protocols/MSN/src/msn_menu.cpp +++ b/protocols/MSN/src/msn_menu.cpp @@ -186,42 +186,29 @@ void CMsnProto::MSN_EnableMenuItems(bool bEnable) ////////////////////////////////////////////////////////////////////////////////////// -static CMsnProto* GetProtoInstanceByHContact(MCONTACT hContact) +static INT_PTR MsnMenuBlockCommand(WPARAM hContact, LPARAM lParam) { - char* szProto = GetContactProto(hContact); - if (szProto == nullptr) - return nullptr; - - for (auto &it : g_Instances) - if (!mir_strcmp(szProto, it->m_szModuleName)) - return it; - - return nullptr; -} - -static INT_PTR MsnMenuBlockCommand(WPARAM wParam, LPARAM lParam) -{ - CMsnProto* ppro = GetProtoInstanceByHContact(wParam); - return (ppro) ? ppro->MsnBlockCommand(wParam, lParam) : 0; + CMsnProto* ppro = CMPlugin::getInstance(hContact); + return (ppro) ? ppro->MsnBlockCommand(hContact, lParam) : 0; } -static INT_PTR MsnMenuViewProfile(WPARAM wParam, LPARAM lParam) +static INT_PTR MsnMenuViewProfile(WPARAM hContact, LPARAM lParam) { - CMsnProto* ppro = GetProtoInstanceByHContact(wParam); - return (ppro) ? ppro->MsnViewProfile(wParam, lParam) : 0; + CMsnProto* ppro = CMPlugin::getInstance(hContact); + return (ppro) ? ppro->MsnViewProfile(hContact, lParam) : 0; } -static INT_PTR MsnMenuSendHotmail(WPARAM wParam, LPARAM lParam) +static INT_PTR MsnMenuSendHotmail(WPARAM hContact, LPARAM lParam) { - CMsnProto* ppro = GetProtoInstanceByHContact(wParam); - return (ppro) ? ppro->MsnSendHotmail(wParam, lParam) : 0; + CMsnProto* ppro = CMPlugin::getInstance(hContact); + return (ppro) ? ppro->MsnSendHotmail(hContact, lParam) : 0; } -static int MSN_OnPrebuildContactMenu(WPARAM wParam, LPARAM lParam) +static int MSN_OnPrebuildContactMenu(WPARAM hContact, LPARAM lParam) { - CMsnProto* ppro = GetProtoInstanceByHContact(wParam); + CMsnProto* ppro = CMPlugin::getInstance(hContact); if (ppro) - ppro->OnPrebuildContactMenu(wParam, lParam); + ppro->OnPrebuildContactMenu(hContact, lParam); else { Menu_ShowItem(hBlockMenuItem, false); Menu_ShowItem(hLiveSpaceMenuItem, false); diff --git a/protocols/MSN/src/msn_proto.h b/protocols/MSN/src/msn_proto.h index 511c311b0f..ece0e0d6a2 100644 --- a/protocols/MSN/src/msn_proto.h +++ b/protocols/MSN/src/msn_proto.h @@ -492,6 +492,11 @@ struct CMsnProto : public PROTO void setStringUtf(MCONTACT hContact, const char* name, const char* value); }; -extern OBJLIST g_Instances; +struct CMPlugin : public ACCPROTOPLUGIN +{ + CMPlugin() : + ACCPROTOPLUGIN("MSN") + {} +}; #endif -- cgit v1.2.3