summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2013-05-24 12:55:07 +0200
committerAleksander Morgado <aleksander@lanedo.com>2013-05-24 12:55:07 +0200
commit364a9b070d0dc0da2ada14d9fcbe50dd4e6d5335 (patch)
tree1507d3fd9411c3605b8fe3938baeb2caeeba966d
parente4703e843b78aaddd9828a36bbf4ee61342e61e4 (diff)
downloadModemManager-364a9b070d0dc0da2ada14d9fcbe50dd4e6d5335.tar.gz
api,introspection: new 'SetCapabilities' method
For those modems which expose a valid SupportedCapabilities property, we'll allow switching between them.
-rw-r--r--docs/reference/libmm-glib/libmm-glib-sections.txt7
-rw-r--r--introspection/org.freedesktop.ModemManager1.Modem.xml10
-rw-r--r--libmm-glib/mm-modem.c82
-rw-r--r--libmm-glib/mm-modem.h13
-rw-r--r--src/mm-iface-modem.c94
-rw-r--r--src/mm-iface-modem.h9
6 files changed, 215 insertions, 0 deletions
diff --git a/docs/reference/libmm-glib/libmm-glib-sections.txt b/docs/reference/libmm-glib/libmm-glib-sections.txt
index a02bf199a..930277541 100644
--- a/docs/reference/libmm-glib/libmm-glib-sections.txt
+++ b/docs/reference/libmm-glib/libmm-glib-sections.txt
@@ -138,6 +138,9 @@ mm_modem_set_allowed_modes_sync
mm_modem_set_bands
mm_modem_set_bands_finish
mm_modem_set_bands_sync
+mm_modem_set_capabilities
+mm_modem_set_capabilities_finish
+mm_modem_set_capabilities_sync
mm_modem_reset
mm_modem_reset_finish
mm_modem_reset_sync
@@ -1486,6 +1489,9 @@ mm_gdbus_modem_call_set_allowed_modes_sync
mm_gdbus_modem_call_set_bands
mm_gdbus_modem_call_set_bands_finish
mm_gdbus_modem_call_set_bands_sync
+mm_gdbus_modem_call_set_capabilities
+mm_gdbus_modem_call_set_capabilities_finish
+mm_gdbus_modem_call_set_capabilities_sync
mm_gdbus_modem_call_command
mm_gdbus_modem_call_command_finish
mm_gdbus_modem_call_command_sync
@@ -1528,6 +1534,7 @@ mm_gdbus_modem_complete_list_bearers
mm_gdbus_modem_complete_reset
mm_gdbus_modem_complete_set_allowed_modes
mm_gdbus_modem_complete_set_bands
+mm_gdbus_modem_complete_set_capabilities
mm_gdbus_modem_interface_info
mm_gdbus_modem_override_properties
<SUBSECTION Standard>
diff --git a/introspection/org.freedesktop.ModemManager1.Modem.xml b/introspection/org.freedesktop.ModemManager1.Modem.xml
index d2707a1a0..09c1b363b 100644
--- a/introspection/org.freedesktop.ModemManager1.Modem.xml
+++ b/introspection/org.freedesktop.ModemManager1.Modem.xml
@@ -137,6 +137,16 @@
</method>
<!--
+ SetCapabilities:
+ @capabilities: Bitmask of <link linkend="MMModemCapability">MMModemCapability</link> values, to specify the capabilities to use.
+
+ Set the capabilities of the device. A restart of the modem may be required.
+ -->
+ <method name="SetCapabilities">
+ <arg name="capabilities" type="u" direction="in" />
+ </method>
+
+ <!--
SetAllowedModes:
@modes: Bitmask of <link linkend="MMModemMode">MMModemMode</link> values, to specify all the modes allowed in the modem.
@preferred: Specific <link linkend="MMModemMode">MMModemMode</link> preferred among the ones allowed, if any.
diff --git a/libmm-glib/mm-modem.c b/libmm-glib/mm-modem.c
index 38d15e8ae..caec0b128 100644
--- a/libmm-glib/mm-modem.c
+++ b/libmm-glib/mm-modem.c
@@ -2296,6 +2296,88 @@ mm_modem_set_power_state_sync (MMModem *self,
/*****************************************************************************/
/**
+ * mm_modem_set_capabilities_finish:
+ * @self: A #MMModem.
+ * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to mm_modem_set_capabilities().
+ * @error: Return location for error or %NULL.
+ *
+ * Finishes an operation started with mm_modem_set_capabilities().
+ *
+ * Returns: %TRUE if the capabilities were successfully set, %FALSE if @error is set.
+ */
+gboolean
+mm_modem_set_capabilities_finish (MMModem *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ g_return_val_if_fail (MM_IS_MODEM (self), FALSE);
+
+ return mm_gdbus_modem_call_set_capabilities_finish (MM_GDBUS_MODEM (self), res, error);
+}
+
+/**
+ * mm_modem_set_capabilities:
+ * @self: A #MMModem.
+ * @capabilities: A #MMModemCapability mask.
+ * @cancellable: (allow-none): A #GCancellable or %NULL.
+ * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL.
+ * @user_data: User data to pass to @callback.
+ *
+ * Asynchronously sets the capabilities of the device. A restart of the modem may be required.
+ *
+ * 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.
+ * You can then call mm_modem_set_capabilities_finish() to get the result of the operation.
+ *
+ * See mm_modem_set_capabilities_sync() for the synchronous, blocking version of this method.
+ */
+void
+mm_modem_set_capabilities (MMModem *self,
+ MMModemCapability capabilities,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_return_if_fail (MM_IS_MODEM (self));
+
+ mm_gdbus_modem_call_set_capabilities (MM_GDBUS_MODEM (self),
+ capabilities,
+ cancellable,
+ callback,
+ user_data);
+}
+
+/**
+ * mm_modem_set_capabilities_sync:
+ * @self: A #MMModem.
+ * @capabilities: A #MMModemCapability mask.
+ * @cancellable: (allow-none): A #GCancellable or %NULL.
+ * @error: Return location for error or %NULL.
+ *
+ * Synchronously sets the capabilities of the device. A restart of the modem may be required.
+ *
+ * The calling thread is blocked until a reply is received. See mm_modem_set_capabilities()
+ * for the asynchronous version of this method.
+ *
+ * Returns: %TRUE if the capabilities were successfully set, %FALSE if @error is set.
+ */
+gboolean
+mm_modem_set_capabilities_sync (MMModem *self,
+ MMModemCapability capabilities,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_return_val_if_fail (MM_IS_MODEM (self), FALSE);
+
+ return (mm_gdbus_modem_call_set_capabilities_sync (
+ MM_GDBUS_MODEM (self),
+ capabilities,
+ cancellable,
+ error));
+}
+
+/*****************************************************************************/
+
+/**
* mm_modem_set_allowed_modes_finish:
* @self: A #MMModem.
* @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to mm_modem_set_allowed_modes().
diff --git a/libmm-glib/mm-modem.h b/libmm-glib/mm-modem.h
index 87d688b25..faa511a46 100644
--- a/libmm-glib/mm-modem.h
+++ b/libmm-glib/mm-modem.h
@@ -263,6 +263,19 @@ gboolean mm_modem_set_power_state_sync (MMModem *self,
GCancellable *cancellable,
GError **error);
+void mm_modem_set_capabilities (MMModem *self,
+ MMModemCapability capabilities,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean mm_modem_set_capabilities_finish (MMModem *self,
+ GAsyncResult *res,
+ GError **error);
+gboolean mm_modem_set_capabilities_sync (MMModem *self,
+ MMModemCapability capabilities,
+ GCancellable *cancellable,
+ GError **error);
+
void mm_modem_set_allowed_modes (MMModem *self,
MMModemMode modes,
MMModemMode preferred,
diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c
index 0a8563fc1..c89d4e60a 100644
--- a/src/mm-iface-modem.c
+++ b/src/mm-iface-modem.c
@@ -1791,6 +1791,96 @@ handle_factory_reset (MmGdbusModem *skeleton,
}
/*****************************************************************************/
+/* CAPABILITIES */
+
+typedef struct {
+ MmGdbusModem *skeleton;
+ GDBusMethodInvocation *invocation;
+ MMIfaceModem *self;
+ MMModemCapability capabilities;
+} HandleSetCapabilitiesContext;
+
+static void
+handle_set_capabilities_context_free (HandleSetCapabilitiesContext *ctx)
+{
+ g_object_unref (ctx->skeleton);
+ g_object_unref (ctx->invocation);
+ g_object_unref (ctx->self);
+ g_free (ctx);
+}
+
+static void
+set_capabilities_ready (MMIfaceModem *self,
+ GAsyncResult *res,
+ HandleSetCapabilitiesContext *ctx)
+{
+ GError *error = NULL;
+
+ if (!MM_IFACE_MODEM_GET_INTERFACE (self)->set_capabilities_finish (self, res, &error))
+ g_dbus_method_invocation_take_error (ctx->invocation, error);
+ else
+ mm_gdbus_modem_complete_set_capabilities (ctx->skeleton, ctx->invocation);
+ handle_set_capabilities_context_free (ctx);
+}
+
+static void
+handle_set_capabilities_auth_ready (MMBaseModem *self,
+ GAsyncResult *res,
+ HandleSetCapabilitiesContext *ctx)
+{
+ GError *error = NULL;
+ gchar *capabilities_string;
+
+ if (!mm_base_modem_authorize_finish (self, res, &error)) {
+ g_dbus_method_invocation_take_error (ctx->invocation, error);
+ handle_set_capabilities_context_free (ctx);
+ return;
+ }
+
+ /* If setting allowed capabilities is not implemented, report an error */
+ if (!MM_IFACE_MODEM_GET_INTERFACE (self)->set_capabilities ||
+ !MM_IFACE_MODEM_GET_INTERFACE (self)->set_capabilities_finish) {
+ g_dbus_method_invocation_return_error (ctx->invocation,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_UNSUPPORTED,
+ "Setting allowed capabilities not supported");
+ handle_set_capabilities_context_free (ctx);
+ return;
+ }
+
+ capabilities_string = mm_modem_capability_build_string_from_mask (ctx->capabilities);
+ mm_dbg ("Setting new list of capabilities: '%s'", capabilities_string);
+ MM_IFACE_MODEM_GET_INTERFACE (self)->set_capabilities (
+ MM_IFACE_MODEM (self),
+ ctx->capabilities,
+ (GAsyncReadyCallback)set_capabilities_ready,
+ ctx);
+ g_free (capabilities_string);
+}
+
+static gboolean
+handle_set_capabilities (MmGdbusModem *skeleton,
+ GDBusMethodInvocation *invocation,
+ guint capabilities,
+ MMIfaceModem *self)
+{
+ HandleSetCapabilitiesContext *ctx;
+
+ ctx = g_new (HandleSetCapabilitiesContext, 1);
+ ctx->skeleton = g_object_ref (skeleton);
+ ctx->invocation = g_object_ref (invocation);
+ ctx->self = g_object_ref (self);
+ ctx->capabilities = capabilities;
+
+ mm_base_modem_authorize (MM_BASE_MODEM (self),
+ invocation,
+ MM_AUTHORIZATION_DEVICE_CONTROL,
+ (GAsyncReadyCallback)handle_set_capabilities_auth_ready,
+ ctx);
+ return TRUE;
+}
+
+/*****************************************************************************/
/* BANDS */
typedef struct {
@@ -4188,6 +4278,10 @@ interface_initialization_step (InitializationContext *ctx)
G_CALLBACK (handle_factory_reset),
ctx->self);
g_signal_connect (ctx->skeleton,
+ "handle-set-capabilities",
+ G_CALLBACK (handle_set_capabilities),
+ ctx->self);
+ g_signal_connect (ctx->skeleton,
"handle-set-bands",
G_CALLBACK (handle_set_bands),
ctx->self);
diff --git a/src/mm-iface-modem.h b/src/mm-iface-modem.h
index 113fd610b..9e4a4cdca 100644
--- a/src/mm-iface-modem.h
+++ b/src/mm-iface-modem.h
@@ -209,6 +209,15 @@ struct _MMIfaceModem {
GAsyncResult *res,
GError **error);
+ /* Asynchronous capabilities setting operation */
+ void (*set_capabilities) (MMIfaceModem *self,
+ MMModemCapability,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+ gboolean (*set_capabilities_finish) (MMIfaceModem *self,
+ GAsyncResult *res,
+ GError **error);
+
/* Asynchronous allowed band setting operation */
void (*set_bands) (MMIfaceModem *self,
GArray *bands_array,