summaryrefslogtreecommitdiff
path: root/legacy/edbus/src/examples/simple-signal-emit.c
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.demarchi@profusion.mobi>2012-10-19 18:24:36 +0000
committerLucas De Marchi <lucas.demarchi@profusion.mobi>2012-10-19 18:24:36 +0000
commit1799e141b7af475965b5e5d7f2d20b821f6e7090 (patch)
treec608e07816f9c6d5bff155bc509174d4be91e0b0 /legacy/edbus/src/examples/simple-signal-emit.c
parent6d2bd31902abcb74b491a6b5a862e4a6d1f0bc26 (diff)
edbus: Add example for emitting signal
SVN revision: 78263
Diffstat (limited to 'legacy/edbus/src/examples/simple-signal-emit.c')
-rw-r--r--legacy/edbus/src/examples/simple-signal-emit.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/legacy/edbus/src/examples/simple-signal-emit.c b/legacy/edbus/src/examples/simple-signal-emit.c
new file mode 100644
index 0000000000..a9574d3d29
--- /dev/null
+++ b/legacy/edbus/src/examples/simple-signal-emit.c
@@ -0,0 +1,79 @@
1#include <EDBus.h>
2
3enum {
4 TEST_SIGNAL_ALIVE,
5 TEST_SIGNAL_PROP,
6 TEST_SIGNAL_NAME,
7};
8
9static const EDBus_Signal test_signals[] = {
10 [TEST_SIGNAL_ALIVE] = { "Alive" },
11 [TEST_SIGNAL_PROP] = { "Properties", EDBUS_ARGS({ "a{ss}", "properties"}) },
12 [TEST_SIGNAL_NAME] = { "Name", EDBUS_ARGS({ "s", "name"}) },
13 { }
14};
15
16/* signal with complex arguments (a dict) */
17static void emit_properties(EDBus_Service_Interface *iface)
18{
19 EDBus_Message *alive2;
20 EDBus_Message_Iter *iter, *dict;
21 struct keyval {
22 const char *key;
23 const char *val;
24 } keyval[] = {
25 { "key1", "val1" },
26 { "key2", "val2" },
27 { }
28 };
29 struct keyval *k;
30
31 alive2 = edbus_service_signal_new(iface, TEST_SIGNAL_PROP);
32 iter = edbus_message_iter_get(alive2);
33 dict = edbus_message_iter_container_new(iter, 'a', "{ss}");
34
35 for (k = keyval; k && k->key; k++)
36 {
37 EDBus_Message_Iter *entry = edbus_message_iter_container_new(dict, 'e',
38 NULL);
39 edbus_message_iter_arguments_set(entry, "ss", k->key, k->val);
40 edbus_message_iter_container_close(dict, entry);
41 }
42
43 edbus_message_iter_container_close(iter, dict);
44 edbus_service_signal_send(iface, alive2);
45}
46
47/* signal with basic args */
48static void emit_name(EDBus_Service_Interface *iface)
49{
50 edbus_service_signal_emit(iface, TEST_SIGNAL_NAME, "TEST");
51}
52
53/* simple signal example */
54static void emit_alive(EDBus_Service_Interface *iface)
55{
56 edbus_service_signal_emit(iface, TEST_SIGNAL_ALIVE);
57}
58
59int main(void)
60{
61 EDBus_Connection *conn;
62 EDBus_Service_Interface *iface;
63
64 edbus_init();
65
66 conn = edbus_connection_get(EDBUS_CONNECTION_TYPE_SESSION);
67 iface = edbus_service_interface_register(
68 conn, "/org/enlightenment", "org.enlightenment.Test", NULL, test_signals);
69
70 emit_alive(iface);
71 emit_name(iface);
72 emit_properties(iface);
73
74 edbus_connection_unref(conn);
75
76 edbus_shutdown();
77
78 return 0;
79}