summaryrefslogtreecommitdiff
path: root/src/examples/edbus/connman-list-services.c
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2012-12-28 17:53:25 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2012-12-28 17:53:25 +0000
commit331488d1ce3db2d07533ee276dabdc23f153fa61 (patch)
treea091fe83bfcf0c9d8f9f34ebfe44a5347537bff8 /src/examples/edbus/connman-list-services.c
parent6800b178dc918633ede220c572e5b99fa0046e7e (diff)
efl: merge edbus (v2).
SVN revision: 81825
Diffstat (limited to 'src/examples/edbus/connman-list-services.c')
-rw-r--r--src/examples/edbus/connman-list-services.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/src/examples/edbus/connman-list-services.c b/src/examples/edbus/connman-list-services.c
new file mode 100644
index 0000000000..a192d8b506
--- /dev/null
+++ b/src/examples/edbus/connman-list-services.c
@@ -0,0 +1,107 @@
1#include "EDBus.h"
2#include <Ecore.h>
3
4static void
5on_services_get(void *data, const EDBus_Message *msg, EDBus_Pending *pending)
6{
7 EDBus_Message_Iter *array, *entry;
8 const char *errname, *errmsg;
9
10 if (edbus_message_error_get(msg, &errname, &errmsg))
11 {
12 fprintf(stderr, "Error: %s %s\n", errname, errmsg);
13 return;
14 }
15
16 if (!edbus_message_arguments_get(msg, "a(oa{sv})", &array))
17 {
18 fprintf(stderr, "Error: could not get array\n");
19 return;
20 }
21
22 while (edbus_message_iter_get_and_next(array, 'r', &entry))
23 {
24 EDBus_Message_Iter *properties, *dict_entry;
25 const char *path;
26
27 if (!edbus_message_iter_arguments_get(entry, "oa{sv}", &path, &properties))
28 {
29 fprintf(stderr, "Error: could not get entry contents\n");
30 return;
31 }
32
33 printf("service: %s\n", path);
34
35 while (edbus_message_iter_get_and_next(properties, 'e', &dict_entry))
36 {
37 EDBus_Message_Iter *variant;
38 const char *key;
39
40 if (!edbus_message_iter_arguments_get(dict_entry, "sv", &key,
41 &variant))
42 {
43 fprintf(stderr,
44 "Error: could not get property contents\n");
45 return;
46 }
47
48 printf("\t%s: type %s\n", key,
49 edbus_message_iter_signature_get(variant));
50
51 /* TODO: get the value from variant */
52 }
53 }
54}
55
56int
57main(void)
58{
59 EDBus_Connection *conn;
60 EDBus_Object *obj;
61 EDBus_Proxy *manager;
62 EDBus_Pending *pending;
63
64 ecore_init();
65 edbus_init();
66
67 conn = edbus_connection_get(EDBUS_CONNECTION_TYPE_SYSTEM);
68 if (!conn)
69 {
70 fprintf(stderr, "Error: could not get system bus\n");
71 return EXIT_FAILURE;
72 }
73
74 obj = edbus_object_get(conn, "net.connman", "/");
75 if (!obj)
76 {
77 fprintf(stderr, "Error: could not get object\n");
78 return EXIT_FAILURE;
79 }
80
81 manager = edbus_proxy_get(obj, "net.connman.Manager");
82 if (!manager)
83 {
84 fprintf(stderr, "Error: could not get proxy\n");
85 return EXIT_FAILURE;
86 }
87
88 pending = edbus_proxy_call(manager, "GetServices", on_services_get, NULL,
89 -1, "");
90
91 if (!pending)
92 {
93 fprintf(stderr, "Error: could not call\n");
94 return EXIT_FAILURE;
95 }
96
97 ecore_main_loop_begin();
98
99 edbus_proxy_unref(manager);
100 edbus_object_unref(obj);
101 edbus_connection_unref(conn);
102
103 edbus_shutdown();
104 ecore_shutdown();
105 return 0;
106}
107