summaryrefslogtreecommitdiff
path: root/src/bin/e_remote_main.c
blob: 32b8b6bf2cbede59dc15e4d0a9649ed434dd10e2 (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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
/*
 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
 */
#include "e.h"

typedef struct _E_IPC_Opt_Handler E_IPC_Opt_Handler;

struct _E_IPC_Opt_Handler
{
   char *option;
   char *desc;
   int   num_params;
   int   replies;
   int   type;
   int   simple_request_id;
   void (*func) (char **params);
};

/* local subsystem functions */
static int  _e_cb_signal_exit(void *data, int ev_type, void *ev);
static int  _e_ipc_init(void);
static void _e_ipc_shutdown(void);

static int _e_ipc_cb_server_add(void *data, int type, void *event);
static int _e_ipc_cb_server_del(void *data, int type, void *event);
static int _e_ipc_cb_server_data(void *data, int type, void *event);

static void _e_help(void);

static const char *_e_ipc_context_str(int context);
static const char *_e_ipc_modifier_str(int mod);
static Evas_List *_e_ipc_str_list_dec(char *data, int bytes);
    
ECORE_IPC_DEC_EVAS_LIST_PROTO(_e_ipc_module_list_dec);
ECORE_IPC_DEC_EVAS_LIST_PROTO(_e_ipc_font_available_list_dec);
ECORE_IPC_DEC_EVAS_LIST_PROTO(_e_ipc_font_fallback_list_dec);
ECORE_IPC_DEC_EVAS_LIST_PROTO(_e_ipc_font_default_list_dec);
ECORE_IPC_DEC_STRUCT_PROTO(_e_ipc_font_default_dec);
ECORE_IPC_DEC_EVAS_LIST_PROTO(_e_ipc_mouse_binding_list_dec);
ECORE_IPC_ENC_STRUCT_PROTO(_e_ipc_mouse_binding_enc);
ECORE_IPC_DEC_STRUCT_PROTO(_e_ipc_mouse_binding_dec);
ECORE_IPC_DEC_EVAS_LIST_PROTO(_e_ipc_key_binding_list_dec);
ECORE_IPC_ENC_STRUCT_PROTO(_e_ipc_key_binding_enc);
ECORE_IPC_DEC_STRUCT_PROTO(_e_ipc_key_binding_dec);

/* local subsystem globals */
static Ecore_Ipc_Server *_e_ipc_server  = NULL;
static const char *display_name = NULL;
static int reply_count = 0;
static int reply_expect = 0;

static void
_e_opt_binding_mouse_parse(E_Config_Binding_Mouse *eb, char **params)
{
   if (!strcmp(params[0], "NONE")) eb->context = E_BINDING_CONTEXT_NONE;
   else if (!strcmp(params[0], "UNKNOWN")) eb->context = E_BINDING_CONTEXT_UNKNOWN;
   else if (!strcmp(params[0], "BORDER")) eb->context = E_BINDING_CONTEXT_BORDER;
   else if (!strcmp(params[0], "ZONE")) eb->context = E_BINDING_CONTEXT_ZONE;
   else if (!strcmp(params[0], "MANAGER")) eb->context = E_BINDING_CONTEXT_MANAGER;
   else if (!strcmp(params[0], "ANY")) eb->context = E_BINDING_CONTEXT_ANY;
   else
     {
	printf("OPT1 (CONTEXT) is not a valid context. Must be:\n"
	       "  NONE UNKNOWN BORDER ZONE MANAGER ANY\n");
	exit(-1);
     }
   eb->button = atoi(params[1]);
   /* M1[|M2...] */
     {
	char *p, *pp;
	
	eb->modifiers = 0;
	pp = params[2];
	for (;;)
	  {
	     p = strchr(pp, '|');
	     if (p)
	       {
		  if (!strncmp(pp, "SHIFT|", 6)) eb->modifiers |= E_BINDING_MODIFIER_SHIFT;
		  else if (!strncmp(pp, "CTRL|", 5)) eb->modifiers |= E_BINDING_MODIFIER_CTRL;
		  else if (!strncmp(pp, "ALT|", 4)) eb->modifiers |= E_BINDING_MODIFIER_ALT;
		  else if (!strncmp(pp, "WIN|", 4)) eb->modifiers |= E_BINDING_MODIFIER_WIN;
		  else if (strlen(pp) > 0)
		    {
		       printf("OPT3 moidifier unknonw. Must be or mask of:\n"
			      "  SHIFT CTRL ALT WIN\n");
		       exit(-1);
		    }
		  pp = p + 1;
	       }
	     else
	       {
		  if (!strcmp(pp, "SHIFT")) eb->modifiers |= E_BINDING_MODIFIER_SHIFT;
		  else if (!strcmp(pp, "CTRL")) eb->modifiers |= E_BINDING_MODIFIER_CTRL;
		  else if (!strcmp(pp, "ALT")) eb->modifiers |= E_BINDING_MODIFIER_ALT;
		  else if (!strcmp(pp, "WIN")) eb->modifiers |= E_BINDING_MODIFIER_WIN;
		  else if (strlen(pp) > 0)
		    {
		       printf("OPT3 moidifier unknonw. Must be or mask of:\n"
			      "  SHIFT CTRL ALT WIN\n");
		       exit(-1);
		    }
		  break;
	       }
	  }
     }
   eb->any_mod = atoi(params[3]);
   eb->action = params[4];
   eb->params = params[5];
}

static void
_e_opt_binding_mouse_add(char **params)
{
   E_Config_Binding_Mouse bind;
   int bytes;
   char *data;
   
   _e_opt_binding_mouse_parse(&bind, params);
   data = _e_ipc_mouse_binding_enc(&bind, &bytes);
   ecore_ipc_server_send(_e_ipc_server,
			 E_IPC_DOMAIN_REQUEST,
			 E_IPC_OP_BINDING_MOUSE_ADD,
			 0/*ref*/, 0/*ref_to*/, 0/*response*/,
			 data, bytes);
   free(data);
}

static void
_e_opt_binding_mouse_del(char **params)
{
   E_Config_Binding_Mouse bind;
   int bytes;
   char *data;
   
   _e_opt_binding_mouse_parse(&bind, params);
   data = _e_ipc_mouse_binding_enc(&bind, &bytes);
   ecore_ipc_server_send(_e_ipc_server,
			 E_IPC_DOMAIN_REQUEST,
			 E_IPC_OP_BINDING_MOUSE_DEL,
			 0/*ref*/, 0/*ref_to*/, 0/*response*/,
			 data, bytes);
   free(data);
}

static void
_e_opt_binding_key_parse(E_Config_Binding_Key *eb, char **params)
{
   if (!strcmp(params[0], "NONE")) eb->context = E_BINDING_CONTEXT_NONE;
   else if (!strcmp(params[0], "UNKNOWN")) eb->context = E_BINDING_CONTEXT_UNKNOWN;
   else if (!strcmp(params[0], "BORDER")) eb->context = E_BINDING_CONTEXT_BORDER;
   else if (!strcmp(params[0], "ZONE")) eb->context = E_BINDING_CONTEXT_ZONE;
   else if (!strcmp(params[0], "MANAGER")) eb->context = E_BINDING_CONTEXT_MANAGER;
   else if (!strcmp(params[0], "ANY")) eb->context = E_BINDING_CONTEXT_ANY;
   else
     {
	printf("OPT1 (CONTEXT) is not a valid context. Must be:\n"
	       "  NONE UNKNOWN BORDER ZONE MANAGER ANY\n");
	exit(-1);
     }
   eb->key = params[1];
   /* M1[|M2...] */
     {
	char *p, *pp;
	
	eb->modifiers = 0;
	pp = params[2];
	for (;;)
	  {
	     p = strchr(pp, '|');
	     if (p)
	       {
		  if (!strncmp(pp, "SHIFT|", 6)) eb->modifiers |= E_BINDING_MODIFIER_SHIFT;
		  else if (!strncmp(pp, "CTRL|", 5)) eb->modifiers |= E_BINDING_MODIFIER_CTRL;
		  else if (!strncmp(pp, "ALT|", 4)) eb->modifiers |= E_BINDING_MODIFIER_ALT;
		  else if (!strncmp(pp, "WIN|", 4)) eb->modifiers |= E_BINDING_MODIFIER_WIN;
		  else if (strlen(pp) > 0)
		    {
		       printf("OPT3 moidifier unknonw. Must be or mask of:\n"
			      "  SHIFT CTRL ALT WIN\n");
		       exit(-1);
		    }
		  pp = p + 1;
	       }
	     else
	       {
		  if (!strcmp(pp, "SHIFT")) eb->modifiers |= E_BINDING_MODIFIER_SHIFT;
		  else if (!strcmp(pp, "CTRL")) eb->modifiers |= E_BINDING_MODIFIER_CTRL;
		  else if (!strcmp(pp, "ALT")) eb->modifiers |= E_BINDING_MODIFIER_ALT;
		  else if (!strcmp(pp, "WIN")) eb->modifiers |= E_BINDING_MODIFIER_WIN;
		  else if (strlen(pp) > 0)
		    {
		       printf("OPT3 moidifier unknonw. Must be or mask of:\n"
			      "  SHIFT CTRL ALT WIN\n");
		       exit(-1);
		    }
		  break;
	       }
	  }
     }
   eb->any_mod = atoi(params[3]);
   eb->action = params[4];
   eb->params = params[5];
}

static void
_e_opt_binding_key_add(char **params)
{
   E_Config_Binding_Key bind;
   int bytes;
   char *data;
   
   _e_opt_binding_key_parse(&bind, params);
   data = _e_ipc_key_binding_enc(&bind, &bytes);
   ecore_ipc_server_send(_e_ipc_server,
			 E_IPC_DOMAIN_REQUEST,
			 E_IPC_OP_BINDING_KEY_ADD,
			 0/*ref*/, 0/*ref_to*/, 0/*response*/,
			 data, bytes);
   free(data);
}

static void
_e_opt_binding_key_del(char **params)
{
   E_Config_Binding_Key bind;
   int bytes;
   char *data;
   
   _e_opt_binding_key_parse(&bind, params);
   data = _e_ipc_key_binding_enc(&bind, &bytes);
   ecore_ipc_server_send(_e_ipc_server,
			 E_IPC_DOMAIN_REQUEST,
			 E_IPC_OP_BINDING_KEY_DEL,
			 0/*ref*/, 0/*ref_to*/, 0/*response*/,
			 data, bytes);
   free(data);
}

#define SIMPLE_REQ     0
#define SIMPLE_STR_REQ 1
#define FULL_FUNC      2
#define MULTI_STR_REQ  3

#define OREQ(opt, desc, ipc, rep) {opt, desc, 0, rep, SIMPLE_REQ, ipc, NULL}
#define OSTR(opt, desc, ipc, rep) {opt, desc, 1, rep, SIMPLE_STR_REQ, ipc, NULL}
#define OFNC(opt, desc, param, fn, rep) {opt, desc, param, rep, FULL_FUNC, 0, fn}
#define OMUL(opt, desc, ipc, rep, argc) {opt, desc, argc, rep, MULTI_STR_REQ, ipc, NULL}

E_IPC_Opt_Handler handlers[] =
{
   OSTR("-module-load", "Load module OPT1 into memory", E_IPC_OP_MODULE_LOAD, 0),
   OSTR("-module-unload", "Unload (and disable) module OPT1 from memory", E_IPC_OP_MODULE_UNLOAD, 0),
   OSTR("-module-enable", "Enable module OPT1 if not enabled", E_IPC_OP_MODULE_ENABLE, 0),
   OSTR("-module-disable", "Disable module OPT1 if not disabled", E_IPC_OP_MODULE_DISABLE, 0),
   OREQ("-module-list", "List all loaded modules and their states", E_IPC_OP_MODULE_LIST, 1),
   OREQ("-module-dirs-list", "List all modules directories", E_IPC_OP_MODULE_DIRS_LIST, 1),
   OSTR("-bg-set", "Set the background edje file to be OPT1", E_IPC_OP_BG_SET, 0),
   OREQ("-bg-get", "Get the background edje file", E_IPC_OP_BG_GET, 1),
   OREQ("-bg-dirs-list", "Get the background directories", E_IPC_OP_BG_DIRS_LIST, 1),
   OSTR("-font-fallback-remove", "Remove OPT1 from the fontset", E_IPC_OP_FONT_FALLBACK_REMOVE, 0),
   OSTR("-font-fallback-prepend", "Prepend OPT1 to the fontset", E_IPC_OP_FONT_FALLBACK_PREPEND, 0),
   OSTR("-font-fallback-append", "Append OPT1 to the fontset", E_IPC_OP_FONT_FALLBACK_APPEND, 0),
   OREQ("-font-apply", "Apply changes made to the font system", E_IPC_OP_FONT_APPLY, 0),
   OREQ("-font-fallback-list", "List the fallback fonts in order", E_IPC_OP_FONT_FALLBACK_LIST, 1),
   OREQ("-font-available-list", "List available fonts", E_IPC_OP_FONT_AVAILABLE_LIST, 1),
   OREQ("-font-fallback-clear", "Clear font fallback list", E_IPC_OP_FONT_FALLBACK_CLEAR, 0),
   OSTR("-font-default-get", "List the default font associated with OPT1", E_IPC_OP_FONT_DEFAULT_GET, 1),
   OSTR("-font-default-remove", "Remove the default text class OPT1", E_IPC_OP_FONT_DEFAULT_REMOVE, 0),
   OREQ("-font-default-list", "List all configured text classes", E_IPC_OP_FONT_DEFAULT_LIST, 1),
   OMUL("-font-default-set", "Set textclass (OPT1) font (OPT2) and size (OPT3)", E_IPC_OP_FONT_DEFAULT_SET, 0, 3),
   OREQ("-restart", "Restart E17", E_IPC_OP_RESTART, 0),
   OREQ("-shutdown", "Shutdown E17", E_IPC_OP_SHUTDOWN, 0),
   OREQ("-lang-get", "Get the current language", E_IPC_OP_LANG_GET, 1),
   OREQ("-lang-list", "List all available languages", E_IPC_OP_LANG_LIST, 1),
   OSTR("-lang-set", "Set the current language", E_IPC_OP_LANG_SET, 0),
   OREQ("-binding-mouse-list", "List all mouse bindings", E_IPC_OP_BINDING_MOUSE_LIST, 1),
   OFNC("-binding-mouse-add", "Add or replace an existing mouse binding. OPT1 = Context, OPT2 = button, OPT3 = modifiers, OPT4 = any modifier ok, OPT5 = action, OPT6 = action parameters", 6, _e_opt_binding_mouse_add, 0),
   OFNC("-binding-mouse-del", "Delete an existing mouse binding. OPT1 = Context, OPT2 = button, OPT3 = modifiers, OPT4 = any modifier ok, OPT5 = action, OPT6 = action parameters", 6, _e_opt_binding_mouse_del, 0),
   OREQ("-binding-key-list", "List all key bindings", E_IPC_OP_BINDING_KEY_LIST, 1),
   OFNC("-binding-key-add", "Add or replace an existing key binding. OPT1 = Context, OPT2 = key, OPT3 = modifiers, OPT4 = any modifier ok, OPT5 = action, OPT6 = action parameters", 6, _e_opt_binding_key_add, 0),
   OFNC("-binding-key-del", "Delete an existing key binding. OPT1 = Context, OPT2 = key, OPT3 = modifiers, OPT4 = any modifier ok, OPT5 = action, OPT6 = action parameters", 6, _e_opt_binding_key_del, 0)
};

/* externally accessible functions */
int
main(int argc, char **argv)
{
   int i;
   char *s, buf[1024];
   
   /* fix up DISPLAY to be :N.0 if no .screen is in it */
   s = getenv("DISPLAY");
   if (s)
     {
	char *p;
	
	p = strrchr(s, ':');
	if (!p)
	  {
	     snprintf(buf, sizeof(buf), "DISPLAY=%s:0.0", s);
	     putenv(strdup(buf));
	  }
	else
	  {
	     p = strrchr(p, '.');
	     if (!p)
	       {
		  snprintf(buf, sizeof(buf), "DISPLAY=%s.0", s);
		  putenv(strdup(buf));
	       }
	  }
     }
   
   /* handle some command-line parameters */
   display_name = (const char *)getenv("DISPLAY");
   for (i = 1; i < argc; i++)
     {
	if ((!strcmp(argv[i], "-display")) && (i < (argc - 1)))
	  {
	     i++;
	     display_name = argv[i];
	  }
	else if ((!strcmp(argv[i], "-h")) ||
		 (!strcmp(argv[i], "-help")) ||
		 (!strcmp(argv[i], "--h")) ||
		 (!strcmp(argv[i], "--help")))
	  {
	     _e_help();
	     exit(0);
	  }
     }
  
   /* basic ecore init */
   if (!ecore_init())
     {
	printf("ERROR: Enlightenment_remote cannot Initialize Ecore!\n"
	       "Perhaps you are out of memory?\n");
	exit(-1);
     }
   ecore_app_args_set((int)argc, (const char **)argv);
   /* setup a handler for when e is asked to exit via a system signal */
   if (!ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, _e_cb_signal_exit, NULL))
     {
	printf("ERROR: Enlightenment_remote cannot set up an exit signal handler.\n"
	       "Perhaps you are out of memory?\n");
	exit(-1);
     }
   /* init ipc */
   if (!ecore_ipc_init())
     {
	printf("ERROR: Enlightenment_remote cannot initialize the ipc system.\n"
	       "Perhaps you are out of memory?\n");
	exit(-1);
     }
   
   /* setup e ipc service */
   if (!_e_ipc_init())
     {
	printf("ERROR: Enlightenment_remote cannot set up the IPC socket.\n"
	       "Maybe try the '-display :0.0' option?\n");
	exit(-1);
     }
   e_ipc_codec_init();

   /* start our main loop */
   ecore_main_loop_begin();

   e_ipc_codec_shutdown();
   _e_ipc_shutdown();
   ecore_ipc_shutdown();
   ecore_shutdown();
   
   /* just return 0 to keep the compiler quiet */
   return 0;
}

