summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLarry <larry.olj@gmail.com>2015-12-02 21:20:48 -0200
committerLarry <larry.olj@gmail.com>2015-12-02 21:20:48 -0200
commit96bb8b3eebc83f8a72eb7ea8fd2122bc268d3368 (patch)
treeea81a0558f5d04d6344b975fa9b693e551df3333
parente1261d30b2b147db0bfba86f10ad8bfd37dd910e (diff)
eldbud: added eldbud model examplex
-rw-r--r--src/examples/eldbus/Makefile.am11
-rw-r--r--src/examples/eldbus/dbusmodel.c117
2 files changed, 126 insertions, 2 deletions
diff --git a/src/examples/eldbus/Makefile.am b/src/examples/eldbus/Makefile.am
index d820f1d275..65e6254177 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 0000000000..12ddf82db7
--- /dev/null
+++ b/src/examples/eldbus/dbusmodel.c
@@ -0,0 +1,117 @@
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
23 if (EFL_MODEL_LOAD_STATUS_LOADED != actual_load->status)
24 return EINA_TRUE;
25
26 Eina_Array *properties_list;
27 Eina_Array_Iterator iterator;
28 Eina_Value const* property_value;
29 char *property, *prop_str;
30 const char *name;
31 unsigned int i;
32
33 eo_do(model, name = eldbus_model_proxy_name_get());
34 printf(" -> %s\n", name);
35
36 eo_do(model, efl_model_properties_get(&properties_list));
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 unsigned int i;
67
68 if (EFL_MODEL_LOAD_STATUS_LOADED != actual_load->status)
69 return EINA_TRUE;
70
71 eo_do(model, efl_model_children_count_get(&children_count));
72 if (children_count == 0)
73 {
74 printf("Don't find Interfaces\n");
75 ecore_main_loop_quit();
76 return EINA_FALSE;
77 }
78
79 Eina_Accessor *accessor;
80 Eo *child = NULL;
81
82 eo_do(model, efl_model_children_slice_get(0, 0, &accessor));
83 printf("\nInterfaces:\n");
84 EINA_ACCESSOR_FOREACH(accessor, i, child)
85 {
86 eo_do(child, eo_event_callback_add(EFL_MODEL_BASE_EVENT_LOAD_STATUS, _event_interface_load_status_cb, NULL));
87 eo_do(child, efl_model_load());
88 }
89
90 return EINA_FALSE;
91}
92
93int
94main(int argc, char **argv EINA_UNUSED)
95{
96 const char *bus, *path;
97 eldbus_init();
98
99 bus = DEFAULT_BUS;
100 path = DEFAULT_PATH;
101
102 if (argc > 1) bus = argv[1];
103 if (argc > 2) path = argv[2];
104
105 Eo *root = eo_add_ref(ELDBUS_MODEL_OBJECT_CLASS, NULL,
106 eldbus_model_object_constructor(ELDBUS_CONNECTION_TYPE_SESSION,
107 NULL, EINA_FALSE, bus, path));
108
109 eo_do(root, eo_event_callback_add(EFL_MODEL_BASE_EVENT_LOAD_STATUS, _event_load_status_cb, NULL));
110 eo_do(root, efl_model_load());
111
112 ecore_main_loop_begin();
113
114 eo_do(root, eo_event_callback_del(EFL_MODEL_BASE_EVENT_LOAD_STATUS, _event_load_status_cb, NULL));
115
116 eo_unref(root);
117}