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

Alberto Mardegan alberto.mardegan at nokia.com
Mon Nov 17 00:05:20 PST 2008


Add function to create a channel request from a GHashTable of desired
properties.
Use it from mcd-account.c when requesting a channel.
---
 src/mcd-account.c |   57 +++++++++++++++++++++++++++++++++++++++--------
 src/mcd-channel.c |   63 ++++++++++++++++++++++++++++++++++++++++------------
 src/mcd-channel.h |    4 +-
 3 files changed, 97 insertions(+), 27 deletions(-)

diff --git a/src/mcd-account.c b/src/mcd-account.c
index 8748117..22a47df 100644
--- a/src/mcd-account.c
+++ b/src/mcd-account.c
@@ -33,6 +33,7 @@
 #include <glib/gi18n.h>
 #include <glib/gstdio.h>
 #include <telepathy-glib/gtypes.h>
+#include <telepathy-glib/interfaces.h>
 #include <telepathy-glib/svc-generic.h>
 #include <telepathy-glib/util.h>
 
@@ -153,6 +154,14 @@ enum
 guint _mcd_account_signals[LAST_SIGNAL] = { 0 };
 
 static void
+prop_value_free (gpointer data)
+{
+  GValue *value = (GValue *) data;
+  g_value_unset (value);
+  g_slice_free (GValue, value);
+}
+
+static void
 process_online_request (gpointer key, gpointer cb_userdata, gpointer userdata)
 {
     McdOnlineRequestCb callback = key;
@@ -2179,17 +2188,45 @@ mcd_account_request_channel_nmc4 (McdAccount *account,
 				  GError **error)
 {
     McdChannel *channel;
+    GHashTable *properties;
+    GValue *value;
+
+    properties = g_hash_table_new_full (g_str_hash, g_str_equal,
+                                        NULL, prop_value_free);
 
-    /* The channel is temporary */
-    channel = mcd_channel_new (NULL,
-			       req->channel_type,
-			       req->channel_handle,
-			       req->channel_handle_type,
-			       TRUE, /* outgoing */
-			       req->requestor_serial,
-			       req->requestor_client_id);
-    _mcd_channel_set_target_id (channel, req->channel_handle_string);
-    mcd_channel_set_status (channel, MCD_CHANNEL_NO_PROXY);
+    value = g_slice_new0 (GValue);
+    g_value_init (value, G_TYPE_STRING);
+    g_value_set_string (value, req->channel_type);
+    g_hash_table_insert (properties, TP_IFACE_CHANNEL ".ChannelType", value);
+
+    if (req->channel_handle_string)
+    {
+        value = g_slice_new0 (GValue);
+        g_value_init (value, G_TYPE_STRING);
+        g_value_set_string (value, req->channel_handle_string);
+        g_hash_table_insert (properties, TP_IFACE_CHANNEL ".TargetID", value);
+    }
+
+    if (req->channel_handle)
+    {
+        value = g_slice_new0 (GValue);
+        g_value_init (value, G_TYPE_UINT);
+        g_value_set_uint (value, req->channel_handle);
+        g_hash_table_insert (properties, TP_IFACE_CHANNEL ".TargetHandle",
+                             value);
+    }
+
+    value = g_slice_new0 (GValue);
+    g_value_init (value, G_TYPE_UINT);
+    g_value_set_uint (value, req->channel_handle_type);
+    g_hash_table_insert (properties, TP_IFACE_CHANNEL ".TargetHandleType",
+                         value);
+
+    channel = mcd_channel_new_request (properties);
+    g_object_set ((GObject *)channel,
+                  "requestor-serial", req->requestor_serial,
+                  "requestor-client-id", req->requestor_client_id,
+                  NULL);
     g_signal_connect (channel, "status-changed",
                       G_CALLBACK (on_channel_status_changed), account);
 
diff --git a/src/mcd-channel.c b/src/mcd-channel.c
index 01d9587..7c67f73 100644
--- a/src/mcd-channel.c
+++ b/src/mcd-channel.c
@@ -36,6 +36,7 @@
 
 #include <glib/gi18n.h>
 #include <telepathy-glib/interfaces.h>
+#include <telepathy-glib/dbus.h>
 
 #include "mcd-channel.h"
 #include "mcd-enum-types.h"
@@ -1145,20 +1146,6 @@ _mcd_channel_details_free (GPtrArray *channels)
 }
 
 /*
- * _mcd_channel_set_target_id:
- * @channel: the #McdChannel.
- * @target_id: string representing target contact.
- */
-void
-_mcd_channel_set_target_id (McdChannel *channel,
-                            const gchar *target_id)
-{
-    g_return_if_fail (MCD_IS_CHANNEL (channel));
-    g_object_set_data_full ((GObject *)channel, "TargetID",
-                            g_strdup (target_id), g_free);
-}
-
-/*
  * _mcd_channel_get_target_id:
  * @channel: the #McdChannel.
  *
@@ -1167,8 +1154,12 @@ _mcd_channel_set_target_id (McdChannel *channel,
 const gchar *
 _mcd_channel_get_target_id (McdChannel *channel)
 {
+    GHashTable *properties;
+
     g_return_val_if_fail (MCD_IS_CHANNEL (channel), NULL);
-    return g_object_get_data ((GObject *)channel, "TargetID");
+    properties = g_object_get_data ((GObject *)channel, "_ReqProps");
+    return properties ?
+        tp_asv_get_string (properties, TP_IFACE_CHANNEL ".TargetID") : NULL;
 }
 
 /*
@@ -1203,3 +1194,45 @@ _mcd_channel_get_error (McdChannel *channel)
     return g_object_get_data ((GObject *)channel, "Error");
 }
 
+/**
+ * mcd_channel_new_request:
+ * @properties: a #GHashTable of desired channel properties.
+ *
+ * Create a #McdChannel object holding the given properties. The object can
+ * then be used to intiate a channel request, by passing it to
+ * mcd_connection_request_channel() on a connection in connected state.
+ *
+ * Returns: a newly created #McdChannel.
+ */
+McdChannel *
+mcd_channel_new_request (GHashTable *properties)
+{
+    McdChannel *channel;
+    guint handle;
+    TpHandleType handle_type;
+    const gchar *channel_type, *target_id;
+
+    channel_type = tp_asv_get_string (properties,
+                                      TP_IFACE_CHANNEL ".ChannelType");
+    target_id = tp_asv_get_string (properties,
+                                   TP_IFACE_CHANNEL ".TargetID");
+    handle = tp_asv_get_uint32 (properties,
+                                TP_IFACE_CHANNEL ".TargetHandle", NULL);
+    handle_type =
+        tp_asv_get_uint32 (properties,
+                           TP_IFACE_CHANNEL ".TargetHandleType", NULL);
+
+    channel = g_object_new (MCD_TYPE_CHANNEL,
+                            "type", channel_type,
+                            "handle", handle,
+                            "handle-type", handle_type,
+                            "outgoing", TRUE,
+                            NULL);
+    g_object_set_data_full ((GObject *)channel, "_ReqProps",
+                            g_hash_table_ref (properties),
+                            (GDestroyNotify)g_hash_table_unref);
+    mcd_channel_set_status (channel, MCD_CHANNEL_NO_PROXY);
+
+    return channel;
+}
+
diff --git a/src/mcd-channel.h b/src/mcd-channel.h
index aa82650..c3971f4 100644
--- a/src/mcd-channel.h
+++ b/src/mcd-channel.h
@@ -96,6 +96,8 @@ McdChannel *mcd_channel_new_from_path (TpConnection *connection,
                                        const gchar *object_path,
                                        const gchar *type, guint handle,
                                        TpHandleType handle_type);
+McdChannel *mcd_channel_new_request (GHashTable *properties);
+
 gboolean mcd_channel_set_object_path (McdChannel *channel,
                                       TpConnection *connection,
                                       const gchar *object_path);
@@ -126,8 +128,6 @@ GHashTable *_mcd_channel_get_immutable_properties (McdChannel *channel);
 GPtrArray *_mcd_channel_details_build_from_list (GList *channels);
 void _mcd_channel_details_free (GPtrArray *channels);
 
-void _mcd_channel_set_target_id (McdChannel *channel,
-                                 const gchar *target_id);
 const gchar *_mcd_channel_get_target_id (McdChannel *channel);
 
 void _mcd_channel_set_error (McdChannel *channel, GError *error);
-- 
1.5.6.5




More information about the Telepathy-commits mailing list