summaryrefslogtreecommitdiff
path: root/protocols/Tox/src/tox_instances.cpp
blob: ea010f894af43f078b9567ba05f5534d4d7cae5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "common.h"

LIST<CToxProto> CToxProto::instanceList(1, CToxProto::CompareProtos);

int CToxProto::CompareProtos(const CToxProto *p1, const CToxProto *p2)
{
	return wcscmp(p1->m_tszUserName, p2->m_tszUserName);
}

CToxProto* CToxProto::InitProtoInstance(const char* protoName, const wchar_t* userName)
{
	CToxProto *ppro = new CToxProto(protoName, userName);
	CToxProto::instanceList.insert(ppro);

	return ppro;
}

int CToxProto::UninitProtoInstance(CToxProto* ppro)
{
	CToxProto::instanceList.remove(ppro);

	delete ppro;

	return 0;
}

void CToxProto::UninitInstances()
{
	CToxProto::instanceList.destroy();
}

CToxProto* CToxProto::GetContactInstance(MCONTACT hContact)
{
	char *proto = (char *)::CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);

	if (proto == NULL)
		return NULL;

	for (int i = 0; i < CToxProto::instanceList.getCount(); i++)
		if ( !::strcmp(proto, CToxProto::instanceList[i]->m_szModuleName))
			return CToxProto::instanceList[i];

	return NULL;
}