~phablet-team/urfkill/monitor-script

« back to all changes in this revision

Viewing changes to src/urf-device-ofono.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2014-10-07 23:53:07 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20141007235307-5tuskrywdzi7cq8l
Tags: 0.6.0~20141007.235123.f908aff.1-0ubuntu1
* New release snapshot:
  - Asynchronous support for rfkill operations. (LP: #1321627, #1339794)
  - Improvements to state persistence. (LP: #1354716)
  - Support for devices driven by libhybris rather than rfkill.
* debian/patches/ignore_input_monitor_startup.patch: dropped, included
  upstream.
* debian/control:
  - bump Build-Depends on libglib2.0-dev to >= 2.36 for GTask.
  - add a Build-Depends on libhybris-dev for hybris-driven devices support.
  - bump Standards-Version to 3.9.5.
* debian/scripts/enumerate: handle the new hybris device type.
* debian/rules: remove SysV init startup links.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2
2
 *
3
 
 * Copyright (C) 2014 Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com>
 
3
 * Copyright (C) 2014 Canonical Ltd.
4
4
 *
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
31
31
 
32
32
#include <linux/rfkill.h>
33
33
 
 
34
#include "urf-daemon.h"
34
35
#include "urf-device-ofono.h"
35
 
 
36
36
#include "urf-utils.h"
37
37
 
38
38
#define URF_DEVICE_OFONO_INTERFACE "org.freedesktop.URfkill.Device.Ofono"
39
39
 
 
40
#define OFONO_ERROR_IN_PROGRESS "GDBus.Error:org.ofono.Error.InProgress"
 
41
#define OFONO_ERROR_EMERGENCY   "GDBus.Error:org.ofono.Error.EmergencyActive"
 
42
 
40
43
static const char introspection_xml[] =
41
44
"  <interface name='org.freedesktop.URfkill.Device.Ofono'>"
42
45
"    <signal name='Changed'/>"
55
58
 
56
59
struct _UrfDeviceOfonoPrivate {
57
60
        gint index;
58
 
        char *object_path;
59
61
        char *name;
 
62
        char *modem_path;
60
63
 
61
64
        GHashTable *properties;
62
65
        gboolean soft;
63
66
 
64
67
        GDBusProxy *proxy;
65
68
        GCancellable *cancellable;
 
69
        GTask *pending_block_task;
66
70
};
67
71
 
68
72
G_DEFINE_TYPE_WITH_PRIVATE (UrfDeviceOfono, urf_device_ofono, URF_TYPE_DEVICE)
69
73
 
70
 
 
71
74
/**
72
75
 * urf_device_ofono_update_states:
73
76
 *
83
86
        return TRUE;
84
87
}
85
88
 
 
89
/**
 
90
 * urf_device_ofono_get_modem_path:
 
91
 **/
86
92
gchar *
87
 
urf_device_ofono_get_path (UrfDeviceOfono *ofono)
 
93
urf_device_ofono_get_modem_path (UrfDeviceOfono *ofono)
88
94
{
89
95
        UrfDeviceOfonoPrivate *priv = URF_DEVICE_OFONO_GET_PRIVATE (ofono);
90
96
 
91
97
        g_return_val_if_fail (URF_IS_DEVICE_OFONO (ofono), NULL);
92
98
 
93
 
        return g_strdup(priv->object_path);
 
99
        return g_strdup(priv->modem_path);
94
100
}
95
101
 
96
102
/**
183
189
        UrfDeviceOfonoPrivate *priv = URF_DEVICE_OFONO_GET_PRIVATE (modem);
184
190
        GVariant *result;
185
191
        GError *error = NULL;
 
192
        gint code = 0;
186
193
 
187
194
        result = g_dbus_proxy_call_finish (priv->proxy, res, &error);
188
195
 
189
 
        if (!error) {
 
196
        if (error == NULL) {
190
197
                g_debug ("online change successful: %s",
191
198
                         g_variant_print (result, TRUE));
 
199
 
 
200
                if (priv->pending_block_task) {
 
201
                        g_task_return_pointer (priv->pending_block_task, NULL, NULL);
 
202
                        priv->pending_block_task = NULL;
 
203
                }
192
204
        } else {
193
205
                g_warning ("Could not set Online property in oFono: %s",
194
206
                           error ? error->message : "(unknown error)");
 
207
 
 
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;
 
213
                        }
 
214
                }
 
215
 
 
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;
 
222
                }
195
223
        }
196
224
}
197
225
 
198
226
/**
199
227
 * set_soft:
200
228
 **/
201
 
static gboolean
202
 
set_soft (UrfDevice *device, gboolean blocked)
 
229
static void
 
230
set_soft (UrfDevice *device, gboolean blocked, GTask *task)
203
231
{
204
232
        UrfDeviceOfono *modem = URF_DEVICE_OFONO (device);
205
233
        UrfDeviceOfonoPrivate *priv = URF_DEVICE_OFONO_GET_PRIVATE (modem);
206
234
 
207
 
        priv->soft = blocked;
208
 
        g_dbus_proxy_call (priv->proxy,
209
 
                           "SetProperty",
210
 
                           g_variant_new ("(sv)",
211
 
                                          "Online",
212
 
                                          g_variant_new_boolean (!blocked)),
213
 
                           G_DBUS_CALL_FLAGS_NONE,
214
 
                           -1,
215
 
                           priv->cancellable,
216
 
                           (GAsyncReadyCallback) set_online_cb,
217
 
                           modem);
218
 
 
219
 
        /* always succeeds since it's an async call */
220
 
        return TRUE;
 
235
        if (priv->proxy != NULL) {
 
236
                g_message ("%s: Setting WWAN to %s",
 
237
                           __func__,
 
238
                           blocked ? "blocked" : "unblocked");
 
239
 
 
240
                priv->soft = blocked;
 
241
                priv->pending_block_task = task;
 
242
 
 
243
                g_dbus_proxy_call (priv->proxy,
 
244
                                   "SetProperty",
 
245
                                   g_variant_new ("(sv)",
 
246
                                                  "Online",
 
247
                                                  g_variant_new_boolean (!blocked)),
 
248
                                   G_DBUS_CALL_FLAGS_NONE,
 
249
                                   -1,
 
250
                                   priv->cancellable,
 
251
                                   (GAsyncReadyCallback) set_online_cb,
 
252
                                   modem);
 
253
        } else {
 
254
                g_warning ("%s: proxy not ready yet", __func__);
 
255
        }
221
256
}
222
257
 
223
258
/**
251
286
                GVariant *prop_value = NULL;
252
287
 
253
288
                g_debug ("properties changed for %s: %s",
254
 
                         priv->object_path,
 
289
                         priv->modem_path,
255
290
                         g_variant_print (parameters, TRUE));
256
291
 
257
292
                g_variant_get_child (parameters, 0, "s", &prop_name);
271
306
 
272
307
                        powered = g_variant_get_boolean (prop_value);
273
308
 
274
 
                        if (powered)
275
 
                                set_soft (URF_DEVICE (modem), priv->soft);
 
309
                        if (powered) {
 
310
                                g_message("%s: calling set_soft block: %u", __func__, priv->soft);
 
311
                                set_soft (URF_DEVICE (modem), priv->soft, NULL);
 
312
                        }
276
313
                }
277
314
 
278
315
                g_free (prop_name);
296
333
 
297
334
        if (!error) {
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),
 
337
                         priv->modem_path);
300
338
                g_debug ("%s", g_variant_print (properties, TRUE));
301
339
 
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);
307
345
                        }
308
346
 
309
347
                        g_hash_table_insert (priv->properties, g_strdup (key),
322
360
        }
323
361
}
324
362
 
325
 
static void
326
 
proxy_ready_cb (GObject *source_object,
327
 
                GAsyncResult *res,
328
 
                gpointer user_data)
329
 
{
330
 
        UrfDeviceOfono *modem = URF_DEVICE_OFONO (user_data);
331
 
        UrfDeviceOfonoPrivate *priv = URF_DEVICE_OFONO_GET_PRIVATE (modem);
332
 
        GError *error = NULL;
333
 
 
334
 
        priv->proxy = g_dbus_proxy_new_finish (res, &error);
335
 
 
336
 
        if (!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,
341
 
                                   "GetProperties",
342
 
                                   NULL,
343
 
                                   G_DBUS_CALL_FLAGS_NONE,
344
 
                                   -1,
345
 
                                   priv->cancellable,
346
 
                                   (GAsyncReadyCallback) get_properties_cb,
347
 
                                   modem);
348
 
        } else {
349
 
                g_warning ("Could not get oFono Modem proxy: %s",
350
 
                           error ? error->message : "(unknown error)");
351
 
        }
352
 
}
353
 
 
354
363
/**
355
364
 * get_property:
356
365
 **/
408
417
static void
409
418
dispose (GObject *object)
410
419
{
 
420
        UrfDeviceOfonoPrivate *priv = URF_DEVICE_OFONO_GET_PRIVATE (object);
 
421
 
 
422
        if (priv->modem_path) {
 
423
                g_free (priv->modem_path);
 
424
                priv->modem_path = NULL;
 
425
        }
 
426
 
411
427
        G_OBJECT_CLASS(urf_device_ofono_parent_class)->dispose(object);
412
428
}
413
429
 
505
521
{
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;
508
525
 
509
526
        priv->index = index;
510
 
        priv->object_path = g_strdup (object_path);
511
 
 
512
 
        g_debug ("new ofono device: %p for %s", device, priv->object_path);
513
 
 
514
 
        if (!urf_device_register_device (URF_DEVICE (device), interface_vtable, introspection_xml)) {
 
527
 
 
528
        g_debug ("new ofono device: %p for %s", device, object_path);
 
529
 
 
530
        if (!urf_device_register_device (URF_DEVICE (device), interface_vtable, introspection_xml)) {
515
531
                g_object_unref (device);
516
532
                return NULL;
517
533
        }
518
534
 
519
 
        g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
520
 
                                  G_DBUS_PROXY_FLAGS_NONE,
521
 
                                  NULL,
522
 
                                  "org.ofono",
523
 
                                  priv->object_path,
524
 
                                  "org.ofono.Modem",
525
 
                                  priv->cancellable,
526
 
                                  proxy_ready_cb,
527
 
                                  device);
 
535
        priv->modem_path = g_strdup (object_path);
 
536
 
 
537
        priv->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
 
538
                                                     G_DBUS_PROXY_FLAGS_NONE,
 
539
                                                     NULL,
 
540
                                                     "org.ofono",
 
541
                                                     object_path,
 
542
                                                     "org.ofono.Modem",
 
543
                                                     priv->cancellable,
 
544
                                                     &error);
 
545
        if (error == NULL) {
 
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,
 
550
                                   "GetProperties",
 
551
                                   NULL,
 
552
                                   G_DBUS_CALL_FLAGS_NONE,
 
553
                                   -1,
 
554
                                   priv->cancellable,
 
555
                                   (GAsyncReadyCallback) get_properties_cb,
 
556
                                   device);
 
557
        } else {
 
558
                g_warning ("Could not get oFono Modem proxy: %s",
 
559
                           error ? error->message : "(unknown error)");
 
560
        }
528
561
 
529
562
        return URF_DEVICE (device);
530
563
}