-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathinterface.cpp
76 lines (68 loc) · 2 KB
/
interface.cpp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <jni.h>
#include "interfaces.h"
#include "mod/logger.h"
#define _IAML // Do not include "interface" twice!
#include "modslist.h"
#include "mod/listitem.h"
class Interfaces;
Interfaces* listInterfaces = NULL;
LIST_START(Interfaces)
LIST_INITSTART(Interfaces)
pInterface = NULL;
szName[0] = 0;
LIST_INITEND()
static void AddNew(const char* name, void* interface)
{
Interfaces* newItem = new Interfaces;
newItem->pInterface = interface;
strxcpy(newItem->szName, name, 48);
newItem->Push(&listInterfaces);
}
static void* Get(const char* name)
{
LIST_FOR_FAST(listInterfaces)
{
if (!strcmp(item->szName, name)) return item->pInterface;
}
return NULL;
}
void* pInterface;
char szName[48];
LIST_END()
void InterfaceSys::Register(const char* szInterfaceName, void* pInterfacePointer)
{
if(szInterfaceName == NULL)
{
logger->Error("Failed to add unknown interface to the list because it`s NULL!");
return;
}
if(pInterfacePointer == NULL)
{
logger->Error("Failed to add interface %s to the list because it`s NULL!", szInterfaceName);
return;
}
if(Interfaces::Get(szInterfaceName) != NULL)
{
logger->Error("Failed to add interface %s to the list because it`s already registered!", szInterfaceName);
return;
}
Interfaces::AddNew(szInterfaceName, pInterfacePointer);
modlist->OnInterfaceAdded(szInterfaceName, pInterfacePointer);
}
void* InterfaceSys::Get(const char* szInterfaceName)
{
return Interfaces::Get(szInterfaceName);
}
static InterfaceSys interfacesLocal;
InterfaceSys* interfaces = &interfacesLocal;
extern "C"
{
JNIEXPORT void* GetInterface(const char* szInterfaceName)
{
return interfacesLocal.Get(szInterfaceName);
}
JNIEXPORT void CreateInterface(const char* szInterfaceName, void* pInterface)
{
return interfacesLocal.Register(szInterfaceName, pInterface);
}
}