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/Twitter/src/main.cpp | 36 +----------------------------------- protocols/Twitter/src/proto.h | 7 +++++++ protocols/Twitter/src/theme.cpp | 26 ++++++-------------------- 3 files changed, 14 insertions(+), 55 deletions(-) (limited to 'protocols/Twitter/src') diff --git a/protocols/Twitter/src/main.cpp b/protocols/Twitter/src/main.cpp index a4e714ba7e..14e91dc39e 100644 --- a/protocols/Twitter/src/main.cpp +++ b/protocols/Twitter/src/main.cpp @@ -22,6 +22,7 @@ along with this program. If not, see . #include "proto.h" #include "theme.h" +CMPlugin g_plugin; CLIST_INTERFACE* pcli; HINSTANCE g_hInstance; @@ -40,16 +41,6 @@ PLUGININFOEX pluginInfo = { { 0xbc09a71b, 0xb86e, 0x4d33, { 0xb1, 0x8d, 0x82, 0xd3, 0x4, 0x51, 0xdd, 0x3c } } }; -///////////////////////////////////////////////////////////////////////////// -// Protocol instances - -static int compare_protos(const TwitterProto *p1, const TwitterProto *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; @@ -87,28 +78,3 @@ extern "C" int __declspec(dllexport) Unload(void) { return 0; } - -///////////////////////////////////////////////////////////////////////////////////////// - -static PROTO_INTERFACE* protoInit(const char *proto_name, const wchar_t *username) -{ - TwitterProto *proto = new TwitterProto(proto_name, username); - g_Instances.insert(proto); - return proto; -} - -static int protoUninit(PROTO_INTERFACE *proto) -{ - g_Instances.remove(static_cast(proto)); - return 0; -} - -struct CMPlugin : public CMPluginBase -{ - CMPlugin() : - CMPluginBase("Twitter") - { - RegisterProtocol(PROTOTYPE_PROTOCOL, protoInit, protoUninit); - } -} - g_plugin; diff --git a/protocols/Twitter/src/proto.h b/protocols/Twitter/src/proto.h index 46facedcc2..a73b5caacc 100644 --- a/protocols/Twitter/src/proto.h +++ b/protocols/Twitter/src/proto.h @@ -129,6 +129,13 @@ private: wstring AuthorizeUrl; }; +struct CMPlugin : public ACCPROTOPLUGIN +{ + CMPlugin() : + ACCPROTOPLUGIN("Twitter") + {} +}; + // TODO: remove this inline std::string profile_base_url(const std::string &url) { diff --git a/protocols/Twitter/src/theme.cpp b/protocols/Twitter/src/theme.cpp index ca6338edc7..75c5252f34 100644 --- a/protocols/Twitter/src/theme.cpp +++ b/protocols/Twitter/src/theme.cpp @@ -20,8 +20,6 @@ along with this program. If not, see . #include "theme.h" #include "proto.h" -extern OBJLIST g_Instances; - static IconItem icons[] = { { LPGEN("Twitter Icon"), "twitter", IDI_TWITTER }, @@ -57,32 +55,20 @@ HANDLE GetIconHandle(const char *name) static HGENMENU g_hMenuItems[2]; // Helper functions -static TwitterProto* 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) +INT_PTR GlobalService(WPARAM hContact, LPARAM lParam) { - TwitterProto *proto = GetInstanceByHContact(MCONTACT(wParam)); - return proto ? (proto->*Fcn)(wParam, lParam) : 0; + TwitterProto *proto = CMPlugin::getInstance(MCONTACT(hContact)); + return proto ? (proto->*Fcn)(hContact, lParam) : 0; } -static int PrebuildContactMenu(WPARAM wParam, LPARAM lParam) +static int PrebuildContactMenu(WPARAM hContact, LPARAM lParam) { ShowContactMenus(false); - TwitterProto *proto = GetInstanceByHContact(MCONTACT(wParam)); - return proto ? proto->OnPrebuildContactMenu(wParam, lParam) : 0; + TwitterProto *proto = CMPlugin::getInstance(MCONTACT(hContact)); + return proto ? proto->OnPrebuildContactMenu(hContact, lParam) : 0; } void InitContactMenus() -- cgit v1.2.3