~binli/ubuntu/vivid/modemmanager/lp1441095

« back to all changes in this revision

Viewing changes to libmm-glib/mm-modem-simple.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre, Mathieu Trudel-Lapierre, Michael Biebl, Marius B. Kotsbak
  • Date: 2013-06-11 10:35:42 UTC
  • mfrom: (1.2.1) (16.1.20 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20130611103542-xm7vvifc252viorj
Tags: 0.7.991-1
[ Mathieu Trudel-Lapierre ]
* New upstream release.
* debian/patches/handle_data07_capabilities_probing.patch,
  debian/patches/git_skip_add_utf8_check_219424a.patch,
  debian/patches/git_lte_etsi_mode_0af47c7.patch,
  debian/patches/git_lte_4g_parsing_90489ae.patch,
  debian/patches/git_lp1015328_segfault_in_clck_parser_318aaa0.patch,
  debian/patches/git_better_handle_ucs2_convert_e07c216.patch: Dropped,
  these patches were cherry-picks; included upstream
* debian/patches/ericsson_h5321gw_usbids.patch: dropped, included upstream.
* debian/control:
  - clean up build-depends: remove xsltproc, bump
    libglib2.0-dev to (>= 2.30.2), libgudev-1.0-dev to (>= 147).
  - Add gtk-doc-tools to Build-Depends.
  - Add libqmi-glib-dev to Build-Depends.
  - Add gnome-common to Build-Depends.
  - Bump debhelper Build-Depends to >= 9.
  - Make sure libmm-glib0 pre-depends on multiarch-support (lintian).
  - Make libmm-glib0 Multi-Arch: same.
  - Make sure all binary packages (except modemmanager-dbg) are priority
    optional.
  - Update short descriptions.
  - Breaks network-manager (<< 0.9.8.2-1) since otherwise NetworkManager
    will not see ModemManager with its new API.
* debian/compat: bump to compat level 9.
* debian/rules:
  - Replace --with-docs with --enable-gtk-doc.
  - Fix autoreconf to run gnome-autogen.sh.
  - Drop the override for installdocs; docs/spec.html isn't being built
    anymore.
  - Run dh_install with --fail-missing.
  - Remove test pppd plugin which we shouldn't install.
  - Drop old cruft for getting git snapshots.
  - We don't need to exclude the pppd path from makeshlibs, since nothing
    gets installed there.
* debian/patches/lp700316_usb_blacklist.patch: refreshed.
* debian/patches/arduino-blacklist.patch: refreshed.
* debian/patches/linux-default-usb-id.patch: refreshed.
* debian/*.install: make sure the files are properly installed given the new
  packages, also take into account multiarch paths.
* debian/modemmanager.install: install the new mmcli binary.
* debian/ubuntu/modemmanager.upstart: fix the name for the ModemManager
  binary, since it was changed upstream.
* debian/patches/dbus_remove_max_replies_per_connection_limit.patch: dropped,
  included upstream.

[ Michael Biebl ]
* Add symbols file for libmm-glib0.

[ Marius B. Kotsbak ]
* Added binary packages modemmanager-doc and libmm-glib-doc for gtk-docs.
* Split out modemmanager-dev package containing header files and .pc file.
  - add dependency on modemmanager-dev from libmm-glib-dev
    as stated in "mm-glib.pc"
  - add proper replaces/breaks for modemmanager-dev because of moved files
* Build-depends: added "libglib2.0-doc" for the cross references in the doc
  to work.
* debian/rules: make dh_makeshlibs override multiarch aware.
* Update standards version to current 3.9.4.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 
2
/*
 
3
 * libmm -- Access modem status & information from glib applications
 
4
 *
 
5
 * This library is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU Lesser General Public
 
7
 * License as published by the Free Software Foundation; either
 
8
 * version 2 of the License, or (at your option) any later version.
 
9
 *
 
10
 * This library is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * Lesser General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU Lesser General Public
 
16
 * License along with this library; if not, write to the
 
17
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
 * Boston, MA 02110-1301 USA.
 
19
 *
 
20
 * Copyright (C) 2011 - 2012 Aleksander Morgado <aleksander@gnu.org>
 
21
 * Copyright (C) 2012 Google, Inc.
 
22
 */
 
23
 
 
24
#include <gio/gio.h>
 
25
 
 
26
#include "mm-helpers.h"
 
27
#include "mm-errors-types.h"
 
28
#include "mm-modem-simple.h"
 
29
 
 
30
/**
 
31
 * SECTION: mm-modem-simple
 
32
 * @title: MMModemSimple
 
33
 * @short_description: The Simple interface
 
34
 *
 
35
 * The #MMModemSimple is an object providing access to the methods, signals and
 
36
 * properties of the Simple interface.
 
37
 *
 
38
 * The Simple interface is exposed on modems which are not in %MM_MODEM_STATE_FAILED state.
 
39
 */
 
40
 
 
41
G_DEFINE_TYPE (MMModemSimple, mm_modem_simple, MM_GDBUS_TYPE_MODEM_SIMPLE_PROXY)
 
42
 
 
43
/*****************************************************************************/
 
44
 
 
45
/**
 
46
 * mm_modem_simple_get_path:
 
47
 * @self: A #MMModemSimple.
 
48
 *
 
49
 * Gets the DBus path of the #MMObject which implements this interface.
 
50
 *
 
51
 * Returns: (transfer none): The DBus path of the #MMObject object.
 
52
 */
 
53
const gchar *
 
54
mm_modem_simple_get_path (MMModemSimple *self)
 
55
{
 
56
    g_return_val_if_fail (MM_IS_MODEM_SIMPLE (self), NULL);
 
57
 
 
58
    RETURN_NON_EMPTY_CONSTANT_STRING (
 
59
        g_dbus_proxy_get_object_path (G_DBUS_PROXY (self)));
 
60
}
 
61
 
 
62
/**
 
63
 * mm_modem_simple_dup_path:
 
64
 * @self: A #MMModemSimple.
 
65
 *
 
66
 * Gets a copy of the DBus path of the #MMObject object which implements this interface.
 
67
 *
 
68
 * Returns: (transfer full): The DBus path of the #MMObject. The returned value should be freed with g_free().
 
69
 */
 
70
gchar *
 
71
mm_modem_simple_dup_path (MMModemSimple *self)
 
72
{
 
73
    gchar *value;
 
74
 
 
75
    g_return_val_if_fail (MM_IS_MODEM_SIMPLE (self), NULL);
 
76
 
 
77
    g_object_get (G_OBJECT (self),
 
78
                  "g-object-path", &value,
 
79
                  NULL);
 
80
    RETURN_NON_EMPTY_STRING (value);
 
81
}
 
82
 
 
83
/*****************************************************************************/
 
84
 
 
85
typedef struct {
 
86
    GSimpleAsyncResult *result;
 
87
    GCancellable *cancellable;
 
88
} ConnectContext;
 
89
 
 
90
static void
 
91
connect_context_complete_and_free (ConnectContext *ctx)
 
92
{
 
93
    g_simple_async_result_complete (ctx->result);
 
94
    g_object_unref (ctx->result);
 
95
    if (ctx->cancellable)
 
96
        g_object_unref (ctx->cancellable);
 
97
    g_slice_free (ConnectContext, ctx);
 
98
}
 
99
 
 
100
/**
 
101
 * mm_modem_simple_connect_finish:
 
102
 * @self: A #MMModemSimple.
 
103
 * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to mm_modem_simple_connect().
 
104
 * @error: Return location for error or %NULL.
 
105
 *
 
106
 * Finishes an operation started with mm_modem_simple_connect().
 
107
 *
 
108
 * Returns: (transfer full): A #MMBearer, or %FALSE if @error is set. The returned value must be freed with g_object_ref().
 
109
 */
 
110
MMBearer *
 
111
mm_modem_simple_connect_finish (MMModemSimple *self,
 
112
                                GAsyncResult *res,
 
113
                                GError **error)
 
114
{
 
115
    g_return_val_if_fail (MM_IS_MODEM_SIMPLE (self), NULL);
 
116
 
 
117
    if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
 
118
        return NULL;
 
119
 
 
120
    return g_object_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));
 
