1
/* Ekiga -- A VoIP and Video-Conferencing application
2
* Copyright (C) 2000-2009 Damien Sandras <dsandras@seconix.com>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU 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 Foundation,
16
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19
* Ekiga is licensed under the GPL license and as a special exception,
20
* you have permission to link or otherwise combine this program with the
21
* programs OPAL, OpenH323 and PWLIB, and distribute the combination,
22
* without applying the requirements of the GNU GPL to the OPAL, OpenH323
23
* and PWLIB programs, as long as you do follow the requirements of the
24
* GNU GPL for all the rest of the software thus combined.
29
* dbus_component.cpp - description
30
* -----------------------------
31
* begin : Tue Nov 1 2005
32
* copyright : (c) 2005 by Julien Puydt
33
* (c) 2007 by Damien Sandras
34
* (c) 2008 by Steve Frécinaux
35
* description : This files contains the implementation of the DBUS
42
#include <dbus/dbus-glib.h>
47
#include "gmmarshallers.h"
49
#include "callbacks.h"
52
#include "call-core.h"
54
/* Those defines the namespace and path we want to use. */
55
#define EKIGA_DBUS_NAMESPACE "org.ekiga.Ekiga"
56
#define EKIGA_DBUS_PATH "/org/ekiga/Ekiga"
57
#define EKIGA_DBUS_INTERFACE "org.ekiga.Ekiga"
59
G_DEFINE_TYPE(EkigaDBusComponent, ekiga_dbus_component, G_TYPE_OBJECT);
61
struct _EkigaDBusComponentPrivate
63
Ekiga::ServiceCore *core;
66
/**************************
67
* GOBJECT / DBUS METHODS *
68
**************************/
70
static gboolean ekiga_dbus_component_show (EkigaDBusComponent *self,
72
static gboolean ekiga_dbus_component_shutdown (EkigaDBusComponent *self,
74
static gboolean ekiga_dbus_component_call (EkigaDBusComponent *self,
77
static gboolean ekiga_dbus_component_get_user_name (EkigaDBusComponent *self,
80
static gboolean ekiga_dbus_component_get_user_location (EkigaDBusComponent *self,
83
static gboolean ekiga_dbus_component_get_user_comment (EkigaDBusComponent *self,
87
/* get the code to make the GObject accessible through dbus
88
* (this is especially where we get dbus_glib_dbus_component_object_info !)
90
#include "dbus-stub.h"
93
ekiga_dbus_component_init (EkigaDBusComponent *self)
95
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EKIGA_TYPE_DBUS_COMPONENT,
96
EkigaDBusComponentPrivate);
100
ekiga_dbus_component_class_init (EkigaDBusComponentClass *klass)
102
g_type_class_add_private (klass, sizeof (EkigaDBusComponentPrivate));
104
/* initializing as dbus object */
105
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (klass),
106
&dbus_glib_ekiga_dbus_component_object_info);
110
ekiga_dbus_component_show (G_GNUC_UNUSED EkigaDBusComponent *self,
111
G_GNUC_UNUSED GError **error)
113
PTRACE (1, "DBus\tShow");
115
GtkWidget *window = GnomeMeeting::Process ()->GetMainWindow ();
116
if (GTK_WIDGET_VISIBLE (window))
117
gtk_window_set_urgency_hint (GTK_WINDOW (window), TRUE);
119
gtk_window_present (GTK_WINDOW (window));
125
ekiga_dbus_component_shutdown (G_GNUC_UNUSED EkigaDBusComponent *self,
126
G_GNUC_UNUSED GError **error)
128
quit_callback (NULL, NULL);
134
ekiga_dbus_component_call (EkigaDBusComponent *self,
136
G_GNUC_UNUSED GError **error)
138
boost::shared_ptr<Ekiga::CallCore> call_core = self->priv->core->get<Ekiga::CallCore> ("call-core");
139
call_core->dial (uri);
145
ekiga_dbus_component_get_user_name (G_GNUC_UNUSED EkigaDBusComponent *self,
147
G_GNUC_UNUSED GError **error)
150
PTRACE (1, "DBus\tGetName");
152
full_name = gm_conf_get_string (PERSONAL_DATA_KEY "full_name");
156
/* not freeing the full name is not a leak : dbus will do it for us ! */
162
ekiga_dbus_component_get_user_location (G_GNUC_UNUSED EkigaDBusComponent *self,
164
G_GNUC_UNUSED GError **error)
166
PTRACE (1, "DBus\tGetLocation");
168
*location = gm_conf_get_string (PERSONAL_DATA_KEY "location");
174
ekiga_dbus_component_get_user_comment (G_GNUC_UNUSED EkigaDBusComponent *self,
176
G_GNUC_UNUSED GError **error)
178
PTRACE (1, "DBus\tGetComment");
180
*comment = gm_conf_get_string (PERSONAL_DATA_KEY "comment");
189
/** Claim ownership on the EKIGA_DBUS_NAMESPACE namespace.
190
* This function will return false if the namespace is already taken, ie if
191
* another instance of Ekiga is already running.
194
ekiga_dbus_claim_ownership ()
196
DBusGConnection *bus = NULL;
197
DBusGProxy *bus_proxy = NULL;
198
guint request_name_result;
199
GError *error = NULL;
201
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
203
PTRACE (1, "Couldn't connect to session bus : " << error->message);
204
g_error_free (error);
205
return TRUE; // if we return FALSE here, ekiga won't even start without DBUS
208
bus_proxy = dbus_g_proxy_new_for_name (bus, "org.freedesktop.DBus",
209
"/org/freedesktop/DBus",
210
"org.freedesktop.DBus");
212
if (!dbus_g_proxy_call (bus_proxy, "RequestName", &error,
213
G_TYPE_STRING, EKIGA_DBUS_NAMESPACE,
214
G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE,
216
G_TYPE_UINT, &request_name_result,
219
PTRACE (1, "Couldn't get ownership on the " EKIGA_DBUS_NAMESPACE " D-Bus namespace : "
221
g_error_free (error);
225
PTRACE (4, "Ekiga registered on D-Bus: " EKIGA_DBUS_NAMESPACE);
227
return request_name_result == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER;
230
/** Create the server object for the D-Bus interface.
231
* This object acts mostly as a proxy for the manager and other common objects.
232
* NOTE: We expect we have claimed the namespace successfully before, and that
233
* the manager and other key components are running.
236
ekiga_dbus_component_new (Ekiga::ServiceCore *core)
238
DBusGConnection *bus;
239
GError *error = NULL;
240
EkigaDBusComponent *obj;
242
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
244
PTRACE (1, "Couldn't connect to session bus : " << error->message);
245
g_error_free (error);
249
obj = EKIGA_DBUS_COMPONENT (g_object_new (EKIGA_TYPE_DBUS_COMPONENT, NULL));
250
obj->priv->core = core;
251
dbus_g_connection_register_g_object (bus, EKIGA_DBUS_PATH, G_OBJECT (obj));
257
get_ekiga_client_proxy ()
259
DBusGConnection *bus = NULL;
260
GError *error = NULL;
262
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
264
PTRACE (1, "Couldn't connect to session bus : " << error->message);
265
g_error_free (error);
269
return dbus_g_proxy_new_for_name (bus,
270
EKIGA_DBUS_NAMESPACE,
272
EKIGA_DBUS_INTERFACE);
275
/** Tell to a remote instance of Ekiga to connect to a remote SIP or H.323
277
* You will typically use this function when claim_ownership failed.
280
ekiga_dbus_client_connect (const gchar *uri)
282
DBusGProxy *proxy = get_ekiga_client_proxy ();
284
g_return_if_fail (DBUS_IS_G_PROXY (proxy));
286
dbus_g_proxy_call_no_reply (proxy, "Call", G_TYPE_STRING, uri, G_TYPE_INVALID);
287
g_object_unref (proxy);
290
/** Tell to a remote instance of Ekiga to show the main window.
291
* You will typically use this function when claim_ownership failed.
294
ekiga_dbus_client_show ()
296
DBusGProxy *proxy = get_ekiga_client_proxy ();
298
g_return_if_fail (DBUS_IS_G_PROXY (proxy));
300
dbus_g_proxy_call_no_reply (proxy, "Show", G_TYPE_INVALID);
301
g_object_unref (proxy);