author | Medo <smaxein@googlemail.com> |
Thu, 07 Jun 2012 02:45:18 +0200 | |
changeset 7175 | 038e3415100a |
parent 7173 | 7c2eb284f9f1 |
child 7177 | bf6cf4dd847a |
permissions | -rw-r--r-- |
7173
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
1 |
#include "ipc.h" |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
2 |
#include "ipcconn.h" |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
3 |
#include "logging.h" |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
4 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
5 |
#include <stdbool.h> |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
6 |
#include <stdlib.h> |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
7 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
8 |
typedef struct _flib_ipc { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
9 |
flib_ipcconn connection; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
10 |
IpcConnState oldConnState; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
11 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
12 |
void (*onConnectCb)(void*); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
13 |
void *onConnectCtx; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
14 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
15 |
void (*onDisconnectCb)(void*); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
16 |
void *onDisconnectCtx; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
17 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
18 |
void (*onConfigQueryCb)(void*); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
19 |
void *onConfigQueryCtx; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
20 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
21 |
void (*onEngineErrorCb)(void*, const uint8_t*); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
22 |
void *onEngineErrorCtx; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
23 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
24 |
void (*onGameEndCb)(void*, int); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
25 |
void *onGameEndCtx; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
26 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
27 |
void (*onChatCb)(void*, const uint8_t*, int); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
28 |
void *onChatCtx; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
29 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
30 |
void (*onEngineMessageCb)(void*, const uint8_t*, int); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
31 |
void *onEngineMessageCtx; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
32 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
33 |
bool running; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
34 |
bool destroyRequested; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
35 |
} _flib_ipc; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
36 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
37 |
static void emptyCallback(void* ptr) {} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
38 |
static void emptyCallback_int(void* ptr, int i) {} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
39 |
static void emptyCallback_str(void* ptr, const uint8_t* str) {} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
40 |
static void emptyCallback_str_int(void* ptr, const uint8_t* str, int i) {} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
41 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
42 |
static void clearCallbacks(flib_ipc ipc) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
43 |
ipc->onConnectCb = &emptyCallback; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
44 |
ipc->onDisconnectCb = &emptyCallback; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
45 |
ipc->onConfigQueryCb = &emptyCallback; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
46 |
ipc->onEngineErrorCb = &emptyCallback_str; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
47 |
ipc->onGameEndCb = &emptyCallback_int; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
48 |
ipc->onChatCb = &emptyCallback_str_int; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
49 |
ipc->onEngineMessageCb = &emptyCallback_str_int; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
50 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
51 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
52 |
flib_ipc flib_ipc_create(bool recordDemo, const char *localPlayerName) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
53 |
flib_ipc result = malloc(sizeof(_flib_ipc)); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
54 |
flib_ipcconn connection = flib_ipcconn_create(recordDemo, localPlayerName); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
55 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
56 |
if(!result || !connection) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
57 |
free(result); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
58 |
flib_ipcconn_destroy(&connection); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
59 |
return NULL; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
60 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
61 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
62 |
result->connection = connection; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
63 |
result->oldConnState = IPC_LISTENING; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
64 |
result->running = false; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
65 |
result->destroyRequested = false; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
66 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
67 |
clearCallbacks(result); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
68 |
return result; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
69 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
70 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
71 |
void flib_ipc_destroy(flib_ipc *ipcptr) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
72 |
if(!ipcptr || !*ipcptr) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
73 |
return; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
74 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
75 |
flib_ipc ipc = *ipcptr; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
76 |
if(ipc->running) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
77 |
// The function was called from a callback of this ipc connection, |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
78 |
// so the tick function is still running and we delay the actual |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
79 |
// destruction. We ensure no further callbacks will be sent to prevent |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
80 |
// surprises. |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
81 |
clearCallbacks(ipc); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
82 |
ipc->destroyRequested = true; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
83 |
} else { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
84 |
flib_ipcconn_destroy(&ipc->connection); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
85 |
free(ipc); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
86 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
87 |
*ipcptr = NULL; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
88 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
89 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
90 |
void flib_ipc_onConnect(flib_ipc ipc, void (*callback)(void* context), void* context) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
91 |
if(!ipc) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
92 |
flib_log_w("Call to flib_ipc_onConnect with ipc==null"); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
93 |
return; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
94 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
95 |
ipc->onConnectCb = callback ? callback : &emptyCallback; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
96 |
ipc->onConnectCtx = context; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
97 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
98 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
99 |
void flib_ipc_onDisconnect(flib_ipc ipc, void (*callback)(void* context), void* context) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
100 |
if(!ipc) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
101 |
flib_log_w("Call to flib_ipc_onDisconnect with ipc==null"); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
102 |
return; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
103 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
104 |
ipc->onDisconnectCb = callback ? callback : &emptyCallback; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
105 |
ipc->onDisconnectCtx = context; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
106 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
107 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
108 |
void flib_ipc_onConfigQuery(flib_ipc ipc, void (*callback)(void* context), void* context) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
109 |
if(!ipc) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
110 |
flib_log_w("Call to flib_ipc_onConfigQuery with ipc==null"); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
111 |
return; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
112 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
113 |
ipc->onConfigQueryCb = callback ? callback : &emptyCallback; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
114 |
ipc->onConfigQueryCtx = context; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
115 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
116 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
117 |
void flib_ipc_onEngineError(flib_ipc ipc, void (*callback)(void* context, const uint8_t *error), void* context) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
118 |
if(!ipc) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
119 |
flib_log_w("Call to flib_ipc_onEngineError with ipc==null"); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
120 |
return; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
121 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
122 |
ipc->onEngineErrorCb = callback ? callback : &emptyCallback_str; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
123 |
ipc->onEngineErrorCtx = context; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
124 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
125 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
126 |
void flib_ipc_onGameEnd(flib_ipc ipc, void (*callback)(void* context, int gameEndType), void* context) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
127 |
if(!ipc) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
128 |
flib_log_w("Call to flib_ipc_onGameEnd with ipc==null"); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
129 |
return; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
130 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
131 |
ipc->onGameEndCb = callback ? callback : &emptyCallback_int; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
132 |
ipc->onGameEndCtx = context; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
133 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
134 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
135 |
void flib_ipc_onChat(flib_ipc ipc, void (*callback)(void* context, const uint8_t *messagestr, int teamchat), void* context) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
136 |
if(!ipc) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
137 |
flib_log_w("Call to flib_ipc_onChat with ipc==null"); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
138 |
return; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
139 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
140 |
ipc->onChatCb = callback ? callback : &emptyCallback_str_int; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
141 |
ipc->onChatCtx = context; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
142 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
143 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
144 |
void flib_ipc_onEngineMessage(flib_ipc ipc, void (*callback)(void* context, const uint8_t *message, int len), void* context) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
145 |
if(!ipc) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
146 |
flib_log_w("Call to flib_ipc_onEngineMessage with ipc==null"); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
147 |
return; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
148 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
149 |
ipc->onEngineMessageCb = callback ? callback : &emptyCallback_str_int; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
150 |
ipc->onEngineMessageCtx = context; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
151 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
152 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
153 |
static void flib_ipc_wrappedtick(flib_ipc ipc) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
154 |
if(ipc->oldConnState == IPC_NOT_CONNECTED) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
155 |
return; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
156 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
157 |
|
7175
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
158 |
if(ipc->oldConnState == IPC_LISTENING) { |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
159 |
flib_ipcconn_accept(ipc->connection); |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
160 |
if(flib_ipcconn_state(ipc->connection) == IPC_CONNECTED) { |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
161 |
ipc->oldConnState = IPC_CONNECTED; |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
162 |
ipc->onConnectCb(ipc->onConnectCtx); |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
163 |
} |
7173
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
164 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
165 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
166 |
if(ipc->oldConnState == IPC_CONNECTED) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
167 |
uint8_t msgbuffer[257]; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
168 |
int len; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
169 |
while(!ipc->destroyRequested && (len = flib_ipcconn_recv_message(ipc->connection, msgbuffer))>=0) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
170 |
if(len<2) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
171 |
flib_log_w("Received short message from IPC (<2 bytes)"); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
172 |
continue; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
173 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
174 |
msgbuffer[len] = 0; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
175 |
flib_log_i("[IPC in] %s", msgbuffer+1); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
176 |
switch(msgbuffer[1]) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
177 |
case '?': |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
178 |
flib_ipcconn_send_messagestr(ipc->connection, "!"); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
179 |
break; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
180 |
case 'C': |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
181 |
ipc->onConfigQueryCb(ipc->onConfigQueryCtx); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
182 |
break; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
183 |
case 'E': |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
184 |
if(len>=3) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
185 |
msgbuffer[len-2] = 0; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
186 |
ipc->onEngineErrorCb(ipc->onEngineErrorCtx, msgbuffer+2); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
187 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
188 |
break; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
189 |
case 'i': |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
190 |
// TODO |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
191 |
break; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
192 |
case 'Q': |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
193 |
ipc->onGameEndCb(ipc->onGameEndCtx, GAME_END_INTERRUPTED); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
194 |
break; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
195 |
case 'q': |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
196 |
ipc->onGameEndCb(ipc->onGameEndCtx, GAME_END_FINISHED); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
197 |
break; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
198 |
case 'H': |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
199 |
ipc->onGameEndCb(ipc->onGameEndCtx, GAME_END_HALTED); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
200 |
break; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
201 |
case 's': |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
202 |
if(len>=3) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
203 |
msgbuffer[len-2] = 0; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
204 |
ipc->onChatCb(ipc->onChatCtx, msgbuffer+2, 0); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
205 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
206 |
break; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
207 |
case 'b': |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
208 |
if(len>=3) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
209 |
msgbuffer[len-2] = 0; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
210 |
ipc->onChatCb(ipc->onChatCtx, msgbuffer+2, 1); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
211 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
212 |
break; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
213 |
default: |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
214 |
ipc->onEngineMessageCb(ipc->onEngineMessageCtx, msgbuffer, len); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
215 |
break; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
216 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
217 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
218 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
219 |
|
7175
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
220 |
if(flib_ipcconn_state(ipc->connection) == IPC_NOT_CONNECTED) { |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
221 |
ipc->oldConnState = IPC_NOT_CONNECTED; |
7173
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
222 |
ipc->onDisconnectCb(ipc->onDisconnectCtx); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
223 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
224 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
225 |
|
7175
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
226 |
void flib_ipc_tick(flib_ipc ipc) { |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
227 |
if(!ipc) { |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
228 |
flib_log_w("Call to flib_ipc_tick with ipc==null"); |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
229 |
return; |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
230 |
} |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
231 |
if(ipc->running) { |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
232 |
flib_log_w("Call to flib_ipc_tick from a callback"); |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
233 |
return; |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
234 |
} |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
235 |
|
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
236 |
ipc->running = true; |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
237 |
flib_ipc_wrappedtick(ipc); |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
238 |
ipc->running = false; |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
239 |
|
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
240 |
if(ipc->destroyRequested) { |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
241 |
flib_ipc_destroy(&ipc); |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
242 |
} |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
243 |
} |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
244 |
|
7173
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
245 |
int flib_ipc_send_raw(flib_ipc ipc, void *data, size_t len) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
246 |
if(!ipc) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
247 |
flib_log_w("Call to flib_ipc_send_raw with ipc==null"); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
248 |
return -1; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
249 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
250 |
return flib_ipcconn_send_raw(ipc->connection, data, len); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
251 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
252 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
253 |
int flib_ipc_send_message(flib_ipc ipc, void *data, size_t len) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
254 |
if(!ipc) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
255 |
flib_log_w("Call to flib_ipc_send_message with ipc==null"); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
256 |
return -1; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
257 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
258 |
return flib_ipcconn_send_message(ipc->connection, data, len); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
259 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
260 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
261 |
int flib_ipc_send_messagestr(flib_ipc ipc, char *data) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
262 |
if(!ipc) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
263 |
flib_log_w("Call to flib_ipc_send_messagestr with ipc==null"); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
264 |
return -1; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
265 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
266 |
return flib_ipcconn_send_messagestr(ipc->connection, data); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
267 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
268 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
269 |
uint16_t flib_ipc_port(flib_ipc ipc) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
270 |
if(!ipc) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
271 |
flib_log_w("Call to flib_ipc_send_messagestr with ipc==null"); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
272 |
return 0; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
273 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
274 |
return flib_ipcconn_port(ipc->connection); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
275 |
} |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
276 |
|
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
277 |
flib_constbuffer flib_ipc_getdemo(flib_ipc ipc) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
278 |
if(!ipc) { |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
279 |
flib_log_w("Call to flib_ipc_send_messagestr with ipc==null"); |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
280 |
flib_constbuffer result = {NULL, 0}; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
281 |
return result; |
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
282 |
} |
7175
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
7173
diff
changeset
|
283 |
return flib_ipcconn_getrecord(ipc->connection, false); |
7173
7c2eb284f9f1
Frontlib: Work on the callback mechanisms for IPC
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
284 |
} |