diff options
author | George Hazan <ghazan@miranda.im> | 2018-03-28 16:34:30 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-03-28 16:34:30 +0300 |
commit | 81ce57622c3166830b23eae534dacc6b008c659d (patch) | |
tree | 6d6ac74667f733a20b94fa27cc01c2f45688c533 /protocols/IRCG | |
parent | c2bb7727483b9b5620e8cc0ce6adae35ee78d0a4 (diff) |
common protocol instance management code went into template
Diffstat (limited to 'protocols/IRCG')
-rw-r--r-- | protocols/IRCG/src/irclib.cpp | 2 | ||||
-rw-r--r-- | protocols/IRCG/src/main.cpp | 34 | ||||
-rw-r--r-- | protocols/IRCG/src/services.cpp | 43 | ||||
-rw-r--r-- | protocols/IRCG/src/stdafx.h | 9 |
4 files changed, 24 insertions, 64 deletions
diff --git a/protocols/IRCG/src/irclib.cpp b/protocols/IRCG/src/irclib.cpp index 28db677271..1dea025bbe 100644 --- a/protocols/IRCG/src/irclib.cpp +++ b/protocols/IRCG/src/irclib.cpp @@ -1412,7 +1412,7 @@ LBL_Parse: if (iParamCnt != 2) cbLen = mir_snprintf(buf, "%s : ERROR : UNKNOWN-ERROR\r\n", szBuf); else { - for (auto &it : g_Instances) + for (auto &it : CMPlugin::g_arInstances) if (PeerPortNrRcvd == it->m_info.iPort && LocalPortNrRcvd == it->m_myLocalPort) { cbLen = mir_snprintf(buf, "%s : USERID : %S : %S\r\n", szBuf, it->m_info.sIdentServerType.c_str(), it->m_info.sUserID.c_str()); diff --git a/protocols/IRCG/src/main.cpp b/protocols/IRCG/src/main.cpp index 81ff6f6581..1dd78c6e77 100644 --- a/protocols/IRCG/src/main.cpp +++ b/protocols/IRCG/src/main.cpp @@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h"
#include "version.h"
+CMPlugin g_plugin;
CHAT_MANAGER *pci;
CLIST_INTERFACE *pcli;
HINSTANCE hInst = nullptr;
@@ -35,13 +36,6 @@ static int CompareServers( const SERVER_INFO* p1, const SERVER_INFO* p2 ) OBJLIST<SERVER_INFO> g_servers( 20, CompareServers );
-static int sttCompareProtocols(const CIrcProto *p1, const CIrcProto *p2)
-{
- return mir_strcmp(p1->m_szModuleName, p2->m_szModuleName);
-}
-
-LIST<CIrcProto> g_Instances(1, sttCompareProtocols);
-
void UninitTimers( void );
// Information about the plugin
@@ -93,29 +87,3 @@ extern "C" int __declspec(dllexport) Unload(void) UninitTimers();
return 0;
}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
-static PROTO_INTERFACE* ircProtoInit(const char* pszProtoName, const wchar_t* tszUserName)
-{
- CIrcProto *ppro = new CIrcProto(pszProtoName, tszUserName);
- g_Instances.insert(ppro);
- return ppro;
-}
-
-static int ircProtoUninit(PROTO_INTERFACE *ppro)
-{
- g_Instances.remove((CIrcProto*)ppro);
- delete (CIrcProto*)ppro;
- return 0;
-}
-
-struct CMPlugin : public CMPluginBase
-{
- CMPlugin() :
- CMPluginBase("IRC")
- {
- RegisterProtocol(PROTOTYPE_PROTOCOL, ircProtoInit, ircProtoUninit);
- }
-}
- g_plugin;
diff --git a/protocols/IRCG/src/services.cpp b/protocols/IRCG/src/services.cpp index 1bb2274f9c..b6775b8b05 100644 --- a/protocols/IRCG/src/services.cpp +++ b/protocols/IRCG/src/services.cpp @@ -64,52 +64,39 @@ void CIrcProto::InitMainMenus(void) static HGENMENU hUMenuChanSettings, hUMenuWhois, hUMenuDisconnect, hUMenuIgnore;
-static CIrcProto* IrcGetInstanceByHContact(MCONTACT hContact)
+static INT_PTR IrcMenuChanSettings(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 IrcMenuChanSettings(WPARAM wParam, LPARAM lParam)
-{
- CIrcProto *ppro = IrcGetInstanceByHContact(wParam);
- return (ppro) ? ppro->OnMenuChanSettings(wParam, lParam) : 0;
+ CIrcProto *ppro = CMPlugin::getInstance(hContact);
+ return (ppro) ? ppro->OnMenuChanSettings(hContact, lParam) : 0;
}
-static INT_PTR IrcMenuWhois(WPARAM wParam, LPARAM lParam)
+static INT_PTR IrcMenuWhois(WPARAM hContact, LPARAM lParam)
{
- CIrcProto *ppro = IrcGetInstanceByHContact(wParam);
- return (ppro) ? ppro->OnMenuWhois(wParam, lParam) : 0;
+ CIrcProto *ppro = CMPlugin::getInstance(hContact);
+ return (ppro) ? ppro->OnMenuWhois(hContact, lParam) : 0;
}
-static INT_PTR IrcMenuDisconnect(WPARAM wParam, LPARAM lParam)
+static INT_PTR IrcMenuDisconnect(WPARAM hContact, LPARAM lParam)
{
- CIrcProto *ppro = IrcGetInstanceByHContact(wParam);
- return (ppro) ? ppro->OnMenuDisconnect(wParam, lParam) : 0;
+ CIrcProto *ppro = CMPlugin::getInstance(hContact);
+ return (ppro) ? ppro->OnMenuDisconnect(hContact, lParam) : 0;
}
-static INT_PTR IrcMenuIgnore(WPARAM wParam, LPARAM lParam)
+static INT_PTR IrcMenuIgnore(WPARAM hContact, LPARAM lParam)
{
- CIrcProto *ppro = IrcGetInstanceByHContact(wParam);
- return (ppro) ? ppro->OnMenuIgnore(wParam, lParam) : 0;
+ CIrcProto *ppro = CMPlugin::getInstance(hContact);
+ return (ppro) ? ppro->OnMenuIgnore(hContact, lParam) : 0;
}
-int IrcPrebuildContactMenu(WPARAM wParam, LPARAM lParam)
+int IrcPrebuildContactMenu(WPARAM hContact, LPARAM lParam)
{
Menu_ShowItem(hUMenuChanSettings, false);
Menu_ShowItem(hUMenuWhois, false);
Menu_ShowItem(hUMenuDisconnect, false);
Menu_ShowItem(hUMenuIgnore, false);
- CIrcProto *ppro = IrcGetInstanceByHContact(wParam);
- return (ppro) ? ppro->OnMenuPreBuild(wParam, lParam) : 0;
+ CIrcProto *ppro = CMPlugin::getInstance(hContact);
+ return (ppro) ? ppro->OnMenuPreBuild(hContact, lParam) : 0;
}
void InitContactMenus(void)
diff --git a/protocols/IRCG/src/stdafx.h b/protocols/IRCG/src/stdafx.h index eef1cb6a10..6b0f5e659e 100644 --- a/protocols/IRCG/src/stdafx.h +++ b/protocols/IRCG/src/stdafx.h @@ -587,6 +587,13 @@ private: CMStringW sNick4Perform;
};
+struct CMPlugin : public ACCPROTOPLUGIN<CIrcProto>
+{
+ CMPlugin() :
+ ACCPROTOPLUGIN<CIrcProto>("IRC")
+ {}
+};
+
// map actual member functions to their associated IRC command.
// put any number of this macro in the class's constructor.
#define IRC_MAP_ENTRY(name, member) \
@@ -598,8 +605,6 @@ private: //main.cpp
extern HINSTANCE hInst;
-extern LIST<CIrcProto> g_Instances;
-
extern OBJLIST<SERVER_INFO> g_servers;
CIrcProto* GetTimerOwner(UINT_PTR eventId);
|