summaryrefslogtreecommitdiff
path: root/src/examples/eldbus/dbusmodel.c
diff options
context:
space:
mode:
authorLarry <larry.olj@gmail.com>2015-12-02 21:20:48 -0200
committerCedric BAIL <cedric@osg.samsung.com>2015-12-10 12:02:30 -0800
commitec6493a56e37597f31b0e8661e7655da0b93371c (patch)
tree77df57e525b5252caf7cc412bd82cb68188c6666 /src/examples/eldbus/dbusmodel.c
parent10fa1b5b4b2454437c00a9b8931bb3f9ddb9e99c (diff)
eldbus: add eldbus.model examples
Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to '')
-rw-r--r--src/examples/eldbus/dbusmodel.c119
1 files changed, 119 insertions, 0 deletions
diff --git a/src/examples/eldbus/dbusmodel.c b/src/examples/eldbus/dbusmodel.c
new file mode 100644
index 0000000..a3e77e3
--- /dev/null
+++ b/src/examples/eldbus/dbusmodel.c
@@ -0,0 +1,119 @@
1//Compile with:
2// gcc -o busmodel busmodel.c `pkg-config --cflags --libs eldbus ecore eina`
3
4# include <config.h>
5
6#include <Eldbus.h>
7#include <Eldbus_Model.h>
8#include <Efl.h>
9#include <Ecore.h>
10
11#define DEFAULT_BUS "org.freedesktop.DBus"
12#define DEFAULT_PATH "/"
13
14static unsigned int children_count = 0;
15
16static Eina_Bool
17_event_interface_load_status_cb(void *data EINA_UNUSED, Eo *model,
18 const Eo_Event_Description *desc EINA_UNUSED,
19 void *event_info)
20{
21 Efl_Model_Load *actual_load = (Efl_Model_Load*)event_info;
22 Eina_Array *properties_list;
23 Eina_Array_Iterator iterator;
24 Eina_Value const* property_value;
25 char *property, *prop_str;
26 const char *name;
27 unsigned int i;
28
29 if (EFL_MODEL_LOAD_STATUS_LOADED != actual_load->status)
30 return EINA_TRUE;
31
32 eo_do(model,
33 name = eldbus_model_proxy_name_get(),
34 efl_model_properties_get(&properties_list));
35
36 printf(" -> %s\n", name);
37 if (eina_array_count(properties_list))
38 printf(" Properties:\n");
39
40 EINA_ARRAY_ITER_NEXT(properties_list, i, property, iterator)
41 {
42 eo_do(model, efl_model_property_get(property, &property_value));
43 if (property_value)
44 {
45 prop_str = eina_value_to_string(property_value);
46 }
47 printf(" * %s: %s \n", property, prop_str);
48 free(prop_str);
49 prop_str = NULL;
50 }
51
52 children_count--;
53
54 if (!children_count)
55 ecore_main_loop_quit();
56
57 return EINA_FALSE;
58}
59
60static Eina_Bool
61_event_load_status_cb(void *data EINA_UNUSED, Eo *model,
62 const Eo_Event_Description *desc EINA_UNUSED,
63 void *event_info)
64{
65 Efl_Model_Load *actual_load = (Efl_Model_Load*)event_info;
66 Eina_Accessor *accessor;
67 Eo *child = NULL;
68 unsigned int i;
69
70 if (EFL_MODEL_LOAD_STATUS_LOADED != actual_load->status)
71 return EINA_TRUE;
72
73 eo_do(model, efl_model_children_count_get(&children_count));
74 if (children_count == 0)
75 {
76 printf("Don't find Interfaces\n");
77 ecore_main_loop_quit();
78 return EINA_FALSE;
79 }
80
81 eo_do(model, efl_model_children_slice_get(0, 0, &accessor));
82 printf("\nInterfaces:\n");
83 EINA_ACCESSOR_FOREACH(accessor, i, child)
84 {
85 eo_do(child, eo_event_callback_add(EFL_MODEL_BASE_EVENT_LOAD_STATUS, _event_interface_load_status_cb, NULL));
86 eo_do(child, efl_model_load());
87 }
88
89 return EINA_FALSE;
90}
91
92int
93main(int argc, char **argv EINA_UNUSED)
94{
95 const char *bus, *path;
96 Eo *root;
97
98 eldbus_init();
99
100 bus = DEFAULT_BUS;
101 path = DEFAULT_PATH;
102
103 if (argc > 1) bus = argv[1];
104 if (argc > 2) path = argv[2];
105
106 root = eo_add_ref(ELDBUS_MODEL_OBJECT_CLASS, NULL,
107 eldbus_model_object_constructor(ELDBUS_CONNECTION_TYPE_SESSION,
108 NULL, EINA_FALSE, bus, path));
109
110 eo_do(root,
111 eo_event_callback_add(EFL_MODEL_BASE_EVENT_LOAD_STATUS, _event_load_status_cb, NULL),
112 efl_model_load());
113
114 ecore_main_loop_begin();
115
116 eo_do(root, eo_event_callback_del(EFL_MODEL_BASE_EVENT_LOAD_STATUS, _event_load_status_cb, NULL));
117
118 eo_unref(root);
119}