/* local subsystem functions */
static int
_e_cb_signal_exit(void *data, int ev_type, void *ev)
{
   /* called on ctrl-c, kill (pid) (also SIGINT, SIGTERM and SIGQIT) */
   ecore_main_loop_quit();
   return 1;
}

static int
_e_ipc_init(void)
{
   char buf[1024];
   char *disp;
   
   disp = (char *)display_name;
   if (!disp) disp = ":0";
   snprintf(buf, sizeof(buf), "enlightenment-(%s)", disp);
   _e_ipc_server = ecore_ipc_server_connect(ECORE_IPC_LOCAL_USER, buf, 0, NULL);
   /* FIXME: we shoudl also try the generic ":0" if the display is ":0.0" */
   /* similar... */
   if (!_e_ipc_server) return 0;
   
   ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_ADD, _e_ipc_cb_server_add, NULL);
   ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DEL, _e_ipc_cb_server_del, NULL);
   ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DATA, _e_ipc_cb_server_data, NULL);
   
   return 1;
}

static void
_e_ipc_shutdown(void)
{
   if (_e_ipc_server)
     {
	ecore_ipc_server_del(_e_ipc_server);
	_e_ipc_server = NULL;
     }
}

static int
_e_ipc_cb_server_add(void *data, int type, void *event)
{
   Ecore_Ipc_Event_Server_Add *e;
   int argc;
   char **argv;
   int i;
   int process_count = 0;
   
   e = event;
   ecore_app_args_get(&argc, &argv);
   for (i = 1; i < argc; i++)
     {
	char *v, *p;
	int j;
	int k;
	int data_size;
	
	for (j = 0; j < (int)(sizeof(handlers) / sizeof(E_IPC_Opt_Handler)); j++)
	  {
	     E_IPC_Opt_Handler *handler;
	     
	     handler = &handlers[j];
	     if (!strcmp(handler->option, argv[i]))
	       {
		  if (i >= (argc - handler->num_params))
		    {
		       printf("ERROR: option %s expects %i parameters\n",
			      handler->option, handler->num_params);
		       exit(-1);
		    }
		  else
		    {
		       switch (handler->type)
			 {
			  case SIMPLE_REQ:
			    ecore_ipc_server_send(_e_ipc_server,
						  E_IPC_DOMAIN_REQUEST,
						  handler->simple_request_id,
						  0/*ref*/, 0/*ref_to*/, 0/*response*/,
						  NULL, 0);
			    break;
			  case SIMPLE_STR_REQ:
			    v = argv[i + 1];
			    ecore_ipc_server_send(_e_ipc_server,
						  E_IPC_DOMAIN_REQUEST,
						  handler->simple_request_id,
						  0/*ref*/, 0/*ref_to*/, 0/*response*/,
						  v, strlen(v));
			    break;
			  case MULTI_STR_REQ:
			    /* pack up the data "<str>0<str>0" */
			    data_size = 0;
			    for(k = 0; k < handler->num_params; k++) {
				data_size += strlen(argv[ i + 1 + k ]);
				data_size++; /* NULL Pad */
			    }			     
			    v = malloc(data_size);
			    p = v;	    			
			    for(k = 0; k < handler->num_params; k++) {
				 strcpy(p, argv[ i + 1 + k]);
				 p += strlen(argv[ i + 1 + k]);
				 *p = 0;
				 p++;
			    }	
			    ecore_ipc_server_send(_e_ipc_server,
						  E_IPC_DOMAIN_REQUEST,
						  handler->simple_request_id,
						  0/*ref*/, 0/*ref_to*/, 0/*response*/,
						  v, data_size);
			    free(v);
 
			    break;
			  case FULL_FUNC:
			    handler->func(argv + i + 1);
			    break;
			  default:
			    break;
			 }
		       process_count++;
		       reply_expect += handler->replies;
		       i += handler->num_params;
		       break;
		    }
	       }
	  }
     }
   if (process_count <= 0)
     _e_help();
   if (reply_count >= reply_expect) ecore_main_loop_quit();
   return 1;
}

