1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3
* libmm -- Access modem status & information from glib applications
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.
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.
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.
20
* Copyright (C) 2011 - 2012 Aleksander Morgado <aleksander@gnu.org>
21
* Copyright (C) 2012 Google, Inc.
26
#include "mm-helpers.h"
27
#include "mm-errors-types.h"
28
#include "mm-modem-simple.h"
31
* SECTION: mm-modem-simple
32
* @title: MMModemSimple
33
* @short_description: The Simple interface
35
* The #MMModemSimple is an object providing access to the methods, signals and
36
* properties of the Simple interface.
38
* The Simple interface is exposed on modems which are not in %MM_MODEM_STATE_FAILED state.
41
G_DEFINE_TYPE (MMModemSimple, mm_modem_simple, MM_GDBUS_TYPE_MODEM_SIMPLE_PROXY)
43
/*****************************************************************************/
46
* mm_modem_simple_get_path:
47
* @self: A #MMModemSimple.
49
* Gets the DBus path of the #MMObject which implements this interface.
51
* Returns: (transfer none): The DBus path of the #MMObject object.
54
mm_modem_simple_get_path (MMModemSimple *self)
56
g_return_val_if_fail (MM_IS_MODEM_SIMPLE (self), NULL);
58
RETURN_NON_EMPTY_CONSTANT_STRING (
59
g_dbus_proxy_get_object_path (G_DBUS_PROXY (self)));
63
* mm_modem_simple_dup_path:
64
* @self: A #MMModemSimple.
66
* Gets a copy of the DBus path of the #MMObject object which implements this interface.
68
* Returns: (transfer full): The DBus path of the #MMObject. The returned value should be freed with g_free().
71
mm_modem_simple_dup_path (MMModemSimple *self)
75
g_return_val_if_fail (MM_IS_MODEM_SIMPLE (self), NULL);
77
g_object_get (G_OBJECT (self),
78
"g-object-path", &value,
80
RETURN_NON_EMPTY_STRING (value);
83
/*****************************************************************************/
86
GSimpleAsyncResult *result;
87
GCancellable *cancellable;
91
connect_context_complete_and_free (ConnectContext *ctx)
93
g_simple_async_result_complete (ctx->result);
94
g_object_unref (ctx->result);
96
g_object_unref (ctx->cancellable);
97
g_slice_free (ConnectContext, ctx);
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.
106
* Finishes an operation started with mm_modem_simple_connect().
108
* Returns: (transfer full): A #MMBearer, or %FALSE if @error is set. The returned value must be freed with g_object_ref().
111
mm_modem_simple_connect_finish (MMModemSimple *self,
115
g_return_val_if_fail (MM_IS_MODEM_SIMPLE (self), NULL);
117
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
120
return g_object_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));
124
new_bearer_ready (GDBusConnection *connection,
128
GError *error = NULL;
130
GObject *source_object;
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);
137
g_simple_async_result_take_error (ctx->result, error);
139
g_simple_async_result_set_op_res_gpointer (ctx->result,
141
(GDestroyNotify)g_object_unref);
143
connect_context_complete_and_free (ctx);
147
simple_connect_ready (MMModemSimple *self,
151
GError *error = NULL;
152
gchar *bearer_path = NULL;
154
if (!mm_gdbus_modem_simple_call_connect_finish (MM_GDBUS_MODEM_SIMPLE (self),
158
g_simple_async_result_take_error (ctx->result, error);
159
connect_context_complete_and_free (ctx);
163
g_async_initable_new_async (MM_TYPE_BEARER,
166
(GAsyncReadyCallback)new_bearer_ready,
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",
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.
184
* Asynchronously requests to connect the modem using the given @properties.
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.
189
* See mm_modem_simple_connect_sync() for the synchronous, blocking version of this method.
192
mm_modem_simple_connect (MMModemSimple *self,
193
MMSimpleConnectProperties *properties,
194
GCancellable *cancellable,
195
GAsyncReadyCallback callback,
201
g_return_if_fail (MM_IS_MODEM_SIMPLE (self));
203
ctx = g_slice_new0 (ConnectContext);
204
ctx->result = g_simple_async_result_new (G_OBJECT (self),
207
mm_modem_simple_connect);
209
ctx->cancellable = g_object_ref (cancellable);
211
variant = mm_simple_connect_properties_get_dictionary (properties);
212
mm_gdbus_modem_simple_call_connect (
213
MM_GDBUS_MODEM_SIMPLE (self),
216
(GAsyncReadyCallback)simple_connect_ready,
219
g_variant_unref (variant);
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.
229
* Synchronously requests to connect the modem using the given @properties.
231
* The calling thread is blocked until a reply is received. See mm_modem_simple_connect()
232
* for the asynchronous version of this method.
234
* Returns: (transfer full): A #MMBearer, or %FALSE if @error is set. The returned value must be freed with g_object_ref().
237
mm_modem_simple_connect_sync (MMModemSimple *self,
238
MMSimpleConnectProperties *properties,
239
GCancellable *cancellable,
242
GObject *bearer = NULL;
243
gchar *bearer_path = NULL;
246
g_return_val_if_fail (MM_IS_MODEM_SIMPLE (self), NULL);
248
variant = mm_simple_connect_properties_get_dictionary (properties);
249
mm_gdbus_modem_simple_call_connect_sync (MM_GDBUS_MODEM_SIMPLE (self),
255
bearer = g_initable_new (MM_TYPE_BEARER,
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",
264
g_free (bearer_path);
267
g_variant_unref (variant);
269
return (bearer ? MM_BEARER (bearer) : NULL);
272
/*****************************************************************************/
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.
280
* Finishes an operation started with mm_modem_simple_disconnect().
282
* Returns: %TRUE if the modem is successfully disconnected, %FALSE if @error is set.
285
mm_modem_simple_disconnect_finish (MMModemSimple *self,
289
g_return_val_if_fail (MM_IS_MODEM_SIMPLE (self), FALSE);
291
return mm_gdbus_modem_simple_call_disconnect_finish (MM_GDBUS_MODEM_SIMPLE (self), res, error);
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.
302
* Asynchronously requests to disconnect the modem.
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.
307
* See mm_modem_simple_disconnect_sync() for the synchronous, blocking version of this method.
310
mm_modem_simple_disconnect (MMModemSimple *self,
312
GCancellable *cancellable,
313
GAsyncReadyCallback callback,
316
g_return_if_fail (MM_IS_MODEM_SIMPLE (self));
318
mm_gdbus_modem_simple_call_disconnect (MM_GDBUS_MODEM_SIMPLE (self),
319
bearer ? bearer : "/",
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.
332
* Synchronously requests to disconnect the modem.
334
* The calling thread is blocked until a reply is received. See mm_modem_simple_disconnect()
335
* for the asynchronous version of this method.
337
* Returns: %TRUE if the modem is successfully disconnected, %FALSE if @error is set.
340
mm_modem_simple_disconnect_sync (MMModemSimple *self,
342
GCancellable *cancellable,
345
g_return_val_if_fail (MM_IS_MODEM_SIMPLE (self), FALSE);
347
return mm_gdbus_modem_simple_call_disconnect_sync (MM_GDBUS_MODEM_SIMPLE (self),
348
bearer ? bearer : "/",
353
/*****************************************************************************/
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.
361
* Finishes an operation started with mm_modem_simple_get_status().
363
* Returns: (transfer full): A #MMSimpleStatus, or %FALSE if @error is set. The returned value must be freed with g_object_ref().
366
mm_modem_simple_get_status_finish (MMModemSimple *self,
370
MMSimpleStatus *status;
371
GVariant *dictionary = NULL;
373
g_return_val_if_fail (MM_IS_MODEM_SIMPLE (self), NULL);
375
if (!mm_gdbus_modem_simple_call_get_status_finish (MM_GDBUS_MODEM_SIMPLE (self), &dictionary, res, error))
378
status = mm_simple_status_new_from_dictionary (dictionary, error);
379
g_variant_unref (dictionary);
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.
390
* Asynchronously requests a compilation of the status of the modem.
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.
395
* See mm_modem_simple_get_status_sync() for the synchronous, blocking version of this method.
398
mm_modem_simple_get_status (MMModemSimple *self,
399
GCancellable *cancellable,
400
GAsyncReadyCallback callback,
403
g_return_if_fail (MM_IS_MODEM_SIMPLE (self));
405
mm_gdbus_modem_simple_call_get_status (MM_GDBUS_MODEM_SIMPLE (self),
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.
417
* Synchronously requests a compilation of the status of the modem.
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.
422
* Returns: (transfer full): A #MMSimpleStatus, or %FALSE if @error is set. The returned value must be freed with g_object_ref().
425
mm_modem_simple_get_status_sync (MMModemSimple *self,
426
GCancellable *cancellable,
429
MMSimpleStatus *status;
430
GVariant *dictionary = NULL;
432
g_return_val_if_fail (MM_IS_MODEM_SIMPLE (self), NULL);
434
if (!mm_gdbus_modem_simple_call_get_status_sync (MM_GDBUS_MODEM_SIMPLE (self), &dictionary, cancellable, error))
437
status = mm_simple_status_new_from_dictionary (dictionary, error);
438
g_variant_unref (dictionary);
442
/*****************************************************************************/
445
mm_modem_simple_init (MMModemSimple *self)
450
mm_modem_simple_class_init (MMModemSimpleClass *modem_class)