[Telepathy-commits] [telepathy-mission-control/master] Add mcd_channel_new_from_properties()

Alberto Mardegan alberto.mardegan at nokia.com
Mon Feb 2 00:00:14 PST 2009


This function creates a channel with an object path and the given HT of
properties.
---
 src/mcd-channel.c    |   51 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/mcd-channel.h    |    4 +++
 src/mcd-connection.c |   26 ++----------------------
 3 files changed, 58 insertions(+), 23 deletions(-)

diff --git a/src/mcd-channel.c b/src/mcd-channel.c
index 9445d19..9f8ed2c 100644
--- a/src/mcd-channel.c
+++ b/src/mcd-channel.c
@@ -798,6 +798,57 @@ mcd_channel_new (TpChannel * tp_chan,
 }
 
 /**
+ * mcd_channel_new_from_properties:
+ * @connection: the #TpConnection on which the channel exists.
+ * @object_path: the D-Bus object path of an existing channel.
+ * @properties: #GHashTable of immutable channel properties.
+ *
+ * Creates a #McdChannel with an associated #TpChannel proxy for the channel
+ * located at @object_path.
+ *
+ * Returns: a new #McdChannel if the #TpChannel was created successfully, %NULL
+ * otherwise.
+ */
+McdChannel *
+mcd_channel_new_from_properties (TpConnection *connection,
+                                 const gchar *object_path,
+                                 const GHashTable *properties)
+{
+    McdChannel *channel;
+    const gchar *type;
+    guint handle_type, handle;
+
+    type = tp_asv_get_string (properties, TP_IFACE_CHANNEL ".ChannelType");
+
+    handle_type = tp_asv_get_uint32 (properties,
+                                     TP_IFACE_CHANNEL ".TargetHandleType",
+                                     NULL);
+    handle = tp_asv_get_uint32 (properties,
+                                TP_IFACE_CHANNEL ".TargetHandle", NULL);
+    g_debug ("%s: type = %s, handle_type = %u, handle = %u", G_STRFUNC,
+             type, handle_type, handle);
+
+    channel = g_object_new (MCD_TYPE_CHANNEL,
+                            "type", type,
+                            "handle", handle,
+                            "handle-type", handle_type,
+                            NULL);
+    if (mcd_channel_set_object_path (channel, connection, object_path))
+    {
+        _mcd_channel_set_immutable_properties
+            (channel,
+             g_boxed_copy (TP_HASH_TYPE_QUALIFIED_PROPERTY_VALUE_MAP,
+                           properties));
+        return channel;
+    }
+    else
+    {
+        g_object_unref (channel);
+        return NULL;
+    }
+}
+
+/**
  * mcd_channel_new_from_path:
  * @connection: the #TpConnection on which the channel exists.
  * @object_path: the D-Bus object path of an existing channel.
diff --git a/src/mcd-channel.h b/src/mcd-channel.h
index 99cdfe4..5f3dbc1 100644
--- a/src/mcd-channel.h
+++ b/src/mcd-channel.h
@@ -95,6 +95,10 @@ McdChannel *mcd_channel_new (TpChannel *channel,
 			     guint requestor_serial,
                              const gchar *requestor_client_id)
     G_GNUC_DEPRECATED;
+McdChannel *
+mcd_channel_new_from_properties (TpConnection *connection,
+                                 const gchar *object_path,
+                                 const GHashTable *properties);
 McdChannel *mcd_channel_new_from_path (TpConnection *connection,
                                        const gchar *object_path,
                                        const gchar *type, guint handle,
diff --git a/src/mcd-connection.c b/src/mcd-connection.c
index 0d02a85..a49b797 100644
--- a/src/mcd-connection.c
+++ b/src/mcd-connection.c
@@ -1229,10 +1229,9 @@ on_new_channels (TpConnection *proxy, const GPtrArray *channels,
     for (i = 0; i < channels->len; i++)
     {
         GValueArray *va;
-        const gchar *object_path, *channel_type;
+        const gchar *object_path;
         GHashTable *props;
         GValue *value;
-        guint handle_type, handle;
 
         va = g_ptr_array_index (channels, i);
         object_path = g_value_get_boxed (va->values);
@@ -1248,29 +1247,10 @@ on_new_channels (TpConnection *proxy, const GPtrArray *channels,
         channel = find_channel_by_path (connection, object_path);
         if (!channel)
         {
-            /* get channel type, handle type, handle */
-            value = g_hash_table_lookup (props,
-                                         TP_IFACE_CHANNEL ".ChannelType");
-            channel_type = value ? g_value_get_string (value) : NULL;
-
-            value = g_hash_table_lookup (props,
-                                         TP_IFACE_CHANNEL ".TargetHandleType");
-            handle_type = value ? g_value_get_uint (value) : 0;
-
-            value = g_hash_table_lookup (props,
-                                         TP_IFACE_CHANNEL ".TargetHandle");
-            handle = value ? g_value_get_uint (value) : 0;
-
-            g_debug ("%s: type = %s, handle_type = %u, handle = %u", G_STRFUNC,
-                     channel_type, handle_type, handle);
-            channel = mcd_channel_new_from_path (proxy, object_path,
-                                                 channel_type,
-                                                 handle, handle_type);
+            channel = mcd_channel_new_from_properties (proxy, object_path,
+                                                       props);
             if (G_UNLIKELY (!channel)) continue;
 
-            /* properties need to be copied */
-            props = g_value_dup_boxed (va->values + 1);
-            _mcd_channel_set_immutable_properties (channel, props);
             mcd_operation_take_mission (MCD_OPERATION (connection),
                                         MCD_MISSION (channel));
         }
-- 
1.5.6.5




More information about the Telepathy-commits mailing list