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