diff options
author | Senko Rasic <senko.rasic@collabora.co.uk> | 2010-04-13 13:33:43 +0200 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2010-04-15 19:16:13 +0100 |
commit | 3fa338d7411638dea87f0e30ba2ff9b920905333 (patch) | |
tree | bbe27ca3414b4f674cb9267b4568b1544768084e | |
parent | e9b3c027f74d5e952363020a9f1ccaea21534f93 (diff) | |
download | telepathy-mission-control-3fa338d7411638dea87f0e30ba2ff9b920905333.tar.gz |
moved _mcd_tp_channel_* to a separate file
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/channel-utils.c | 154 | ||||
-rw-r--r-- | src/channel-utils.h | 48 | ||||
-rw-r--r-- | src/mcd-channel-priv.h | 11 | ||||
-rw-r--r-- | src/mcd-channel.c | 118 | ||||
-rw-r--r-- | src/mcd-client.c | 13 | ||||
-rw-r--r-- | src/mcd-dispatch-operation.c | 9 |
7 files changed, 217 insertions, 138 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 91a80362..df5b8bf4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -131,6 +131,8 @@ libmcd_convenience_la_SOURCES = \ mcd-account-priv.h \ mcd-client.c \ mcd-client-priv.h \ + channel-utils.c \ + channel-utils.h \ client-registry.c \ client-registry.h \ mcd-dbusprop.c \ diff --git a/src/channel-utils.c b/src/channel-utils.c new file mode 100644 index 00000000..21cf80f6 --- /dev/null +++ b/src/channel-utils.c @@ -0,0 +1,154 @@ +/* vi: set et sw=4 ts=8 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 8 -*- */ +/* + * This file is part of mission-control + * + * Copyright (C) 2007-2009 Nokia Corporation. + * Copyright (C) 2009 Collabora Ltd. + * + * Contact: Naba Kumar <naba.kumar@nokia.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + * + */ + +#include "channel-utils.h" + +#include <telepathy-glib/channel.h> +#include <telepathy-glib/gtypes.h> +#include <telepathy-glib/interfaces.h> + +#include "mcd-channel.h" +#include "mcd-debug.h" + +gboolean +_mcd_tp_channel_should_close (TpChannel *channel, + const gchar *verb) +{ + const GError *invalidated; + const gchar *object_path; + GQuark channel_type; + + if (channel == NULL) + { + DEBUG ("Not %s NULL channel", verb); + return FALSE; + } + + invalidated = tp_proxy_get_invalidated (channel); + object_path = tp_proxy_get_object_path (channel); + + if (invalidated != NULL) + { + DEBUG ("Not %s %p:%s, already invalidated: %s %d: %s", + verb, channel, object_path, + g_quark_to_string (invalidated->domain), + invalidated->code, invalidated->message); + return FALSE; + } + + channel_type = tp_channel_get_channel_type_id (channel); + + if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_CONTACT_LIST) + { + DEBUG ("Not %s %p:%s, it's a ContactList", verb, channel, object_path); + return FALSE; + } + + if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TUBES) + { + DEBUG ("Not %s %p:%s, it's an old Tubes channel", verb, channel, + object_path); + return FALSE; + } + + return TRUE; +} + +static void +_channel_details_array_append (GPtrArray *channel_array, TpChannel *channel) +{ + GType type = TP_STRUCT_TYPE_CHANNEL_DETAILS; + GValue channel_val = { 0, }; + GHashTable *properties; + const gchar *object_path; + + properties = tp_channel_borrow_immutable_properties (channel); + object_path = tp_proxy_get_object_path (channel); + + g_value_init (&channel_val, type); + g_value_take_boxed (&channel_val, + dbus_g_type_specialized_construct (type)); + dbus_g_type_struct_set (&channel_val, + 0, object_path, + 1, properties, + G_MAXUINT); + + g_ptr_array_add (channel_array, g_value_get_boxed (&channel_val)); +} + +/* + * _mcd_tp_channel_details_build_from_list: + * @channels: a #GList of #McdChannel elements. + * + * Returns: a #GPtrArray of Channel_Details, ready to be sent over D-Bus. Free + * with _mcd_tp_channel_details_free(). + */ +GPtrArray * +_mcd_tp_channel_details_build_from_list (const GList *channels) +{ + GPtrArray *channel_array; + const GList *list; + + channel_array = g_ptr_array_sized_new (g_list_length ((GList *) channels)); + + for (list = channels; list != NULL; list = list->next) + { + _channel_details_array_append (channel_array, + mcd_channel_get_tp_channel (MCD_CHANNEL (list->data))); + } + + return channel_array; +} + +/* + * _mcd_tp_channel_details_build_from_tp_chan: + * @channel: a #TpChannel + * + * Returns: a #GPtrArray of Channel_Details, ready to be sent over D-Bus. Free + * with _mcd_tp_channel_details_free(). + */ +GPtrArray * +_mcd_tp_channel_details_build_from_tp_chan (TpChannel *channel) +{ + GPtrArray *channel_array = g_ptr_array_sized_new (1); + + _channel_details_array_append (channel_array, channel); + return channel_array; +} + +/* + * _mcd_tp_channel_details_free: + * @channels: a #GPtrArray of Channel_Details. + * + * Frees the memory used by @channels. + */ +void +_mcd_tp_channel_details_free (GPtrArray *channels) +{ + g_boxed_free (TP_ARRAY_TYPE_CHANNEL_DETAILS_LIST, channels); +} + + diff --git a/src/channel-utils.h b/src/channel-utils.h new file mode 100644 index 00000000..01428cc9 --- /dev/null +++ b/src/channel-utils.h @@ -0,0 +1,48 @@ +/* vi: set et sw=4 ts=8 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 8 -*- */ +/* + * This file is part of mission-control + * + * Copyright (C) 2007-2010 Nokia Corporation. + * Copyright (C) 2009-2010 Collabora Ltd. + * + * Contact: Naba Kumar <naba.kumar@nokia.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + * + */ + +#ifndef CHANNEL_UTILS_H +#define CHANNEL_UTILS_H + +#include <glib.h> +#include <telepathy-glib/channel.h> + +G_BEGIN_DECLS + +G_GNUC_INTERNAL +GPtrArray *_mcd_tp_channel_details_build_from_list (const GList *channels); +G_GNUC_INTERNAL +GPtrArray *_mcd_tp_channel_details_build_from_tp_chan (TpChannel *channel); +G_GNUC_INTERNAL +void _mcd_tp_channel_details_free (GPtrArray *channels); + +/* NULL-safe for @channel; @verb is for debug */ +G_GNUC_INTERNAL gboolean _mcd_tp_channel_should_close (TpChannel *channel, + const gchar *verb); + +G_END_DECLS +#endif + diff --git a/src/mcd-channel-priv.h b/src/mcd-channel-priv.h index 01f11459..0ab1d4b7 100644 --- a/src/mcd-channel-priv.h +++ b/src/mcd-channel-priv.h @@ -47,13 +47,6 @@ G_GNUC_INTERNAL GHashTable *_mcd_channel_get_immutable_properties (McdChannel *channel); G_GNUC_INTERNAL -GPtrArray *_mcd_channel_details_build_from_list (const GList *channels); -G_GNUC_INTERNAL -GPtrArray *_mcd_channel_details_build_from_tp_chan (TpChannel *channel); -G_GNUC_INTERNAL -void _mcd_channel_details_free (GPtrArray *channels); - -G_GNUC_INTERNAL const gchar *_mcd_channel_get_target_id (McdChannel *channel); G_GNUC_INTERNAL GHashTable *_mcd_channel_get_requested_properties (McdChannel *channel); @@ -83,10 +76,6 @@ G_GNUC_INTERNAL void _mcd_channel_depart (McdChannel *channel, TpChannelGroupChangeReason reason, const gchar *message); -/* NULL-safe for @channel; @verb is for debug */ -G_GNUC_INTERNAL gboolean _mcd_tp_channel_should_close (TpChannel *channel, - const gchar *verb); - G_END_DECLS #endif diff --git a/src/mcd-channel.c b/src/mcd-channel.c index bef0516b..3b33b7de 100644 --- a/src/mcd-channel.c +++ b/src/mcd-channel.c @@ -251,50 +251,6 @@ on_channel_ready (TpChannel *tp_chan, const GError *error, gpointer user_data) _mcd_channel_setup_group (channel); } -gboolean -_mcd_tp_channel_should_close (TpChannel *channel, - const gchar *verb) -{ - const GError *invalidated; - const gchar *object_path; - GQuark channel_type; - - if (channel == NULL) - { - DEBUG ("Not %s NULL channel", verb); - return FALSE; - } - - invalidated = tp_proxy_get_invalidated (channel); - object_path = tp_proxy_get_object_path (channel); - - if (invalidated != NULL) - { - DEBUG ("Not %s %p:%s, already invalidated: %s %d: %s", - verb, channel, object_path, - g_quark_to_string (invalidated->domain), - invalidated->code, invalidated->message); - return FALSE; - } - - channel_type = tp_channel_get_channel_type_id (channel); - - if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_CONTACT_LIST) - { - DEBUG ("Not %s %p:%s, it's a ContactList", verb, channel, object_path); - return FALSE; - } - - if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TUBES) - { - DEBUG ("Not %s %p:%s, it's an old Tubes channel", verb, channel, - object_path); - return FALSE; - } - - return TRUE; -} - void _mcd_channel_close (McdChannel *channel) { @@ -1067,80 +1023,6 @@ _mcd_channel_get_immutable_properties (McdChannel *channel) return ret; } -static void -_channel_details_array_append (GPtrArray *channel_array, TpChannel *channel) -{ - GType type = TP_STRUCT_TYPE_CHANNEL_DETAILS; - GValue channel_val = { 0, }; - GHashTable *properties; - const gchar *object_path; - - properties = tp_channel_borrow_immutable_properties (channel); - object_path = tp_proxy_get_object_path (channel); - - g_value_init (&channel_val, type); - g_value_take_boxed (&channel_val, - dbus_g_type_specialized_construct (type)); - dbus_g_type_struct_set (&channel_val, - 0, object_path, - 1, properties, - G_MAXUINT); - - g_ptr_array_add (channel_array, g_value_get_boxed (&channel_val)); -} - -/* - * _mcd_channel_details_build_from_list: - * @channels: a #GList of #McdChannel elements. - * - * Returns: a #GPtrArray of Channel_Details, ready to be sent over D-Bus. Free - * with _mcd_channel_details_free(). - */ -GPtrArray * -_mcd_channel_details_build_from_list (const GList *channels) -{ - GPtrArray *channel_array; - const GList *list; - - channel_array = g_ptr_array_sized_new (g_list_length ((GList *) channels)); - - for (list = channels; list != NULL; list = list->next) - { - _channel_details_array_append (channel_array, - mcd_channel_get_tp_channel (MCD_CHANNEL (list->data))); - } - - return channel_array; -} - -/* - * _mcd_channel_details_build_from_tp_chan: - * @channel: a #TpChannel - * - * Returns: a #GPtrArray of Channel_Details, ready to be sent over D-Bus. Free - * with _mcd_channel_details_free(). - */ -GPtrArray * -_mcd_channel_details_build_from_tp_chan (TpChannel *channel) -{ - GPtrArray *channel_array = g_ptr_array_sized_new (1); - - _channel_details_array_append (channel_array, channel); - return channel_array; -} - -/* - * _mcd_channel_details_free: - * @channels: a #GPtrArray of Channel_Details. - * - * Frees the memory used by @channels. - */ -void -_mcd_channel_details_free (GPtrArray *channels) -{ - g_boxed_free (TP_ARRAY_TYPE_CHANNEL_DETAILS_LIST, channels); -} - /* * _mcd_channel_get_target_id: * @channel: the #McdChannel. diff --git a/src/mcd-client.c b/src/mcd-client.c index 9a235332..51fe016b 100644 --- a/src/mcd-client.c +++ b/src/mcd-client.c @@ -36,6 +36,7 @@ #include <telepathy-glib/proxy-subclass.h> #include <telepathy-glib/util.h> +#include "channel-utils.h" #include "mcd-channel-priv.h" #include "mcd-debug.h" @@ -604,8 +605,10 @@ _mcd_client_recover_observer (McdClientProxy *self, TpChannel *channel, observer_info = g_hash_table_new (g_str_hash, g_str_equal); tp_asv_set_boolean (observer_info, "recovering", TRUE); - channels_array = _mcd_channel_details_build_from_tp_chan (channel); - g_object_get (channel, "connection", &conn, NULL); + channels_array = _mcd_tp_channel_details_build_from_tp_chan (channel); + g_object_get (channel, + "connection", &conn, + NULL); connection_path = tp_proxy_get_object_path (conn); DEBUG ("calling ObserveChannels on %s for channel %p", @@ -617,7 +620,7 @@ _mcd_client_recover_observer (McdClientProxy *self, TpChannel *channel, "/", satisfied_requests, observer_info, NULL, NULL, NULL, NULL); - _mcd_channel_details_free (channels_array); + _mcd_tp_channel_details_free (channels_array); g_ptr_array_free (satisfied_requests, TRUE); g_hash_table_destroy (observer_info); } @@ -1695,7 +1698,7 @@ _mcd_client_proxy_handle_channels (McdClientProxy *self, DEBUG ("calling HandleChannels on %s", tp_proxy_get_bus_name (self)); - channel_details = _mcd_channel_details_build_from_list (channels); + channel_details = _mcd_tp_channel_details_build_from_list (channels); requests_satisfied = g_ptr_array_new (); if (handler_info == NULL) @@ -1734,7 +1737,7 @@ _mcd_client_proxy_handle_channels (McdClientProxy *self, requests_satisfied, user_action_time, handler_info, callback, user_data, destroy, weak_object); - _mcd_channel_details_free (channel_details); + _mcd_tp_channel_details_free (channel_details); g_ptr_array_free (requests_satisfied, TRUE); g_hash_table_unref (handler_info); } diff --git a/src/mcd-dispatch-operation.c b/src/mcd-dispatch-operation.c index 80623912..57054f60 100644 --- a/src/mcd-dispatch-operation.c +++ b/src/mcd-dispatch-operation.c @@ -43,6 +43,7 @@ #include <telepathy-glib/svc-generic.h> #include <telepathy-glib/util.h> +#include "channel-utils.h" #include "mcd-channel-priv.h" #include "mcd-dbusprop.h" #include "mcd-misc.h" @@ -571,7 +572,7 @@ get_channels (TpSvcDBusProperties *iface, const gchar *name, GValue *value) g_value_init (value, TP_ARRAY_TYPE_CHANNEL_DETAILS_LIST); g_value_take_boxed (value, - _mcd_channel_details_build_from_list (self->priv->channels)); + _mcd_tp_channel_details_build_from_list (self->priv->channels)); } static void @@ -1835,7 +1836,7 @@ _mcd_dispatch_operation_run_observers (McdDispatchOperation *self) /* TODO: there's room for optimization here: reuse the channels_array, * if the observed list is the same */ - channels_array = _mcd_channel_details_build_from_list (observed); + channels_array = _mcd_tp_channel_details_build_from_list (observed); satisfied_requests = collect_satisfied_requests (observed); @@ -1859,7 +1860,7 @@ _mcd_dispatch_operation_run_observers (McdDispatchOperation *self) * McdChannel objects */ g_ptr_array_free (satisfied_requests, TRUE); - _mcd_channel_details_free (channels_array); + _mcd_tp_channel_details_free (channels_array); g_list_free (observed); } @@ -1947,7 +1948,7 @@ _mcd_dispatch_operation_run_approvers (McdDispatchOperation *self) dispatch_operation = _mcd_dispatch_operation_get_path (self); properties = _mcd_dispatch_operation_get_properties (self); channel_details = - _mcd_channel_details_build_from_list (self->priv->channels); + _mcd_tp_channel_details_build_from_list (self->priv->channels); DEBUG ("Calling AddDispatchOperation on approver %s for CDO %s @ %p", tp_proxy_get_bus_name (client), dispatch_operation, self); |