more manager methods, not so useful, but they were easy.
[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 static int
381 _on_cmd_manager_request_scan(char *cmd, char *args)
382 {
383    if (args)
384      _tok(args);
385
386    if (!args)
387      args = "";
388
389    if (e_connman_manager_request_scan(args, NULL, NULL))
390      printf(":::Manager Request Scan for %s\n", args[0] ? args : "<all>");
391    else
392      fputs("ERROR: can't request scan on manager\n", stderr);
393    return 1;
394 }
395
396 static int
397 _on_cmd_manager_technology_enable(char *cmd, char *args)
398 {
399    if (!args)
400      {
401         fputs("ERROR: missing the technology type\n", stderr);
402         return 1;
403      }
404    _tok(args);
405
406    if (e_connman_manager_technology_enable(args, NULL, NULL))
407      printf(":::Manager Enable Technology %s\n", args);
408    else
409      fputs("ERROR: can't enable technology on manager\n", stderr);
410    return 1;
411 }
412
413 static int
414 _on_cmd_manager_technology_disable(char *cmd, char *args)
415 {
416    if (!args)
417      {
418         fputs("ERROR: missing the technology type\n", stderr);
419         return 1;
420      }
421    _tok(args);
422
423    if (e_connman_manager_technology_disable(args, NULL, NULL))
424      printf(":::Manager Disable Technology %s\n", args);
425    else
426      fputs("ERROR: can't disable technology on manager\n", stderr);
427    return 1;
428 }
429
430 static int
431 _on_cmd_manager_profile_remove(char *cmd, char *args)
432 {
433    E_Connman_Element *e;
434
435    if (!args)
436      {
437         fputs("ERROR: missing the profile path\n", stderr);
438         return 1;
439      }
440    _tok(args);
441
442    e = e_connman_profile_get(args);
443    if (e_connman_manager_profile_remove(e, NULL, NULL))
444      printf(":::Manager Remove Profile %s\n", args);
445    else
446      fputs("ERROR: can't remove profile from manager\n", stderr);
447    return 1;
448 }
449
450 static int
451 _on_cmd_manager_profile_get_active(char *cmd, char *args)
452 {
453    E_Connman_Element *e;
454
455    if (!e_connman_manager_profile_active_get(&e))
456      fputs("ERROR: can't active_get profile from manager\n", stderr);
457    else
458      e_connman_element_print(stderr, e);
459    return 1;
460 }
461
462 static int
463 _on_cmd_manager_profile_set_active(char *cmd, char *args)
464 {
465    E_Connman_Element *e;
466
467    if (!args)
468      {
469         fputs("ERROR: missing the profile path\n", stderr);
470         return 1;
471      }
472    _tok(args);
473
474    e = e_connman_profile_get(args);
475    if (e_connman_manager_profile_active_set(e, NULL, NULL))
476      printf(":::Manager Active Profile set to %s\n", args);
477    else
478      fputs("ERROR: can't set active profile\n", stderr);
479    return 1;
480 }
481
482 /* Device Commands */
483 static int
484 _on_cmd_device_propose_scan(char *cmd, char *args)
485 {
486    char *path;
487    E_Connman_Element *e;
488
489    if (!args)
490      {
491         fputs("ERROR: missing the device path\n", stderr);
492         return 1;
493      }
494    _tok(args);
495    path = args;
496
497    e = e_connman_device_get(path);
498    if (e_connman_device_propose_scan(e, NULL, NULL))
499      printf(":::Proposing scan %s...\n", path);
500    else
501      fputs("ERROR: can't propose scan\n", stderr);
502    return 1;
503 }
504
505 static int
506 _on_cmd_device_get_address(char *cmd, char *args)
507 {
508    const char *address, *path;
509    E_Connman_Element *e;
510
511    if (!args)
512      {
513         fputs("ERROR: missing the device path\n", stderr);
514         return 1;
515      }
516    _tok(args);
517    path = args;
518
519    e = e_connman_device_get(path);
520    if (e_connman_device_address_get(e, &address))
521      printf(":::Device %s Address = \"%s\"\n", path, address);
522    else
523      fputs("ERROR: can't get device address\n", stderr);
524    return 1;
525 }
526
527 static int
528 _on_cmd_device_get_name(char *cmd, char *args)
529 {
530    const char *name, *path;
531    E_Connman_Element *e;
532
533    if (!args)
534      {
535         fputs("ERROR: missing the device path\n", stderr);
536         return 1;
537      }
538    _tok(args);
539    path = args;
540
541    e = e_connman_device_get(path);
542    if (e_connman_device_name_get(e, &name))
543      printf(":::Device %s Name = \"%s\"\n", path, name);
544    else
545      fputs("ERROR: can't get device name\n", stderr);
546    return 1;
547 }
548
549 static int
550 _on_cmd_device_get_type(char *cmd, char *args)
551 {
552    const char *type, *path;
553    E_Connman_Element *e;
554
555    if (!args)
556      {
557         fputs("ERROR: missing the device path\n", stderr);
558         return 1;
559      }
560    _tok(args);
561    path = args;
562
563    e = e_connman_device_get(path);
564    if (e_connman_device_type_get(e, &type))
565      printf(":::Device %s Type = \"%s\"\n", path, type);
566    else
567      fputs("ERROR: can't get device type\n", stderr);
568    return 1;
569 }
570
571 static int
572 _on_cmd_device_get_interface(char *cmd, char *args)
573 {
574    const char *interface, *path;
575    E_Connman_Element *e;
576
577    if (!args)
578      {
579         fputs("ERROR: missing the device path\n", stderr);
580         return 1;
581      }
582    _tok(args);
583    path = args;
584
585    e = e_connman_device_get(path);
586    if (e_connman_device_interface_get(e, &interface))
587      printf(":::Device %s Interface = \"%s\"\n", path, interface);
588    else
589      fputs("ERROR: can't get device interface\n", stderr);
590    return 1;
591 }
592
593 static int
594 _on_cmd_device_get_powered(char *cmd, char *args)
595 {
596    char *path;
597    bool powered;
598    E_Connman_Element *e;
599
600    if (!args)
601      {
602         fputs("ERROR: missing the device path\n", stderr);
603         return 1;
604      }
605    _tok(args);
606    path = args;
607
608    e = e_connman_device_get(path);
609    if (e_connman_device_powered_get(e, &powered))
610      printf(":::Device %s Powered = %hhu\n", path, powered);
611    else
612      fputs("ERROR: can't get device powered\n", stderr);
613    return 1;
614 }
615
616 static int
617 _on_cmd_device_set_powered(char *cmd, char *args)
618 {
619    char *device_path, *next_args;
620    bool powered;
621    E_Connman_Element *e;
622
623    if (!args)
624      {
625         fputs("ERROR: missing the device path\n", stderr);
626         return 1;
627      }
628    device_path = args;
629    next_args = _tok(args);
630    if (!next_args)
631      {
632         fputs("ERROR: missing the powered value\n", stderr);
633         return 1;
634      }
635    powered = !!atol(next_args);
636
637    e = e_connman_device_get(device_path);
638    if (e_connman_device_powered_set(e, powered, NULL, NULL))
639      printf(":::Device %s powered set to %hhu\n", device_path, powered);
640    else
641      fputs("ERROR: can't set device powered\n", stderr);
642    return 1;
643 }
644
645 static int
646 _on_cmd_device_get_scan_interval(char *cmd, char *args)
647 {
648    char *path;
649    unsigned short scan_interval;
650    E_Connman_Element *e;
651
652    if (!args)
653      {
654         fputs("ERROR: missing the device path\n", stderr);
655         return 1;
656      }
657    _tok(args);
658    path = args;
659
660    e = e_connman_device_get(path);
661    if (e_connman_device_scan_interval_get(e, &scan_interval))
662      printf(":::Device %s ScanInterval = %hu\n", path, scan_interval);
663    else
664      fputs("ERROR: can't get device scan interval\n", stderr);
665    return 1;
666 }
667
668 static int
669 _on_cmd_device_set_scan_interval(char *cmd, char *args)
670 {
671    char *device_path, *next_args, *p;
672    unsigned short scan_interval;
673    E_Connman_Element *e;
674
675    if (!args)
676      {
677         fputs("ERROR: missing the device path\n", stderr);
678         return 1;
679      }
680    device_path = args;
681    next_args = _tok(args);
682    if (!next_args)
683      {
684         fputs("ERROR: missing the scan interval value\n", stderr);
685         return 1;
686      }
687    scan_interval = strtol(next_args, &p, 0);
688    if (p == next_args)
689      {
690         fprintf(stderr, "ERROR: invalid number \"%s\".\n", next_args);
691         return 1;
692      }
693
694    e = e_connman_device_get(device_path);
695    if (e_connman_device_scan_interval_set(e, scan_interval, NULL, NULL))
696      printf(":::Device %s scan interval set to %hu\n", device_path, scan_interval);
697    else
698      fputs("ERROR: can't set device scan interval\n", stderr);
699    return 1;
700 }
701
702 static int
703 _on_cmd_device_get_scanning(char *cmd, char *args)
704 {
705    char *path;
706    bool scanning;
707    E_Connman_Element *e;
708
709    if (!args)
710      {
711         fputs("ERROR: missing the device path\n", stderr);
712         return 1;
713      }
714    _tok(args);
715    path = args;
716
717    e = e_connman_device_get(path);
718    if (e_connman_device_scanning_get(e, &scanning))
719      printf(":::Device %s Scanning = %hhu\n", path, scanning);
720    else
721      fputs("ERROR: can't get device scanning\n", stderr);
722    return 1;
723 }
724
725 static int
726 _on_cmd_device_get_networks(char *cmd, char *args)
727 {
728    E_Connman_Element **networks;
729    unsigned int count;
730    char *path;
731    E_Connman_Element *e;
732
733    if (!args)
734      {
735         fputs("ERROR: missing the device path\n", stderr);
736         return 1;
737      }
738    _tok(args);
739    path = args;
740
741    e = e_connman_device_get(path);
742    if (!e_connman_device_networks_get(e, &count, &networks))
743      {
744         fputs("ERROR: can't get networks\n", stderr);
745         return 1;
746      }
747
748    printf("BEG: all device network elements count = %d\n", count);
749    _elements_print(networks, count);
750    return 1;
751 }
752
753 /* Profile Commands */
754
755 static int
756 _on_cmd_profile_get_name(char *cmd, char *args)
757 {
758    const char *name, *path;
759    E_Connman_Element *e;
760
761    if (!args)
762      {
763         fputs("ERROR: missing the profile path\n", stderr);
764         return 1;
765      }
766    _tok(args);
767    path = args;
768
769    e = e_connman_profile_get(path);
770    if (e_connman_profile_name_get(e, &name))
771      printf(":::Profile %s Name = \"%s\"\n", path, name);
772    else
773      fputs("ERROR: can't get profile name\n", stderr);
774    return 1;
775 }
776
777 static int
778 _on_cmd_profile_set_name(char *cmd, char *args)
779 {
780    char *path, *next_args;
781    E_Connman_Element *e;
782
783    if (!args)
784      {
785         fputs("ERROR: missing the profile path\n", stderr);
786         return 1;
787      }
788    path = args;
789    next_args = _tok(args);
790    if (!next_args)
791      {
792         fputs("ERROR: missing the offline mode value\n", stderr);
793         return 1;
794      }
795    _tok(next_args);
796
797    e = e_connman_profile_get(path);
798    if (e_connman_profile_name_set(e, next_args, NULL, NULL))
799      printf(":::Profile %s Name set to %s\n", path, next_args);
800    else
801      fputs("ERROR: can't set profile name\n", stderr);
802    return 1;
803 }
804
805 static int
806 _on_cmd_profile_get_offline_mode(char *cmd, char *args)
807 {
808    char *path;
809    bool offline;
810    E_Connman_Element *e;
811
812    if (!args)
813      {
814         fputs("ERROR: missing the profile path\n", stderr);
815         return 1;
816      }
817    _tok(args);
818    path = args;
819
820    e = e_connman_profile_get(path);
821    if (e_connman_profile_offline_mode_get(e, &offline))
822      printf(":::Profile  %s Offline Mode = %hhu\n", path, offline);
823    else
824      fputs("ERROR: can't get profile offline mode\n", stderr);
825    return 1;
826 }
827
828 static int
829 _on_cmd_profile_set_offline_mode(char *cmd, char *args)
830 {
831    char *path, *next_args;
832    bool offline;
833    E_Connman_Element *e;
834
835    if (!args)
836      {
837         fputs("ERROR: missing the profile path\n", stderr);
838         return 1;
839      }
840    path = args;
841    next_args = _tok(args);
842    if (!next_args)
843      {
844         fputs("ERROR: missing the offline mode value\n", stderr);
845         return 1;
846      }
847    _tok(next_args);
848    offline = !!atol(next_args);
849
850    e = e_connman_profile_get(path);
851    if (e_connman_profile_offline_mode_set(e, offline, NULL, NULL))
852      printf(":::Profile %s Offline Mode set to %hhu\n", path, offline);
853    else
854      fputs("ERROR: can't set profile offline mode\n", stderr);
855    return 1;
856 }
857
858 static int
859 _on_cmd_profile_get_services(char *cmd, char *args)
860 {
861    E_Connman_Element **services;
862    E_Connman_Element *e;
863    unsigned int count;
864    char *path;
865
866    if (!args)
867      {
868         fputs("ERROR: missing the profile path\n", stderr);
869         return 1;
870      }
871    _tok(args);
872    path = args;
873
874    e = e_connman_profile_get(path);
875    if (!e_connman_profile_services_get(e, &count, &services))
876      {
877         fputs("ERROR: can't get services\n", stderr);
878         return 1;
879      }
880    printf("BEG: all profile services count = %d\n", count);
881    _elements_print(services, count);
882    return 1;
883 }
884
885
886 /* Network Commands */
887
888 static int
889 _on_cmd_network_get_address(char *cmd, char *args)
890 {
891    const char *address, *path;
892    E_Connman_Element *e;
893
894    if (!args)
895      {
896         fputs("ERROR: missing the network path\n", stderr);
897         return 1;
898      }
899    _tok(args);
900    path = args;
901
902    e = e_connman_network_get(path);
903    if (e_connman_network_address_get(e, &address))
904      printf(":::Network %s Address = \"%s\"\n", path, address);
905    else
906      fputs("ERROR: can't get network address\n", stderr);
907    return 1;
908 }
909
910 static int
911 _on_cmd_network_get_name(char *cmd, char *args)
912 {
913    const char *name, *path;
914    E_Connman_Element *e;
915
916    if (!args)
917      {
918         fputs("ERROR: missing the network path\n", stderr);
919         return 1;
920      }
921    _tok(args);
922    path = args;
923
924    e = e_connman_network_get(path);
925    if (e_connman_network_name_get(e, &name))
926      printf(":::Network %s Name = \"%s\"\n", path, name);
927    else
928      fputs("ERROR: can't get network name\n", stderr);
929    return 1;
930 }
931
932 static int
933 _on_cmd_network_get_connected(char *cmd, char *args)
934 {
935    char *path;
936    bool connected;
937    E_Connman_Element *e;
938
939    if (!args)
940      {
941         fputs("ERROR: missing the network path\n", stderr);
942         return 1;
943      }
944    _tok(args);
945    path = args;
946
947    e = e_connman_network_get(path);
948    if (e_connman_network_connected_get(e, &connected))
949      printf(":::Network %s Connected = %hhu\n", path, connected);
950    else
951      fputs("ERROR: can't get network connected\n", stderr);
952    return 1;
953 }
954
955 static int
956 _on_cmd_network_get_strength(char *cmd, char *args)
957 {
958    char *path;
959    unsigned char strength;
960    E_Connman_Element *e;
961
962    if (!args)
963      {
964         fputs("ERROR: missing the network path\n", stderr);
965         return 1;
966      }
967    _tok(args);
968    path = args;
969
970    e = e_connman_network_get(path);
971    if (e_connman_network_strength_get(e, &strength))
972      printf(":::Network %s Strength = %#02hhx (%d)\n", path, strength, strength);
973    else
974      fputs("ERROR: can't get network strength\n", stderr);
975    return 1;
976 }
977
978 static int
979 _on_cmd_network_get_frequency(char *cmd, char *args)
980 {
981    char *path;
982    unsigned short frequency;
983    E_Connman_Element *e;
984
985    if (!args)
986      {
987         fputs("ERROR: missing the network path\n", stderr);
988         return 1;
989      }
990    _tok(args);
991    path = args;
992
993    e = e_connman_network_get(path);
994    if (e_connman_network_frequency_get(e, &frequency))
995      printf(":::Network %s Frequency = %#04hx (%d)\n", path, frequency, frequency);
996    else
997      fputs("ERROR: can't get network frequency\n", stderr);
998    return 1;
999 }
1000
1001 static int
1002 _on_cmd_network_get_device(char *cmd, char *args)
1003 {
1004    E_Connman_Element *e, *device;
1005    char *path;
1006
1007    if (!args)
1008      {
1009         fputs("ERROR: missing the network path\n", stderr);
1010         return 1;
1011      }
1012    _tok(args);
1013    path = args;
1014
1015    e = e_connman_network_get(path);
1016    if (!e_connman_network_device_get(e, &device))
1017      fputs("ERROR: can't get network device\n", stderr);
1018    else
1019      e_connman_element_print(stderr, device);
1020    return 1;
1021 }
1022
1023 static int
1024 _on_cmd_network_get_wifi_ssid(char *cmd, char *args)
1025 {
1026    unsigned char *bytes;
1027    char *path;
1028    unsigned int i, count;
1029    E_Connman_Element *e;
1030
1031    if (!args)
1032      {
1033         fputs("ERROR: missing the network path\n", stderr);
1034         return 1;
1035      }
1036    _tok(args);
1037    path = args;
1038
1039    e = e_connman_network_get(path);
1040    if (e_connman_network_wifi_ssid_get(e, &count, &bytes))
1041      {
1042         printf(":::Network %s Wifi SSID = ", path);
1043         for (i = 0; i < count; i++)
1044           printf("%#02hhx (\"%c\"), ", bytes[i], bytes[i]);
1045         printf("\n");
1046      }
1047    else
1048      fputs("ERROR: can't get network wifi ssid\n", stderr);
1049    return 1;
1050 }
1051
1052 static int
1053 _on_cmd_network_get_wifi_mode(char *cmd, char *args)
1054 {
1055    const char *wifi_mode, *path;
1056    E_Connman_Element *e;
1057
1058    if (!args)
1059      {
1060         fputs("ERROR: missing the network path\n", stderr);
1061         return 1;
1062      }
1063    _tok(args);
1064    path = args;
1065
1066    e = e_connman_network_get(path);
1067    if (e_connman_network_wifi_mode_get(e, &wifi_mode))
1068      printf(":::Network %s Wifi Mode = \"%s\"\n", path, wifi_mode);
1069    else
1070      fputs("ERROR: can't get network wifi mode\n", stderr);
1071    return 1;
1072 }
1073
1074 static int
1075 _on_cmd_network_get_wifi_security(char *cmd, char *args)
1076 {
1077    const char *wifi_security, *path;
1078    E_Connman_Element *e;
1079
1080    if (!args)
1081      {
1082         fputs("ERROR: missing the network path\n", stderr);
1083         return 1;
1084      }
1085    _tok(args);
1086    path = args;
1087
1088    e = e_connman_network_get(path);
1089    if (e_connman_network_wifi_security_get(e, &wifi_security))
1090      printf(":::Network %s Wifi Security = \"%s\"\n", path, wifi_security);
1091    else
1092      fputs("ERROR: can't get network wifi security\n", stderr);
1093    return 1;
1094 }
1095
1096 static int
1097 _on_cmd_network_get_wifi_passphrase(char *cmd, char *args)
1098 {
1099    const char *wifi_passphrase, *path;
1100    E_Connman_Element *e;
1101
1102    if (!args)
1103      {
1104         fputs("ERROR: missing the network path\n", stderr);
1105         return 1;
1106      }
1107    _tok(args);
1108    path = args;
1109
1110    e = e_connman_network_get(path);
1111    if (e_connman_network_wifi_passphrase_get(e, &wifi_passphrase))
1112      printf(":::Network %s Wifi Passphrase = \"%s\"\n", path, wifi_passphrase);
1113    else
1114      fputs("ERROR: can't get network wifi passphrase\n", stderr);
1115    return 1;
1116 }
1117
1118 static int
1119 _on_cmd_network_get_wifi_channel(char *cmd, char *args)
1120 {
1121    char *path;
1122    E_Connman_Element *e;
1123    unsigned short wifi_channel;
1124
1125    if (!args)
1126      {
1127         fputs("ERROR: missing the network path\n", stderr);
1128         return 1;
1129      }
1130    _tok(args);
1131    path = args;
1132
1133    e = e_connman_network_get(path);
1134    if (e_connman_network_wifi_channel_get(e, &wifi_channel))
1135      printf(":::Network %s Wifi Channel = %#02hx (%d)\n", path, wifi_channel, wifi_channel);
1136    else
1137      fputs("ERROR: can't get network wifi channel\n", stderr);
1138    return 1;
1139 }
1140
1141 static int
1142 _on_cmd_network_get_wifi_eap(char *cmd, char *args)
1143 {
1144    const char *wifi_eap, *path;
1145    E_Connman_Element *e;
1146
1147    if (!args)
1148      {
1149         fputs("ERROR: missing the network path\n", stderr);
1150         return 1;
1151      }
1152    _tok(args);
1153    path = args;
1154
1155    e = e_connman_network_get(path);
1156    if (e_connman_network_wifi_eap_get(e, &wifi_eap))
1157      printf(":::Network %s Wifi EAP = \"%s\"\n", path, wifi_eap);
1158    else
1159      fputs("ERROR: can't get network wifi eap\n", stderr);
1160    return 1;
1161 }
1162
1163 /* Services Commands */
1164 static int
1165 _on_cmd_service_connect(char *cmd, char *args)
1166 {
1167    char *path;
1168    E_Connman_Element *e;
1169
1170    if (!args)
1171      {
1172         fputs("ERROR: missing the service path\n", stderr);
1173         return 1;
1174      }
1175    _tok(args);
1176    path = args;
1177
1178    e = e_connman_service_get(path);
1179    if (e_connman_service_connect(e, NULL, NULL))
1180      printf(":::Connecting to Service %s...\n", path);
1181    else
1182      fputs("ERROR: can't connect to service\n", stderr);
1183    return 1;
1184 }
1185
1186 static int
1187 _on_cmd_service_disconnect(char *cmd, char *args)
1188 {
1189    char *path;
1190    E_Connman_Element *e;
1191
1192    if (!args)
1193      {
1194         fputs("ERROR: missing the service path\n", stderr);
1195         return 1;
1196      }
1197    _tok(args);
1198    path = args;
1199
1200    e = e_connman_service_get(path);
1201    if (e_connman_service_disconnect(e, NULL, NULL))
1202      printf(":::Disconnecting Service %s...\n", path);
1203    else
1204      fputs("ERROR: can't disconnect service\n", stderr);
1205    return 1;
1206 }
1207
1208 static int
1209 _on_cmd_service_remove(char *cmd, char *args)
1210 {
1211    char *path;
1212    E_Connman_Element *e;
1213
1214    if (!args)
1215      {
1216         fputs("ERROR: missing the service path\n", stderr);
1217         return 1;
1218      }
1219    _tok(args);
1220    path = args;
1221
1222    e = e_connman_service_get(path);
1223    if (e_connman_service_remove(e, NULL, NULL))
1224      printf(":::Removing Service %s...\n", path);
1225    else
1226      fputs("ERROR: can't remove service\n", stderr);
1227    return 1;
1228 }
1229
1230 static int
1231 _on_cmd_service_move_before(char *cmd, char *args)
1232 {
1233    char *path, *service_path;
1234    E_Connman_Element *e;
1235
1236    if (!args)
1237      {
1238         fputs("ERROR: missing the service path\n", stderr);
1239         return 1;
1240      }
1241    service_path = args;
1242    path = _tok(args);
1243
1244    if (!path)
1245      {
1246         fputs("ERROR: missing the object service\n", stderr);
1247         return 1;
1248      }
1249    _tok(path);
1250
1251    e = e_connman_service_get(service_path);
1252    if (e_connman_service_move_before(e, path, NULL, NULL))
1253      printf(":::Moving before %s...\n", path);
1254    else
1255      fputs("ERROR: can't move before\n", stderr);
1256    return 1;
1257 }
1258
1259 static int
1260 _on_cmd_service_move_after(char *cmd, char *args)
1261 {
1262    char *path, *service_path;
1263    E_Connman_Element *e;
1264
1265    if (!args)
1266      {
1267         fputs("ERROR: missing the service path\n", stderr);
1268         return 1;
1269      }
1270    service_path = args;
1271    path = _tok(args);
1272
1273    if (!path)
1274      {
1275         fputs("ERROR: missing the object service\n", stderr);
1276         return 1;
1277      }
1278    _tok(path);
1279
1280    e = e_connman_service_get(service_path);
1281    if (e_connman_service_move_after(e, path, NULL, NULL))
1282      printf(":::Moving after %s...\n", path);
1283    else
1284      fputs("ERROR: can't move after\n", stderr);
1285    return 1;
1286 }
1287
1288 static int
1289 _on_cmd_service_get_state(char *cmd, char *args)
1290 {
1291    const char *state, *path;
1292    E_Connman_Element *e;
1293
1294    if (!args)
1295      {
1296         fputs("ERROR: missing the service path\n", stderr);
1297         return 1;
1298      }
1299    _tok(args);
1300    path = args;
1301
1302    e = e_connman_service_get(path);
1303    if (e_connman_service_state_get(e, &state))
1304      printf(":::Service %s State = \"%s\"\n", path, state);
1305    else
1306      fputs("ERROR: can't get service state\n", stderr);
1307    return 1;
1308 }
1309
1310 static int
1311 _on_cmd_service_get_error(char *cmd, char *args)
1312 {
1313    const char *error, *path;
1314    E_Connman_Element *e;
1315
1316    if (!args)
1317      {
1318         fputs("ERROR: missing the service path\n", stderr);
1319         return 1;
1320      }
1321    _tok(args);
1322    path = args;
1323
1324    e = e_connman_service_get(path);
1325    if (e_connman_service_error_get(e, &error))
1326      printf(":::Service %s Error = \"%s\"\n", path, error);
1327    else
1328      fputs("ERROR: can't get service error\n", stderr);
1329    return 1;
1330 }
1331
1332 static int
1333 _on_cmd_service_get_name(char *cmd, char *args)
1334 {
1335    const char *name, *path;
1336    E_Connman_Element *e;
1337
1338    if (!args)
1339      {
1340         fputs("ERROR: missing the service path\n", stderr);
1341         return 1;
1342      }
1343    _tok(args);
1344    path = args;
1345
1346    e = e_connman_service_get(path);
1347    if (e_connman_service_name_get(e, &name))
1348      printf(":::Service %s Name = \"%s\"\n", path, name);
1349    else
1350      fputs("ERROR: can't get service name\n", stderr);
1351    return 1;
1352 }
1353
1354 static int
1355 _on_cmd_service_get_type(char *cmd, char *args)
1356 {
1357    const char *type, *path;
1358    E_Connman_Element *e;
1359
1360    if (!args)
1361      {
1362         fputs("ERROR: missing the service path\n", stderr);
1363         return 1;
1364      }
1365    _tok(args);
1366    path = args;
1367
1368    e = e_connman_service_get(path);
1369    if (e_connman_service_type_get(e, &type))
1370      printf(":::Service %s Type = \"%s\"\n", path, type);
1371    else
1372      fputs("ERROR: can't get service type\n", stderr);
1373    return 1;
1374 }
1375
1376 static int
1377 _on_cmd_service_get_mode(char *cmd, char *args)
1378 {
1379    const char *mode, *path;
1380    E_Connman_Element *e;
1381
1382    if (!args)
1383      {
1384         fputs("ERROR: missing the service path\n", stderr);
1385         return 1;
1386      }
1387    _tok(args);
1388    path = args;
1389
1390    e = e_connman_service_get(path);
1391    if (e_connman_service_mode_get(e, &mode))
1392      printf(":::Service %s Mode = \"%s\"\n", path, mode);
1393    else
1394      fputs("ERROR: can't get service mode\n", stderr);
1395    return 1;
1396 }
1397
1398 static int
1399 _on_cmd_service_get_security(char *cmd, char *args)
1400 {
1401    const char *security, *path;
1402    E_Connman_Element *e;
1403
1404    if (!args)
1405      {
1406         fputs("ERROR: missing the service path\n", stderr);
1407         return 1;
1408      }
1409    _tok(args);
1410    path = args;
1411
1412    e = e_connman_service_get(path);
1413    if (e_connman_service_security_get(e, &security))
1414      printf(":::Service %s Security = \"%s\"\n", path, security);
1415    else
1416      fputs("ERROR: can't get service security\n", stderr);
1417    return 1;
1418 }
1419
1420 static int
1421 _on_cmd_service_get_passphrase(char *cmd, char *args)
1422 {
1423    const char *passphrase, *path;
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_passphrase_get(e, &passphrase))
1436      printf(":::Service %s Passphrase = \"%s\"\n", path, passphrase);
1437    else
1438      fputs("ERROR: can't get service passphrase\n", stderr);
1439    return 1;
1440 }
1441
1442 static int
1443 _on_cmd_service_set_passphrase(char *cmd, char *args)
1444 {
1445    char *passphrase, *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    path = args;
1454    passphrase = _tok(args);
1455
1456    if (!passphrase)
1457      {
1458         fputs("ERROR: missing the passphrase value\n", stderr);
1459         return 1;
1460      }
1461    _tok(passphrase);
1462
1463    e = e_connman_service_get(path);
1464    if (e_connman_service_passphrase_set(e, passphrase, NULL, NULL))
1465      printf(":::Service %s passphrase set to \"%s\"\n", path, passphrase);
1466    else
1467      fputs("ERROR: can't set service passphrase\n", stderr);
1468    return 1;
1469 }
1470
1471 static int
1472 _on_cmd_service_get_passphrase_required(char *cmd, char *args)
1473 {
1474    const char *path;
1475    bool passphrase;
1476    E_Connman_Element *e;
1477
1478    if (!args)
1479      {
1480         fputs("ERROR: missing the service path\n", stderr);
1481         return 1;
1482      }
1483    _tok(args);
1484    path = args;
1485
1486    e = e_connman_service_get(path);
1487    if (e_connman_service_passphrase_required_get(e, &passphrase))
1488      printf(":::Service %s Passphrase Required = %hhu\n", path, passphrase);
1489    else
1490      fputs("ERROR: can't get service passphrase required\n", stderr);
1491    return 1;
1492 }
1493
1494 static int
1495 _on_cmd_service_get_strength(char *cmd, char *args)
1496 {
1497    const char *path;
1498    unsigned char strength;
1499    E_Connman_Element *e;
1500
1501    if (!args)
1502      {
1503         fputs("ERROR: missing the service path\n", stderr);
1504         return 1;
1505      }
1506    _tok(args);
1507    path = args;
1508
1509    e = e_connman_service_get(path);
1510    if (e_connman_service_strength_get(e, &strength))
1511      printf(":::Service %s Strength = %#02hhx (%d)\n", path, strength, strength);
1512    else
1513      fputs("ERROR: can't get service strength\n", stderr);
1514    return 1;
1515 }
1516
1517 static int
1518 _on_cmd_service_get_favorite(char *cmd, char *args)
1519 {
1520    const char *path;
1521    bool favorite;
1522    E_Connman_Element *e;
1523
1524    if (!args)
1525      {
1526         fputs("ERROR: missing the service path\n", stderr);
1527         return 1;
1528      }
1529    _tok(args);
1530    path = args;
1531
1532    e = e_connman_service_get(path);
1533    if (e_connman_service_favorite_get(e, &favorite))
1534      printf(":::Service %s Favorite = %hhu\n", path, favorite);
1535    else
1536      fputs("ERROR: can't get service favorite\n", stderr);
1537    return 1;
1538 }
1539
1540 static int
1541 _on_cmd_service_get_immutable(char *cmd, char *args)
1542 {
1543    const char *path;
1544    bool immutable;
1545    E_Connman_Element *e;
1546
1547    if (!args)
1548      {
1549         fputs("ERROR: missing the service path\n", stderr);
1550         return 1;
1551      }
1552    _tok(args);
1553    path = args;
1554
1555    e = e_connman_service_get(path);
1556    if (e_connman_service_immutable_get(e, &immutable))
1557      printf(":::Service %s Immutable = %hhu\n", path, immutable);
1558    else
1559      fputs("ERROR: can't get service immutable\n", stderr);
1560    return 1;
1561 }
1562
1563 static int
1564 _on_cmd_service_get_auto_connect(char *cmd, char *args)
1565 {
1566    const char *path;
1567    bool auto_connect;
1568    E_Connman_Element *e;
1569
1570    if (!args)
1571      {
1572         fputs("ERROR: missing the service path\n", stderr);
1573         return 1;
1574      }
1575    _tok(args);
1576    path = args;
1577
1578    e = e_connman_service_get(path);
1579    if (e_connman_service_auto_connect_get(e, &auto_connect))
1580      printf(":::Service %s Auto Connect = %hhu\n", path, auto_connect);
1581    else
1582      fputs("ERROR: can't get service auto connect\n", stderr);
1583    return 1;
1584 }
1585
1586 static int
1587 _on_cmd_service_set_auto_connect(char *cmd, char *args)
1588 {
1589    char *path, *next_args;
1590    bool auto_connect;
1591    E_Connman_Element *e;
1592
1593    if (!args)
1594      {
1595         fputs("ERROR: missing the service path\n", stderr);
1596         return 1;
1597      }
1598    path = args;
1599    next_args = _tok(args);
1600
1601    if (!next_args)
1602      {
1603         fputs("ERROR: missing the auto connect value\n", stderr);
1604         return 1;
1605      }
1606    _tok(next_args);
1607    auto_connect = !!atol(next_args);
1608
1609    e = e_connman_service_get(path);
1610    if (e_connman_service_auto_connect_set(e, auto_connect, NULL, NULL))
1611      printf(":::Service %s auto connect set to %d\n", path, auto_connect);
1612    else
1613      fputs("ERROR: can't set service auto connect\n", stderr);
1614    return 1;
1615 }
1616
1617 static int
1618 _on_cmd_service_get_setup_required(char *cmd, char *args)
1619 {
1620    const char *path;
1621    bool setup_required;
1622    E_Connman_Element *e;
1623
1624    if (!args)
1625      {
1626         fputs("ERROR: missing the service path\n", stderr);
1627         return 1;
1628      }
1629    _tok(args);
1630    path = args;
1631
1632    e = e_connman_service_get(path);
1633    if (e_connman_service_setup_required_get(e, &setup_required))
1634      printf(":::Service %s Setup Required = %hhu\n", path, setup_required);
1635    else
1636      fputs("ERROR: can't get service setup required\n", stderr);
1637    return 1;
1638 }
1639
1640 static int
1641 _on_cmd_service_get_apn(char *cmd, char *args)
1642 {
1643    const char *apn, *path;
1644    E_Connman_Element *e;
1645
1646    if (!args)
1647      {
1648         fputs("ERROR: missing the service path\n", stderr);
1649         return 1;
1650      }
1651    _tok(args);
1652    path = args;
1653
1654    e = e_connman_service_get(path);
1655    if (e_connman_service_apn_get(e, &apn))
1656      printf(":::Service %s APN = \"%s\"\n", path, apn);
1657    else
1658      fputs("ERROR: can't get service APN\n", stderr);
1659    return 1;
1660 }
1661
1662 static int
1663 _on_cmd_service_set_apn(char *cmd, char *args)
1664 {
1665    char *apn, *path;
1666    E_Connman_Element *e;
1667
1668    if (!args)
1669      {
1670         fputs("ERROR: missing the service path\n", stderr);
1671         return 1;
1672      }
1673    path = args;
1674    apn = _tok(args);
1675
1676    if (!apn)
1677      {
1678         fputs("ERROR: missing the apn value\n", stderr);
1679         return 1;
1680      }
1681    _tok(apn);
1682
1683    e = e_connman_service_get(path);
1684    if (e_connman_service_apn_set(e, apn, NULL, NULL))
1685      printf(":::Service %s APN set to \"%s\"\n", path, apn);
1686    else
1687      fputs("ERROR: can't set service APN\n", stderr);
1688    return 1;
1689 }
1690
1691 static int
1692 _on_cmd_service_get_mcc(char *cmd, char *args)
1693 {
1694    const char *mcc, *path;
1695    E_Connman_Element *e;
1696
1697    if (!args)
1698      {
1699         fputs("ERROR: missing the service path\n", stderr);
1700         return 1;
1701      }
1702    _tok(args);
1703    path = args;
1704
1705    e = e_connman_service_get(path);
1706    if (e_connman_service_mcc_get(e, &mcc))
1707      printf(":::Service %s MCC = \"%s\"\n", path, mcc);
1708    else
1709      fputs("ERROR: can't get service MCC\n", stderr);
1710    return 1;
1711 }
1712
1713 static int
1714 _on_cmd_service_get_mnc(char *cmd, char *args)
1715 {
1716    const char *mnc, *path;
1717    E_Connman_Element *e;
1718
1719    if (!args)
1720      {
1721         fputs("ERROR: missing the service path\n", stderr);
1722         return 1;
1723      }
1724    _tok(args);
1725    path = args;
1726
1727    e = e_connman_service_get(path);
1728    if (e_connman_service_mnc_get(e, &mnc))
1729      printf(":::Service %s MNC = \"%s\"\n", path, mnc);
1730    else
1731      fputs("ERROR: can't get service MNC\n", stderr);
1732    return 1;
1733 }
1734
1735 static int
1736 _on_cmd_service_get_roaming(char *cmd, char *args)
1737 {
1738    const char *path;
1739    bool roaming;
1740    E_Connman_Element *e;
1741
1742    if (!args)
1743      {
1744         fputs("ERROR: missing the service path\n", stderr);
1745         return 1;
1746      }
1747    _tok(args);
1748    path = args;
1749
1750    e = e_connman_service_get(path);
1751    if (e_connman_service_roaming_get(e, &roaming))
1752      printf(":::Service %s Roaming = %hhu\n", path, roaming);
1753    else
1754      fputs("ERROR: can't get service roaming\n", stderr);
1755    return 1;
1756 }
1757
1758 static int
1759 _on_cmd_service_get_ipv4_method(char *cmd, char *args)
1760 {
1761    const char *ipv4_method, *path;
1762    E_Connman_Element *e;
1763
1764    if (!args)
1765      {
1766         fputs("ERROR: missing the service path\n", stderr);
1767         return 1;
1768      }
1769    _tok(args);
1770    path = args;
1771
1772    e = e_connman_service_get(path);
1773    if (e_connman_service_ipv4_method_get(e, &ipv4_method))
1774      printf(":::Service %s ipv4 method = \"%s\"\n", path, ipv4_method);
1775    else
1776      fputs("ERROR: can't get service ipv4 method\n", stderr);
1777    return 1;
1778 }
1779
1780 static int
1781 _on_cmd_service_get_ipv4_address(char *cmd, char *args)
1782 {
1783    const char *ipv4_address, *path;
1784    E_Connman_Element *e;
1785
1786    if (!args)
1787      {
1788         fputs("ERROR: missing the service path\n", stderr);
1789         return 1;
1790      }
1791    _tok(args);
1792    path = args;
1793
1794    e = e_connman_service_get(path);
1795    if (e_connman_service_ipv4_address_get(e, &ipv4_address))
1796      printf(":::Service %s ipv4 address = \"%s\"\n", path, ipv4_address);
1797    else
1798      fputs("ERROR: can't get service ipv4 address\n", stderr);
1799    return 1;
1800 }
1801
1802
1803 static int
1804 _on_input(void *data, Ecore_Fd_Handler *fd_handler)
1805 {
1806    char buf[256];
1807    char *cmd, *args;
1808    const struct {
1809       const char *cmd;
1810       int (*cb)(char *cmd, char *args);
1811    } *itr, maps[] = {
1812      {"quit", _on_cmd_quit},
1813      {"sync", _on_cmd_sync},
1814      {"get_all", _on_cmd_get_all},
1815      {"print", _on_cmd_print},
1816      {"get_properties", _on_cmd_get_properties},
1817      {"set_property", _on_cmd_property_set},
1818      {"manager_get", _on_cmd_manager_get},
1819      {"manager_get_profiles", _on_cmd_manager_get_profiles},
1820      {"manager_get_devices", _on_cmd_manager_get_devices},
1821      {"manager_get_services", _on_cmd_manager_get_services},
1822      {"manager_register_agent", _on_cmd_manager_register_agent},
1823      {"manager_unregister_agent", _on_cmd_manager_unregister_agent},
1824      {"manager_get_state", _on_cmd_manager_get_state},
1825      {"manager_get_offline_mode", _on_cmd_manager_get_offline_mode},
1826      {"manager_set_offline_mode", _on_cmd_manager_set_offline_mode},
1827      {"manager_request_scan", _on_cmd_manager_request_scan},
1828      {"manager_technology_enable", _on_cmd_manager_technology_enable},
1829      {"manager_technology_disable", _on_cmd_manager_technology_disable},
1830      {"manager_profile_remove", _on_cmd_manager_profile_remove},
1831      {"manager_profile_get_active", _on_cmd_manager_profile_get_active},
1832      {"manager_profile_set_active", _on_cmd_manager_profile_set_active},
1833      {"device_propose_scan", _on_cmd_device_propose_scan},
1834      {"device_get_address", _on_cmd_device_get_address},
1835      {"device_get_name", _on_cmd_device_get_name},
1836      {"device_get_type", _on_cmd_device_get_type},
1837      {"device_get_interface", _on_cmd_device_get_interface},
1838      {"device_get_powered", _on_cmd_device_get_powered},
1839      {"device_set_powered", _on_cmd_device_set_powered},
1840      {"device_get_scan_interval", _on_cmd_device_get_scan_interval},
1841      {"device_set_scan_interval", _on_cmd_device_set_scan_interval},
1842      {"device_get_scanning", _on_cmd_device_get_scanning},
1843      {"device_get_networks", _on_cmd_device_get_networks},
1844      {"profile_get_name", _on_cmd_profile_get_name},
1845      {"profile_set_name", _on_cmd_profile_set_name},
1846      {"profile_get_offline_mode", _on_cmd_profile_get_offline_mode},
1847      {"profile_set_offline_mode", _on_cmd_profile_set_offline_mode},
1848      {"profile_get_services", _on_cmd_profile_get_services},
1849      {"network_get_address", _on_cmd_network_get_address},
1850      {"network_get_name", _on_cmd_network_get_name},
1851      {"network_get_connected", _on_cmd_network_get_connected},
1852      {"network_get_strength", _on_cmd_network_get_strength},
1853      {"network_get_frequency", _on_cmd_network_get_frequency},
1854      {"network_get_device", _on_cmd_network_get_device},
1855      {"network_get_wifi_ssid", _on_cmd_network_get_wifi_ssid},
1856      {"network_get_wifi_mode", _on_cmd_network_get_wifi_mode},
1857      {"network_get_wifi_security", _on_cmd_network_get_wifi_security},
1858      {"network_get_wifi_passphrase", _on_cmd_network_get_wifi_passphrase},
1859      {"network_get_wifi_channel", _on_cmd_network_get_wifi_channel},
1860      {"network_get_wifi_eap", _on_cmd_network_get_wifi_eap},
1861      {"service_connect", _on_cmd_service_connect},
1862      {"service_disconnect", _on_cmd_service_disconnect},
1863      {"service_remove", _on_cmd_service_remove},
1864      {"service_move_before", _on_cmd_service_move_before},
1865      {"service_move_after", _on_cmd_service_move_after},
1866      {"service_get_state", _on_cmd_service_get_state},
1867      {"service_get_error", _on_cmd_service_get_error},
1868      {"service_get_name", _on_cmd_service_get_name},
1869      {"service_get_type", _on_cmd_service_get_type},
1870      {"service_get_mode", _on_cmd_service_get_mode},
1871      {"service_get_security", _on_cmd_service_get_security},
1872      {"service_get_passphrase", _on_cmd_service_get_passphrase},
1873      {"service_set_passphrase", _on_cmd_service_set_passphrase},
1874      {"service_get_passphrase_required", _on_cmd_service_get_passphrase_required},
1875      {"service_get_strength", _on_cmd_service_get_strength},
1876      {"service_get_favorite", _on_cmd_service_get_favorite},
1877      {"service_get_immutable", _on_cmd_service_get_immutable},
1878      {"service_get_auto_connect", _on_cmd_service_get_auto_connect},
1879      {"service_set_auto_connect", _on_cmd_service_set_auto_connect},
1880      {"service_get_setup_required", _on_cmd_service_get_setup_required},
1881      {"service_get_apn", _on_cmd_service_get_apn},
1882      {"service_set_apn", _on_cmd_service_set_apn},
1883      {"service_get_mcc", _on_cmd_service_get_mcc},
1884      {"service_get_mnc", _on_cmd_service_get_mnc},
1885      {"service_get_roaming", _on_cmd_service_get_roaming},
1886      {"service_get_ipv4_method", _on_cmd_service_get_ipv4_method},
1887      {"service_get_ipv4_address", _on_cmd_service_get_ipv4_address},
1888      {NULL, NULL}
1889    };
1890
1891
1892    if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR))
1893      {
1894         fputs("ERROR: reading from stdin, exit\n", stderr);
1895         return 0;
1896      }
1897
1898    if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
1899      {
1900         fputs("ERROR: nothing to read?\n", stderr);
1901         return 0;
1902      }
1903
1904    if (!fgets(buf, sizeof(buf), stdin))
1905      {
1906         fprintf(stderr, "ERROR: could not read command: %s\n", strerror(errno));
1907         ecore_main_loop_quit();
1908         return 0;
1909      }
1910
1911    cmd = buf;
1912    while (isspace(*cmd))
1913      cmd++;
1914
1915    args = strchr(cmd, ' ');
1916    if (args)
1917      {
1918         char *p;
1919
1920         *args = '\0';
1921         args++;
1922
1923         while (isspace(*args))
1924           args++;
1925
1926         p = args + strlen(args) - 1;
1927         if (*p == '\n')
1928           *p = '\0';
1929      }
1930    else
1931      {
1932         char *p;
1933
1934         p = cmd + strlen(cmd) - 1;
1935         if (*p == '\n')
1936           *p = '\0';
1937      }
1938
1939    if (strcmp(cmd, "help") == 0)
1940      {
1941         if (args)
1942           {
1943              printf("Commands with '%s' in the name:\n", args);
1944              for (itr = maps; itr->cmd != NULL; itr++)
1945                if (strstr(itr->cmd, args))
1946                  printf("\t%s\n", itr->cmd);
1947           }
1948         else
1949           {
1950              fputs("Commands:\n", stdout);
1951              for (itr = maps; itr->cmd != NULL; itr++)
1952                printf("\t%s\n", itr->cmd);
1953           }
1954         fputc('\n', stdout);
1955         return 1;
1956      }
1957
1958    for (itr = maps; itr->cmd != NULL; itr++)
1959      if (strcmp(itr->cmd, cmd) == 0)
1960        return itr->cb(cmd, args);
1961
1962    printf("unknown command \"%s\", args=%s\n", cmd, args);
1963    return 1;
1964 }
1965
1966 int
1967 main(int argc, char *argv[])
1968 {
1969    E_DBus_Connection *c;
1970
1971    ecore_init();
1972    e_dbus_init();
1973    eina_init();
1974
1975    c = e_dbus_bus_get(DBUS_BUS_SYSTEM);
1976    if (!c) {
1977       printf("ERROR: can't connect to system session\n");
1978       return -1;
1979    }
1980
1981    e_connman_system_init(c);
1982    ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_ADD, _on_element_add, NULL);
1983    ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_DEL, _on_element_del, NULL);
1984    ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_UPDATED,
1985                            _on_element_updated, NULL);
1986
1987    ecore_main_fd_handler_add
1988      (0, ECORE_FD_READ | ECORE_FD_ERROR, _on_input, NULL, NULL, NULL);
1989
1990    ecore_main_loop_begin();
1991
1992    e_connman_system_shutdown();
1993
1994    e_dbus_connection_close(c);
1995    eina_shutdown();
1996    e_dbus_shutdown();
1997    ecore_shutdown();
1998
1999    fputs("DBG: clean exit.\n", stderr);
2000
2001    return 0;
2002 }