summaryrefslogtreecommitdiff
path: root/src/examples/eldbus/connect-address.c
diff options
context:
space:
mode:
authorEduardo Lima (Etrunko) <eduardo.lima@intel.com>2013-05-27 18:14:44 -0300
committerEduardo Lima (Etrunko) <eduardo.lima@intel.com>2013-05-28 09:42:29 -0300
commit3142db28805802d8964778b9f770fa9a40886887 (patch)
treeab0b3e7900c43dd5fd384434c6dccce274896026 /src/examples/eldbus/connect-address.c
parent4fc274253d5562c4369f384167996468a000e397 (diff)
Example for eldbus_address_connection_get() functions
Signed-off-by: Eduardo Lima (Etrunko) <eduardo.lima@intel.com>
Diffstat (limited to '')
-rw-r--r--src/examples/eldbus/connect-address.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/examples/eldbus/connect-address.c b/src/examples/eldbus/connect-address.c
new file mode 100644
index 0000000..11858f4
--- /dev/null
+++ b/src/examples/eldbus/connect-address.c
@@ -0,0 +1,100 @@
1//Compile with:
2// gcc -o client client.c `pkg-config --cflags --libs eldbus ecore eina`
3
4#include <stdlib.h>
5
6#include "Eldbus.h"
7#include <Ecore.h>
8
9#define BUS "org.freedesktop.IBus"
10#define PATH "/org/freedesktop/IBus"
11#define INTERFACE "org.freedesktop.IBus"
12
13static int _client_log_dom = -1;
14#define ERR(...) EINA_LOG_DOM_ERR(_client_log_dom, __VA_ARGS__)
15
16static void
17_on_registry_changed(void *context EINA_UNUSED, const Eldbus_Message *msg EINA_UNUSED)
18{
19 printf("RegistryChanged\n\n");
20}
21
22static void
23_on_global_engine_changed(void *context EINA_UNUSED, const Eldbus_Message *msg)
24{
25 const char *txt;
26 if (eldbus_message_arguments_get(msg, "s", &txt))
27 printf("GlobalEngineChanged %s\n", txt);
28}
29
30static void
31on_name_owner_changed(void *data EINA_UNUSED, const char *bus, const char *old_id, const char *new_id EINA_UNUSED)
32{
33 printf("Bus=%s | old=%s | new=%s\n", bus, old_id, new_id);
34}
35
36static Eina_Bool
37finish(void *data EINA_UNUSED)
38{
39 ecore_main_loop_quit();
40 return ECORE_CALLBACK_CANCEL;
41}
42
43int
44main(void)
45{
46 Eldbus_Connection *conn;
47 Eldbus_Object *obj;
48 Eldbus_Proxy *proxy;
49 const char *address;
50
51 eina_init();
52 _client_log_dom = eina_log_domain_register("connect_address", EINA_COLOR_CYAN);
53 if (_client_log_dom < 0)
54 {
55 EINA_LOG_ERR("Unable to create 'client' log domain");
56 goto exit_eina;
57 }
58
59 if (!(address = getenv("IBUS_ADDRESS")))
60 {
61 ERR("IBUS_ADDRESS environment variable must be set");
62 goto exit_eina;
63 }
64
65 ecore_init();
66 eldbus_init();
67
68 printf("Connecting to %s\n", address);
69 conn = eldbus_address_connection_get(address);
70
71 if (!conn)
72 {
73 ERR("Failed to get dbus connection to address '%s'", address);
74 goto end;
75 }
76
77 printf("CONNECTED!!!\n");
78 obj = eldbus_object_get(conn, BUS, PATH);
79 proxy = eldbus_proxy_get(obj, INTERFACE);
80 eldbus_proxy_signal_handler_add(proxy, "RegistryChanged", _on_registry_changed, NULL);
81 eldbus_proxy_signal_handler_add(proxy, "GlobalEngineChanged", _on_global_engine_changed, NULL);
82
83 eldbus_name_owner_changed_callback_add(conn, BUS, on_name_owner_changed,
84 conn, EINA_TRUE);
85 ecore_timer_add(30, finish, NULL);
86
87 ecore_main_loop_begin();
88
89 eldbus_connection_unref(conn);
90
91end:
92 eldbus_shutdown();
93 ecore_shutdown();
94
95 eina_log_domain_unregister(_client_log_dom);
96exit_eina:
97 eina_shutdown();
98
99 return 0;
100}