1
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
3
* Copyright (C) 2014 Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com>
3
* Copyright (C) 2014 Canonical Ltd.
5
5
* This program is free software; you can redistribute it and/or modify
6
6
* it under the terms of the GNU General Public License as published by
32
32
#include <linux/rfkill.h>
34
#include "urf-daemon.h"
34
35
#include "urf-device-ofono.h"
36
36
#include "urf-utils.h"
38
38
#define URF_DEVICE_OFONO_INTERFACE "org.freedesktop.URfkill.Device.Ofono"
40
#define OFONO_ERROR_IN_PROGRESS "GDBus.Error:org.ofono.Error.InProgress"
41
#define OFONO_ERROR_EMERGENCY "GDBus.Error:org.ofono.Error.EmergencyActive"
40
43
static const char introspection_xml[] =
41
44
" <interface name='org.freedesktop.URfkill.Device.Ofono'>"
42
45
" <signal name='Changed'/>"
56
59
struct _UrfDeviceOfonoPrivate {
61
64
GHashTable *properties;
65
68
GCancellable *cancellable;
69
GTask *pending_block_task;
68
72
G_DEFINE_TYPE_WITH_PRIVATE (UrfDeviceOfono, urf_device_ofono, URF_TYPE_DEVICE)
72
75
* urf_device_ofono_update_states:
90
* urf_device_ofono_get_modem_path:
87
urf_device_ofono_get_path (UrfDeviceOfono *ofono)
93
urf_device_ofono_get_modem_path (UrfDeviceOfono *ofono)
89
95
UrfDeviceOfonoPrivate *priv = URF_DEVICE_OFONO_GET_PRIVATE (ofono);
91
97
g_return_val_if_fail (URF_IS_DEVICE_OFONO (ofono), NULL);
93
return g_strdup(priv->object_path);
99
return g_strdup(priv->modem_path);
183
189
UrfDeviceOfonoPrivate *priv = URF_DEVICE_OFONO_GET_PRIVATE (modem);
184
190
GVariant *result;
185
191
GError *error = NULL;
187
194
result = g_dbus_proxy_call_finish (priv->proxy, res, &error);
190
197
g_debug ("online change successful: %s",
191
198
g_variant_print (result, TRUE));
200
if (priv->pending_block_task) {
201
g_task_return_pointer (priv->pending_block_task, NULL, NULL);
202
priv->pending_block_task = NULL;
193
205
g_warning ("Could not set Online property in oFono: %s",
194
206
error ? error->message : "(unknown error)");
208
if (error->message) {
209
if (g_strcmp0 (error->message, OFONO_ERROR_IN_PROGRESS) == 0) {
210
code = URF_DAEMON_ERROR_IN_PROGRESS;
211
} else if (g_strcmp0 (error->message, OFONO_ERROR_EMERGENCY) == 0) {
212
code = URF_DAEMON_ERROR_EMERGENCY;
216
if (priv->pending_block_task) {
217
g_task_return_new_error(priv->pending_block_task,
218
URF_DAEMON_ERROR, code,
219
"set_soft failed: %s",
220
urf_device_get_object_path (URF_DEVICE (modem)));
221
priv->pending_block_task = NULL;
202
set_soft (UrfDevice *device, gboolean blocked)
230
set_soft (UrfDevice *device, gboolean blocked, GTask *task)
204
232
UrfDeviceOfono *modem = URF_DEVICE_OFONO (device);
205
233
UrfDeviceOfonoPrivate *priv = URF_DEVICE_OFONO_GET_PRIVATE (modem);
207
priv->soft = blocked;
208
g_dbus_proxy_call (priv->proxy,
210
g_variant_new ("(sv)",
212
g_variant_new_boolean (!blocked)),
213
G_DBUS_CALL_FLAGS_NONE,
216
(GAsyncReadyCallback) set_online_cb,
219
/* always succeeds since it's an async call */
235
if (priv->proxy != NULL) {
236
g_message ("%s: Setting WWAN to %s",
238
blocked ? "blocked" : "unblocked");
240
priv->soft = blocked;
241
priv->pending_block_task = task;
243
g_dbus_proxy_call (priv->proxy,
245
g_variant_new ("(sv)",
247
g_variant_new_boolean (!blocked)),
248
G_DBUS_CALL_FLAGS_NONE,
251
(GAsyncReadyCallback) set_online_cb,
254
g_warning ("%s: proxy not ready yet", __func__);
251
286
GVariant *prop_value = NULL;
253
288
g_debug ("properties changed for %s: %s",
255
290
g_variant_print (parameters, TRUE));
257
292
g_variant_get_child (parameters, 0, "s", &prop_name);
272
307
powered = g_variant_get_boolean (prop_value);
275
set_soft (URF_DEVICE (modem), priv->soft);
310
g_message("%s: calling set_soft block: %u", __func__, priv->soft);
311
set_soft (URF_DEVICE (modem), priv->soft, NULL);
278
315
g_free (prop_name);
298
335
properties = g_variant_get_child_value (result, 0);
299
g_debug ("%zd properties for %s", g_variant_n_children (properties), priv->object_path);
336
g_debug ("%zd properties for %s", g_variant_n_children (properties),
300
338
g_debug ("%s", g_variant_print (properties, TRUE));
302
340
g_variant_iter_init (&iter, properties);
303
341
while (g_variant_iter_next (&iter, "{sv}", &key, &variant)) {
304
342
if (g_strcmp0 ("Powered", key) == 0 &&
305
343
g_variant_get_boolean (variant) == TRUE) {
306
set_soft (URF_DEVICE (modem), priv->soft);
344
set_soft (URF_DEVICE (modem), priv->soft, NULL);
309
347
g_hash_table_insert (priv->properties, g_strdup (key),
326
proxy_ready_cb (GObject *source_object,
330
UrfDeviceOfono *modem = URF_DEVICE_OFONO (user_data);
331
UrfDeviceOfonoPrivate *priv = URF_DEVICE_OFONO_GET_PRIVATE (modem);
332
GError *error = NULL;
334
priv->proxy = g_dbus_proxy_new_finish (res, &error);
337
g_cancellable_reset (priv->cancellable);
338
g_signal_connect (priv->proxy, "g-signal",
339
G_CALLBACK (modem_signal_cb), modem);
340
g_dbus_proxy_call (priv->proxy,
343
G_DBUS_CALL_FLAGS_NONE,
346
(GAsyncReadyCallback) get_properties_cb,
349
g_warning ("Could not get oFono Modem proxy: %s",
350
error ? error->message : "(unknown error)");
506
522
UrfDeviceOfono *device = g_object_new (URF_TYPE_DEVICE_OFONO, NULL);
507
523
UrfDeviceOfonoPrivate *priv = URF_DEVICE_OFONO_GET_PRIVATE (device);
524
GError *error = NULL;
509
526
priv->index = index;
510
priv->object_path = g_strdup (object_path);
512
g_debug ("new ofono device: %p for %s", device, priv->object_path);
514
if (!urf_device_register_device (URF_DEVICE (device), interface_vtable, introspection_xml)) {
528
g_debug ("new ofono device: %p for %s", device, object_path);
530
if (!urf_device_register_device (URF_DEVICE (device), interface_vtable, introspection_xml)) {
515
531
g_object_unref (device);
519
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
520
G_DBUS_PROXY_FLAGS_NONE,
535
priv->modem_path = g_strdup (object_path);
537
priv->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
538
G_DBUS_PROXY_FLAGS_NONE,
546
g_cancellable_reset (priv->cancellable);
547
g_signal_connect (priv->proxy, "g-signal",
548
G_CALLBACK (modem_signal_cb), device);
549
g_dbus_proxy_call (priv->proxy,
552
G_DBUS_CALL_FLAGS_NONE,
555
(GAsyncReadyCallback) get_properties_cb,
558
g_warning ("Could not get oFono Modem proxy: %s",
559
error ? error->message : "(unknown error)");
529
562
return URF_DEVICE (device);