static int
_e_ipc_cb_server_del(void *data, int type, void *event)
{
   Ecore_Ipc_Event_Server_Del *e;
   
   e = event;
   return 1; 
}

static int
_e_ipc_cb_server_data(void *data, int type, void *event)
{
   Ecore_Ipc_Event_Server_Data *e;
   
   e = event;
   /* FIXME: should make this function/callback based in a table like the */
   /* option handlers... */
   printf("REPLY: BEGIN\n");
   switch (e->minor)
     {  
      case E_IPC_OP_MODULE_LIST_REPLY:
	if (e->data)
	  {
	     Evas_List *modules;
	     E_Module *m;
	     
	     modules = _e_ipc_module_list_dec(e->data, e->size);	     
	     while(modules)
	       {
	     	   m = modules->data;
	     	   printf("REPLY: MODULE NAME=\"%s\" ENABLED=%i\n",
				   	m->name, m->enabled);
		   modules = evas_list_remove_list(modules, modules);
		   E_FREE(m);
	       }
	  }
	else
	  printf("REPLY: MODULE NONE\n");
	break;
      case E_IPC_OP_MODULE_DIRS_LIST_REPLY:
	if (e->data)
	  {
	     char *p;

	     p = e->data;
	     while (p < (char *)(e->data + e->size))
	       {
		  char *dir;
		  
		  dir = p;
		  printf("REPLY: MODULE DIR=%s\n", dir);
		  p += strlen(dir) + 1;
	       }
	  }
	break;
      case E_IPC_OP_BG_GET_REPLY:
	if (e->data)
	  {
	     printf("REPLY: %s\n", (char *)e->data);
	  }
	break;
      case E_IPC_OP_BG_DIRS_LIST_REPLY:
	if (e->data)
	  {	
	     char *p;
	     
	     p = e->data;
	     while (p < (char *)(e->data + e->size))
	       {
		  char *dir;
		  
		  dir = p;
		  printf("REPLY: BG DIR=%s\n", dir);
		  p += strlen(dir) + 1;
	       }
	  }
	break;
      case E_IPC_OP_FONT_FALLBACK_LIST_REPLY:
	if (e->data)
	  {
	     Evas_List *fallbacks;
	     E_Font_Fallback *eff;
	     
	     fallbacks = _e_ipc_font_fallback_list_dec(e->data, e->size);
	     while(fallbacks)
	       {
		  eff = fallbacks->data;
		  printf("REPLY: FALLBACK NAME=\"%s\"\n", eff->name);
		  fallbacks = evas_list_remove_list(fallbacks, fallbacks);
		  E_FREE(eff);
	       }
	  }
	else
	  printf("REPLY: FALLBACK NONE\n");
	break;
      case E_IPC_OP_FONT_AVAILABLE_LIST_REPLY:
        if (e->data)
          {
             Evas_List *available;
	     E_Font_Available *fa;
	     
	     available = _e_ipc_font_available_list_dec(e->data, e->size);
	     while(available)
	       {
		  fa = available->data;
		  printf("REPLY: AVAILABLE NAME=\"%s\"\n", fa->name);
		  available = evas_list_remove_list(available, available);
		  E_FREE(fa);
	       }
          }
        else
          printf("REPLY: AVAILABLE NONE\n"); 
        break;   
      case E_IPC_OP_FONT_DEFAULT_GET_REPLY:
        if (e->data)
          {
             E_Font_Default efd;
             _e_ipc_font_default_dec(e->data, e->size, &efd);
             printf("REPLY: DEFAULT TEXT_CLASS=\"%s\" NAME=\"%s\" SIZE=%d\n",
		    efd.text_class, efd.font, efd.size);
          }
        else
          printf("REPLY: DEFAULT NONE\n"); 
        break;
      case E_IPC_OP_FONT_DEFAULT_LIST_REPLY:
        if (e->data)
          {
             Evas_List *defaults;
             E_Font_Default *efd;
	     
             defaults = _e_ipc_font_default_list_dec(e->data, e->size);
             while (defaults)
               {
		  efd = defaults->data;
		  printf("REPLY: DEFAULT TEXT_CLASS=\"%s\" NAME=\"%s\" SIZE=%d\n",
			 efd->text_class, efd->font, efd->size);  
                  defaults = evas_list_remove_list(defaults, defaults);
		  E_FREE(efd);
	       }
          }
        else
          printf("REPLY: DEFAULT NONE\n"); 
        break;	
      case E_IPC_OP_LANG_LIST_REPLY:
        if (e->data)
          {
	     Evas_List *langs;
	     
	     langs = _e_ipc_str_list_dec(e->data, e->size);
	     if (langs)
	       {
		  Evas_List *l;
		  
		  for (l = langs; l; l = l->next)
		    printf("REPLY: LANG=\"%s\"\n", (char *)l->data);
		  evas_list_free(langs);
	       }
          }
        else
          printf("REPLY: AVAILABLE NONE\n"); 
        break;   
      case E_IPC_OP_LANG_GET_REPLY:
	if (e->data)
	  {
	     printf("REPLY: %s\n", (char *)e->data);
	  }
	break;
      case E_IPC_OP_BINDING_MOUSE_LIST_REPLY:
        if (e->data)
          {
	     Evas_List *bindings;
	     E_Config_Binding_Mouse *eb;
	     
	     bindings = _e_ipc_mouse_binding_list_dec(e->data, e->size);
	     while (bindings)
	       {
		  eb = bindings->data;
		  printf("REPLY: BINDING CONTEXT=%s MODIFIERS=%s BUTTON=%i ANY_MOD=%i ACTION=\"%s\" PARAMS=\"%s\"\n", 
			 _e_ipc_context_str(eb->context),
			 _e_ipc_modifier_str(eb->modifiers),
			 eb->button,
			 eb->any_mod,
			 eb->action,
			 eb->params
			 );
                  bindings = evas_list_remove_list(bindings, bindings);
		  E_FREE(eb);
	       }
          }
        else
          printf("REPLY: AVAILABLE NONE\n"); 
        break;   
      case E_IPC_OP_BINDING_KEY_LIST_REPLY:
        if (e->data)
          {
	     Evas_List *bindings;
	     E_Config_Binding_Key *eb;
	     
	     bindings = _e_ipc_key_binding_list_dec(e->data, e->size);
	     while (bindings)
	       {
		  eb = bindings->data;
		  printf("REPLY: BINDING CONTEXT=%s MODIFIERS=%s KEY=\"%s\" ANY_MOD=%i ACTION=\"%s\" PARAMS=\"%s\"\n", 
			 _e_ipc_context_str(eb->context),
			 _e_ipc_modifier_str(eb->modifiers),
			 eb->key,
			 eb->any_mod,
			 eb->action,
			 eb->params
			 );
                  bindings = evas_list_remove_list(bindings, bindings);
		  E_FREE(eb);
	       }
          }
        else
          printf("REPLY: AVAILABLE NONE\n"); 
        break;   
      default:
	break;
     }
   printf("REPLY: END\n");
   reply_count++;
   if (reply_count >= reply_expect) ecore_main_loop_quit();
   return 1;
}