121
}
 
122
 
 
123
static void
 
124
new_bearer_ready (GDBusConnection *connection,
 
125
                  GAsyncResult *res,
 
126
                  ConnectContext *ctx)
 
127
{
 
128
    GError *error = NULL;
 
129
    GObject *bearer;
 
130
    GObject *source_object;
 
131
 
 
132
    source_object = g_async_result_get_source_object (res);
 
133
    bearer = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, &error);
 
134
    g_object_unref (source_object);
 
135
 
 
136
    if (error)
 
137
        g_simple_async_result_take_error (ctx->result, error);
 
138
    else
 
139
        g_simple_async_result_set_op_res_gpointer (ctx->result,
 
140
                                                   bearer,
 
141
                                                   (GDestroyNotify)g_object_unref);
 
142
 
 
143
    connect_context_complete_and_free (ctx);
 
144
}
 
145
 
 
146
static void
 
147
simple_connect_ready (MMModemSimple *self,
 
148
                      GAsyncResult *res,
 
149
                      ConnectContext *ctx)
 
150
{
 
151
    GError *error = NULL;
 
152
    gchar *bearer_path = NULL;
 
153
 
 
154
    if (!mm_gdbus_modem_simple_call_connect_finish (MM_GDBUS_MODEM_SIMPLE (self),
 
155
                                                    &bearer_path,
 
156
                                                    res,
 
157
                                                    &error)) {
 
158
        g_simple_async_result_take_error (ctx->result, error);
 
159
        connect_context_complete_and_free (ctx);
 
160
        return;
 
161
    }
 
162
 
 
163
    g_async_initable_new_async (MM_TYPE_BEARER,
 
164
                                G_PRIORITY_DEFAULT,
 
165
                                ctx->cancellable,
 
166
                                (GAsyncReadyCallback)new_bearer_ready,
 
167
                                ctx,
 
168
                                "g-flags",          G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
 
169
                                "g-name",           MM_DBUS_SERVICE,
 
170
                                "g-connection",     g_dbus_proxy_get_connection (G_DBUS_PROXY (self)),
 
171
                                "g-object-path",    bearer_path,
 
172
                                "g-interface-name", "org.freedesktop.ModemManager1.Bearer",
 
173
                                NULL);
 
174
}
 
