device and network "address_get"
[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_device(char *cmd, char *args)
850 {
851    E_Connman_Element *e, *device;
852    char *path;
853
854    if (!args)
855      {
856         fputs("ERROR: missing the network path\n", stderr);
857         return 1;
858      }
859    _tok(args);
860    path = args;
861
862    e = e_connman_network_get(path);
863    if (!e_connman_network_device_get(e, &device))
864      fputs("ERROR: can't get network device\n", stderr);
865    else
866      e_connman_element_print(stderr, device);
867    return 1;
868 }
869
870 static int
871 _on_cmd_network_get_wifi_ssid(char *cmd, char *args)
872 {
873    unsigned char *bytes;
874    char *path;
875    unsigned int i, count;
876    E_Connman_Element *e;
877
878    if (!args)
879      {
880         fputs("ERROR: missing the network path\n", stderr);
881         return 1;
882      }
883    _tok(args);
884    path = args;
885
886    e = e_connman_network_get(path);
887    if (e_connman_network_wifi_ssid_get(e, &count, &bytes))
888      {
889         printf(":::Network %s Wifi SSID = ", path);
890         for (i = 0; i < count; i++)
891           printf("%#02hhx (\"%c\"), ", bytes[i], bytes[i]);
892         printf("\n");
893      }
894    else
895      fputs("ERROR: can't get network wifi ssid\n", stderr);
896    return 1;
897 }
898
899 static int
900 _on_cmd_network_get_wifi_mode(char *cmd, char *args)
901 {
902    const char *wifi_mode, *path;
903    E_Connman_Element *e;
904
905    if (!args)
906      {
907         fputs("ERROR: missing the network path\n", stderr);
908         return 1;
909      }
910    _tok(args);
911    path = args;
912
913    e = e_connman_network_get(path);
914    if (e_connman_network_wifi_mode_get(e, &wifi_mode))
915      printf(":::Network %s Wifi Mode = \"%s\"\n", path, wifi_mode);
916    else
917      fputs("ERROR: can't get network wifi mode\n", stderr);
918    return 1;
919 }
920
921 static int
922 _on_cmd_network_get_wifi_security(char *cmd, char *args)
923 {
924    const char *wifi_security, *path;
925    E_Connman_Element *e;
926
927    if (!args)
928      {
929         fputs("ERROR: missing the network path\n", stderr);
930         return 1;
931      }
932    _tok(args);
933    path = args;
934
935    e = e_connman_network_get(path);
936    if (e_connman_network_wifi_security_get(e, &wifi_security))
937      printf(":::Network %s Wifi Security = \"%s\"\n", path, wifi_security);
938    else
939      fputs("ERROR: can't get network wifi security\n", stderr);
940    return 1;
941 }
942
943 static int
944 _on_cmd_network_get_wifi_passphrase(char *cmd, char *args)
945 {
946    const char *wifi_passphrase, *path;
947    E_Connman_Element *e;
948
949    if (!args)
950      {
951         fputs("ERROR: missing the network path\n", stderr);
952         return 1;
953      }
954    _tok(args);
955    path = args;
956
957    e = e_connman_network_get(path);
958    if (e_connman_network_wifi_passphrase_get(e, &wifi_passphrase))
959      printf(":::Network %s Wifi Passphrase = \"%s\"\n", path, wifi_passphrase);
960    else
961      fputs("ERROR: can't get network wifi passphrase\n", stderr);
962    return 1;
963 }
964
965 /* Services Commands */
966 static int
967 _on_cmd_service_connect(char *cmd, char *args)
968 {
969    char *path;
970    E_Connman_Element *e;
971
972    if (!args)
973      {
974         fputs("ERROR: missing the service path\n", stderr);
975         return 1;
976      }
977    _tok(args);
978    path = args;
979
980    e = e_connman_service_get(path);
981    if (e_connman_service_connect(e, NULL, NULL))
982      printf(":::Connecting to Service %s...\n", path);
983    else
984      fputs("ERROR: can't connect to service\n", stderr);
985    return 1;
986 }
987
988 static int
989 _on_cmd_service_disconnect(char *cmd, char *args)
990 {
991    char *path;
992    E_Connman_Element *e;
993
994    if (!args)
995      {
996         fputs("ERROR: missing the service path\n", stderr);
997         return 1;
998      }
999    _tok(args);
1000    path = args;
1001
1002    e = e_connman_service_get(path);
1003    if (e_connman_service_disconnect(e, NULL, NULL))
1004      printf(":::Disconnecting Service %s...\n", path);
1005    else
1006      fputs("ERROR: can't disconnect service\n", stderr);
1007    return 1;
1008 }
1009
1010 static int
1011 _on_cmd_service_remove(char *cmd, char *args)
1012 {
1013    char *path;
1014    E_Connman_Element *e;
1015
1016    if (!args)
1017      {
1018         fputs("ERROR: missing the service path\n", stderr);
1019         return 1;
1020      }
1021    _tok(args);
1022    path = args;
1023
1024    e = e_connman_service_get(path);
1025    if (e_connman_service_remove(e, NULL, NULL))
1026      printf(":::Removing Service %s...\n", path);
1027    else
1028      fputs("ERROR: can't remove service\n", stderr);
1029    return 1;
1030 }
1031
1032 static int
1033 _on_cmd_service_move_before(char *cmd, char *args)
1034 {
1035    char *path, *service_path;
1036    E_Connman_Element *e;
1037
1038    if (!args)
1039      {
1040         fputs("ERROR: missing the service path\n", stderr);
1041         return 1;
1042      }
1043    service_path = args;
1044    path = _tok(args);
1045
1046    if (!path)
1047      {
1048         fputs("ERROR: missing the object service\n", stderr);
1049         return 1;
1050      }
1051    _tok(path);
1052
1053    e = e_connman_service_get(service_path);
1054    if (e_connman_service_move_before(e, path, NULL, NULL))
1055      printf(":::Moving before %s...\n", path);
1056    else
1057      fputs("ERROR: can't move before\n", stderr);
1058    return 1;
1059 }
1060
1061 static int
1062 _on_cmd_service_move_after(char *cmd, char *args)
1063 {
1064    char *path, *service_path;
1065    E_Connman_Element *e;
1066
1067    if (!args)
1068      {
1069         fputs("ERROR: missing the service path\n", stderr);
1070         return 1;
1071      }
1072    service_path = args;
1073    path = _tok(args);
1074
1075    if (!path)
1076      {
1077         fputs("ERROR: missing the object service\n", stderr);
1078         return 1;
1079      }
1080    _tok(path);
1081
1082    e = e_connman_service_get(service_path);
1083    if (e_connman_service_move_after(e, path, NULL, NULL))
1084      printf(":::Moving after %s...\n", path);
1085    else
1086      fputs("ERROR: can't move after\n", stderr);
1087    return 1;
1088 }
1089
1090 static int
1091 _on_cmd_service_get_state(char *cmd, char *args)
1092 {
1093    const char *state, *path;
1094    E_Connman_Element *e;
1095
1096    if (!args)
1097      {
1098         fputs("ERROR: missing the service path\n", stderr);
1099         return 1;
1100      }
1101    _tok(args);
1102    path = args;
1103
1104    e = e_connman_service_get(path);
1105    if (e_connman_service_state_get(e, &state))
1106      printf(":::Service %s State = \"%s\"\n", path, state);
1107    else
1108      fputs("ERROR: can't get service state\n", stderr);
1109    return 1;
1110 }
1111
1112 static int
1113 _on_cmd_service_get_error(char *cmd, char *args)
1114 {
1115    const char *error, *path;
1116    E_Connman_Element *e;
1117
1118    if (!args)
1119      {
1120         fputs("ERROR: missing the service path\n", stderr);
1121         return 1;
1122      }
1123    _tok(args);
1124    path = args;
1125
1126    e = e_connman_service_get(path);
1127    if (e_connman_service_error_get(e, &error))
1128      printf(":::Service %s Error = \"%s\"\n", path, error);
1129    else
1130      fputs("ERROR: can't get service error\n", stderr);
1131    return 1;
1132 }
1133
1134 static int
1135 _on_cmd_service_get_name(char *cmd, char *args)
1136 {
1137    const char *name, *path;
1138    E_Connman_Element *e;
1139
1140    if (!args)
1141      {
1142         fputs("ERROR: missing the service path\n", stderr);
1143         return 1;
1144      }
1145    _tok(args);
1146    path = args;
1147
1148    e = e_connman_service_get(path);
1149    if (e_connman_service_name_get(e, &name))
1150      printf(":::Service %s Name = \"%s\"\n", path, name);
1151    else
1152      fputs("ERROR: can't get service name\n", stderr);
1153    return 1;
1154 }
1155
1156 static int
1157 _on_cmd_service_get_type(char *cmd, char *args)
1158 {
1159    const char *type, *path;
1160    E_Connman_Element *e;
1161
1162    if (!args)
1163      {
1164         fputs("ERROR: missing the service path\n", stderr);
1165         return 1;
1166      }
1167    _tok(args);
1168    path = args;
1169
1170    e = e_connman_service_get(path);
1171    if (e_connman_service_type_get(e, &type))
1172      printf(":::Service %s Type = \"%s\"\n", path, type);
1173    else
1174      fputs("ERROR: can't get service type\n", stderr);
1175    return 1;
1176 }
1177
1178 static int
1179 _on_cmd_service_get_mode(char *cmd, char *args)
1180 {
1181    const char *mode, *path;
1182    E_Connman_Element *e;
1183
1184    if (!args)
1185      {
1186         fputs("ERROR: missing the service path\n", stderr);
1187         return 1;
1188      }
1189    _tok(args);
1190    path = args;
1191
1192    e = e_connman_service_get(path);
1193    if (e_connman_service_mode_get(e, &mode))
1194      printf(":::Service %s Mode = \"%s\"\n", path, mode);
1195    else
1196      fputs("ERROR: can't get service mode\n", stderr);
1197    return 1;
1198 }
1199
1200 static int
1201 _on_cmd_service_get_security(char *cmd, char *args)
1202 {
1203    const char *security, *path;
1204    E_Connman_Element *e;
1205
1206    if (!args)
1207      {
1208         fputs("ERROR: missing the service path\n", stderr);
1209         return 1;
1210      }
1211    _tok(args);
1212    path = args;
1213
1214    e = e_connman_service_get(path);
1215    if (e_connman_service_security_get(e, &security))
1216      printf(":::Service %s Security = \"%s\"\n", path, security);
1217    else
1218      fputs("ERROR: can't get service security\n", stderr);
1219    return 1;
1220 }
1221
1222 static int
1223 _on_cmd_service_get_passphrase(char *cmd, char *args)
1224 {
1225    const char *passphrase, *path;
1226    E_Connman_Element *e;
1227
1228    if (!args)
1229      {
1230         fputs("ERROR: missing the service path\n", stderr);
1231         return 1;
1232      }
1233    _tok(args);
1234    path = args;
1235
1236    e = e_connman_service_get(path);
1237    if (e_connman_service_passphrase_get(e, &passphrase))
1238      printf(":::Service %s Passphrase = \"%s\"\n", path, passphrase);
1239    else
1240      fputs("ERROR: can't get service passphrase\n", stderr);
1241    return 1;
1242 }
1243
1244 static int
1245 _on_cmd_service_set_passphrase(char *cmd, char *args)
1246 {
1247    char *passphrase, *path;
1248    E_Connman_Element *e;
1249
1250    if (!args)
1251      {
1252         fputs("ERROR: missing the service path\n", stderr);
1253         return 1;
1254      }
1255    path = args;
1256    passphrase = _tok(args);
1257
1258    if (!passphrase)
1259      {
1260         fputs("ERROR: missing the passphrase value\n", stderr);
1261         return 1;
1262      }
1263    _tok(passphrase);
1264
1265    e = e_connman_service_get(path);
1266    if (e_connman_service_passphrase_set(e, passphrase, NULL, NULL))
1267      printf(":::Service %s passphrase set to \"%s\"\n", path, passphrase);
1268    else
1269      fputs("ERROR: can't set service passphrase\n", stderr);
1270    return 1;
1271 }
1272
1273 static int
1274 _on_cmd_service_get_passphrase_required(char *cmd, char *args)
1275 {
1276    const char *path;
1277    bool passphrase;
1278    E_Connman_Element *e;
1279
1280    if (!args)
1281      {
1282         fputs("ERROR: missing the service path\n", stderr);
1283         return 1;
1284      }
1285    _tok(args);
1286    path = args;
1287
1288    e = e_connman_service_get(path);
1289    if (e_connman_service_passphrase_required_get(e, &passphrase))
1290      printf(":::Service %s Passphrase Required = %hhu\n", path, passphrase);
1291    else
1292      fputs("ERROR: can't get service passphrase required\n", stderr);
1293    return 1;
1294 }
1295
1296 static int
1297 _on_cmd_service_get_strength(char *cmd, char *args)
1298 {
1299    const char *path;
1300    unsigned char strength;
1301    E_Connman_Element *e;
1302
1303    if (!args)
1304      {
1305         fputs("ERROR: missing the service path\n", stderr);
1306         return 1;
1307      }
1308    _tok(args);
1309    path = args;
1310
1311    e = e_connman_service_get(path);
1312    if (e_connman_service_strength_get(e, &strength))
1313      printf(":::Service %s Strength = %#02hhx (%d)\n", path, strength, strength);
1314    else
1315      fputs("ERROR: can't get service strength\n", stderr);
1316    return 1;
1317 }
1318
1319 static int
1320 _on_cmd_service_get_favorite(char *cmd, char *args)
1321 {
1322    const char *path;
1323    bool favorite;
1324    E_Connman_Element *e;
1325
1326    if (!args)
1327      {
1328         fputs("ERROR: missing the service path\n", stderr);
1329         return 1;
1330      }
1331    _tok(args);
1332    path = args;
1333
1334    e = e_connman_service_get(path);
1335    if (e_connman_service_favorite_get(e, &favorite))
1336      printf(":::Service %s Favorite = %hhu\n", path, favorite);
1337    else
1338      fputs("ERROR: can't get service favorite\n", stderr);
1339    return 1;
1340 }
1341
1342 static int
1343 _on_cmd_service_get_immutable(char *cmd, char *args)
1344 {
1345    const char *path;
1346    bool immutable;
1347    E_Connman_Element *e;
1348
1349    if (!args)
1350      {
1351         fputs("ERROR: missing the service path\n", stderr);
1352         return 1;
1353      }
1354    _tok(args);
1355    path = args;
1356
1357    e = e_connman_service_get(path);
1358    if (e_connman_service_immutable_get(e, &immutable))
1359      printf(":::Service %s Immutable = %hhu\n", path, immutable);
1360    else
1361      fputs("ERROR: can't get service immutable\n", stderr);
1362    return 1;
1363 }
1364
1365 static int
1366 _on_cmd_service_get_auto_connect(char *cmd, char *args)
1367 {
1368    const char *path;
1369    bool auto_connect;
1370    E_Connman_Element *e;
1371
1372    if (!args)
1373      {
1374         fputs("ERROR: missing the service path\n", stderr);
1375         return 1;
1376      }
1377    _tok(args);
1378    path = args;
1379
1380    e = e_connman_service_get(path);
1381    if (e_connman_service_auto_connect_get(e, &auto_connect))
1382      printf(":::Service %s Auto Connect = %hhu\n", path, auto_connect);
1383    else
1384      fputs("ERROR: can't get service auto connect\n", stderr);
1385    return 1;
1386 }
1387
1388 static int
1389 _on_cmd_service_set_auto_connect(char *cmd, char *args)
1390 {
1391    char *path, *next_args;
1392    bool auto_connect;
1393    E_Connman_Element *e;
1394
1395    if (!args)
1396      {
1397         fputs("ERROR: missing the service path\n", stderr);
1398         return 1;
1399      }
1400    path = args;
1401    next_args = _tok(args);
1402
1403    if (!next_args)
1404      {
1405         fputs("ERROR: missing the auto connect value\n", stderr);
1406         return 1;
1407      }
1408    _tok(next_args);
1409    auto_connect = !!atol(next_args);
1410
1411    e = e_connman_service_get(path);
1412    if (e_connman_service_auto_connect_set(e, auto_connect, NULL, NULL))
1413      printf(":::Service %s auto connect set to %d\n", path, auto_connect);
1414    else
1415      fputs("ERROR: can't set service auto connect\n", stderr);
1416    return 1;
1417 }
1418
1419 static int
1420 _on_cmd_service_get_setup_required(char *cmd, char *args)
1421 {
1422    const char *path;
1423    bool setup_required;
1424    E_Connman_Element *e;
1425
1426    if (!args)
1427      {
1428         fputs("ERROR: missing the service path\n", stderr);
1429         return 1;
1430      }
1431    _tok(args);
1432    path = args;
1433
1434    e = e_connman_service_get(path);
1435    if (e_connman_service_setup_required_get(e, &setup_required))
1436      printf(":::Service %s Setup Required = %hhu\n", path, setup_required);
1437    else
1438      fputs("ERROR: can't get service setup required\n", stderr);
1439    return 1;
1440 }
1441
1442 static int
1443 _on_cmd_service_get_apn(char *cmd, char *args)
1444 {
1445    const char *apn, *path;
1446    E_Connman_Element *e;
1447
1448    if (!args)
1449      {
1450         fputs("ERROR: missing the service path\n", stderr);
1451         return 1;
1452      }
1453    _tok(args);
1454    path = args;
1455
1456    e = e_connman_service_get(path);
1457    if (e_connman_service_apn_get(e, &apn))
1458      printf(":::Service %s APN = \"%s\"\n", path, apn);
1459    else
1460      fputs("ERROR: can't get service APN\n", stderr);
1461    return 1;
1462 }
1463
1464 static int
1465 _on_cmd_service_set_apn(char *cmd, char *args)
1466 {
1467    char *apn, *path;
1468    E_Connman_Element *e;
1469
1470    if (!args)
1471      {
1472         fputs("ERROR: missing the service path\n", stderr);
1473         return 1;
1474      }
1475    path = args;
1476    apn = _tok(args);
1477
1478    if (!apn)
1479      {
1480         fputs("ERROR: missing the apn value\n", stderr);
1481         return 1;
1482      }
1483    _tok(apn);
1484
1485    e = e_connman_service_get(path);
1486    if (e_connman_service_apn_set(e, apn, NULL, NULL))
1487      printf(":::Service %s APN set to \"%s\"\n", path, apn);
1488    else
1489      fputs("ERROR: can't set service APN\n", stderr);
1490    return 1;
1491 }
1492
1493 static int
1494 _on_cmd_service_get_mcc(char *cmd, char *args)
1495 {
1496    const char *mcc, *path;
1497    E_Connman_Element *e;
1498
1499    if (!args)
1500      {
1501         fputs("ERROR: missing the service path\n", stderr);
1502         return 1;
1503      }
1504    _tok(args);
1505    path = args;
1506
1507    e = e_connman_service_get(path);
1508    if (e_connman_service_mcc_get(e, &mcc))
1509      printf(":::Service %s MCC = \"%s\"\n", path, mcc);
1510    else
1511      fputs("ERROR: can't get service MCC\n", stderr);
1512    return 1;
1513 }
1514
1515 static int
1516 _on_cmd_service_get_mnc(char *cmd, char *args)
1517 {
1518    const char *mnc, *path;
1519    E_Connman_Element *e;
1520
1521    if (!args)
1522      {
1523         fputs("ERROR: missing the service path\n", stderr);
1524         return 1;
1525      }
1526    _tok(args);
1527    path = args;
1528
1529    e = e_connman_service_get(path);
1530    if (e_connman_service_mnc_get(e, &mnc))
1531      printf(":::Service %s MNC = \"%s\"\n", path, mnc);
1532    else
1533      fputs("ERROR: can't get service MNC\n", stderr);
1534    return 1;
1535 }
1536
1537 static int
1538 _on_cmd_service_get_roaming(char *cmd, char *args)
1539 {
1540    const char *path;
1541    bool roaming;
1542    E_Connman_Element *e;
1543
1544    if (!args)
1545      {
1546         fputs("ERROR: missing the service path\n", stderr);
1547         return 1;
1548      }
1549    _tok(args);
1550    path = args;
1551
1552    e = e_connman_service_get(path);
1553    if (e_connman_service_roaming_get(e, &roaming))
1554      printf(":::Service %s Roaming = %hhu\n", path, roaming);
1555    else
1556      fputs("ERROR: can't get service roaming\n", stderr);
1557    return 1;
1558 }
1559
1560 static int
1561 _on_cmd_service_get_ipv4_method(char *cmd, char *args)
1562 {
1563    const char *ipv4_method, *path;
1564    E_Connman_Element *e;
1565
1566    if (!args)
1567      {
1568         fputs("ERROR: missing the service path\n", stderr);
1569         return 1;
1570      }
1571    _tok(args);
1572    path = args;
1573
1574    e = e_connman_service_get(path);
1575    if (e_connman_service_ipv4_method_get(e, &ipv4_method))
1576      printf(":::Service %s ipv4 method = \"%s\"\n", path, ipv4_method);
1577    else
1578      fputs("ERROR: can't get service ipv4 method\n", stderr);
1579    return 1;
1580 }
1581
1582 static int
1583 _on_cmd_service_get_ipv4_address(char *cmd, char *args)
1584 {
1585    const char *ipv4_address, *path;
1586    E_Connman_Element *e;
1587
1588    if (!args)
1589      {
1590         fputs("ERROR: missing the service path\n", stderr);
1591         return 1;
1592      }
1593    _tok(args);
1594    path = args;
1595
1596    e = e_connman_service_get(path);
1597    if (e_connman_service_ipv4_address_get(e, &ipv4_address))
1598      printf(":::Service %s ipv4 address = \"%s\"\n", path, ipv4_address);
1599    else
1600      fputs("ERROR: can't get service ipv4 address\n", stderr);
1601    return 1;
1602 }
1603
1604
1605 static int
1606 _on_input(void *data, Ecore_Fd_Handler *fd_handler)
1607 {
1608    char buf[256];
1609    char *cmd, *args;
1610    const struct {
1611       const char *cmd;
1612       int (*cb)(char *cmd, char *args);
1613    } *itr, maps[] = {
1614      {"quit", _on_cmd_quit},
1615      {"sync", _on_cmd_sync},
1616      {"get_all", _on_cmd_get_all},
1617      {"print", _on_cmd_print},
1618      {"get_properties", _on_cmd_get_properties},
1619      {"set_property", _on_cmd_property_set},
1620      {"manager_get", _on_cmd_manager_get},
1621      {"manager_get_profiles", _on_cmd_manager_get_profiles},
1622      {"manager_get_devices", _on_cmd_manager_get_devices},
1623      {"manager_get_services", _on_cmd_manager_get_services},
1624      {"manager_register_agent", _on_cmd_manager_register_agent},
1625      {"manager_unregister_agent", _on_cmd_manager_unregister_agent},
1626      {"manager_get_state", _on_cmd_manager_get_state},
1627      {"manager_get_offline_mode", _on_cmd_manager_get_offline_mode},
1628      {"manager_set_offline_mode", _on_cmd_manager_set_offline_mode},
1629      {"device_propose_scan", _on_cmd_device_propose_scan},
1630      {"device_get_address", _on_cmd_device_get_address},
1631      {"device_get_name", _on_cmd_device_get_name},
1632      {"device_get_type", _on_cmd_device_get_type},
1633      {"device_get_interface", _on_cmd_device_get_interface},
1634      {"device_get_powered", _on_cmd_device_get_powered},
1635      {"device_set_powered", _on_cmd_device_set_powered},
1636      {"device_get_scan_interval", _on_cmd_device_get_scan_interval},
1637      {"device_set_scan_interval", _on_cmd_device_set_scan_interval},
1638      {"device_get_scanning", _on_cmd_device_get_scanning},
1639      {"device_get_networks", _on_cmd_device_get_networks},
1640      {"profile_get_name", _on_cmd_profile_get_name},
1641      {"profile_get_offline_mode", _on_cmd_profile_get_offline_mode},
1642      {"profile_set_offline_mode", _on_cmd_profile_set_offline_mode},
1643      {"profile_get_services", _on_cmd_profile_get_services},
1644      {"network_get_address", _on_cmd_network_get_address},
1645      {"network_get_name", _on_cmd_network_get_name},
1646      {"network_get_connected", _on_cmd_network_get_connected},
1647      {"network_get_strength", _on_cmd_network_get_strength},
1648      {"network_get_device", _on_cmd_network_get_device},
1649      {"network_get_wifi_ssid", _on_cmd_network_get_wifi_ssid},
1650      {"network_get_wifi_mode", _on_cmd_network_get_wifi_mode},
1651      {"network_get_wifi_security", _on_cmd_network_get_wifi_security},
1652      {"network_get_wifi_passphrase", _on_cmd_network_get_wifi_passphrase},
1653      {"service_connect", _on_cmd_service_connect},
1654      {"service_disconnect", _on_cmd_service_disconnect},
1655      {"service_remove", _on_cmd_service_remove},
1656      {"service_move_before", _on_cmd_service_move_before},
1657      {"service_move_after", _on_cmd_service_move_after},
1658      {"service_get_state", _on_cmd_service_get_state},
1659      {"service_get_error", _on_cmd_service_get_error},
1660      {"service_get_name", _on_cmd_service_get_name},
1661      {"service_get_type", _on_cmd_service_get_type},
1662      {"service_get_mode", _on_cmd_service_get_mode},
1663      {"service_get_security", _on_cmd_service_get_security},
1664      {"service_get_passphrase", _on_cmd_service_get_passphrase},
1665      {"service_set_passphrase", _on_cmd_service_set_passphrase},
1666      {"service_get_passphrase_required", _on_cmd_service_get_passphrase_required},
1667      {"service_get_strength", _on_cmd_service_get_strength},
1668      {"service_get_favorite", _on_cmd_service_get_favorite},
1669      {"service_get_immutable", _on_cmd_service_get_immutable},
1670      {"service_get_auto_connect", _on_cmd_service_get_auto_connect},
1671      {"service_set_auto_connect", _on_cmd_service_set_auto_connect},
1672      {"service_get_setup_required", _on_cmd_service_get_setup_required},
1673      {"service_get_apn", _on_cmd_service_get_apn},
1674      {"service_set_apn", _on_cmd_service_set_apn},
1675      {"service_get_mcc", _on_cmd_service_get_mcc},
1676      {"service_get_mnc", _on_cmd_service_get_mnc},
1677      {"service_get_roaming", _on_cmd_service_get_roaming},
1678      {"service_get_ipv4_method", _on_cmd_service_get_ipv4_method},
1679      {"service_get_ipv4_address", _on_cmd_service_get_ipv4_address},
1680      {NULL, NULL}
1681    };
1682
1683
1684    if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR))
1685      {
1686         fputs("ERROR: reading from stdin, exit\n", stderr);
1687         return 0;
1688      }
1689
1690    if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
1691      {
1692         fputs("ERROR: nothing to read?\n", stderr);
1693         return 0;
1694      }
1695
1696    if (!fgets(buf, sizeof(buf), stdin))
1697      {
1698         fprintf(stderr, "ERROR: could not read command: %s\n", strerror(errno));
1699         ecore_main_loop_quit();
1700         return 0;
1701      }
1702
1703    cmd = buf;
1704    while (isspace(*cmd))
1705      cmd++;
1706
1707    args = strchr(cmd, ' ');
1708    if (args)
1709      {
1710         char *p;
1711
1712         *args = '\0';
1713         args++;
1714
1715         while (isspace(*args))
1716           args++;
1717
1718         p = args + strlen(args) - 1;
1719         if (*p == '\n')
1720           *p = '\0';
1721      }
1722    else
1723      {
1724         char *p;
1725
1726         p = cmd + strlen(cmd) - 1;
1727         if (*p == '\n')
1728           *p = '\0';
1729      }
1730
1731    if (strcmp(cmd, "help") == 0)
1732      {
1733         if (args)
1734           {
1735              printf("Commands with '%s' in the name:\n", args);
1736              for (itr = maps; itr->cmd != NULL; itr++)
1737                if (strstr(itr->cmd, args))
1738                  printf("\t%s\n", itr->cmd);
1739           }
1740         else
1741           {
1742              fputs("Commands:\n", stdout);
1743              for (itr = maps; itr->cmd != NULL; itr++)
1744                printf("\t%s\n", itr->cmd);
1745           }
1746         fputc('\n', stdout);
1747         return 1;
1748      }
1749
1750    for (itr = maps; itr->cmd != NULL; itr++)
1751      if (strcmp(itr->cmd, cmd) == 0)
1752        return itr->cb(cmd, args);
1753
1754    printf("unknown command \"%s\", args=%s\n", cmd, args);
1755    return 1;
1756 }
1757
1758 int
1759 main(int argc, char *argv[])
1760 {
1761    E_DBus_Connection *c;
1762
1763    ecore_init();
1764    e_dbus_init();
1765    eina_init();
1766
1767    c = e_dbus_bus_get(DBUS_BUS_SYSTEM);
1768    if (!c) {
1769       printf("ERROR: can't connect to system session\n");
1770       return -1;
1771    }
1772
1773    e_connman_system_init(c);
1774    ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_ADD, _on_element_add, NULL);
1775    ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_DEL, _on_element_del, NULL);
1776    ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_UPDATED,
1777                            _on_element_updated, NULL);
1778
1779    ecore_main_fd_handler_add
1780      (0, ECORE_FD_READ | ECORE_FD_ERROR, _on_input, NULL, NULL, NULL);
1781
1782    ecore_main_loop_begin();
1783
1784    e_connman_system_shutdown();
1785
1786    e_dbus_connection_close(c);
1787    eina_shutdown();
1788    e_dbus_shutdown();
1789    ecore_shutdown();
1790
1791    fputs("DBG: clean exit.\n", stderr);
1792
1793    return 0;
1794 }