#include <telepathy-glib/util.h>
#include <telepathy-glib/dbus.h>
#include <telepathy-glib/proxy-subclass.h>
+#include <telepathy-glib/gtypes.h>
#include <libmissioncontrol/mission-control.h>
#include <libmissioncontrol/mc-account.h>
#include <libempathy/empathy-debug.h>
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyDispatcher)
-typedef struct {
+typedef struct
+{
EmpathyAccountManager *account_manager;
MissionControl *mc;
/* connection to connection data mapping */
- GHashTable *connections;
+ GHashTable *connections;
/* accounts to connection mapping */
- GHashTable *accounts;
- gpointer token;
- GSList *tubes;
+ GHashTable *accounts;
+ gpointer token;
+ GSList *tubes;
+
+ /* channels which the dispatcher is listening "invalidated" */
+ GList *channels;
} EmpathyDispatcherPriv;
G_DEFINE_TYPE (EmpathyDispatcher, empathy_dispatcher, G_TYPE_OBJECT);
-enum {
+enum
+{
OBSERVE,
APPROVE,
DISPATCH,
static guint signals[LAST_SIGNAL];
static EmpathyDispatcher *dispatcher = NULL;
-typedef struct {
+typedef struct
+{
EmpathyDispatcher *dispatcher;
EmpathyDispatchOperation *operation;
TpConnection *connection;
gpointer *request_data;
} DispatcherRequestData;
-typedef struct {
+typedef struct
+{
TpChannel *channel;
/* Channel type specific wrapper object */
GObject *channel_wrapper;
} DispatchData;
-typedef struct {
+typedef struct
+{
McAccount *account;
/* ObjectPath => DispatchData.. */
GHashTable *dispatched_channels;
GHashTable *outstanding_channels;
/* List of DispatcherRequestData */
GList *outstanding_requests;
+ /* List of requestable channel classes */
+ GPtrArray *requestable_channels;
} ConnectionData;
static DispatchData *
-new_dispatch_data (TpChannel *channel, GObject *channel_wrapper)
+new_dispatch_data (TpChannel *channel,
+ GObject *channel_wrapper)
{
DispatchData *d = g_slice_new0 (DispatchData);
d->channel = g_object_ref (channel);
- d->channel_wrapper = g_object_ref (channel_wrapper);
+ if (channel_wrapper != NULL)
+ d->channel_wrapper = g_object_ref (channel_wrapper);
return d;
}
free_dispatch_data (DispatchData *data)
{
g_object_unref (data->channel);
- g_object_unref (data->channel_wrapper);
+ if (data->channel_wrapper != NULL)
+ g_object_unref (data->channel_wrapper);
g_slice_free (DispatchData, data);
}
-
static DispatcherRequestData *
new_dispatcher_request_data (EmpathyDispatcher *dispatcher,
- TpConnection *connection, const gchar *channel_type, guint handle_type,
- guint handle, GHashTable *request,
- EmpathyContact *contact, EmpathyDispatcherRequestCb *cb, gpointer user_data)
+ TpConnection *connection,
+ const gchar *channel_type,
+ guint handle_type,
+ guint handle,
+ GHashTable *request,
+ EmpathyContact *contact,
+ EmpathyDispatcherRequestCb *cb,
+ gpointer user_data)
{
DispatcherRequestData *result = g_slice_new0 (DispatcherRequestData);
- result->dispatcher = dispatcher;
+ result->dispatcher = g_object_ref (dispatcher);
result->connection = connection;
result->channel_type = g_strdup (channel_type);
{
g_free (r->channel_type);
+ if (r->dispatcher != NULL)
+ g_object_unref (r->dispatcher);
+
if (r->contact != NULL)
g_object_unref (r->contact);
cd->account = g_object_ref (account);
cd->dispatched_channels = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, (GDestroyNotify) free_dispatch_data);
+ g_free, (GDestroyNotify) free_dispatch_data);
cd->dispatching_channels = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, g_object_unref);
+ g_free, g_object_unref);
cd->outstanding_channels = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, NULL);
+ g_free, NULL);
return cd;
}
g_object_unref (cd->account);
g_hash_table_destroy (cd->dispatched_channels);
g_hash_table_destroy (cd->dispatching_channels);
+ int i;
for (l = cd->outstanding_requests ; l != NULL; l = g_list_delete_link (l,l))
{
free_dispatcher_request_data (l->data);
}
+
+ if (cd->requestable_channels != NULL)
+ {
+ for (i = 0 ; i < cd->requestable_channels->len ; i++)
+ g_value_array_free (
+ g_ptr_array_index (cd->requestable_channels, i));
+ g_ptr_array_free (cd->requestable_channels, TRUE);
+ }
}
static void
-dispatcher_connection_invalidated_cb (TpConnection *connection,
- guint domain, gint code, gchar *message,
- EmpathyDispatcher *dispatcher)
+dispatcher_connection_invalidated_cb (TpConnection *connection,
+ guint domain,
+ gint code,
+ gchar *message,
+ EmpathyDispatcher *dispatcher)
{
EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
ConnectionData *cd;
static gboolean
dispatcher_operation_can_start (EmpathyDispatcher *self,
- EmpathyDispatchOperation *operation, ConnectionData *cd)
+ EmpathyDispatchOperation *operation,
+ ConnectionData *cd)
{
GList *l;
const gchar *channel_type =
static void
dispatch_operation_flush_requests (EmpathyDispatcher *dispatcher,
- EmpathyDispatchOperation *operation, GError *error, ConnectionData *cd)
+ EmpathyDispatchOperation *operation,
+ GError *error,
+ ConnectionData *cd)
{
GList *l;
}
static void
-dispatcher_channel_invalidated_cb (TpProxy *proxy, guint domain, gint code,
- gchar *message, EmpathyDispatcher *dispatcher)
+dispatcher_channel_invalidated_cb (TpProxy *proxy,
+ guint domain,
+ gint code,
+ gchar *message,
+ EmpathyDispatcher *dispatcher)
{
/* Channel went away... */
EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
g_hash_table_remove (cd->dispatched_channels, object_path);
g_hash_table_remove (cd->dispatching_channels, object_path);
+ priv->channels = g_list_remove (priv->channels, proxy);
+
operation = g_hash_table_lookup (cd->outstanding_channels, object_path);
if (operation != NULL)
{
static void
dispatch_operation_approved_cb (EmpathyDispatchOperation *operation,
- EmpathyDispatcher *dispatcher)
+ EmpathyDispatcher *dispatcher)
{
g_assert (empathy_dispatch_operation_is_incoming (operation));
DEBUG ("Send of for dispatching: %s",
static void
dispatch_operation_claimed_cb (EmpathyDispatchOperation *operation,
- EmpathyDispatcher *dispatcher)
+ EmpathyDispatcher *dispatcher)
{
/* Our job is done, remove the dispatch operation and mark the channel as
* dispatched */
static void
dispatch_operation_ready_cb (EmpathyDispatchOperation *operation,
- EmpathyDispatcher *dispatcher)
+ EmpathyDispatcher *dispatcher)
{
EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
TpConnection *connection;
g_object_unref (G_OBJECT (connection));
g_object_ref (operation);
+ g_object_ref (dispatcher);
dispatch_operation_flush_requests (dispatcher, operation, NULL, cd);
status = empathy_dispatch_operation_get_status (operation);
g_signal_emit (dispatcher, signals[DISPATCH], 0, operation);
}
+ g_object_unref (dispatcher);
}
static void
dispatcher_start_dispatching (EmpathyDispatcher *self,
- EmpathyDispatchOperation *operation, ConnectionData *cd)
+ EmpathyDispatchOperation *operation,
+ ConnectionData *cd)
{
const gchar *object_path =
empathy_dispatch_operation_get_object_path (operation);
}
}
-
static void
dispatcher_flush_outstanding_operations (EmpathyDispatcher *self,
- ConnectionData *cd)
+ ConnectionData *cd)
{
GHashTableIter iter;
gpointer value;
}
}
-
static void
dispatcher_connection_new_channel (EmpathyDispatcher *dispatcher,
- TpConnection *connection,
- const gchar *object_path, const gchar *channel_type,
- guint handle_type, guint handle, GHashTable *properties,
- gboolean incoming)
+ TpConnection *connection,
+ const gchar *object_path,
+ const gchar *channel_type,
+ guint handle_type,
+ guint handle,
+ GHashTable *properties,
+ gboolean incoming)
{
EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
TpChannel *channel;
if (g_hash_table_lookup (cd->outstanding_channels, object_path) != NULL)
return;
- /* Only pick up non-requested text channels. For all other it doesn't make
- * sense to handle it if we didn't request it. The same goes for channels we
- * discovered by the Channels property or ListChannels */
- if (!incoming && tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_TEXT))
+ /* Only pick up non-requested text and file channels. For all other it
+ * doesn't make sense to handle it if we didn't request it. The same goes
+ * for channels we discovered by the Channels property or ListChannels */
+ if (!incoming && tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_TEXT)
+ && tp_strdiff (channel_type, EMP_IFACE_CHANNEL_TYPE_FILE_TRANSFER))
{
DEBUG ("Ignoring incoming channel of type %s on %s",
channel_type, object_path);
G_CALLBACK (dispatcher_channel_invalidated_cb),
dispatcher);
+ priv->channels = g_list_prepend (priv->channels, channel);
+
if (handle_type == TP_CONN_HANDLE_TYPE_CONTACT)
{
EmpathyContactFactory *factory = empathy_contact_factory_dup_singleton ();
static void
dispatcher_connection_new_channel_cb (TpConnection *connection,
- const gchar *object_path, const gchar *channel_type,
- guint handle_type, guint handle,
- gboolean suppress_handler, gpointer user_data,
- GObject *object)
+ const gchar *object_path,
+ const gchar *channel_type,
+ guint handle_type,
+ guint handle,
+ gboolean suppress_handler,
+ gpointer user_data,
+ GObject *object)
{
EmpathyDispatcher *dispatcher = EMPATHY_DISPATCHER (object);
}
static void
-dispatcher_connection_new_channel_with_properties (
- EmpathyDispatcher *dispatcher, TpConnection *connection,
- const gchar *object_path, GHashTable *properties)
+dispatcher_connection_new_channel_with_properties (EmpathyDispatcher *dispatcher,
+ TpConnection *connection,
+ const gchar *object_path,
+ GHashTable *properties)
{
const gchar *channel_type;
guint handle_type;
object_path, channel_type, handle_type, handle, properties, !requested);
}
-
static void
-dispatcher_connection_new_channels_cb (
- TpConnection *connection, const GPtrArray *channels, gpointer user_data,
- GObject *object)
+dispatcher_connection_new_channels_cb (TpConnection *connection,
+ const GPtrArray *channels,
+ gpointer user_data,
+ GObject *object)
{
EmpathyDispatcher *dispatcher = EMPATHY_DISPATCHER (object);
int i;
}
static void
-dispatcher_connection_got_channels_property (TpProxy *proxy,
- const GValue *channels_prop, const GError *error, gpointer user_data,
- GObject *object)
+dispatcher_connection_got_all (TpProxy *proxy,
+ GHashTable *properties,
+ const GError *error,
+ gpointer user_data,
+ GObject *object)
{
+ EmpathyDispatcher *dispatcher = EMPATHY_DISPATCHER (object);
+ EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
GPtrArray *channels;
+ GPtrArray *requestable_channels;
if (error) {
DEBUG ("Error: %s", error->message);
return;
}
- channels = g_value_get_boxed (channels_prop);
- dispatcher_connection_new_channels_cb (TP_CONNECTION (proxy),
- channels, NULL, object);
+ channels = tp_asv_get_boxed (properties, "Channels",
+ TP_ARRAY_TYPE_CHANNEL_DETAILS_LIST);
+
+ if (channels == NULL)
+ DEBUG ("No Channels property !?! on connection");
+ else
+ dispatcher_connection_new_channels_cb (TP_CONNECTION (proxy),
+ channels, NULL, object);
+
+ requestable_channels = tp_asv_get_boxed (properties,
+ "RequestableChannelClasses", TP_ARRAY_TYPE_REQUESTABLE_CHANNEL_CLASS_LIST);
+
+ if (requestable_channels == NULL)
+ DEBUG ("No RequestableChannelClasses property !?! on connection");
+ else
+ {
+ ConnectionData *cd;
+
+ cd = g_hash_table_lookup (priv->connections, proxy);
+ g_assert (cd != NULL);
+
+ cd->requestable_channels = g_boxed_copy (
+ TP_ARRAY_TYPE_REQUESTABLE_CHANNEL_CLASS_LIST, requestable_channels);
+ }
}
static void
dispatcher_connection_list_channels_cb (TpConnection *connection,
- const GPtrArray *channels,
- const GError *error,
- gpointer user_data,
- GObject *dispatcher)
+ const GPtrArray *channels,
+ const GError *error,
+ gpointer user_data,
+ GObject *dispatcher)
{
- int i;
-
- if (error) {
- DEBUG ("Error: %s", error->message);
- return;
- }
-
- for (i = 0; i < channels->len; i++) {
- GValueArray *values;
-
- values = g_ptr_array_index (channels, i);
- /* We don't have any extra info, so assume already existing channels are
- * incoming... */
- dispatcher_connection_new_channel (EMPATHY_DISPATCHER (dispatcher),
- connection,
- g_value_get_boxed (g_value_array_get_nth (values, 0)),
- g_value_get_string (g_value_array_get_nth (values, 1)),
- g_value_get_uint (g_value_array_get_nth (values, 2)),
- g_value_get_uint (g_value_array_get_nth (values, 3)),
- NULL, TRUE);
- }
+ int i;
+
+ if (error)
+ {
+ DEBUG ("Error: %s", error->message);
+ return;
+ }
+
+ for (i = 0; i < channels->len; i++)
+ {
+ GValueArray *values;
+
+ values = g_ptr_array_index (channels, i);
+ /* We don't have any extra info, so assume already existing channels are
+ * incoming... */
+ dispatcher_connection_new_channel (EMPATHY_DISPATCHER (dispatcher),
+ connection,
+ g_value_get_boxed (g_value_array_get_nth (values, 0)),
+ g_value_get_string (g_value_array_get_nth (values, 1)),
+ g_value_get_uint (g_value_array_get_nth (values, 2)),
+ g_value_get_uint (g_value_array_get_nth (values, 3)),
+ NULL, TRUE);
+ }
}
static void
dispatcher_connection_advertise_capabilities_cb (TpConnection *connection,
- const GPtrArray *capabilities,
- const GError *error,
- gpointer user_data,
- GObject *dispatcher)
+ const GPtrArray *capabilities,
+ const GError *error,
+ gpointer user_data,
+ GObject *dispatcher)
{
- if (error) {
- DEBUG ("Error: %s", error->message);
- }
+ if (error)
+ DEBUG ("Error: %s", error->message);
}
static void
-dispatcher_connection_ready_cb (TpConnection *connection,
- const GError *error, gpointer dispatcher)
+dispatcher_connection_ready_cb (TpConnection *connection,
+ const GError *error,
+ gpointer dispatcher)
{
GPtrArray *capabilities;
GType cap_type;
g_signal_connect (connection, "invalidated",
G_CALLBACK (dispatcher_connection_invalidated_cb), dispatcher);
-
if (tp_proxy_has_interface_by_id (TP_PROXY (connection),
TP_IFACE_QUARK_CONNECTION_INTERFACE_REQUESTS))
{
dispatcher_connection_new_channels_cb,
NULL, NULL, G_OBJECT (dispatcher), NULL);
- tp_cli_dbus_properties_call_get (connection, -1,
- TP_IFACE_CONNECTION_INTERFACE_REQUESTS, "Channels",
- dispatcher_connection_got_channels_property,
+ tp_cli_dbus_properties_call_get_all (connection, -1,
+ TP_IFACE_CONNECTION_INTERFACE_REQUESTS,
+ dispatcher_connection_got_all,
NULL, NULL, dispatcher);
}
else
}
static void
-dispatcher_update_account (EmpathyDispatcher *dispatcher, McAccount *account)
+dispatcher_update_account (EmpathyDispatcher *dispatcher,
+ McAccount *account)
{
EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
TpConnection *connection;
connection = g_hash_table_lookup (priv->accounts, account);
- if (connection != NULL)
+ if (connection != NULL)
return;
connection = mission_control_get_tpconnection (priv->mc, account, NULL);
static void
dispatcher_account_connection_cb (EmpathyAccountManager *manager,
- McAccount *account, TpConnectionStatusReason reason,
- TpConnectionStatus status, TpConnectionStatus previous,
- EmpathyDispatcher *dispatcher)
+ McAccount *account,
+ TpConnectionStatusReason reason,
+ TpConnectionStatus status,
+ TpConnectionStatus previous,
+ EmpathyDispatcher *dispatcher)
{
dispatcher_update_account (dispatcher, account);
}
-
static GObject*
-dispatcher_constructor (GType type, guint n_construct_params,
- GObjectConstructParam *construct_params)
+dispatcher_constructor (GType type,
+ guint n_construct_params,
+ GObjectConstructParam *construct_params)
{
GObject *retval;
(type, n_construct_params, construct_params);
dispatcher = EMPATHY_DISPATCHER (retval);
- g_object_add_weak_pointer (retval, (gpointer *) &dispatcher);
+ g_object_add_weak_pointer (retval, (gpointer) &dispatcher);
}
else
{
dispatcher_finalize (GObject *object)
{
EmpathyDispatcherPriv *priv = GET_PRIV (object);
+ GList *l;
+ GHashTableIter iter;
+ gpointer connection;
g_signal_handlers_disconnect_by_func (priv->account_manager,
dispatcher_account_connection_cb, object);
+ for (l = priv->channels; l; l = l->next)
+ {
+ g_signal_handlers_disconnect_by_func (l->data,
+ dispatcher_channel_invalidated_cb, object);
+ }
+
+ g_list_free (priv->channels);
+
+ g_hash_table_iter_init (&iter, priv->connections);
+ while (g_hash_table_iter_next (&iter, &connection, NULL))
+ {
+ g_signal_handlers_disconnect_by_func (connection,
+ dispatcher_connection_invalidated_cb, object);
+ }
+
g_object_unref (priv->account_manager);
g_object_unref (priv->mc);
EMPATHY_TYPE_DISPATCHER, EmpathyDispatcherPriv);
dispatcher->priv = priv;
- priv->mc = empathy_mission_control_new ();
+ priv->mc = empathy_mission_control_dup_singleton ();
priv->account_manager = empathy_account_manager_dup_singleton ();
g_signal_connect (priv->account_manager,
priv->connections = g_hash_table_new_full (g_direct_hash, g_direct_equal,
g_object_unref, (GDestroyNotify) free_connection_data);
+ priv->channels = NULL;
+
accounts = mc_accounts_list_by_enabled (TRUE);
- for (l = accounts; l; l = l->next) {
- dispatcher_update_account (dispatcher, l->data);
- g_object_unref (l->data);
- }
+ for (l = accounts; l; l = l->next)
+ {
+ dispatcher_update_account (dispatcher, l->data);
+ g_object_unref (l->data);
+ }
g_list_free (accounts);
}
static void
dispatcher_request_failed (EmpathyDispatcher *dispatcher,
- DispatcherRequestData *request_data, const GError *error)
+ DispatcherRequestData *request_data,
+ const GError *error)
{
EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
ConnectionData *conn_data;
static void
dispatcher_connection_new_requested_channel (EmpathyDispatcher *dispatcher,
- DispatcherRequestData *request_data, const gchar *object_path,
- GHashTable *properties, const GError *error)
+ DispatcherRequestData *request_data,
+ const gchar *object_path,
+ GHashTable *properties,
+ const GError *error)
{
EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
EmpathyDispatchOperation *operation = NULL;
dispatcher_request_failed (dispatcher, request_data, error);
goto out;
- }
+ }
operation = g_hash_table_lookup (conn_data->outstanding_channels,
object_path);
G_CALLBACK (dispatcher_channel_invalidated_cb),
request_data->dispatcher);
+ priv->channels = g_list_prepend (priv->channels, channel);
+
operation = empathy_dispatch_operation_new (request_data->connection,
channel, request_data->contact, FALSE);
g_object_unref (channel);
static void
dispatcher_request_channel_cb (TpConnection *connection,
- const gchar *object_path, const GError *error,
- gpointer user_data, GObject *weak_object)
+ const gchar *object_path,
+ const GError *error,
+ gpointer user_data,
+ GObject *weak_object)
{
EmpathyDispatcher *dispatcher = EMPATHY_DISPATCHER (weak_object);
DispatcherRequestData *request_data = (DispatcherRequestData*) user_data;
}
void
-empathy_dispatcher_call_with_contact ( EmpathyContact *contact,
- EmpathyDispatcherRequestCb *callback, gpointer user_data)
+empathy_dispatcher_call_with_contact (EmpathyContact *contact,
+ EmpathyDispatcherRequestCb *callback,
+ gpointer user_data)
{
EmpathyDispatcher *dispatcher = empathy_dispatcher_dup_singleton();
EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
ConnectionData *cd;
DispatcherRequestData *request_data;
+ g_return_if_fail (EMPATHY_IS_CONTACT (contact));
+
account = empathy_contact_get_account (contact);
connection = g_hash_table_lookup (priv->accounts, account);
g_object_unref (dispatcher);
}
-
static void
dispatcher_chat_with_contact_cb (EmpathyContact *contact,
- const GError *error, gpointer user_data, GObject *object)
+ const GError *error,
+ gpointer user_data,
+ GObject *object)
{
DispatcherRequestData *request_data = (DispatcherRequestData *) user_data;
void
empathy_dispatcher_chat_with_contact (EmpathyContact *contact,
- EmpathyDispatcherRequestCb *callback, gpointer user_data)
+ EmpathyDispatcherRequestCb *callback,
+ gpointer user_data)
{
EmpathyDispatcher *dispatcher;
EmpathyDispatcherPriv *priv;
ConnectionData *connection_data;
DispatcherRequestData *request_data;
+ g_return_if_fail (EMPATHY_IS_CONTACT (contact));
+
dispatcher = empathy_dispatcher_dup_singleton();
priv = GET_PRIV (dispatcher);
}
void
-empathy_dispatcher_chat_with_contact_id (McAccount *account, const gchar
- *contact_id, EmpathyDispatcherRequestCb *callback, gpointer user_data)
+empathy_dispatcher_chat_with_contact_id (McAccount *account,
+ const gchar *contact_id,
+ EmpathyDispatcherRequestCb *callback,
+ gpointer user_data)
{
EmpathyDispatcher *dispatcher = empathy_dispatcher_dup_singleton ();
EmpathyContactFactory *factory;
EmpathyContact *contact;
+ g_return_if_fail (MC_IS_ACCOUNT (account));
+ g_return_if_fail (!EMP_STR_EMPTY (contact_id));
+
factory = empathy_contact_factory_dup_singleton ();
contact = empathy_contact_factory_get_from_id (factory, account, contact_id);
g_object_unref (dispatcher);
}
-
static void
dispatcher_request_handles_cb (TpConnection *connection,
- const GArray *handles, const GError *error, gpointer user_data,
- GObject *object)
+ const GArray *handles,
+ const GError *error,
+ gpointer user_data,
+ GObject *object)
{
DispatcherRequestData *request_data = (DispatcherRequestData *) user_data;
}
void
-empathy_dispatcher_join_muc (McAccount *account, const gchar *roomname,
- EmpathyDispatcherRequestCb *callback, gpointer user_data)
+empathy_dispatcher_join_muc (McAccount *account,
+ const gchar *roomname,
+ EmpathyDispatcherRequestCb *callback,
+ gpointer user_data)
{
EmpathyDispatcher *dispatcher;
EmpathyDispatcherPriv *priv;
ConnectionData *connection_data;
const gchar *names[] = { roomname, NULL };
+ g_return_if_fail (MC_IS_ACCOUNT (account));
+ g_return_if_fail (!EMP_STR_EMPTY (roomname));
+
dispatcher = empathy_dispatcher_dup_singleton();
priv = GET_PRIV (dispatcher);
static void
dispatcher_create_channel_cb (TpConnection *connect,
- const gchar *object_path, GHashTable *properties, const GError *error,
- gpointer user_data, GObject *weak_object)
+ const gchar *object_path,
+ GHashTable *properties,
+ const GError *error,
+ gpointer user_data,
+ GObject *weak_object)
{
EmpathyDispatcher *dispatcher = EMPATHY_DISPATCHER (weak_object);
DispatcherRequestData *request_data = (DispatcherRequestData*) user_data;
request_data, object_path, properties, error);
}
+void
+empathy_dispatcher_create_channel (EmpathyDispatcher *dispatcher,
+ McAccount *account,
+ GHashTable *request,
+ EmpathyDispatcherRequestCb *callback,
+ gpointer user_data)
+{
+ EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
+ ConnectionData *connection_data;
+ DispatcherRequestData *request_data;
+ const gchar *channel_type;
+ guint handle_type;
+ guint handle;
+ gboolean valid;
+ TpConnection *connection;
+
+ g_return_if_fail (EMPATHY_IS_DISPATCHER (dispatcher));
+ g_return_if_fail (MC_IS_ACCOUNT (account));
+ g_return_if_fail (request != NULL);
+
+ connection = g_hash_table_lookup (priv->accounts, account);
+ g_assert (connection != NULL);
+
+ connection_data = g_hash_table_lookup (priv->connections, connection);
+ g_assert (connection_data != NULL);
+
+ channel_type = tp_asv_get_string (request, TP_IFACE_CHANNEL ".ChannelType");
+
+ handle_type = tp_asv_get_uint32 (request,
+ TP_IFACE_CHANNEL ".TargetHandleType", &valid);
+ if (!valid)
+ handle_type = TP_UNKNOWN_HANDLE_TYPE;
+
+ handle = tp_asv_get_uint32 (request, TP_IFACE_CHANNEL ".TargetHandle", NULL);
+
+ request_data = new_dispatcher_request_data (dispatcher, connection,
+ channel_type, handle_type, handle, request,
+ NULL, callback, user_data);
+
+ connection_data->outstanding_requests = g_list_prepend
+ (connection_data->outstanding_requests, request_data);
+
+ tp_cli_connection_interface_requests_call_create_channel (
+ request_data->connection, -1,
+ request_data->request, dispatcher_create_channel_cb, request_data, NULL,
+ G_OBJECT (request_data->dispatcher));
+}
static void
dispatcher_create_channel_with_contact_cb (EmpathyContact *contact,
- const GError *error, gpointer user_data, GObject *object)
+ const GError *error,
+ gpointer user_data,
+ GObject *object)
{
DispatcherRequestData *request_data = (DispatcherRequestData *) user_data;
GValue *target_handle;
G_OBJECT (request_data->dispatcher));
}
+static void
+dispatcher_send_file_connection_ready_cb (TpConnection *connection,
+ const GError *error,
+ gpointer user_data)
+{
+ DispatcherRequestData *request_data = (DispatcherRequestData *) user_data;
+
+ if (error != NULL)
+ {
+ dispatcher_request_failed (request_data->dispatcher,
+ request_data, error);
+ return;
+ }
+
+ empathy_contact_call_when_ready (request_data->contact,
+ EMPATHY_CONTACT_READY_HANDLE, dispatcher_create_channel_with_contact_cb,
+ request_data, NULL, G_OBJECT (request_data->dispatcher));
+}
+
void
empathy_dispatcher_send_file_to_contact (EmpathyContact *contact,
- const gchar *filename, guint64 size, guint64 date,
- const gchar *content_type, EmpathyDispatcherRequestCb *callback,
- gpointer user_data)
+ const gchar *filename,
+ guint64 size,
+ guint64 date,
+ const gchar *content_type,
+ EmpathyDispatcherRequestCb *callback,
+ gpointer user_data)
{
EmpathyDispatcher *dispatcher = empathy_dispatcher_dup_singleton();
EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
GHashTable *request = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
(GDestroyNotify) tp_g_value_slice_free);
+ g_return_if_fail (EMPATHY_IS_CONTACT (contact));
+ g_return_if_fail (!EMP_STR_EMPTY (filename));
+ g_return_if_fail (!EMP_STR_EMPTY (content_type));
+
/* org.freedesktop.Telepathy.Channel.ChannelType */
value = tp_g_value_slice_new (G_TYPE_STRING);
g_value_set_string (value, EMP_IFACE_CHANNEL_TYPE_FILE_TRANSFER);
connection_data->outstanding_requests = g_list_prepend
(connection_data->outstanding_requests, request_data);
- empathy_contact_call_when_ready (contact,
- EMPATHY_CONTACT_READY_HANDLE, dispatcher_create_channel_with_contact_cb,
- request_data, NULL, G_OBJECT (dispatcher));
+ tp_connection_call_when_ready (connection,
+ dispatcher_send_file_connection_ready_cb, (gpointer) request_data);
g_object_unref (dispatcher);
}
+
+GStrv
+empathy_dispatcher_find_channel_class (EmpathyDispatcher *dispatcher,
+ McAccount *account,
+ const gchar *channel_type,
+ guint handle_type)
+{
+ EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
+ ConnectionData *cd;
+ TpConnection *connection;
+ int i;
+ GPtrArray *classes;
+
+ g_return_val_if_fail (channel_type != NULL, NULL);
+ g_return_val_if_fail (handle_type != 0, NULL);
+
+ connection = g_hash_table_lookup (priv->accounts, account);
+
+ if (connection == NULL)
+ return NULL;
+
+ cd = g_hash_table_lookup (priv->connections, connection);
+
+ if (cd == NULL)
+ return NULL;
+
+
+ classes = cd->requestable_channels;
+ if (classes == NULL)
+ return NULL;
+
+ for (i = 0; i < classes->len; i++)
+ {
+ GValueArray *class;
+ GValue *fixed;
+ GValue *allowed;
+ GHashTable *fprops;
+ const gchar *c_type;
+ guint32 h_type;
+ gboolean valid;
+
+ class = g_ptr_array_index (classes, i);
+ fixed = g_value_array_get_nth (class, 0);
+
+ fprops = g_value_get_boxed (fixed);
+ c_type = tp_asv_get_string (fprops, TP_IFACE_CHANNEL ".ChannelType");
+
+ if (tp_strdiff (channel_type, c_type))
+ continue;
+
+ h_type = tp_asv_get_uint32 (fprops,
+ TP_IFACE_CHANNEL ".TargetHandleType", &valid);
+
+ if (!valid || handle_type != h_type)
+ continue;
+
+ allowed = g_value_array_get_nth (class, 1);
+
+ return g_value_get_boxed (allowed);
+ }
+
+ return NULL;
+}
+