175
 
 
176
/**
 
177
 * mm_modem_simple_connect:
 
178
 * @self: A #MMModemSimple.
 
179
 * @properties: (transfer none): A #MMSimpleConnectProperties bundle.
 
180
 * @cancellable: (allow-none): A #GCancellable or %NULL.
 
181
 * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL.
 
182
 * @user_data: User data to pass to @callback.
 
183
 *
 
184
 * Asynchronously requests to connect the modem using the given @properties.
 
185
 *
 
186
 * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from.
 
187
 * You can then call mm_modem_simple_connect_finish() to get the result of the operation.
 
188
 *
 
189
 * See mm_modem_simple_connect_sync() for the synchronous, blocking version of this method.
 
190
 */
 
191
void
 
192
mm_modem_simple_connect (MMModemSimple *self,
 
193
                         MMSimpleConnectProperties *properties,
 
194
                         GCancellable *cancellable,
 
195
                         GAsyncReadyCallback callback,
 
196
                         gpointer user_data)
 
197
{
 
198
    ConnectContext *ctx;
 
199
    GVariant *variant;
 
200
 
 
201
    g_return_if_fail (MM_IS_MODEM_SIMPLE (self));
 
202
 
 
203
    ctx = g_slice_new0 (ConnectContext);
 
204
    ctx->result = g_simple_async_result_new (G_OBJECT (self),
 
205
                                             callback,
 
206
                                             user_data,
 
207
                                             mm_modem_simple_connect);
 
208
    if (cancellable)
 
209
        ctx->cancellable = g_object_ref (cancellable);
 
210
 
 
211
    variant = mm_simple_connect_properties_get_dictionary (properties);
 
212
    mm_gdbus_modem_simple_call_connect (
 
213
        MM_GDBUS_MODEM_SIMPLE (self),
 
214
        variant,
 
215
        cancellable,
 
216
        (GAsyncReadyCallback)simple_connect_ready,
 
217
        ctx);
 
218
 
 
219
    g_variant_unref (variant);
 
220
}
 
