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/Gadu-Gadu/src | |
parent | c2bb7727483b9b5620e8cc0ce6adae35ee78d0a4 (diff) |
common protocol instance management code went into template
Diffstat (limited to 'protocols/Gadu-Gadu/src')
-rw-r--r-- | protocols/Gadu-Gadu/src/gg.cpp | 47 | ||||
-rw-r--r-- | protocols/Gadu-Gadu/src/gg.h | 1 | ||||
-rw-r--r-- | protocols/Gadu-Gadu/src/gg_proto.h | 6 | ||||
-rw-r--r-- | protocols/Gadu-Gadu/src/libgadu/libgadu.cpp | 4 | ||||
-rw-r--r-- | protocols/Gadu-Gadu/src/links.cpp | 6 |
5 files changed, 13 insertions, 51 deletions
diff --git a/protocols/Gadu-Gadu/src/gg.cpp b/protocols/Gadu-Gadu/src/gg.cpp index 31ba420df2..8aeffc1391 100644 --- a/protocols/Gadu-Gadu/src/gg.cpp +++ b/protocols/Gadu-Gadu/src/gg.cpp @@ -38,12 +38,12 @@ PLUGININFOEX pluginInfo = { };
// Other variables
+CMPlugin g_plugin;
HINSTANCE hInstance;
SSL_API sslApi;
CLIST_INTERFACE *pcli;
int hLangpack;
-LIST<GaduProto> g_Instances(1, PtrKeySortT);
static unsigned long crc_table[256];
@@ -214,27 +214,11 @@ static int gg_modulesloaded(WPARAM, LPARAM) }
//////////////////////////////////////////////////////////
-// Gets protocol instance associated with a contact
-//
-static GaduProto* gg_getprotoinstance(MCONTACT hContact)
-{
- char* szProto = GetContactProto(hContact);
- if (szProto == nullptr)
- return nullptr;
-
- for (auto &it : g_Instances)
- if (mir_strcmp(szProto, it->m_szModuleName) == 0)
- return it;
-
- return nullptr;
-}
-
-//////////////////////////////////////////////////////////
// Handles PrebuildContactMenu event
//
static int gg_prebuildcontactmenu(WPARAM hContact, LPARAM)
{
- GaduProto* gg = gg_getprotoinstance(hContact);
+ GaduProto* gg = CMPlugin::getInstance(hContact);
if (gg == nullptr)
return 0;
@@ -437,30 +421,3 @@ BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD, LPVOID) #endif
return TRUE;
}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
-static PROTO_INTERFACE* gg_proto_init(const char *pszProtoName, const wchar_t *tszUserName)
-{
- GaduProto *gg = new GaduProto(pszProtoName, tszUserName);
- g_Instances.insert(gg);
- return gg;
-}
-
-static int gg_proto_uninit(PROTO_INTERFACE *proto)
-{
- GaduProto *gg = (GaduProto*)proto;
- g_Instances.remove(gg);
- delete gg;
- return 0;
-}
-
-struct CMPlugin : public CMPluginBase
-{
- CMPlugin() :
- CMPluginBase(GGDEF_PROTO)
- {
- RegisterProtocol(PROTOTYPE_PROTOCOL, gg_proto_init, gg_proto_uninit);
- }
-}
- g_plugin;
diff --git a/protocols/Gadu-Gadu/src/gg.h b/protocols/Gadu-Gadu/src/gg.h index 558c3227d3..2e74058d02 100644 --- a/protocols/Gadu-Gadu/src/gg.h +++ b/protocols/Gadu-Gadu/src/gg.h @@ -260,7 +260,6 @@ struct GaduProto; extern HINSTANCE hInstance;
extern CLIST_INTERFACE *pcli;
-extern LIST<GaduProto> g_Instances;
extern PLUGININFOEX pluginInfo;
extern IconItem iconList[];
extern SSL_API sslApi;
diff --git a/protocols/Gadu-Gadu/src/gg_proto.h b/protocols/Gadu-Gadu/src/gg_proto.h index 543c936ea4..ff973f010d 100644 --- a/protocols/Gadu-Gadu/src/gg_proto.h +++ b/protocols/Gadu-Gadu/src/gg_proto.h @@ -309,5 +309,11 @@ inline void GaduProto::gg_sleep(DWORD miliseconds, BOOL alterable, char* calling #endif
}
+struct CMPlugin : public ACCPROTOPLUGIN<GaduProto>
+{
+ CMPlugin() :
+ ACCPROTOPLUGIN<GaduProto>(GGDEF_PROTO)
+ {}
+};
#endif
diff --git a/protocols/Gadu-Gadu/src/libgadu/libgadu.cpp b/protocols/Gadu-Gadu/src/libgadu/libgadu.cpp index edfc7fd034..931d55810d 100644 --- a/protocols/Gadu-Gadu/src/libgadu/libgadu.cpp +++ b/protocols/Gadu-Gadu/src/libgadu/libgadu.cpp @@ -565,8 +565,8 @@ void *gg_recv_packet(struct gg_session *sess) h.type = gg_fix32(h.type);
h.length = gg_fix32(h.length);
- } else
- memcpy(&h, sess->recv_buf, sizeof(h));
+ }
+ else memcpy(&h, sess->recv_buf, sizeof(h));
/* jakieÅ› sensowne limity na rozmiar pakietu */
if (h.length > 65535) {
diff --git a/protocols/Gadu-Gadu/src/links.cpp b/protocols/Gadu-Gadu/src/links.cpp index 295e9dbcf2..4d95b0fc01 100644 --- a/protocols/Gadu-Gadu/src/links.cpp +++ b/protocols/Gadu-Gadu/src/links.cpp @@ -41,7 +41,7 @@ static INT_PTR gg_parselink(WPARAM, LPARAM lParam) {
char *arg = (char*)lParam;
- if (g_Instances.getCount() == 0)
+ if (CMPlugin::g_arInstances.getCount() == 0)
return 0;
if (arg == nullptr)
@@ -60,7 +60,7 @@ static INT_PTR gg_parselink(WPARAM, LPARAM lParam) GaduProto *gg = nullptr;
int items = 0;
- for (auto &it : g_Instances) {
+ for (auto &it : CMPlugin::g_arInstances) {
gg = it;
if (it->m_iStatus > ID_STATUS_OFFLINE) {
++items;
@@ -117,7 +117,7 @@ void GaduProto::links_instance_init() if (ServiceExists(MS_ASSOCMGR_ADDNEWURLTYPE)) {
CMenuItem mi;
mi.flags = CMIF_UNICODE;
- mi.position = g_Instances.getCount();
+ mi.position = CMPlugin::g_arInstances.getCount();
mi.name.w = m_tszUserName;
hInstanceMenuItem = Menu_AddItem(hInstanceMenu, &mi, this);
}
|