summaryrefslogtreecommitdiff
path: root/src/examples/eldbus
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.demarchi@profusion.mobi>2013-04-23 11:40:05 -0300
committerLucas De Marchi <lucas.demarchi@profusion.mobi>2013-04-23 12:36:29 -0300
commit4e3804041f8e865e007b2a6a0d45a05f39500c3b (patch)
treea493b9c8f8a610d2667651f3ba81819ed16fbe8c /src/examples/eldbus
parent4cf68bf728b5a858ce1c0efac25ded1a49ba8d9d (diff)
Rename edbus->eldbus
git grep -l edbus2 | while read f; do sed -i 's/edbus2/eldbus/g' "$f"; done find . -name '*edbus2*' -exec rename edbus2 eldbus {} \; git grep -l "EDBUS" | while read f; do sed -i 's/EDBUS/ELDBUS/g' "$f"; done git grep -l "EDBus" | while read f; do sed -i 's/EDBus/Eldbus/g' "$f"; done git grep -l "edbus (v2)" | while read f; do sed -i 's/edbus (v2)/eldbus/g' "$f"; done git grep -l "Edbus" | while read f; do sed -i 's/Edbus/Eldbus/g' "$f"; done git grep -l "edbus" | while read f; do sed -i 's/edbus/eldbus/g' "$f"; done find . -name '*edbus*' -exec rename edbus eldbus {} \; find . -name '*EDBus*' -exec rename EDBus Eldbus {} \;
Diffstat (limited to 'src/examples/eldbus')
-rw-r--r--src/examples/eldbus/Makefile.am90
-rw-r--r--src/examples/eldbus/Makefile.examples21
-rw-r--r--src/examples/eldbus/banshee.c241
-rw-r--r--src/examples/eldbus/client.c334
-rw-r--r--src/examples/eldbus/complex-types-client-eina-value.c324
-rw-r--r--src/examples/eldbus/complex-types-server.c393
-rw-r--r--src/examples/eldbus/complex-types.c284
-rw-r--r--src/examples/eldbus/connman-list-services.c110
-rw-r--r--src/examples/eldbus/ofono-dial.c88
-rw-r--r--src/examples/eldbus/server.c247
-rw-r--r--src/examples/eldbus/simple-signal-emit.c86
11 files changed, 2218 insertions, 0 deletions
diff --git a/src/examples/eldbus/Makefile.am b/src/examples/eldbus/Makefile.am
new file mode 100644
index 0000000..8163a42
--- /dev/null
+++ b/src/examples/eldbus/Makefile.am
@@ -0,0 +1,90 @@
1MAINTAINERCLEANFILES = Makefile.in
2
3AM_CPPFLAGS = \
4-I$(top_srcdir)/src/lib/eina \
5-I$(top_srcdir)/src/lib/eo \
6-I$(top_srcdir)/src/lib/ecore \
7-I$(top_srcdir)/src/lib/eldbus \
8-I$(top_builddir)/src/lib/eina \
9-I$(top_builddir)/src/lib/eo \
10-I$(top_builddir)/src/lib/ecore \
11-I$(top_builddir)/src/lib/eldbus \
12@ELDBUS_CFLAGS@
13
14EXAMPLES_LIBS = \
15$(top_builddir)/src/lib/eo/libeo.la \
16$(top_builddir)/src/lib/ecore/libecore.la \
17$(top_builddir)/src/lib/eina/libeina.la \
18$(top_builddir)/src/lib/eldbus/libeldbus.la \
19@ELDBUS_LDFLAGS@
20
21SRCS = \
22connman-list-services.c \
23ofono-dial.c \
24banshee.c \
25complex-types.c \
26complex-types-server.c \
27server.c \
28client.c \
29simple-signal-emit.c \
30complex-types-client-eina-value.c
31
32EXTRA_PROGRAMS = \
33connman-list-services \
34ofono-dial \
35banshee \
36complex-types \
37complex-types-server \
38server \
39client \
40simple-signal-emit \
41complex-types-client-eina-value
42
43connman_list_services_SOURCES = connman-list-services.c
44connman_list_services_LDADD = $(EXAMPLES_LIBS)
45
46ofono_dial_SOURCES = ofono-dial.c
47ofono_dial_LDADD = $(EXAMPLES_LIBS)
48
49banshee_SOURCES = banshee.c
50banshee_LDADD = $(EXAMPLES_LIBS)
51
52complex_types_SOURCES = complex-types.c
53complex_types_LDADD = $(EXAMPLES_LIBS)
54
55complex_types_server_SOURCES = complex-types-server.c
56complex_types_server_LDADD = $(EXAMPLES_LIBS)
57
58server_SOURCES = server.c
59server_LDADD = $(EXAMPLES_LIBS)
60
61client_SOURCES = client.c
62client_LDADD = $(EXAMPLES_LIBS)
63
64simple_signal_emit_SOURCES = simple-signal-emit.c
65simple_signal_emit_LDADD = $(EXAMPLES_LIBS)
66
67complex_types_client_eina_value_SOURCES = complex-types-client-eina-value.c
68complex_types_client_eina_value_LDADD = $(EXAMPLES_LIBS)
69
70DATA_FILES = Makefile.examples
71
72EXTRA_DIST = $(DATA_FILES)
73
74examples: $(EXTRA_PROGRAMS)
75
76clean-local:
77 rm -f $(EXTRA_PROGRAMS)
78
79install-examples:
80 mkdir -p $(datadir)/eldbus/examples
81 $(install_sh_DATA) -c $(SRCS) $(DATA_FILES) $(datadir)/eldbus/examples
82
83uninstall-local:
84 for f in $(SRCS) $(DATA_FILES); do \
85 rm -f $(datadir)/eldbus/examples/$$f ; \
86 done
87
88if ALWAYS_BUILD_EXAMPLES
89noinst_PROGRAMS = $(EXTRA_PROGRAMS)
90endif
diff --git a/src/examples/eldbus/Makefile.examples b/src/examples/eldbus/Makefile.examples
new file mode 100644
index 0000000..32d0d93
--- /dev/null
+++ b/src/examples/eldbus/Makefile.examples
@@ -0,0 +1,21 @@
1CC=gcc
2COMMON_FLAGS=`pkg-config --libs --cflags eina,ecore,eldbus`
3
4EXAMPLES= banshee client \
5 complex-types \
6 complex-types-client-eina-value \
7 complex-types-server \
8 connman-list-services \
9 ofono-dial \
10 server \
11 simple-signal-emit
12
13all: examples
14examples: $(EXAMPLES)
15
16$(EXAMPLES):
17 $(CC) -o $@ $@.c $(COMMON_FLAGS)
18
19clean:
20 @echo "Cleaning up built objects..."
21 @rm -Rf $(EXAMPLES)
diff --git a/src/examples/eldbus/banshee.c b/src/examples/eldbus/banshee.c
new file mode 100644
index 0000000..c9d30b5
--- /dev/null
+++ b/src/examples/eldbus/banshee.c
@@ -0,0 +1,241 @@
1//Compile with:
2// gcc -o banshee banshee.c `pkg-config --cflags --libs eldbus ecore eina`
3
4#include "Eldbus.h"
5#include <Ecore.h>
6
7#define BUS "org.bansheeproject.Banshee"
8#define ENGINE_PATH "/org/bansheeproject/Banshee/PlayerEngine"
9#define CONTROLLER_PATH "/org/bansheeproject/Banshee/PlaybackController"
10#define MPRIS_PATH "/org/mpris/MediaPlayer2"
11
12#define ENGINE_IFACE "org.bansheeproject.Banshee.PlayerEngine"
13#define CONTROLLER_IFACE "org.bansheeproject.Banshee.PlaybackController"
14#define MPRIS_IFACE "org.mpris.MediaPlayer2.Playlists"
15
16static Eldbus_Signal_Handler *state_changed2;
17
18static Eina_Bool
19_timeout_application(void *data EINA_UNUSED)
20{
21 printf("\n## ecore_main_loop_quit()\n");
22 ecore_main_loop_quit();
23 return EINA_TRUE;
24}
25
26static void
27on_get_playlists(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
28{
29 Eldbus_Message_Iter *array, *struct_entry;
30 const char *path, *name, *image;
31 int i = 0;
32
33 EINA_SAFETY_ON_TRUE_RETURN(eldbus_message_error_get(msg, NULL, NULL));
34
35 if (!eldbus_message_arguments_get(msg, "a(oss)", &array))
36 {
37 fprintf(stderr, "Error: could not get entry contents\n");
38 return;
39 }
40 printf("on_get_playlists() \n\n");
41 while (eldbus_message_iter_get_and_next(array, 'r', &struct_entry))
42 {
43 if (!eldbus_message_iter_arguments_get(struct_entry, "oss", &path, &name, &image))
44 {
45 printf("error on eldbus_massage_iterator_arguments_get()");
46 return;
47 }
48 i++;
49 printf("%d - %s | %s | %s\n", i, path, name, image);
50 }
51 printf("end of on_get_playlists()\n\n");
52}
53
54static void
55iterate_dict(void *data EINA_UNUSED, const void *key, Eldbus_Message_Iter *var)
56{
57 const char *skey = key;
58
59 if (!strcmp(skey, "PlaylistCount"))
60 {
61 unsigned count;
62 if (!eldbus_message_iter_arguments_get(var, "u", &count))
63 printf("error2\n");
64 printf("PlaylistCount=%u\n", count);
65 }
66 else if (!strcmp(skey, "Orderings"))
67 {
68 Eldbus_Message_Iter *as;
69 const char *txt;
70 printf("- Orderings\n");
71 if (!eldbus_message_iter_arguments_get(var, "as", &as))
72 printf("error1\n");
73 while (eldbus_message_iter_get_and_next(as, 's', &txt))
74 printf("\t%s\n", txt);
75 }
76}
77
78static void
79playlist_get_all_cb(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
80{
81 Eldbus_Message_Iter *array;
82 EINA_SAFETY_ON_TRUE_RETURN(eldbus_message_error_get(msg, NULL, NULL));
83
84 if (eldbus_message_arguments_get(msg, "a{sv}", &array))
85 eldbus_message_iter_dict_iterate(array, "sv", iterate_dict, NULL);
86}
87
88static void
89on_introspect(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
90{
91 const char *string;
92
93 EINA_SAFETY_ON_TRUE_RETURN(eldbus_message_error_get(msg, NULL, NULL));
94
95 if (!eldbus_message_arguments_get(msg, "s", &string))
96 {
97 fprintf(stderr, "Error: could not get entry contents\n");
98 return;
99 }
100
101 printf("on_introspect() data=\n%s\n\n", string);
102}
103
104static void
105on_next_or_pause(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
106{
107 const char *status = data;
108
109 EINA_SAFETY_ON_TRUE_RETURN(eldbus_message_error_get(msg, NULL, NULL));
110
111 printf("%s\n", status);
112}
113
114static void
115on_state_changed(void *data EINA_UNUSED, const Eldbus_Message *msg)
116{
117 const char *status;
118 EINA_SAFETY_ON_TRUE_RETURN(eldbus_message_error_get(msg, NULL, NULL));
119
120 if (!eldbus_message_arguments_get(msg, "s", &status))
121 {
122 fprintf(stderr, "Error: could not get entry contents\n");
123 return;
124 }
125
126 printf("on_state_changed = %s\n", status);
127}
128
129static void
130on_state_changed2(void *data EINA_UNUSED, const Eldbus_Message *msg)
131{
132 const char *status;
133 EINA_SAFETY_ON_TRUE_RETURN(eldbus_message_error_get(msg, NULL, NULL));
134
135 if (!eldbus_message_arguments_get(msg, "s", &status))
136 {
137 fprintf(stderr, "Error: could not get entry contents\n");
138 return;
139 }
140
141 printf("on_state_changed2 = %s\n", status);
142 eldbus_signal_handler_unref(state_changed2);
143 state_changed2 = NULL;
144}
145
146static void
147on_banshee_startup(void *data EINA_UNUSED, const Eldbus_Message *msg)
148{
149 const char *bus, *older_id, *new_id;
150
151 EINA_SAFETY_ON_TRUE_RETURN(eldbus_message_error_get(msg, NULL, NULL));
152 if (!eldbus_message_arguments_get(msg, "sss", &bus, &older_id, &new_id))
153 {
154 printf("Error getting arguments from NameOwnerChanged");
155 return;
156 }
157
158 printf("banshee started on id=%s\n", new_id);
159}
160
161static void
162on_name_owner_changed(void *data EINA_UNUSED, const Eldbus_Message *msg)
163{
164 const char *bus, *older_id, *new_id;
165
166 EINA_SAFETY_ON_TRUE_RETURN(eldbus_message_error_get(msg, NULL, NULL));
167 if (!eldbus_message_arguments_get(msg, "sss", &bus, &older_id, &new_id))
168 {
169 printf("Error getting arguments from NameOwnerChanged");
170 return;
171 }
172
173 printf("bus = %s older=%s new=%s\n\n", bus, older_id, new_id);
174}
175
176int
177main(void)
178{
179 Eldbus_Connection *conn;
180 Eldbus_Object *engine_obj, *controller_obj, *mpris_obj;
181 Eldbus_Proxy *engine, *controler, *playlists;
182 Eldbus_Signal_Handler *sh;
183
184 ecore_init();
185 eldbus_init();
186
187 conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SESSION);
188
189 engine_obj = eldbus_object_get(conn, BUS, ENGINE_PATH);
190 controller_obj = eldbus_object_get(conn, BUS, CONTROLLER_PATH);
191 mpris_obj = eldbus_object_get(conn, BUS, MPRIS_PATH);
192
193 engine = eldbus_proxy_get(engine_obj, ENGINE_IFACE);
194 EINA_SAFETY_ON_NULL_GOTO(engine, end);
195 controler = eldbus_proxy_get(controller_obj, CONTROLLER_IFACE);
196 EINA_SAFETY_ON_NULL_GOTO(controler, end);
197 playlists = eldbus_proxy_get(mpris_obj, MPRIS_IFACE);
198 EINA_SAFETY_ON_NULL_GOTO(playlists, end);
199
200 eldbus_object_introspect(engine_obj, on_introspect, NULL);
201
202 eldbus_proxy_signal_handler_add(engine, "StateChanged", on_state_changed, NULL);
203 eldbus_proxy_call(engine, "Pause", on_next_or_pause, "Pause", -1, "");
204
205 eldbus_proxy_call(controler, "Next", on_next_or_pause, "Next", -1, "b", EINA_TRUE);
206
207 eldbus_proxy_property_get_all(playlists, playlist_get_all_cb, NULL);
208 eldbus_proxy_call(playlists, "GetPlaylists", on_get_playlists, NULL, -1,
209 "uusb", (unsigned)0, (unsigned)30, "asc", EINA_FALSE);
210
211 eldbus_signal_handler_add(conn, BUS, ENGINE_PATH, ENGINE_IFACE,
212 "StateChanged", on_state_changed, NULL);
213 state_changed2 = eldbus_signal_handler_add(conn, BUS, ENGINE_PATH, ENGINE_IFACE,
214 "StateChanged", on_state_changed2, NULL);
215
216 sh = eldbus_signal_handler_add(conn, ELDBUS_FDO_BUS, ELDBUS_FDO_PATH,
217 ELDBUS_FDO_INTERFACE, "NameOwnerChanged",
218 on_name_owner_changed, NULL);
219 eldbus_signal_handler_match_extra_set(sh, "arg0", BUS, NULL);
220
221 sh = eldbus_signal_handler_add(conn, ELDBUS_FDO_BUS, ELDBUS_FDO_PATH,
222 ELDBUS_FDO_INTERFACE, "NameOwnerChanged",
223 on_banshee_startup, NULL);
224 eldbus_signal_handler_match_extra_set(sh, "arg0", BUS, "arg1", "", NULL);
225
226 ecore_timer_add(50, _timeout_application, NULL);
227
228 ecore_main_loop_begin();
229
230end:
231 /**
232 * It's not necessary unref all objecs, proxys and signal handlers
233 * When a parent have ref = 0, it will unref all your childrens
234 * before free it self.
235 **/
236 eldbus_connection_unref(conn);
237
238 eldbus_shutdown();
239 ecore_shutdown();
240 return 0;
241}
diff --git a/src/examples/eldbus/client.c b/src/examples/eldbus/client.c
new file mode 100644
index 0000000..18a1fcd
--- /dev/null
+++ b/src/examples/eldbus/client.c
@@ -0,0 +1,334 @@
1//Compile with:
2// gcc -o client client.c `pkg-config --cflags --libs eldbus ecore eina`
3
4#include "Eldbus.h"
5#include <Ecore.h>
6
7#define BUS "org.Enlightenment"
8#define PATH "/org/enlightenment"
9#define INTERFACE "org.enlightenment.Test"
10#define NTESTS 8
11
12static int _client_log_dom = -1;
13#define ERR(...) EINA_LOG_DOM_ERR(_client_log_dom, __VA_ARGS__)
14
15static void
16_on_alive(void *context EINA_UNUSED, const Eldbus_Message *msg EINA_UNUSED)
17{
18 printf("Alive\n\n");
19}
20
21static void
22_on_hello(void *context EINA_UNUSED, const Eldbus_Message *msg)
23{
24 const char *txt;
25 if (eldbus_message_arguments_get(msg, "s", &txt))
26 printf("%s\n", txt);
27}
28
29#include <inttypes.h>
30
31static struct expected
32{
33 Eina_Bool b;
34 uint8_t y;
35 uint32_t u;
36 int32_t i;
37 int16_t n;
38 double d;
39 const char *s;
40} expected = {
41 .b = EINA_TRUE,
42 .y = 0xAA,
43 .u = 0xFFFFFFFF,
44 .i = 0xFFFFFFFF,
45 .n = 0xFFFF,
46 .d = 3.1415926,
47 .s = "test",
48};
49
50static void
51test(void)
52{
53 static int n = 0;
54 n++;
55 if (n >= NTESTS)
56 printf("Passed in all tests\n");
57 else
58 printf("Passed in %d/%d tests\n", n, NTESTS);
59}
60
61static void
62_on_send_bool(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
63{
64 const char *errname, *errmsg;
65 Eina_Bool b;
66
67 if (eldbus_message_error_get(msg, &errname, &errmsg))
68 {
69 ERR("%s %s", errname, errmsg);
70 return;
71 }
72
73 if (!eldbus_message_arguments_get(msg, "b", &b))
74 {
75 ERR("Could not get entry contents");
76 return;
77 }
78
79 if (b != expected.b)
80 {
81 ERR("Bool value doesn't match");
82 return;
83 }
84
85 test();
86}
87
88static void
89_on_send_byte(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
90{
91 const char *errname, *errmsg;
92 uint8_t y;
93
94 if (eldbus_message_error_get(msg, &errname, &errmsg))
95 {
96 ERR("%s %s", errname, errmsg);
97 return;
98 }
99
100 if (!eldbus_message_arguments_get(msg, "y", &y))
101 {
102 ERR("Could not get entry contents");
103 return;
104 }
105
106 if (y != expected.y)
107 {
108 ERR("Byte value doesn't match expected value");
109 return;
110 }
111
112 test();
113}
114
115static void
116_on_send_uint32(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
117{
118 const char *errname, *errmsg;
119 unsigned int u;
120
121 if (eldbus_message_error_get(msg, &errname, &errmsg))
122 {
123 ERR("%s %s", errname, errmsg);
124 return;
125 }
126
127 if (!eldbus_message_arguments_get(msg, "u", &u))
128 {
129 ERR("Could not get entry contents");
130 return;
131 }
132
133 if (u != expected.u)
134 {
135 ERR("Uint32 value doesn't match expected value");
136 return;
137 }
138
139 test();
140}
141
142static void
143_on_send_int32(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
144{
145 const char *errname, *errmsg;
146 int32_t i;
147
148 if (eldbus_message_error_get(msg, &errname, &errmsg))
149 {
150 ERR("%s %s", errname, errmsg);
151 return;
152 }
153
154 if (!eldbus_message_arguments_get(msg, "i", &i))
155 {
156 ERR("Could not get entry contents");
157 return;
158 }
159
160 if (i != expected.i)
161 {
162 ERR("Int32 value doesn't match expected value");
163 return;
164 }
165
166 test();
167}
168
169static void
170_on_send_int16(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
171{
172 const char *errname, *errmsg;
173 int16_t n;
174
175 if (eldbus_message_error_get(msg, &errname, &errmsg))
176 {
177 ERR("%s %s", errname, errmsg);
178 return;
179 }
180
181 if (!eldbus_message_arguments_get(msg, "n", &n))
182 {
183 ERR("Could not get entry contents");
184 return;
185 }
186
187 if (n != expected.n)
188 {
189 ERR("Int16 value doesn't match expected value");
190 return;
191 }
192
193 test();
194}
195
196static void
197_on_send_double(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
198{
199 const char *errname, *errmsg;
200 double d;
201
202 if (eldbus_message_error_get(msg, &errname, &errmsg))
203 {
204 ERR("%s %s", errname, errmsg);
205 return;
206 }
207
208 if (!eldbus_message_arguments_get(msg, "d", &d))
209 {
210 ERR("Could not get entry contents");
211 return;
212 }
213
214 if (d != expected.d)
215 {
216 ERR("Double value doesn't match expected value");
217 return;
218 }
219
220 test();
221}
222
223static void
224_on_send_string(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
225{
226 const char *errname, *errmsg;
227 char *s;
228
229 if (eldbus_message_error_get(msg, &errname, &errmsg))
230 {
231 ERR("%s %s", errname, errmsg);
232 return;
233 }
234
235 if (!eldbus_message_arguments_get(msg, "s", &s))
236 {
237 ERR("Could not get entry contents");
238 return;
239 }
240
241 if (strcmp(s, expected.s) != 0)
242 {
243 ERR("Uint32 value doesn't match expected value");
244 return;
245 }
246
247 test();
248}
249
250static void
251_on_async_test(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
252{
253 const char *errname, *errmsg;
254
255 if (eldbus_message_error_get(msg, &errname, &errmsg))
256 {
257 ERR("%s %s", errname, errmsg);
258 return;
259 }
260
261 test();
262}
263
264static void
265on_name_owner_changed(void *data EINA_UNUSED, const char *bus, const char *old_id, const char *new_id EINA_UNUSED)
266{
267 printf("Bus=%s | old=%s | new=%s\n", bus, old_id, new_id);
268}
269
270static Eina_Bool
271finish(void *data EINA_UNUSED)
272{
273 ecore_main_loop_quit();
274 return ECORE_CALLBACK_CANCEL;
275}
276
277int
278main(void)
279{
280 Eldbus_Connection *conn;
281 Eldbus_Object *obj;
282 Eldbus_Proxy *proxy;
283
284 eina_init();
285 _client_log_dom = eina_log_domain_register("client", EINA_COLOR_CYAN);
286 if (_client_log_dom < 0)
287 {
288 EINA_LOG_ERR("Unable to create 'client' log domain");
289 goto exit_eina;
290 }
291
292 ecore_init();
293 eldbus_init();
294
295 conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SESSION);
296
297 obj = eldbus_object_get(conn, BUS, PATH);
298 proxy = eldbus_proxy_get(obj, INTERFACE);
299 eldbus_proxy_signal_handler_add(proxy, "Alive", _on_alive, NULL);
300 eldbus_proxy_signal_handler_add(proxy, "Hello", _on_hello, NULL);
301
302 eldbus_proxy_call(proxy, "SendBool", _on_send_bool, NULL, -1, "b",
303 expected.b);
304 eldbus_proxy_call(proxy, "SendByte", _on_send_byte, NULL, -1, "y",
305 expected.y);
306 eldbus_proxy_call(proxy, "SendUint32", _on_send_uint32, NULL, -1, "u",
307 expected.u);
308 eldbus_proxy_call(proxy, "SendInt32", _on_send_int32, NULL, -1, "i",
309 expected.i);
310 eldbus_proxy_call(proxy, "SendInt16", _on_send_int16, NULL, -1, "n",
311 expected.n);
312 eldbus_proxy_call(proxy, "SendDouble", _on_send_double, NULL, -1, "d",
313 expected.d);
314 eldbus_proxy_call(proxy, "SendString", _on_send_string, NULL, -1, "s",
315 expected.s);
316 eldbus_proxy_call(proxy, "AsyncTest", _on_async_test, NULL, -1, "");
317
318 eldbus_name_owner_changed_callback_add(conn, BUS, on_name_owner_changed,
319 conn, EINA_TRUE);
320 ecore_timer_add(30, finish, NULL);
321
322 ecore_main_loop_begin();
323
324 eldbus_connection_unref(conn);
325
326 eldbus_shutdown();
327 ecore_shutdown();
328
329 eina_log_domain_unregister(_client_log_dom);
330exit_eina:
331 eina_shutdown();
332
333 return 0;
334}
diff --git a/src/examples/eldbus/complex-types-client-eina-value.c b/src/examples/eldbus/complex-types-client-eina-value.c
new file mode 100644
index 0000000..3d290ae
--- /dev/null
+++ b/src/examples/eldbus/complex-types-client-eina-value.c
@@ -0,0 +1,324 @@
1//Compile with:
2// gcc -o complex-types-client-eina-value complex-types-client-eina-value.c `pkg-config --cflags --libs eldbus ecore eina`
3
4#include "Eldbus.h"
5#include <Ecore.h>
6
7#define BUS "com.profusion"
8#define PATH "/com/profusion/Test"
9#define IFACE "com.profusion.Test"
10
11#define size_of_array 5
12static const char *array_string[] = {
13 "aaaa", "bbbb", "cccc", "dddd", "eeee"
14};
15
16typedef struct _sub_struct
17{
18 char *txt;
19 int num;
20} sub_struct;
21
22typedef struct _main_struct
23{
24 int size;
25 sub_struct array[];
26} main_struct;
27
28static unsigned int
29_type_offset(unsigned base, unsigned size)
30{
31 unsigned padding;
32 if (!(base % size))
33 return base;
34 padding = abs(base - size);
35 return base + padding;
36}
37
38static void
39_fill_receive_array_of_string_int_with_size(Eldbus_Message *msg, int size, const char *array[])
40{
41 Eina_Value *value_struct, *value_array;
42 int i;
43 unsigned offset;
44 Eina_Value_Struct_Member main_members[2];
45 Eina_Value_Struct_Member sub_members[] = {
46 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_STRING, sub_struct, txt),
47 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, sub_struct, num)
48 };
49 Eina_Value_Struct_Desc desc_sub_struct = {
50 EINA_VALUE_STRUCT_DESC_VERSION,
51 NULL, // no special operations
52 sub_members,
53 2,
54 sizeof(sub_struct)
55 };
56 Eina_Value_Struct_Desc desc_struct = {
57 EINA_VALUE_STRUCT_DESC_VERSION,
58 NULL, // no special operations
59 main_members,
60 2,
61 0//will be set below
62 };
63
64 offset = _type_offset(sizeof(int), sizeof(Eina_Value_Array));
65 main_members[0].name = "size";
66 main_members[0].type = EINA_VALUE_TYPE_INT, 0;
67 main_members[0].offset = 0;
68 main_members[1].name = "array";
69 main_members[1].type = EINA_VALUE_TYPE_ARRAY;
70 main_members[1].offset = offset;
71 desc_struct.size = offset + sizeof(Eina_Value_Array);
72
73 value_struct = eina_value_struct_new(&desc_struct);
74 eina_value_struct_set(value_struct, "size", size);
75
76 value_array = eina_value_array_new(EINA_VALUE_TYPE_STRUCT, size);
77 for (i = 0; i < size; i++)
78 {
79 Eina_Value *value_sub_struct = eina_value_struct_new(&desc_sub_struct);
80 Eina_Value_Struct st;
81 eina_value_struct_set(value_sub_struct, "txt", array[i]);
82 eina_value_struct_set(value_sub_struct, "num", i);
83 eina_value_get(value_sub_struct, &st);
84 eina_value_array_append(value_array, st);
85 eina_value_free(value_sub_struct);
86 }
87 eina_value_struct_value_set(value_struct, "array", value_array);
88
89 eldbus_message_from_eina_value("ia(si)", msg, value_struct);
90
91 eina_value_free(value_struct);
92 eina_value_free(value_array);
93}
94
95static void
96on_send_array(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
97{
98 Eina_Value *v, array;
99 const char *txt;
100 unsigned i;
101 printf("2 - on_send_array()\n");
102
103 if (eldbus_message_error_get(msg, NULL, NULL))
104 {
105 printf("Message error\n\n");
106 return;
107 }
108
109 v = eldbus_message_to_eina_value(msg);
110 eina_value_struct_value_get(v, "arg0", &array);
111 for (i = 0; i < eina_value_array_count(&array); i++)
112 {
113 eina_value_array_get(&array, i, &txt);
114 printf("\t%s\n", txt);
115 }
116
117 eina_value_free(v);
118 eina_value_flush(&array);
119}
120
121static void
122on_receive_array_with_size(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
123{
124 const char *errname;
125 const char *errmsg;
126
127 printf("1 - on_receive_array_with_size()\n");
128 if (eldbus_message_error_get(msg, &errname, &errmsg))
129 {
130 fprintf(stderr, "Error: %s %s\n", errname, errmsg);
131 }
132}
133
134static void
135on_plus_one(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
136{
137 Eina_Value *v;
138 int num2;
139
140 if (eldbus_message_error_get(msg, NULL, NULL))
141 {
142 printf("Message error\n\n");
143 return;
144 }
145
146 v = eldbus_message_to_eina_value(msg);
147 eina_value_struct_get(v, "arg0", &num2);
148
149 printf("3 - on_plus_one() %d\n", num2);
150 eina_value_free(v);
151}
152
153static void
154receive_variant_cb(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
155{
156 Eina_Value *v, variant, array;
157 unsigned i;
158
159 printf("4 - receive a variant with an array of strings\n");
160 if (eldbus_message_error_get(msg, NULL, NULL))
161 {
162 printf("Message error\n\n");
163 return;
164 }
165
166 v = eldbus_message_to_eina_value(msg);
167
168 eina_value_struct_value_get(v, "arg0", &variant);
169 eina_value_struct_value_get(&variant, "arg0", &array);
170 for (i = 0; i < eina_value_array_count(&array); i++)
171 {
172 const char *txt;
173 eina_value_array_get(&array, i, &txt);
174 printf("\t%s\n", txt);
175 }
176
177 eina_value_flush(&array);
178 eina_value_flush(&variant);
179 eina_value_free(v);
180}
181
182static void
183_property_removed(void *data EINA_UNUSED, Eldbus_Proxy *proxy EINA_UNUSED, void *event_info)
184{
185 Eldbus_Proxy_Event_Property_Removed *event = event_info;
186
187 printf("\nproperty removed: %s", event->name);
188}
189
190static void
191_property_changed(void *data EINA_UNUSED, Eldbus_Proxy *proxy EINA_UNUSED, void *event_info)
192{
193 Eldbus_Proxy_Event_Property_Changed *event = event_info;
194 const char *name;
195 const Eina_Value *value;
196 printf("\nproperty changed\n");
197
198 name = event->name;
199 value = event->value;
200
201 if (!strcmp(name, "text") || !strcmp(name, "Resp2"))
202 {
203 const char *txt;
204 eina_value_get(value, &txt);
205 printf("[%s] = %s\n", name, txt);
206 }
207 else if (!strcmp(name, "int32"))
208 {
209 int num;
210 eina_value_get(value, &num);
211 printf("[%s] = %d\n", name, num);
212 }
213 else if (!strcmp(name, "st"))
214 {
215 const char *txt;
216 eina_value_struct_get(value, "arg0", &txt);
217 printf("[%s] %s | ", name, txt);
218 eina_value_struct_get(value, "arg1", &txt);
219 printf("%s\n", txt);
220 }
221}
222
223static Eina_Bool
224_read_cache(void *data)
225{
226 Eldbus_Proxy *proxy = data;
227 const char *txt;
228 int num;
229 Eina_Value *v;
230
231 v = eldbus_proxy_property_local_get(proxy, "text");
232 if (v)
233 {
234 eina_value_get(v, &txt);
235 printf("Read cache: [txt] = %s\n", txt);
236 }
237
238 v = eldbus_proxy_property_local_get(proxy, "int32");
239 if (v)
240 {
241 eina_value_get(v, &num);
242 printf("Read cache: [int32] = %d\n", num);
243 }
244
245 v = eldbus_proxy_property_local_get(proxy, "st");
246 if (v)
247 {
248 eina_value_struct_get(v, "arg0", &txt);
249 printf("Read cache: [st] %s | ", txt);
250 eina_value_struct_get(v, "arg1", &txt);
251 printf("%s\n", txt);
252 }
253
254 return EINA_FALSE;
255}
256
257static void
258_fill_plus_one(Eldbus_Message *msg, int num)
259{
260 Eina_Value *v;
261 Eina_Value_Struct_Member main_members[] = {
262 {"num", EINA_VALUE_TYPE_INT, 0}
263 };
264 Eina_Value_Struct_Desc desc_struct = {
265 EINA_VALUE_STRUCT_DESC_VERSION,
266 NULL, // no special operations
267 main_members,
268 1,
269 sizeof(int)
270 };
271 v = eina_value_struct_new(&desc_struct);
272 eina_value_struct_set(v, "num", num);
273
274 eldbus_message_from_eina_value("i", msg, v);
275
276 eina_value_free(v);
277}
278
279int
280main(void)
281{
282 Eldbus_Connection *conn;
283 Eldbus_Object *obj;
284 Eldbus_Proxy *proxy;
285 Eldbus_Message *msg;
286
287 ecore_init();
288 eldbus_init();
289
290 conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SESSION);
291 obj = eldbus_object_get(conn, BUS, PATH);
292 proxy = eldbus_proxy_get(obj, IFACE);
293
294 msg = eldbus_proxy_method_call_new(proxy, "ReceiveArrayOfStringIntWithSize");
295 _fill_receive_array_of_string_int_with_size(msg, size_of_array, array_string);
296 eldbus_proxy_send(proxy, msg, on_receive_array_with_size, NULL, -1);
297
298 eldbus_proxy_call(proxy, "SendArray", on_send_array, NULL, -1 , "");
299
300 msg = eldbus_proxy_method_call_new(proxy, "PlusOne");
301 _fill_plus_one(msg, 14);
302 eldbus_proxy_send(proxy, msg, on_plus_one, NULL, -1);
303
304 eldbus_proxy_event_callback_add(proxy,
305 ELDBUS_PROXY_EVENT_PROPERTY_CHANGED,
306 _property_changed, NULL);
307 eldbus_proxy_event_callback_add(proxy, ELDBUS_PROXY_EVENT_PROPERTY_REMOVED,
308 _property_removed, NULL);
309
310 eldbus_proxy_properties_monitor(proxy, EINA_TRUE);
311 ecore_timer_add(10, _read_cache, proxy);
312
313 eldbus_proxy_call(proxy, "ReceiveVariantData", receive_variant_cb, NULL, -1, "");
314
315 ecore_main_loop_begin();
316
317 eldbus_proxy_event_callback_del(proxy, ELDBUS_PROXY_EVENT_PROPERTY_CHANGED,
318 _property_changed, NULL);
319 eldbus_connection_unref(conn);
320
321 eldbus_shutdown();
322 ecore_shutdown();
323 return 0;
324}
diff --git a/src/examples/eldbus/complex-types-server.c b/src/examples/eldbus/complex-types-server.c
new file mode 100644
index 0000000..125fef8
--- /dev/null
+++ b/src/examples/eldbus/complex-types-server.c
@@ -0,0 +1,393 @@
1//Compile with:
2// gcc -o complex-types-server complex-types-server.c `pkg-config --cflags --libs eldbus ecore`
3
4#include "Eldbus.h"
5#include <Ecore.h>
6
7#define BUS "com.profusion"
8#define PATH "/com/profusion/Test"
9#define IFACE "com.profusion.Test"
10
11static char *resp2;
12/* dummy, incremented each time DBus.Properties.Get() is called */
13static int int32 = 35;
14static Ecore_Timer *timer;
15
16static Eldbus_Message *
17_receive_array(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
18{
19 Eldbus_Message *reply = eldbus_message_method_return_new(msg);
20 Eldbus_Message_Iter *array;
21 const char *txt;
22
23 printf("- receiveArray\n");
24 if (!eldbus_message_arguments_get(msg, "as", &array))
25 {
26 printf("Error on eldbus_message_arguments_get()\n");
27 return reply;
28 }
29
30 while (eldbus_message_iter_get_and_next(array, 's', &txt))
31 printf("%s\n", txt);
32 printf("}\n\n");
33
34 return reply;
35}
36
37static Eldbus_Message *
38_receive_array_of_string_int_with_size(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
39{
40 Eldbus_Message *reply = eldbus_message_method_return_new(msg);
41 Eldbus_Message_Iter *array, *struct_si;
42 int size, i = 0;
43
44 printf("- receiveArrayOfStringIntWithSize\n{\n");
45 if (!eldbus_message_arguments_get(msg, "ia(si)", &size, &array))
46 {
47 printf("Error on eldbus_message_arguments_get()\n");
48 return reply;
49 }
50
51 while (eldbus_message_iter_get_and_next(array, 'r', &struct_si))
52 {
53 const char *txt;
54 int num;
55 if (!eldbus_message_iter_arguments_get(struct_si, "si", &txt, &num))
56 {
57 printf("Error on eldbus_message_arguments_get()\n");
58 return reply;
59 }
60 printf("%s | %d\n", txt, num);
61 i++;
62 }
63 printf("size in msg %d | size read %d\n", size, i);
64 printf("}\n\n");
65
66 return reply;
67}
68
69static Eldbus_Message *
70_receive_variant(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
71{
72 Eldbus_Message *reply = eldbus_message_method_return_new(msg);
73 Eldbus_Message_Iter *var, *array, *main_iter;
74
75 main_iter = eldbus_message_iter_get(reply);
76 var = eldbus_message_iter_container_new(main_iter, 'v', "as");
77 eldbus_message_iter_arguments_append(var, "as", &array);
78
79 eldbus_message_iter_arguments_append(array, "s", "item1");
80 eldbus_message_iter_arguments_append(array, "s", "item2");
81 eldbus_message_iter_arguments_append(array, "s", "item3");
82
83 eldbus_message_iter_container_close(var, array);
84 eldbus_message_iter_container_close(main_iter, var);
85
86 return reply;
87}
88
89static Eldbus_Message *
90_send_variant(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
91{
92 Eldbus_Message *reply = eldbus_message_method_return_new(msg);
93 Eldbus_Message_Iter *variant;
94 char *type;
95
96 printf("- sendVariantData\n{\n");
97 if (!eldbus_message_arguments_get(msg, "v", &variant))
98 {
99 printf("Error on eldbus_message_arguments_get()\n");
100 return reply;
101 }
102
103 type = eldbus_message_iter_signature_get(variant);
104 if (type[1])
105 {
106 printf("It is a complex type, not handle yet.\n");
107 free(type);
108 return reply;
109 }
110
111 switch (type[0])
112 {
113 case 's':
114 case 'o':
115 {
116 char *txt;
117 eldbus_message_iter_arguments_get(variant, type, &txt);
118 printf("type = %c value = %s\n", type[0], txt);
119 break;
120 }
121 case 'i':
122 {
123 int num;
124 eldbus_message_iter_arguments_get(variant, type, &num);
125 printf("type = %c value = %d\n", type[0], num);
126 break;
127 }
128 default:
129 {
130 printf("Unhandled type\n");
131 }
132 }
133
134 printf("}\n\n");
135
136 free(type);
137 return reply;
138}
139
140static Eldbus_Message *
141_send_array_int(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
142{
143 Eldbus_Message *reply = eldbus_message_method_return_new(msg);
144 Eldbus_Message_Iter *iter, *array;
145 int i;
146
147 printf("- sendArrayInt\n\n");
148
149 iter = eldbus_message_iter_get(reply);
150 array = eldbus_message_iter_container_new(iter, 'a', "i");
151 for (i = 0; i < 5; i++)
152 eldbus_message_iter_arguments_append(array, "i", i);
153 eldbus_message_iter_container_close(iter, array);
154
155 return reply;
156}
157
158static Eldbus_Message *
159_send_array(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
160{
161 Eldbus_Message *reply = eldbus_message_method_return_new(msg);
162 Eldbus_Message_Iter *iter, *array;
163 const char *array_string[5] = {"qqqq", "wwwww", "eeeeee", "rrrrr", "ttttt"};
164 int i;
165
166 printf("sendArray\n\n");
167
168 iter = eldbus_message_iter_get(reply);
169 array = eldbus_message_iter_container_new(iter, 'a', "s");
170 for (i = 0; i < 5; i++)
171 eldbus_message_iter_arguments_append(array, "s", array_string[i]);
172 eldbus_message_iter_container_close(iter, array);
173
174 return reply;
175}
176
177static Eldbus_Message *
178_plus_one(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
179{
180 Eldbus_Message *reply = eldbus_message_method_return_new(msg);
181 int num;
182
183 printf("- plusOne\n\n");
184 if (!eldbus_message_arguments_get(msg, "i", &num))
185 {
186 printf("Error on eldbus_message_arguments_get()\n");
187 return reply;
188 }
189 num++;
190 eldbus_message_arguments_append(reply, "i", num);
191
192 return reply;
193}
194
195static Eldbus_Message *
196_double_container(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
197{
198 Eldbus_Message_Iter *array1, *array2, *structure;
199 int num1, num2;
200 Eldbus_Message *reply = eldbus_message_method_return_new(msg);
201
202 if (!eldbus_message_arguments_get(msg, "a(ii)a(ii)", &array1, &array2))
203 {
204 printf("Error on eldbus_message_arguments_get()\n");
205 return NULL;
206 }
207
208 printf("DoubleCountainer\n{\nArray1:\n");
209 while (eldbus_message_iter_get_and_next(array1, 'r', &structure))
210 {
211 eldbus_message_iter_arguments_get(structure, "ii", &num1, &num2);
212 printf("1 %d - 2 %d\n", num1, num2);
213 }
214
215 printf("Array2:\n");
216 while (eldbus_message_iter_get_and_next(array2, 'r', &structure))
217 {
218 eldbus_message_iter_arguments_get(structure, "ii", &num1, &num2);
219 printf("1 %d - 2 %d\n", num1, num2);
220 }
221 printf("}\n\n");
222 return reply;
223}
224
225static Eina_Bool
226_properties_get(const Eldbus_Service_Interface *iface EINA_UNUSED, const char *propname, Eldbus_Message_Iter *iter, const Eldbus_Message *request_msg EINA_UNUSED, Eldbus_Message **error EINA_UNUSED)
227{
228 printf("Properties_get - %s\n", propname);
229 if (!strcmp(propname, "Resp2"))
230 eldbus_message_iter_basic_append(iter, 's', resp2);
231 else if (!strcmp(propname, "text"))
232 eldbus_message_iter_basic_append(iter, 's', "lalalala");
233 else if (!strcmp(propname, "int32"))
234 {
235 eldbus_message_iter_arguments_append(iter, "i", int32);
236 int32++;
237 }
238 else if (!strcmp(propname, "st"))
239 {
240 Eldbus_Message_Iter *st;
241 eldbus_message_iter_arguments_append(iter, "(ss)", &st);
242 eldbus_message_iter_arguments_append(st, "ss", "string1", "string2");
243 eldbus_message_iter_container_close(iter, st);
244 }
245 return EINA_TRUE;
246}
247
248static Eldbus_Message *
249_properties_set(const Eldbus_Service_Interface *iface EINA_UNUSED, const char *propname, Eldbus_Message_Iter *iter, const Eldbus_Message *msg)
250{
251 char *type;
252
253 type = eldbus_message_iter_signature_get(iter);
254
255 if (!strcmp(propname, "int32"))
256 {
257 int num;
258 if (type[0] != 'i')
259 goto invalid_signature;
260 eldbus_message_iter_arguments_get(iter, "i", &num);
261 printf("int32 was set to: %d, previously was: %d\n", num, int32);
262 int32 = num;
263 }
264 else if (!strcmp(propname, "Resp2"))
265 {
266 const char *txt;
267 if (type[0] != 's')
268 goto invalid_signature;
269 eldbus_message_iter_arguments_get(iter, "s", &txt);
270 printf("Resp2 was set to: %s, previously was: %s\n", txt, resp2);
271 free(resp2);
272 resp2 = strdup(txt);
273 }
274 free(type);
275 return eldbus_message_method_return_new(msg);
276
277invalid_signature:
278 free(type);
279 return eldbus_message_error_new(msg, "org.freedesktop.DBus.Error.InvalidSignature",
280 "Invalid type.");
281}
282
283static const Eldbus_Method methods[] = {
284 {
285 "ReceiveArray", ELDBUS_ARGS({"as", "array_of_strings"}),
286 NULL, _receive_array
287 },
288 {
289 "ReceiveArrayOfStringIntWithSize",
290 ELDBUS_ARGS({"i", "size_of_array"}, {"a(si)", "array"}),
291 NULL, _receive_array_of_string_int_with_size, 0
292 },
293 {
294 "SendVariantData", ELDBUS_ARGS({"v", "variant_data"}),
295 NULL, _send_variant
296 },
297 {
298 "ReceiveVariantData", NULL, ELDBUS_ARGS({"v", "variant_data"}),
299 _receive_variant
300 },
301 {
302 "SendArrayInt", NULL,
303 ELDBUS_ARGS({"ai", "array_of_int"}), _send_array_int, 0
304 },
305 {
306 "SendArray", NULL, ELDBUS_ARGS({"as", "array_string"}),
307 _send_array
308 },
309 {
310 "PlusOne", ELDBUS_ARGS({"i", "integer"}),
311 ELDBUS_ARGS({"i", "integer_plus_one"}), _plus_one
312 },
313 {
314 "DoubleContainner", ELDBUS_ARGS({"a(ii)", "array1"}, {"a(ii)", "array2"}),
315 NULL, _double_container
316 },
317 { }
318};
319
320static const Eldbus_Property properties[] = {
321 { "Resp2", "s", NULL, _properties_set },
322 { "text", "s" },
323 { "int32", "i", NULL, _properties_set },
324 { "st", "(ss)" },
325 { }
326};
327
328static const Eldbus_Service_Interface_Desc iface_desc = {
329 IFACE, methods, NULL, properties, _properties_get
330};
331
332static Eina_Bool _emit_changed(void *data)
333{
334 Eldbus_Service_Interface *iface = data;
335 eldbus_service_property_changed(iface, "int32");
336 eldbus_service_property_invalidate_set(iface, "Resp2", EINA_TRUE);
337 return ECORE_CALLBACK_RENEW;
338}
339
340static void
341on_name_request(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
342{
343 unsigned int reply;
344 Eldbus_Service_Interface *iface = data;
345
346 if (eldbus_message_error_get(msg, NULL, NULL))
347 {
348 printf("error on on_name_request\n");
349 return;
350 }
351
352 if (!eldbus_message_arguments_get(msg, "u", &reply))
353 {
354 printf("error geting arguments on on_name_request\n");
355 return;
356 }
357
358 if (reply != ELDBUS_NAME_REQUEST_REPLY_PRIMARY_OWNER)
359 {
360 printf("error name already in use\n");
361 return;
362 }
363
364 timer = ecore_timer_add(3, _emit_changed, iface);
365}
366
367int
368main(void)
369{
370 Eldbus_Connection *conn;
371 Eldbus_Service_Interface *iface;
372
373 ecore_init();
374 eldbus_init();
375
376 conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SESSION);
377
378 resp2 = malloc(sizeof(char) * 5);
379 strcpy(resp2, "test");
380 iface = eldbus_service_interface_register(conn, PATH, &iface_desc);
381 eldbus_name_request(conn, BUS, ELDBUS_NAME_REQUEST_FLAG_DO_NOT_QUEUE,
382 on_name_request, iface);
383
384 ecore_main_loop_begin();
385
386 free(resp2);
387 ecore_timer_del(timer);
388 eldbus_connection_unref(conn);
389
390 eldbus_shutdown();
391 ecore_shutdown();
392 return 0;
393}
diff --git a/src/examples/eldbus/complex-types.c b/src/examples/eldbus/complex-types.c
new file mode 100644
index 0000000..fc0063a
--- /dev/null
+++ b/src/examples/eldbus/complex-types.c
@@ -0,0 +1,284 @@
1//Compile with:
2// gcc -o complex-types complex-types.c `pkg-config --cflags --libs eldbus ecore`
3
4#include "Eldbus.h"
5#include <Ecore.h>
6
7#define BUS "com.profusion"
8#define PATH "/com/profusion/Test"
9#define IFACE "com.profusion.Test"
10
11Eldbus_Connection *conn;
12
13static Eina_Bool
14_timer1_cb(void *data EINA_UNUSED)
15{
16 printf("\nFishing...\n");
17 ecore_main_loop_quit();
18 return ECORE_CALLBACK_CANCEL;
19}
20
21static void
22on_plus_one(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
23{
24 int num2 = 0;
25
26 if (eldbus_message_error_get(msg, NULL, NULL))
27 {
28 printf("Message error\n\n");
29 return;
30 }
31 if (!eldbus_message_arguments_get(msg, "i", &num2))
32 {
33 printf("Error getting arguments.");
34 return;
35 }
36
37 printf("on_plus_one() %d\n", num2);
38}
39
40static void
41set_property_resp2(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
42{
43 const char *errname;
44 const char *errmsg;
45
46 printf("set_property_resp2()\n");
47 if (eldbus_message_error_get(msg, &errname, &errmsg))
48 {
49 printf("Message error %s - %s\n\n", errname, errmsg);
50 return;
51 }
52}
53
54static void
55get_property_resp2(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
56{
57 Eldbus_Proxy *proxy = data;
58 Eldbus_Message_Iter *variant = NULL;
59 char *type;
60 char *resp2;
61 const char *errname;
62 const char *errmsg;
63
64 printf("get_property_resp2()\n");
65 if (eldbus_message_error_get(msg, &errname, &errmsg))
66 {
67 printf("Message error %s - %s\n\n", errname, errmsg);
68 return;
69 }
70 if (!eldbus_message_arguments_get(msg, "v", &variant))
71 {
72 printf("Error getting arguments.");
73 return;
74 }
75
76 type = eldbus_message_iter_signature_get(variant);
77 if (type[1])
78 {
79 printf("It is a complex type, not handle yet.\n\n");
80 return;
81 }
82 if (type[0] != 's')
83 {
84 printf("Expected type is string.\n\n");
85 return;
86 }
87 if (!eldbus_message_iter_arguments_get(variant, "s", &resp2))
88 {
89 printf("error in eldbus_message_iter_arguments_get()\n\n");
90 return;
91 }
92 printf("resp2=%s\n", resp2);
93 free(type);
94
95 eldbus_proxy_property_set(proxy, "Resp2", "s", &"lalala", set_property_resp2, NULL);
96 eldbus_proxy_property_set(proxy, "int32", "i", (void*)(intptr_t)99, set_property_resp2, NULL);
97}
98
99static void
100on_send_array_int(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
101{
102 Eldbus_Message_Iter *array = NULL;
103 int num;
104
105 printf("on_send_array_int()\n");
106 if (eldbus_message_error_get(msg, NULL, NULL))
107 {
108 printf("Message error\n\n");
109 return;
110 }
111 if (!eldbus_message_arguments_get(msg, "ai", &array))
112 {
113 printf("Error getting arguments.");
114 return;
115 }
116
117 while (eldbus_message_iter_get_and_next(array, 'i', &num))
118 {
119 printf("%d\n", num);
120 }
121}
122
123static void
124on_send_array(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
125{
126 Eldbus_Message_Iter *array = NULL;
127 char *txt = NULL;
128 char *string[10];
129 int i = 0;
130 int z;
131
132 printf("on_send_array()\n");
133 if (eldbus_message_error_get(msg, NULL, NULL))
134 {
135 printf("Message error\n\n");
136 return;
137 }
138 if (!eldbus_message_arguments_get(msg, "as", &array))
139 {
140 printf("Error getting arguments.");
141 return;
142 }
143
144 while (eldbus_message_iter_get_and_next(array, 's', &txt))
145 {
146 string[i] = txt;
147 i++;
148 }
149
150 for (z = 0; z < i; z++)
151 printf("string = %s\n", string[z]);
152}
153
154static void
155on_receive_array_with_size(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
156{
157 const char *errname;
158 const char *errmsg;
159
160 printf("on_receive_array_with_size()\n");
161 if (eldbus_message_error_get(msg, &errname, &errmsg))
162 {
163 fprintf(stderr, "Error: %s %s\n", errname, errmsg);
164 }
165}
166
167static void
168on_send_variant(void *data EINA_UNUSED, const Eldbus_Message *msg EINA_UNUSED, Eldbus_Pending *pending EINA_UNUSED)
169{
170 printf("on_send_variant()\n\n");
171}
172
173static void
174on_receive_array(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
175{
176 const char *errname;
177 const char *errmsg;
178
179 printf("on_receive_array()\n");
180 if (eldbus_message_error_get(msg, &errname, &errmsg))
181 {
182 fprintf(stderr, "Error: %s %s\n", errname, errmsg);
183 }
184}
185
186int
187main(void)
188{
189 Eldbus_Object *test2_obj;
190 Eldbus_Proxy *test2_proxy;
191 Eldbus_Pending *pending;
192 Eldbus_Message_Iter *iter, *array_of_string, *variant;
193 Eldbus_Message_Iter *array_itr, *structure;
194 Eldbus_Message *msg;
195 int size_of_array = 5;
196 const char *array[5] = { "aaaa", "bbbb", "cccc", "dddd", "eeee" };
197 int i;
198 int plus_one = 24;
199
200 ecore_init();
201 eldbus_init();
202
203 conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SESSION);
204
205 test2_obj = eldbus_object_get(conn, BUS, PATH);
206 test2_proxy = eldbus_proxy_get(test2_obj, IFACE);
207
208 msg = eldbus_proxy_method_call_new(test2_proxy, "ReceiveArray");
209 iter = eldbus_message_iter_get(msg);
210 array_of_string = eldbus_message_iter_container_new(iter, 'a',"s");
211 if (!array_of_string) printf("array_of_string == NULL\n\n");
212 for (i = 0; i < 5; i++)
213 eldbus_message_iter_basic_append(array_of_string, 's', array[i]);
214 eldbus_message_iter_container_close(iter, array_of_string);
215 pending = eldbus_proxy_send(test2_proxy, msg, on_receive_array, NULL, -1);
216 if (!pending) printf("Error in eldbus_proxy_send()\n\n");
217
218 msg = eldbus_proxy_method_call_new(test2_proxy, "ReceiveArrayOfStringIntWithSize");
219 iter = eldbus_message_iter_get(msg);
220 if (!eldbus_message_iter_arguments_append(iter, "ia(si)", size_of_array, &array_of_string))
221 printf("error on eldbus_massage_iterator_arguments_set()\n\n");
222 for (i = 0; i < size_of_array; i++)
223 {
224 Eldbus_Message_Iter *struct_of_si;
225 eldbus_message_iter_arguments_append(array_of_string, "(si)", &struct_of_si);
226 eldbus_message_iter_arguments_append(struct_of_si, "si", array[i], i);
227 eldbus_message_iter_container_close(array_of_string, struct_of_si);
228 }
229 eldbus_message_iter_container_close(iter, array_of_string);
230 pending = eldbus_proxy_send(test2_proxy, msg, on_receive_array_with_size, NULL, -1);
231
232 msg = eldbus_proxy_method_call_new(test2_proxy, "SendVariantData");
233 iter = eldbus_message_iter_get(msg);
234 variant = eldbus_message_iter_container_new(iter, 'v', "s");
235 eldbus_message_iter_basic_append(variant, 's', "test");
236 eldbus_message_iter_container_close(iter, variant);
237 pending = eldbus_proxy_send(test2_proxy, msg, on_send_variant, NULL, -1);
238
239 msg = eldbus_proxy_method_call_new(test2_proxy, "DoubleContainner");
240 iter = eldbus_message_iter_get(msg);
241 /**
242 * eldbus_message_iterator_arguments_set(itr, "a(ii)a(ii)", &array_itr, &array_itr2);
243 * this will cause a error, we could not open another container until
244 * we close the first one
245 */
246 eldbus_message_iter_arguments_append(iter, "a(ii)", &array_itr);
247 for (i = 0; i < 5; i++)
248 {
249 eldbus_message_iter_arguments_append(array_itr, "(ii)", &structure);
250 eldbus_message_iter_arguments_append(structure, "ii", i, i*i);
251 eldbus_message_iter_container_close(array_itr, structure);
252 }
253 eldbus_message_iter_container_close(iter, array_itr);
254 eldbus_message_iter_arguments_append(iter, "a(ii)", &array_itr);
255 for (i = 0; i < 7; i++)
256 {
257 eldbus_message_iter_arguments_append(array_itr, "(ii)", &structure);
258 eldbus_message_iter_arguments_append(structure, "ii", i, i*i*i);
259 eldbus_message_iter_container_close(array_itr, structure);
260 }
261 eldbus_message_iter_container_close(iter, array_itr);
262 eldbus_proxy_send(test2_proxy, msg, NULL, NULL, -1);
263
264 pending = eldbus_proxy_call(test2_proxy, "SendArrayInt", on_send_array_int, NULL,
265 -1 , "");
266
267 pending = eldbus_proxy_call(test2_proxy, "SendArray", on_send_array, NULL,
268 -1 , "");
269
270 pending = eldbus_proxy_call(test2_proxy, "PlusOne", on_plus_one, NULL,
271 -1 , "i", plus_one);
272
273 pending = eldbus_proxy_property_get(test2_proxy, "Resp2", get_property_resp2, test2_proxy);
274
275 ecore_timer_add(10, _timer1_cb, NULL);
276
277 ecore_main_loop_begin();
278
279 eldbus_connection_unref(conn);
280
281 eldbus_shutdown();
282 ecore_shutdown();
283 return 0;
284}
diff --git a/src/examples/eldbus/connman-list-services.c b/src/examples/eldbus/connman-list-services.c
new file mode 100644
index 0000000..2e98097
--- /dev/null
+++ b/src/examples/eldbus/connman-list-services.c
@@ -0,0 +1,110 @@
1//Compile with:
2// gcc -o connman-list-services connman-list-services.c `pkg-config --cflags --libs eldbus ecore`
3
4#include "Eldbus.h"
5#include <Ecore.h>
6
7static void
8on_services_get(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
9{
10 Eldbus_Message_Iter *array, *entry;
11 const char *errname, *errmsg;
12
13 if (eldbus_message_error_get(msg, &errname, &errmsg))
14 {
15 fprintf(stderr, "Error: %s %s\n", errname, errmsg);
16 return;
17 }
18
19 if (!eldbus_message_arguments_get(msg, "a(oa{sv})", &array))
20 {
21 fprintf(stderr, "Error: could not get array\n");
22 return;
23 }
24
25 while (eldbus_message_iter_get_and_next(array, 'r', &entry))
26 {
27 Eldbus_Message_Iter *properties, *dict_entry;
28 const char *path;
29
30 if (!eldbus_message_iter_arguments_get(entry, "oa{sv}", &path, &properties))
31 {
32 fprintf(stderr, "Error: could not get entry contents\n");
33 return;
34 }
35
36 printf("service: %s\n", path);
37
38 while (eldbus_message_iter_get_and_next(properties, 'e', &dict_entry))
39 {
40 Eldbus_Message_Iter *variant;
41 const char *key;
42
43 if (!eldbus_message_iter_arguments_get(dict_entry, "sv", &key,
44 &variant))
45 {
46 fprintf(stderr,
47 "Error: could not get property contents\n");
48 return;
49 }
50
51 printf("\t%s: type %s\n", key,
52 eldbus_message_iter_signature_get(variant));
53
54 /* TODO: get the value from variant */
55 }
56 }
57}
58
59int
60main(void)
61{
62 Eldbus_Connection *conn;
63 Eldbus_Object *obj;
64 Eldbus_Proxy *manager;
65 Eldbus_Pending *pending;
66
67 ecore_init();
68 eldbus_init();
69
70 conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM);
71 if (!conn)
72 {
73 fprintf(stderr, "Error: could not get system bus\n");
74 return EXIT_FAILURE;
75 }
76
77 obj = eldbus_object_get(conn, "net.connman", "/");
78 if (!obj)
79 {
80 fprintf(stderr, "Error: could not get object\n");
81 return EXIT_FAILURE;
82 }
83
84 manager = eldbus_proxy_get(obj, "net.connman.Manager");
85 if (!manager)
86 {
87 fprintf(stderr, "Error: could not get proxy\n");
88 return EXIT_FAILURE;
89 }
90
91 pending = eldbus_proxy_call(manager, "GetServices", on_services_get, NULL,
92 -1, "");
93
94 if (!pending)
95 {
96 fprintf(stderr, "Error: could not call\n");
97 return EXIT_FAILURE;
98 }
99
100 ecore_main_loop_begin();
101
102 eldbus_proxy_unref(manager);
103 eldbus_object_unref(obj);
104 eldbus_connection_unref(conn);
105
106 eldbus_shutdown();
107 ecore_shutdown();
108 return 0;
109}
110
diff --git a/src/examples/eldbus/ofono-dial.c b/src/examples/eldbus/ofono-dial.c
new file mode 100644
index 0000000..a672102
--- /dev/null
+++ b/src/examples/eldbus/ofono-dial.c
@@ -0,0 +1,88 @@
1//Compile with:
2// gcc -o ofono-dial ofono-dial.c `pkg-config --cflags --libs eldbus ecore`
3
4#include "Eldbus.h"
5#include <Ecore.h>
6
7static void
8on_dial(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
9{
10 const char *errname, *errmsg;
11 const char *call_path;
12
13 if (eldbus_message_error_get(msg, &errname, &errmsg))
14 {
15 fprintf(stderr, "Error: %s %s\n", errname, errmsg);
16 return;
17 }
18
19 if (!eldbus_message_arguments_get(msg, "o", &call_path))
20 {
21 fprintf(stderr, "Error: could not get call path\n");
22 return;
23 }
24
25 printf("dialed! call path: %s\n", call_path);
26}
27
28int
29main(int argc, char *argv[])
30{
31 Eldbus_Connection *conn;
32 Eldbus_Object *obj;
33 Eldbus_Proxy *manager;
34 Eldbus_Pending *pending;
35 const char *number, *hide_callerid;
36
37 if (argc < 2)
38 {
39 fprintf(stderr, "Usage:\n\t%s <number> [hide_callerid]\n", argv[0]);
40 return EXIT_FAILURE;
41 }
42
43 number = argv[1];
44 hide_callerid = (argc > 2) ? argv[2] : "";
45
46 ecore_init();
47 eldbus_init();
48
49 conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM);
50 if (!conn)
51 {
52 fprintf(stderr, "Error: could not get system bus\n");
53 return EXIT_FAILURE;
54 }
55
56 obj = eldbus_object_get(conn, "org.ofono", "/");
57 if (!obj)
58 {
59 fprintf(stderr, "Error: could not get object\n");
60 return EXIT_FAILURE;
61 }
62
63 manager = eldbus_proxy_get(obj, "org.ofono.Manager");
64 if (!manager)
65 {
66 fprintf(stderr, "Error: could not get proxy\n");
67 return EXIT_FAILURE;
68 }
69
70 pending = eldbus_proxy_call(manager, "Dial", on_dial, NULL,
71 -1, "ss", number, hide_callerid);
72 if (!pending)
73 {
74 fprintf(stderr, "Error: could not call\n");
75 return EXIT_FAILURE;
76 }
77
78 ecore_main_loop_begin();
79
80 eldbus_proxy_unref(manager);
81 eldbus_object_unref(obj);
82 eldbus_connection_unref(conn);
83
84 eldbus_shutdown();
85 ecore_shutdown();
86 return 0;
87}
88
diff --git a/src/examples/eldbus/server.c b/src/examples/eldbus/server.c
new file mode 100644
index 0000000..532ce42
--- /dev/null
+++ b/src/examples/eldbus/server.c
@@ -0,0 +1,247 @@
1//Compile with:
2// gcc -o server server.c `pkg-config --cflags --libs eldbus ecore`
3
4#include "Eldbus.h"
5#include <Ecore.h>
6
7#define BUS "org.Enlightenment"
8#define PATH "/org/enlightenment"
9#define PATH_TEST_SON "/org/enlightenment/son"
10#define INTERFACE "org.enlightenment.Test"
11
12static Eldbus_Connection *conn;
13
14static Eldbus_Message *
15_hello(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *message)
16{
17 Eldbus_Message *reply = eldbus_message_method_return_new(message);
18 eldbus_message_arguments_append(reply, "s", "Hello World");
19 printf("Hello\n");
20 return reply;
21}
22
23static Eldbus_Message *
24_quit(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *message)
25{
26 printf("Quit\n");
27 ecore_main_loop_quit();
28 return eldbus_message_method_return_new(message);
29}
30
31enum
32{
33 TEST_SIGNAL_ALIVE = 0,
34 TEST_SIGNAL_HELLO
35};
36
37static Eina_Bool
38send_signal_alive(void *data)
39{
40 Eldbus_Service_Interface *iface = data;
41 eldbus_service_signal_emit(iface, TEST_SIGNAL_ALIVE);
42 return ECORE_CALLBACK_RENEW;
43}
44
45static Eina_Bool
46send_signal_hello(void *data)
47{
48 Eldbus_Service_Interface *iface = data;
49 eldbus_service_signal_emit(iface, TEST_SIGNAL_HELLO, "Hello World");
50 return ECORE_CALLBACK_RENEW;
51}
52
53static Eldbus_Message *
54_send_bool(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
55{
56 Eldbus_Message *reply = eldbus_message_method_return_new(msg);
57 Eina_Bool bool;
58 if (!eldbus_message_arguments_get(msg, "b", &bool))
59 printf("eldbus_message_arguments_get() error\n");
60 eldbus_message_arguments_append(reply, "b", bool);
61 return reply;
62}
63
64static Eldbus_Message *
65_send_byte(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
66{
67 Eldbus_Message *reply = eldbus_message_method_return_new(msg);
68 unsigned char byte;
69 if (!eldbus_message_arguments_get(msg, "y", &byte))
70 printf("eldbus_message_arguments_get() error\n");
71 eldbus_message_arguments_append(reply, "y", byte);
72 return reply;
73}
74
75static Eldbus_Message *
76_send_uint32(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
77{
78 Eldbus_Message *reply = eldbus_message_method_return_new(msg);
79 unsigned int uint32;
80 if (!eldbus_message_arguments_get(msg, "u", &uint32))
81 printf("eldbus_message_arguments_get() error\n");
82 eldbus_message_arguments_append(reply, "u", uint32);
83 return reply;
84}
85
86static Eldbus_Message *
87_send_int32(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
88{
89 Eldbus_Message *reply = eldbus_message_method_return_new(msg);
90 int int32;
91 if (!eldbus_message_arguments_get(msg, "i", &int32))
92 printf("eldbus_message_arguments_get() error\n");
93 eldbus_message_arguments_append(reply, "i", int32);
94 return reply;
95}
96
97static Eldbus_Message *
98_send_int16(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
99{
100 Eldbus_Message *reply = eldbus_message_method_return_new(msg);
101 short int int16;
102 if (!eldbus_message_arguments_get(msg, "n", &int16))
103 printf("eldbus_message_arguments_get() error\n");
104 eldbus_message_arguments_append(reply, "n", int16);
105 return reply;
106}
107
108static Eldbus_Message *
109_send_double(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
110{
111 Eldbus_Message *reply = eldbus_message_method_return_new(msg);
112 double d;
113 if (!eldbus_message_arguments_get(msg, "d", &d))
114 printf("eldbus_message_arguments_get() error\n");
115 eldbus_message_arguments_append(reply, "d", d);
116 return reply;
117}
118
119static Eldbus_Message *
120_send_string(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
121{
122 Eldbus_Message *reply = eldbus_message_method_return_new(msg);
123 const char *txt;
124 if (!eldbus_message_arguments_get(msg, "s", &txt))
125 printf("eldbus_message_arguments_get() error\n");
126 eldbus_message_arguments_append(reply, "s", txt);
127 return reply;
128}
129
130static Eina_Bool
131_resp_async(void *data)
132{
133 Eldbus_Message *msg = data;
134 eldbus_message_arguments_append(msg, "s", "Async test ok");
135 eldbus_connection_send(conn, msg, NULL, NULL, -1);
136 return ECORE_CALLBACK_CANCEL;
137}
138
139static Eldbus_Message *
140_async_test(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
141{
142 Eldbus_Message *reply = eldbus_message_method_return_new(msg);
143 printf("Received a call to AsyncTest.\n");
144 printf("Response will be send in 5 seconds.\n");
145 ecore_timer_add(5, _resp_async, reply);
146 return NULL;
147}
148
149static const Eldbus_Signal signals[] = {
150 [TEST_SIGNAL_ALIVE] = {"Alive", NULL, 0},
151 [TEST_SIGNAL_HELLO] = {"Hello", ELDBUS_ARGS({ "s", "message" }), 0},
152 { }
153};
154
155static const Eldbus_Method methods[] = {
156 {
157 "Hello", NULL, ELDBUS_ARGS({"s", "message"}),
158 _hello
159 },
160 {
161 "Quit", NULL, NULL,
162 _quit, ELDBUS_METHOD_FLAG_DEPRECATED
163 },
164 { "SendBool", ELDBUS_ARGS({"b", "bool"}), ELDBUS_ARGS({"b", "bool"}),
165 _send_bool
166 },
167 { "SendByte", ELDBUS_ARGS({"y", "byte"}), ELDBUS_ARGS({"y", "byte"}),
168 _send_byte
169 },
170 { "SendUint32", ELDBUS_ARGS({"u", "uint32"}), ELDBUS_ARGS({"u", "uint32"}),
171 _send_uint32
172 },
173 { "SendInt32", ELDBUS_ARGS({"i", "int32"}), ELDBUS_ARGS({"i", "int32"}),
174 _send_int32
175 },
176 { "SendInt16", ELDBUS_ARGS({"n", "int16"}), ELDBUS_ARGS({"n", "int16"}),
177 _send_int16
178 },
179 { "SendDouble", ELDBUS_ARGS({"d", "double"}), ELDBUS_ARGS({"d", "double"}),
180 _send_double
181 },
182 { "SendString", ELDBUS_ARGS({"s", "string"}), ELDBUS_ARGS({"s", "string"}),
183 _send_string
184 },
185 { "AsyncTest", NULL, ELDBUS_ARGS({"s", "text"}),
186 _async_test
187 },
188 { }
189};
190
191static const Eldbus_Service_Interface_Desc iface_desc = {
192 INTERFACE, methods, signals
193};
194
195static void
196on_name_request(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
197{
198 Eldbus_Service_Interface *iface;
199 unsigned int reply;
200
201 iface = data;
202 if (eldbus_message_error_get(msg, NULL, NULL))
203 {
204 printf("error on on_name_request\n");
205 return;
206 }
207
208 if (!eldbus_message_arguments_get(msg, "u", &reply))
209 {
210 printf("error geting arguments on on_name_request\n");
211 return;
212 }
213
214 if (reply != ELDBUS_NAME_REQUEST_REPLY_PRIMARY_OWNER)
215 {
216 printf("error name already in use\n");
217 return;
218 }
219
220 ecore_timer_add(5, send_signal_alive, iface);
221 ecore_timer_add(6, send_signal_hello, iface);
222}
223
224int
225main(void)
226{
227 Eldbus_Service_Interface *iface;
228
229 ecore_init();
230 eldbus_init();
231
232 conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SESSION);
233
234 iface = eldbus_service_interface_register(conn, PATH, &iface_desc);
235 eldbus_name_request(conn, BUS, ELDBUS_NAME_REQUEST_FLAG_DO_NOT_QUEUE,
236 on_name_request, iface);
237
238 eldbus_service_interface_register(conn, PATH_TEST_SON, &iface_desc);
239
240 ecore_main_loop_begin();
241
242 eldbus_connection_unref(conn);
243
244 eldbus_shutdown();
245 ecore_shutdown();
246 return 0;
247}
diff --git a/src/examples/eldbus/simple-signal-emit.c b/src/examples/eldbus/simple-signal-emit.c
new file mode 100644
index 0000000..8b0bf89
--- /dev/null
+++ b/src/examples/eldbus/simple-signal-emit.c
@@ -0,0 +1,86 @@
1//Compile with:
2// gcc -o simple-signal-emit simple-signal-emit.c `pkg-config --cflags --libs eldbus`
3
4#include <Eldbus.h>
5
6enum {
7 TEST_SIGNAL_ALIVE,
8 TEST_SIGNAL_PROP,
9 TEST_SIGNAL_NAME,
10};
11
12static const Eldbus_Signal test_signals[] = {
13 [TEST_SIGNAL_ALIVE] = { "Alive" },
14 [TEST_SIGNAL_PROP] = { "Properties", ELDBUS_ARGS({ "a{ss}", "properties"}) },
15 [TEST_SIGNAL_NAME] = { "Name", ELDBUS_ARGS({ "s", "name"}) },
16 { }
17};
18
19/* signal with complex arguments (a dict) */
20static void emit_properties(Eldbus_Service_Interface *iface)
21{
22 Eldbus_Message *alive2;
23 Eldbus_Message_Iter *iter, *dict;
24 struct keyval {
25 const char *key;
26 const char *val;
27 } keyval[] = {
28 { "key1", "val1" },
29 { "key2", "val2" },
30 { }
31 };
32 struct keyval *k;
33
34 alive2 = eldbus_service_signal_new(iface, TEST_SIGNAL_PROP);
35 iter = eldbus_message_iter_get(alive2);
36 dict = eldbus_message_iter_container_new(iter, 'a', "{ss}");
37
38 for (k = keyval; k && k->key; k++)
39 {
40 Eldbus_Message_Iter *entry = eldbus_message_iter_container_new(dict, 'e',
41 NULL);
42 eldbus_message_iter_arguments_append(entry, "ss", k->key, k->val);
43 eldbus_message_iter_container_close(dict, entry);
44 }
45
46 eldbus_message_iter_container_close(iter, dict);
47 eldbus_service_signal_send(iface, alive2);
48}
49
50/* signal with basic args */
51static void emit_name(Eldbus_Service_Interface *iface)
52{
53 eldbus_service_signal_emit(iface, TEST_SIGNAL_NAME, "TEST");
54}
55
56/* simple signal example */
57static void emit_alive(Eldbus_Service_Interface *iface)
58{
59 eldbus_service_signal_emit(iface, TEST_SIGNAL_ALIVE);
60}
61
62static const Eldbus_Service_Interface_Desc iface_desc = {
63 "org.enlightenment.Test", NULL, test_signals
64};
65
66int main(void)
67{
68 Eldbus_Connection *conn;
69 Eldbus_Service_Interface *iface;
70
71 eldbus_init();
72
73 conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SESSION);
74 iface = eldbus_service_interface_register(conn, "/org/enlightenment",
75 &iface_desc);
76
77 emit_alive(iface);
78 emit_name(iface);
79 emit_properties(iface);
80
81 eldbus_connection_unref(conn);
82
83 eldbus_shutdown();
84
85 return 0;
86}