221
 
 
222
/**
 
223
 * mm_modem_simple_connect_sync:
 
224
 * @self: A #MMModemSimple.
 
225
 * @properties: (transfer none): A #MMSimpleConnectProperties bundle.
 
226
 * @cancellable: (allow-none): A #GCancellable or %NULL.
 
227
 * @error: Return location for error or %NULL.
 
228
 *
 
229
 * Synchronously requests to connect the modem using the given @properties.
 
230
 *
 
231
 * The calling thread is blocked until a reply is received. See mm_modem_simple_connect()
 
232
 * for the asynchronous version of this method.
 
233
 *
 
234
 * Returns: (transfer full): A #MMBearer, or %FALSE if @error is set. The returned value must be freed with g_object_ref().
 
235
 */
 
236
MMBearer *
 
237
mm_modem_simple_connect_sync (MMModemSimple *self,
 
238
                              MMSimpleConnectProperties *properties,
 
239
                              GCancellable *cancellable,
 
240
                              GError **error)
 
241
{
 
242
    GObject *bearer = NULL;
 
243
    gchar *bearer_path = NULL;
 
244
    GVariant *variant;
 
245
 
 
246
    g_return_val_if_fail (MM_IS_MODEM_SIMPLE (self), NULL);
 
247
 
 
248
    variant = mm_simple_connect_properties_get_dictionary (properties);
 
249
    mm_gdbus_modem_simple_call_connect_sync (MM_GDBUS_MODEM_SIMPLE (self),
 
250
                                             variant,
 
251
                                             &bearer_path,
 
252
                                             cancellable,
 
253
                                             error);
 
254
    if (bearer_path) {
 
255
        bearer = g_initable_new (MM_TYPE_BEARER,
 
256
                                 cancellable,
 
257
                                 error,
 
258
                                 "g-flags",          G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
 
259
                                 "g-name",           MM_DBUS_SERVICE,
 
260
                                 "g-connection",     g_dbus_proxy_get_connection (G_DBUS_PROXY (self)),
 
261
                                 "g-object-path",    bearer_path,
 
262
                                 "g-interface-name", "org.freedesktop.ModemManager1.Bearer",
 
263
                                 NULL);
 
264
        g_free (bearer_path);
 
265
    }
 
266
 
 
267
    g_variant_unref (variant);
 
268
 
 
269
    return (bearer ? MM_BEARER (bearer) : NULL);
 
270
}
 
271
 
 
272
/*****************************************************************************/
 
273
 
 
274
/**
 
275
 * mm_modem_simple_disconnect_finish:
 
276
 * @self: A #MMModemSimple.
 
277
 * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to mm_modem_simple_disconnect().
 
278
 * @error: Return location for error or %NULL.
 
279
 *
 
280
 * Finishes an operation started with mm_modem_simple_disconnect().
 
281
 *
 
282
 * Returns: %TRUE if the modem is successfully disconnected, %FALSE if @error is set.
 
283
 */
 
