]> git.0d.be Git - empathy.git/blob - libempathy/empathy-chandler.c
[darcs-to-svn @ Updating TODO]
[empathy.git] / libempathy / empathy-chandler.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2007 Collabora Ltd.
4  *
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.
9  *
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.
14  *
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.
19  * 
20  * Authors: Xavier Claessens <xclaesse@gmail.com>
21  */
22
23 #include <config.h>
24
25 #include <dbus/dbus-glib.h>
26
27 #include <libtelepathy/tp-helpers.h>
28 #include <libtelepathy/tp-conn.h>
29 #include <libtelepathy/tp-chan.h>
30
31 #include "empathy-chandler.h"
32 #include "gossip-debug.h"
33 #include "empathy-marshal.h"
34
35 #define DEBUG_DOMAIN "EmpathyChandler"
36
37 static gboolean empathy_chandler_handle_channel (EmpathyChandler *chandler,
38                                                  const gchar     *bus_name,
39                                                  const gchar     *connection,
40                                                  const gchar     *channel_type,
41                                                  const gchar     *channel,
42                                                  guint            handle_type,
43                                                  guint            handle,
44                                                  GError         **error);
45
46 #include "empathy-chandler-glue.h"
47
48 enum {
49         NEW_CHANNEL,
50         LAST_SIGNAL
51 };
52
53 static guint signals[LAST_SIGNAL];
54
55 G_DEFINE_TYPE (EmpathyChandler, empathy_chandler, G_TYPE_OBJECT)
56
57 static void
58 empathy_chandler_class_init (EmpathyChandlerClass *klass)
59 {
60         signals[NEW_CHANNEL] =
61                 g_signal_new ("new-channel",
62                               G_OBJECT_CLASS_TYPE (klass),
63                               G_SIGNAL_RUN_LAST,
64                               0,
65                               NULL, NULL,
66                               empathy_marshal_VOID__OBJECT_OBJECT,
67                               G_TYPE_NONE,
68                               2, TELEPATHY_CONN_TYPE, TELEPATHY_CHAN_TYPE);
69 }
70
71 static void
72 empathy_chandler_init (EmpathyChandler *chandler)
73 {
74 }
75
76 EmpathyChandler *
77 empathy_chandler_new (const gchar *bus_name,
78                       const gchar *object_path)
79 {
80         static gboolean  initialized = FALSE;
81         EmpathyChandler *chandler;
82         DBusGProxy      *proxy;
83         guint            result;
84         GError          *error = NULL;
85
86         if (!initialized) {
87                 dbus_g_object_type_install_info (EMPATHY_TYPE_CHANDLER,
88                                                  &dbus_glib_empathy_chandler_object_info);
89                 initialized = TRUE;
90         }
91
92         proxy = dbus_g_proxy_new_for_name (tp_get_bus (),
93                                            DBUS_SERVICE_DBUS,
94                                            DBUS_PATH_DBUS,
95                                            DBUS_INTERFACE_DBUS);
96
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,
100                                 G_TYPE_INVALID,
101                                 G_TYPE_UINT, &result,
102                                 G_TYPE_INVALID)) {
103                 gossip_debug (DEBUG_DOMAIN,
104                               "Failed to request name: %s",
105                               error ? error->message : "No error given");
106                 g_clear_error (&error);
107
108                 return NULL;
109         }
110         g_object_unref (proxy);
111
112         chandler = g_object_new (EMPATHY_TYPE_CHANDLER, NULL);
113         dbus_g_connection_register_g_object (tp_get_bus (),
114                                              object_path,
115                                              G_OBJECT (chandler));
116
117         return chandler;
118 }
119
120 static gboolean
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,
126                                  guint             handle_type,
127                                  guint             handle,
128                                  GError          **error)
129 {
130         TpChan *tp_chan;
131         TpConn *tp_conn;
132
133         tp_conn = tp_conn_new (tp_get_bus (),
134                                bus_name,
135                                connection);
136
137         tp_chan = tp_chan_new (tp_get_bus(),
138                                bus_name,
139                                channel,
140                                channel_type,
141                                handle_type,
142                                handle);
143
144         g_signal_emit (chandler, signals[NEW_CHANNEL], 0, tp_conn, tp_chan);
145
146         g_object_unref (tp_chan);
147         g_object_unref (tp_conn);
148
149         return TRUE;
150 }
151