]> git.0d.be Git - empathy.git/blob - libempathy/empathy-chandler.c
Do not export symbols outside the empathy_ namespace.
[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 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.
9  *
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.
14  *
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
18  * 
19  * Authors: Xavier Claessens <xclaesse@gmail.com>
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 "empathy-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                 empathy_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_without_connect (tp_get_bus (),
133                                                bus_name,
134                                                connection,
135                                                NULL,
136                                                error);
137         if (!tp_conn) {
138                 return FALSE;
139         }
140
141         tp_chan = tp_chan_new (tp_get_bus(),
142                                bus_name,
143                                channel,
144                                channel_type,
145                                handle_type,
146                                handle);
147
148         empathy_debug (DEBUG_DOMAIN, "New channel to be handled: "
149                                      "type=%s handle=%d",
150                                      channel_type, handle);
151         g_signal_emit (chandler, signals[NEW_CHANNEL], 0, tp_conn, tp_chan);
152
153         g_object_unref (tp_chan);
154         g_object_unref (tp_conn);
155
156         return TRUE;
157 }
158