summaryrefslogtreecommitdiff
path: root/src/examples/edbus/simple-signal-emit.c
blob: 960bfe632ef6e32480525cbf26c13533f334b92b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <EDBus.h>

enum {
   TEST_SIGNAL_ALIVE,
   TEST_SIGNAL_PROP,
   TEST_SIGNAL_NAME,
};

static const EDBus_Signal test_signals[] = {
   [TEST_SIGNAL_ALIVE] = { "Alive" },
   [TEST_SIGNAL_PROP] = { "Properties", EDBUS_ARGS({ "a{ss}", "properties"}) },
   [TEST_SIGNAL_NAME] = { "Name", EDBUS_ARGS({ "s", "name"}) },
   { }
};

/* signal with complex arguments (a dict) */
static void emit_properties(EDBus_Service_Interface *iface)
{
   EDBus_Message *alive2;
   EDBus_Message_Iter *iter, *dict;
   struct keyval {
      const char *key;
      const char *val;
   } keyval[] = {
      { "key1", "val1" },
      { "key2", "val2" },
      { }
   };
   struct keyval *k;

   alive2 = edbus_service_signal_new(iface, TEST_SIGNAL_PROP);
   iter = edbus_message_iter_get(alive2);
   dict = edbus_message_iter_container_new(iter, 'a', "{ss}");

   for (k = keyval; k && k->key; k++)
     {
        EDBus_Message_Iter *entry = edbus_message_iter_container_new(dict, 'e',
                                                                     NULL);
        edbus_message_iter_arguments_append(entry, "ss", k->key, k->val);
        edbus_message_iter_container_close(dict, entry);
     }

   edbus_message_iter_container_close(iter, dict);
   edbus_service_signal_send(iface, alive2);
}

/* signal with basic args */
static void emit_name(EDBus_Service_Interface *iface)
{
   edbus_service_signal_emit(iface, TEST_SIGNAL_NAME, "TEST");
}

/* simple signal example */
static void emit_alive(EDBus_Service_Interface *iface)
{
   edbus_service_signal_emit(iface, TEST_SIGNAL_ALIVE);
}

static const EDBus_Service_Interface_Desc iface_desc = {
   "org.enlightenment.Test", NULL, test_signals
};

int main(void)
{
   EDBus_Connection *conn;
   EDBus_Service_Interface *iface;

   edbus_init();

   conn = edbus_connection_get(EDBUS_CONNECTION_TYPE_SESSION);
   iface = edbus_service_interface_register(conn, "/org/enlightenment",
                                            &iface_desc);

   emit_alive(iface);
   emit_name(iface);
   emit_properties(iface);

   edbus_connection_unref(conn);

   edbus_shutdown();

   return 0;
}