zehortigoza pushed a commit to branch master.

commit f180d716367ec0c9f681abd97c37a2a63678bcd7
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]>
---
 Makefile.am                    |   6 ++-
 src/examples/connect-address.c | 100 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 105 insertions(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index 1b24e37..c8d850c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -97,7 +97,8 @@ EXAMPLES = \
        src/examples/server \
        src/examples/client \
        src/examples/simple-signal-emit \
-       src/examples/complex-types-client-eina-value
+       src/examples/complex-types-client-eina-value \
+       src/examples/connect-address
 
 EXAMPLES_LIBS = libeldbus.la @ECORE_LIBS@ @EINA_LIBS@
 
@@ -130,6 +131,9 @@ src_examples_simple_signal_emit_LDADD = $(EXAMPLES_LIBS)
 src_examples_complex_types_client_eina_value_SOURCES = 
src/examples/complex-types-client-eina-value.c
 src_examples_complex_types_client_eina_value_LDADD = $(EXAMPLES_LIBS)
 
+src_examples_connect_address_SOURCE = src/examples/connect-address.c
+src_examples_connect_address_LDADD = $(EXAMPLES_LIBS)
+
 if BUILD_ELDBUS_CODEGEN
 bin_PROGRAMS = src/codegen/eldbus-codegen
 src_codegen_eldbus_codegen_SOURCES = \
diff --git a/src/examples/connect-address.c b/src/examples/connect-address.c
new file mode 100644
index 0000000..11858f4
--- /dev/null
+++ b/src/examples/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;
+}

-- 

------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent 
caught up. So what steps can you take to put your SQL databases under 
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk

Reply via email to