284
gboolean
 
285
mm_modem_simple_disconnect_finish (MMModemSimple *self,
 
286
                                   GAsyncResult *res,
 
287
                                   GError **error)
 
288
{
 
289
    g_return_val_if_fail (MM_IS_MODEM_SIMPLE (self), FALSE);
 
290
 
 
291
    return mm_gdbus_modem_simple_call_disconnect_finish (MM_GDBUS_MODEM_SIMPLE (self), res, error);
 
292
}
 
293
 
 
294
/**
 
295
 * mm_modem_simple_disconnect:
 
296
 * @self: A #MMModemSimple.
 
297
 * @bearer: Path of the bearer to disconnect, or %NULL to disconnect all connected bearers.
 
298
 * @cancellable: (allow-none): A #GCancellable or %NULL.
 
299
 * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL.
 
300
 * @user_data: User data to pass to @callback.
 
301
 *
 
302
 * Asynchronously requests to disconnect the modem.
 
303
 *
 
304
 * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from.
 
305
 * You can then call mm_modem_simple_disconnect_finish() to get the result of the operation.
 
306
 *
 
307
 * See mm_modem_simple_disconnect_sync() for the synchronous, blocking version of this method.
 
308
 */
 
309
void
 
310
mm_modem_simple_disconnect (MMModemSimple *self,
 
311
                            const gchar *bearer,
 
312
                            GCancellable *cancellable,
 
313
                            GAsyncReadyCallback callback,
 
314
                            gpointer user_data)
 
315
{
 
316
    g_return_if_fail (MM_IS_MODEM_SIMPLE (self));
 
317
 
 
318
    mm_gdbus_modem_simple_call_disconnect (MM_GDBUS_MODEM_SIMPLE (self),
 
319
                                           bearer ? bearer : "/",
 
320
                                           cancellable,
 
321
                                           callback,
 
322
                                           user_data);
 
323
}
 
324
 
 
325
/**
 
326
 * mm_modem_simple_disconnect_sync:
 
327
 * @self: A #MMModemSimple.
 
328
 * @bearer: Path of the bearer to disconnect, or %NULL to disconnect all connected bearers.
 
329
 * @cancellable: (allow-none): A #GCancellable or %NULL.
 
330
 * @error: Return location for error or %NULL.
 
331
 *
 
332
 * Synchronously requests to disconnect the modem.
 
333
 *
 
334
 * The calling thread is blocked until a reply is received. See mm_modem_simple_disconnect()
 
335
 * for the asynchronous version of this method.
 
336
 *
 
337
 * Returns: %TRUE if the modem is successfully disconnected, %FALSE if @error is set.
 
338
 */
 
339
gboolean
 
340
mm_modem_simple_disconnect_sync (MMModemSimple *self,
 
341
                                 const gchar *bearer,
 
342
                                 GCancellable *cancellable,
 
343
                                 GError **error)
 
344
{
 
345
    g_return_val_if_fail (MM_IS_MODEM_SIMPLE (self), FALSE);
 
346
 
 
347
    return mm_gdbus_modem_simple_call_disconnect_sync (MM_GDBUS_MODEM_SIMPLE (self),
 
348
                                                       bearer ? bearer : "/",
 
349
                                                       cancellable,
 
350
                                                       error);
 
351
}
 
352
 
 
353
/*****************************************************************************/
 
354
 
 
355
/**
 
356
 * mm_modem_simple_get_status_finish:
 
357
 * @self: A #MMModemSimple.
 
358
 * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to mm_modem_simple_connect().
 
359
 * @error: Return location for error or %NULL.
 
360
 *
 
361
 * Finishes an operation started with mm_modem_simple_get_status().
 
362
 *
 
363
 * Returns: (transfer full): A #MMSimpleStatus, or %FALSE if @error is set. The returned value must be freed with g_object_ref().
 
364
 */
 
