summaryrefslogtreecommitdiff
path: root/src/examples/eldbus
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2018-04-30 13:41:38 -0700
committerCedric BAIL <cedric@osg.samsung.com>2018-05-01 10:39:01 -0700
commit2afe201fff741a49ee67d59e3ee48afaaf807d77 (patch)
tree8b56d60bc5a3855c56de0cd995b541d7959e7c61 /src/examples/eldbus
parent90df5c2bc99323550b65e3cfe9cb5be359d08f99 (diff)
eldbus: update dbus efl.model example.
Diffstat (limited to 'src/examples/eldbus')
-rw-r--r--src/examples/eldbus/dbusmodel.c196
1 files changed, 87 insertions, 109 deletions
diff --git a/src/examples/eldbus/dbusmodel.c b/src/examples/eldbus/dbusmodel.c
index fb197b6..10150c4 100644
--- a/src/examples/eldbus/dbusmodel.c
+++ b/src/examples/eldbus/dbusmodel.c
@@ -14,150 +14,126 @@
14#define DEFAULT_BUS_NAME "org.freedesktop.DBus" 14#define DEFAULT_BUS_NAME "org.freedesktop.DBus"
15#define DEFAULT_PATH "/" 15#define DEFAULT_PATH "/"
16 16
17static int prop_count = 0;
18static int retval = EXIT_SUCCESS; 17static int retval = EXIT_SUCCESS;
19static Eina_Bool quit_on_done = EINA_TRUE; 18static Eina_Bool quit_on_done = EINA_TRUE;
20 19
21static void 20static void
22future_properties_then(void* data, const Efl_Event *event) 21_on_properties_changed(void *data EINA_UNUSED, const Efl_Event *event)
23{ 22{
24 Eo* obj = data; 23 Efl_Model_Property_Event *ev = event->info;
25 Efl_Future_Event_Success *future = event->info; 24 Eina_Array_Iterator it;
26 Eina_Value * property_value; 25 const char *property;
27 const Eina_Array *properties_list; 26 unsigned int i;
28 Eina_Array_Iterator a_it; 27
29 char *property, *prop_str; 28 printf("Properties changed:\n");
30 const char *name; 29 EINA_ARRAY_ITER_NEXT(ev->changed_properties, i, property, it)
31 Eina_Iterator* it = future->value;
32
33 name = eldbus_model_proxy_name_get(obj);
34 properties_list = efl_model_properties_get(obj);
35
36 printf(" -> %s\n Properties:\n", name);
37 unsigned i = 0;
38 EINA_ARRAY_ITER_NEXT(properties_list, i, property, a_it)
39 { 30 {
40 if (eina_iterator_next(it, (void **)&property_value) && property_value) 31 Eina_Value *v;
32 char *str;
33
34 v = efl_model_property_get(event->object, property);
35
36 if (!v)
41 { 37 {
42 prop_str = eina_value_to_string(property_value); 38 EINA_LOG_CRIT("Property '%s' returned nothing.", property);
43 printf(" * %s=%s \n", property, prop_str); 39 abort();
44 free(prop_str);
45 } 40 }
46 }
47 41
48 prop_count--; 42 str = eina_value_to_string(v);
49 if (prop_count == 0) 43 printf("\t%s: '%s'\n", property, str);
50 { 44 free(str);
51 if (quit_on_done) 45
52 ecore_main_loop_quit(); 46 eina_value_free(v);
53 else
54 printf("monitoring events...\n");
55 } 47 }
48
49 printf("Properties invalidated:\n");
50 EINA_ARRAY_ITER_NEXT(ev->invalidated_properties, i, property, it)
51 printf("\t%s\n", property);
56} 52}
57 53
58static void 54static void
59error_cb(void* data EINA_UNUSED, const Efl_Event *event) 55_on_invalidate(void *data EINA_UNUSED, const Efl_Event *event)
60{ 56{
61 Efl_Future_Event_Failure *future = event->info; 57 efl_unref(event->object);
62 printf(" ERROR: #%d '%s'\n", future->error, eina_error_msg_get(future->error));
63 ecore_main_loop_quit();
64 retval = EXIT_FAILURE;
65} 58}
66 59
60EFL_CALLBACKS_ARRAY_DEFINE(child_cbs,
61 { EFL_MODEL_EVENT_PROPERTIES_CHANGED, _on_properties_changed },
62 { EFL_EVENT_INVALIDATE, _on_invalidate });
63
67static void 64static void
68loop_children(Eina_Accessor *children) 65process(Eo *child, unsigned int index)
69{ 66{
70 Eo* child; 67 Eina_Array *properties = efl_model_properties_get(child);
71 int i = 0; 68 const char *property;
69 Eina_Array_Iterator it;
70 Eina_Strbuf *buf;
71 unsigned int i;
72
73 buf = eina_strbuf_new();
72 74
73 EINA_ACCESSOR_FOREACH(children, i, child) 75 const char *name = eldbus_model_proxy_name_get(child);
76
77 EINA_ARRAY_ITER_NEXT(properties, i, property, it)
74 { 78 {
75 const Eina_Array *properties_list = efl_model_properties_get(child); 79 Eina_Value *v = efl_model_property_get(child, property);
76 unsigned p_count = eina_array_count(properties_list); 80 char *str;
77 const char *name = eldbus_model_proxy_name_get(child);
78 81
79 if (p_count) 82 if (!v)
80 {
81 Efl_Future **futures = calloc(p_count + 1, sizeof(Efl_Future *));
82 Eina_Array_Iterator a_it;
83 const char *property;
84 unsigned j = 0;
85
86 EINA_ARRAY_ITER_NEXT(properties_list, j, property, a_it)
87 {
88 futures[j] = efl_model_property_get(child, property);
89 }
90 efl_future_then(efl_future_iterator_all(eina_carray_iterator_new((void **)futures)),
91 &future_properties_then, &error_cb, NULL, child);
92 prop_count++;
93 free(futures);
94 printf(" %2d: %s (loading %u properties asynchronously)\n", i, name, j);
95 }
96 else
97 { 83 {
98 printf(" %2d: %s (no properties yet)\n", i, name); 84 EINA_LOG_CRIT("Property '%s' returned nothing.", property);
85 abort();
99 } 86 }
100 }
101 87
102 if (prop_count == 0) 88 str = eina_value_to_string(v);
103 { 89 eina_strbuf_append_printf(buf, " \t* %s: '%s'\n", property, str);
104 if (quit_on_done) 90 free(str);
105 ecore_main_loop_quit(); 91
106 else 92 eina_value_free(v);
107 printf("monitoring events...\n");
108 } 93 }
109}
110 94
111static void 95 if (eina_array_count(properties) <= 0)
112future_then(void* obj EINA_UNUSED, const Efl_Event *event) 96 eina_strbuf_append_printf(buf, " %2d: %s (no properties yet)\n", index, name);
113{ 97 else
114 Efl_Future_Event_Success *future = event->info; 98 eina_strbuf_prepend_printf(buf, " -> %s\n Properties:\n", name);
115 Eina_Accessor *values = future->value;
116 Eina_Accessor *children;
117 unsigned int *count;
118 99
119 if (!eina_accessor_data_get(values, 0, (void**)&children)) 100 printf("%s", eina_strbuf_string_get(buf));
120 {
121 fprintf(stderr, "ERROR: missing future fulfillment value #0\n");
122 retval = EXIT_FAILURE;
123 ecore_main_loop_quit();
124 return;
125 }
126 101
127 if (!eina_accessor_data_get(values, 1, (void**)&count)) 102 eina_array_free(properties);
128 { 103 eina_strbuf_free(buf);
129 fprintf(stderr, "ERROR: missing future fulfillment value #1\n"); 104
130 retval = EXIT_FAILURE; 105 efl_ref(child);
131 ecore_main_loop_quit(); 106
132 return; 107 efl_event_callback_array_add(child, child_cbs(), NULL);
133 }
134 108
135 printf("efl_model_loaded count %u\n", *count); 109 printf("monitoring events...\n");
136 loop_children(children);
137} 110}
138 111
139static void 112static Eina_Value
140_on_properties_changed(void *data EINA_UNUSED, const Efl_Event *event) 113_slice(void *data, const Eina_Value v,
114 const Eina_Future *dead_future EINA_UNUSED)
141{ 115{
142 Efl_Model_Property_Event *ev = event->info; 116 unsigned int offset = (unsigned int)(uintptr_t) data;
143 Eina_Array_Iterator it; 117 unsigned int i, len;
144 const char *str; 118 Eo *child;
145 unsigned int i;
146 119
147 printf("Properties changed:\n"); 120 if (eina_value_type_get(&v) == EINA_VALUE_TYPE_ERROR) return v;
148 EINA_ARRAY_ITER_NEXT(ev->changed_properties, i, str, it)
149 printf("\t%s\n", str);
150 121
151 printf("Properties invalidated:\n"); 122 EINA_VALUE_ARRAY_FOREACH(&v, len, i, child)
152 EINA_ARRAY_ITER_NEXT(ev->invalidated_properties, i, str, it) 123 process(child, offset + i);
153 printf("\t%s\n", str); 124
125 return v;
154} 126}
155 127
156static void 128static void
157_on_child_added(void *data EINA_UNUSED, const Efl_Event *event) 129_on_child_added(void *data EINA_UNUSED, const Efl_Event *event)
158{ 130{
159 Eo *child = event->info; 131 Efl_Model_Children_Event *ev = event->info;
160 printf("Children Added: %p\n", child); 132
133 printf("Children Added: %i\n", ev->index);
134
135 eina_future_then(efl_model_children_slice_get(event->object, ev->index, 1),
136 _slice, (void*)(uintptr_t) ev->index);
161} 137}
162 138
163static void 139static void
@@ -250,12 +226,14 @@ main(int argc, char **argv EINA_UNUSED)
250 ELDBUS_CONNECTION_TYPE_SESSION); 226 ELDBUS_CONNECTION_TYPE_SESSION);
251 227
252 root = efl_add_ref(ELDBUS_MODEL_OBJECT_CLASS, efl_main_loop_get(), 228 root = efl_add_ref(ELDBUS_MODEL_OBJECT_CLASS, efl_main_loop_get(),
253 eldbus_model_object_custom_constructor(efl_added, conn_type, NULL, EINA_FALSE, bus_name, path), 229 eldbus_model_connect(efl_added, conn_type, NULL, EINA_FALSE),
230 eldbus_model_object_bus_set(efl_added, bus_name),
231 eldbus_model_object_path_set(efl_added, path),
254 efl_event_callback_array_add(efl_added, event_cbs(), NULL)); 232 efl_event_callback_array_add(efl_added, event_cbs(), NULL));
255 233
256 efl_future_then(efl_future_all(efl_model_children_slice_get(root, 0, 0), 234 if (efl_model_children_count_get(root))
257 efl_model_children_count_get(root)), 235 eina_future_then(efl_model_children_slice_get(root, 0, efl_model_children_count_get(root)),
258 &future_then, &error_cb, NULL, root); 236 _slice, (uintptr_t) 0);
259 237
260 ecore_main_loop_begin(); 238 ecore_main_loop_begin();
261 efl_del(root); 239 efl_del(root);