more easy properties for network, fix typo with "Strength".
[framework/uifw/edbus.git] / src / bin / e_dbus_connman_test.c
1 #include "E_Connman.h"
2 #include <stdio.h>
3 #include <string.h>
4 #include <ctype.h>
5 #include <errno.h>
6
7 static void
8 _elements_print(E_Connman_Element **elements, int count)
9 {
10    int i;
11    for (i = 0; i < count; i++)
12      {
13         printf("--- element %d:\n", i);
14         e_connman_element_print(stdout, elements[i]);
15      }
16    free(elements);
17    printf("END: all elements count = %d\n", count);
18 }
19
20 static int
21 _on_element_add(void *data, int type, void *info)
22 {
23    E_Connman_Element *element = info;
24    printf(">>> %s\n", element->path);
25    return 1;
26 }
27
28 static int
29 _on_element_del(void *data, int type, void *info)
30 {
31    E_Connman_Element *element = info;
32    printf("<<< %s\n", element->path);
33    return 1;
34 }
35
36 static int
37 _on_element_updated(void *data, int type, void *info)
38 {
39    E_Connman_Element *element = info;
40    printf("!!! %s\n", element->path);
41    e_connman_element_print(stderr, element);
42    return 1;
43 }
44
45 static int
46 _on_cmd_quit(char *cmd, char *args)
47 {
48    fputs("Bye!\n", stderr);
49    ecore_main_loop_quit();
50    return 0;
51 }
52
53 static int
54 _on_cmd_sync(char *cmd, char *args)
55 {
56    e_connman_manager_sync_elements();
57    return 1;
58 }
59
60 static char *
61 _tok(char *p)
62 {
63    p = strchr(p, ' ');
64    if (!p)
65      return NULL;
66
67    *p = '\0';
68    p++;
69    while (isspace(*p))
70      p++;
71    if (*p == '\0')
72      return NULL;
73
74    return p;
75 }
76
77 static int
78 _on_cmd_get_all(char *cmd, char *args)
79 {
80    E_Connman_Element **elements;
81    char *type;
82    unsigned int count;
83    bool ret;
84
85    if (!args)
86      type = NULL;
87    else
88      type = args;
89
90    if (type)
91      ret = e_connman_elements_get_all_type(type, &count, &elements);
92    else
93      ret = e_connman_elements_get_all(&count, &elements);
94
95    if (!ret)
96      fputs("ERROR: could not get elements\n", stderr);
97    else
98      {
99         printf("BEG: all elements type=%s count = %d\n", type, count);
100         _elements_print(elements, count);
101      }
102
103    return 1;
104 }
105
106 static E_Connman_Element *
107 _element_from_args(char *args, char **next_args)
108 {
109    E_Connman_Element *element;
110
111    if (!args)
112      {
113         fputs("ERROR: missing element path\n", stderr);
114         *next_args = NULL;
115         return NULL;
116      }
117
118    *next_args = _tok(args);
119    element = e_connman_element_get(args);
120    if (!element)
121      fprintf(stderr, "ERROR: no element called \"%s\".\n", args);
122
123    return element;
124 }
125
126 static int
127 _on_cmd_print(char *cmd, char *args)
128 {
129    char *next_args;
130    E_Connman_Element *element = _element_from_args(args, &next_args);
131    if (element)
132      e_connman_element_print(stdout, element);
133    return 1;
134 }
135
136 static int
137 _on_cmd_get_properties(char *cmd, char *args)
138 {
139    char *next_args;
140    E_Connman_Element *element = _element_from_args(args, &next_args);
141    if (element)
142      e_connman_element_properties_sync(element);
143    return 1;
144 }
145
146 static int
147 _on_cmd_property_set(char *cmd, char *args)
148 {
149    char *next_args, *name, *p;
150    E_Connman_Element *element = _element_from_args(args, &next_args);
151    void *value;
152    long vlong;
153    unsigned short vu16;
154    unsigned int vu32;
155    int type;
156
157    if (!element)
158      return 1;
159
160    if (!next_args)
161      {
162         fputs("ERROR: missing parameters name, type and value.\n", stderr);
163         return 1;
164      }
165
166    name = next_args;
167    p = _tok(name);
168    if (!p)
169      {
170         fputs("ERROR: missing parameters type and value.\n", stderr);
171         return 1;
172      }
173
174    next_args = _tok(p);
175    if (!next_args)
176      {
177         fputs("ERROR: missing parameter value.\n", stderr);
178         return 1;
179      }
180
181    type = p[0];
182    switch (type)
183      {
184       case DBUS_TYPE_BOOLEAN:
185          vlong = !!atol(next_args);
186          value = (void *)vlong;
187          fprintf(stderr, "DBG: boolean is: %ld\n", vlong);
188          break;
189       case DBUS_TYPE_UINT16:
190          vu16 = strtol(next_args, &p, 0);
191          if (p == next_args)
192            {
193               fprintf(stderr, "ERROR: invalid number \"%s\".\n", next_args);
194               return 1;
195            }
196          value = &vu16;
197          fprintf(stderr, "DBG: u16 is: %hu\n", vu16);
198          break;
199       case DBUS_TYPE_UINT32:
200          vu32 = strtol(next_args, &p, 0);
201          if (p == next_args)
202            {
203               fprintf(stderr, "ERROR: invalid number \"%s\".\n", next_args);
204               return 1;
205            }
206          value = &vu32;
207          fprintf(stderr, "DBG: u16 is: %u\n", vu32);
208          break;
209       case DBUS_TYPE_STRING:
210       case DBUS_TYPE_OBJECT_PATH:
211          p = next_args + strlen(next_args);
212          if (p > next_args)
213            p--;
214          while (p > next_args && isspace(*p))
215            p--;
216          if (p <= next_args)
217            {
218               fprintf(stderr, "ERROR: invalid string \"%s\".\n", next_args);
219            }
220          p[1] = '\0';
221          value = next_args;
222          fprintf(stderr, "DBG: string is: \"%s\"\n", next_args);
223          break;
224       default:
225          fprintf(stderr, "ERROR: don't know how to parse type '%c' (%d)\n",
226                  type, type);
227          return 1;
228      }
229
230    fprintf(stderr, "set_property %s [%p] %s %c %p...\n",
231            args, element, name, type, value);
232    if (!e_connman_element_property_set(element, name, type, value))
233      {
234         fputs("ERROR: error setting property.\n", stderr);
235         return 1;
236      }
237    return 1;
238 }
239
240
241 /* Manager Commands */
242
243 static int
244 _on_cmd_manager_get(char *cmd, char *args)
245 {
246    E_Connman_Element *element;
247    element = e_connman_manager_get();
248    e_connman_element_print(stderr, element);
249    return 1;
250 }
251
252 static int
253 _on_cmd_manager_get_profiles(char *cmd, char *args)
254 {
255    unsigned int count;
256    E_Connman_Element **profiles;
257
258    if (!e_connman_manager_profiles_get(&count, &profiles))
259      {
260         fputs("ERROR: can't get profiles\n", stderr);
261         return 1;
262      }
263    printf("BEG: all manager profiles elements count = %d\n", count);
264    _elements_print(profiles, count);
265    return 1;
266 }
267
268 static int
269 _on_cmd_manager_get_devices(char *cmd, char *args)
270 {
271    unsigned int count;
272    E_Connman_Element **devices;
273
274    if (!e_connman_manager_devices_get(&count, &devices))
275      {
276         fputs("ERROR: can't get devices\n", stderr);
277         return 1;
278      }
279    printf("BEG: all manager devices elements count = %d\n", count);
280    _elements_print(devices, count);
281    return 1;
282 }
283
284 static int
285 _on_cmd_manager_get_services(char *cmd, char *args)
286 {
287    unsigned int count;
288    E_Connman_Element **services;
289
290    if (!e_connman_manager_services_get(&count, &services))
291      {
292         fputs("ERROR: can't get services\n", stderr);
293         return 1;
294      }
295    printf("BEG: all manager services elements count = %d\n", count);
296    _elements_print(services, count);
297    return 1;
298 }
299
300 static int
301 _on_cmd_manager_register_agent(char *cmd, char *args)
302 {
303    char *path;
304
305    if (!args)
306      {
307         fputs("ERROR: missing the object path\n", stderr);
308         return 1;
309      }
310
311    path = args;
312    if (e_connman_manager_agent_register(path, NULL, NULL))
313      printf(":::Registering agent %s...\n", path);
314    else
315      fprintf(stderr, "ERROR: can't register agent %s\n", path);
316
317    return 1;
318 }
319
320 static int
321 _on_cmd_manager_unregister_agent(char *cmd, char *args)
322 {
323    char *path;
324
325    if (!args)
326      {
327         fputs("ERROR: missing the object path\n", stderr);
328         return 1;
329      }
330
331    path = args;
332    if (e_connman_manager_agent_unregister(path, NULL, NULL))
333      printf(":::Unregistering agent %s...\n", path);
334    else
335      fprintf(stderr, "ERROR: can't unregister agent %s\n", path);
336
337    return 1;
338 }
339
340 static int
341 _on_cmd_manager_get_state(char *cmd, char *args)
342 {
343    const char *state;
344    if (e_connman_manager_state_get(&state))
345      printf(":::Manager state = \"%s\"\n", state);
346    else
347      fputs("ERROR: can't get manager state\n", stderr);
348    return 1;
349 }
350
351 static int
352 _on_cmd_manager_get_offline_mode(char *cmd, char *args)
353 {
354    bool offline;
355    if (e_connman_manager_offline_mode_get(&offline))
356      printf(":::Manager Offline Mode = %hhu\n", offline);
357    else
358      fputs("ERROR: can't get manager offline mode\n", stderr);
359    return 1;
360 }
361
362 static int
363 _on_cmd_manager_set_offline_mode(char *cmd, char *args)
364 {
365    bool offline;
366    if (!args)
367      {
368         fputs("ERROR: missing the offline mode value\n", stderr);
369         return 1;
370      }
371    _tok(args);
372    offline = !!atol(args);
373    if (e_connman_manager_offline_mode_set(offline, NULL, NULL))
374      printf(":::Manager Offline Mode set to %hhu\n", offline);
375    else
376      fputs("ERROR: can't set manager offline mode\n", stderr);
377    return 1;
378 }
379
380 /* Device Commands */
381 static int
382 _on_cmd_device_propose_scan(char *cmd, char *args)
383 {
384    char *path;
385    E_Connman_Element *e;
386
387    if (!args)
388      {
389         fputs("ERROR: missing the device path\n", stderr);
390         return 1;
391      }
392    _tok(args);
393    path = args;
394
395    e = e_connman_device_get(path);
396    if (e_connman_device_propose_scan(e, NULL, NULL))
397      printf(":::Proposing scan %s...\n", path);
398    else
399      fputs("ERROR: can't propose scan\n", stderr);
400    return 1;
401 }
402
403 static int
404 _on_cmd_device_get_address(char *cmd, char *args)
405 {
406    const char *address, *path;
407    E_Connman_Element *e;
408
409    if (!args)
410      {
411         fputs("ERROR: missing the device path\n", stderr);
412         return 1;
413      }
414    _tok(args);
415    path = args;
416
417    e = e_connman_device_get(path);
418    if (e_connman_device_address_get(e, &address))
419      printf(":::Device %s Address = \"%s\"\n", path, address);
420    else
421      fputs("ERROR: can't get device address\n", stderr);
422    return 1;
423 }
424
425 static int
426 _on_cmd_device_get_name(char *cmd, char *args)
427 {
428    const char *name, *path;
429    E_Connman_Element *e;
430
431    if (!args)
432      {
433         fputs("ERROR: missing the device path\n", stderr);
434         return 1;
435      }
436    _tok(args);
437    path = args;
438
439    e = e_connman_device_get(path);
440    if (e_connman_device_name_get(e, &name))
441      printf(":::Device %s Name = \"%s\"\n", path, name);
442    else
443      fputs("ERROR: can't get device name\n", stderr);
444    return 1;
445 }
446
447 static int
448 _on_cmd_device_get_type(char *cmd, char *args)
449 {
450    const char *type, *path;
451    E_Connman_Element *e;
452
453    if (!args)
454      {
455         fputs("ERROR: missing the device path\n", stderr);
456         return 1;
457      }
458    _tok(args);
459    path = args;
460
461    e = e_connman_device_get(path);
462    if (e_connman_device_type_get(e, &type))
463      printf(":::Device %s Type = \"%s\"\n", path, type);
464    else
465      fputs("ERROR: can't get device type\n", stderr);
466    return 1;
467 }
468
469 static int
470 _on_cmd_device_get_interface(char *cmd, char *args)
471 {
472    const char *interface, *path;
473    E_Connman_Element *e;
474
475    if (!args)
476      {
477         fputs("ERROR: missing the device path\n", stderr);
478         return 1;
479      }
480    _tok(args);
481    path = args;
482
483    e = e_connman_device_get(path);
484    if (e_connman_device_interface_get(e, &interface))
485      printf(":::Device %s Interface = \"%s\"\n", path, interface);
486    else
487      fputs("ERROR: can't get device interface\n", stderr);
488    return 1;
489 }
490
491 static int
492 _on_cmd_device_get_powered(char *cmd, char *args)
493 {
494    char *path;
495    bool powered;
496    E_Connman_Element *e;
497
498    if (!args)
499      {
500         fputs("ERROR: missing the device path\n", stderr);
501         return 1;
502      }
503    _tok(args);
504    path = args;
505
506    e = e_connman_device_get(path);
507    if (e_connman_device_powered_get(e, &powered))
508      printf(":::Device %s Powered = %hhu\n", path, powered);
509    else
510      fputs("ERROR: can't get device powered\n", stderr);
511    return 1;
512 }
513
514 static int
515 _on_cmd_device_set_powered(char *cmd, char *args)
516 {
517    char *device_path, *next_args;
518    bool powered;
519    E_Connman_Element *e;
520
521    if (!args)
522      {
523         fputs("ERROR: missing the device path\n", stderr);
524         return 1;
525      }
526    device_path = args;
527    next_args = _tok(args);
528    if (!next_args)
529      {
530         fputs("ERROR: missing the powered value\n", stderr);
531         return 1;
532      }
533    powered = !!atol(next_args);
534
535    e = e_connman_device_get(device_path);
536    if (e_connman_device_powered_set(e, powered, NULL, NULL))
537      printf(":::Device %s powered set to %hhu\n", device_path, powered);
538    else
539      fputs("ERROR: can't set device powered\n", stderr);
540    return 1;
541 }
542
543 static int
544 _on_cmd_device_get_scan_interval(char *cmd, char *args)
545 {
546    char *path;
547    unsigned short scan_interval;
548    E_Connman_Element *e;
549
550    if (!args)
551      {
552         fputs("ERROR: missing the device path\n", stderr);
553         return 1;
554      }
555    _tok(args);
556    path = args;
557
558    e = e_connman_device_get(path);
559    if (e_connman_device_scan_interval_get(e, &scan_interval))
560      printf(":::Device %s ScanInterval = %hu\n", path, scan_interval);
561    else
562      fputs("ERROR: can't get device scan interval\n", stderr);
563    return 1;
564 }
565
566 static int
567 _on_cmd_device_set_scan_interval(char *cmd, char *args)
568 {
569    char *device_path, *next_args, *p;
570    unsigned short scan_interval;
571    E_Connman_Element *e;
572
573    if (!args)
574      {
575         fputs("ERROR: missing the device path\n", stderr);
576         return 1;
577      }
578    device_path = args;
579    next_args = _tok(args);
580    if (!next_args)
581      {
582         fputs("ERROR: missing the scan interval value\n", stderr);
583         return 1;
584      }
585    scan_interval = strtol(next_args, &p, 0);
586    if (p == next_args)
587      {
588         fprintf(stderr, "ERROR: invalid number \"%s\".\n", next_args);
589         return 1;
590      }
591
592    e = e_connman_device_get(device_path);
593    if (e_connman_device_scan_interval_set(e, scan_interval, NULL, NULL))
594      printf(":::Device %s scan interval set to %hu\n", device_path, scan_interval);
595    else
596      fputs("ERROR: can't set device scan interval\n", stderr);
597    return 1;
598 }
599
600 static int
601 _on_cmd_device_get_scanning(char *cmd, char *args)
602 {
603    char *path;
604    bool scanning;
605    E_Connman_Element *e;
606
607    if (!args)
608      {
609         fputs("ERROR: missing the device path\n", stderr);
610         return 1;
611      }
612    _tok(args);
613    path = args;
614
615    e = e_connman_device_get(path);
616    if (e_connman_device_scanning_get(e, &scanning))
617      printf(":::Device %s Scanning = %hhu\n", path, scanning);
618    else
619      fputs("ERROR: can't get device scanning\n", stderr);
620    return 1;
621 }
622
623 static int
624 _on_cmd_device_get_networks(char *cmd, char *args)
625 {
626    E_Connman_Element **networks;
627    unsigned int count;
628    char *path;
629    E_Connman_Element *e;
630
631    if (!args)
632      {
633         fputs("ERROR: missing the device path\n", stderr);
634         return 1;
635      }
636    _tok(args);
637    path = args;
638
639    e = e_connman_device_get(path);
640    if (!e_connman_device_networks_get(e, &count, &networks))
641      {
642         fputs("ERROR: can't get networks\n", stderr);
643         return 1;
644      }
645
646    printf("BEG: all device network elements count = %d\n", count);
647    _elements_print(networks, count);
648    return 1;
649 }
650
651 /* Profile Commands */
652
653 static int
654 _on_cmd_profile_get_name(char *cmd, char *args)
655 {
656    const char *name, *path;
657    E_Connman_Element *e;
658
659    if (!args)
660      {
661         fputs("ERROR: missing the profile path\n", stderr);
662         return 1;
663      }
664    _tok(args);
665    path = args;
666
667    e = e_connman_profile_get(path);
668    if (e_connman_profile_name_get(e, &name))
669      printf(":::Profile %s Name = \"%s\"\n", path, name);
670    else
671      fputs("ERROR: can't get profile name\n", stderr);
672    return 1;
673 }
674
675 static int
676 _on_cmd_profile_get_offline_mode(char *cmd, char *args)
677 {
678    char *path;
679    bool offline;
680    E_Connman_Element *e;
681
682    if (!args)
683      {
684         fputs("ERROR: missing the profile path\n", stderr);
685         return 1;
686      }
687    _tok(args);
688    path = args;
689
690    e = e_connman_profile_get(path);
691    if (e_connman_profile_offline_mode_get(e, &offline))
692      printf(":::Profile  %s Offline Mode = %hhu\n", path, offline);
693    else
694      fputs("ERROR: can't get profile offline mode\n", stderr);
695    return 1;
696 }
697
698 static int
699 _on_cmd_profile_set_offline_mode(char *cmd, char *args)
700 {
701    char *path, *next_args;
702    bool offline;
703    E_Connman_Element *e;
704
705    if (!args)
706      {
707         fputs("ERROR: missing the profile path\n", stderr);
708         return 1;
709      }
710    path = args;
711    next_args = _tok(args);
712    if (!next_args)
713      {
714         fputs("ERROR: missing the offline mode value\n", stderr);
715         return 1;
716      }
717    _tok(next_args);
718    offline = !!atol(next_args);
719
720    e = e_connman_profile_get(path);
721    if (e_connman_profile_offline_mode_set(e, offline, NULL, NULL))
722      printf(":::Profile %s Offline Mode set to %hhu\n", path, offline);
723    else
724      fputs("ERROR: can't set profile offline mode\n", stderr);
725    return 1;
726 }
727
728 static int
729 _on_cmd_profile_get_services(char *cmd, char *args)
730 {
731    E_Connman_Element **services;
732    E_Connman_Element *e;
733    unsigned int count;
734    char *path;
735
736    if (!args)
737      {
738         fputs("ERROR: missing the profile path\n", stderr);
739         return 1;
740      }
741    _tok(args);
742    path = args;
743
744    e = e_connman_profile_get(path);
745    if (!e_connman_profile_services_get(e, &count, &services))
746      {
747         fputs("ERROR: can't get services\n", stderr);
748         return 1;
749      }
750    printf("BEG: all profile services count = %d\n", count);
751    _elements_print(services, count);
752    return 1;
753 }
754
755
756 /* Network Commands */
757
758 static int
759 _on_cmd_network_get_address(char *cmd, char *args)
760 {
761    const char *address, *path;
762    E_Connman_Element *e;
763
764    if (!args)
765      {
766         fputs("ERROR: missing the network path\n", stderr);
767         return 1;
768      }
769    _tok(args);
770    path = args;
771
772    e = e_connman_network_get(path);
773    if (e_connman_network_address_get(e, &address))
774      printf(":::Network %s Address = \"%s\"\n", path, address);
775    else
776      fputs("ERROR: can't get network address\n", stderr);
777    return 1;
778 }
779
780 static int
781 _on_cmd_network_get_name(char *cmd, char *args)
782 {
783    const char *name, *path;
784    E_Connman_Element *e;
785
786    if (!args)
787      {
788         fputs("ERROR: missing the network path\n", stderr);
789         return 1;
790      }
791    _tok(args);
792    path = args;
793
794    e = e_connman_network_get(path);
795    if (e_connman_network_name_get(e, &name))
796      printf(":::Network %s Name = \"%s\"\n", path, name);
797    else
798      fputs("ERROR: can't get network name\n", stderr);
799    return 1;
800 }
801
802 static int
803 _on_cmd_network_get_connected(char *cmd, char *args)
804 {
805    char *path;
806    bool connected;
807    E_Connman_Element *e;
808
809    if (!args)
810      {
811         fputs("ERROR: missing the network path\n", stderr);
812         return 1;
813      }
814    _tok(args);
815    path = args;
816
817    e = e_connman_network_get(path);
818    if (e_connman_network_connected_get(e, &connected))
819      printf(":::Network %s Connected = %hhu\n", path, connected);
820    else
821      fputs("ERROR: can't get network connected\n", stderr);
822    return 1;
823 }
824
825 static int
826 _on_cmd_network_get_strength(char *cmd, char *args)
827 {
828    char *path;
829    unsigned char strength;
830    E_Connman_Element *e;
831
832    if (!args)
833      {
834         fputs("ERROR: missing the network path\n", stderr);
835         return 1;
836      }
837    _tok(args);
838    path = args;
839
840    e = e_connman_network_get(path);
841    if (e_connman_network_strength_get(e, &strength))
842      printf(":::Network %s Strength = %#02hhx (%d)\n", path, strength, strength);
843    else
844      fputs("ERROR: can't get network strength\n", stderr);
845    return 1;
846 }
847
848 static int
849 _on_cmd_network_get_frequency(char *cmd, char *args)
850 {
851    char *path;
852    unsigned short frequency;
853    E_Connman_Element *e;
854
855    if (!args)
856      {
857         fputs("ERROR: missing the network path\n", stderr);
858         return 1;
859      }
860    _tok(args);
861    path = args;
862
863    e = e_connman_network_get(path);
864    if (e_connman_network_frequency_get(e, &frequency))
865      printf(":::Network %s Frequency = %#04hx (%d)\n", path, frequency, frequency);
866    else
867      fputs("ERROR: can't get network frequency\n", stderr);
868    return 1;
869 }
870
871 static int
872 _on_cmd_network_get_device(char *cmd, char *args)
873 {
874    E_Connman_Element *e, *device;
875    char *path;
876
877    if (!args)
878      {
879         fputs("ERROR: missing the network path\n", stderr);
880         return 1;
881      }
882    _tok(args);
883    path = args;
884
885    e = e_connman_network_get(path);
886    if (!e_connman_network_device_get(e, &device))
887      fputs("ERROR: can't get network device\n", stderr);
888    else
889      e_connman_element_print(stderr, device);
890    return 1;
891 }
892
893 static int
894 _on_cmd_network_get_wifi_ssid(char *cmd, char *args)
895 {
896    unsigned char *bytes;
897    char *path;
898    unsigned int i, count;
899    E_Connman_Element *e;
900
901    if (!args)
902      {
903         fputs("ERROR: missing the network path\n", stderr);
904         return 1;
905      }
906    _tok(args);
907    path = args;
908
909    e = e_connman_network_get(path);
910    if (e_connman_network_wifi_ssid_get(e, &count, &bytes))
911      {
912         printf(":::Network %s Wifi SSID = ", path);
913         for (i = 0; i < count; i++)
914           printf("%#02hhx (\"%c\"), ", bytes[i], bytes[i]);
915         printf("\n");
916      }
917    else
918      fputs("ERROR: can't get network wifi ssid\n", stderr);
919    return 1;
920 }
921
922 static int
923 _on_cmd_network_get_wifi_mode(char *cmd, char *args)
924 {
925    const char *wifi_mode, *path;
926    E_Connman_Element *e;
927
928    if (!args)
929      {
930         fputs("ERROR: missing the network path\n", stderr);
931         return 1;
932      }
933    _tok(args);
934    path = args;
935
936    e = e_connman_network_get(path);
937    if (e_connman_network_wifi_mode_get(e, &wifi_mode))
938      printf(":::Network %s Wifi Mode = \"%s\"\n", path, wifi_mode);
939    else
940      fputs("ERROR: can't get network wifi mode\n", stderr);
941    return 1;
942 }
943
944 static int
945 _on_cmd_network_get_wifi_security(char *cmd, char *args)
946 {
947    const char *wifi_security, *path;
948    E_Connman_Element *e;
949
950    if (!args)
951      {
952         fputs("ERROR: missing the network path\n", stderr);
953         return 1;
954      }
955    _tok(args);
956    path = args;
957
958    e = e_connman_network_get(path);
959    if (e_connman_network_wifi_security_get(e, &wifi_security))
960      printf(":::Network %s Wifi Security = \"%s\"\n", path, wifi_security);
961    else
962      fputs("ERROR: can't get network wifi security\n", stderr);
963    return 1;
964 }
965
966 static int
967 _on_cmd_network_get_wifi_passphrase(char *cmd, char *args)
968 {
969    const char *wifi_passphrase, *path;
970    E_Connman_Element *e;
971
972    if (!args)
973      {
974         fputs("ERROR: missing the network path\n", stderr);
975         return 1;
976      }
977    _tok(args);
978    path = args;
979
980    e = e_connman_network_get(path);
981    if (e_connman_network_wifi_passphrase_get(e, &wifi_passphrase))
982      printf(":::Network %s Wifi Passphrase = \"%s\"\n", path, wifi_passphrase);
983    else
984      fputs("ERROR: can't get network wifi passphrase\n", stderr);
985    return 1;
986 }
987
988 static int
989 _on_cmd_network_get_wifi_channel(char *cmd, char *args)
990 {
991    char *path;
992    E_Connman_Element *e;
993    unsigned short wifi_channel;
994
995    if (!args)
996      {
997         fputs("ERROR: missing the network path\n", stderr);
998         return 1;
999      }
1000    _tok(args);
1001    path = args;
1002
1003    e = e_connman_network_get(path);
1004    if (e_connman_network_wifi_channel_get(e, &wifi_channel))
1005      printf(":::Network %s Wifi Channel = %#02hx (%d)\n", path, wifi_channel, wifi_channel);
1006    else
1007      fputs("ERROR: can't get network wifi channel\n", stderr);
1008    return 1;
1009 }
1010
1011 static int
1012 _on_cmd_network_get_wifi_eap(char *cmd, char *args)
1013 {
1014    const char *wifi_eap, *path;
1015    E_Connman_Element *e;
1016
1017    if (!args)
1018      {
1019         fputs("ERROR: missing the network path\n", stderr);
1020         return 1;
1021      }
1022    _tok(args);
1023    path = args;
1024
1025    e = e_connman_network_get(path);
1026    if (e_connman_network_wifi_eap_get(e, &wifi_eap))
1027      printf(":::Network %s Wifi EAP = \"%s\"\n", path, wifi_eap);
1028    else
1029      fputs("ERROR: can't get network wifi eap\n", stderr);
1030    return 1;
1031 }
1032
1033 /* Services Commands */
1034 static int
1035 _on_cmd_service_connect(char *cmd, char *args)
1036 {
1037    char *path;
1038    E_Connman_Element *e;
1039
1040    if (!args)
1041      {
1042         fputs("ERROR: missing the service path\n", stderr);
1043         return 1;
1044      }
1045    _tok(args);
1046    path = args;
1047
1048    e = e_connman_service_get(path);
1049    if (e_connman_service_connect(e, NULL, NULL))
1050      printf(":::Connecting to Service %s...\n", path);
1051    else
1052      fputs("ERROR: can't connect to service\n", stderr);
1053    return 1;
1054 }
1055
1056 static int
1057 _on_cmd_service_disconnect(char *cmd, char *args)
1058 {
1059    char *path;
1060    E_Connman_Element *e;
1061
1062    if (!args)
1063      {
1064         fputs("ERROR: missing the service path\n", stderr);
1065         return 1;
1066      }
1067    _tok(args);
1068    path = args;
1069
1070    e = e_connman_service_get(path);
1071    if (e_connman_service_disconnect(e, NULL, NULL))
1072      printf(":::Disconnecting Service %s...\n", path);
1073    else
1074      fputs("ERROR: can't disconnect service\n", stderr);
1075    return 1;
1076 }
1077
1078 static int
1079 _on_cmd_service_remove(char *cmd, char *args)
1080 {
1081    char *path;
1082    E_Connman_Element *e;
1083
1084    if (!args)
1085      {
1086         fputs("ERROR: missing the service path\n", stderr);
1087         return 1;
1088      }
1089    _tok(args);
1090    path = args;
1091
1092    e = e_connman_service_get(path);
1093    if (e_connman_service_remove(e, NULL, NULL))
1094      printf(":::Removing Service %s...\n", path);
1095    else
1096      fputs("ERROR: can't remove service\n", stderr);
1097    return 1;
1098 }
1099
1100 static int
1101 _on_cmd_service_move_before(char *cmd, char *args)
1102 {
1103    char *path, *service_path;
1104    E_Connman_Element *e;
1105
1106    if (!args)
1107      {
1108         fputs("ERROR: missing the service path\n", stderr);
1109         return 1;
1110      }
1111    service_path = args;
1112    path = _tok(args);
1113
1114    if (!path)
1115      {
1116         fputs("ERROR: missing the object service\n", stderr);
1117         return 1;
1118      }
1119    _tok(path);
1120
1121    e = e_connman_service_get(service_path);
1122    if (e_connman_service_move_before(e, path, NULL, NULL))
1123      printf(":::Moving before %s...\n", path);
1124    else
1125      fputs("ERROR: can't move before\n", stderr);
1126    return 1;
1127 }
1128
1129 static int
1130 _on_cmd_service_move_after(char *cmd, char *args)
1131 {
1132    char *path, *service_path;
1133    E_Connman_Element *e;
1134
1135    if (!args)
1136      {
1137         fputs("ERROR: missing the service path\n", stderr);
1138         return 1;
1139      }
1140    service_path = args;
1141    path = _tok(args);
1142
1143    if (!path)
1144      {
1145         fputs("ERROR: missing the object service\n", stderr);
1146         return 1;
1147      }
1148    _tok(path);
1149
1150    e = e_connman_service_get(service_path);
1151    if (e_connman_service_move_after(e, path, NULL, NULL))
1152      printf(":::Moving after %s...\n", path);
1153    else
1154      fputs("ERROR: can't move after\n", stderr);
1155    return 1;
1156 }
1157
1158 static int
1159 _on_cmd_service_get_state(char *cmd, char *args)
1160 {
1161    const char *state, *path;
1162    E_Connman_Element *e;
1163
1164    if (!args)
1165      {
1166         fputs("ERROR: missing the service path\n", stderr);
1167         return 1;
1168      }
1169    _tok(args);
1170    path = args;
1171
1172    e = e_connman_service_get(path);
1173    if (e_connman_service_state_get(e, &state))
1174      printf(":::Service %s State = \"%s\"\n", path, state);
1175    else
1176      fputs("ERROR: can't get service state\n", stderr);
1177    return 1;
1178 }
1179
1180 static int
1181 _on_cmd_service_get_error(char *cmd, char *args)
1182 {
1183    const char *error, *path;
1184    E_Connman_Element *e;
1185
1186    if (!args)
1187      {
1188         fputs("ERROR: missing the service path\n", stderr);
1189         return 1;
1190      }
1191    _tok(args);
1192    path = args;
1193
1194    e = e_connman_service_get(path);
1195    if (e_connman_service_error_get(e, &error))
1196      printf(":::Service %s Error = \"%s\"\n", path, error);
1197    else
1198      fputs("ERROR: can't get service error\n", stderr);
1199    return 1;
1200 }
1201
1202 static int
1203 _on_cmd_service_get_name(char *cmd, char *args)
1204 {
1205    const char *name, *path;
1206    E_Connman_Element *e;
1207
1208    if (!args)
1209      {
1210         fputs("ERROR: missing the service path\n", stderr);
1211         return 1;
1212      }
1213    _tok(args);
1214    path = args;
1215
1216    e = e_connman_service_get(path);
1217    if (e_connman_service_name_get(e, &name))
1218      printf(":::Service %s Name = \"%s\"\n", path, name);
1219    else
1220      fputs("ERROR: can't get service name\n", stderr);
1221    return 1;
1222 }
1223
1224 static int
1225 _on_cmd_service_get_type(char *cmd, char *args)
1226 {
1227    const char *type, *path;
1228    E_Connman_Element *e;
1229
1230    if (!args)
1231      {
1232         fputs("ERROR: missing the service path\n", stderr);
1233         return 1;
1234      }
1235    _tok(args);
1236    path = args;
1237
1238    e = e_connman_service_get(path);
1239    if (e_connman_service_type_get(e, &type))
1240      printf(":::Service %s Type = \"%s\"\n", path, type);
1241    else
1242      fputs("ERROR: can't get service type\n", stderr);
1243    return 1;
1244 }
1245
1246 static int
1247 _on_cmd_service_get_mode(char *cmd, char *args)
1248 {
1249    const char *mode, *path;
1250    E_Connman_Element *e;
1251
1252    if (!args)
1253      {
1254         fputs("ERROR: missing the service path\n", stderr);
1255         return 1;
1256      }
1257    _tok(args);
1258    path = args;
1259
1260    e = e_connman_service_get(path);
1261    if (e_connman_service_mode_get(e, &mode))
1262      printf(":::Service %s Mode = \"%s\"\n", path, mode);
1263    else
1264      fputs("ERROR: can't get service mode\n", stderr);
1265    return 1;
1266 }
1267
1268 static int
1269 _on_cmd_service_get_security(char *cmd, char *args)
1270 {
1271    const char *security, *path;
1272    E_Connman_Element *e;
1273
1274    if (!args)
1275      {
1276         fputs("ERROR: missing the service path\n", stderr);
1277         return 1;
1278      }
1279    _tok(args);
1280    path = args;
1281
1282    e = e_connman_service_get(path);
1283    if (e_connman_service_security_get(e, &security))
1284      printf(":::Service %s Security = \"%s\"\n", path, security);
1285    else
1286      fputs("ERROR: can't get service security\n", stderr);
1287    return 1;
1288 }
1289
1290 static int
1291 _on_cmd_service_get_passphrase(char *cmd, char *args)
1292 {
1293    const char *passphrase, *path;
1294    E_Connman_Element *e;
1295
1296    if (!args)
1297      {
1298         fputs("ERROR: missing the service path\n", stderr);
1299         return 1;
1300      }
1301    _tok(args);
1302    path = args;
1303
1304    e = e_connman_service_get(path);
1305    if (e_connman_service_passphrase_get(e, &passphrase))
1306      printf(":::Service %s Passphrase = \"%s\"\n", path, passphrase);
1307    else
1308      fputs("ERROR: can't get service passphrase\n", stderr);
1309    return 1;
1310 }
1311
1312 static int
1313 _on_cmd_service_set_passphrase(char *cmd, char *args)
1314 {
1315    char *passphrase, *path;
1316    E_Connman_Element *e;
1317
1318    if (!args)
1319      {
1320         fputs("ERROR: missing the service path\n", stderr);
1321         return 1;
1322      }
1323    path = args;
1324    passphrase = _tok(args);
1325
1326    if (!passphrase)
1327      {
1328         fputs("ERROR: missing the passphrase value\n", stderr);
1329         return 1;
1330      }
1331    _tok(passphrase);
1332
1333    e = e_connman_service_get(path);
1334    if (e_connman_service_passphrase_set(e, passphrase, NULL, NULL))
1335      printf(":::Service %s passphrase set to \"%s\"\n", path, passphrase);
1336    else
1337      fputs("ERROR: can't set service passphrase\n", stderr);
1338    return 1;
1339 }
1340
1341 static int
1342 _on_cmd_service_get_passphrase_required(char *cmd, char *args)
1343 {
1344    const char *path;
1345    bool passphrase;
1346    E_Connman_Element *e;
1347
1348    if (!args)
1349      {
1350         fputs("ERROR: missing the service path\n", stderr);
1351         return 1;
1352      }
1353    _tok(args);
1354    path = args;
1355
1356    e = e_connman_service_get(path);
1357    if (e_connman_service_passphrase_required_get(e, &passphrase))
1358      printf(":::Service %s Passphrase Required = %hhu\n", path, passphrase);
1359    else
1360      fputs("ERROR: can't get service passphrase required\n", stderr);
1361    return 1;
1362 }
1363
1364 static int
1365 _on_cmd_service_get_strength(char *cmd, char *args)
1366 {
1367    const char *path;
1368    unsigned char strength;
1369    E_Connman_Element *e;
1370
1371    if (!args)
1372      {
1373         fputs("ERROR: missing the service path\n", stderr);
1374         return 1;
1375      }
1376    _tok(args);
1377    path = args;
1378
1379    e = e_connman_service_get(path);
1380    if (e_connman_service_strength_get(e, &strength))
1381      printf(":::Service %s Strength = %#02hhx (%d)\n", path, strength, strength);
1382    else
1383      fputs("ERROR: can't get service strength\n", stderr);
1384    return 1;
1385 }
1386
1387 static int
1388 _on_cmd_service_get_favorite(char *cmd, char *args)
1389 {
1390    const char *path;
1391    bool favorite;
1392    E_Connman_Element *e;
1393
1394    if (!args)
1395      {
1396         fputs("ERROR: missing the service path\n", stderr);
1397         return 1;
1398      }
1399    _tok(args);
1400    path = args;
1401
1402    e = e_connman_service_get(path);
1403    if (e_connman_service_favorite_get(e, &favorite))
1404      printf(":::Service %s Favorite = %hhu\n", path, favorite);
1405    else
1406      fputs("ERROR: can't get service favorite\n", stderr);
1407    return 1;
1408 }
1409
1410 static int
1411 _on_cmd_service_get_immutable(char *cmd, char *args)
1412 {
1413    const char *path;
1414    bool immutable;
1415    E_Connman_Element *e;
1416
1417    if (!args)
1418      {
1419         fputs("ERROR: missing the service path\n", stderr);
1420         return 1;
1421      }
1422    _tok(args);
1423    path = args;
1424
1425    e = e_connman_service_get(path);
1426    if (e_connman_service_immutable_get(e, &immutable))
1427      printf(":::Service %s Immutable = %hhu\n", path, immutable);
1428    else
1429      fputs("ERROR: can't get service immutable\n", stderr);
1430    return 1;
1431 }
1432
1433 static int
1434 _on_cmd_service_get_auto_connect(char *cmd, char *args)
1435 {
1436    const char *path;
1437    bool auto_connect;
1438    E_Connman_Element *e;
1439
1440    if (!args)
1441      {
1442         fputs("ERROR: missing the service path\n", stderr);
1443         return 1;
1444      }
1445    _tok(args);
1446    path = args;
1447
1448    e = e_connman_service_get(path);
1449    if (e_connman_service_auto_connect_get(e, &auto_connect))
1450      printf(":::Service %s Auto Connect = %hhu\n", path, auto_connect);
1451    else
1452      fputs("ERROR: can't get service auto connect\n", stderr);
1453    return 1;
1454 }
1455
1456 static int
1457 _on_cmd_service_set_auto_connect(char *cmd, char *args)
1458 {
1459    char *path, *next_args;
1460    bool auto_connect;
1461    E_Connman_Element *e;
1462
1463    if (!args)
1464      {
1465         fputs("ERROR: missing the service path\n", stderr);
1466         return 1;
1467      }
1468    path = args;
1469    next_args = _tok(args);
1470
1471    if (!next_args)
1472      {
1473         fputs("ERROR: missing the auto connect value\n", stderr);
1474         return 1;
1475      }
1476    _tok(next_args);
1477    auto_connect = !!atol(next_args);
1478
1479    e = e_connman_service_get(path);
1480    if (e_connman_service_auto_connect_set(e, auto_connect, NULL, NULL))
1481      printf(":::Service %s auto connect set to %d\n", path, auto_connect);
1482    else
1483      fputs("ERROR: can't set service auto connect\n", stderr);
1484    return 1;
1485 }
1486
1487 static int
1488 _on_cmd_service_get_setup_required(char *cmd, char *args)
1489 {
1490    const char *path;
1491    bool setup_required;
1492    E_Connman_Element *e;
1493
1494    if (!args)
1495      {
1496         fputs("ERROR: missing the service path\n", stderr);
1497         return 1;
1498      }
1499    _tok(args);
1500    path = args;
1501
1502    e = e_connman_service_get(path);
1503    if (e_connman_service_setup_required_get(e, &setup_required))
1504      printf(":::Service %s Setup Required = %hhu\n", path, setup_required);
1505    else
1506      fputs("ERROR: can't get service setup required\n", stderr);
1507    return 1;
1508 }
1509
1510 static int
1511 _on_cmd_service_get_apn(char *cmd, char *args)
1512 {
1513    const char *apn, *path;
1514    E_Connman_Element *e;
1515
1516    if (!args)
1517      {
1518         fputs("ERROR: missing the service path\n", stderr);
1519         return 1;
1520      }
1521    _tok(args);
1522    path = args;
1523
1524    e = e_connman_service_get(path);
1525    if (e_connman_service_apn_get(e, &apn))
1526      printf(":::Service %s APN = \"%s\"\n", path, apn);
1527    else
1528      fputs("ERROR: can't get service APN\n", stderr);
1529    return 1;
1530 }
1531
1532 static int
1533 _on_cmd_service_set_apn(char *cmd, char *args)
1534 {
1535    char *apn, *path;
1536    E_Connman_Element *e;
1537
1538    if (!args)
1539      {
1540         fputs("ERROR: missing the service path\n", stderr);
1541         return 1;
1542      }
1543    path = args;
1544    apn = _tok(args);
1545
1546    if (!apn)
1547      {
1548         fputs("ERROR: missing the apn value\n", stderr);
1549         return 1;
1550      }
1551    _tok(apn);
1552
1553    e = e_connman_service_get(path);
1554    if (e_connman_service_apn_set(e, apn, NULL, NULL))
1555      printf(":::Service %s APN set to \"%s\"\n", path, apn);
1556    else
1557      fputs("ERROR: can't set service APN\n", stderr);
1558    return 1;
1559 }
1560
1561 static int
1562 _on_cmd_service_get_mcc(char *cmd, char *args)
1563 {
1564    const char *mcc, *path;
1565    E_Connman_Element *e;
1566
1567    if (!args)
1568      {
1569         fputs("ERROR: missing the service path\n", stderr);
1570         return 1;
1571      }
1572    _tok(args);
1573    path = args;
1574
1575    e = e_connman_service_get(path);
1576    if (e_connman_service_mcc_get(e, &mcc))
1577      printf(":::Service %s MCC = \"%s\"\n", path, mcc);
1578    else
1579      fputs("ERROR: can't get service MCC\n", stderr);
1580    return 1;
1581 }
1582
1583 static int
1584 _on_cmd_service_get_mnc(char *cmd, char *args)
1585 {
1586    const char *mnc, *path;
1587    E_Connman_Element *e;
1588
1589    if (!args)
1590      {
1591         fputs("ERROR: missing the service path\n", stderr);
1592         return 1;
1593      }
1594    _tok(args);
1595    path = args;
1596
1597    e = e_connman_service_get(path);
1598    if (e_connman_service_mnc_get(e, &mnc))
1599      printf(":::Service %s MNC = \"%s\"\n", path, mnc);
1600    else
1601      fputs("ERROR: can't get service MNC\n", stderr);
1602    return 1;
1603 }
1604
1605 static int
1606 _on_cmd_service_get_roaming(char *cmd, char *args)
1607 {
1608    const char *path;
1609    bool roaming;
1610    E_Connman_Element *e;
1611
1612    if (!args)
1613      {
1614         fputs("ERROR: missing the service path\n", stderr);
1615         return 1;
1616      }
1617    _tok(args);
1618    path = args;
1619
1620    e = e_connman_service_get(path);
1621    if (e_connman_service_roaming_get(e, &roaming))
1622      printf(":::Service %s Roaming = %hhu\n", path, roaming);
1623    else
1624      fputs("ERROR: can't get service roaming\n", stderr);
1625    return 1;
1626 }
1627
1628 static int
1629 _on_cmd_service_get_ipv4_method(char *cmd, char *args)
1630 {
1631    const char *ipv4_method, *path;
1632    E_Connman_Element *e;
1633
1634    if (!args)
1635      {
1636         fputs("ERROR: missing the service path\n", stderr);
1637         return 1;
1638      }
1639    _tok(args);
1640    path = args;
1641
1642    e = e_connman_service_get(path);
1643    if (e_connman_service_ipv4_method_get(e, &ipv4_method))
1644      printf(":::Service %s ipv4 method = \"%s\"\n", path, ipv4_method);
1645    else
1646      fputs("ERROR: can't get service ipv4 method\n", stderr);
1647    return 1;
1648 }
1649
1650 static int
1651 _on_cmd_service_get_ipv4_address(char *cmd, char *args)
1652 {
1653    const char *ipv4_address, *path;
1654    E_Connman_Element *e;
1655
1656    if (!args)
1657      {
1658         fputs("ERROR: missing the service path\n", stderr);
1659         return 1;
1660      }
1661    _tok(args);
1662    path = args;
1663
1664    e = e_connman_service_get(path);
1665    if (e_connman_service_ipv4_address_get(e, &ipv4_address))
1666      printf(":::Service %s ipv4 address = \"%s\"\n", path, ipv4_address);
1667    else
1668      fputs("ERROR: can't get service ipv4 address\n", stderr);
1669    return 1;
1670 }
1671
1672
1673 static int
1674 _on_input(void *data, Ecore_Fd_Handler *fd_handler)
1675 {
1676    char buf[256];
1677    char *cmd, *args;
1678    const struct {
1679       const char *cmd;
1680       int (*cb)(char *cmd, char *args);
1681    } *itr, maps[] = {
1682      {"quit", _on_cmd_quit},
1683      {"sync", _on_cmd_sync},
1684      {"get_all", _on_cmd_get_all},
1685      {"print", _on_cmd_print},
1686      {"get_properties", _on_cmd_get_properties},
1687      {"set_property", _on_cmd_property_set},
1688      {"manager_get", _on_cmd_manager_get},
1689      {"manager_get_profiles", _on_cmd_manager_get_profiles},
1690      {"manager_get_devices", _on_cmd_manager_get_devices},
1691      {"manager_get_services", _on_cmd_manager_get_services},
1692      {"manager_register_agent", _on_cmd_manager_register_agent},
1693      {"manager_unregister_agent", _on_cmd_manager_unregister_agent},
1694      {"manager_get_state", _on_cmd_manager_get_state},
1695      {"manager_get_offline_mode", _on_cmd_manager_get_offline_mode},
1696      {"manager_set_offline_mode", _on_cmd_manager_set_offline_mode},
1697      {"device_propose_scan", _on_cmd_device_propose_scan},
1698      {"device_get_address", _on_cmd_device_get_address},
1699      {"device_get_name", _on_cmd_device_get_name},
1700      {"device_get_type", _on_cmd_device_get_type},
1701      {"device_get_interface", _on_cmd_device_get_interface},
1702      {"device_get_powered", _on_cmd_device_get_powered},
1703      {"device_set_powered", _on_cmd_device_set_powered},
1704      {"device_get_scan_interval", _on_cmd_device_get_scan_interval},
1705      {"device_set_scan_interval", _on_cmd_device_set_scan_interval},
1706      {"device_get_scanning", _on_cmd_device_get_scanning},
1707      {"device_get_networks", _on_cmd_device_get_networks},
1708      {"profile_get_name", _on_cmd_profile_get_name},
1709      {"profile_get_offline_mode", _on_cmd_profile_get_offline_mode},
1710      {"profile_set_offline_mode", _on_cmd_profile_set_offline_mode},
1711      {"profile_get_services", _on_cmd_profile_get_services},
1712      {"network_get_address", _on_cmd_network_get_address},
1713      {"network_get_name", _on_cmd_network_get_name},
1714      {"network_get_connected", _on_cmd_network_get_connected},
1715      {"network_get_strength", _on_cmd_network_get_strength},
1716      {"network_get_frequency", _on_cmd_network_get_frequency},
1717      {"network_get_device", _on_cmd_network_get_device},
1718      {"network_get_wifi_ssid", _on_cmd_network_get_wifi_ssid},
1719      {"network_get_wifi_mode", _on_cmd_network_get_wifi_mode},
1720      {"network_get_wifi_security", _on_cmd_network_get_wifi_security},
1721      {"network_get_wifi_passphrase", _on_cmd_network_get_wifi_passphrase},
1722      {"network_get_wifi_channel", _on_cmd_network_get_wifi_channel},
1723      {"network_get_wifi_eap", _on_cmd_network_get_wifi_eap},
1724      {"service_connect", _on_cmd_service_connect},
1725      {"service_disconnect", _on_cmd_service_disconnect},
1726      {"service_remove", _on_cmd_service_remove},
1727      {"service_move_before", _on_cmd_service_move_before},
1728      {"service_move_after", _on_cmd_service_move_after},
1729      {"service_get_state", _on_cmd_service_get_state},
1730      {"service_get_error", _on_cmd_service_get_error},
1731      {"service_get_name", _on_cmd_service_get_name},
1732      {"service_get_type", _on_cmd_service_get_type},
1733      {"service_get_mode", _on_cmd_service_get_mode},
1734      {"service_get_security", _on_cmd_service_get_security},
1735      {"service_get_passphrase", _on_cmd_service_get_passphrase},
1736      {"service_set_passphrase", _on_cmd_service_set_passphrase},
1737      {"service_get_passphrase_required", _on_cmd_service_get_passphrase_required},
1738      {"service_get_strength", _on_cmd_service_get_strength},
1739      {"service_get_favorite", _on_cmd_service_get_favorite},
1740      {"service_get_immutable", _on_cmd_service_get_immutable},
1741      {"service_get_auto_connect", _on_cmd_service_get_auto_connect},
1742      {"service_set_auto_connect", _on_cmd_service_set_auto_connect},
1743      {"service_get_setup_required", _on_cmd_service_get_setup_required},
1744      {"service_get_apn", _on_cmd_service_get_apn},
1745      {"service_set_apn", _on_cmd_service_set_apn},
1746      {"service_get_mcc", _on_cmd_service_get_mcc},
1747      {"service_get_mnc", _on_cmd_service_get_mnc},
1748      {"service_get_roaming", _on_cmd_service_get_roaming},
1749      {"service_get_ipv4_method", _on_cmd_service_get_ipv4_method},
1750      {"service_get_ipv4_address", _on_cmd_service_get_ipv4_address},
1751      {NULL, NULL}
1752    };
1753
1754
1755    if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR))
1756      {
1757         fputs("ERROR: reading from stdin, exit\n", stderr);
1758         return 0;
1759      }
1760
1761    if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
1762      {
1763         fputs("ERROR: nothing to read?\n", stderr);
1764         return 0;
1765      }
1766
1767    if (!fgets(buf, sizeof(buf), stdin))
1768      {
1769         fprintf(stderr, "ERROR: could not read command: %s\n", strerror(errno));
1770         ecore_main_loop_quit();
1771         return 0;
1772      }
1773
1774    cmd = buf;
1775    while (isspace(*cmd))
1776      cmd++;
1777
1778    args = strchr(cmd, ' ');
1779    if (args)
1780      {
1781         char *p;
1782
1783         *args = '\0';
1784         args++;
1785
1786         while (isspace(*args))
1787           args++;
1788
1789         p = args + strlen(args) - 1;
1790         if (*p == '\n')
1791           *p = '\0';
1792      }
1793    else
1794      {
1795         char *p;
1796
1797         p = cmd + strlen(cmd) - 1;
1798         if (*p == '\n')
1799           *p = '\0';
1800      }
1801
1802    if (strcmp(cmd, "help") == 0)
1803      {
1804         if (args)
1805           {
1806              printf("Commands with '%s' in the name:\n", args);
1807              for (itr = maps; itr->cmd != NULL; itr++)
1808                if (strstr(itr->cmd, args))
1809                  printf("\t%s\n", itr->cmd);
1810           }
1811         else
1812           {
1813              fputs("Commands:\n", stdout);
1814              for (itr = maps; itr->cmd != NULL; itr++)
1815                printf("\t%s\n", itr->cmd);
1816           }
1817         fputc('\n', stdout);
1818         return 1;
1819      }
1820
1821    for (itr = maps; itr->cmd != NULL; itr++)
1822      if (strcmp(itr->cmd, cmd) == 0)
1823        return itr->cb(cmd, args);
1824
1825    printf("unknown command \"%s\", args=%s\n", cmd, args);
1826    return 1;
1827 }
1828
1829 int
1830 main(int argc, char *argv[])
1831 {
1832    E_DBus_Connection *c;
1833
1834    ecore_init();
1835    e_dbus_init();
1836    eina_init();
1837
1838    c = e_dbus_bus_get(DBUS_BUS_SYSTEM);
1839    if (!c) {
1840       printf("ERROR: can't connect to system session\n");
1841       return -1;
1842    }
1843
1844    e_connman_system_init(c);
1845    ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_ADD, _on_element_add, NULL);
1846    ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_DEL, _on_element_del, NULL);
1847    ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_UPDATED,
1848                            _on_element_updated, NULL);
1849
1850    ecore_main_fd_handler_add
1851      (0, ECORE_FD_READ | ECORE_FD_ERROR, _on_input, NULL, NULL, NULL);
1852
1853    ecore_main_loop_begin();
1854
1855    e_connman_system_shutdown();
1856
1857    e_dbus_connection_close(c);
1858    eina_shutdown();
1859    e_dbus_shutdown();
1860    ecore_shutdown();
1861
1862    fputs("DBG: clean exit.\n", stderr);
1863
1864    return 0;
1865 }