summaryrefslogtreecommitdiff
path: root/src/examples/eldbus
diff options
context:
space:
mode:
authorLarry Jr <larry.olj@gmail.com>2016-04-20 17:07:53 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-04-29 13:21:24 -0300
commit0c76f82a31b1ad06a4da4c12f1a02139e0d0c6fa (patch)
tree254f0542b8fc5ea1af14936da8e6806262f3f8a6 /src/examples/eldbus
parent42346e22f4c06634e180c44cf63924dbc50a5184 (diff)
Efl, Eio, Eldbus, Elementary: new model API use eina_promise
Efl - efl_model_base changed to use eina_promise Eio - eio_model use efl_model_base with promise Eldbus - elddbus models use promise now Elementary - elm_view_list and elm_view_form use new models with promise updated all related examples and tests
Diffstat (limited to 'src/examples/eldbus')
-rw-r--r--src/examples/eldbus/dbusmodel.c144
1 files changed, 93 insertions, 51 deletions
diff --git a/src/examples/eldbus/dbusmodel.c b/src/examples/eldbus/dbusmodel.c
index f2c5e87..a7c8ee7 100644
--- a/src/examples/eldbus/dbusmodel.c
+++ b/src/examples/eldbus/dbusmodel.c
@@ -1,7 +1,9 @@
1//Compile with: 1//Compile with:
2// gcc -o busmodel busmodel.c `pkg-config --cflags --libs eldbus ecore eina` 2// gcc -o busmodel busmodel.c `pkg-config --cflags --libs eldbus ecore eina`
3 3
4#ifdef HAVE_CONFIG_H
4# include <config.h> 5# include <config.h>
6#endif
5 7
6#include <Eldbus.h> 8#include <Eldbus.h>
7#include <Eldbus_Model.h> 9#include <Eldbus_Model.h>
@@ -11,77 +13,113 @@
11#define DEFAULT_BUS "org.freedesktop.DBus" 13#define DEFAULT_BUS "org.freedesktop.DBus"
12#define DEFAULT_PATH "/" 14#define DEFAULT_PATH "/"
13 15
14static unsigned int children_count = 0; 16static int prop_count = 0;
15 17
16static Eina_Bool 18struct eina_iterator
17_event_interface_load_status_cb(void *data EINA_UNUSED, const Eo_Event *event)
18{ 19{
19 Efl_Model_Load *actual_load = (Efl_Model_Load*)event->info; 20 Eina_Iterator* success_iterator;
20 Eina_Array *properties_list; 21 Eina_Iterator* failure_iterator;
21 Eina_Array_Iterator iterator; 22};
22 Eina_Value const* property_value; 23
24static void
25promise_then_prop_c(Eo* obj, struct eina_iterator* it_struct)
26{
27 Eina_Value * property_value;
28 const Eina_Array *properties_list;
29 Eina_Array_Iterator a_it;
23 char *property, *prop_str; 30 char *property, *prop_str;
24 const char *name; 31 const char *name;
25 unsigned int i; 32 Eina_Iterator* it = it_struct->success_iterator;
26
27 if (EFL_MODEL_LOAD_STATUS_LOADED != actual_load->status)
28 return EINA_TRUE;
29
30 name = eldbus_model_proxy_name_get(event->obj);
31 efl_model_properties_get(event->obj, &properties_list);
32 33
33 printf(" -> %s\n", name); 34 name = eldbus_model_proxy_name_get(obj);
34 if (eina_array_count(properties_list)) 35 properties_list = efl_model_properties_get(obj);
35 printf(" Properties:\n");
36 36
37 EINA_ARRAY_ITER_NEXT(properties_list, i, property, iterator) 37 printf(" -> %s\n Properties:\n", name);
38 unsigned i = 0;
39 EINA_ARRAY_ITER_NEXT(properties_list, i, property, a_it)
38 { 40 {
39 efl_model_property_get(event->obj, property, &property_value); 41 if (eina_iterator_next(it, (void **)&property_value) && property_value)
40 if (property_value)
41 { 42 {
42 prop_str = eina_value_to_string(property_value); 43 prop_str = eina_value_to_string(property_value);
44 printf(" * %s=%s \n", property, prop_str);
45 free(prop_str);
43 } 46 }
44 printf(" * %s: %s \n", property, prop_str);
45 free(prop_str);
46 prop_str = NULL;
47 } 47 }
48 48
49 children_count--; 49 prop_count--;
50 50 if (prop_count == 0)
51 if (!children_count)
52 ecore_main_loop_quit(); 51 ecore_main_loop_quit();
53
54 return EINA_FALSE;
55} 52}
56 53
57static Eina_Bool 54static void
58_event_load_status_cb(void *data EINA_UNUSED, const Eo_Event *event) 55error_cb(void* data EINA_UNUSED, const Eina_Error *error EINA_UNUSED)
59{ 56{
60 Efl_Model_Load *actual_load = (Efl_Model_Load*)event->info; 57 printf(" ERROR\n");
61 Eina_Accessor *accessor; 58 ecore_main_loop_quit();
62 Eo *child = NULL; 59}
63 unsigned int i;
64 60
65 if (EFL_MODEL_LOAD_STATUS_LOADED != actual_load->status) 61static void
66 return EINA_TRUE; 62promise_then_a(Eo* obj EINA_UNUSED, Eina_Accessor **accessor)
63{
64 const Eina_Array *properties_list;
65 Eina_Array_Iterator a_it;
66 Eina_Promise **promises;
67 const char *name;
68 char *property;
69 Eo* child;
70 int i = 0;
67 71
68 efl_model_children_count_get(event->obj, &children_count); 72 EINA_ACCESSOR_FOREACH(*accessor, i, child)
69 if (children_count == 0)
70 { 73 {
71 printf("Don't find Interfaces\n"); 74 properties_list = efl_model_properties_get(child);
72 ecore_main_loop_quit(); 75 name = eldbus_model_proxy_name_get(child);
73 return EINA_FALSE; 76
77 unsigned p_count = eina_array_count(properties_list);
78
79 if (p_count)
80 {
81 promises = (Eina_Promise **)calloc(p_count + 1, sizeof(Eina_Promise *));
82 promises[p_count] = NULL;
83
84 unsigned j = 0;
85 EINA_ARRAY_ITER_NEXT(properties_list, j, property, a_it)
86 {
87 efl_model_property_get(child, property, &promises[j]);
88 }
89 eina_promise_then(eina_promise_all(eina_carray_iterator_new((void **)promises)),
90 (Eina_Promise_Cb)&promise_then_prop_c, &error_cb, child);
91 prop_count++;
92 }
93 else
94 {
95 printf(" -> %s\n", name);
96 }
74 } 97 }
75 98
76 efl_model_children_slice_get(event->obj, 0, 0, &accessor); 99 if (prop_count == 0)
77 printf("\nInterfaces:\n"); 100 ecore_main_loop_quit();
78 EINA_ACCESSOR_FOREACH(accessor, i, child) 101}
102static void
103promise_then(Eo* obj EINA_UNUSED, struct eina_iterator* it_struct)
104{
105 Eina_Accessor **accessor;
106 unsigned int* count;
107
108 Eina_Iterator* iterator = it_struct->success_iterator;
109
110 if (!eina_iterator_next(iterator, (void **)&accessor))
79 { 111 {
80 eo_event_callback_add(child, EFL_MODEL_BASE_EVENT_LOAD_STATUS, _event_interface_load_status_cb, NULL); 112 printf("bye\n");
81 efl_model_load(child); 113 ecore_main_loop_quit();
114 return;
82 } 115 }
83 116
84 return EINA_FALSE; 117 eina_iterator_next(iterator, (void **)&count);
118
119 printf("efl_model_loaded count %d\n", (int)*count); fflush(stdout);
120 printf("efl_model_loaded accessor %p\n", accessor); fflush(stdout);
121
122 promise_then_a(NULL, accessor);
85} 123}
86 124
87int 125int
@@ -90,6 +128,7 @@ main(int argc, char **argv EINA_UNUSED)
90 const char *bus, *path; 128 const char *bus, *path;
91 Eo *root; 129 Eo *root;
92 130
131 ecore_init();
93 eldbus_init(); 132 eldbus_init();
94 133
95 bus = DEFAULT_BUS; 134 bus = DEFAULT_BUS;
@@ -100,12 +139,15 @@ main(int argc, char **argv EINA_UNUSED)
100 139
101 root = eo_add_ref(ELDBUS_MODEL_OBJECT_CLASS, NULL, eldbus_model_object_constructor(eo_self, ELDBUS_CONNECTION_TYPE_SESSION, NULL, EINA_FALSE, bus, path)); 140 root = eo_add_ref(ELDBUS_MODEL_OBJECT_CLASS, NULL, eldbus_model_object_constructor(eo_self, ELDBUS_CONNECTION_TYPE_SESSION, NULL, EINA_FALSE, bus, path));
102 141
103 eo_event_callback_add(root, EFL_MODEL_BASE_EVENT_LOAD_STATUS, _event_load_status_cb, NULL); 142 Eina_Promise *promises[] = { NULL, NULL, NULL};
104 efl_model_load(root); 143 efl_model_children_slice_get(root, 0, 0, &promises[0]);
144 efl_model_children_count_get(root, &promises[1]);
105 145
106 ecore_main_loop_begin(); 146 eina_promise_then(eina_promise_all(eina_carray_iterator_new((void **)promises)),
147 (Eina_Promise_Cb)&promise_then, &error_cb, root);
107 148
108 eo_event_callback_del(root, EFL_MODEL_BASE_EVENT_LOAD_STATUS, _event_load_status_cb, NULL); 149 ecore_main_loop_begin();
109 150
110 eo_unref(root); 151 eo_unref(root);
152 eldbus_shutdown();
111} 153}