1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007 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 <dbus/dbus-glib.h>
26 #include <libtelepathy/tp-helpers.h>
27 #include <libtelepathy/tp-conn.h>
28 #include <libtelepathy/tp-chan.h>
30 #include "empathy-chandler.h"
31 #include "empathy-debug.h"
32 #include "empathy-marshal.h"
34 #define DEBUG_DOMAIN "EmpathyChandler"
36 static gboolean empathy_chandler_handle_channel (EmpathyChandler *chandler,
37 const gchar *bus_name,
38 const gchar *connection,
39 const gchar *channel_type,
45 #include "empathy-chandler-glue.h"
52 static guint signals[LAST_SIGNAL];
54 G_DEFINE_TYPE (EmpathyChandler, empathy_chandler, G_TYPE_OBJECT)
57 empathy_chandler_class_init (EmpathyChandlerClass *klass)
59 signals[NEW_CHANNEL] =
60 g_signal_new ("new-channel",
61 G_OBJECT_CLASS_TYPE (klass),
65 empathy_marshal_VOID__OBJECT_OBJECT,
67 2, TELEPATHY_CONN_TYPE, TELEPATHY_CHAN_TYPE);
71 empathy_chandler_init (EmpathyChandler *chandler)
76 empathy_chandler_new (const gchar *bus_name,
77 const gchar *object_path)
79 static gboolean initialized = FALSE;
80 EmpathyChandler *chandler;
86 dbus_g_object_type_install_info (EMPATHY_TYPE_CHANDLER,
87 &dbus_glib_empathy_chandler_object_info);
91 proxy = dbus_g_proxy_new_for_name (tp_get_bus (),
96 if (!dbus_g_proxy_call (proxy, "RequestName", &error,
97 G_TYPE_STRING, bus_name,
98 G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE,
100 G_TYPE_UINT, &result,
102 empathy_debug (DEBUG_DOMAIN,
103 "Failed to request name: %s",
104 error ? error->message : "No error given");
105 g_clear_error (&error);
109 g_object_unref (proxy);
111 chandler = g_object_new (EMPATHY_TYPE_CHANDLER, NULL);
112 dbus_g_connection_register_g_object (tp_get_bus (),
114 G_OBJECT (chandler));
120 empathy_chandler_handle_channel (EmpathyChandler *chandler,
121 const gchar *bus_name,
122 const gchar *connection,
123 const gchar *channel_type,
124 const gchar *channel,
132 tp_conn = tp_conn_new_without_connect (tp_get_bus (),
141 tp_chan = tp_chan_new (tp_get_bus(),
148 empathy_debug (DEBUG_DOMAIN, "New channel to be handled: "
150 channel_type, handle);
151 g_signal_emit (chandler, signals[NEW_CHANNEL], 0, tp_conn, tp_chan);
153 g_object_unref (tp_chan);
154 g_object_unref (tp_conn);