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