[Telepathy-commits] [telepathy-haze/master] HazeImChannelFactory: simplify access to priv data

Simon McVittie simon.mcvittie at collabora.co.uk
Mon Mar 23 02:44:09 PDT 2009


---
 src/im-channel-factory.c |  109 ++++++++++++++++++----------------------------
 src/im-channel-factory.h |    4 +-
 2 files changed, 46 insertions(+), 67 deletions(-)

diff --git a/src/im-channel-factory.c b/src/im-channel-factory.c
index a06ecbd..915bab0 100644
--- a/src/im-channel-factory.c
+++ b/src/im-channel-factory.c
@@ -19,6 +19,9 @@
  *
  */
 
+#include "config.h"
+#include "im-channel-factory.h"
+
 #include <string.h>
 
 #include <telepathy-glib/channel-factory-iface.h>
@@ -28,18 +31,13 @@
 
 #include "debug.h"
 #include "im-channel.h"
-#include "im-channel-factory.h"
 #include "connection.h"
 
-typedef struct _HazeImChannelFactoryPrivate HazeImChannelFactoryPrivate;
 struct _HazeImChannelFactoryPrivate {
     HazeConnection *conn;
     GHashTable *channels;
     gboolean dispose_has_run;
 };
-#define HAZE_IM_CHANNEL_FACTORY_GET_PRIVATE(o) \
-    (G_TYPE_INSTANCE_GET_PRIVATE((o), HAZE_TYPE_IM_CHANNEL_FACTORY, \
-                                 HazeImChannelFactoryPrivate))
 
 static void haze_im_channel_factory_iface_init (gpointer g_iface,
                                                 gpointer iface_data);
@@ -111,48 +109,43 @@ conversation_updated_cb (PurpleConversation *conv,
 static void
 haze_im_channel_factory_init (HazeImChannelFactory *self)
 {
-    HazeImChannelFactoryPrivate *priv =
-        HAZE_IM_CHANNEL_FACTORY_GET_PRIVATE(self);
-
-    priv->channels = g_hash_table_new_full (g_direct_hash, g_direct_equal,
-                                            NULL, g_object_unref);
+    self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+        HAZE_TYPE_IM_CHANNEL_FACTORY, HazeImChannelFactoryPrivate);
 
-    priv->conn = NULL;
-    priv->dispose_has_run = FALSE;
+    self->priv->channels = g_hash_table_new_full (NULL, NULL,
+        NULL, g_object_unref);
+    self->priv->conn = NULL;
+    self->priv->dispose_has_run = FALSE;
 }
 
 static void
 haze_im_channel_factory_dispose (GObject *object)
 {
     HazeImChannelFactory *self = HAZE_IM_CHANNEL_FACTORY (object);
-    HazeImChannelFactoryPrivate *priv =
-        HAZE_IM_CHANNEL_FACTORY_GET_PRIVATE(self);
 
-    if (priv->dispose_has_run)
+    if (self->priv->dispose_has_run)
         return;
 
-    priv->dispose_has_run = TRUE;
+    self->priv->dispose_has_run = TRUE;
 
     tp_channel_factory_iface_close_all (TP_CHANNEL_FACTORY_IFACE (object));
-    g_assert (priv->channels == NULL);
+    g_assert (self->priv->channels == NULL);
 
     if (G_OBJECT_CLASS (haze_im_channel_factory_parent_class)->dispose)
         G_OBJECT_CLASS (haze_im_channel_factory_parent_class)->dispose (object);
 }
 
 static void
