[telepathy-mission-control/master] fd.o #23651 (partial): prefer the PreferredHandler when a request approves a pending dispatch operation

Simon McVittie simon.mcvittie at collabora.co.uk
Tue Oct 20 06:40:32 PDT 2009


---
 src/mcd-dispatch-operation-priv.h |    2 +-
 src/mcd-dispatch-operation.c      |   28 +++++++++++++++++++++++++---
 src/mcd-dispatcher.c              |    5 ++++-
 3 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/src/mcd-dispatch-operation-priv.h b/src/mcd-dispatch-operation-priv.h
index 4b37db9..4654cdb 100644
--- a/src/mcd-dispatch-operation-priv.h
+++ b/src/mcd-dispatch-operation-priv.h
@@ -59,7 +59,7 @@ G_GNUC_INTERNAL const gchar *_mcd_dispatch_operation_get_path
 G_GNUC_INTERNAL GHashTable *_mcd_dispatch_operation_get_properties
     (McdDispatchOperation *operation);
 G_GNUC_INTERNAL void _mcd_dispatch_operation_approve
-    (McdDispatchOperation *self);
+    (McdDispatchOperation *self, const gchar *preferred_handler);
 
 #define MCD_TYPE_DISPATCH_OPERATION         (_mcd_dispatch_operation_get_type ())
 #define MCD_DISPATCH_OPERATION(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), MCD_TYPE_DISPATCH_OPERATION, McdDispatchOperation))
diff --git a/src/mcd-dispatch-operation.c b/src/mcd-dispatch-operation.c
index 0a8d75e..acce61b 100644
--- a/src/mcd-dispatch-operation.c
+++ b/src/mcd-dispatch-operation.c
@@ -1147,11 +1147,32 @@ mcd_dispatch_operation_check_handle_with (McdDispatchOperation *self,
 }
 
 void
-_mcd_dispatch_operation_approve (McdDispatchOperation *self)
+_mcd_dispatch_operation_approve (McdDispatchOperation *self,
+                                 const gchar *preferred_handler)
 {
     g_return_if_fail (MCD_IS_DISPATCH_OPERATION (self));
 
-    DEBUG ("%s/%p", self->priv->unique_name, self);
+    /* NULL-safety: treat both NULL and "" as "unspecified" */
+    if (preferred_handler == NULL)
+        preferred_handler = "";
+
+    DEBUG ("%s/%p (preferred handler: '%s')", self->priv->unique_name, self,
+           preferred_handler);
+
+    if (!g_str_has_prefix (preferred_handler, MCD_CLIENT_BASE_NAME) ||
+        !tp_dbus_check_valid_bus_name (preferred_handler,
+                                       TP_DBUS_NAME_TYPE_WELL_KNOWN, NULL))
+    {
+        DEBUG ("preferred handler name '%s' is bad, treating as unspecified",
+               preferred_handler);
+        preferred_handler = "";
+    }
+
+    if (preferred_handler[0] != '\0')
+    {
+        self->priv->handler = g_strdup (preferred_handler +
+                                        MCD_CLIENT_BASE_NAME_LEN);
+    }
 
     if (self->priv->ado_pending > 0
         || self->priv->awaiting_approval)
@@ -1159,7 +1180,8 @@ _mcd_dispatch_operation_approve (McdDispatchOperation *self)
         /* the existing channel is waiting for approval; but since the
          * same channel has been requested, the approval operation must
          * terminate */
-        if (!mcd_dispatch_operation_check_handle_with (self, NULL, NULL))
+        if (!mcd_dispatch_operation_check_handle_with (self, preferred_handler,
+                                                       NULL))
         {
             return;
         }
diff --git a/src/mcd-dispatcher.c b/src/mcd-dispatcher.c
index 5cd47a2..e11e121 100644
--- a/src/mcd-dispatcher.c
+++ b/src/mcd-dispatcher.c
@@ -1853,6 +1853,9 @@ _mcd_dispatcher_add_channel_request (McdDispatcher *dispatcher,
     }
     else
     {
+        const gchar *preferred_handler =
+            _mcd_channel_get_request_preferred_handler (request);
+
         _mcd_channel_set_request_proxy (request, channel);
         if (status == MCD_CHANNEL_STATUS_DISPATCHING)
         {
@@ -1862,7 +1865,7 @@ _mcd_dispatcher_add_channel_request (McdDispatcher *dispatcher,
             g_return_if_fail (op != NULL);
 
             DEBUG ("channel %p is in CDO %p", channel, op);
-            _mcd_dispatch_operation_approve (op);
+            _mcd_dispatch_operation_approve (op, preferred_handler);
         }
         DEBUG ("channel %p is proxying %p", request, channel);
     }
-- 
1.5.6.5




More information about the telepathy-commits mailing list