~ubuntu-branches/ubuntu/vivid/ekiga/vivid-proposed

« back to all changes in this revision

Viewing changes to src/dbus-helper/dbus.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kilian Krause
  • Date: 2011-07-17 00:24:50 UTC
  • mfrom: (5.1.5 upstream) (7.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110717002450-ytg3wsrc1ptd3153
Tags: 3.3.1-1
* New upstream release.
 - Required libpt-dev 2.10 and libopal-dev 3.10
* Fix debian/watch to catch new version
* Remove libnotify0.7.patch - included upstream
* Add libboost-dev and libboost-signals-dev to Build-Depends
* debian/rules: Don't install *.la files for new internal shared libs
* Fix Vcs URIs to point to correct desktop/experimental/ekiga tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Ekiga -- A VoIP and Video-Conferencing application
 
2
 * Copyright (C) 2000-2009 Damien Sandras <dsandras@seconix.com>
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 *
 
18
 *
 
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.
 
25
 */
 
26
 
 
27
 
 
28
/*
 
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
 
36
 *                          interface of ekiga.
 
37
 *
 
38
 */
 
39
 
 
40
#include "config.h"
 
41
 
 
42
#include <dbus/dbus-glib.h>
 
43
 
 
44
#include "dbus.h"
 
45
 
 
46
#include "ekiga.h"
 
47
#include "gmmarshallers.h"
 
48
#include "gmconf.h"
 
49
#include "callbacks.h"
 
50
#include "accounts.h"
 
51
 
 
52
#include "call-core.h"
 
53
 
 
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"
 
58
 
 
59
G_DEFINE_TYPE(EkigaDBusComponent, ekiga_dbus_component, G_TYPE_OBJECT);
 
60
 
 
61
struct _EkigaDBusComponentPrivate
 
62
{
 
63
  Ekiga::ServiceCore *core;
 
64
};
 
65
 
 
66
/**************************
 
67
 * GOBJECT / DBUS METHODS *
 
68
 **************************/
 
69
 
 
70
static gboolean ekiga_dbus_component_show (EkigaDBusComponent *self,
 
71
                                           GError **error);
 
72
static gboolean ekiga_dbus_component_shutdown (EkigaDBusComponent *self,
 
73
                                               GError **error);
 
74
static gboolean ekiga_dbus_component_call (EkigaDBusComponent *self,
 
75
                                           const gchar *uri,
 
76
                                           GError **error);
 
77
static gboolean ekiga_dbus_component_get_user_name (EkigaDBusComponent *self,
 
78
                                                    char **name,
 
79
                                                    GError **error);
 
80
static gboolean ekiga_dbus_component_get_user_location (EkigaDBusComponent *self,
 
81
                                                        char **location,
 
82
                                                        GError **error);
 
83
static gboolean ekiga_dbus_component_get_user_comment (EkigaDBusComponent *self,
 
84
                                                       char **comment,
 
85
                                                       GError **error);
 
86
 
 
87
/* get the code to make the GObject accessible through dbus
 
88
 * (this is especially where we get dbus_glib_dbus_component_object_info !)
 
89
 */
 
90
#include "dbus-stub.h"
 
91
 
 
92
static void
 
93
ekiga_dbus_component_init (EkigaDBusComponent *self)
 
94
{
 
95
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EKIGA_TYPE_DBUS_COMPONENT,
 
96
                                            EkigaDBusComponentPrivate);
 
97
}
 
98
 
 
99
static void
 
100
ekiga_dbus_component_class_init (EkigaDBusComponentClass *klass)
 
101
{
 
102
  g_type_class_add_private (klass, sizeof (EkigaDBusComponentPrivate));
 
103
 
 
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);
 
107
}
 
108
 
 
109
static gboolean
 
110
ekiga_dbus_component_show (G_GNUC_UNUSED EkigaDBusComponent *self,
 
111
                           G_GNUC_UNUSED GError **error)
 
112
{
 
113
  PTRACE (1, "DBus\tShow");
 
114
 
 
115
  GtkWidget *window = GnomeMeeting::Process ()->GetMainWindow ();
 
116
  if (GTK_WIDGET_VISIBLE (window))
 
117
    gtk_window_set_urgency_hint (GTK_WINDOW (window), TRUE);
 
118
  else
 
119
    gtk_window_present (GTK_WINDOW (window));
 
120
 
 
121
  return TRUE;
 
122
}
 
123
 
 
124
static gboolean
 
125
ekiga_dbus_component_shutdown (G_GNUC_UNUSED EkigaDBusComponent *self,
 
126
                               G_GNUC_UNUSED GError **error)
 
127
{
 
128
  quit_callback (NULL, NULL);
 
129
 
 
130
  return TRUE;
 
131
}
 
132
 
 
133
static gboolean
 
134
ekiga_dbus_component_call (EkigaDBusComponent *self,
 
135
                           const gchar *uri,
 
136
                           G_GNUC_UNUSED GError **error)
 
137
{
 
138
  boost::shared_ptr<Ekiga::CallCore> call_core = self->priv->core->get<Ekiga::CallCore> ("call-core");
 
139
  call_core->dial (uri);
 
140
 
 
141
  return TRUE;
 
142
}
 
143
 
 
144
static gboolean
 
145
ekiga_dbus_component_get_user_name (G_GNUC_UNUSED EkigaDBusComponent *self,
 
146
                                    char **name,
 
147
                                    G_GNUC_UNUSED GError **error)
 