365
MMSimpleStatus *
 
366
mm_modem_simple_get_status_finish (MMModemSimple *self,
 
367
                                   GAsyncResult *res,
 
368
                                   GError **error)
 
369
{
 
370
    MMSimpleStatus *status;
 
371
    GVariant *dictionary = NULL;
 
372
 
 
373
    g_return_val_if_fail (MM_IS_MODEM_SIMPLE (self), NULL);
 
374
 
 
375
    if (!mm_gdbus_modem_simple_call_get_status_finish (MM_GDBUS_MODEM_SIMPLE (self), &dictionary, res, error))
 
376
        return NULL;
 
377
 
 
378
    status = mm_simple_status_new_from_dictionary (dictionary, error);
 
379
    g_variant_unref (dictionary);
 
380
    return status;
 
381
}
 
382
 
 
383
/**
 
384
 * mm_modem_simple_get_status:
 
385
 * @self: A #MMModemSimple.
 
386
 * @cancellable: (allow-none): A #GCancellable or %NULL.
 
387
 * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL.
 
388
 * @user_data: User data to pass to @callback.
 
389
 *
 
390
 * Asynchronously requests a compilation of the status of the modem.
 
391
 *
 
392
 * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from.
 
393
 * You can then call mm_modem_simple_get_status_finish() to get the result of the operation.
 
394
 *
 
395
 * See mm_modem_simple_get_status_sync() for the synchronous, blocking version of this method.
 
396
 */
 
397
void
 
398
mm_modem_simple_get_status (MMModemSimple *self,
 
399
                            GCancellable *cancellable,
 
400
                            GAsyncReadyCallback callback,
 
401
                            gpointer user_data)
 
402
{
 
403
    g_return_if_fail (MM_IS_MODEM_SIMPLE (self));
 
404
 
 
405
    mm_gdbus_modem_simple_call_get_status (MM_GDBUS_MODEM_SIMPLE (self),
 
406
                                           cancellable,
 
407
                                           callback,
 
408
                                           user_data);
 
409
}
 
410
 
 
411
/**
 
412
 * mm_modem_simple_get_status_sync:
 
413
 * @self: A #MMModemSimple.
 
414
 * @cancellable: (allow-none): A #GCancellable or %NULL.
 
415
 * @error: Return location for error or %NULL.
 
416
 *
 
417
 * Synchronously requests a compilation of the status of the modem.
 
418
 *
 
419
 * The calling thread is blocked until a reply is received. See mm_modem_simple_get_status()
 
420
 * for the asynchronous version of this method.
 
421
 *
 
422
 * Returns: (transfer full): A #MMSimpleStatus, or %FALSE if @error is set. The returned value must be freed with g_object_ref().
 
423
 */
 
424
MMSimpleStatus *
 
425
mm_modem_simple_get_status_sync (MMModemSimple *self,
 
426
                                 GCancellable *cancellable,
 
427
                                 GError **error)
 
428
{
 
429
    MMSimpleStatus *status;
 
430
    GVariant *dictionary = NULL;
 
431
 
 
432
    g_return_val_if_fail (MM_IS_MODEM_SIMPLE (self), NULL);
 
433
 
 
434
    if (!mm_gdbus_modem_simple_call_get_status_sync (MM_GDBUS_MODEM_SIMPLE (self), &dictionary, cancellable, error))
 
435
        return NULL;
 
436
 
 
437
    status = mm_simple_status_new_from_dictionary (dictionary, error);
 
438
    g_variant_unref (dictionary);
 
439
    return status;
 
440
}
 
441
 
 
442
/*****************************************************************************/
 
443
 
 
444
static void
 
445
mm_modem_simple_init (MMModemSimple *self)
 
446
{
 
447
}
 
448
 
 
449
static void
 
450
mm_modem_simple_class_init (MMModemSimpleClass *modem_class)
 
451
{
 
452
}