static void
_e_help(void)
{
   int j, k, l;
   E_IPC_Opt_Handler *handler;
   char buf[128];
   int parsize = 0, opsize = 0;
   
   printf("OPTIONS:\n");
   for (j = 0; j < (int)(sizeof(handlers) / sizeof(E_IPC_Opt_Handler)); j++)
     {
	handler = &handlers[j];
	if ((int)strlen(handler->option) > parsize) parsize = strlen(handler->option);
	l = 0;
	for (k = 0; k < handler->num_params; k++)
	  {
	     snprintf(buf, sizeof(buf), " OPT%i", k + 1);
	     l += strlen(buf);
	  }
	if (l > opsize) opsize = l;
     }
   for (j = 0; j < (int)(sizeof(handlers) / sizeof(E_IPC_Opt_Handler)); j++)
     {
	handler = &handlers[j];
	printf("  %s", handler->option);
	l = parsize - strlen(handler->option);
	for (k = 0; k < l; k++) printf(" ");
	l = 0;
	for (k = 0; k < handler->num_params; k++)
	  {
	     snprintf(buf, sizeof(buf), " OPT%i", k + 1);
	     printf("%s", buf);
	     l += strlen(buf);
	  }
	while (l < opsize)
	  {
	     printf(" ");
	     l++;
	  }
	printf("  - %s\n", handler->desc);
     }
}

