1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007 Xavier Claessens <xclaesse@gmail.com>
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.
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 "gossip-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 gossip_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 (tp_get_bus (),
136 tp_chan = tp_chan_new (tp_get_bus(),
143 g_signal_emit (chandler, signals[NEW_CHANNEL], 0, tp_conn, tp_chan);
145 g_object_unref (tp_chan);
146 g_object_unref (tp_conn);