summaryrefslogtreecommitdiff
path: root/src/examples/eldbus
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
parent10fa1b5b4b2454437c00a9b8931bb3f9ddb9e99c (diff)
eldbus: add eldbus.model examples
Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/examples/eldbus')
-rw-r--r--src/examples/eldbus/Makefile.am11
-rw-r--r--src/examples/eldbus/dbusmodel.c119
2 files changed, 128 insertions, 2 deletions
diff --git a/src/examples/eldbus/Makefile.am b/src/examples/eldbus/Makefile.am
index d820f1d..65e6254 100644
--- a/src/examples/eldbus/Makefile.am
+++ b/src/examples/eldbus/Makefile.am
@@ -3,6 +3,7 @@ MAINTAINERCLEANFILES = Makefile.in
3AM_CPPFLAGS = \ 3AM_CPPFLAGS = \
4-I$(top_builddir)/src/lib/efl \ 4-I$(top_builddir)/src/lib/efl \
5-I$(top_srcdir)/src/lib/eina \ 5-I$(top_srcdir)/src/lib/eina \
6-I$(top_srcdir)/src/lib/efl \
6-I$(top_srcdir)/src/lib/eo \ 7-I$(top_srcdir)/src/lib/eo \
7-I$(top_srcdir)/src/lib/ecore \ 8-I$(top_srcdir)/src/lib/ecore \
8-I$(top_srcdir)/src/lib/eldbus \ 9-I$(top_srcdir)/src/lib/eldbus \
@@ -17,6 +18,7 @@ $(top_builddir)/src/lib/eo/libeo.la \
17$(top_builddir)/src/lib/ecore/libecore.la \ 18$(top_builddir)/src/lib/ecore/libecore.la \
18$(top_builddir)/src/lib/eina/libeina.la \ 19$(top_builddir)/src/lib/eina/libeina.la \
19$(top_builddir)/src/lib/eldbus/libeldbus.la \ 20$(top_builddir)/src/lib/eldbus/libeldbus.la \
21$(top_builddir)/src/lib/efl/libefl.la \
20@ELDBUS_LDFLAGS@ 22@ELDBUS_LDFLAGS@
21 23
22SRCS = \ 24SRCS = \
@@ -29,7 +31,8 @@ server.c \
29client.c \ 31client.c \
30simple-signal-emit.c \ 32simple-signal-emit.c \
31complex-types-client-eina-value.c \ 33complex-types-client-eina-value.c \
32connect-address.c 34connect-address.c \
35dbusmodel.c
33 36
34EXTRA_PROGRAMS = \ 37EXTRA_PROGRAMS = \
35connman-list-services \ 38connman-list-services \
@@ -41,7 +44,8 @@ server \
41client \ 44client \
42simple-signal-emit \ 45simple-signal-emit \
43complex-types-client-eina-value \ 46complex-types-client-eina-value \
44connect-address 47connect-address \
48dbusmodel
45 49
46connman_list_services_SOURCES = connman-list-services.c 50connman_list_services_SOURCES = connman-list-services.c
47connman_list_services_LDADD = $(EXAMPLES_LIBS) 51connman_list_services_LDADD = $(EXAMPLES_LIBS)
@@ -73,6 +77,9 @@ complex_types_client_eina_value_LDADD = $(EXAMPLES_LIBS)
73connect_address_SOURCES = connect-address.c 77connect_address_SOURCES = connect-address.c
74connect_address_LDADD = $(EXAMPLES_LIBS) 78connect_address_LDADD = $(EXAMPLES_LIBS)
75 79
80dbusmodel_SOURCES = dbusmodel.c
81dbusmodel_LDADD = $(EXAMPLES_LIBS)
82
76DATA_FILES = Makefile.examples 83DATA_FILES = Makefile.examples
77 84
78EXTRA_DIST = $(DATA_FILES) 85EXTRA_DIST = $(DATA_FILES)
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}