151 lines
3.7 KiB
C
151 lines
3.7 KiB
C
//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>
|
|
#include <Efl.h>
|
|
#include <Ecore.h>
|
|
|
|
#define DEFAULT_BUS "org.freedesktop.DBus"
|
|
#define DEFAULT_PATH "/"
|
|
|
|
static int prop_count = 0;
|
|
|
|
static void
|
|
promise_then_prop_c(void* priv_obj, void* data)
|
|
{
|
|
Eo* obj = priv_obj;
|
|
Eina_Value * property_value;
|
|
const Eina_Array *properties_list;
|
|
Eina_Array_Iterator a_it;
|
|
char *property, *prop_str;
|
|
const char *name;
|
|
Eina_Iterator* it = data;
|
|
|
|
name = eldbus_model_proxy_name_get(obj);
|
|
properties_list = efl_model_properties_get(obj);
|
|
|
|
printf(" -> %s\n Properties:\n", name);
|
|
unsigned i = 0;
|
|
EINA_ARRAY_ITER_NEXT(properties_list, i, property, a_it)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
|
|
prop_count--;
|
|
if (prop_count == 0)
|
|
ecore_main_loop_quit();
|
|
}
|
|
|
|
static void
|
|
error_cb(void* data EINA_UNUSED, Eina_Error error EINA_UNUSED)
|
|
{
|
|
printf(" ERROR\n");
|
|
ecore_main_loop_quit();
|
|
}
|
|
|
|
static void
|
|
promise_then_a(void* priv_obj EINA_UNUSED, void* data)
|
|
{
|
|
const Eina_Array *properties_list;
|
|
Eina_Array_Iterator a_it;
|
|
Eina_Promise **promises;
|
|
const char *name;
|
|
char *property;
|
|
Eo* child;
|
|
int i = 0;
|
|
Eina_Accessor* accessor = data;
|
|
|
|
EINA_ACCESSOR_FOREACH(accessor, i, child)
|
|
{
|
|
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)
|
|
{
|
|
promises[j] = efl_model_property_get(child, property);
|
|
}
|
|
eina_promise_then(eina_promise_all(eina_carray_iterator_new((void **)promises)),
|
|
&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(void* obj EINA_UNUSED, void* data)
|
|
{
|
|
Eina_Accessor *accessor;
|
|
unsigned int* count;
|
|
|
|
Eina_Iterator* iterator = data;
|
|
|
|
if (!eina_iterator_next(iterator, (void**)&accessor))
|
|
{
|
|
printf("bye\n");
|
|
ecore_main_loop_quit();
|
|
return;
|
|
}
|
|
|
|
if(eina_iterator_next(iterator, (void **)&count))
|
|
{
|
|
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
|
|
main(int argc, char **argv EINA_UNUSED)
|
|
{
|
|
const char *bus, *path;
|
|
Eo *root;
|
|
|
|
ecore_init();
|
|
eldbus_init();
|
|
|
|
bus = DEFAULT_BUS;
|
|
path = DEFAULT_PATH;
|
|
|
|
if (argc > 1) bus = argv[1];
|
|
if (argc > 2) path = argv[2];
|
|
|
|
root = efl_add_ref(ELDBUS_MODEL_OBJECT_CLASS, NULL, eldbus_model_object_constructor(efl_self, ELDBUS_CONNECTION_TYPE_SESSION, NULL, EINA_FALSE, bus, path));
|
|
|
|
Eina_Promise *promises[] = { NULL, NULL, NULL};
|
|
promises[0] = efl_model_children_slice_get(root, 0, 0);
|
|
promises[1] = efl_model_children_count_get(root);
|
|
|
|
eina_promise_then(eina_promise_all(eina_carray_iterator_new((void **)promises)),
|
|
&promise_then, &error_cb, root);
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
efl_unref(root);
|
|
eldbus_shutdown();
|
|
}
|