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