libmm-glib: handle the Simple interface
This commit is contained in:
@@ -20,6 +20,8 @@ libmm_glib_la_SOURCES = \
|
||||
mm-modem.c \
|
||||
mm-modem-3gpp.h \
|
||||
mm-modem-3gpp.c \
|
||||
mm-modem-simple.h \
|
||||
mm-modem-simple.c \
|
||||
mm-sim.h \
|
||||
mm-sim.c \
|
||||
mm-bearer.h \
|
||||
|
||||
@@ -0,0 +1,265 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* libmm -- Access modem status & information from glib applications
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright (C) 2011 Aleksander Morgado <aleksander@gnu.org>
|
||||
*/
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include "mm-helpers.h"
|
||||
#include "mm-modem-simple.h"
|
||||
|
||||
/**
|
||||
* mm_modem_simple_get_path:
|
||||
* @self: A #MMModemSimple.
|
||||
*
|
||||
* Gets the DBus path of the #MMObject which implements this interface.
|
||||
*
|
||||
* Returns: (transfer none): The DBus path of the #MMObject object.
|
||||
*/
|
||||
const gchar *
|
||||
mm_modem_simple_get_path (MMModemSimple *self)
|
||||
{
|
||||
g_return_val_if_fail (G_IS_DBUS_PROXY (self), NULL);
|
||||
|
||||
RETURN_NON_EMPTY_CONSTANT_STRING (
|
||||
g_dbus_proxy_get_object_path (G_DBUS_PROXY (self)));
|
||||
}
|
||||
|
||||
/**
|
||||
* mm_modem_simple_dup_path:
|
||||
* @self: A #MMModemSimple.
|
||||
*
|
||||
* Gets a copy of the DBus path of the #MMObject object which implements this interface.
|
||||
*
|
||||
* Returns: (transfer full): The DBus path of the #MMObject. The returned value should be freed with g_free().
|
||||
*/
|
||||
gchar *
|
||||
mm_modem_simple_dup_path (MMModemSimple *self)
|
||||
{
|
||||
gchar *value;
|
||||
|
||||
g_return_val_if_fail (G_IS_DBUS_PROXY (self), NULL);
|
||||
|
||||
g_object_get (G_OBJECT (self),
|
||||
"g-object-path", &value,
|
||||
NULL);
|
||||
RETURN_NON_EMPTY_STRING (value);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
GSimpleAsyncResult *result;
|
||||
GCancellable *cancellable;
|
||||
} ConnectContext;
|
||||
|
||||
static void
|
||||
connect_context_complete_and_free (ConnectContext *ctx)
|
||||
{
|
||||
g_simple_async_result_complete (ctx->result);
|
||||
g_object_unref (ctx->result);
|
||||
if (ctx->cancellable)
|
||||
g_object_unref (ctx->cancellable);
|
||||
g_slice_free (ConnectContext, ctx);
|
||||
}
|
||||
|
||||
static GVariant *
|
||||
connect_build_properties (const gchar *first_property_name,
|
||||
va_list var_args)
|
||||
{
|
||||
const gchar *key;
|
||||
GVariantBuilder builder;
|
||||
|
||||
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
|
||||
|
||||
key = first_property_name;
|
||||
while (key) {
|
||||
if (g_str_equal (key, MM_SIMPLE_PROPERTY_PIN) ||
|
||||
g_str_equal (key, MM_SIMPLE_PROPERTY_OPERATOR_ID) ||
|
||||
g_str_equal (key, MM_SIMPLE_PROPERTY_APN) ||
|
||||
g_str_equal (key, MM_SIMPLE_PROPERTY_IP_TYPE) ||
|
||||
g_str_equal (key, MM_SIMPLE_PROPERTY_NUMBER)) {
|
||||
const gchar *value;
|
||||
|
||||
/* If a key with NULL value is given, just ignore it. */
|
||||
value = va_arg (var_args, gchar *);
|
||||
if (value)
|
||||
g_variant_builder_add (&builder, "{sv}", key, g_variant_new_string (value));
|
||||
} else if (g_str_equal (key, MM_SIMPLE_PROPERTY_ALLOW_ROAMING)) {
|
||||
gboolean value;
|
||||
|
||||
value = va_arg (var_args, gboolean);
|
||||
g_variant_builder_add (&builder, "{sv}", key, g_variant_new_boolean (value));
|
||||
} else if (g_str_equal (key, MM_SIMPLE_PROPERTY_ALLOWED_BANDS)) {
|
||||
guint64 value;
|
||||
|
||||
value = va_arg (var_args, guint64);
|
||||
g_variant_builder_add (&builder, "{sv}", key, g_variant_new_uint64 (value));
|
||||
} else if (g_str_equal (key, MM_SIMPLE_PROPERTY_ALLOWED_MODES) ||
|
||||
g_str_equal (key, MM_SIMPLE_PROPERTY_PREFERRED_MODE)) {
|
||||
guint32 value;
|
||||
|
||||
value = va_arg (var_args, guint32);
|
||||
g_variant_builder_add (&builder, "{sv}", key, g_variant_new_uint32 (value));
|
||||
} else {
|
||||
g_warning ("Unexpected key '%s'", key);
|
||||
/* ignore value */
|
||||
va_arg (var_args, gpointer);
|
||||
}
|
||||
|
||||
key = va_arg (var_args, gchar *);
|
||||
}
|
||||
|
||||
return g_variant_ref_sink (g_variant_builder_end (&builder));
|
||||
}
|
||||
|
||||
MMBearer *
|
||||
mm_modem_simple_connect_finish (MMModemSimple *self,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (MM_GDBUS_IS_MODEM_SIMPLE (self), NULL);
|
||||
|
||||
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
|
||||
return NULL;
|
||||
|
||||
return g_object_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));
|
||||
}
|
||||
|
||||
static void
|
||||
new_bearer_ready (GDBusConnection *connection,
|
||||
GAsyncResult *res,
|
||||
ConnectContext *ctx)
|
||||
{
|
||||
GError *error = NULL;
|
||||
MMBearer *bearer;
|
||||
|
||||
bearer = mm_gdbus_bearer_proxy_new_finish (res, &error);
|
||||
if (error)
|
||||
g_simple_async_result_take_error (ctx->result, error);
|
||||
else
|
||||
g_simple_async_result_set_op_res_gpointer (ctx->result,
|
||||
bearer,
|
||||
(GDestroyNotify)g_object_unref);
|
||||
|
||||
connect_context_complete_and_free (ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
simple_connect_ready (MMModemSimple *self,
|
||||
GAsyncResult *res,
|
||||
ConnectContext *ctx)
|
||||
{
|
||||
GError *error = NULL;
|
||||
gchar *bearer_path = NULL;
|
||||
|
||||
if (!mm_gdbus_modem_simple_call_connect_finish (self,
|
||||
&bearer_path,
|
||||
res,
|
||||
&error)) {
|
||||
g_simple_async_result_take_error (ctx->result, error);
|
||||
connect_context_complete_and_free (ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
mm_gdbus_bearer_proxy_new (
|
||||
g_dbus_proxy_get_connection (
|
||||
G_DBUS_PROXY (self)),
|
||||
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
|
||||
MM_DBUS_SERVICE,
|
||||
bearer_path,
|
||||
ctx->cancellable,
|
||||
(GAsyncReadyCallback)new_bearer_ready,
|
||||
ctx);
|
||||
}
|
||||
|
||||
void
|
||||
mm_modem_simple_connect (MMModemSimple *self,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data,
|
||||
const gchar *first_property_name,
|
||||
...)
|
||||
{
|
||||
ConnectContext *ctx;
|
||||
va_list va_args;
|
||||
GVariant *properties;
|
||||
|
||||
g_return_if_fail (MM_GDBUS_IS_MODEM_SIMPLE (self));
|
||||
|
||||
ctx = g_slice_new0 (ConnectContext);
|
||||
ctx->result = g_simple_async_result_new (G_OBJECT (self),
|
||||
callback,
|
||||
user_data,
|
||||
mm_modem_simple_connect);
|
||||
if (cancellable)
|
||||
ctx->cancellable = g_object_ref (cancellable);
|
||||
|
||||
|
||||
va_start (va_args, first_property_name);
|
||||
properties = connect_build_properties (first_property_name, va_args);
|
||||
mm_gdbus_modem_simple_call_connect (
|
||||
self,
|
||||
properties,
|
||||
cancellable,
|
||||
(GAsyncReadyCallback)simple_connect_ready,
|
||||
ctx);
|
||||
|
||||
g_variant_unref (properties);
|
||||
va_end (va_args);
|
||||
}
|
||||
|
||||
MMBearer *
|
||||
mm_modem_simple_connect_sync (MMModemSimple *self,
|
||||
GCancellable *cancellable,
|
||||
GError **error,
|
||||
const gchar *first_property_name,
|
||||
...)
|
||||
{
|
||||
MMBearer *bearer = NULL;
|
||||
gchar *bearer_path = NULL;
|
||||
va_list va_args;
|
||||
GVariant *properties;
|
||||
|
||||
g_return_val_if_fail (MM_GDBUS_IS_MODEM (self), NULL);
|
||||
|
||||
va_start (va_args, first_property_name);
|
||||
properties = connect_build_properties (first_property_name, va_args);
|
||||
|
||||
mm_gdbus_modem_simple_call_connect_sync (self,
|
||||
properties,
|
||||
&bearer_path,
|
||||
cancellable,
|
||||
error);
|
||||
if (bearer_path) {
|
||||
bearer = mm_gdbus_bearer_proxy_new_sync (
|
||||
g_dbus_proxy_get_connection (
|
||||
G_DBUS_PROXY (self)),
|
||||
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
|
||||
MM_DBUS_SERVICE,
|
||||
bearer_path,
|
||||
cancellable,
|
||||
error);
|
||||
g_free (bearer_path);
|
||||
}
|
||||
|
||||
g_variant_unref (properties);
|
||||
va_end (va_args);
|
||||
|
||||
return bearer;
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* libmm -- Access modem status & information from glib applications
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright (C) 2011 Aleksander Morgado <aleksander@gnu.org>
|
||||
*/
|
||||
|
||||
#ifndef _MM_MODEM_SIMPLE_H_
|
||||
#define _MM_MODEM_SIMPLE_H_
|
||||
|
||||
#include <ModemManager.h>
|
||||
#include <mm-gdbus-modem.h>
|
||||
|
||||
#include "mm-bearer.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef MmGdbusModemSimple MMModemSimple;
|
||||
#define MM_TYPE_MODEM_SIMPLE(o) MM_GDBUS_TYPE_MODEM_SIMPLE (o)
|
||||
#define MM_MODEM_SIMPLE(o) MM_GDBUS_MODEM_SIMPLE(o)
|
||||
#define MM_IS_MODEM_SIMPLE(o) MM_GDBUS_IS_MODEM_SIMPLE(o)
|
||||
|
||||
const gchar *mm_modem_simple_get_path (MMModemSimple *self);
|
||||
gchar *mm_modem_simple_dup_path (MMModemSimple *self);
|
||||
|
||||
#define MM_SIMPLE_PROPERTY_PIN "pin" /* string */
|
||||
#define MM_SIMPLE_PROPERTY_OPERATOR_ID "operator-id" /* string */
|
||||
#define MM_SIMPLE_PROPERTY_ALLOWED_BANDS "allowed-bands" /* MMModemBand */
|
||||
#define MM_SIMPLE_PROPERTY_ALLOWED_MODES "allowed-modes" /* MMModemMode */
|
||||
#define MM_SIMPLE_PROPERTY_PREFERRED_MODE "preferred-mode" /* MMModemMode */
|
||||
#define MM_SIMPLE_PROPERTY_APN "apn" /* string */
|
||||
#define MM_SIMPLE_PROPERTY_IP_TYPE "ip-type" /* string */
|
||||
#define MM_SIMPLE_PROPERTY_NUMBER "number" /* string */
|
||||
#define MM_SIMPLE_PROPERTY_ALLOW_ROAMING "allow-roaming" /* boolean */
|
||||
|
||||
void mm_modem_simple_connect (MMModemSimple *self,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data,
|
||||
const gchar *first_property_name,
|
||||
...);
|
||||
MMBearer *mm_modem_simple_connect_finish (MMModemSimple *self,
|
||||
GAsyncResult *res,
|
||||
GError **error);
|
||||
MMBearer *mm_modem_simple_connect_sync (MMModemSimple *self,
|
||||
GCancellable *cancellable,
|
||||
GError **error,
|
||||
const gchar *first_property_name,
|
||||
...);
|
||||
|
||||
/* void mm_modem_simple_disconnect (MMModemSimple *self, */
|
||||
/* GCancellable *cancellable, */
|
||||
/* GAsyncReadyCallback callback, */
|
||||
/* gpointer user_data); */
|
||||
/* GList *mm_modem_simple_disconnect_finish (MMModemSimple *self, */
|
||||
/* GAsyncResult *res, */
|
||||
/* GError **error); */
|
||||
/* GList *mm_modem_simple_disconnect_sync (MMModemSimple *self, */
|
||||
/* GCancellable *cancellable, */
|
||||
/* GError **error); */
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _MM_MODEM_SIMPLE_H_ */
|
||||
@@ -92,6 +92,22 @@ mm_object_get_modem_3gpp (MMObject *object)
|
||||
return mm_gdbus_object_get_modem3gpp (object);
|
||||
}
|
||||
|
||||
/**
|
||||
* mm_object_get_modem_simple:
|
||||
* @object: A #MMObject.
|
||||
*
|
||||
* Gets the #MMModemSimple instance for the D-Bus interface <link linkend="gdbus-interface-org-freedesktop-ModemManager1-Modem-Modemsimple.top_of_page">org.freedesktop.ModemManager1.Modem.Modemsimple</link> on @object, if any.
|
||||
*
|
||||
* Returns: (transfer full): A #MMModemSimple that must be freed with g_object_unref() or %NULL if @object does not implement the interface.
|
||||
*/
|
||||
MMModemSimple *
|
||||
mm_object_get_modem_simple (MMObject *object)
|
||||
{
|
||||
g_return_val_if_fail (MM_GDBUS_IS_OBJECT (object), NULL);
|
||||
|
||||
return mm_gdbus_object_get_modem_simple (object);
|
||||
}
|
||||
|
||||
/**
|
||||
* mm_object_peek_modem: (skip)
|
||||
* @object: A #MMObject.
|
||||
@@ -127,3 +143,21 @@ mm_object_peek_modem_3gpp (MMObject *object)
|
||||
|
||||
return mm_gdbus_object_peek_modem3gpp (object);
|
||||
}
|
||||
|
||||
/**
|
||||
* mm_object_peek_modem_simple: (skip)
|
||||
* @object: A #MMObject.
|
||||
*
|
||||
* Like mm_object_get_modem_simple() but doesn't increase the reference count on the returned object.
|
||||
*
|
||||
* <warning>It is not safe to use the returned object if you are on another thread than the one where the #MMManager is running.</warning>
|
||||
*
|
||||
* Returns: (transfer none): A #MMModemSimple or %NULL if @object does not implement the interface. Do not free the returned object, it is owned by @object.
|
||||
*/
|
||||
MMModemSimple *
|
||||
mm_object_peek_modem_simple (MMObject *object)
|
||||
{
|
||||
g_return_val_if_fail (MM_GDBUS_IS_OBJECT (object), NULL);
|
||||
|
||||
return mm_gdbus_object_peek_modem_simple (object);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "mm-modem.h"
|
||||
#include "mm-modem-3gpp.h"
|
||||
#include "mm-modem-simple.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@@ -41,9 +42,11 @@ gchar *mm_object_dup_path (MMObject *self);
|
||||
|
||||
MMModem *mm_object_get_modem (MMObject *object);
|
||||
MMModem3gpp *mm_object_get_modem_3gpp (MMObject *object);
|
||||
MMModemSimple *mm_object_get_modem_simple (MMObject *object);
|
||||
|
||||
MMModem *mm_object_peek_modem (MMObject *object);
|
||||
MMModem3gpp *mm_object_peek_modem_3gpp (MMObject *object);
|
||||
MMModemSimple *mm_object_peek_modem_simple (MMObject *object);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
Reference in New Issue
Block a user