summaryrefslogtreecommitdiff
path: root/src/examples/eldbus
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
parent4fc274253d5562c4369f384167996468a000e397 (diff)
Example for eldbus_address_connection_get() functions
Signed-off-by: Eduardo Lima (Etrunko) <eduardo.lima@intel.com>
Diffstat (limited to 'src/examples/eldbus')
-rw-r--r--src/examples/eldbus/Makefile.am9
-rw-r--r--src/examples/eldbus/Makefile.examples3
-rw-r--r--src/examples/eldbus/connect-address.c100
3 files changed, 109 insertions, 3 deletions
diff --git a/src/examples/eldbus/Makefile.am b/src/examples/eldbus/Makefile.am
index 1ec9d34..e0c79b3 100644
--- a/src/examples/eldbus/Makefile.am
+++ b/src/examples/eldbus/Makefile.am
@@ -28,7 +28,8 @@ complex-types-server.c \
28server.c \ 28server.c \
29client.c \ 29client.c \
30simple-signal-emit.c \ 30simple-signal-emit.c \
31complex-types-client-eina-value.c 31complex-types-client-eina-value.c \
32connect-address.c
32 33
33EXTRA_PROGRAMS = \ 34EXTRA_PROGRAMS = \
34connman-list-services \ 35connman-list-services \
@@ -39,7 +40,8 @@ complex-types-server \
39server \ 40server \
40client \ 41client \
41simple-signal-emit \ 42simple-signal-emit \
42complex-types-client-eina-value 43complex-types-client-eina-value \
44connect-address
43 45
44connman_list_services_SOURCES = connman-list-services.c 46connman_list_services_SOURCES = connman-list-services.c
45connman_list_services_LDADD = $(EXAMPLES_LIBS) 47connman_list_services_LDADD = $(EXAMPLES_LIBS)
@@ -68,6 +70,9 @@ simple_signal_emit_LDADD = $(EXAMPLES_LIBS)
68complex_types_client_eina_value_SOURCES = complex-types-client-eina-value.c 70complex_types_client_eina_value_SOURCES = complex-types-client-eina-value.c
69complex_types_client_eina_value_LDADD = $(EXAMPLES_LIBS) 71complex_types_client_eina_value_LDADD = $(EXAMPLES_LIBS)
70 72
73connect_address_SOURCES = connect-address.c
74connect_address_LDADD = $(EXAMPLES_LIBS)
75
71DATA_FILES = Makefile.examples 76DATA_FILES = Makefile.examples
72 77
73EXTRA_DIST = $(DATA_FILES) 78EXTRA_DIST = $(DATA_FILES)
diff --git a/src/examples/eldbus/Makefile.examples b/src/examples/eldbus/Makefile.examples
index 32d0d93..c6d2406 100644
--- a/src/examples/eldbus/Makefile.examples
+++ b/src/examples/eldbus/Makefile.examples
@@ -8,7 +8,8 @@ EXAMPLES= banshee client \
8 connman-list-services \ 8 connman-list-services \
9 ofono-dial \ 9 ofono-dial \
10 server \ 10 server \
11 simple-signal-emit 11 simple-signal-emit \
12 connect-address
12 13
13all: examples 14all: examples
14examples: $(EXAMPLES) 15examples: $(EXAMPLES)
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}