/* generic encoding functions */
static const char *
_e_ipc_context_str(int context)
{
   if (context == E_BINDING_CONTEXT_NONE) return "NONE";
   if (context == E_BINDING_CONTEXT_UNKNOWN) return "UNKNOWN";
   if (context == E_BINDING_CONTEXT_BORDER) return "BORDER";
   if (context == E_BINDING_CONTEXT_ZONE) return "ZONE";
   if (context == E_BINDING_CONTEXT_MANAGER) return "MANAGER";
   if (context == E_BINDING_CONTEXT_ANY) return "ANY";
   return "";
}

static char _mod_buf[256];
static const char *
_e_ipc_modifier_str(int mod)
{
   _mod_buf[0] = 0;
   if (mod & E_BINDING_MODIFIER_SHIFT)
     {
	if (_mod_buf[0] != 0) strcat(_mod_buf, "|");
	strcat(_mod_buf, "SHIFT");
     }
   if (mod & E_BINDING_MODIFIER_CTRL)
     {
	if (_mod_buf[0] != 0) strcat(_mod_buf, "|");
	strcat(_mod_buf, "CTRL");
     }
   if (mod & E_BINDING_MODIFIER_ALT)
     {
	if (_mod_buf[0] != 0) strcat(_mod_buf, "|");
	strcat(_mod_buf, "ALT");
     }
   if (mod & E_BINDING_MODIFIER_WIN)
     {
	if (_mod_buf[0] != 0) strcat(_mod_buf, "|");
	strcat(_mod_buf, "WIN");
     }
   return _mod_buf;
}

