summaryrefslogtreecommitdiff
path: root/src/examples/eldbus/simple-signal-emit.c
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/simple-signal-emit.c
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 '')
-rw-r--r--src/examples/eldbus/simple-signal-emit.c86
1 files changed, 86 insertions, 0 deletions
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}