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
This commit is contained in:
parent
5ec412c4bd
commit
b37ad2b589
|
@ -1,7 +1,9 @@
|
|||
//Compile with:
|
||||
// gcc -o busmodel busmodel.c `pkg-config --cflags --libs eldbus ecore eina`
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <Eldbus.h>
|
||||
#include <Eldbus_Model.h>
|
||||
|
@ -11,77 +13,113 @@
|
|||
#define DEFAULT_BUS "org.freedesktop.DBus"
|
||||
#define DEFAULT_PATH "/"
|
||||
|
||||
static unsigned int children_count = 0;
|
||||
static int prop_count = 0;
|
||||
|
||||
static Eina_Bool
|
||||
_event_interface_load_status_cb(void *data EINA_UNUSED, const Eo_Event *event)
|
||||
struct eina_iterator
|
||||
{
|
||||
Efl_Model_Load *actual_load = (Efl_Model_Load*)event->info;
|
||||
Eina_Array *properties_list;
|
||||
Eina_Array_Iterator iterator;
|
||||
Eina_Value const* property_value;
|
||||
Eina_Iterator* success_iterator;
|
||||
Eina_Iterator* failure_iterator;
|
||||
};
|
||||
|
||||
static void
|
||||
promise_then_prop_c(Eo* obj, struct eina_iterator* it_struct)
|
||||
{
|
||||
Eina_Value * property_value;
|
||||
const Eina_Array *properties_list;
|
||||
Eina_Array_Iterator a_it;
|
||||
char *property, *prop_str;
|
||||
const char *name;
|
||||
unsigned int i;
|
||||
Eina_Iterator* it = it_struct->success_iterator;
|
||||
|
||||
if (EFL_MODEL_LOAD_STATUS_LOADED != actual_load->status)
|
||||
return EINA_TRUE;
|
||||
name = eldbus_model_proxy_name_get(obj);
|
||||
properties_list = efl_model_properties_get(obj);
|
||||
|
||||
name = eldbus_model_proxy_name_get(event->obj);
|
||||
efl_model_properties_get(event->obj, &properties_list);
|
||||
|
||||
printf(" -> %s\n", name);
|
||||
if (eina_array_count(properties_list))
|
||||
printf(" Properties:\n");
|
||||
|
||||
EINA_ARRAY_ITER_NEXT(properties_list, i, property, iterator)
|
||||
printf(" -> %s\n Properties:\n", name);
|
||||
unsigned i = 0;
|
||||
EINA_ARRAY_ITER_NEXT(properties_list, i, property, a_it)
|
||||
{
|
||||
efl_model_property_get(event->obj, property, &property_value);
|
||||
if (property_value)
|
||||
if (eina_iterator_next(it, (void **)&property_value) && property_value)
|
||||
{
|
||||
prop_str = eina_value_to_string(property_value);
|
||||
printf(" * %s=%s \n", property, prop_str);
|
||||
free(prop_str);
|
||||
}
|
||||
printf(" * %s: %s \n", property, prop_str);
|
||||
free(prop_str);
|
||||
prop_str = NULL;
|
||||
}
|
||||
|
||||
children_count--;
|
||||
|
||||
if (!children_count)
|
||||
prop_count--;
|
||||
if (prop_count == 0)
|
||||
ecore_main_loop_quit();
|
||||
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_event_load_status_cb(void *data EINA_UNUSED, const Eo_Event *event)
|
||||
static void
|
||||
error_cb(void* data EINA_UNUSED, const Eina_Error *error EINA_UNUSED)
|
||||
{
|
||||
Efl_Model_Load *actual_load = (Efl_Model_Load*)event->info;
|
||||
Eina_Accessor *accessor;
|
||||
Eo *child = NULL;
|
||||
unsigned int i;
|
||||
printf(" ERROR\n");
|
||||
ecore_main_loop_quit();
|
||||
}
|
||||
|
||||
if (EFL_MODEL_LOAD_STATUS_LOADED != actual_load->status)
|
||||
return EINA_TRUE;
|
||||
static void
|
||||
promise_then_a(Eo* obj EINA_UNUSED, Eina_Accessor **accessor)
|
||||
{
|
||||
const Eina_Array *properties_list;
|
||||
Eina_Array_Iterator a_it;
|
||||
Eina_Promise **promises;
|
||||
const char *name;
|
||||
char *property;
|
||||
Eo* child;
|
||||
int i = 0;
|
||||
|
||||
efl_model_children_count_get(event->obj, &children_count);
|
||||
if (children_count == 0)
|
||||
EINA_ACCESSOR_FOREACH(*accessor, i, child)
|
||||
{
|
||||
printf("Don't find Interfaces\n");
|
||||
properties_list = efl_model_properties_get(child);
|
||||
name = eldbus_model_proxy_name_get(child);
|
||||
|
||||
unsigned p_count = eina_array_count(properties_list);
|
||||
|
||||
if (p_count)
|
||||
{
|
||||
promises = (Eina_Promise **)calloc(p_count + 1, sizeof(Eina_Promise *));
|
||||
promises[p_count] = NULL;
|
||||
|
||||
unsigned j = 0;
|
||||
EINA_ARRAY_ITER_NEXT(properties_list, j, property, a_it)
|
||||
{
|
||||
efl_model_property_get(child, property, &promises[j]);
|
||||
}
|
||||
eina_promise_then(eina_promise_all(eina_carray_iterator_new((void **)promises)),
|
||||
(Eina_Promise_Cb)&promise_then_prop_c, &error_cb, child);
|
||||
prop_count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(" -> %s\n", name);
|
||||
}
|
||||
}
|
||||
|
||||
if (prop_count == 0)
|
||||
ecore_main_loop_quit();
|
||||
}
|
||||
static void
|
||||
promise_then(Eo* obj EINA_UNUSED, struct eina_iterator* it_struct)
|
||||
{
|
||||
Eina_Accessor **accessor;
|
||||
unsigned int* count;
|
||||
|
||||
Eina_Iterator* iterator = it_struct->success_iterator;
|
||||
|
||||
if (!eina_iterator_next(iterator, (void **)&accessor))
|
||||
{
|
||||
printf("bye\n");
|
||||
ecore_main_loop_quit();
|
||||
return EINA_FALSE;
|
||||
return;
|
||||
}
|
||||
|
||||
efl_model_children_slice_get(event->obj, 0, 0, &accessor);
|
||||
printf("\nInterfaces:\n");
|
||||
EINA_ACCESSOR_FOREACH(accessor, i, child)
|
||||
{
|
||||
eo_event_callback_add(child, EFL_MODEL_BASE_EVENT_LOAD_STATUS, _event_interface_load_status_cb, NULL);
|
||||
efl_model_load(child);
|
||||
}
|
||||
eina_iterator_next(iterator, (void **)&count);
|
||||
|
||||
return EINA_FALSE;
|
||||
printf("efl_model_loaded count %d\n", (int)*count); fflush(stdout);
|
||||
printf("efl_model_loaded accessor %p\n", accessor); fflush(stdout);
|
||||
|
||||
promise_then_a(NULL, accessor);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -90,6 +128,7 @@ main(int argc, char **argv EINA_UNUSED)
|
|||
const char *bus, *path;
|
||||
Eo *root;
|
||||
|
||||
ecore_init();
|
||||
eldbus_init();
|
||||
|
||||
bus = DEFAULT_BUS;
|
||||
|
@ -100,12 +139,15 @@ main(int argc, char **argv EINA_UNUSED)
|
|||
|
||||
root = eo_add_ref(ELDBUS_MODEL_OBJECT_CLASS, NULL, eldbus_model_object_constructor(eo_self, ELDBUS_CONNECTION_TYPE_SESSION, NULL, EINA_FALSE, bus, path));
|
||||
|
||||
eo_event_callback_add(root, EFL_MODEL_BASE_EVENT_LOAD_STATUS, _event_load_status_cb, NULL);
|
||||
efl_model_load(root);
|
||||
Eina_Promise *promises[] = { NULL, NULL, NULL};
|
||||
efl_model_children_slice_get(root, 0, 0, &promises[0]);
|
||||
efl_model_children_count_get(root, &promises[1]);
|
||||
|
||||
eina_promise_then(eina_promise_all(eina_carray_iterator_new((void **)promises)),
|
||||
(Eina_Promise_Cb)&promise_then, &error_cb, root);
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
||||
eo_event_callback_del(root, EFL_MODEL_BASE_EVENT_LOAD_STATUS, _event_load_status_cb, NULL);
|
||||
|
||||
eo_unref(root);
|
||||
eldbus_shutdown();
|
||||
}
|
||||
|
|
|
@ -51,29 +51,41 @@ _list_selected_cb(void *data EINA_UNUSED, const Eo_Event *event)
|
|||
{
|
||||
Efl_Model_Test_Filemvc_Data *priv = data;
|
||||
Eo *child = event->info;
|
||||
ethumb_client_file_free(elm_thumb_ethumb_client_get());
|
||||
// ethumb_client_file_free(elm_thumb_ethumb_client_get());
|
||||
|
||||
printf("LIST selected model\n");
|
||||
elm_view_form_model_set(priv->formview, child);
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
_promise_then(void *data, void *value)
|
||||
{
|
||||
Efl_Model_Test_Filemvc_Data *priv = data;
|
||||
char *path;
|
||||
Eo *model;
|
||||
|
||||
eina_value_get((Eina_Value *)value, &path);
|
||||
model = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(eo_self, path));
|
||||
elm_view_list_model_set(priv->fileview, model);
|
||||
}
|
||||
|
||||
static void
|
||||
_promise_error(void *data, const Eina_Error *err)
|
||||
{
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_tree_selected_cb(void *data, const Eo_Event *event)
|
||||
{
|
||||
Efl_Model_Test_Filemvc_Data *priv = data;
|
||||
Eo *child = event->info;
|
||||
const Eina_Value *vpath;
|
||||
Eo *model;
|
||||
char *path;
|
||||
Eina_Promise *promise;
|
||||
|
||||
printf("TREE selected model\n");
|
||||
|
||||
efl_model_property_get(child, "path", &vpath);
|
||||
eina_value_get(vpath, &path);
|
||||
model = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(eo_self, path));
|
||||
efl_model_load(model);
|
||||
elm_view_list_model_set(priv->fileview, model);
|
||||
efl_model_property_get(child, "path", &promise);
|
||||
eina_promise_then(promise, &_promise_then, &_promise_error, priv);
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
|
@ -130,16 +142,12 @@ elm_main(int argc, char **argv)
|
|||
evas_object_size_hint_weight_set(panes, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
elm_win_resize_object_add(win, panes);
|
||||
|
||||
ecore_init();
|
||||
eio_init();
|
||||
|
||||
if(argv[1] != NULL) dirname = argv[1];
|
||||
else dirname = EFL_MODEL_TEST_FILENAME_PATH;
|
||||
|
||||
//treemodel
|
||||
priv.treemodel = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(eo_self, dirname));
|
||||
eio_model_children_filter_set(priv.treemodel, _filter_cb, NULL);
|
||||
efl_model_load(priv.treemodel);
|
||||
|
||||
//treeview
|
||||
genlist = elm_genlist_add(win);
|
||||
|
@ -155,6 +163,7 @@ elm_main(int argc, char **argv)
|
|||
_widget_init(vpanes);
|
||||
elm_object_part_content_set(panes, "right", vpanes);
|
||||
eo_event_callback_add(priv.treeview, ELM_VIEW_LIST_EVENT_MODEL_SELECTED, _tree_selected_cb, &priv);
|
||||
|
||||
//listview
|
||||
genlist = elm_genlist_add(win);
|
||||
priv.fileview = eo_add(ELM_VIEW_LIST_CLASS, NULL, elm_view_list_genlist_set(eo_self, genlist, ELM_GENLIST_ITEM_NONE, "double_label"));
|
||||
|
|
|
@ -42,7 +42,6 @@ elm_main(int argc, char **argv)
|
|||
memset(&priv, 0, sizeof(Efl_Model_Test_Fileview_Data));
|
||||
|
||||
ecore_init();
|
||||
eio_init();
|
||||
|
||||
if(argv[1] != NULL) dirname = argv[1];
|
||||
else dirname = EFL_MODEL_TEST_FILENAME_PATH;
|
||||
|
@ -58,7 +57,6 @@ elm_main(int argc, char **argv)
|
|||
priv.filemodel = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(eo_self, dirname));
|
||||
priv.fileview = eo_add(ELM_VIEW_LIST_CLASS, NULL, elm_view_list_genlist_set(eo_self, genlist, ELM_GENLIST_ITEM_TREE, "double_label"));
|
||||
elm_view_list_model_set(priv.fileview, priv.filemodel);
|
||||
efl_model_load(priv.filemodel);
|
||||
evas_object_event_callback_add(win, EVAS_CALLBACK_DEL, _cleanup_cb, &priv);
|
||||
|
||||
elm_view_list_property_connect(priv.fileview, "filename", "elm.text");
|
||||
|
|
Loading…
Reference in New Issue