static Evas_List *
_e_ipc_str_list_dec(char *data, int bytes)
{
   Evas_List *strs = NULL;
   char *p;
   
   /* malformed list? */
   if (data[bytes - 1] != 0) return NULL;
   p = data;
   while (p < (data + bytes))
     {
	strs = evas_list_append(strs, p);
	p += strlen(p) + 1;
     }
   return strs;
}

/* list/struct encoding functions */
ECORE_IPC_DEC_EVAS_LIST_PROTO(_e_ipc_module_list_dec)
{
   ECORE_IPC_DEC_EVAS_LIST_HEAD(E_Module);
   ECORE_IPC_GETS(name);
   ECORE_IPC_GET8(enabled);
   ECORE_IPC_DEC_EVAS_LIST_FOOT();
}

ECORE_IPC_DEC_EVAS_LIST_PROTO(_e_ipc_font_available_list_dec)
{
   ECORE_IPC_DEC_EVAS_LIST_HEAD(E_Font_Available);
   ECORE_IPC_GETS(name);
   ECORE_IPC_DEC_EVAS_LIST_FOOT();
}

ECORE_IPC_DEC_EVAS_LIST_PROTO(_e_ipc_font_fallback_list_dec)
{
   ECORE_IPC_DEC_EVAS_LIST_HEAD(E_Font_Fallback);
   ECORE_IPC_GETS(name);
   ECORE_IPC_DEC_EVAS_LIST_FOOT();
}

