summaryrefslogtreecommitdiff
path: root/src/examples/eldbus
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>2016-11-04 13:09:27 -0200
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>2016-11-04 13:19:57 -0200
commit218403dc19aa55c50c554375ad73b63dfaae7715 (patch)
tree886ed837665e55e2d3650da32eb45826efbbaacc /src/examples/eldbus
parente466dd5c3b34f4a022b87e7f99e119d2ab93fbc7 (diff)
examples/eldbus/dbusmodel.c improve situation, far from correct.
it was using old API, updated, but still doesn't work as expected, lots of warnings from children being left alive, all proxies are reporting no properties... when model dies, all children proxies should die as well, otherwise we get on console: ``` CRI:eldbus lib/eldbus/eldbus_core.c:215 eldbus_shutdown() Alive TYPE_SYSTEM connection ERR:eldbus lib/eldbus/eldbus_core.c:175 print_live_connection() conn=0x8219230 alive object=0x8276d50 net.connman of bus=net.connman ... ``` Also, all proxies are reporting no properties "(no properties yet)", likely they are missing to fetch such... even if "--wait" to let it run, no asynchronous properties are delivered, at least not triggering EFL_MODEL_EVENT_PROPERTIES_CHANGED.
Diffstat (limited to 'src/examples/eldbus')
-rw-r--r--src/examples/eldbus/dbusmodel.c217
1 files changed, 167 insertions, 50 deletions
diff --git a/src/examples/eldbus/dbusmodel.c b/src/examples/eldbus/dbusmodel.c
index 034fde6..47aecd3 100644
--- a/src/examples/eldbus/dbusmodel.c
+++ b/src/examples/eldbus/dbusmodel.c
@@ -9,22 +9,26 @@
9#include <Eldbus_Model.h> 9#include <Eldbus_Model.h>
10#include <Efl.h> 10#include <Efl.h>
11#include <Ecore.h> 11#include <Ecore.h>
12#include <Ecore_Getopt.h>
12 13
13#define DEFAULT_BUS "org.freedesktop.DBus" 14#define DEFAULT_BUS_NAME "org.freedesktop.DBus"
14#define DEFAULT_PATH "/" 15#define DEFAULT_PATH "/"
15 16
16static int prop_count = 0; 17static int prop_count = 0;
18static int retval = EXIT_SUCCESS;
19static Eina_Bool quit_on_done = EINA_TRUE;
17 20
18static void 21static void
19promise_then_prop_c(void* priv_obj, void* data) 22future_properties_then(void* data, const Efl_Event *event)
20{ 23{
21 Eo* obj = priv_obj; 24 Eo* obj = data;
25 Efl_Future_Event_Success *future = event->info;
22 Eina_Value * property_value; 26 Eina_Value * property_value;
23 const Eina_Array *properties_list; 27 const Eina_Array *properties_list;
24 Eina_Array_Iterator a_it; 28 Eina_Array_Iterator a_it;
25 char *property, *prop_str; 29 char *property, *prop_str;
26 const char *name; 30 const char *name;
27 Eina_Iterator* it = data; 31 Eina_Iterator* it = future->value;
28 32
29 name = eldbus_model_proxy_name_get(obj); 33 name = eldbus_model_proxy_name_get(obj);
30 properties_list = efl_model_properties_get(obj); 34 properties_list = efl_model_properties_get(obj);
@@ -43,108 +47,221 @@ promise_then_prop_c(void* priv_obj, void* data)
43 47
44 prop_count--; 48 prop_count--;
45 if (prop_count == 0) 49 if (prop_count == 0)
46 ecore_main_loop_quit(); 50 {
51 if (quit_on_done)
52 ecore_main_loop_quit();
53 else
54 printf("monitoring events...\n");
55 }
47} 56}
48 57
49static void 58static void
50error_cb(void* data EINA_UNUSED, Eina_Error error EINA_UNUSED) 59error_cb(void* data EINA_UNUSED, const Efl_Event *event)
51{ 60{
52 printf(" ERROR\n"); 61 Efl_Future_Event_Failure *future = event->info;
62 printf(" ERROR: #%d '%s'\n", future->error, eina_error_msg_get(future->error));
53 ecore_main_loop_quit(); 63 ecore_main_loop_quit();
64 retval = EXIT_FAILURE;
54} 65}
55 66
56static void 67static void
57promise_then_a(void* priv_obj EINA_UNUSED, void* data) 68loop_children(Eina_Accessor *children)
58{ 69{
59 const Eina_Array *properties_list;
60 Eina_Array_Iterator a_it;
61 Eina_Promise **promises;
62 const char *name;
63 char *property;
64 Eo* child; 70 Eo* child;
65 int i = 0; 71 int i = 0;
66 Eina_Accessor* accessor = data;
67 72
68 EINA_ACCESSOR_FOREACH(accessor, i, child) 73 EINA_ACCESSOR_FOREACH(children, i, child)
69 { 74 {
70 properties_list = efl_model_properties_get(child); 75 const Eina_Array *properties_list = efl_model_properties_get(child);
71 name = eldbus_model_proxy_name_get(child);
72
73 unsigned p_count = eina_array_count(properties_list); 76 unsigned p_count = eina_array_count(properties_list);
77 const char *name = eldbus_model_proxy_name_get(child);
74 78
75 if (p_count) 79 if (p_count)
76 { 80 {
77 promises = (Eina_Promise **)calloc(p_count + 1, sizeof(Eina_Promise *)); 81 Efl_Future **futures = calloc(p_count + 1, sizeof(Efl_Future *));
78 promises[p_count] = NULL; 82 Eina_Array_Iterator a_it;
79 83 const char *property;
80 unsigned j = 0; 84 unsigned j = 0;
85
81 EINA_ARRAY_ITER_NEXT(properties_list, j, property, a_it) 86 EINA_ARRAY_ITER_NEXT(properties_list, j, property, a_it)
82 { 87 {
83 promises[j] = efl_model_property_get(child, property); 88 futures[j] = efl_model_property_get(child, property);
84 } 89 }
85 eina_promise_then(eina_promise_all(eina_carray_iterator_new((void **)promises)), 90 efl_future_then(efl_future_iterator_all(eina_carray_iterator_new((void **)futures)),
86 &promise_then_prop_c, &error_cb, child); 91 &future_properties_then, &error_cb, NULL, child);
87 prop_count++; 92 prop_count++;
93 free(futures);
94 printf(" %2d: %s (loading %u properties asynchronously)\n", i, name, j);
88 } 95 }
89 else 96 else
90 { 97 {
91 printf(" -> %s\n", name); 98 printf(" %2d: %s (no properties yet)\n", i, name);
92 } 99 }
93 } 100 }
94 101
95 if (prop_count == 0) 102 if (prop_count == 0)
96 ecore_main_loop_quit(); 103 {
104 if (quit_on_done)
105 ecore_main_loop_quit();
106 else
107 printf("monitoring events...\n");
108 }
97} 109}
110
98static void 111static void
99promise_then(void* obj EINA_UNUSED, void* data) 112future_then(void* obj EINA_UNUSED, const Efl_Event *event)
100{ 113{
101 Eina_Accessor *accessor; 114 Efl_Future_Event_Success *future = event->info;
102 unsigned int* count; 115 Eina_Accessor *values = future->value;
103 116 Eina_Accessor *children;
104 Eina_Iterator* iterator = data; 117 unsigned int *count;
105 118
106 if (!eina_iterator_next(iterator, (void**)&accessor)) 119 if (!eina_accessor_data_get(values, 0, (void**)&children))
107 { 120 {
108 printf("bye\n"); 121 fprintf(stderr, "ERROR: missing future fulfillment value #0\n");
122 retval = EXIT_FAILURE;
109 ecore_main_loop_quit(); 123 ecore_main_loop_quit();
110 return; 124 return;
111 } 125 }
112 126
113 if(eina_iterator_next(iterator, (void **)&count)) 127 if (!eina_accessor_data_get(values, 1, (void**)&count))
114 { 128 {
115 printf("efl_model_loaded count %d\n", (int)*count); fflush(stdout); 129 fprintf(stderr, "ERROR: missing future fulfillment value #1\n");
116 printf("efl_model_loaded accessor %p\n", accessor); fflush(stdout); 130 retval = EXIT_FAILURE;
117 131 ecore_main_loop_quit();
118 promise_then_a(NULL, accessor); 132 return;
119 } 133 }
134
135 printf("efl_model_loaded count %u\n", *count);
136 loop_children(children);
120} 137}
121 138
139static void
140_on_properties_changed(void *data EINA_UNUSED, const Efl_Event *event)
141{
142 Efl_Model_Property_Event *ev = event->info;
143 Eina_Array_Iterator it;
144 const char *str;
145 unsigned int i;
146
147 printf("Properties changed:\n");
148 EINA_ARRAY_ITER_NEXT(ev->changed_properties, i, str, it)
149 printf("\t%s\n", str);
150
151 printf("Properties invalidated:\n");
152 EINA_ARRAY_ITER_NEXT(ev->invalidated_properties, i, str, it)
153 printf("\t%s\n", str);
154}
155
156static void
157_on_child_added(void *data EINA_UNUSED, const Efl_Event *event)
158{
159 Eo *child = event->info;
160 printf("Children Added: %p\n", child);
161}
162
163static void
164_on_child_removed(void *data EINA_UNUSED, const Efl_Event *event)
165{
166 Eo *child = event->info;
167 printf("Children Removed: %p\n", child);
168}
169
170EFL_CALLBACKS_ARRAY_DEFINE(event_cbs,
171 { EFL_MODEL_EVENT_PROPERTIES_CHANGED, _on_properties_changed },
172 { EFL_MODEL_EVENT_CHILD_ADDED, _on_child_added },
173 { EFL_MODEL_EVENT_CHILD_REMOVED, _on_child_removed });
174
175static const Ecore_Getopt options = {
176 "dbusmodel", /* program name */
177 NULL, /* usage line */
178 "1", /* version */
179 "(C) 2016 Enlightenment Project", /* copyright */
180 "BSD 2-Clause", /* license */
181 /* long description, may be multiline and contain \n */
182 "Example of Eldbus.Model.Object to fetch children and properties.\n",
183 EINA_FALSE,
184 {
185 ECORE_GETOPT_STORE_TRUE('s', "system", "connect to the system bus, not user session."),
186 ECORE_GETOPT_STORE_FALSE('w', "wait", "after done, wait for events (monitoring)"),
187
188 ECORE_GETOPT_VERSION('V', "version"),
189 ECORE_GETOPT_COPYRIGHT('C', "copyright"),
190 ECORE_GETOPT_LICENSE('L', "license"),
191 ECORE_GETOPT_HELP('h', "help"),
192
193 ECORE_GETOPT_STORE_METAVAR_STR(0, NULL, "The bus name to connect.", "bus_name"),
194 ECORE_GETOPT_STORE_METAVAR_STR(0, NULL, "The path to explore.", "path"),
195
196 ECORE_GETOPT_SENTINEL
197 }
198};
199
122int 200int
123main(int argc, char **argv EINA_UNUSED) 201main(int argc, char **argv EINA_UNUSED)
124{ 202{
125 const char *bus, *path; 203 Eldbus_Connection_Type conn_type;
204 Eina_Bool is_system = EINA_FALSE;
205 char *bus_name = DEFAULT_BUS_NAME;
206 char *path = DEFAULT_PATH;
207 Eina_Bool quit_option = EINA_FALSE;
208 Ecore_Getopt_Value values[] = {
209 ECORE_GETOPT_VALUE_BOOL(is_system),
210 ECORE_GETOPT_VALUE_BOOL(quit_on_done),
211
212 /* standard block to provide version, copyright, license and help */
213 ECORE_GETOPT_VALUE_BOOL(quit_option), /* -V/--version quits */
214 ECORE_GETOPT_VALUE_BOOL(quit_option), /* -C/--copyright quits */
215 ECORE_GETOPT_VALUE_BOOL(quit_option), /* -L/--license quits */
216 ECORE_GETOPT_VALUE_BOOL(quit_option), /* -h/--help quits */
217
218 /* positional argument */
219 ECORE_GETOPT_VALUE_STR(bus_name),
220 ECORE_GETOPT_VALUE_STR(path),
221
222 ECORE_GETOPT_VALUE_NONE /* sentinel */
223 };
224 int args;
126 Eo *root; 225 Eo *root;
127 226
128 ecore_init(); 227 ecore_init();
129 eldbus_init(); 228 eldbus_init();
130 229
131 bus = DEFAULT_BUS; 230 args = ecore_getopt_parse(&options, values, argc, argv);
132 path = DEFAULT_PATH; 231 if (args < 0)
232 {
233 fputs("ERROR: Could not parse command line options.\n", stderr);
234 retval = EXIT_FAILURE;
235 goto end;
236 }
237
238 if (quit_option) goto end;
133 239
134 if (argc > 1) bus = argv[1]; 240 args = ecore_getopt_parse_positional(&options, values, argc, argv, args);
135 if (argc > 2) path = argv[2]; 241 if (args < 0)
242 {
243 fputs("ERROR: Could not parse positional arguments.\n", stderr);
244 retval = EXIT_FAILURE;
245 goto end;
246 }
136 247
137 root = efl_add_ref(ELDBUS_MODEL_OBJECT_CLASS, NULL, eldbus_model_object_constructor(efl_added, ELDBUS_CONNECTION_TYPE_SESSION, NULL, EINA_FALSE, bus, path)); 248 conn_type = (is_system ?
249 ELDBUS_CONNECTION_TYPE_SYSTEM :
250 ELDBUS_CONNECTION_TYPE_SESSION);
138 251
139 Eina_Promise *promises[] = { NULL, NULL, NULL}; 252 root = efl_add_ref(ELDBUS_MODEL_OBJECT_CLASS, ecore_main_loop_get(),
140 promises[0] = efl_model_children_slice_get(root, 0, 0); 253 eldbus_model_object_constructor(efl_added, conn_type, NULL, EINA_FALSE, bus_name, path),
141 promises[1] = efl_model_children_count_get(root); 254 efl_event_callback_array_add(efl_added, event_cbs(), NULL));
142 255
143 eina_promise_then(eina_promise_all(eina_carray_iterator_new((void **)promises)), 256 efl_future_then(efl_future_all(efl_model_children_slice_get(root, 0, 0),
144 &promise_then, &error_cb, root); 257 efl_model_children_count_get(root)),
258 &future_then, &error_cb, NULL, root);
145 259
146 ecore_main_loop_begin(); 260 ecore_main_loop_begin();
261 efl_del(root);
147 262
148 efl_unref(root); 263 end:
149 eldbus_shutdown(); 264 eldbus_shutdown();
265 ecore_shutdown();
266 return retval;
150} 267}