5b5772a54d9ed37472cd922167fac76cd7bec06e
[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_security(__UNUSED__ char *cmd, char *args)
909 {
910    const E_Connman_Array *security;
911    const char *path;
912    E_Connman_Element *e;
913
914    if (!args)
915      {
916         fputs("ERROR: missing the service path\n", stderr);
917         return ECORE_CALLBACK_RENEW;
918      }
919    _tok(args);
920    path = args;
921
922    e = e_connman_service_get(path);
923    if (e_connman_service_security_get(e, &security))
924      {
925         Eina_Array_Iterator iterator;
926         unsigned int i;
927         const char *entry;
928         if (security->type != DBUS_TYPE_STRING)
929           {
930              fprintf(stderr, "ERROR: expected type '%c' but got '%c' for "
931                      "security array.\n",
932                      DBUS_TYPE_STRING, security->type);
933              return ECORE_CALLBACK_RENEW;
934           }
935         printf(":::Service %s Security = ", path);
936         EINA_ARRAY_ITER_NEXT(security->array, i, entry, iterator)
937           printf("\"%s\", ", entry);
938         putchar('\n');
939      }
940    else
941      fputs("ERROR: can't get service security\n", stderr);
942    return ECORE_CALLBACK_RENEW;
943 }
944
945 static Eina_Bool
946 _on_cmd_service_get_passphrase(__UNUSED__ char *cmd, char *args)
947 {
948    const char *passphrase, *path;
949    E_Connman_Element *e;
950
951    if (!args)
952      {
953         fputs("ERROR: missing the service path\n", stderr);
954         return ECORE_CALLBACK_RENEW;
955      }
956    _tok(args);
957    path = args;
958
959    e = e_connman_service_get(path);
960    if (e_connman_service_passphrase_get(e, &passphrase))
961      printf(":::Service %s Passphrase = \"%s\"\n", path, passphrase);
962    else
963      fputs("ERROR: can't get service passphrase\n", stderr);
964    return ECORE_CALLBACK_RENEW;
965 }
966
967 static Eina_Bool
968 _on_cmd_service_set_passphrase(__UNUSED__ char *cmd, char *args)
969 {
970    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    path = args;
979    passphrase = _tok(args);
980
981    if (!passphrase)
982      {
983         fputs("ERROR: missing the passphrase value\n", stderr);
984         return ECORE_CALLBACK_RENEW;
985      }
986    _tok(passphrase);
987
988    e = e_connman_service_get(path);
989    if (e_connman_service_passphrase_set
990        (e, passphrase, _method_success_check, "service_set_passphrase"))
991      printf(":::Service %s passphrase set to \"%s\"\n", path, passphrase);
992    else
993      fputs("ERROR: can't set service passphrase\n", stderr);
994    return ECORE_CALLBACK_RENEW;
995 }
996
997 static Eina_Bool
998 _on_cmd_service_get_passphrase_required(__UNUSED__ char *cmd, char *args)
999 {
1000    const char *path;
1001    Eina_Bool passphrase;
1002    E_Connman_Element *e;
1003
1004    if (!args)
1005      {
1006         fputs("ERROR: missing the service path\n", stderr);
1007         return ECORE_CALLBACK_RENEW;
1008      }
1009    _tok(args);
1010    path = args;
1011
1012    e = e_connman_service_get(path);
1013    if (e_connman_service_passphrase_required_get(e, &passphrase))
1014      printf(":::Service %s Passphrase Required = %hhu\n", path, passphrase);
1015    else
1016      fputs("ERROR: can't get service passphrase required\n", stderr);
1017    return ECORE_CALLBACK_RENEW;
1018 }
1019
1020 static Eina_Bool
1021 _on_cmd_service_get_strength(__UNUSED__ char *cmd, char *args)
1022 {
1023    const char *path;
1024    unsigned char strength;
1025    E_Connman_Element *e;
1026
1027    if (!args)
1028      {
1029         fputs("ERROR: missing the service path\n", stderr);
1030         return ECORE_CALLBACK_RENEW;
1031      }
1032    _tok(args);
1033    path = args;
1034
1035    e = e_connman_service_get(path);
1036    if (e_connman_service_strength_get(e, &strength))
1037      printf(":::Service %s Strength = %#02hhx (%d)\n", path, strength, strength);
1038    else
1039      fputs("ERROR: can't get service strength\n", stderr);
1040    return ECORE_CALLBACK_RENEW;
1041 }
1042
1043 static Eina_Bool
1044 _on_cmd_service_get_favorite(__UNUSED__ char *cmd, char *args)
1045 {
1046    const char *path;
1047    Eina_Bool favorite;
1048    E_Connman_Element *e;
1049
1050    if (!args)
1051      {
1052         fputs("ERROR: missing the service path\n", stderr);
1053         return ECORE_CALLBACK_RENEW;
1054      }
1055    _tok(args);
1056    path = args;
1057
1058    e = e_connman_service_get(path);
1059    if (e_connman_service_favorite_get(e, &favorite))
1060      printf(":::Service %s Favorite = %hhu\n", path, favorite);
1061    else
1062      fputs("ERROR: can't get service favorite\n", stderr);
1063    return ECORE_CALLBACK_RENEW;
1064 }
1065
1066 static Eina_Bool
1067 _on_cmd_service_get_immutable(__UNUSED__ char *cmd, char *args)
1068 {
1069    const char *path;
1070    Eina_Bool immutable;
1071    E_Connman_Element *e;
1072
1073    if (!args)
1074      {
1075         fputs("ERROR: missing the service path\n", stderr);
1076         return ECORE_CALLBACK_RENEW;
1077      }
1078    _tok(args);
1079    path = args;
1080
1081    e = e_connman_service_get(path);
1082    if (e_connman_service_immutable_get(e, &immutable))
1083      printf(":::Service %s Immutable = %hhu\n", path, immutable);
1084    else
1085      fputs("ERROR: can't get service immutable\n", stderr);
1086    return ECORE_CALLBACK_RENEW;
1087 }
1088
1089 static Eina_Bool
1090 _on_cmd_service_get_auto_connect(__UNUSED__ char *cmd, char *args)
1091 {
1092    const char *path;
1093    Eina_Bool auto_connect;
1094    E_Connman_Element *e;
1095
1096    if (!args)
1097      {
1098         fputs("ERROR: missing the service path\n", stderr);
1099         return ECORE_CALLBACK_RENEW;
1100      }
1101    _tok(args);
1102    path = args;
1103
1104    e = e_connman_service_get(path);
1105    if (e_connman_service_auto_connect_get(e, &auto_connect))
1106      printf(":::Service %s Auto Connect = %hhu\n", path, auto_connect);
1107    else
1108      fputs("ERROR: can't get service auto connect\n", stderr);
1109    return ECORE_CALLBACK_RENEW;
1110 }
1111
1112 static Eina_Bool
1113 _on_cmd_service_set_auto_connect(__UNUSED__ char *cmd, char *args)
1114 {
1115    char *path, *next_args;
1116    Eina_Bool auto_connect;
1117    E_Connman_Element *e;
1118
1119    if (!args)
1120      {
1121         fputs("ERROR: missing the service path\n", stderr);
1122         return ECORE_CALLBACK_RENEW;
1123      }
1124    path = args;
1125    next_args = _tok(args);
1126
1127    if (!next_args)
1128      {
1129         fputs("ERROR: missing the auto connect value\n", stderr);
1130         return ECORE_CALLBACK_RENEW;
1131      }
1132    _tok(next_args);
1133    auto_connect = !!atol(next_args);
1134
1135    e = e_connman_service_get(path);
1136    if (e_connman_service_auto_connect_set
1137        (e, auto_connect, _method_success_check, "service_set_auto_connect"))
1138      printf(":::Service %s auto connect set to %d\n", path, auto_connect);
1139    else
1140      fputs("ERROR: can't set service auto connect\n", stderr);
1141    return ECORE_CALLBACK_RENEW;
1142 }
1143
1144 static Eina_Bool
1145 _on_cmd_service_get_roaming(__UNUSED__ char *cmd, char *args)
1146 {
1147    const char *path;
1148    Eina_Bool roaming;
1149    E_Connman_Element *e;
1150
1151    if (!args)
1152      {
1153         fputs("ERROR: missing the service path\n", stderr);
1154         return ECORE_CALLBACK_RENEW;
1155      }
1156    _tok(args);
1157    path = args;
1158
1159    e = e_connman_service_get(path);
1160    if (e_connman_service_roaming_get(e, &roaming))
1161      printf(":::Service %s Roaming = %hhu\n", path, roaming);
1162    else
1163      fputs("ERROR: can't get service roaming\n", stderr);
1164    return ECORE_CALLBACK_RENEW;
1165 }
1166
1167 static Eina_Bool
1168 _on_cmd_service_get_ipv4_method(__UNUSED__ char *cmd, char *args)
1169 {
1170    const char *ipv4_method, *path;
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_ipv4_method_get(e, &ipv4_method))
1183      printf(":::Service %s IPv4 Method = \"%s\"\n", path, ipv4_method);
1184    else
1185      fputs("ERROR: can't get service ipv4 method\n", stderr);
1186    return ECORE_CALLBACK_RENEW;
1187 }
1188
1189 static Eina_Bool
1190 _on_cmd_service_get_ipv4_address(__UNUSED__ char *cmd, char *args)
1191 {
1192    const char *ipv4_address, *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_ipv4_address_get(e, &ipv4_address))
1205      printf(":::Service %s IPv4 Address = \"%s\"\n", path, ipv4_address);
1206    else
1207      fputs("ERROR: can't get service ipv4 address\n", stderr);
1208    return ECORE_CALLBACK_RENEW;
1209 }
1210
1211 static Eina_Bool
1212 _on_cmd_service_get_ipv4_gateway(__UNUSED__ char *cmd, char *args)
1213 {
1214    const char *ipv4_gateway, *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    _tok(args);
1223    path = args;
1224
1225    e = e_connman_service_get(path);
1226    if (e_connman_service_ipv4_gateway_get(e, &ipv4_gateway))
1227      printf(":::Service %s IPv4 Gateway = \"%s\"\n", path, ipv4_gateway);
1228    else
1229      fputs("ERROR: can't get service ipv4 gateway\n", stderr);
1230    return ECORE_CALLBACK_RENEW;
1231 }
1232
1233 static Eina_Bool
1234 _on_cmd_service_get_ipv4_netmask(__UNUSED__ char *cmd, char *args)
1235 {
1236    const char *ipv4_netmask, *path;
1237    E_Connman_Element *e;
1238
1239    if (!args)
1240      {
1241         fputs("ERROR: missing the service path\n", stderr);
1242         return ECORE_CALLBACK_RENEW;
1243      }
1244    _tok(args);
1245    path = args;
1246
1247    e = e_connman_service_get(path);
1248    if (e_connman_service_ipv4_netmask_get(e, &ipv4_netmask))
1249      printf(":::Service %s IPv4 Netmask = \"%s\"\n", path, ipv4_netmask);
1250    else
1251      fputs("ERROR: can't get service ipv4 netmask\n", stderr);
1252    return ECORE_CALLBACK_RENEW;
1253 }
1254
1255 static Eina_Bool
1256 _on_cmd_service_get_ipv4_configuration_method(__UNUSED__ char *cmd, char *args)
1257 {
1258    const char *ipv4_method, *path;
1259    E_Connman_Element *e;
1260
1261    if (!args)
1262      {
1263         fputs("ERROR: missing the service path\n", stderr);
1264         return ECORE_CALLBACK_RENEW;
1265      }
1266    _tok(args);
1267    path = args;
1268
1269    e = e_connman_service_get(path);
1270    if (e_connman_service_ipv4_configuration_method_get(e, &ipv4_method))
1271      printf(":::Service %s IPv4 Configuration Method = \"%s\"\n",
1272             path, ipv4_method);
1273    else
1274      fputs("ERROR: can't get service ipv4_configuration method\n", stderr);
1275    return ECORE_CALLBACK_RENEW;
1276 }
1277
1278 static Eina_Bool
1279 _on_cmd_service_get_ipv4_configuration_address(__UNUSED__ char *cmd, char *args)
1280 {
1281    const char *ipv4_address, *path;
1282    E_Connman_Element *e;
1283
1284    if (!args)
1285      {
1286         fputs("ERROR: missing the service path\n", stderr);
1287         return ECORE_CALLBACK_RENEW;
1288      }
1289    _tok(args);
1290    path = args;
1291
1292    e = e_connman_service_get(path);
1293    if (e_connman_service_ipv4_configuration_address_get(e, &ipv4_address))
1294      printf(":::Service %s IPv4 Configuration Address = \"%s\"\n",
1295             path, ipv4_address);
1296    else
1297      fputs("ERROR: can't get service ipv4_configuration address\n", stderr);
1298    return ECORE_CALLBACK_RENEW;
1299 }
1300
1301 static Eina_Bool
1302 _on_cmd_service_get_ipv4_configuration_gateway(__UNUSED__ char *cmd, char *args)
1303 {
1304    const char *ipv4_gateway, *path;
1305    E_Connman_Element *e;
1306
1307    if (!args)
1308      {
1309         fputs("ERROR: missing the service path\n", stderr);
1310         return ECORE_CALLBACK_RENEW;
1311      }
1312    _tok(args);
1313    path = args;
1314
1315    e = e_connman_service_get(path);
1316    if (e_connman_service_ipv4_configuration_gateway_get(e, &ipv4_gateway))
1317      printf(":::Service %s IPv4 Configuration Gateway = \"%s\"\n",
1318             path, ipv4_gateway);
1319    else
1320      fputs("ERROR: can't get service ipv4_configuration gateway\n", stderr);
1321    return ECORE_CALLBACK_RENEW;
1322 }
1323
1324 static Eina_Bool
1325 _on_cmd_service_get_ipv4_configuration_netmask(__UNUSED__ char *cmd, char *args)
1326 {
1327    const char *ipv4_netmask, *path;
1328    E_Connman_Element *e;
1329
1330    if (!args)
1331      {
1332         fputs("ERROR: missing the service path\n", stderr);
1333         return ECORE_CALLBACK_RENEW;
1334      }
1335    _tok(args);
1336    path = args;
1337
1338    e = e_connman_service_get(path);
1339    if (e_connman_service_ipv4_configuration_netmask_get(e, &ipv4_netmask))
1340      printf(":::Service %s IPv4 Configuration Netmask = \"%s\"\n",
1341             path, ipv4_netmask);
1342    else
1343      fputs("ERROR: can't get service ipv4 configuration netmask\n", stderr);
1344    return ECORE_CALLBACK_RENEW;
1345 }
1346
1347 static Eina_Bool
1348 _on_cmd_service_ipv4_configure_dhcp(__UNUSED__ char *cmd, char *args)
1349 {
1350    char *path;
1351    E_Connman_Element *e;
1352
1353    if (!args)
1354      {
1355         fputs("ERROR: missing the service path\n", stderr);
1356         return ECORE_CALLBACK_RENEW;
1357      }
1358    path = args;
1359    _tok(args);
1360
1361    e = e_connman_service_get(path);
1362    if (e_connman_service_ipv4_configure_dhcp
1363        (e, _method_success_check, "service_ipv4_configure_dhcp"))
1364      printf(":::Service %s IPv4 Configuration set to DHCP\n", path);
1365    else
1366      fputs("ERROR: can't set service ipv4_configuration dhcp\n", stderr);
1367    return ECORE_CALLBACK_RENEW;
1368 }
1369
1370 static Eina_Bool
1371 _on_cmd_service_ipv4_configure_manual(__UNUSED__ char *cmd, char *args)
1372 {
1373    char *path, *next_args, *address, *netmask = NULL, *gateway = NULL;
1374    E_Connman_Element *e;
1375
1376    if (!args)
1377      {
1378         fputs("ERROR: missing the service path\n", stderr);
1379         return ECORE_CALLBACK_RENEW;
1380      }
1381    path = args;
1382    next_args = _tok(args);
1383    if (!next_args)
1384      {
1385         fputs("ERROR: missing the service address\n", stderr);
1386         return ECORE_CALLBACK_RENEW;
1387      }
1388
1389    address = next_args;
1390    next_args = _tok(next_args);
1391    if (next_args)
1392       netmask = next_args;
1393
1394    next_args = _tok(next_args);
1395    if (next_args)
1396      {
1397         gateway = next_args;
1398         _tok(next_args);
1399      }
1400
1401    e = e_connman_service_get(path);
1402    if (e_connman_service_ipv4_configure_manual
1403        (e, address, netmask, gateway,
1404         _method_success_check, "service_ipv4_configure_manual"))
1405      printf(":::Service %s IPv4 Configuration set to Manual (%s/%s) gw %s\n",
1406             path, address, netmask, gateway);
1407    else
1408      fputs("ERROR: can't set service ipv4_configuration manual\n", stderr);
1409    return ECORE_CALLBACK_RENEW;
1410 }
1411
1412 static Eina_Bool
1413 _on_cmd_service_get_ethernet_method(__UNUSED__ char *cmd, char *args)
1414 {
1415    const char *ethernet_method, *path;
1416    E_Connman_Element *e;
1417
1418    if (!args)
1419      {
1420         fputs("ERROR: missing the service path\n", stderr);
1421         return ECORE_CALLBACK_RENEW;
1422      }
1423    _tok(args);
1424    path = args;
1425
1426    e = e_connman_service_get(path);
1427    if (e_connman_service_ethernet_method_get(e, &ethernet_method))
1428      printf(":::Service %s Ethernet Method = \"%s\"\n", path, ethernet_method);
1429    else
1430      fputs("ERROR: can't get service ethernet method\n", stderr);
1431    return ECORE_CALLBACK_RENEW;
1432 }
1433
1434 static Eina_Bool
1435 _on_cmd_service_get_ethernet_address(__UNUSED__ char *cmd, char *args)
1436 {
1437    const char *ethernet_address, *path;
1438    E_Connman_Element *e;
1439
1440    if (!args)
1441      {
1442         fputs("ERROR: missing the service path\n", stderr);
1443         return ECORE_CALLBACK_RENEW;
1444      }
1445    _tok(args);
1446    path = args;
1447
1448    e = e_connman_service_get(path);
1449    if (e_connman_service_ethernet_address_get(e, &ethernet_address))
1450      printf(":::Service %s Ethernet Address = \"%s\"\n",
1451             path, ethernet_address);
1452    else
1453      fputs("ERROR: can't get service ethernet address\n", stderr);
1454    return ECORE_CALLBACK_RENEW;
1455 }
1456
1457 static Eina_Bool
1458 _on_cmd_service_get_ethernet_mtu(__UNUSED__ char *cmd, char *args)
1459 {
1460    const char *path;
1461    E_Connman_Element *e;
1462    unsigned short ethernet_mtu;
1463
1464    if (!args)
1465      {
1466         fputs("ERROR: missing the service path\n", stderr);
1467         return ECORE_CALLBACK_RENEW;
1468      }
1469    _tok(args);
1470    path = args;
1471
1472    e = e_connman_service_get(path);
1473    if (e_connman_service_ethernet_mtu_get(e, &ethernet_mtu))
1474      printf(":::Service %s Ethernet MTU = %hu\n", path, ethernet_mtu);
1475    else
1476      fputs("ERROR: can't get service ethernet mtu\n", stderr);
1477    return ECORE_CALLBACK_RENEW;
1478 }
1479
1480 static Eina_Bool
1481 _on_cmd_technology_get_state(__UNUSED__ char *cmd, char *args)
1482 {
1483    const char *state, *path;
1484    E_Connman_Element *e;
1485
1486    if (!args)
1487      {
1488         fputs("ERROR: missing the technology path\n", stderr);
1489         return ECORE_CALLBACK_RENEW;
1490      }
1491    _tok(args);
1492    path = args;
1493
1494    e = e_connman_technology_get(path);
1495    if (e_connman_technology_state_get(e, &state))
1496      printf(":::Technology %s State = \"%s\"\n", path, state);
1497    else
1498      fputs("ERROR: can't get technology state\n", stderr);
1499    return ECORE_CALLBACK_RENEW;
1500 }
1501
1502 static Eina_Bool
1503 _on_cmd_technology_get_type(__UNUSED__ char *cmd, char *args)
1504 {
1505    const char *type, *path;
1506    E_Connman_Element *e;
1507
1508    if (!args)
1509      {
1510         fputs("ERROR: missing the technology path\n", stderr);
1511         return ECORE_CALLBACK_RENEW;
1512      }
1513    _tok(args);
1514    path = args;
1515
1516    e = e_connman_technology_get(path);
1517    if (e_connman_technology_type_get(e, &type))
1518      printf(":::Technology %s Type = \"%s\"\n", path, type);
1519    else
1520      fputs("ERROR: can't get technology type\n", stderr);
1521    return ECORE_CALLBACK_RENEW;
1522 }
1523
1524 static Eina_Bool
1525 _on_cmd_technology_get_name(__UNUSED__ char *cmd, char *args)
1526 {
1527    const char *name, *path;
1528    E_Connman_Element *e;
1529
1530    if (!args)
1531      {
1532         fputs("ERROR: missing the technology path\n", stderr);
1533         return ECORE_CALLBACK_RENEW;
1534      }
1535    _tok(args);
1536    path = args;
1537
1538    e = e_connman_technology_get(path);
1539    if (e_connman_technology_name_get(e, &name))
1540      printf(":::Technology %s Name = \"%s\"\n", path, name);
1541    else
1542      fputs("ERROR: can't get technology name\n", stderr);
1543    return ECORE_CALLBACK_RENEW;
1544 }
1545
1546 static Eina_Bool
1547 _on_input(__UNUSED__ void *data, Ecore_Fd_Handler *fd_handler)
1548 {
1549    char buf[256];
1550    char *cmd, *args;
1551    const struct {
1552       const char *cmd;
1553       Eina_Bool (*cb)(char *cmd, char *args);
1554    } *itr, maps[] = {
1555      {"quit", _on_cmd_quit},
1556      {"sync", _on_cmd_sync},
1557      {"get_all", _on_cmd_get_all},
1558      {"print", _on_cmd_print},
1559      {"get_properties", _on_cmd_get_properties},
1560      {"set_property", _on_cmd_property_set},
1561      {"manager_get", _on_cmd_manager_get},
1562      {"manager_get_profiles", _on_cmd_manager_get_profiles},
1563      {"manager_get_services", _on_cmd_manager_get_services},
1564      {"manager_register_agent", _on_cmd_manager_register_agent},
1565      {"manager_unregister_agent", _on_cmd_manager_unregister_agent},
1566      {"manager_get_state", _on_cmd_manager_get_state},
1567      {"manager_get_offline_mode", _on_cmd_manager_get_offline_mode},
1568      {"manager_set_offline_mode", _on_cmd_manager_set_offline_mode},
1569      {"manager_request_scan", _on_cmd_manager_request_scan},
1570      {"manager_technology_enable", _on_cmd_manager_technology_enable},
1571      {"manager_technology_disable", _on_cmd_manager_technology_disable},
1572      {"manager_get_technologies_available", _on_cmd_manager_get_technologies_available},
1573      {"manager_get_technologies_enabled", _on_cmd_manager_get_technologies_enabled},
1574      {"manager_get_technologies_connected", _on_cmd_manager_get_technologies_connected},
1575      {"manager_profile_remove", _on_cmd_manager_profile_remove},
1576      {"manager_profile_get_active", _on_cmd_manager_profile_get_active},
1577      {"manager_profile_set_active", _on_cmd_manager_profile_set_active},
1578      {"profile_get_name", _on_cmd_profile_get_name},
1579      {"profile_set_name", _on_cmd_profile_set_name},
1580      {"profile_get_offline_mode", _on_cmd_profile_get_offline_mode},
1581      {"profile_set_offline_mode", _on_cmd_profile_set_offline_mode},
1582      {"profile_get_services", _on_cmd_profile_get_services},
1583      {"service_connect", _on_cmd_service_connect},
1584      {"service_disconnect", _on_cmd_service_disconnect},
1585      {"service_remove", _on_cmd_service_remove},
1586      {"service_move_before", _on_cmd_service_move_before},
1587      {"service_move_after", _on_cmd_service_move_after},
1588      {"service_get_state", _on_cmd_service_get_state},
1589      {"service_get_error", _on_cmd_service_get_error},
1590      {"service_get_name", _on_cmd_service_get_name},
1591      {"service_get_type", _on_cmd_service_get_type},
1592      {"service_get_security", _on_cmd_service_get_security},
1593      {"service_get_passphrase", _on_cmd_service_get_passphrase},
1594      {"service_set_passphrase", _on_cmd_service_set_passphrase},
1595      {"service_get_passphrase_required", _on_cmd_service_get_passphrase_required},
1596      {"service_get_strength", _on_cmd_service_get_strength},
1597      {"service_get_favorite", _on_cmd_service_get_favorite},
1598      {"service_get_immutable", _on_cmd_service_get_immutable},
1599      {"service_get_auto_connect", _on_cmd_service_get_auto_connect},
1600      {"service_set_auto_connect", _on_cmd_service_set_auto_connect},
1601      {"service_get_roaming", _on_cmd_service_get_roaming},
1602      {"service_get_ipv4_method", _on_cmd_service_get_ipv4_method},
1603      {"service_get_ipv4_address", _on_cmd_service_get_ipv4_address},
1604      {"service_get_ipv4_gateway", _on_cmd_service_get_ipv4_gateway},
1605      {"service_get_ipv4_netmask", _on_cmd_service_get_ipv4_netmask},
1606      {"service_get_ipv4_configuration_method", _on_cmd_service_get_ipv4_configuration_method},
1607      {"service_get_ipv4_configuration_address", _on_cmd_service_get_ipv4_configuration_address},
1608      {"service_get_ipv4_configuration_gateway", _on_cmd_service_get_ipv4_configuration_gateway},
1609      {"service_get_ipv4_configuration_netmask", _on_cmd_service_get_ipv4_configuration_netmask},
1610      {"service_ipv4_configure_dhcp", _on_cmd_service_ipv4_configure_dhcp},
1611      {"service_ipv4_configure_manual", _on_cmd_service_ipv4_configure_manual},
1612      {"service_get_ethernet_method", _on_cmd_service_get_ethernet_method},
1613      {"service_get_ethernet_address", _on_cmd_service_get_ethernet_address},
1614      {"service_get_ethernet_mtu", _on_cmd_service_get_ethernet_mtu},
1615      {"technology_get_state", _on_cmd_technology_get_state},
1616      {"technology_get_type", _on_cmd_technology_get_type},
1617      {"technology_get_name", _on_cmd_technology_get_name},
1618      {NULL, NULL}
1619    };
1620
1621
1622    if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR))
1623      {
1624         fputs("ERROR: reading from stdin, exit\n", stderr);
1625         return ECORE_CALLBACK_CANCEL;
1626      }
1627
1628    if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
1629      {
1630         fputs("ERROR: nothing to read?\n", stderr);
1631         return ECORE_CALLBACK_CANCEL;
1632      }
1633
1634    if (!fgets(buf, sizeof(buf), stdin))
1635      {
1636         fprintf(stderr, "ERROR: could not read command: %s\n", strerror(errno));
1637         ecore_main_loop_quit();
1638         return ECORE_CALLBACK_CANCEL;
1639      }
1640
1641    cmd = buf;
1642    while (isspace(*cmd))
1643      cmd++;
1644
1645    args = strchr(cmd, ' ');
1646    if (args)
1647      {
1648         char *p;
1649
1650         *args = '\0';
1651         args++;
1652
1653         while (isspace(*args))
1654           args++;
1655
1656         p = args + strlen(args) - 1;
1657         if (*p == '\n')
1658           *p = '\0';
1659      }
1660    else
1661      {
1662         char *p;
1663
1664         p = cmd + strlen(cmd) - 1;
1665         if (*p == '\n')
1666           *p = '\0';
1667      }
1668
1669    if (strcmp(cmd, "help") == 0)
1670      {
1671         if (args)
1672           {
1673              printf("Commands with '%s' in the name:\n", args);
1674              for (itr = maps; itr->cmd; itr++)
1675                if (strstr(itr->cmd, args))
1676                  printf("\t%s\n", itr->cmd);
1677           }
1678         else
1679           {
1680              fputs("Commands:\n", stdout);
1681              for (itr = maps; itr->cmd; itr++)
1682                printf("\t%s\n", itr->cmd);
1683           }
1684         fputc('\n', stdout);
1685         return ECORE_CALLBACK_RENEW;
1686      }
1687
1688    for (itr = maps; itr->cmd; itr++)
1689      if (strcmp(itr->cmd, cmd) == 0)
1690        return itr->cb(cmd, args);
1691
1692    printf("unknown command \"%s\", args=%s\n", cmd, args);
1693    return ECORE_CALLBACK_RENEW;
1694 }
1695
1696 int
1697 main(__UNUSED__ int argc, __UNUSED__ char *argv[])
1698 {
1699    E_DBus_Connection *c;
1700
1701    ecore_init();
1702    e_dbus_init();
1703    eina_init();
1704
1705    c = e_dbus_bus_get(DBUS_BUS_SYSTEM);
1706    if (!c) {
1707       printf("ERROR: can't connect to system session\n");
1708       return -1;
1709    }
1710
1711    e_connman_system_init(c);
1712    ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_ADD, _on_element_add, NULL);
1713    ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_DEL, _on_element_del, NULL);
1714    ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_UPDATED,
1715                            _on_element_updated, NULL);
1716
1717    ecore_main_fd_handler_add
1718      (0, ECORE_FD_READ | ECORE_FD_ERROR, _on_input, NULL, NULL, NULL);
1719
1720    ecore_main_loop_begin();
1721
1722    e_connman_system_shutdown();
1723
1724    e_dbus_connection_close(c);
1725    eina_shutdown();
1726    e_dbus_shutdown();
1727    ecore_shutdown();
1728
1729    fputs("DBG: clean exit.\n", stderr);
1730
1731    return 0;
1732 }