ECORE_IPC_DEC_EVAS_LIST_PROTO(_e_ipc_font_default_list_dec)
{
   ECORE_IPC_DEC_EVAS_LIST_HEAD(E_Font_Default);
   ECORE_IPC_GETS(text_class);
   ECORE_IPC_GETS(font);
   ECORE_IPC_GET32(size);
   ECORE_IPC_DEC_EVAS_LIST_FOOT();
}

ECORE_IPC_DEC_STRUCT_PROTO(_e_ipc_font_default_dec)
{  
   ECORE_IPC_DEC_STRUCT_HEAD_MIN(E_Font_Default,
				 1 +
				 1 +
				 4);
   ECORE_IPC_CHEKS();
   ECORE_IPC_GETS(text_class);
   ECORE_IPC_GETS(font);
   ECORE_IPC_GET32(size);
   ECORE_IPC_DEC_STRUCT_FOOT();
}

ECORE_IPC_DEC_EVAS_LIST_PROTO(_e_ipc_mouse_binding_list_dec)
{
   ECORE_IPC_DEC_EVAS_LIST_HEAD(E_Config_Binding_Mouse);
   ECORE_IPC_GET32(context);
   ECORE_IPC_GET32(modifiers);
   ECORE_IPC_GETS(action);
   ECORE_IPC_GETS(params);
   ECORE_IPC_GET8(button);
   ECORE_IPC_GET8(any_mod);
   ECORE_IPC_DEC_EVAS_LIST_FOOT();
}

