summaryrefslogtreecommitdiff
path: root/src/examples
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
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')
-rw-r--r--src/examples/eldbus/dbusmodel.c144
-rw-r--r--src/examples/elementary/filemvc.c35
-rw-r--r--src/examples/elementary/fileviewlist.c2
3 files changed, 115 insertions, 66 deletions
diff --git a/src/examples/eldbus/dbusmodel.c b/src/examples/eldbus/dbusmodel.c
index f2c5e87860..a7c8ee7dac 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}
diff --git a/src/examples/elementary/filemvc.c b/src/examples/elementary/filemvc.c
index 3b4fe5a121..f33b2002eb 100644
--- a/src/examples/elementary/filemvc.c
+++ b/src/examples/elementary/filemvc.c
@@ -51,29 +51,41 @@ _list_selected_cb(void *data EINA_UNUSED, const Eo_Event *event)
51{ 51{
52 Efl_Model_Test_Filemvc_Data *priv = data; 52 Efl_Model_Test_Filemvc_Data *priv = data;
53 Eo *child = event->info; 53 Eo *child = event->info;
54 ethumb_client_file_free(elm_thumb_ethumb_client_get()); 54// ethumb_client_file_free(elm_thumb_ethumb_client_get());
55 55
56 printf("LIST selected model\n"); 56 printf("LIST selected model\n");
57 elm_view_form_model_set(priv->formview, child); 57 elm_view_form_model_set(priv->formview, child);
58 return EINA_TRUE; 58 return EINA_TRUE;
59} 59}
60 60
61static void
62_promise_then(void *data, void *value)
63{
64 Efl_Model_Test_Filemvc_Data *priv = data;
65 char *path;
66 Eo *model;
67
68 eina_value_get((Eina_Value *)value, &path);
69 model = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(eo_self, path));
70 elm_view_list_model_set(priv->fileview, model);
71}
72
73static void
74_promise_error(void *data, const Eina_Error *err)
75{
76}
77
61static Eina_Bool 78static Eina_Bool
62_tree_selected_cb(void *data, const Eo_Event *event) 79_tree_selected_cb(void *data, const Eo_Event *event)
63{ 80{
64 Efl_Model_Test_Filemvc_Data *priv = data; 81 Efl_Model_Test_Filemvc_Data *priv = data;
65 Eo *child = event->info; 82 Eo *child = event->info;
66 const Eina_Value *vpath; 83 Eina_Promise *promise;
67 Eo *model;
68 char *path;
69 84
70 printf("TREE selected model\n"); 85 printf("TREE selected model\n");
71 86
72 efl_model_property_get(child, "path", &vpath); 87 efl_model_property_get(child, "path", &promise);
73 eina_value_get(vpath, &path); 88 eina_promise_then(promise, &_promise_then, &_promise_error, priv);
74 model = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(eo_self, path));
75 efl_model_load(model);
76 elm_view_list_model_set(priv->fileview, model);
77 return EINA_TRUE; 89 return EINA_TRUE;
78} 90}
79 91
@@ -130,16 +142,12 @@ elm_main(int argc, char **argv)
130 evas_object_size_hint_weight_set(panes, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 142 evas_object_size_hint_weight_set(panes, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
131 elm_win_resize_object_add(win, panes); 143 elm_win_resize_object_add(win, panes);
132 144
133 ecore_init();
134 eio_init();
135
136 if(argv[1] != NULL) dirname = argv[1]; 145 if(argv[1] != NULL) dirname = argv[1];
137 else dirname = EFL_MODEL_TEST_FILENAME_PATH; 146 else dirname = EFL_MODEL_TEST_FILENAME_PATH;
138 147
139 //treemodel 148 //treemodel
140 priv.treemodel = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(eo_self, dirname)); 149 priv.treemodel = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(eo_self, dirname));
141 eio_model_children_filter_set(priv.treemodel, _filter_cb, NULL); 150 eio_model_children_filter_set(priv.treemodel, _filter_cb, NULL);
142 efl_model_load(priv.treemodel);
143 151
144 //treeview 152 //treeview
145 genlist = elm_genlist_add(win); 153 genlist = elm_genlist_add(win);
@@ -155,6 +163,7 @@ elm_main(int argc, char **argv)
155 _widget_init(vpanes); 163 _widget_init(vpanes);
156 elm_object_part_content_set(panes, "right", vpanes); 164 elm_object_part_content_set(panes, "right", vpanes);
157 eo_event_callback_add(priv.treeview, ELM_VIEW_LIST_EVENT_MODEL_SELECTED, _tree_selected_cb, &priv); 165 eo_event_callback_add(priv.treeview, ELM_VIEW_LIST_EVENT_MODEL_SELECTED, _tree_selected_cb, &priv);
166
158 //listview 167 //listview
159 genlist = elm_genlist_add(win); 168 genlist = elm_genlist_add(win);
160 priv.fileview = eo_add(ELM_VIEW_LIST_CLASS, NULL, elm_view_list_genlist_set(eo_self, genlist, ELM_GENLIST_ITEM_NONE, "double_label")); 169 priv.fileview = eo_add(ELM_VIEW_LIST_CLASS, NULL, elm_view_list_genlist_set(eo_self, genlist, ELM_GENLIST_ITEM_NONE, "double_label"));
diff --git a/src/examples/elementary/fileviewlist.c b/src/examples/elementary/fileviewlist.c
index 2d765acb8a..a3a434ef1c 100644
--- a/src/examples/elementary/fileviewlist.c
+++ b/src/examples/elementary/fileviewlist.c
@@ -42,7 +42,6 @@ elm_main(int argc, char **argv)
42 memset(&priv, 0, sizeof(Efl_Model_Test_Fileview_Data)); 42 memset(&priv, 0, sizeof(Efl_Model_Test_Fileview_Data));
43 43
44 ecore_init(); 44 ecore_init();
45 eio_init();
46 45
47 if(argv[1] != NULL) dirname = argv[1]; 46 if(argv[1] != NULL) dirname = argv[1];
48 else dirname = EFL_MODEL_TEST_FILENAME_PATH; 47 else dirname = EFL_MODEL_TEST_FILENAME_PATH;
@@ -58,7 +57,6 @@ elm_main(int argc, char **argv)
58 priv.filemodel = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(eo_self, dirname)); 57 priv.filemodel = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(eo_self, dirname));
59 priv.fileview = eo_add(ELM_VIEW_LIST_CLASS, NULL, elm_view_list_genlist_set(eo_self, genlist, ELM_GENLIST_ITEM_TREE, "double_label")); 58 priv.fileview = eo_add(ELM_VIEW_LIST_CLASS, NULL, elm_view_list_genlist_set(eo_self, genlist, ELM_GENLIST_ITEM_TREE, "double_label"));
60 elm_view_list_model_set(priv.fileview, priv.filemodel); 59 elm_view_list_model_set(priv.fileview, priv.filemodel);
61 efl_model_load(priv.filemodel);
62 evas_object_event_callback_add(win, EVAS_CALLBACK_DEL, _cleanup_cb, &priv); 60 evas_object_event_callback_add(win, EVAS_CALLBACK_DEL, _cleanup_cb, &priv);
63 61
64 elm_view_list_property_connect(priv.fileview, "filename", "elm.text"); 62 elm_view_list_property_connect(priv.fileview, "filename", "elm.text");