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