summaryrefslogtreecommitdiff
path: root/src/examples/edbus/complex-types.c
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2012-12-28 17:53:25 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2012-12-28 17:53:25 +0000
commit331488d1ce3db2d07533ee276dabdc23f153fa61 (patch)
treea091fe83bfcf0c9d8f9f34ebfe44a5347537bff8 /src/examples/edbus/complex-types.c
parent6800b178dc918633ede220c572e5b99fa0046e7e (diff)
efl: merge edbus (v2).
SVN revision: 81825
Diffstat (limited to 'src/examples/edbus/complex-types.c')
-rw-r--r--src/examples/edbus/complex-types.c285
1 files changed, 285 insertions, 0 deletions
diff --git a/src/examples/edbus/complex-types.c b/src/examples/edbus/complex-types.c
new file mode 100644
index 0000000000..a0af846f5f
--- /dev/null
+++ b/src/examples/edbus/complex-types.c
@@ -0,0 +1,285 @@
1#include "EDBus.h"
2#include <Ecore.h>
3
4#define BUS "com.profusion"
5#define PATH "/com/profusion/Test"
6#define IFACE "com.profusion.Test"
7
8EDBus_Connection *conn;
9
10static Eina_Bool
11_timer1_cb(void *data)
12{
13 printf("\nFishing...\n");
14 ecore_main_loop_quit();
15 return ECORE_CALLBACK_CANCEL;
16}
17
18static void
19on_plus_one(void *data, const EDBus_Message *msg, EDBus_Pending *pending)
20{
21 int num2 = 0;
22
23 if (edbus_message_error_get(msg, NULL, NULL))
24 {
25 printf("Message error\n\n");
26 return;
27 }
28 if (!edbus_message_arguments_get(msg, "i", &num2))
29 {
30 printf("Error getting arguments.");
31 return;
32 }
33
34 printf("on_plus_one() %d\n", num2);
35}
36
37static void
38set_property_resp2(void *data, const EDBus_Message *msg, EDBus_Pending *pending)
39{
40 const char *errname;
41 const char *errmsg;
42
43 printf("set_property_resp2()\n");
44 if (edbus_message_error_get(msg, &errname, &errmsg))
45 {
46 printf("Message error %s - %s\n\n", errname, errmsg);
47 return;
48 }
49}
50
51static void
52get_property_resp2(void *data, const EDBus_Message *msg, EDBus_Pending *pending)
53{
54 EDBus_Proxy *proxy = data;
55 EDBus_Message_Iter *variant = NULL;
56 char *type;
57 char *resp2;
58 const char *errname;
59 const char *errmsg;
60
61 printf("get_property_resp2()\n");
62 if (edbus_message_error_get(msg, &errname, &errmsg))
63 {
64 printf("Message error %s - %s\n\n", errname, errmsg);
65 return;
66 }
67 if (!edbus_message_arguments_get(msg, "v", &variant))
68 {
69 printf("Error getting arguments.");
70 return;
71 }
72
73 type = edbus_message_iter_signature_get(variant);
74 if (type[1])
75 {
76 printf("It is a complex type, not handle yet.\n\n");
77 return;
78 }
79 if (type[0] != 's')
80 {
81 printf("Expected type is string.\n\n");
82 return;
83 }
84 if (!edbus_message_iter_arguments_get(variant, "s", &resp2))
85 {
86 printf("error in edbus_message_iter_arguments_get()\n\n");
87 return;
88 }
89 printf("resp2=%s\n", resp2);
90 free(type);
91
92 edbus_proxy_property_set(proxy, "Resp2", "s", &"lalala", set_property_resp2, NULL);
93 edbus_proxy_property_set(proxy, "int32", "i", (void*)(intptr_t)99, set_property_resp2, NULL);
94}
95
96static void
97on_send_array_int(void *data, const EDBus_Message *msg, EDBus_Pending *pending)
98{
99 EDBus_Message_Iter *array = NULL;
100 int num;
101
102 printf("on_send_array_int()\n");
103 if (edbus_message_error_get(msg, NULL, NULL))
104 {
105 printf("Message error\n\n");
106 return;
107 }
108 if (!edbus_message_arguments_get(msg, "ai", &array))
109 {
110 printf("Error getting arguments.");
111 return;
112 }
113
114 while (edbus_message_iter_get_and_next(array, 'i', &num))
115 {
116 printf("%d\n", num);
117 }
118}
119
120static void
121on_send_array(void *data, const EDBus_Message *msg, EDBus_Pending *pending)
122{
123 EDBus_Message_Iter *array = NULL;
124 char *txt = NULL;
125 char *string[10];
126 int i = 0;
127 int z;
128
129 printf("on_send_array()\n");
130 if (edbus_message_error_get(msg, NULL, NULL))
131 {
132 printf("Message error\n\n");
133 return;
134 }
135 if (!edbus_message_arguments_get(msg, "as", &array))
136 {
137 printf("Error getting arguments.");
138 return;
139 }
140
141 while (edbus_message_iter_get_and_next(array, 's', &txt))
142 {
143 string[i] = txt;
144 i++;
145 }
146
147 for (z = 0; z < i; z++)
148 printf("string = %s\n", string[z]);
149}
150
151static void
152on_receive_array_with_size(void *data, const EDBus_Message *msg, EDBus_Pending *pending)
153{
154 const char *errname;
155 const char *errmsg;
156
157 printf("on_receive_array_with_size()\n");
158 if (edbus_message_error_get(msg, &errname, &errmsg))
159 {
160 fprintf(stderr, "Error: %s %s\n", errname, errmsg);
161 }
162}
163
164static void
165on_send_variant(void *data, const EDBus_Message *msg, EDBus_Pending *pending)
166{
167 printf("on_send_variant()\n\n");
168}
169
170static void
171on_receive_array(void *data, const EDBus_Message *msg, EDBus_Pending *pending)
172{
173 const char *errname;
174 const char *errmsg;
175
176 printf("on_receive_array()\n");
177 if (edbus_message_error_get(msg, &errname, &errmsg))
178 {
179 fprintf(stderr, "Error: %s %s\n", errname, errmsg);
180 }
181}
182
183int
184main(void)
185{
186 EDBus_Object *test2_obj;
187 EDBus_Proxy *test2_proxy;
188 EDBus_Pending *pending;
189 EDBus_Message_Iter *iter, *array_of_string, *variant;
190 EDBus_Message_Iter *array_itr, *structure;
191 EDBus_Message *msg;
192 int size_of_array = 5;
193 const char *array[5] = { "aaaa", "bbbb", "cccc", "dddd", "eeee" };
194 int i;
195 int plus_one = 24;
196
197 ecore_init();
198 edbus_init();
199
200 conn = edbus_connection_get(EDBUS_CONNECTION_TYPE_SESSION);
201
202 test2_obj = edbus_object_get(conn, BUS, PATH);
203 test2_proxy = edbus_proxy_get(test2_obj, IFACE);
204
205 msg = edbus_proxy_method_call_new(test2_proxy, "ReceiveArray");
206 iter = edbus_message_iter_get(msg);
207 array_of_string = edbus_message_iter_container_new(iter, 'a',"s");
208 if (!array_of_string) printf("array_of_string == NULL\n\n");
209 for (i = 0; i < 5; i++)
210 edbus_message_iter_basic_append(array_of_string, 's', array[i]);
211 edbus_message_iter_container_close(iter, array_of_string);
212 pending = edbus_proxy_send(test2_proxy, msg, on_receive_array, NULL, -1);
213 if (!pending) printf("Error in edbus_proxy_send()\n\n");
214 edbus_message_unref(msg);
215
216 msg = edbus_proxy_method_call_new(test2_proxy, "ReceiveArrayOfStringIntWithSize");
217 iter = edbus_message_iter_get(msg);
218 if (!edbus_message_iter_arguments_append(iter, "ia(si)", size_of_array, &array_of_string))
219 printf("error on edbus_massage_iterator_arguments_set()\n\n");
220 for (i = 0; i < size_of_array; i++)
221 {
222 EDBus_Message_Iter *struct_of_si;
223 edbus_message_iter_arguments_append(array_of_string, "(si)", &struct_of_si);
224 edbus_message_iter_arguments_append(struct_of_si, "si", array[i], i);
225 edbus_message_iter_container_close(array_of_string, struct_of_si);
226 }
227 edbus_message_iter_container_close(iter, array_of_string);
228 pending = edbus_proxy_send(test2_proxy, msg, on_receive_array_with_size, NULL, -1);
229 edbus_message_unref(msg);
230
231 msg = edbus_proxy_method_call_new(test2_proxy, "SendVariantData");
232 iter = edbus_message_iter_get(msg);
233 variant = edbus_message_iter_container_new(iter, 'v', "s");
234 edbus_message_iter_basic_append(variant, 's', "test");
235 edbus_message_iter_container_close(iter, variant);
236 pending = edbus_proxy_send(test2_proxy, msg, on_send_variant, NULL, -1);
237 edbus_message_unref(msg);
238
239 msg = edbus_proxy_method_call_new(test2_proxy, "DoubleContainner");
240 iter = edbus_message_iter_get(msg);
241 /**
242 * edbus_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 edbus_message_iter_arguments_append(iter, "a(ii)", &array_itr);
247 for (i = 0; i < 5; i++)
248 {
249 edbus_message_iter_arguments_append(array_itr, "(ii)", &structure);
250 edbus_message_iter_arguments_append(structure, "ii", i, i*i);
251 edbus_message_iter_container_close(array_itr, structure);
252 }
253 edbus_message_iter_container_close(iter, array_itr);
254 edbus_message_iter_arguments_append(iter, "a(ii)", &array_itr);
255 for (i = 0; i < 7; i++)
256 {
257 edbus_message_iter_arguments_append(array_itr, "(ii)", &structure);
258 edbus_message_iter_arguments_append(structure, "ii", i, i*i*i);
259 edbus_message_iter_container_close(array_itr, structure);
260 }
261 edbus_message_iter_container_close(iter, array_itr);
262 edbus_proxy_send(test2_proxy, msg, NULL, NULL, -1);
263 edbus_message_unref(msg);
264
265 pending = edbus_proxy_call(test2_proxy, "SendArrayInt", on_send_array_int, NULL,
266 -1 , "");
267
268 pending = edbus_proxy_call(test2_proxy, "SendArray", on_send_array, NULL,
269 -1 , "");
270
271 pending = edbus_proxy_call(test2_proxy, "PlusOne", on_plus_one, NULL,
272 -1 , "i", plus_one);
273
274 pending = edbus_proxy_property_get(test2_proxy, "Resp2", get_property_resp2, test2_proxy);
275
276 ecore_timer_add(10, _timer1_cb, NULL);
277
278 ecore_main_loop_begin();
279
280 edbus_connection_unref(conn);
281
282 edbus_shutdown();
283 ecore_shutdown();
284 return 0;
285}