etrunko pushed a commit to branch master.

commit 3142db28805802d8964778b9f770fa9a40886887
Author: Eduardo Lima (Etrunko) <[email protected]>
Date:   Mon May 27 18:14:44 2013 -0300

    Example for eldbus_address_connection_get() functions
    
    Signed-off-by: Eduardo Lima (Etrunko) <[email protected]>
---
 .gitignore                            |   1 +
 src/examples/eldbus/Makefile.am       |   9 ++-
 src/examples/eldbus/Makefile.examples |   3 +-
 src/examples/eldbus/connect-address.c | 100 ++++++++++++++++++++++++++++++++++
 4 files changed, 110 insertions(+), 3 deletions(-)

diff --git a/.gitignore b/.gitignore
index 483b916..2197a7f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -208,6 +208,7 @@ tags
 /src/examples/eldbus/complex-types
 /src/examples/eldbus/complex-types-client-eina-value
 /src/examples/eldbus/complex-types-server
+/src/examples/eldbus/conect-address
 /src/examples/eldbus/connman-list-services
 /src/examples/eldbus/ofono-dial
 /src/examples/eldbus/server
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 \
 server.c \
 client.c \
 simple-signal-emit.c \
-complex-types-client-eina-value.c
+complex-types-client-eina-value.c \
+connect-address.c
 
 EXTRA_PROGRAMS = \
 connman-list-services \
@@ -39,7 +40,8 @@ complex-types-server \
 server \
 client \
 simple-signal-emit \
-complex-types-client-eina-value
+complex-types-client-eina-value \
+connect-address
 
 connman_list_services_SOURCES = connman-list-services.c
 connman_list_services_LDADD = $(EXAMPLES_LIBS)
@@ -68,6 +70,9 @@ simple_signal_emit_LDADD = $(EXAMPLES_LIBS)
 complex_types_client_eina_value_SOURCES = complex-types-client-eina-value.c
 complex_types_client_eina_value_LDADD = $(EXAMPLES_LIBS)
 
+connect_address_SOURCES = connect-address.c
+connect_address_LDADD = $(EXAMPLES_LIBS)
+
 DATA_FILES = Makefile.examples
 
 EXTRA_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 \
           connman-list-services \
           ofono-dial \
           server \
-          simple-signal-emit 
+          simple-signal-emit \
+          connect-address
 
 all: examples
 examples: $(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 @@
+//Compile with:
+// gcc -o client client.c `pkg-config --cflags --libs eldbus ecore eina`
+
+#include <stdlib.h>
+
+#include "Eldbus.h"
+#include <Ecore.h>
+
+#define BUS "org.freedesktop.IBus"
+#define PATH "/org/freedesktop/IBus"
+#define INTERFACE "org.freedesktop.IBus"
+
+static int _client_log_dom = -1;
+#define ERR(...)      EINA_LOG_DOM_ERR(_client_log_dom, __VA_ARGS__)
+
+static void
+_on_registry_changed(void *context EINA_UNUSED, const Eldbus_Message *msg 
EINA_UNUSED)
+{
+   printf("RegistryChanged\n\n");
+}
+
+static void
+_on_global_engine_changed(void *context EINA_UNUSED, const Eldbus_Message *msg)
+{
+   const char *txt;
+   if (eldbus_message_arguments_get(msg, "s", &txt))
+     printf("GlobalEngineChanged %s\n", txt);
+}
+
+static void
+on_name_owner_changed(void *data EINA_UNUSED, const char *bus, const char 
*old_id, const char *new_id EINA_UNUSED)
+{
+   printf("Bus=%s | old=%s | new=%s\n", bus, old_id, new_id);
+}
+
+static Eina_Bool
+finish(void *data EINA_UNUSED)
+{
+   ecore_main_loop_quit();
+   return ECORE_CALLBACK_CANCEL;
+}
+
+int
+main(void)
+{
+   Eldbus_Connection *conn;
+   Eldbus_Object *obj;
+   Eldbus_Proxy *proxy;
+   const char *address;
+
+   eina_init();
+   _client_log_dom = eina_log_domain_register("connect_address", 
EINA_COLOR_CYAN);
+   if (_client_log_dom < 0)
+     {
+        EINA_LOG_ERR("Unable to create 'client' log domain");
+        goto exit_eina;
+     }
+
+   if (!(address = getenv("IBUS_ADDRESS")))
+     {
+        ERR("IBUS_ADDRESS environment variable must be set");
+        goto exit_eina;
+     }
+
+   ecore_init();
+   eldbus_init();
+
+   printf("Connecting to %s\n", address);
+   conn = eldbus_address_connection_get(address);
+
+   if (!conn)
+     {
+        ERR("Failed to get dbus connection to address '%s'", address);
+        goto end;
+     }
+
+   printf("CONNECTED!!!\n");
+   obj = eldbus_object_get(conn, BUS, PATH);
+   proxy = eldbus_proxy_get(obj, INTERFACE);
+   eldbus_proxy_signal_handler_add(proxy, "RegistryChanged", 
_on_registry_changed, NULL);
+   eldbus_proxy_signal_handler_add(proxy, "GlobalEngineChanged", 
_on_global_engine_changed, NULL);
+
+   eldbus_name_owner_changed_callback_add(conn, BUS, on_name_owner_changed,
+                                         conn, EINA_TRUE);
+   ecore_timer_add(30, finish, NULL);
+
+   ecore_main_loop_begin();
+
+   eldbus_connection_unref(conn);
+
+end:
+   eldbus_shutdown();
+   ecore_shutdown();
+
+   eina_log_domain_unregister(_client_log_dom);
+exit_eina:
+   eina_shutdown();
+
+   return 0;
+}

-- 

------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may

Reply via email to