1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007 Collabora Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program 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 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Authors: Xavier Claessens <xclaesse@gmail.com>
25 #include <dbus/dbus-glib.h>
27 #include <libtelepathy/tp-helpers.h>
28 #include <libtelepathy/tp-conn.h>
29 #include <libtelepathy/tp-chan.h>
31 #include "empathy-chandler.h"
32 #include "gossip-debug.h"
33 #include "empathy-marshal.h"
35 #define DEBUG_DOMAIN "EmpathyChandler"
37 static gboolean empathy_chandler_handle_channel (EmpathyChandler *chandler,
38 const gchar *bus_name,
39 const gchar *connection,
40 const gchar *channel_type,
46 #include "empathy-chandler-glue.h"
53 static guint signals[LAST_SIGNAL];
55 G_DEFINE_TYPE (EmpathyChandler, empathy_chandler, G_TYPE_OBJECT)
58 empathy_chandler_class_init (EmpathyChandlerClass *klass)
60 signals[NEW_CHANNEL] =
61 g_signal_new ("new-channel",
62 G_OBJECT_CLASS_TYPE (klass),
66 empathy_marshal_VOID__OBJECT_OBJECT,
68 2, TELEPATHY_CONN_TYPE, TELEPATHY_CHAN_TYPE);
72 empathy_chandler_init (EmpathyChandler *chandler)
77 empathy_chandler_new (const gchar *bus_name,
78 const gchar *object_path)
80 static gboolean initialized = FALSE;
81 EmpathyChandler *chandler;
87 dbus_g_object_type_install_info (EMPATHY_TYPE_CHANDLER,
88 &dbus_glib_empathy_chandler_object_info);
92 proxy = dbus_g_proxy_new_for_name (tp_get_bus (),
97 if (!dbus_g_proxy_call (proxy, "RequestName", &error,
98 G_TYPE_STRING, bus_name,
99 G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE,
101 G_TYPE_UINT, &result,
103 gossip_debug (DEBUG_DOMAIN,
104 "Failed to request name: %s",
105 error ? error->message : "No error given");
106 g_clear_error (&error);
110 g_object_unref (proxy);
112 chandler = g_object_new (EMPATHY_TYPE_CHANDLER, NULL);
113 dbus_g_connection_register_g_object (tp_get_bus (),
115 G_OBJECT (chandler));
121 empathy_chandler_handle_channel (EmpathyChandler *chandler,
122 const gchar *bus_name,
123 const gchar *connection,
124 const gchar *channel_type,
125 const gchar *channel,
133 tp_conn = tp_conn_new (tp_get_bus (),
137 tp_chan = tp_chan_new (tp_get_bus(),
144 g_signal_emit (chandler, signals[NEW_CHANNEL], 0, tp_conn, tp_chan);
146 g_object_unref (tp_chan);
147 g_object_unref (tp_conn);