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/FacebookRM/src/main.cpp | 35 +---------------------------------- protocols/FacebookRM/src/proto.h | 7 +++++++ protocols/FacebookRM/src/theme.cpp | 19 ++----------------- 3 files changed, 10 insertions(+), 51 deletions(-) (limited to 'protocols/FacebookRM/src') diff --git a/protocols/FacebookRM/src/main.cpp b/protocols/FacebookRM/src/main.cpp index 28bc66d172..2e7f7849dd 100644 --- a/protocols/FacebookRM/src/main.cpp +++ b/protocols/FacebookRM/src/main.cpp @@ -24,6 +24,7 @@ along with this program. If not, see . // TODO: Make following as "globals" structure? +CMPlugin g_plugin; CLIST_INTERFACE *pcli; int hLangpack; @@ -44,15 +45,6 @@ PLUGININFOEX pluginInfo = { { 0x8432b009, 0xff32, 0x4727, { 0xaa, 0xe6, 0xa9, 0x3, 0x50, 0x38, 0xfd, 0x58 } } }; -///////////////////////////////////////////////////////////////////////////// -// Protocol instances -static int compare_protos(const FacebookProto *p1, const FacebookProto *p2) -{ - return mir_wstrcmp(p1->m_tszUserName, p2->m_tszUserName); -} - -OBJLIST g_Instances(1, compare_protos); - DWORD WINAPI DllMain(HINSTANCE hInstance, DWORD, LPVOID) { g_hInstance = hInstance; @@ -73,19 +65,6 @@ extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PROTOC ///////////////////////////////////////////////////////////////////////////////////////// // Load -static PROTO_INTERFACE* protoInit(const char *proto_name, const wchar_t *username) -{ - FacebookProto *proto = new FacebookProto(proto_name, username); - g_Instances.insert(proto); - return proto; -} - -static int protoUninit(PROTO_INTERFACE* proto) -{ - g_Instances.remove((FacebookProto*)proto); - return EXIT_SUCCESS; -} - extern "C" int __declspec(dllexport) Load(void) { mir_getLP(&pluginInfo); @@ -120,15 +99,3 @@ extern "C" int __declspec(dllexport) Unload(void) { return 0; } - -///////////////////////////////////////////////////////////////////////////////////////// - -struct CMPlugin : public CMPluginBase -{ - CMPlugin() : - CMPluginBase(FACEBOOK_NAME) - { - RegisterProtocol(PROTOTYPE_PROTOCOL, protoInit, protoUninit); - } -} - g_plugin; diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h index 98262699ff..8f4b547e61 100644 --- a/protocols/FacebookRM/src/proto.h +++ b/protocols/FacebookRM/src/proto.h @@ -286,3 +286,10 @@ public: HWND NotifyEvent(wchar_t* title, wchar_t* text, MCONTACT contact, EventType type, std::string *url = nullptr, std::string *notification_id = nullptr, const char *icon = nullptr); void ShowNotifications(); }; + +struct CMPlugin : public ACCPROTOPLUGIN +{ + CMPlugin() : + ACCPROTOPLUGIN(FACEBOOK_NAME) + {} +}; diff --git a/protocols/FacebookRM/src/theme.cpp b/protocols/FacebookRM/src/theme.cpp index 91d7931076..ce5fb25df3 100644 --- a/protocols/FacebookRM/src/theme.cpp +++ b/protocols/FacebookRM/src/theme.cpp @@ -22,8 +22,6 @@ along with this program. If not, see . #include "stdafx.h" -extern OBJLIST g_Instances; - // Contact menu items HGENMENU g_hContactMenuVisitProfile; HGENMENU g_hContactMenuVisitFriendship; @@ -69,23 +67,10 @@ HANDLE GetIconHandle(const char* name) } // Helper functions -static FacebookProto * GetInstanceByHContact(MCONTACT hContact) -{ - char *proto = GetContactProto(hContact); - if (!proto) - return nullptr; - - for (auto &it : g_Instances) - if (!mir_strcmp(proto, it->m_szModuleName)) - return it; - - return nullptr; -} - template INT_PTR GlobalService(WPARAM wParam, LPARAM lParam) { - FacebookProto *proto = GetInstanceByHContact(MCONTACT(wParam)); + FacebookProto *proto = CMPlugin::getInstance(MCONTACT(wParam)); return proto ? (proto->*Fcn)(wParam, lParam) : 0; } @@ -102,7 +87,7 @@ static int PrebuildContactMenu(WPARAM wParam, LPARAM lParam) Menu_ShowItem(g_hContactMenuLoadHistory, false); // Process them in correct account - FacebookProto *proto = GetInstanceByHContact(MCONTACT(wParam)); + FacebookProto *proto = CMPlugin::getInstance(MCONTACT(wParam)); return proto ? proto->OnPrebuildContactMenu(wParam, lParam) : 0; } -- cgit v1.2.3