[empathy/next] Observer high level API: now singular



commit bb5117c95458a61779c41bef807fad9f6d3db3fa
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date:   Mon Jan 27 13:51:22 2014 +0100

    Observer high level API: now singular

 libempathy-gtk/empathy-log-window.c   |   58 ++++++++++++++------------------
 libempathy/empathy-auth-factory.c     |   31 +++--------------
 libempathy/empathy-chatroom-manager.c |   56 ++++++++++++++++----------------
 src/empathy-call-observer.c           |   42 ++----------------------
 4 files changed, 62 insertions(+), 125 deletions(-)
---
diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c
index 9b58444..8f1f9b3 100644
--- a/libempathy-gtk/empathy-log-window.c
+++ b/libempathy-gtk/empathy-log-window.c
@@ -991,50 +991,43 @@ on_call_ended (TpChannel *channel,
 }
 
 static void
-observe_channels (TpSimpleObserver *observer,
+observe_channel (TpSimpleObserver *observer,
     TpAccount *account,
     TpConnection *connection,
-    GList *channels,
+    TpChannel *channel,
     TpChannelDispatchOperation *dispatch_operation,
     GList *requests,
     TpObserveChannelContext *context,
     gpointer user_data)
 {
   EmpathyLogWindow *self = user_data;
+  const gchar *type = tp_channel_get_channel_type (channel);
 
-  GList *l;
-
-  for (l = channels; l != NULL; l = g_list_next (l))
+  if (!tp_strdiff (type, TP_IFACE_CHANNEL_TYPE_TEXT))
     {
-      TpChannel *channel = l->data;
-      const gchar *type = tp_channel_get_channel_type (channel);
-
-      if (!tp_strdiff (type, TP_IFACE_CHANNEL_TYPE_TEXT))
-        {
-          TpTextChannel *text_channel = TP_TEXT_CHANNEL (channel);
+      TpTextChannel *text_channel = TP_TEXT_CHANNEL (channel);
 
-          g_hash_table_insert (self->priv->channels,
-              g_object_ref (channel), g_object_ref (account));
+      g_hash_table_insert (self->priv->channels,
+          g_object_ref (channel), g_object_ref (account));
 
-          tp_g_signal_connect_object (text_channel, "message-sent",
-              G_CALLBACK (on_msg_sent), self, 0);
-          tp_g_signal_connect_object (text_channel, "message-received",
-              G_CALLBACK (on_msg_received), self, 0);
-          tp_g_signal_connect_object (channel, "invalidated",
-              G_CALLBACK (on_channel_ended), self, 0);
-        }
-      else if (!tp_strdiff (type, TP_IFACE_CHANNEL_TYPE_CALL1))
-        {
-          g_hash_table_insert (self->priv->channels,
-              g_object_ref (channel), g_object_ref (account));
+      tp_g_signal_connect_object (text_channel, "message-sent",
+          G_CALLBACK (on_msg_sent), self, 0);
+      tp_g_signal_connect_object (text_channel, "message-received",
+          G_CALLBACK (on_msg_received), self, 0);
+      tp_g_signal_connect_object (channel, "invalidated",
+          G_CALLBACK (on_channel_ended), self, 0);
+    }
+  else if (!tp_strdiff (type, TP_IFACE_CHANNEL_TYPE_CALL1))
+    {
+      g_hash_table_insert (self->priv->channels,
+          g_object_ref (channel), g_object_ref (account));
 
-          tp_g_signal_connect_object (channel, "invalidated",
-              G_CALLBACK (on_call_ended), self, 0);
-        }
-      else
-        {
-          g_warning ("Unknown channel type: %s", type);
-        }
+      tp_g_signal_connect_object (channel, "invalidated",
+          G_CALLBACK (on_call_ended), self, 0);
+    }
+  else
+    {
+      g_warning ("Unknown channel type: %s", type);
     }
 
   tp_observe_channel_context_accept (context);
@@ -1048,8 +1041,7 @@ log_window_create_observer (EmpathyLogWindow *self)
   am = tp_account_manager_dup ();
 
   self->priv->observer = tp_simple_observer_new_with_am (am, TRUE, "LogWindow",
-      TRUE, observe_channels,
-      g_object_ref (self), g_object_unref);
+      TRUE, observe_channel, g_object_ref (self), g_object_unref);
 
   self->priv->channels = g_hash_table_new_full (g_direct_hash, g_direct_equal,
       g_object_unref, g_object_unref);
diff --git a/libempathy/empathy-auth-factory.c b/libempathy/empathy-auth-factory.c
index ffab08d..9ce73bd 100644
--- a/libempathy/empathy-auth-factory.c
+++ b/libempathy/empathy-auth-factory.c
@@ -249,30 +249,14 @@ server_sasl_handler_ready_cb (GObject *source,
 
 static gboolean
 common_checks (EmpathyAuthFactory *self,
-    GList *channels,
+    TpChannel *channel,
     gboolean observe,
     GError **error)
 {
   EmpathyAuthFactoryPriv *priv = GET_PRIV (self);
-  TpChannel *channel;
   const GError *dbus_error;
   EmpathyServerSASLHandler *handler;
 
-  /* there can't be more than one ServerTLSConnection or
-   * ServerAuthentication channels at the same time, for the same
-   * connection/account.
-   */
-  if (g_list_length (channels) != 1)
-    {
-      g_set_error (error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
-          "Can't %s more than one ServerTLSConnection or ServerAuthentication "
-          "channel for the same connection.", observe ? "observe" : "handle");
-
-      return FALSE;
-    }
-
-  channel = channels->data;
-
   if (tp_channel_get_channel_type_id (channel) !=
       TP_IFACE_QUARK_CHANNEL_TYPE_SERVER_AUTHENTICATION1)
     {
@@ -333,7 +317,7 @@ handle_channels (TpBaseClient *handler,
 
   DEBUG ("Handle TLS or SASL carrier channels.");
 
-  if (!common_checks (self, channels, FALSE, &error))
+  if (!common_checks (self, channels->data, FALSE, &error))
     {
       DEBUG ("Failed checks: %s", error->message);
       tp_handle_channels_context_fail (context, error);
@@ -507,22 +491,21 @@ uoa_claim_cb (GObject *source,
 #endif /* HAVE_UOA */
 
 static void
-observe_channels (TpBaseClient *client,
+observe_channel (TpBaseClient *client,
     TpAccount *account,
     TpConnection *connection,
-    GList *channels,
+    TpChannel *channel,
     TpChannelDispatchOperation *dispatch_operation,
     GList *requests,
     TpObserveChannelContext *context)
 {
   EmpathyAuthFactory *self = EMPATHY_AUTH_FACTORY (client);
-  TpChannel *channel;
   GError *error = NULL;
   ObserveChannelsData *data;
 
   DEBUG ("New auth channel to observe");
 
-  if (!common_checks (self, channels, TRUE, &error))
+  if (!common_checks (self, channel, TRUE, &error))
     {
       DEBUG ("Failed checks: %s", error->message);
       tp_observe_channel_context_fail (context, error);
@@ -531,8 +514,6 @@ observe_channels (TpBaseClient *client,
     }
 
   /* The common checks above have checked this is fine. */
-  channel = channels->data;
-
   data = g_slice_new0 (ObserveChannelsData);
   data->self = self;
   data->context = g_object_ref (context);
@@ -727,7 +708,7 @@ empathy_auth_factory_class_init (EmpathyAuthFactoryClass *klass)
   oclass->dispose = empathy_auth_factory_dispose;
 
   base_client_cls->handle_channels = handle_channels;
-  base_client_cls->observe_channels = observe_channels;
+  base_client_cls->observe_channel = observe_channel;
 
   g_type_class_add_private (klass, sizeof (EmpathyAuthFactoryPriv));
 
diff --git a/libempathy/empathy-chatroom-manager.c b/libempathy/empathy-chatroom-manager.c
index 81db302..78e5a04 100644
--- a/libempathy/empathy-chatroom-manager.c
+++ b/libempathy/empathy-chatroom-manager.c
@@ -40,10 +40,10 @@
 
 static EmpathyChatroomManager *chatroom_manager_singleton = NULL;
 
-static void observe_channels_cb (TpSimpleObserver *observer,
+static void observe_channel_cb (TpSimpleObserver *observer,
     TpAccount *account,
     TpConnection *connection,
-    GList *channels,
+    TpChannel *channel,
     TpChannelDispatchOperation *dispatch_operation,
     GList *requests,
     TpObserveChannelContext *context,
@@ -586,7 +586,7 @@ empathy_chatroom_manager_constructor (GType type,
 
   /* Setup a room observer */
   priv->observer = tp_simple_observer_new_with_am (priv->account_manager, TRUE,
-      "Empathy.ChatroomManager", TRUE, observe_channels_cb, self, NULL);
+      "Empathy.ChatroomManager", TRUE, observe_channel_cb, self, NULL);
 
   tp_base_client_take_observer_filter (priv->observer, tp_asv_new (
       TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
@@ -861,47 +861,47 @@ chatroom_manager_chat_invalidated_cb (EmpathyTpChat *chat,
 }
 
 static void
-observe_channels_cb (TpSimpleObserver *observer,
+observe_channel_cb (TpSimpleObserver *observer,
     TpAccount *account,
     TpConnection *connection,
-    GList *channels,
+    TpChannel *channel,
     TpChannelDispatchOperation *dispatch_operation,
     GList *requests,
     TpObserveChannelContext *context,
     gpointer user_data)
 {
   EmpathyChatroomManager *self = user_data;
-  GList *l;
+  EmpathyTpChat *tp_chat;
+  const gchar *roomname;
+  EmpathyChatroom *chatroom;
 
-  for (l = channels; l != NULL; l = g_list_next (l))
+  if (tp_proxy_get_invalidated (channel) == NULL ||
+      !EMPATHY_IS_TP_CHAT (channel))
     {
-      EmpathyTpChat *tp_chat = l->data;
-      const gchar *roomname;
-      EmpathyChatroom *chatroom;
+      GError e = { TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
+          "Not a text channel" };
 
-      if (tp_proxy_get_invalidated ((TpChannel *) tp_chat) != NULL)
-        continue;
+      tp_observe_channel_context_fail (context, &e);
+    }
 
-      if (!EMPATHY_IS_TP_CHAT (tp_chat))
-        continue;
+  tp_chat = EMPATHY_TP_CHAT (channel);
 
-      roomname = empathy_tp_chat_get_id (tp_chat);
-      chatroom = empathy_chatroom_manager_find (self, account, roomname);
+  roomname = empathy_tp_chat_get_id (tp_chat);
+  chatroom = empathy_chatroom_manager_find (self, account, roomname);
 
-      if (chatroom == NULL)
-        {
-          chatroom = empathy_chatroom_new_full (account, roomname, roomname,
-            FALSE);
-          empathy_chatroom_manager_add (self, chatroom);
-          g_object_unref (chatroom);
-        }
+  if (chatroom == NULL)
+    {
+      chatroom = empathy_chatroom_new_full (account, roomname, roomname,
+        FALSE);
+      empathy_chatroom_manager_add (self, chatroom);
+      g_object_unref (chatroom);
+    }
 
-      empathy_chatroom_set_tp_chat (chatroom, tp_chat);
+  empathy_chatroom_set_tp_chat (chatroom, tp_chat);
 
-      g_signal_connect (tp_chat, "invalidated",
-        G_CALLBACK (chatroom_manager_chat_invalidated_cb),
-        self);
-    }
+  g_signal_connect (tp_chat, "invalidated",
+    G_CALLBACK (chatroom_manager_chat_invalidated_cb),
+    self);
 
   tp_observe_channel_context_accept (context);
 }
diff --git a/src/empathy-call-observer.c b/src/empathy-call-observer.c
index 85c31aa..524b2a4 100644
--- a/src/empathy-call-observer.c
+++ b/src/empathy-call-observer.c
@@ -132,28 +132,6 @@ display_reject_notification (EmpathyCallObserver *self,
   g_object_unref (emp_contact);
 }
 
-static TpChannel *
-find_main_channel (GList *channels)
-{
-  GList *l;
-
-  for (l = channels; l != NULL; l = g_list_next (l))
-    {
-      TpChannel *channel = l->data;
-      GQuark channel_type;
-
-      if (tp_proxy_get_invalidated (channel) != NULL)
-        continue;
-
-      channel_type = tp_channel_get_channel_type_id (channel);
-
-      if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_CALL1)
-        return channel;
-    }
-
-  return NULL;
-}
-
 static gboolean
 has_ongoing_calls (EmpathyCallObserver *self)
 {
@@ -200,31 +178,18 @@ out:
 }
 
 static void
-observe_channels (TpSimpleObserver *observer,
+observe_channel (TpSimpleObserver *observer,
     TpAccount *account,
     TpConnection *connection,
-    GList *channels,
+    TpChannel *channel,
     TpChannelDispatchOperation *dispatch_operation,
     GList *requests,
     TpObserveChannelContext *context,
     gpointer user_data)
 {
   EmpathyCallObserver *self = EMPATHY_CALL_OBSERVER (user_data);
-  TpChannel *channel;
   const GError *error;
 
-  channel = find_main_channel (channels);
-  if (channel == NULL)
-    {
-      GError err = { TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
-          "Unknown channel type" };
-
-      DEBUG ("Didn't find any Call channel; ignoring");
-
-      tp_observe_channel_context_fail (context, &err);
-      return;
-    }
-
   /* Autoreject if there are other ongoing calls */
   if (has_ongoing_calls (self))
     {
@@ -320,8 +285,7 @@ empathy_call_observer_init (EmpathyCallObserver *self)
   am = tp_account_manager_dup ();
 
   self->priv->observer = tp_simple_observer_new_with_am (am, TRUE,
-      "Empathy.CallObserver", FALSE,
-      observe_channels, self, NULL);
+      "Empathy.CallObserver", FALSE, observe_channel, self, NULL);
 
   /* Observe Call channels */
   tp_base_client_take_observer_filter (self->priv->observer,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]