2 * Copyright (C) 2008 Collabora Ltd.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 * Authors: Xavier Claessens <xclaesse@gmail.com>
19 * Elliot Fairweather <elliot.fairweather@collabora.co.uk>
22 #include <dbus/dbus-glib.h>
24 #include <telepathy-glib/dbus.h>
25 #include <telepathy-glib/connection.h>
26 #include <telepathy-glib/channel.h>
27 #include <telepathy-glib/interfaces.h>
29 #include <extensions/extensions.h>
31 #include "empathy-debug.h"
32 #include "empathy-tube.h"
33 #include "empathy-tube-handler.h"
34 #include "empathy-tubes.h"
36 #define DEBUG_DOMAIN "EmpathyTubeHandler"
45 static void empathy_tube_handler_iface_init (EmpSvcTubeHandlerClass *klass);
46 static guint signals[LAST_SIGNAL];
48 G_DEFINE_TYPE_WITH_CODE (EmpathyTubeHandler, empathy_tube_handler,
49 G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (EMP_TYPE_SVC_TUBE_HANDLER,
50 empathy_tube_handler_iface_init))
54 EmpathyTubeHandler *thandler;
64 empathy_tube_handler_handle_tube_idle_cb (gpointer data)
66 IdleData *idle_data = data;
67 TpConnection *connection;
71 static TpDBusDaemon *daemon = NULL;
74 daemon = tp_dbus_daemon_new (tp_get_bus ());
76 connection = tp_connection_new (daemon, idle_data->bus_name,
77 idle_data->connection, NULL);
78 channel = tp_channel_new (connection, idle_data->channel,
79 TP_IFACE_CHANNEL_TYPE_TUBES, idle_data->handle_type,
80 idle_data->handle, NULL);
81 tp_channel_run_until_ready (channel, NULL, NULL);
83 tubes = empathy_tubes_new (channel);
84 tube = empathy_tubes_get_tube (tubes, idle_data->id);
86 empathy_debug (DEBUG_DOMAIN, "New tube to be handled");
88 g_signal_emit (idle_data->thandler, signals[NEW_TUBE], 0, tube);
90 g_object_unref (tube);
91 g_object_unref (tubes);
92 g_object_unref (channel);
93 g_object_unref (connection);
94 g_free (idle_data->bus_name);
95 g_free (idle_data->connection);
96 g_free (idle_data->channel);
97 g_slice_free (IdleData, idle_data);
104 empathy_tube_handler_handle_tube (EmpSvcTubeHandler *self,
105 const gchar *bus_name,
106 const gchar *connection,
107 const gchar *channel,
111 DBusGMethodInvocation *context)
113 EmpathyTubeHandler *thandler = EMPATHY_TUBE_HANDLER (self);
114 IdleData *data = g_slice_new (IdleData);
116 data->thandler = thandler;
117 data->bus_name = g_strdup (bus_name);
118 data->connection = g_strdup (connection);
119 data->channel = g_strdup (channel);
120 data->handle_type = handle_type;
121 data->handle = handle;
124 g_idle_add_full (G_PRIORITY_HIGH, empathy_tube_handler_handle_tube_idle_cb,
127 emp_svc_tube_handler_return_from_handle_tube (context);
132 empathy_tube_handler_class_init (EmpathyTubeHandlerClass *klass)
135 g_signal_new ("new-tube", G_OBJECT_CLASS_TYPE (klass),
136 G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT,
137 G_TYPE_NONE, 1, EMPATHY_TYPE_TUBE);
142 empathy_tube_handler_iface_init (EmpSvcTubeHandlerClass *klass)
144 emp_svc_tube_handler_implement_handle_tube (klass,
145 empathy_tube_handler_handle_tube);
150 empathy_tube_handler_init (EmpathyTubeHandler *thandler)
156 empathy_tube_handler_new (const gchar *bus_name,
157 const gchar *object_path)
159 EmpathyTubeHandler *thandler;
162 GError *error = NULL;
164 proxy = dbus_g_proxy_new_for_name (tp_get_bus (), DBUS_SERVICE_DBUS,
165 DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
167 if (!dbus_g_proxy_call (proxy, "RequestName", &error,
168 G_TYPE_STRING, bus_name, G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE,
169 G_TYPE_INVALID, G_TYPE_UINT, &result, G_TYPE_INVALID))
171 empathy_debug (DEBUG_DOMAIN, "Failed to request name: %s",
172 error ? error->message : "No error given");
173 g_clear_error (&error);
177 g_object_unref (proxy);
179 thandler = g_object_new (EMPATHY_TYPE_TUBE_HANDLER, NULL);
180 dbus_g_connection_register_g_object (tp_get_bus (), object_path,
181 G_OBJECT (thandler));