summaryrefslogtreecommitdiff
path: root/src/bin/e_ipc.c
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2005-04-22 04:25:51 +0000
committerCarsten Haitzler <raster@rasterman.com>2005-04-22 04:25:51 +0000
commit374d09d00b7ac071a9f985f9f5721a1fc4a8032d (patch)
tree18324b6b959c7649c8f833908f4007a84148502b /src/bin/e_ipc.c
parentdd4a98045aefeb6c73147a0a34fe542d1c626ffc (diff)
shorne's cleanups
SVN revision: 14288
Diffstat (limited to 'src/bin/e_ipc.c')
-rw-r--r--src/bin/e_ipc.c356
1 files changed, 177 insertions, 179 deletions
diff --git a/src/bin/e_ipc.c b/src/bin/e_ipc.c
index 253f8a7..d0b1180 100644
--- a/src/bin/e_ipc.c
+++ b/src/bin/e_ipc.c
@@ -5,6 +5,15 @@ static int _e_ipc_cb_client_add(void *data, int type, void *event);
5static int _e_ipc_cb_client_del(void *data, int type, void *event); 5static int _e_ipc_cb_client_del(void *data, int type, void *event);
6static int _e_ipc_cb_client_data(void *data, int type, void *event); 6static int _e_ipc_cb_client_data(void *data, int type, void *event);
7static char *_e_ipc_path_str_get(char **paths, int *bytes); 7static char *_e_ipc_path_str_get(char **paths, int *bytes);
8static char *_e_ipc_simple_str_dec(char *data, int bytes);
9static char **_e_ipc_multi_str_dec(char *data, int bytes, int str_count);
10
11/* encode functions, Should these be global? */
12ECORE_IPC_ENC_EVAS_LIST_PROTO(_e_ipc_module_list_enc);
13ECORE_IPC_ENC_EVAS_LIST_PROTO(_e_ipc_font_available_list_enc);
14ECORE_IPC_ENC_EVAS_LIST_PROTO(_e_ipc_font_fallback_list_enc);
15ECORE_IPC_ENC_EVAS_LIST_PROTO(_e_ipc_font_default_list_enc);
16ECORE_IPC_ENC_STRUCT_PROTO(_e_ipc_font_default_enc);
8 17
9/* local subsystem globals */ 18/* local subsystem globals */
10static Ecore_Ipc_Server *_e_ipc_server = NULL; 19static Ecore_Ipc_Server *_e_ipc_server = NULL;
@@ -76,9 +85,8 @@ _e_ipc_cb_client_data(void *data __UNUSED__, int type __UNUSED__, void *event)
76 { 85 {
77 char *name; 86 char *name;
78 87
79 name = malloc(e->size + 1); 88 name = _e_ipc_simple_str_dec(e->data, e->size);
80 name[e->size] = 0; 89
81 memcpy(name, e->data, e->size);
82 if (!e_module_find(name)) 90 if (!e_module_find(name))
83 { 91 {
84 e_module_new(name); 92 e_module_new(name);
@@ -92,9 +100,8 @@ _e_ipc_cb_client_data(void *data __UNUSED__, int type __UNUSED__, void *event)
92 char *name; 100 char *name;
93 E_Module *m; 101 E_Module *m;
94 102
95 name = malloc(e->size + 1); 103 name = _e_ipc_simple_str_dec(e->data, e->size);
96 name[e->size] = 0; 104
97 memcpy(name, e->data, e->size);
98 if ((m = e_module_find(name))) 105 if ((m = e_module_find(name)))
99 { 106 {
100 if (e_module_enabled_get(m)) 107 if (e_module_enabled_get(m))
@@ -109,9 +116,8 @@ _e_ipc_cb_client_data(void *data __UNUSED__, int type __UNUSED__, void *event)
109 char *name; 116 char *name;
110 E_Module *m; 117 E_Module *m;
111 118
112 name = malloc(e->size + 1); 119 name = _e_ipc_simple_str_dec(e->data, e->size);
113 name[e->size] = 0; 120
114 memcpy(name, e->data, e->size);
115 if ((m = e_module_find(name))) 121 if ((m = e_module_find(name)))
116 { 122 {
117 if (!e_module_enabled_get(m)) 123 if (!e_module_enabled_get(m))
@@ -121,13 +127,12 @@ _e_ipc_cb_client_data(void *data __UNUSED__, int type __UNUSED__, void *event)
121 } 127 }
122 break; 128 break;
123 case E_IPC_OP_MODULE_DISABLE: 129 case E_IPC_OP_MODULE_DISABLE:
124 { 130 {
125 char *name; 131 char *name;
126 E_Module *m; 132 E_Module *m;
127 133
128 name = malloc(e->size + 1); 134 name = _e_ipc_simple_str_dec(e->data, e->size);
129 name[e->size] = 0; 135
130 memcpy(name, e->data, e->size);
131 if ((m = e_module_find(name))) 136 if ((m = e_module_find(name)))
132 { 137 {
133 if (e_module_enabled_get(m)) 138 if (e_module_enabled_get(m))
@@ -138,30 +143,15 @@ _e_ipc_cb_client_data(void *data __UNUSED__, int type __UNUSED__, void *event)
138 break; 143 break;
139 case E_IPC_OP_MODULE_LIST: 144 case E_IPC_OP_MODULE_LIST:
140 { 145 {
141 Evas_List *modules, *l; 146 /* encode module list (str,8-bit) */
147 Evas_List *modules;
148 char * data;
142 int bytes; 149 int bytes;
143 E_Module *m; 150
144 char *data, *p; 151 modules = e_module_list();
145 152 data = _e_ipc_module_list_enc(modules, &bytes);
146 bytes = 0; 153
147 modules = e_module_list(); 154 /* send reply data */
148 for (l = modules; l; l = l->next)
149 {
150 m = l->data;
151 bytes += strlen(m->name) + 1 + 1;
152 }
153 data = malloc(bytes);
154 p = data;
155 for (l = modules; l; l = l->next)
156 {
157 m = l->data;
158 strcpy(p, m->name);
159 p += strlen(m->name);
160 *p = 0;
161 p++;
162 *p = e_module_enabled_get(m);
163 p++;
164 }
165 ecore_ipc_client_send(e->client, 155 ecore_ipc_client_send(e->client,
166 E_IPC_DOMAIN_REPLY, 156 E_IPC_DOMAIN_REPLY,
167 E_IPC_OP_MODULE_LIST_REPLY, 157 E_IPC_OP_MODULE_LIST_REPLY,
@@ -194,10 +184,9 @@ _e_ipc_cb_client_data(void *data __UNUSED__, int type __UNUSED__, void *event)
194 { 184 {
195 char *file; 185 char *file;
196 Evas_List *managers, *l; 186 Evas_List *managers, *l;
187
188 file = _e_ipc_simple_str_dec(e->data, e->size);
197 189
198 file = malloc(e->size + 1);
199 file[e->size] = 0;
200 memcpy(file, e->data, e->size);
201 E_FREE(e_config->desktop_default_background); 190 E_FREE(e_config->desktop_default_background);
202 e_config->desktop_default_background = file; 191 e_config->desktop_default_background = file;
203 192
@@ -236,29 +225,13 @@ _e_ipc_cb_client_data(void *data __UNUSED__, int type __UNUSED__, void *event)
236 break; 225 break;
237 case E_IPC_OP_FONT_AVAILABLE_LIST: 226 case E_IPC_OP_FONT_AVAILABLE_LIST:
238 { 227 {
239 Evas_List *fonts_available, *l; 228 /* encode font available list (str) */
229 Evas_List *fonts_available;
240 int bytes; 230 int bytes;
241 char *font_name, *data, *p; 231 char *data;
242 232
243 bytes = 0; 233 fonts_available = e_font_available_list();
244 fonts_available = e_font_available_list(); 234 data = _e_ipc_font_available_list_enc(fonts_available, &bytes);
245 printf("ipc font av: %d\n", fonts_available);
246 for (l = fonts_available; l; l = l->next)
247 {
248 font_name = evas_list_data(l);
249 bytes += strlen(font_name) + 1;
250 }
251
252 data = malloc(bytes);
253 p = data;
254 for (l = fonts_available; l; l = l->next)
255 {
256 font_name = evas_list_data(l);
257 strcpy(p, font_name);
258 p += strlen(font_name);
259 *p = 0;
260 p++;
261 }
262 ecore_ipc_client_send(e->client, 235 ecore_ipc_client_send(e->client,
263 E_IPC_DOMAIN_REPLY, 236 E_IPC_DOMAIN_REPLY,
264 E_IPC_OP_FONT_AVAILABLE_LIST_REPLY, 237 E_IPC_OP_FONT_AVAILABLE_LIST_REPLY,
@@ -282,9 +255,8 @@ _e_ipc_cb_client_data(void *data __UNUSED__, int type __UNUSED__, void *event)
282 case E_IPC_OP_FONT_FALLBACK_APPEND: 255 case E_IPC_OP_FONT_FALLBACK_APPEND:
283 { 256 {
284 char * font_name; 257 char * font_name;
285 font_name = malloc(e->size + 1); 258
286 font_name[e->size] = 0; 259 font_name = _e_ipc_simple_str_dec(e->data, e->size);
287 memcpy(font_name, e->data, e->size);
288 e_font_fallback_append(font_name); 260 e_font_fallback_append(font_name);
289 free(font_name); 261 free(font_name);
290 262
@@ -294,9 +266,8 @@ _e_ipc_cb_client_data(void *data __UNUSED__, int type __UNUSED__, void *event)
294 case E_IPC_OP_FONT_FALLBACK_PREPEND: 266 case E_IPC_OP_FONT_FALLBACK_PREPEND:
295 { 267 {
296 char * font_name; 268 char * font_name;
297 font_name = malloc(e->size + 1); 269
298 font_name[e->size] = 0; 270 font_name = _e_ipc_simple_str_dec(e->data, e->size);
299 memcpy(font_name, e->data, e->size);
300 e_font_fallback_prepend(font_name); 271 e_font_fallback_prepend(font_name);
301 free(font_name); 272 free(font_name);
302 273
@@ -305,28 +276,15 @@ _e_ipc_cb_client_data(void *data __UNUSED__, int type __UNUSED__, void *event)
305 break; 276 break;
306 case E_IPC_OP_FONT_FALLBACK_LIST: 277 case E_IPC_OP_FONT_FALLBACK_LIST:
307 { 278 {
308 Evas_List *fallbacks, *l; 279
280 /* encode font fallback list (str) */
281 Evas_List *fallbacks;
309 int bytes; 282 int bytes;
310 E_Font_Fallback *eff; 283 char *data;
311 char *data, *p; 284
312
313 bytes = 0;
314 fallbacks = e_font_fallback_list(); 285 fallbacks = e_font_fallback_list();
315 for (l = fallbacks; l; l = l->next) 286
316 { 287 data = _e_ipc_font_fallback_list_enc(fallbacks, &bytes);
317 eff = evas_list_data(l);
318 bytes += strlen(eff->name) + 1;
319 }
320 data = malloc(bytes);
321 p = data;
322 for (l = fallbacks; l; l = l->next)
323 {
324 eff = evas_list_data(l);
325 strcpy(p, eff->name);
326 p += strlen(eff->name);
327 *p = 0;
328 p++;
329 }
330 ecore_ipc_client_send(e->client, 288 ecore_ipc_client_send(e->client,
331 E_IPC_DOMAIN_REPLY, 289 E_IPC_DOMAIN_REPLY,
332 E_IPC_OP_FONT_FALLBACK_LIST_REPLY, 290 E_IPC_OP_FONT_FALLBACK_LIST_REPLY,
@@ -339,9 +297,8 @@ _e_ipc_cb_client_data(void *data __UNUSED__, int type __UNUSED__, void *event)
339 case E_IPC_OP_FONT_FALLBACK_REMOVE: 297 case E_IPC_OP_FONT_FALLBACK_REMOVE:
340 { 298 {
341 char * font_name; 299 char * font_name;
342 font_name = malloc(e->size + 1); 300
343 font_name[e->size] = 0; 301 font_name = _e_ipc_simple_str_dec(e->data, e->size);
344 memcpy(font_name, e->data, e->size);
345 e_font_fallback_remove(font_name); 302 e_font_fallback_remove(font_name);
346 free(font_name); 303 free(font_name);
347 304
@@ -350,75 +307,30 @@ _e_ipc_cb_client_data(void *data __UNUSED__, int type __UNUSED__, void *event)
350 break; 307 break;
351 case E_IPC_OP_FONT_DEFAULT_SET: 308 case E_IPC_OP_FONT_DEFAULT_SET:
352 { 309 {
353 char * p; 310 char ** argv;
354 char * font_name; 311 int i, argc;
355 char * text_class;
356 int font_size;
357
358 312
359 p = e->data; 313 argc = 3;
314
315 argv = _e_ipc_multi_str_dec(e->data, e->size, argc);
316 e_font_default_set(argv[0], argv[1], atoi(argv[2]));
317 free(argv);
360 318
361 /* Make sure our data is packed for us <str>0<str>0 */
362 if( p[e->size - 1] != 0) {
363 break;
364 }
365
366 text_class = strdup(p);
367
368 p += strlen(text_class) + 1;
369 font_name = strdup(p);
370
371 p += strlen(font_name) + 1;
372 font_size = atoi(p);
373
374 e_font_default_set(text_class, font_name, font_size);
375
376 free(font_name);
377 free(text_class);
378
379 e_config_save_queue(); 319 e_config_save_queue();
380 } 320 }
381 break; 321 break;
382 case E_IPC_OP_FONT_DEFAULT_GET: 322 case E_IPC_OP_FONT_DEFAULT_GET:
383 { 323 {
384 int bytes; 324
325 /* encode font default struct (str,str,32-bits)(E_Font_Default) */
385 E_Font_Default *efd; 326 E_Font_Default *efd;
386 char *data, *p, *text_class; 327 char *data, *text_class;
387 328 int bytes;
388 text_class = malloc(e->size + 1);
389 text_class[e->size] = 0;
390 memcpy(text_class, e->data, e->size);
391
392 efd = e_font_default_get (text_class);
393 329
330 text_class = _e_ipc_simple_str_dec(e->data, e->size);
331 efd = e_font_default_get (text_class);
394 free(text_class); 332 free(text_class);
395 333 data = _e_ipc_font_default_enc(efd, &bytes);
396 bytes = 0;
397 if (efd) {
398 bytes += strlen(efd->text_class) + 1;
399 bytes += strlen(efd->font) + 1;
400 bytes++; /* efd->size */
401 }
402
403 data = malloc(bytes);
404 p = data;
405
406 if (efd) {
407 strcpy(p, efd->text_class);
408 p += strlen(efd->text_class);
409 *p = 0;
410 p++;
411
412 strcpy(p, efd->font);
413 p += strlen(efd->font);
414 *p = 0;
415 p++;
416
417 /* FIXME: should this be packed like this (int to char) ? */
418 *p = (char) efd->size;
419 p++;
420 }
421
422 ecore_ipc_client_send(e->client, 334 ecore_ipc_client_send(e->client,
423 E_IPC_DOMAIN_REPLY, 335 E_IPC_DOMAIN_REPLY,
424 E_IPC_OP_FONT_DEFAULT_GET_REPLY, 336 E_IPC_OP_FONT_DEFAULT_GET_REPLY,
@@ -430,9 +342,8 @@ _e_ipc_cb_client_data(void *data __UNUSED__, int type __UNUSED__, void *event)
430 case E_IPC_OP_FONT_DEFAULT_REMOVE: 342 case E_IPC_OP_FONT_DEFAULT_REMOVE:
431 { 343 {
432 char * text_class; 344 char * text_class;
433 text_class = malloc(e->size + 1); 345
434 text_class[e->size] = 0; 346 text_class = _e_ipc_simple_str_dec(e->data, e->size);
435 memcpy(text_class, e->data, e->size);
436 e_font_default_remove(text_class); 347 e_font_default_remove(text_class);
437 free(text_class); 348 free(text_class);
438 349
@@ -441,37 +352,13 @@ _e_ipc_cb_client_data(void *data __UNUSED__, int type __UNUSED__, void *event)
441 break; 352 break;
442 case E_IPC_OP_FONT_DEFAULT_LIST: 353 case E_IPC_OP_FONT_DEFAULT_LIST:
443 { 354 {
444 Evas_List *defaults, *l; 355 /* encode font default struct list (str,str,32-bits)(E_Font_Default) */
356 Evas_List *defaults;
445 int bytes; 357 int bytes;
446 E_Font_Default *efd; 358 char *data;
447 char *data, *p;
448 359
449 bytes = 0;
450 defaults = e_font_default_list(); 360 defaults = e_font_default_list();
451 for (l = defaults; l; l = l->next) 361 data = _e_ipc_font_default_list_enc(defaults, &bytes);
452 {
453 efd = l->data;
454 bytes += strlen(efd->text_class) + 1;
455 bytes += strlen(efd->font) + 1;
456 bytes++; /* efd->size */
457 }
458 data = malloc(bytes);
459 p = data;
460 for (l =defaults; l; l = l->next)
461 {
462 efd = l->data;
463 strcpy(p, efd->text_class);
464 p += strlen(efd->text_class);
465 *p = 0;
466 p++;
467 strcpy(p, efd->font);
468 p += strlen(efd->font);
469 *p = 0;
470 p++;
471 /* FIXME: should this be packed like this (int to char) ? */
472 *p = (char) efd->size;
473 p++;
474 }
475 ecore_ipc_client_send(e->client, 362 ecore_ipc_client_send(e->client,
476 E_IPC_DOMAIN_REPLY, 363 E_IPC_DOMAIN_REPLY,
477 E_IPC_OP_FONT_DEFAULT_LIST_REPLY, 364 E_IPC_OP_FONT_DEFAULT_LIST_REPLY,
@@ -557,4 +444,115 @@ _e_ipc_path_str_get(char **paths, int *bytes)
557 return data; 444 return data;
558} 445}
559 446
447/**
448 * Decode a simple string that was passed by an IPC client
449 *
450 * The returned string must be freed
451 */
452static char *
453_e_ipc_simple_str_dec(char *data, int bytes)
454{
455 char *str;
456
457 str = malloc(bytes + 1);
458 str[bytes] = 0;
459 memcpy(str, data, bytes);
460
461 return str;
462}
463
464/**
465 * Decode a list of strings and return an array, you need to pass
466 * the string count that you are expecting back.
467 *
468 * Strings are encoded <str>0<str>0...
469 *
470 * free up the array that you get back
471 */
472static char **
473_e_ipc_multi_str_dec(char *data, int bytes, int str_count)
474{
475 char ** str_array;
476 int i;
477
478 /* Make sure our data is packed for us <str>0<str>0 */
479 if( data[bytes - 1] != 0) {
480 return NULL;
481 }
482
483 str_array = malloc(sizeof(char *)*str_count);
484
485 for(i = 0; i < str_count; i++)
486 {
487 str_array[i] = data;
488 data += strlen(str_array[i]) + 1;
489 }
490
491 return str_array;
492}
560 493
494
495/* list/struct encoding functions */
496ECORE_IPC_ENC_EVAS_LIST_PROTO(_e_ipc_module_list_enc)
497{
498 ECORE_IPC_ENC_EVAS_LIST_HEAD_START(E_Module);
499 ECORE_IPC_CNTS(name);
500 ECORE_IPC_CNT8();
501 ECORE_IPC_ENC_EVAS_LIST_HEAD_FINISH();
502 int l1;
503 ECORE_IPC_SLEN(l1, name);
504 ECORE_IPC_PUTS(name, l1);
505 ECORE_IPC_PUT8(enabled);
506 ECORE_IPC_ENC_EVAS_LIST_FOOT();
507}
508
509ECORE_IPC_ENC_EVAS_LIST_PROTO(_e_ipc_font_available_list_enc)
510{
511 ECORE_IPC_ENC_EVAS_LIST_HEAD_START(E_Font_Available);
512 ECORE_IPC_CNTS(name);
513 ECORE_IPC_ENC_EVAS_LIST_HEAD_FINISH();
514 int l1;
515 ECORE_IPC_SLEN(l1, name);
516 ECORE_IPC_PUTS(name, l1);
517 ECORE_IPC_ENC_EVAS_LIST_FOOT();
518}
519
520ECORE_IPC_ENC_EVAS_LIST_PROTO(_e_ipc_font_fallback_list_enc)
521{
522 ECORE_IPC_ENC_EVAS_LIST_HEAD_START(E_Font_Fallback);
523 ECORE_IPC_CNTS(name);
524 ECORE_IPC_ENC_EVAS_LIST_HEAD_FINISH();
525 int l1;
526 ECORE_IPC_SLEN(l1, name);
527 ECORE_IPC_PUTS(name, l1);
528 ECORE_IPC_ENC_EVAS_LIST_FOOT();
529}
530
531ECORE_IPC_ENC_EVAS_LIST_PROTO(_e_ipc_font_default_list_enc)
532{
533 ECORE_IPC_ENC_EVAS_LIST_HEAD_START(E_Font_Default);
534 ECORE_IPC_CNTS(text_class);
535 ECORE_IPC_CNTS(font);
536 ECORE_IPC_CNT32();
537 ECORE_IPC_ENC_EVAS_LIST_HEAD_FINISH();
538 int l1, l2;
539 ECORE_IPC_SLEN(l1, text_class);
540 ECORE_IPC_SLEN(l2, font);
541 ECORE_IPC_PUTS(text_class, l1);
542 ECORE_IPC_PUTS(font, l2);
543 ECORE_IPC_PUT32(size);
544 ECORE_IPC_ENC_EVAS_LIST_FOOT();
545}
546
547ECORE_IPC_ENC_STRUCT_PROTO(_e_ipc_font_default_enc)
548{
549 int l1, l2;
550 ECORE_IPC_ENC_STRUCT_HEAD(E_Font_Default,
551 ECORE_IPC_SLEN(l1, text_class) +
552 ECORE_IPC_SLEN(l2, font) +
553 4);
554 ECORE_IPC_PUTS(text_class, l1);
555 ECORE_IPC_PUTS(font, l2);
556 ECORE_IPC_PUT32(size);
557 ECORE_IPC_ENC_STRUCT_FOOT();
558}