aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ecore/src/lib/ecore_ipc/Ecore_Ipc.h
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ecore/src/lib/ecore_ipc/Ecore_Ipc.h')
-rw-r--r--libraries/ecore/src/lib/ecore_ipc/Ecore_Ipc.h325
1 files changed, 325 insertions, 0 deletions
diff --git a/libraries/ecore/src/lib/ecore_ipc/Ecore_Ipc.h b/libraries/ecore/src/lib/ecore_ipc/Ecore_Ipc.h
new file mode 100644
index 0000000..40ae621
--- /dev/null
+++ b/libraries/ecore/src/lib/ecore_ipc/Ecore_Ipc.h
@@ -0,0 +1,325 @@
1#ifndef _ECORE_IPC_H
2#define _ECORE_IPC_H
3
4#ifdef EAPI
5# undef EAPI
6#endif
7
8#ifdef _WIN32
9# ifdef EFL_ECORE_IPC_BUILD
10# ifdef DLL_EXPORT
11# define EAPI __declspec(dllexport)
12# else
13# define EAPI
14# endif
15# else
16# define EAPI __declspec(dllimport)
17# endif
18#else
19# ifdef __GNUC__
20# if __GNUC__ >= 4
21# define EAPI __attribute__ ((visibility("default")))
22# else
23# define EAPI
24# endif
25# else
26# define EAPI
27# endif
28#endif
29
30/**
31 * @file Ecore_Ipc.h
32 * @brief Ecore inter-process communication functions.
33 */
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39typedef struct _Ecore_Ipc_Server Ecore_Ipc_Server; /**< An IPC connection handle */
40typedef struct _Ecore_Ipc_Client Ecore_Ipc_Client; /**< An IPC connection handle */
41
42EAPI unsigned short _ecore_ipc_swap_16(unsigned short v);
43EAPI unsigned int _ecore_ipc_swap_32(unsigned int v);
44EAPI unsigned long long _ecore_ipc_swap_64(unsigned long long v);
45
46#ifdef WORDS_BIGENDIAN
47#define ECORE_IPC_SWAP2NET64(x) _ecore_ipc_swap_64(x)
48#define ECORE_IPC_SWAP2CPU64(x) _ecore_ipc_swap_64(x)
49#define ECORE_IPC_SWAP2NET32(x) _ecore_ipc_swap_32(x)
50#define ECORE_IPC_SWAP2CPU32(x) _ecore_ipc_swap_32(x)
51#define ECORE_IPC_SWAP2NET16(x) _ecore_ipc_swap_16(x)
52#define ECORE_IPC_SWAP2CPU16(x) _ecore_ipc_swap_16(x)
53#define ECORE_IPC_SWAP2NET8(x) (x)
54#define ECORE_IPC_SWAP2CPU8(x) (x)
55#else
56#define ECORE_IPC_SWAP2NET64(x) (x)
57#define ECORE_IPC_SWAP2CPU64(x) (x)
58#define ECORE_IPC_SWAP2NET32(x) (x)
59#define ECORE_IPC_SWAP2CPU32(x) (x)
60#define ECORE_IPC_SWAP2NET16(x) (x)
61#define ECORE_IPC_SWAP2CPU16(x) (x)
62#define ECORE_IPC_SWAP2NET8(x) (x)
63#define ECORE_IPC_SWAP2CPU8(x) (x)
64#endif
65
66/* 1, 2, 4 and 8 byte datatypes */
67/* unpacking */
68#define ECORE_IPC_GET64(v)\
69 { \
70 p->v = ECORE_IPC_SWAP2CPU64(*(long long *)(ptr)); \
71 ptr += 8; \
72 }
73#define ECORE_IPC_GET32(v)\
74 { \
75 p->v = ECORE_IPC_SWAP2CPU32(*(int *)(ptr)); \
76 ptr += 4; \
77 }
78#define ECORE_IPC_GET16(v)\
79 { \
80 p->v = ECORE_IPC_SWAP2CPU16(*(short *)(ptr)); \
81 ptr += 2; \
82 }
83#define ECORE_IPC_GET8(v) \
84 { \
85 p->v = ECORE_IPC_SWAP2CPU8(*(char *)(ptr)); \
86 ptr += 1; \
87 }
88/* packing */
89#define ECORE_IPC_PUT64(v)\
90 { \
91 *(long long *)(ptr) = ECORE_IPC_SWAP2NET64(p->v); \
92 ptr += 8; \
93 }
94#define ECORE_IPC_PUT32(v)\
95 { \
96 *(int *)(ptr) = ECORE_IPC_SWAP2NET32(p->v); \
97 ptr += 4; \
98 }
99#define ECORE_IPC_PUT16(v)\
100 { \
101 *(short *)(ptr) = ECORE_IPC_SWAP2NET16(p->v); \
102 ptr += 2; \
103 }
104#define ECORE_IPC_PUT8(v) \
105 { \
106 *(char *)(ptr) = ECORE_IPC_SWAP2NET8(p->v); \
107 ptr += 1; \
108 }
109/* padding data */
110#define ECORE_IPC_PAD8() ptr += 1
111#define ECORE_IPC_PAD16() ptr += 2
112#define ECORE_IPC_PAD32() ptr += 4
113#define ECORE_IPC_PAD64() ptr += 8
114
115/* counting data when encoding lists */
116#define ECORE_IPC_CNT8() len += 1
117#define ECORE_IPC_CNT16() len += 2
118#define ECORE_IPC_CNT32() len += 4
119#define ECORE_IPC_CNT64() len += 8
120
121/* strings */
122#define ECORE_IPC_CHEKS() if (*((unsigned char *)d + s - 1) != 0) return 0;
123#define ECORE_IPC_GETS(v) \
124 { \
125 if (ptr < ((unsigned char *)d + s)) \
126 { \
127 p->v = (char *)ptr; \
128 ptr += strlen(p->v) + 1; \
129 } \
130 }
131#define ECORE_IPC_PUTS(v, l)\
132 { \
133 strcpy((char *)ptr, p->v); \
134 ptr += l + 1; \
135 }
136
137/* handy to calculate what sized block we need to alloc */
138#define ECORE_IPC_SLEN(l, v) ((l = strlen(p->v)) + 1)
139#define ECORE_IPC_CNTS(v) len += strlen(p->v) + 1
140
141/* saves typing function headers */
142#define ECORE_IPC_DEC_STRUCT_PROTO(x) static int x(void *d, int s, void *pp)
143#define ECORE_IPC_ENC_STRUCT_PROTO(x) static void *x(void *pp, int *s)
144#define ECORE_IPC_DEC_EINA_LIST_PROTO(x) static Eina_List *x(void *d, int s)
145#define ECORE_IPC_ENC_EINA_LIST_PROTO(x) static void *x(Eina_List *lp, int *s)
146
147
148/* decoder setup - saves typing. requires data packet of exact size, or fail */
149#define ECORE_IPC_DEC_STRUCT_HEAD_EXACT(typ, x) \
150 typ *p; \
151 unsigned char *ptr; \
152 p = (typ *)pp; \
153 if (!d) return 0; if (s != (x)) return 0; \
154 ptr = d;
155/* decoder setup - saves typing. requires data packet of a minimum size */
156#define ECORE_IPC_DEC_STRUCT_HEAD_MIN(typ, x) \
157 typ *p; \
158 unsigned char *ptr; \
159 p = (typ *)pp; \
160 if (!d) return 0; if (s < (x)) return 0; \
161 ptr = d;
162/* footer for the hell of it */
163#define ECORE_IPC_DEC_STRUCT_FOOT() return 1
164/* header for encoder - gives native strct type and size of flattened packet */
165#define ECORE_IPC_ENC_STRUCT_HEAD(typ, sz) \
166 typ *p; \
167 unsigned char *d, *ptr; \
168 int len; \
169 *s = 0; \
170 if(!pp) return NULL; \
171 p = (typ *)pp; \
172 len = sz; \
173 d = malloc(len); \
174 if (!d) return NULL; \
175 *s = len; \
176 ptr = d;
177/* footer for the hell of it */
178#define ECORE_IPC_ENC_STRUCT_FOOT() return d
179
180#define ECORE_IPC_DEC_EINA_LIST_HEAD(typ) \
181 unsigned char *ptr; \
182 Eina_List *l; \
183 typ *p; \
184 l = NULL; \
185 ptr = d; \
186 while(ptr < (unsigned char *)(d + s)) \
187 { \
188 p = malloc(sizeof(typ));
189
190#define ECORE_IPC_DEC_EINA_LIST_FOOT() \
191 l = eina_list_append(l, p); \
192 } \
193 return l
194#define ECORE_IPC_ENC_EINA_LIST_HEAD_START(typ) \
195 Eina_List *l; \
196 typ *p; \
197 unsigned char *d, *ptr; \
198 int len; \
199 *s = 0; \
200 len = 0; \
201 for (l = lp; l; l = l->next) \
202 { \
203 p = l->data;
204#define ECORE_IPC_ENC_EINA_LIST_HEAD_FINISH() \
205 } \
206 d = malloc(len); \
207 if(!d) return NULL; \
208 *s = len; \
209 ptr = d; \
210 for (l = lp; l; l = l->next) \
211 { \
212 p = l->data;
213
214#define ECORE_IPC_ENC_EINA_LIST_FOOT() \
215 } \
216 return d
217
218typedef enum _Ecore_Ipc_Type
219{
220 ECORE_IPC_LOCAL_USER,
221 ECORE_IPC_LOCAL_SYSTEM,
222 ECORE_IPC_REMOTE_SYSTEM,
223 ECORE_IPC_USE_SSL = 16
224} Ecore_Ipc_Type;
225
226typedef struct _Ecore_Ipc_Event_Client_Add Ecore_Ipc_Event_Client_Add;
227typedef struct _Ecore_Ipc_Event_Client_Del Ecore_Ipc_Event_Client_Del;
228typedef struct _Ecore_Ipc_Event_Server_Add Ecore_Ipc_Event_Server_Add;
229typedef struct _Ecore_Ipc_Event_Server_Del Ecore_Ipc_Event_Server_Del;
230typedef struct _Ecore_Ipc_Event_Client_Data Ecore_Ipc_Event_Client_Data;
231typedef struct _Ecore_Ipc_Event_Server_Data Ecore_Ipc_Event_Server_Data;
232
233struct _Ecore_Ipc_Event_Client_Add
234{
235 Ecore_Ipc_Client *client;
236};
237
238struct _Ecore_Ipc_Event_Client_Del
239{
240 Ecore_Ipc_Client *client;
241};
242
243struct _Ecore_Ipc_Event_Server_Add
244{
245 Ecore_Ipc_Server *server;
246};
247
248struct _Ecore_Ipc_Event_Server_Del
249{
250 Ecore_Ipc_Server *server;
251};
252
253struct _Ecore_Ipc_Event_Client_Data
254{
255 Ecore_Ipc_Client *client;
256 /* FIXME: this needs to become an ipc message */
257 int major;
258 int minor;
259 int ref;
260 int ref_to;
261 int response;
262 void *data;
263 int size;
264};
265
266struct _Ecore_Ipc_Event_Server_Data
267{
268 Ecore_Ipc_Server *server;
269 /* FIXME: this needs to become an ipc message */
270 int major;
271 int minor;
272 int ref;
273 int ref_to;
274 int response;
275 void *data;
276 int size;
277};
278
279EAPI extern int ECORE_IPC_EVENT_CLIENT_ADD;
280EAPI extern int ECORE_IPC_EVENT_CLIENT_DEL;
281EAPI extern int ECORE_IPC_EVENT_SERVER_ADD;
282EAPI extern int ECORE_IPC_EVENT_SERVER_DEL;
283EAPI extern int ECORE_IPC_EVENT_CLIENT_DATA;
284EAPI extern int ECORE_IPC_EVENT_SERVER_DATA;
285
286EAPI int ecore_ipc_init(void);
287EAPI int ecore_ipc_shutdown(void);
288
289/* FIXME: need to add protocol type parameter */
290EAPI Ecore_Ipc_Server *ecore_ipc_server_add(Ecore_Ipc_Type type, const char *name, int port, const void *data);
291
292/* FIXME: need to add protocol type parameter */
293EAPI Ecore_Ipc_Server *ecore_ipc_server_connect(Ecore_Ipc_Type type, char *name, int port, const void *data);
294EAPI void *ecore_ipc_server_del(Ecore_Ipc_Server *svr);
295EAPI void *ecore_ipc_server_data_get(Ecore_Ipc_Server *svr);
296EAPI Eina_Bool ecore_ipc_server_connected_get(Ecore_Ipc_Server *svr);
297EAPI Eina_List *ecore_ipc_server_clients_get(Ecore_Ipc_Server *svr);
298/* FIXME: this needs to become an ipc message */
299EAPI int ecore_ipc_server_send(Ecore_Ipc_Server *svr, int major, int minor, int ref, int ref_to, int response, const void *data, int size);
300EAPI void ecore_ipc_server_client_limit_set(Ecore_Ipc_Server *svr, int client_limit, char reject_excess_clients);
301EAPI void ecore_ipc_server_data_size_max_set(Ecore_Ipc_Server *srv, int size);
302EAPI int ecore_ipc_server_data_size_max_get(Ecore_Ipc_Server *srv);
303EAPI const char *ecore_ipc_server_ip_get(Ecore_Ipc_Server *svr);
304EAPI void ecore_ipc_server_flush(Ecore_Ipc_Server *svr);
305
306/* FIXME: this needs to become an ipc message */
307EAPI int ecore_ipc_client_send(Ecore_Ipc_Client *cl, int major, int minor, int ref, int ref_to, int response, const void *data, int size);
308EAPI Ecore_Ipc_Server *ecore_ipc_client_server_get(Ecore_Ipc_Client *cl);
309EAPI void *ecore_ipc_client_del(Ecore_Ipc_Client *cl);
310EAPI void ecore_ipc_client_data_set(Ecore_Ipc_Client *cl, const void *data);
311EAPI void *ecore_ipc_client_data_get(Ecore_Ipc_Client *cl);
312EAPI void ecore_ipc_client_data_size_max_set(Ecore_Ipc_Client *cl, int size);
313EAPI int ecore_ipc_client_data_size_max_get(Ecore_Ipc_Client *cl);
314EAPI const char *ecore_ipc_client_ip_get(Ecore_Ipc_Client *cl);
315EAPI void ecore_ipc_client_flush(Ecore_Ipc_Client *cl);
316
317EAPI int ecore_ipc_ssl_available_get(void);
318/* FIXME: need to add a callback to "ok" large ipc messages greater than */
319/* a certain size (seurity/DOS attack safety) */
320
321#ifdef __cplusplus
322}
323#endif
324
325#endif