148
{
 
149
  gchar * full_name;
 
150
  PTRACE (1, "DBus\tGetName");
 
151
 
 
152
  full_name = gm_conf_get_string (PERSONAL_DATA_KEY "full_name");
 
153
  if (full_name)
 
154
    *name = full_name;
 
155
 
 
156
  /* not freeing the full name is not a leak : dbus will do it for us ! */
 
157
 
 
158
  return TRUE;
 
159
}
 
160
 
 
161
static gboolean
 
162
ekiga_dbus_component_get_user_location (G_GNUC_UNUSED EkigaDBusComponent *self,
 
163
                                        char **location,
 
164
                                        G_GNUC_UNUSED GError **error)
 
165
{
 
166
  PTRACE (1, "DBus\tGetLocation");
 
167
 
 
168
  *location = gm_conf_get_string (PERSONAL_DATA_KEY "location");
 
169
 
 
170
  return TRUE;
 
171
}
 
172
 
 
173
static gboolean
 
174
ekiga_dbus_component_get_user_comment (G_GNUC_UNUSED EkigaDBusComponent *self,
 
175
                                       char **comment,
 
176
                                       G_GNUC_UNUSED GError **error)
 
177
{
 
178
  PTRACE (1, "DBus\tGetComment");
 
179
 
 
180
  *comment = gm_conf_get_string (PERSONAL_DATA_KEY "comment");
 
181
 
 
182
  return TRUE;
 
183
}
 
184
 
 
185
/**************
 
186
 * PUBLIC API *
 
187
 **************/
 
188
 
 
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.
 
192
 */
 
193
gboolean
 
194
ekiga_dbus_claim_ownership ()
 
195
{
 
196
  DBusGConnection *bus = NULL;
 
197
  DBusGProxy *bus_proxy = NULL;
 
198
  guint request_name_result;
 
199
  GError *error = NULL;
 
200
 
 
201
  bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
 
202
  if (!bus) {
 
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
 
206
  }
 
207
 
 
208
  bus_proxy = dbus_g_proxy_new_for_name (bus, "org.freedesktop.DBus",
 
209
                                         "/org/freedesktop/DBus",
 
210
                                         "org.freedesktop.DBus");
 
211
 
 
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,
 
215
                          G_TYPE_INVALID,
 
216
                          G_TYPE_UINT, &request_name_result,
 
217
                          G_TYPE_INVALID)) {
 
218
 
 
219
    PTRACE (1, "Couldn't get ownership on the " EKIGA_DBUS_NAMESPACE " D-Bus namespace : "
 
220
               << error->message);
 
221
    g_error_free (error);
 
222
    return FALSE;
 
223
  }
 
224
 
 
225
  PTRACE (4, "Ekiga registered on D-Bus: " EKIGA_DBUS_NAMESPACE);
 
226
 
 
227
  return request_name_result == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER;
 
228
}
 
229
 
 
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.
 
234
 */
 
235
EkigaDBusComponent *
 
236
ekiga_dbus_component_new (Ekiga::ServiceCore *core)
 
237
{
 
238
  DBusGConnection *bus;
 
239
  GError *error = NULL;
 
240
  EkigaDBusComponent *obj;
 
241
 
 
242
  bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
 
243
  if (!bus) {
 
244
    PTRACE (1, "Couldn't connect to session bus : " << error->message);
 
245
    g_error_free (error);
 
246
    return NULL;
 
247
  }
 
248
 
 
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));
 
252
 
 
253
  return obj;
 
254
}
 
255
 
 
256
static DBusGProxy *
 
257
get_ekiga_client_proxy ()
 
258
{
 
259
  DBusGConnection *bus = NULL;
 
260
  GError *error = NULL;
 
261
 
 
262
  bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
 
263
  if (!bus) {
 
264
    PTRACE (1, "Couldn't connect to session bus : " << error->message);
 
265
    g_error_free (error);
 
266
    return NULL;
 
267
  }
 
268
 
 
269
  return dbus_g_proxy_new_for_name (bus,
 
270
                                    EKIGA_DBUS_NAMESPACE,
 
271
                                    EKIGA_DBUS_PATH,
 
272
                                    EKIGA_DBUS_INTERFACE);
 
273
}
 
274
 
 
275
/** Tell to a remote instance of Ekiga to connect to a remote SIP or H.323 
 
276
 * address.
 
277
 * You will typically use this function when claim_ownership failed.
 
278
 */
 
279
void
 
280
ekiga_dbus_client_connect (const gchar *uri)
 
281
{
 
282
  DBusGProxy *proxy = get_ekiga_client_proxy ();
 
283
 
 
284
  g_return_if_fail (DBUS_IS_G_PROXY (proxy));
 
285
 
 
286
  dbus_g_proxy_call_no_reply (proxy, "Call", G_TYPE_STRING, uri, G_TYPE_INVALID);
 
287
  g_object_unref (proxy);
 
288
}
 
289
 
 
290
/** Tell to a remote instance of Ekiga to show the main window.
 
291
 * You will typically use this function when claim_ownership failed.
 
292
 */
 
293
void
 
294
ekiga_dbus_client_show ()
 
295
{
 
296
  DBusGProxy *proxy = get_ekiga_client_proxy ();
 
297
 
 
298
  g_return_if_fail (DBUS_IS_G_PROXY (proxy));
 
299
 
 
300
  dbus_g_proxy_call_no_reply (proxy, "Show", G_TYPE_INVALID);
 
301
  g_object_unref (proxy);
 
302
}