-haze_im_channel_factory_get_property (GObject    *object,
-                                 guint       property_id,
-                                 GValue     *value,
-                                 GParamSpec *pspec)
+haze_im_channel_factory_get_property (GObject *object,
+                                      guint property_id,
+                                      GValue *value,
+                                      GParamSpec *pspec)
 {
-    HazeImChannelFactory *fac = HAZE_IM_CHANNEL_FACTORY (object);
-    HazeImChannelFactoryPrivate *priv =
-        HAZE_IM_CHANNEL_FACTORY_GET_PRIVATE (fac);
+    HazeImChannelFactory *self = HAZE_IM_CHANNEL_FACTORY (object);
 
     switch (property_id) {
         case PROP_CONNECTION:
-            g_value_set_object (value, priv->conn);
+            g_value_set_object (value, self->priv->conn);
             break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -161,18 +154,16 @@ haze_im_channel_factory_get_property (GObject    *object,
 }
 
 static void
-haze_im_channel_factory_set_property (GObject      *object,
-                                 guint         property_id,
-                                 const GValue *value,
-                                 GParamSpec   *pspec)
+haze_im_channel_factory_set_property (GObject *object,
+                                      guint property_id,
+                                      const GValue *value,
+                                      GParamSpec *pspec)
 {
-    HazeImChannelFactory *fac = HAZE_IM_CHANNEL_FACTORY (object);
-    HazeImChannelFactoryPrivate *priv =
-        HAZE_IM_CHANNEL_FACTORY_GET_PRIVATE (fac);
+    HazeImChannelFactory *self = HAZE_IM_CHANNEL_FACTORY (object);
 
     switch (property_id) {
         case PROP_CONNECTION:
-            priv->conn = g_value_get_object (value);
+            self->priv->conn = g_value_get_object (value);
             break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -211,18 +202,17 @@ haze_im_channel_factory_class_init (HazeImChannelFactoryClass *klass)
 static void
 im_channel_closed_cb (HazeIMChannel *chan, gpointer user_data)
 {
-    HazeImChannelFactory *fac = HAZE_IM_CHANNEL_FACTORY (user_data);
-    HazeImChannelFactoryPrivate *priv =
-        HAZE_IM_CHANNEL_FACTORY_GET_PRIVATE (fac);
+    HazeImChannelFactory *self = HAZE_IM_CHANNEL_FACTORY (user_data);
     TpHandle contact_handle;
 
-    if (priv->channels)
+    if (self->priv->channels)
     {
         g_object_get (chan, "handle", &contact_handle, NULL);
 
         DEBUG ("removing channel with handle %d", contact_handle);
 
-        g_hash_table_remove (priv->channels, GINT_TO_POINTER (contact_handle));
+        g_hash_table_remove (self->priv->channels,
+            GUINT_TO_POINTER (contact_handle));
     }
 }
 
@@ -231,22 +221,21 @@ new_im_channel (HazeImChannelFactory *self,
                 TpHandle handle,
                 TpHandle initiator)
 {
-    HazeImChannelFactoryPrivate *priv;
     TpBaseConnection *conn;
     HazeIMChannel *chan;
     char *object_path;
 
     g_assert (HAZE_IS_IM_CHANNEL_FACTORY (self));
 
-    priv = HAZE_IM_CHANNEL_FACTORY_GET_PRIVATE (self);
-    conn = (TpBaseConnection *)priv->conn;
+    conn = (TpBaseConnection *) self->priv->conn;
 
-    g_assert (!g_hash_table_lookup (priv->channels, GINT_TO_POINTER (handle)));
+    g_assert (!g_hash_table_lookup (self->priv->channels,
+          GINT_TO_POINTER (handle)));
 
     object_path = g_strdup_printf ("%s/ImChannel%u", conn->object_path, handle);
 
     chan = g_object_new (HAZE_TYPE_IM_CHANNEL,
-                         "connection", priv->conn,
+                         "connection", self->priv->conn,
                          "object-path", object_path,
                          "handle", handle,
                          "initiator-handle", initiator,
@@ -256,7 +245,7 @@ new_im_channel (HazeImChannelFactory *self,
 
     g_signal_connect (chan, "closed", G_CALLBACK (im_channel_closed_cb), self);
 
-    g_hash_table_insert (priv->channels, GINT_TO_POINTER (handle), chan);
+    g_hash_table_insert (self->priv->channels, GINT_TO_POINTER (handle), chan);
 
     tp_channel_factory_iface_emit_new_channel (self, (TpChannelIface *)chan,
             NULL);
@@ -272,10 +261,8 @@ get_im_channel (HazeImChannelFactory *self,
                 TpHandle initiator,
                 gboolean *created)
 {
-    HazeImChannelFactoryPrivate *priv =
-        HAZE_IM_CHANNEL_FACTORY_GET_PRIVATE (self);
     HazeIMChannel *chan =
-        g_hash_table_lookup (priv->channels, GINT_TO_POINTER (handle));
+        g_hash_table_lookup (self->priv->channels, GINT_TO_POINTER (handle));
 
     if (chan)
     {
@@ -295,17 +282,15 @@ get_im_channel (HazeImChannelFactory *self,
 static void
 haze_im_channel_factory_iface_close_all (TpChannelFactoryIface *iface)
 {
-    HazeImChannelFactory *fac = HAZE_IM_CHANNEL_FACTORY (iface);
-    HazeImChannelFactoryPrivate *priv =
-        HAZE_IM_CHANNEL_FACTORY_GET_PRIVATE (fac);
+    HazeImChannelFactory *self = HAZE_IM_CHANNEL_FACTORY (iface);
     GHashTable *tmp;
 
     DEBUG ("closing im channels");
 
-    if (priv->channels)
+    if (self->priv->channels)
     {
-        tmp = priv->channels;
-        priv->channels = NULL;
+        tmp = self->priv->channels;
+        self->priv->channels = NULL;
         g_hash_table_destroy (tmp);
     }
 }
@@ -342,15 +327,13 @@ haze_im_channel_factory_iface_foreach (TpChannelFactoryIface *iface,
                                        TpChannelFunc foreach,
                                        gpointer user_data)
 {
-    HazeImChannelFactory *fac = HAZE_IM_CHANNEL_FACTORY (iface);
-    HazeImChannelFactoryPrivate *priv =
-        HAZE_IM_CHANNEL_FACTORY_GET_PRIVATE (fac);
+    HazeImChannelFactory *self = HAZE_IM_CHANNEL_FACTORY (iface);
     struct _ForeachData data;
 
     data.user_data = user_data;
     data.foreach = foreach;
 
-    g_hash_table_foreach (priv->channels, _foreach_slave, &data);
+    g_hash_table_foreach (self->priv->channels, _foreach_slave, &data);
 }
 
 static TpChannelFactoryRequestStatus
@@ -363,9 +346,7 @@ haze_im_channel_factory_iface_request (TpChannelFactoryIface *iface,
                                        GError **error)
 {
     HazeImChannelFactory *self = HAZE_IM_CHANNEL_FACTORY (iface);
-    HazeImChannelFactoryPrivate *priv =
-        HAZE_IM_CHANNEL_FACTORY_GET_PRIVATE (self);
-    TpBaseConnection *base_conn = (TpBaseConnection *) priv->conn;
+    TpBaseConnection *base_conn = (TpBaseConnection *) self->priv->conn;
     TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
             base_conn, TP_HANDLE_TYPE_CONTACT);
     HazeIMChannel *chan;
@@ -489,9 +470,7 @@ haze_create_conversation (PurpleConversation *conv)
 
     HazeImChannelFactory *im_factory =
         ACCOUNT_GET_HAZE_CONNECTION (account)->im_factory;
-    HazeImChannelFactoryPrivate *priv =
-        HAZE_IM_CHANNEL_FACTORY_GET_PRIVATE (im_factory);
-    TpBaseConnection *base_conn = TP_BASE_CONNECTION (priv->conn);
+    TpBaseConnection *base_conn = TP_BASE_CONNECTION (im_factory->priv->conn);
     TpHandleRepoIface *contact_repo =
         tp_base_connection_get_handles (base_conn, TP_HANDLE_TYPE_CONTACT);
 
@@ -522,9 +501,7 @@ haze_destroy_conversation (PurpleConversation *conv)
 
     HazeImChannelFactory *im_factory =
         ACCOUNT_GET_HAZE_CONNECTION (account)->im_factory;
-    HazeImChannelFactoryPrivate *priv =
-        HAZE_IM_CHANNEL_FACTORY_GET_PRIVATE (im_factory);
-    TpBaseConnection *base_conn = TP_BASE_CONNECTION (priv->conn);
+    TpBaseConnection *base_conn = TP_BASE_CONNECTION (im_factory->priv->conn);
     TpHandleRepoIface *contact_repo =
         tp_base_connection_get_handles (base_conn, TP_HANDLE_TYPE_CONTACT);
 
diff --git a/src/im-channel-factory.h b/src/im-channel-factory.h
index 9a21a5a..251c56c 100644
--- a/src/im-channel-factory.h
+++ b/src/im-channel-factory.h
@@ -44,16 +44,18 @@ G_BEGIN_DECLS
 
 typedef struct _HazeImChannelFactory      HazeImChannelFactory;
 typedef struct _HazeImChannelFactoryClass HazeImChannelFactoryClass;
+typedef struct _HazeImChannelFactoryPrivate HazeImChannelFactoryPrivate;
 
 struct _HazeImChannelFactory {
     GObject parent;
+    HazeImChannelFactoryPrivate *priv;
 };
 
 struct _HazeImChannelFactoryClass {
     GObjectClass parent_class;
 };
 
-GType        haze_im_channel_factory_get_type    (void) G_GNUC_CONST;
+GType haze_im_channel_factory_get_type (void) G_GNUC_CONST;
 
 PurpleConversationUiOps *haze_get_conv_ui_ops (void);
 
-- 
1.5.6.5




More information about the telepathy-commits mailing list