2
* © 2009, Collabora Ltd
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; either version 2 of the
7
* License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20
* Arnaud Maillet <arnaud.maillet@collabora.co.uk>
23
#include <glib-object.h>
25
#include <dbus/dbus-glib.h>
27
#include <telepathy-glib/telepathy-glib.h>
29
#include "vino-tube-servers-manager.h"
30
#include "vino-server.h"
31
#include "vino-tube-server.h"
32
#include "vino-dbus-error.h"
33
#include "vino-status-tube-icon.h"
34
#include "vino-util.h"
36
G_DEFINE_TYPE (VinoTubeServersManager, vino_tube_servers_manager,
39
#define VINO_TUBE_SERVERS_MANAGER_GET_PRIVATE(obj)\
40
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), VINO_TYPE_TUBE_SERVERS_MANAGER,\
41
VinoTubeServersManagerPrivate))
43
static void handle_channels_cb (TpSimpleHandler *handler,
45
TpConnection *connection,
47
GList *requests_satisfied,
48
gint64 user_action_time,
49
TpHandleChannelsContext *context,
52
struct _VinoTubeServersManagerPrivate
54
GSList *vino_tube_servers;
55
guint alternative_port;
57
TpBaseClient *handler;
61
vino_tube_servers_manager_dispose (GObject *object)
63
VinoTubeServersManager *self = VINO_TUBE_SERVERS_MANAGER (object);
66
for (l = self->priv->vino_tube_servers; l; l = l->next)
67
g_object_unref (l->data);
69
g_slist_free (self->priv->vino_tube_servers);
70
self->priv->vino_tube_servers = NULL;
72
dprintf (TUBE, "Destruction of the VinoTubeServersManager\n");
74
if (G_OBJECT_CLASS (vino_tube_servers_manager_parent_class)->dispose)
75
G_OBJECT_CLASS (vino_tube_servers_manager_parent_class)->dispose (object);
79
vino_tube_servers_manager_class_init (VinoTubeServersManagerClass *klass)
81
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
83
dprintf (TUBE, "Creation of the VinoTubeServersManager\n");
85
gobject_class->dispose = vino_tube_servers_manager_dispose;
87
g_type_class_add_private (klass, sizeof (VinoTubeServersManagerPrivate));
91
vino_tube_servers_manager_init (VinoTubeServersManager *self)
96
self->priv = VINO_TUBE_SERVERS_MANAGER_GET_PRIVATE (self);
97
self->priv->vino_tube_servers = NULL;
98
self->priv->alternative_port = 26570;
100
dbus = tp_dbus_daemon_dup (NULL);
102
self->priv->handler = tp_simple_handler_new (dbus, FALSE, FALSE, "Vino",
103
FALSE, handle_channels_cb, self, NULL);
105
g_object_unref (dbus);
107
tp_base_client_take_handler_filter (self->priv->handler, tp_asv_new (
108
TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
109
TP_IFACE_CHANNEL_TYPE_STREAM_TUBE,
110
TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT,
111
TP_HANDLE_TYPE_CONTACT,
112
TP_PROP_CHANNEL_REQUESTED, G_TYPE_BOOLEAN,
114
TP_PROP_CHANNEL_TYPE_STREAM_TUBE_SERVICE, G_TYPE_STRING,
118
if (!tp_base_client_register (self->priv->handler, &error))
120
dprintf (TUBE, "Failed to register Handler: %s\n", error->message);
121
g_error_free (error);
126
vino_tube_servers_manager_disconnected_cb (VinoTubeServer *server,
129
VinoTubeServersManager *self = VINO_TUBE_SERVERS_MANAGER (object);
130
self->priv->vino_tube_servers = g_slist_remove
131
(self->priv->vino_tube_servers, server);
132
g_object_unref (server);
135
VinoTubeServersManager *
136
vino_tube_servers_manager_new (void)
138
return g_object_new (VINO_TYPE_TUBE_SERVERS_MANAGER, NULL);
142
handle_channels_cb (TpSimpleHandler *handler,
144
TpConnection *connection,
146
GList *requests_satisfied,
147
gint64 user_action_time,
148
TpHandleChannelsContext *context,
151
VinoTubeServersManager *self = user_data;
152
VinoTubeServer *server;
155
/* the server is listenning only on lo as only the tube is supposed to
157
gchar * network_interface = "lo";
159
TpChannel *channel = NULL;
161
for (l = channels; l != NULL; l = g_list_next (l))
163
TpChannel *chan = l->data;
164
const gchar *service;
166
if (tp_channel_get_channel_type_id (chan) !=
167
TP_IFACE_QUARK_CHANNEL_TYPE_STREAM_TUBE)
170
if (tp_proxy_get_invalidated (chan) != NULL)
173
service = tp_asv_get_string (
174
tp_channel_borrow_immutable_properties (chan),
175
TP_PROP_CHANNEL_TYPE_STREAM_TUBE_SERVICE);
177
if (tp_strdiff (service, "rfb"))
186
/* No stream tube channel ?! */
187
GError error = { TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
188
"No stream tube channel" };
190
tp_handle_channels_context_fail (context, &error);
194
display = gdk_display_get_default ();
195
screen = gdk_display_get_default_screen (display);
197
server = g_object_new (VINO_TYPE_TUBE_SERVER,
198
"display-status-icon", 0,
201
"network-interface", network_interface,
202
"use-alternative-port", 1,
203
"alternative-port", self->priv->alternative_port,
205
"require-encryption", 0,
206
"vnc-password", NULL,
210
"disable-background", 0,
212
"connection", connection,
216
self->priv->vino_tube_servers = g_slist_prepend
217
(self->priv->vino_tube_servers, server);
219
g_signal_connect (G_OBJECT (server), "disconnected", G_CALLBACK
220
(vino_tube_servers_manager_disconnected_cb), self);
222
self->priv->alternative_port++;
224
vino_tube_server_share_with_tube (server, NULL);
226
tp_handle_channels_context_accept (context);