ECORE_IPC_ENC_STRUCT_PROTO(_e_ipc_mouse_binding_enc)
{
   int l1, l2;
   ECORE_IPC_ENC_STRUCT_HEAD(E_Config_Binding_Mouse,
				 4 + 4 +
				 ECORE_IPC_SLEN(l1, action) +
				 ECORE_IPC_SLEN(l2, params) +
				 1 + 1);
   ECORE_IPC_PUT32(context);
   ECORE_IPC_PUT32(modifiers);
   ECORE_IPC_PUTS(action, l1);
   ECORE_IPC_PUTS(params, l2);
   ECORE_IPC_PUT8(button);
   ECORE_IPC_PUT8(any_mod);
   ECORE_IPC_ENC_STRUCT_FOOT();
}

ECORE_IPC_DEC_STRUCT_PROTO(_e_ipc_mouse_binding_dec)
{
   ECORE_IPC_DEC_STRUCT_HEAD_MIN(E_Config_Binding_Mouse,
				     4 + 4 +
				     1 +
				     1 +
				     1 + 1);
   ECORE_IPC_CHEKS();
   ECORE_IPC_GET32(context);
   ECORE_IPC_GET32(modifiers);
   ECORE_IPC_GETS(action);
   ECORE_IPC_GETS(params);
   ECORE_IPC_GET8(button);
   ECORE_IPC_GET8(any_mod);
   ECORE_IPC_DEC_STRUCT_FOOT();
}

ECORE_IPC_DEC_EVAS_LIST_PROTO(_e_ipc_key_binding_list_dec)
{
   ECORE_IPC_DEC_EVAS_LIST_HEAD(E_Config_Binding_Key);
   ECORE_IPC_GET32(context);
   ECORE_IPC_GET32(modifiers);
   ECORE_IPC_GETS(key);
   ECORE_IPC_GETS(action);
   ECORE_IPC_GETS(params);
   ECORE_IPC_GET8(any_mod);
   ECORE_IPC_DEC_EVAS_LIST_FOOT();
}

ECORE_IPC_ENC_STRUCT_PROTO(_e_ipc_key_binding_enc)
{
   int l1, l2, l3;
   ECORE_IPC_ENC_STRUCT_HEAD(E_Config_Binding_Key,
			     4 + 4 +
			     ECORE_IPC_SLEN(l1, key) +
			     ECORE_IPC_SLEN(l2, action) +
			     ECORE_IPC_SLEN(l3, params) +
			     1);
   ECORE_IPC_PUT32(context);
   ECORE_IPC_PUT32(modifiers);
   ECORE_IPC_PUTS(key, l1);
   ECORE_IPC_PUTS(action, l2);
   ECORE_IPC_PUTS(params, l3);
   ECORE_IPC_PUT8(any_mod);
   ECORE_IPC_ENC_STRUCT_FOOT();
}

ECORE_IPC_DEC_STRUCT_PROTO(_e_ipc_key_binding_dec)
{
   ECORE_IPC_DEC_STRUCT_HEAD_MIN(E_Config_Binding_Key,
				 4 + 4 +
				 1 +
				 1 +
				 1 +
				 1);
   ECORE_IPC_CHEKS();
   ECORE_IPC_GET32(context);
   ECORE_IPC_GET32(modifiers);
   ECORE_IPC_GETS(key);
   ECORE_IPC_GETS(action);
   ECORE_IPC_GETS(params);
   ECORE_IPC_GET8(any_mod);
   ECORE_IPC_DEC_STRUCT_FOOT();
}