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