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



commit ee55da48e6b6cd42e5d7e5fe2b6fa21503e5ead8
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date:   Mon Jan 27 14:01:23 2014 +0100

    Handler high level API: now singular

 libempathy/empathy-auth-factory.c |   12 +++------
 libempathy/empathy-ft-factory.c   |   23 +++-------------
 src/empathy-call-factory.c        |   50 ++++++++++++-------------------------
 src/empathy-chat-manager.c        |   27 ++++---------------
 4 files changed, 31 insertions(+), 81 deletions(-)
---
diff --git a/libempathy/empathy-auth-factory.c b/libempathy/empathy-auth-factory.c
index 70cbaf6..91d4fab 100644
--- a/libempathy/empathy-auth-factory.c
+++ b/libempathy/empathy-auth-factory.c
@@ -302,22 +302,21 @@ common_checks (EmpathyAuthFactory *self,
 }
 
 static void
-handle_channels (TpBaseClient *handler,
+handle_channel (TpBaseClient *handler,
     TpAccount *account,
     TpConnection *connection,
-    GList *channels,
+    TpChannel *channel,
     GList *requests_satisfied,
     gint64 user_action_time,
     TpHandleChannelContext *context)
 {
-  TpChannel *channel;
   GError *error = NULL;
   EmpathyAuthFactory *self = EMPATHY_AUTH_FACTORY (handler);
   HandlerContextData *data;
 
   DEBUG ("Handle TLS or SASL carrier channels.");
 
-  if (!common_checks (self, channels->data, FALSE, &error))
+  if (!common_checks (self, channel, FALSE, &error))
     {
       DEBUG ("Failed checks: %s", error->message);
       tp_handle_channel_context_fail (context, error);
@@ -325,9 +324,6 @@ handle_channels (TpBaseClient *handler,
       return;
     }
 
-  /* The common checks above have checked this is fine. */
-  channel = channels->data;
-
   /* Only password authentication is supported from here */
   if (tp_channel_get_channel_type_id (channel) ==
       TP_IFACE_QUARK_CHANNEL_TYPE_SERVER_AUTHENTICATION1 &&
@@ -707,7 +703,7 @@ empathy_auth_factory_class_init (EmpathyAuthFactoryClass *klass)
   oclass->constructed = empathy_auth_factory_constructed;
   oclass->dispose = empathy_auth_factory_dispose;
 
-  base_client_cls->handle_channels = handle_channels;
+  base_client_cls->handle_channel = handle_channel;
   base_client_cls->observe_channel = observe_channel;
 
   g_type_class_add_private (klass, sizeof (EmpathyAuthFactoryPriv));
diff --git a/libempathy/empathy-ft-factory.c b/libempathy/empathy-ft-factory.c
index dfc237b..98ae675 100644
--- a/libempathy/empathy-ft-factory.c
+++ b/libempathy/empathy-ft-factory.c
@@ -162,33 +162,20 @@ ft_handler_incoming_ready_cb (EmpathyFTHandler *handler,
 }
 
 static void
-handle_channels_cb (TpSimpleHandler *handler,
+handle_channel_cb (TpSimpleHandler *handler,
     TpAccount *account,
     TpConnection *connection,
-    GList *channels,
+    TpChannel *channel,
     GList *requests_satisfied,
     gint64 user_action_time,
     TpHandleChannelContext *context,
     gpointer user_data)
 {
   EmpathyFTFactory *self = user_data;
-  GList *l;
 
-  for (l = channels; l != NULL; l = g_list_next (l))
-    {
-      TpChannel *channel = l->data;
-
-      if (tp_proxy_get_invalidated (channel) != NULL)
-        continue;
-
-      if (!TP_IS_FILE_TRANSFER_CHANNEL (channel))
-        continue;
-
-      /* We handle only incoming FT */
-      empathy_ft_handler_new_incoming ((TpFileTransferChannel *) channel,
+  /* We handle only incoming FT */
+  empathy_ft_handler_new_incoming (TP_FILE_TRANSFER_CHANNEL (channel),
           ft_handler_incoming_ready_cb, self);
-    }
-
 
   tp_handle_channel_context_accept (context);
 }
@@ -205,7 +192,7 @@ empathy_ft_factory_init (EmpathyFTFactory *self)
   am = tp_account_manager_dup ();
 
   priv->handler = tp_simple_handler_new_with_am (am, FALSE, FALSE,
-      EMPATHY_FT_BUS_NAME_SUFFIX, FALSE, handle_channels_cb, self, NULL);
+      EMPATHY_FT_BUS_NAME_SUFFIX, FALSE, handle_channel_cb, self, NULL);
 
   tp_base_client_take_handler_filter (priv->handler, tp_asv_new (
         TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
diff --git a/src/empathy-call-factory.c b/src/empathy-call-factory.c
index 8dcfdf8..08f2222 100644
--- a/src/empathy-call-factory.c
+++ b/src/empathy-call-factory.c
@@ -32,10 +32,10 @@
 
 G_DEFINE_TYPE(EmpathyCallFactory, empathy_call_factory, TP_TYPE_BASE_CLIENT)
 
-static void handle_channels (TpBaseClient *client,
+static void handle_channel (TpBaseClient *client,
     TpAccount *account,
     TpConnection *connection,
-    GList *channels,
+    TpChannel *channel,
     GList *requests_satisfied,
     gint64 user_action_time,
     TpHandleChannelContext *context);
@@ -124,7 +124,7 @@ empathy_call_factory_class_init (EmpathyCallFactoryClass *klass)
 
   object_class->constructor = empathy_call_factory_constructor;
 
-  base_clt_cls->handle_channels = handle_channels;
+  base_clt_cls->handle_channel = handle_channel;
   base_clt_cls->add_dispatch_operation = approve_channels;
 
   signals[NEW_CALL_HANDLER] =
@@ -177,47 +177,29 @@ empathy_call_factory_get (void)
 }
 
 static void
-handle_channels (TpBaseClient *client,
+handle_channel (TpBaseClient *client,
     TpAccount *account,
     TpConnection *connection,
-    GList *channels,
+    TpChannel *channel,
     GList *requests_satisfied,
     gint64 user_action_time,
     TpHandleChannelContext *context)
 {
   EmpathyCallFactory *self = EMPATHY_CALL_FACTORY (client);
-  GList *l;
-
-  for (l = channels; l != NULL; l = g_list_next (l))
-    {
-      TpChannel *channel = l->data;
-      TpCallChannel *call;
-      TpContact *tp_contact;
-      EmpathyContact *contact;
-      EmpathyCallHandler *handler;
-
-      if (tp_proxy_get_invalidated (channel) != NULL)
-        continue;
-
-      if (tp_channel_get_channel_type_id (channel) !=
-          TP_IFACE_QUARK_CHANNEL_TYPE_CALL1)
-        continue;
+  TpCallChannel *call = TP_CALL_CHANNEL (channel);
+  TpContact *tp_contact;
+  EmpathyContact *contact;
+  EmpathyCallHandler *handler;
 
-      if (!TP_IS_CALL_CHANNEL (channel))
-        continue;
-
-      call = TP_CALL_CHANNEL (channel);
+  tp_contact = tp_channel_get_target_contact (channel);
+  contact = empathy_contact_dup_from_tp_contact (tp_contact);
+  handler = empathy_call_handler_new_for_channel (call, contact);
 
-      tp_contact = tp_channel_get_target_contact (channel);
-      contact = empathy_contact_dup_from_tp_contact (tp_contact);
-      handler = empathy_call_handler_new_for_channel (call, contact);
+  g_signal_emit (self, signals[NEW_CALL_HANDLER], 0,
+      handler, user_action_time);
 
-      g_signal_emit (self, signals[NEW_CALL_HANDLER], 0,
-          handler, user_action_time);
-
-      g_object_unref (handler);
-      g_object_unref (contact);
-    }
+  g_object_unref (handler);
+  g_object_unref (contact);
 
   tp_handle_channel_context_accept (context);
 }
diff --git a/src/empathy-chat-manager.c b/src/empathy-chat-manager.c
index 812dbe8..53bba99 100644
--- a/src/empathy-chat-manager.c
+++ b/src/empathy-chat-manager.c
@@ -237,36 +237,21 @@ process_tp_chat (EmpathyChatManager *self,
 }
 
 static void
-handle_channels (TpSimpleHandler *handler,
+handle_channel (TpSimpleHandler *handler,
     TpAccount *account,
     TpConnection *connection,
-    GList *channels,
+    TpChannel *channel,
     GList *requests_satisfied,
     gint64 user_action_time,
     TpHandleChannelContext *context,
     gpointer user_data)
 {
   EmpathyChatManager *self = (EmpathyChatManager *) user_data;
-  GList *l;
+  EmpathyTpChat *tp_chat = EMPATHY_TP_CHAT (channel);
 
-  for (l = channels; l != NULL; l = g_list_next (l))
-    {
-      EmpathyTpChat *tp_chat = l->data;
-
-      if (tp_proxy_get_invalidated (tp_chat) != NULL)
-        continue;
+  DEBUG ("Now handling channel %s", tp_proxy_get_object_path (tp_chat));
 
-      if (!EMPATHY_IS_TP_CHAT (tp_chat))
-        {
-          DEBUG ("Channel %s doesn't implement Messages; can't handle it",
-              tp_proxy_get_object_path (tp_chat));
-          continue;
-        }
-
-      DEBUG ("Now handling channel %s", tp_proxy_get_object_path (tp_chat));
-
-      process_tp_chat (self, tp_chat, account, user_action_time);
-    }
+  process_tp_chat (self, tp_chat, account, user_action_time);
 
   tp_handle_channel_context_accept (context);
 }
@@ -288,7 +273,7 @@ empathy_chat_manager_init (EmpathyChatManager *self)
 
   /* Text channels handler */
   priv->handler = tp_simple_handler_new_with_am (am, FALSE, FALSE,
-      EMPATHY_CHAT_BUS_NAME_SUFFIX, FALSE, handle_channels, self, NULL);
+      EMPATHY_CHAT_BUS_NAME_SUFFIX, FALSE, handle_channel, self, NULL);
 
   g_object_unref (am);
 


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