diff options
-rw-r--r-- | docs/reference/telepathy-glib/telepathy-glib-docs.sgml | 1 | ||||
-rw-r--r-- | docs/reference/telepathy-glib/telepathy-glib-sections.txt | 19 | ||||
-rw-r--r-- | telepathy-glib/Makefile.am | 2 | ||||
-rw-r--r-- | telepathy-glib/base-connection.c | 187 | ||||
-rw-r--r-- | telepathy-glib/channel-manager-request-internal.h | 104 | ||||
-rw-r--r-- | telepathy-glib/channel-manager-request.c | 258 | ||||
-rw-r--r-- | telepathy-glib/channel-manager-request.h | 32 | ||||
-rw-r--r-- | telepathy-glib/introspection.am | 1 |
8 files changed, 450 insertions, 154 deletions
diff --git a/docs/reference/telepathy-glib/telepathy-glib-docs.sgml b/docs/reference/telepathy-glib/telepathy-glib-docs.sgml index 3f3fcf06a..e05011d0d 100644 --- a/docs/reference/telepathy-glib/telepathy-glib-docs.sgml +++ b/docs/reference/telepathy-glib/telepathy-glib-docs.sgml @@ -75,6 +75,7 @@ <xi:include href="xml/base-protocol.xml"/> <xi:include href="xml/base-connection.xml"/> <xi:include href="xml/channel-manager.xml"/> + <xi:include href="xml/channel-manager-request.xml"/> <xi:include href="xml/base-contact-list.xml"/> <xi:include href="xml/dbus-properties-mixin.xml"/> <xi:include href="xml/exportable-channel.xml"/> diff --git a/docs/reference/telepathy-glib/telepathy-glib-sections.txt b/docs/reference/telepathy-glib/telepathy-glib-sections.txt index 42def29dc..0bf65c991 100644 --- a/docs/reference/telepathy-glib/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib/telepathy-glib-sections.txt @@ -147,6 +147,25 @@ TP_CHANNEL_MANAGER_GET_INTERFACE <SECTION> <INCLUDE>telepathy-glib/telepathy-glib.h</INCLUDE> +<FILE>channel-manager-request</FILE> +<TITLE>TpChannelManagerRequest</TITLE> +TpChannelManagerRequest +TpChannelManagerRequestClass +TpChannelManagerRequestMethod +<SUBSECTION Standard> +TP_CHANNEL_MANAGER_REQUEST +TP_CHANNEL_MANAGER_REQUEST_CLASS +TP_CHANNEL_MANAGER_REQUEST_GET_CLASS +TP_IS_CHANNEL_MANAGER_REQUEST +TP_IS_CHANNEL_MANAGER_REQUEST_CLASS +TP_TYPE_CHANNEL_MANAGER_REQUEST +tp_channel_manager_request_get_type +<SUBSECTION Private> +TpChannelManagerRequestPriv +</SECTION> + +<SECTION> +<INCLUDE>telepathy-glib/telepathy-glib.h</INCLUDE> <FILE>exportable-channel</FILE> TpExportableChannelFunc <TITLE>TpExportableChannel</TITLE> diff --git a/telepathy-glib/Makefile.am b/telepathy-glib/Makefile.am index 67da0f607..e39e11222 100644 --- a/telepathy-glib/Makefile.am +++ b/telepathy-glib/Makefile.am @@ -70,6 +70,7 @@ tpginclude_HEADERS = \ channel-dispatcher.h \ channel-dispatch-operation.h \ channel-manager.h \ + channel-manager-request.h \ channel-request.h \ client.h \ client-factory.h \ @@ -251,6 +252,7 @@ libtelepathy_glib_main_internal_la_SOURCES = \ channel-dispatcher.c \ channel-dispatch-operation.c \ channel-manager.c \ + channel-manager-request.c \ channel-request.c \ client.c \ client-factory.c \ diff --git a/telepathy-glib/base-connection.c b/telepathy-glib/base-connection.c index 01615fb09..461b53b72 100644 --- a/telepathy-glib/base-connection.c +++ b/telepathy-glib/base-connection.c @@ -239,6 +239,7 @@ #include <dbus/dbus-glib-lowlevel.h> #include <telepathy-glib/channel-manager.h> +#include <telepathy-glib/channel-manager-request-internal.h> #include <telepathy-glib/connection-manager.h> #include <telepathy-glib/dbus-properties-mixin.h> #include <telepathy-glib/dbus.h> @@ -291,82 +292,13 @@ enum static guint signals[N_SIGNALS] = {0}; -typedef struct _ChannelRequest ChannelRequest; - -typedef enum { - METHOD_CREATE_CHANNEL, - METHOD_ENSURE_CHANNEL, - NUM_METHODS -} ChannelRequestMethod; - -struct _ChannelRequest -{ - DBusGMethodInvocation *context; - ChannelRequestMethod method; - - gchar *channel_type; - guint handle_type; - guint handle; - - /* only meaningful for METHOD_ENSURE_CHANNEL; only true if this is the first - * request to be satisfied with a particular channel, and no other request - * satisfied by that channel has a different method. - */ - unsigned yours : 1; -}; - -static ChannelRequest * -channel_request_new (DBusGMethodInvocation *context, - ChannelRequestMethod method, - const char *channel_type, - guint handle_type, - guint handle) -{ - ChannelRequest *ret; - - g_assert (NULL != context); - g_assert (NULL != channel_type); - g_assert (method < NUM_METHODS); - - ret = g_slice_new0 (ChannelRequest); - ret->context = context; - ret->method = method; - ret->channel_type = g_strdup (channel_type); - ret->handle_type = handle_type; - ret->handle = handle; - ret->yours = FALSE; - - DEBUG("New channel request at %p: ctype=%s htype=%d handle=%d", - ret, channel_type, handle_type, handle); - - return ret; -} - static void -channel_request_free (ChannelRequest *request) -{ - g_assert (NULL == request->context); - DEBUG("Freeing channel request at %p: ctype=%s htype=%d handle=%d", - request, request->channel_type, request->handle_type, - request->handle); - g_free (request->channel_type); - g_slice_free (ChannelRequest, request); -} - -static void -channel_request_cancel (gpointer data, gpointer user_data) +channel_request_cancel (gpointer data, + gpointer user_data) { - ChannelRequest *request = (ChannelRequest *) data; - GError error = { TP_ERROR, TP_ERROR_DISCONNECTED, - "unable to service this channel request, we're disconnecting!" }; + TpChannelManagerRequest *request = (TpChannelManagerRequest *) data; - DEBUG ("cancelling request at %p for %s/%u/%u", request, - request->channel_type, request->handle_type, request->handle); - - dbus_g_method_return_error (request->context, &error); - request->context = NULL; - - channel_request_free (request); + _tp_channel_manager_request_cancel (request); } struct _TpBaseConnectionPrivate @@ -386,7 +318,7 @@ struct _TpBaseConnectionPrivate gboolean dispose_has_run; /* array of (TpChannelManager *) */ GPtrArray *channel_managers; - /* array of (ChannelRequest *) */ + /* array of reffed (TpChannelManagerRequest *) */ GPtrArray *channel_requests; TpHandleRepoIface *handles[TP_NUM_HANDLE_TYPES]; @@ -658,75 +590,24 @@ get_channel_details (GObject *obj) static void satisfy_request (TpBaseConnection *conn, - ChannelRequest *request, - GObject *channel, - const gchar *object_path) + TpChannelManagerRequest *request, + TpExportableChannel *channel) { TpBaseConnectionPrivate *priv = conn->priv; - DEBUG ("completing queued request %p with success, " - "channel_type=%s, handle_type=%u, " - "handle=%u", request, request->channel_type, - request->handle_type, request->handle); - - switch (request->method) - { - case METHOD_CREATE_CHANNEL: - { - GHashTable *properties; - - g_assert (TP_IS_EXPORTABLE_CHANNEL (channel)); - g_object_get (channel, - "channel-properties", &properties, - NULL); - tp_svc_connection_interface_requests_return_from_create_channel ( - request->context, object_path, properties); - g_hash_table_unref (properties); - } - break; - - case METHOD_ENSURE_CHANNEL: - { - GHashTable *properties; - - g_assert (TP_IS_EXPORTABLE_CHANNEL (channel)); - g_object_get (channel, - "channel-properties", &properties, - NULL); - tp_svc_connection_interface_requests_return_from_ensure_channel ( - request->context, request->yours, object_path, properties); - g_hash_table_unref (properties); - } - break; - - default: - g_assert_not_reached (); - } - request->context = NULL; - + _tp_channel_manager_request_satisfy (request, channel); g_ptr_array_remove (priv->channel_requests, request); - - channel_request_free (request); } static void fail_channel_request (TpBaseConnection *conn, - ChannelRequest *request, - GError *error) + TpChannelManagerRequest *request, + GError *error) { TpBaseConnectionPrivate *priv = conn->priv; - DEBUG ("completing queued request %p with error, channel_type=%s, " - "handle_type=%u, handle=%u", - request, request->channel_type, - request->handle_type, request->handle); - - dbus_g_method_return_error (request->context, error); - request->context = NULL; - + _tp_channel_manager_request_fail (request, error); g_ptr_array_remove (priv->channel_requests, request); - - channel_request_free (request); } /* Channel manager signal handlers */ @@ -742,7 +623,7 @@ manager_new_channel (gpointer key, gchar *object_path; GSList *iter; gboolean satisfies_create_channel = FALSE; - ChannelRequest *first_ensure = NULL; + TpChannelManagerRequest *first_ensure = NULL; g_object_get (channel, "object-path", &object_path, @@ -750,21 +631,21 @@ manager_new_channel (gpointer key, for (iter = request_tokens; iter != NULL; iter = iter->next) { - ChannelRequest *request = iter->data; + TpChannelManagerRequest *request = iter->data; switch (request->method) { - case METHOD_CREATE_CHANNEL: + case TP_CHANNEL_MANAGER_REQUEST_METHOD_CREATE_CHANNEL: satisfies_create_channel = TRUE; goto break_loop_early; break; - case METHOD_ENSURE_CHANNEL: + case TP_CHANNEL_MANAGER_REQUEST_METHOD_ENSURE_CHANNEL: if (first_ensure == NULL) first_ensure = request; break; - case NUM_METHODS: + case TP_NUM_CHANNEL_MANAGER_REQUEST_METHODS: g_assert_not_reached (); } @@ -782,8 +663,7 @@ break_loop_early: for (iter = request_tokens; iter != NULL; iter = iter->next) { - satisfy_request (self, iter->data, G_OBJECT (channel), - object_path); + satisfy_request (self, iter->data, TP_EXPORTABLE_CHANNEL (channel)); } g_free (object_path); @@ -843,7 +723,7 @@ manager_request_already_satisfied_cb (TpChannelManager *manager, "object-path", &object_path, NULL); - satisfy_request (self, request_token, G_OBJECT (channel), object_path); + satisfy_request (self, request_token, TP_EXPORTABLE_CHANNEL (channel)); g_free (object_path); } @@ -1382,7 +1262,7 @@ tp_base_connection_init (TpBaseConnection *self) priv->handles[i] = NULL; } - priv->channel_requests = g_ptr_array_new (); + priv->channel_requests = g_ptr_array_new_with_free_func (g_object_unref); priv->client_interests = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) g_hash_table_unref); priv->interested_clients = g_hash_table_new_full (g_str_hash, g_str_equal, @@ -2484,18 +2364,18 @@ finally: * the chain unless an error has occured. */ static void conn_requests_check_basic_properties (TpBaseConnection *self, - GHashTable *requested_properties, ChannelRequestMethod method, + GHashTable *requested_properties, TpChannelManagerRequestMethod method, DBusGMethodInvocation *context); static void conn_requests_requestotron_validate_handle (TpBaseConnection *self, - GHashTable *requested_properties, ChannelRequestMethod method, + GHashTable *requested_properties, TpChannelManagerRequestMethod method, const gchar *type, TpHandleType target_handle_type, TpHandle target_handle, const gchar *target_id, DBusGMethodInvocation *context); static void conn_requests_offer_request (TpBaseConnection *self, - GHashTable *requested_properties, ChannelRequestMethod method, + GHashTable *requested_properties, TpChannelManagerRequestMethod method, const gchar *type, TpHandleType target_handle_type, TpHandle target_handle, DBusGMethodInvocation *context); @@ -2511,7 +2391,7 @@ static void conn_requests_offer_request (TpBaseConnection *self, static void conn_requests_requestotron (TpBaseConnection *self, GHashTable *requested_properties, - ChannelRequestMethod method, + TpChannelManagerRequestMethod method, DBusGMethodInvocation *context) { TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (self, context); @@ -2527,7 +2407,7 @@ conn_requests_requestotron (TpBaseConnection *self, static void conn_requests_check_basic_properties (TpBaseConnection *self, GHashTable *requested_properties, - ChannelRequestMethod method, + TpChannelManagerRequestMethod method, DBusGMethodInvocation *context) { /* Step 1: @@ -2602,7 +2482,7 @@ conn_requests_check_basic_properties (TpBaseConnection *self, static void conn_requests_requestotron_validate_handle (TpBaseConnection *self, GHashTable *requested_properties, - ChannelRequestMethod method, + TpChannelManagerRequestMethod method, const gchar *type, TpHandleType target_handle_type, TpHandle target_handle, @@ -2726,7 +2606,7 @@ conn_requests_requestotron_validate_handle (TpBaseConnection *self, static void conn_requests_offer_request (TpBaseConnection *self, GHashTable *requested_properties, - ChannelRequestMethod method, + TpChannelManagerRequestMethod method, const gchar *type, TpHandleType target_handle_type, TpHandle target_handle, @@ -2737,16 +2617,16 @@ conn_requests_offer_request (TpBaseConnection *self, */ TpBaseConnectionPrivate *priv = self->priv; TpChannelManagerRequestFunc func; - ChannelRequest *request; + TpChannelManagerRequest *request; guint i; switch (method) { - case METHOD_CREATE_CHANNEL: + case TP_CHANNEL_MANAGER_REQUEST_METHOD_CREATE_CHANNEL: func = tp_channel_manager_create_channel; break; - case METHOD_ENSURE_CHANNEL: + case TP_CHANNEL_MANAGER_REQUEST_METHOD_ENSURE_CHANNEL: func = tp_channel_manager_ensure_channel; break; @@ -2754,7 +2634,7 @@ conn_requests_offer_request (TpBaseConnection *self, g_assert_not_reached (); } - request = channel_request_new (context, method, + request = _tp_channel_manager_request_new (context, method, type, target_handle_type, target_handle); g_ptr_array_add (priv->channel_requests, request); @@ -2772,7 +2652,6 @@ conn_requests_offer_request (TpBaseConnection *self, request->context = NULL; g_ptr_array_remove (priv->channel_requests, request); - channel_request_free (request); } @@ -2784,7 +2663,7 @@ conn_requests_create_channel (TpSvcConnectionInterfaceRequests *svc, TpBaseConnection *self = TP_BASE_CONNECTION (svc); conn_requests_requestotron (self, requested_properties, - METHOD_CREATE_CHANNEL, context); + TP_CHANNEL_MANAGER_REQUEST_METHOD_CREATE_CHANNEL, context); } @@ -2796,7 +2675,7 @@ conn_requests_ensure_channel (TpSvcConnectionInterfaceRequests *svc, TpBaseConnection *self = TP_BASE_CONNECTION (svc); conn_requests_requestotron (self, requested_properties, - METHOD_ENSURE_CHANNEL, context); + TP_CHANNEL_MANAGER_REQUEST_METHOD_ENSURE_CHANNEL, context); } diff --git a/telepathy-glib/channel-manager-request-internal.h b/telepathy-glib/channel-manager-request-internal.h new file mode 100644 index 000000000..1d0c4b88b --- /dev/null +++ b/telepathy-glib/channel-manager-request-internal.h @@ -0,0 +1,104 @@ +/* + * channel-manager-request-internal.h + * + * Copyright (C) 2014 Collabora Ltd. <http://www.collabora.co.uk/> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * 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, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __TP_CHANNEL_MANAGER_REQUEST_INTERNAL_H__ +#define __TP_CHANNEL_MANAGER_REQUEST_INTERNAL_H__ + +#include "channel-manager-request.h" + +#include <glib-object.h> + +#include <dbus/dbus-glib-lowlevel.h> +#include <telepathy-glib/telepathy-glib.h> + +G_BEGIN_DECLS + +typedef enum { + TP_CHANNEL_MANAGER_REQUEST_METHOD_CREATE_CHANNEL, + TP_CHANNEL_MANAGER_REQUEST_METHOD_ENSURE_CHANNEL, + TP_NUM_CHANNEL_MANAGER_REQUEST_METHODS, +} TpChannelManagerRequestMethod; + +struct _TpChannelManagerRequestClass +{ + /*<private>*/ + GObjectClass parent_class; +}; + +struct _TpChannelManagerRequest +{ + /*<private>*/ + GObject parent; + + DBusGMethodInvocation *context; + TpChannelManagerRequestMethod method; + + gchar *channel_type; + TpHandleType handle_type; + TpHandle handle; + + /* only meaningful for METHOD_ENSURE_CHANNEL; only true if this is the first + * request to be satisfied with a particular channel, and no other request + * satisfied by that channel has a different method. + */ + gboolean yours; +}; + +GType tp_channel_manager_request_get_type (void); + +/* TYPE MACROS */ +#define TP_TYPE_CHANNEL_MANAGER_REQUEST \ + (tp_channel_manager_request_get_type ()) +#define TP_CHANNEL_MANAGER_REQUEST(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + TP_TYPE_CHANNEL_MANAGER_REQUEST, \ + TpChannelManagerRequest)) +#define TP_CHANNEL_MANAGER_REQUEST_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), \ + TP_TYPE_CHANNEL_MANAGER_REQUEST, \ + TpChannelManagerRequestClass)) +#define TP_IS_CHANNEL_MANAGER_REQUEST(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + TP_TYPE_CHANNEL_MANAGER_REQUEST)) +#define TP_IS_CHANNEL_MANAGER_REQUEST_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), \ + TP_TYPE_CHANNEL_MANAGER_REQUEST)) +#define TP_CHANNEL_MANAGER_REQUEST_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + TP_TYPE_CHANNEL_MANAGER_REQUEST, \ + TpChannelManagerRequestClass)) + +TpChannelManagerRequest * _tp_channel_manager_request_new ( + DBusGMethodInvocation *context, + TpChannelManagerRequestMethod method, + const char *channel_type, + TpHandleType handle_type, + TpHandle handle); + +void _tp_channel_manager_request_cancel (TpChannelManagerRequest *self); + +void _tp_channel_manager_request_satisfy (TpChannelManagerRequest *self, + TpExportableChannel *channel); + +void _tp_channel_manager_request_fail (TpChannelManagerRequest *self, + GError *error); + +G_END_DECLS + +#endif /* #ifndef __TP_CHANNEL_MANAGER_REQUEST_INTERNAL_H__*/ diff --git a/telepathy-glib/channel-manager-request.c b/telepathy-glib/channel-manager-request.c new file mode 100644 index 000000000..bbbe72c03 --- /dev/null +++ b/telepathy-glib/channel-manager-request.c @@ -0,0 +1,258 @@ +/* + * channel-manager-request.c + * + * Copyright (C) 2014 Collabora Ltd. <http://www.collabora.co.uk/> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * 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, see <http://www.gnu.org/licenses/>. + */ + +#include "config.h" + +#include "channel-manager-request.h" +#include "channel-manager-request-internal.h" + +#define DEBUG_FLAG TP_DEBUG_DISPATCHER +#include "telepathy-glib/debug-internal.h" + +#include <telepathy-glib/telepathy-glib-dbus.h> + +/** + * SECTION: channel-manager-request + * @title: TpChannelManagerRequest + * @short_description: TODO + * + * TODO + */ + +/** + * TpChannelManagerRequest: + * + * Data structure representing a #TpChannelManagerRequest. + * + * Since: UNRELEASED + */ + +/** + * TpChannelManagerRequestClass: + * + * The class of a #TpChannelManagerRequest. + * + * Since: UNRELEASED + */ + +G_DEFINE_TYPE (TpChannelManagerRequest, tp_channel_manager_request, G_TYPE_OBJECT) + +enum +{ + PROP_FIRST_PROP = 1, + N_PROPS +}; + +/* +enum +{ + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL]; +*/ + +struct _TpChannelManagerRequestPriv +{ + gpointer badger; +}; + +static void +tp_channel_manager_request_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + //TpChannelManagerRequest *self = TP_CHANNEL_MANAGER_REQUEST (object); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +tp_channel_manager_request_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + //TpChannelManagerRequest *self = TP_CHANNEL_MANAGER_REQUEST (object); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +tp_channel_manager_request_constructed (GObject *object) +{ + //TpChannelManagerRequest *self = TP_CHANNEL_MANAGER_REQUEST (object); + void (*chain_up) (GObject *) = + ((GObjectClass *) tp_channel_manager_request_parent_class)->constructed; + + chain_up (object); +} + +static void +tp_channel_manager_request_dispose (GObject *object) +{ + //TpChannelManagerRequest *self = TP_CHANNEL_MANAGER_REQUEST (object); + void (*chain_up) (GObject *) = + ((GObjectClass *) tp_channel_manager_request_parent_class)->dispose; + + chain_up (object); +} + +static void +tp_channel_manager_request_finalize (GObject *object) +{ + TpChannelManagerRequest *self = TP_CHANNEL_MANAGER_REQUEST (object); + void (*chain_up) (GObject *) = + ((GObjectClass *) tp_channel_manager_request_parent_class)->finalize; + + g_assert (self->context == NULL); + + DEBUG("Freeing channel request at %p: ctype=%s htype=%d handle=%d", + self, self->channel_type, self->handle_type, + self->handle); + + g_free (self->channel_type); + + chain_up (object); +} + +static void +tp_channel_manager_request_class_init ( + TpChannelManagerRequestClass *klass) +{ + GObjectClass *oclass = G_OBJECT_CLASS (klass); + //GParamSpec *spec; + + oclass->get_property = tp_channel_manager_request_get_property; + oclass->set_property = tp_channel_manager_request_set_property; + oclass->constructed = tp_channel_manager_request_constructed; + oclass->dispose = tp_channel_manager_request_dispose; + oclass->finalize = tp_channel_manager_request_finalize; +} + +static void +tp_channel_manager_request_init (TpChannelManagerRequest *self) +{ +} + +TpChannelManagerRequest * +_tp_channel_manager_request_new ( + DBusGMethodInvocation *context, + TpChannelManagerRequestMethod method, + const char *channel_type, + TpHandleType handle_type, + TpHandle handle) +{ + TpChannelManagerRequest *result; + + g_return_val_if_fail (context != NULL, NULL); + g_return_val_if_fail (channel_type != NULL, NULL); + g_return_val_if_fail (method < TP_NUM_CHANNEL_MANAGER_REQUEST_METHODS, NULL); + + result = g_object_new (TP_TYPE_CHANNEL_MANAGER_REQUEST, + NULL); + + result->context = context; + result->method = method; + result->channel_type = g_strdup (channel_type); + result->handle_type = handle_type; + result->handle = handle; + result->yours = FALSE; + + DEBUG ("New channel request at %p: ctype=%s htype=%d handle=%d", + result, channel_type, handle_type, handle); + + return result; +} + +void +_tp_channel_manager_request_cancel (TpChannelManagerRequest *self) +{ + GError error = { TP_ERROR, TP_ERROR_DISCONNECTED, + "unable to service this channel request, we're disconnecting!" }; + + DEBUG ("cancelling request at %p for %s/%u/%u", self, + self->channel_type, self->handle_type, self->handle); + + dbus_g_method_return_error (self->context, &error); + self->context = NULL; +} + +void +_tp_channel_manager_request_satisfy (TpChannelManagerRequest *self, + TpExportableChannel *channel) +{ + gchar *object_path; + GHashTable *properties; + + g_return_if_fail (TP_IS_EXPORTABLE_CHANNEL (channel)); + + DEBUG ("completing queued request %p with success, " + "channel_type=%s, handle_type=%u, " + "handle=%u", self, self->channel_type, self->handle_type, self->handle); + + g_object_get (channel, + "object-path", &object_path, + "channel-properties", &properties, + NULL); + + switch (self->method) + { + case TP_CHANNEL_MANAGER_REQUEST_METHOD_CREATE_CHANNEL: + tp_svc_connection_interface_requests_return_from_create_channel ( + self->context, object_path, properties); + break; + + case TP_CHANNEL_MANAGER_REQUEST_METHOD_ENSURE_CHANNEL: + tp_svc_connection_interface_requests_return_from_ensure_channel ( + self->context, self->yours, object_path, properties); + break; + + default: + g_assert_not_reached (); + } + + self->context = NULL; + + g_free (object_path); + g_hash_table_unref (properties); +} + +void +_tp_channel_manager_request_fail (TpChannelManagerRequest *self, + GError *error) +{ + DEBUG ("completing queued request %p with error, channel_type=%s, " + "handle_type=%u, handle=%u", + self, self->channel_type, self->handle_type, self->handle); + + dbus_g_method_return_error (self->context, error); + self->context = NULL; +} diff --git a/telepathy-glib/channel-manager-request.h b/telepathy-glib/channel-manager-request.h new file mode 100644 index 000000000..0da61a3c8 --- /dev/null +++ b/telepathy-glib/channel-manager-request.h @@ -0,0 +1,32 @@ +/* + * channel-manager-request.h + * + * Copyright (C) 2014 Collabora Ltd. <http://www.collabora.co.uk/> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * 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, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __TP_CHANNEL_MANAGER_REQUEST_H__ +#define __TP_CHANNEL_MANAGER_REQUEST_H__ + +#include <glib-object.h> + +G_BEGIN_DECLS + +typedef struct _TpChannelManagerRequest TpChannelManagerRequest; +typedef struct _TpChannelManagerRequestClass TpChannelManagerRequestClass; + +G_END_DECLS + +#endif /* #ifndef __TP_CHANNEL_MANAGER_REQUEST_H__*/ diff --git a/telepathy-glib/introspection.am b/telepathy-glib/introspection.am index 1a5e2a41e..ef7683e90 100644 --- a/telepathy-glib/introspection.am +++ b/telepathy-glib/introspection.am @@ -31,6 +31,7 @@ TelepathyGLib_1_gir_FILES = \ $(srcdir)/protocol.c $(srcdir)/protocol.h \ $(srcdir)/connection-manager.c $(srcdir)/connection-manager.h \ $(srcdir)/channel.c $(srcdir)/channel.h \ + $(srcdir)/channel-manager-request.c $(srcdir)/channel-manager-request.h \ $(srcdir)/channel-group.c \ $(srcdir)/handle.c $(srcdir)/handle.h \ $(srcdir)/handle-channel-context.c $(srcdir)/handle-channel-context.h \ |