From 16cd619726f6e7f605817f3cf32bf1a6fb712214 Mon Sep 17 00:00:00 2001
From: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
Date: Thu, 22 Jan 2009 12:37:44 -0500
Subject: [PATCH] Implement NameOwnerChanged signal callback

---
 sflphone-gtk/src/dbus.c | 40 +++++++++++++++++++++++++++++++++++++---
 1 file changed, 37 insertions(+), 3 deletions(-)

diff --git a/sflphone-gtk/src/dbus.c b/sflphone-gtk/src/dbus.c
index 9aa6a94493..68e0e2d423 100644
--- a/sflphone-gtk/src/dbus.c
+++ b/sflphone-gtk/src/dbus.c
@@ -39,6 +39,7 @@ DBusGConnection * connection;
 DBusGProxy * callManagerProxy;
 DBusGProxy * configurationManagerProxy;
 DBusGProxy * instanceProxy;
+DBusGProxy * nameOwnerProxy;
 
 static void  
 incoming_call_cb (DBusGProxy *proxy UNUSED,
@@ -172,18 +173,32 @@ error_alert(DBusGProxy *proxy UNUSED,
   sflphone_throw_exception( errCode );
 }
 
+
+static void nameOwnerChanged(DBusGProxy *proxy, char *name, char *old_owner, char *new_owner, gpointer data )
+{
+
+    g_print("******************************************************************\n");
+    g_print("Owner name of the service %s changed from %s to %s\n", name, old_owner, new_owner);
+    g_print("******************************************************************\n");
+
+    if (strcmp(name, "org.sflphone.SFLphone")!=0)   return;
+
+}
+
 gboolean 
 dbus_connect ()
 {
 
   GError *error = NULL;
   connection = NULL;
+  instanceProxy = NULL;
+  nameOwnerProxy = NULL;
   
   g_type_init ();
 
   connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
   
-  if (connection == NULL)
+  if (error)
   {
     g_printerr ("Failed to open connection to bus: %s\n",
                 error->message);
@@ -191,6 +206,25 @@ dbus_connect ()
     return FALSE;
   }
 
+    
+    nameOwnerProxy = dbus_g_proxy_new_for_name_owner( connection,
+                                                    DBUS_SERVICE_DBUS,
+                                                    DBUS_PATH_DBUS,
+                                                    DBUS_INTERFACE_DBUS,
+                                                    &error);
+
+    if( nameOwnerProxy==NULL)
+    {
+        g_printerr ("Failed to get proxy to NameOwner\n");
+        return FALSE;
+    }
+
+    dbus_g_proxy_add_signal( nameOwnerProxy, "NameOwnerChanged",
+                G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+    dbus_g_proxy_connect_signal (nameOwnerProxy, "NameOwnerChanged",
+                G_CALLBACK (nameOwnerChanged), NULL, NULL);
+
+
   /* Create a proxy object for the "bus driver" (name "org.freedesktop.DBus") */
   
   instanceProxy = dbus_g_proxy_new_for_name_owner (connection,
@@ -198,7 +232,7 @@ dbus_connect ()
                                      "/org/sflphone/SFLphone/Instance",
                                      "org.sflphone.SFLphone.Instance",
                                      &error);
-  if (!instanceProxy) 
+  if (instanceProxy==NULL) 
   {
     g_printerr ("Failed to get proxy to Instance\n");
     return FALSE;
@@ -212,7 +246,7 @@ dbus_connect ()
                                      "/org/sflphone/SFLphone/CallManager",
                                      "org.sflphone.SFLphone.CallManager",
                                      &error);
-  if (!callManagerProxy) 
+  if (callManagerProxy==NULL) 
   {
     g_printerr ("Failed to get proxy to CallManagers\n");
     return FALSE;
-- 
GitLab