1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007-2008 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Authors: Xavier Claessens <xclaesse@gmail.com>
24 #include <telepathy-glib/dbus.h>
25 #include <telepathy-glib/connection.h>
26 #include <telepathy-glib/channel.h>
28 #include <extensions/extensions.h>
29 #include "empathy-chandler.h"
30 #include "empathy-debug.h"
32 #define DEBUG_DOMAIN "EmpathyChandler"
34 static void chandler_iface_init (EmpSvcChandlerClass *klass);
41 static guint signals[LAST_SIGNAL];
43 G_DEFINE_TYPE_WITH_CODE (EmpathyChandler, empathy_chandler, G_TYPE_OBJECT,
44 G_IMPLEMENT_INTERFACE (EMP_TYPE_SVC_CHANDLER,
45 chandler_iface_init));
48 EmpathyChandler *chandler;
58 handle_channel_idle_cb (gpointer data)
60 IdleData *idle_data = data;
63 static TpDBusDaemon *daemon = NULL;
66 daemon = tp_dbus_daemon_new (tp_get_bus ());
69 conn = tp_connection_new (daemon, idle_data->bus_name,
70 idle_data->connection, NULL);
71 chan = tp_channel_new (conn, idle_data->channel, idle_data->channel_type,
72 idle_data->handle_type, idle_data->handle, NULL);
73 tp_channel_run_until_ready (chan, NULL, NULL);
75 empathy_debug (DEBUG_DOMAIN, "New channel to be handled: "
77 idle_data->channel_type, idle_data->handle);
78 g_signal_emit (idle_data->chandler, signals[NEW_CHANNEL], 0, chan);
80 g_object_unref (chan);
81 g_object_unref (conn);
82 g_free (idle_data->bus_name);
83 g_free (idle_data->connection);
84 g_free (idle_data->channel_type);
85 g_free (idle_data->channel);
86 g_slice_free (IdleData, idle_data);
92 my_handle_channel (EmpSvcChandler *self,
93 const gchar *bus_name,
94 const gchar *connection,
95 const gchar *channel_type,
99 DBusGMethodInvocation *context)
101 EmpathyChandler *chandler = EMPATHY_CHANDLER (self);
104 data = g_slice_new (IdleData);
105 data->chandler = chandler;
106 data->bus_name = g_strdup (bus_name);
107 data->connection = g_strdup (connection);
108 data->channel_type = g_strdup (channel_type);
109 data->channel = g_strdup (channel);
110 data->handle_type = handle_type;
111 data->handle = handle;
112 g_idle_add_full (G_PRIORITY_HIGH,
113 handle_channel_idle_cb,
116 emp_svc_chandler_return_from_handle_channel (context);
120 empathy_chandler_class_init (EmpathyChandlerClass *klass)
122 signals[NEW_CHANNEL] =
123 g_signal_new ("new-channel",
124 G_OBJECT_CLASS_TYPE (klass),
128 g_cclosure_marshal_VOID__OBJECT,
134 chandler_iface_init (EmpSvcChandlerClass *klass)
136 #define IMPLEMENT(x) emp_svc_chandler_implement_##x \
138 IMPLEMENT (handle_channel);
143 empathy_chandler_init (EmpathyChandler *chandler)
148 empathy_chandler_new (const gchar *bus_name,
149 const gchar *object_path)
151 EmpathyChandler *chandler;
154 GError *error = NULL;
156 proxy = dbus_g_proxy_new_for_name (tp_get_bus (),
159 DBUS_INTERFACE_DBUS);
161 if (!dbus_g_proxy_call (proxy, "RequestName", &error,
162 G_TYPE_STRING, bus_name,
163 G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE,
165 G_TYPE_UINT, &result,
167 empathy_debug (DEBUG_DOMAIN,
168 "Failed to request name: %s",
169 error ? error->message : "No error given");
170 g_clear_error (&error);
174 g_object_unref (proxy);
176 chandler = g_object_new (EMPATHY_TYPE_CHANDLER, NULL);
177 dbus_g_connection_register_g_object (tp_get_bus (),
179 G_OBJECT (chandler));