summaryrefslogtreecommitdiff
path: root/libmm-glib
diff options
context:
space:
mode:
authorlvmaorui <ZRMaorui.Lu@fibocom.com>2021-03-26 16:38:45 +0800
committerAleksander Morgado <aleksander@aleksander.es>2021-10-13 13:14:10 +0200
commit8e67d2375c8280235b5125e73ccf1e0973c28319 (patch)
tree15fea90084080eb50580c99f7fdc6f05f8d67617 /libmm-glib
parentdbd95e30c4a59aee30b3f93ed1f7ac85f96533ea (diff)
docs,libmm-glib: add SAR user-level api
Diffstat (limited to 'libmm-glib')
-rw-r--r--libmm-glib/Makefile.am3
-rw-r--r--libmm-glib/libmm-glib.h1
-rw-r--r--libmm-glib/mm-manager.c1
-rw-r--r--libmm-glib/mm-modem-sar.c306
-rw-r--r--libmm-glib/mm-modem-sar.h104
-rw-r--r--libmm-glib/mm-object.c45
-rw-r--r--libmm-glib/mm-object.h3
7 files changed, 463 insertions, 0 deletions
diff --git a/libmm-glib/Makefile.am b/libmm-glib/Makefile.am
index efbe43d3..77f69e19 100644
--- a/libmm-glib/Makefile.am
+++ b/libmm-glib/Makefile.am
@@ -32,6 +32,8 @@ libmm_glib_la_SOURCES = \
mm-modem-time.c \
mm-modem-firmware.h \
mm-modem-firmware.c \
+ mm-modem-sar.h \
+ mm-modem-sar.c \
mm-modem-signal.h \
mm-modem-signal.c \
mm-modem-oma.h \
@@ -140,6 +142,7 @@ include_HEADERS = \
mm-modem-location.h \
mm-modem-time.h \
mm-modem-firmware.h \
+ mm-modem-sar.h \
mm-modem-signal.h \
mm-modem-oma.h \
mm-modem-simple.h \
diff --git a/libmm-glib/libmm-glib.h b/libmm-glib/libmm-glib.h
index 86088509..4366ca42 100644
--- a/libmm-glib/libmm-glib.h
+++ b/libmm-glib/libmm-glib.h
@@ -51,6 +51,7 @@
# include <mm-modem-firmware.h>
# include <mm-modem-signal.h>
# include <mm-modem-oma.h>
+# include <mm-modem-sar.h>
#endif
#if defined (_LIBMM_INSIDE_MM) || \
diff --git a/libmm-glib/mm-manager.c b/libmm-glib/mm-manager.c
index 73da6df8..1100b2d9 100644
--- a/libmm-glib/mm-manager.c
+++ b/libmm-glib/mm-manager.c
@@ -71,6 +71,7 @@ get_proxy_type (GDBusObjectManagerClient *manager,
g_hash_table_insert (lookup_hash, (gpointer) "org.freedesktop.ModemManager1.Modem.Voice", GSIZE_TO_POINTER (MM_TYPE_MODEM_VOICE));
g_hash_table_insert (lookup_hash, (gpointer) "org.freedesktop.ModemManager1.Modem.Location", GSIZE_TO_POINTER (MM_TYPE_MODEM_LOCATION));
g_hash_table_insert (lookup_hash, (gpointer) "org.freedesktop.ModemManager1.Modem.Time", GSIZE_TO_POINTER (MM_TYPE_MODEM_TIME));
+ g_hash_table_insert (lookup_hash, (gpointer) "org.freedesktop.ModemManager1.Modem.Sar", GSIZE_TO_POINTER (MM_TYPE_MODEM_SAR));
g_hash_table_insert (lookup_hash, (gpointer) "org.freedesktop.ModemManager1.Modem.Signal", GSIZE_TO_POINTER (MM_TYPE_MODEM_SIGNAL));
g_hash_table_insert (lookup_hash, (gpointer) "org.freedesktop.ModemManager1.Modem.Firmware", GSIZE_TO_POINTER (MM_TYPE_MODEM_FIRMWARE));
g_hash_table_insert (lookup_hash, (gpointer) "org.freedesktop.ModemManager1.Modem.Oma", GSIZE_TO_POINTER (MM_TYPE_MODEM_OMA));
diff --git a/libmm-glib/mm-modem-sar.c b/libmm-glib/mm-modem-sar.c
new file mode 100644
index 00000000..c93594e2
--- /dev/null
+++ b/libmm-glib/mm-modem-sar.c
@@ -0,0 +1,306 @@
+/* -*- 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) 2021 Fibocom Wireless Inc.
+ */
+
+#include <gio/gio.h>
+
+#include "mm-helpers.h"
+#include "mm-errors-types.h"
+#include "mm-modem-sar.h"
+#include "mm-common-helpers.h"
+
+/**
+ * SECTION: mm-modem-sar
+ * @title: MMModemSar
+ * @short_description: The SAR interface
+ *
+ * The #MMModemSar is an object providing access to the methods, signals and
+ * properties of the SAR interface.
+ *
+ * The SAR interface is exposed whenever a modem has SAR capabilities.
+ */
+
+G_DEFINE_TYPE (MMModemSar, mm_modem_sar, MM_GDBUS_TYPE_MODEM_SAR_PROXY)
+
+/*****************************************************************************/
+
+/**
+ * mm_modem_sar_get_path:
+ * @self: A #MMModemSar.
+ *
+ * Gets the DBus path of the #MMObject which implements this interface.
+ *
+ * Returns: (transfer none): The DBus path of the #MMObject object.
+ *
+ * Since: 1.20
+ */
+const gchar *
+mm_modem_sar_get_path (MMModemSar *self)
+{
+ g_return_val_if_fail (MM_IS_MODEM_SAR (self), NULL);
+
+ RETURN_NON_EMPTY_CONSTANT_STRING (
+ g_dbus_proxy_get_object_path (G_DBUS_PROXY (self)));
+}
+
+/**
+ * mm_modem_sar_dup_path:
+ * @self: A #MMModemSar.
+ *
+ * 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().
+ *
+ * Since: 1.20
+ */
+gchar *
+mm_modem_sar_dup_path (MMModemSar *self)
+{
+ gchar *value;
+
+ g_return_val_if_fail (MM_IS_MODEM_SAR (self), NULL);
+
+ g_object_get (G_OBJECT (self),
+ "g-object-path", &value,
+ NULL);
+ RETURN_NON_EMPTY_STRING (value);
+}
+/*****************************************************************************/
+
+/**
+ * mm_modem_sar_enable_finish:
+ * @self: A #MMModemSar.
+ * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to
+ * mm_modem_sar_enable().
+ * @error: Return location for error or %NULL.
+ *
+ * Finishes an operation started with mm_modem_sar_enable().
+ *
+ * Returns: %TRUE if the enable was successful, %FALSE if @error is set.
+ *
+ * Since: 1.20
+ */
+gboolean
+mm_modem_sar_enable_finish (MMModemSar *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ g_return_val_if_fail (MM_IS_MODEM_SAR (self), FALSE);
+
+ return mm_gdbus_modem_sar_call_enable_finish (MM_GDBUS_MODEM_SAR (self), res, error);
+}
+
+/**
+ * mm_modem_sar_enable:
+ * @self: A #MMModemSar.
+ * @enable: %TRUE to enable dynamic SAR and %FALSE to disable it.
+ * @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 enable or disable dynamic SAR.
+ *
+ * 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_sar_enable_finish() to get the result of the operation.
+ *
+ * See mm_modem_sar_enable_sync() for the synchronous, blocking version of
+ * this method.
+ *
+ * Since: 1.20
+ */
+void
+mm_modem_sar_enable (MMModemSar *self,
+ gboolean enable,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_return_if_fail (MM_IS_MODEM_SAR (self));
+
+ mm_gdbus_modem_sar_call_enable (MM_GDBUS_MODEM_SAR (self), enable, cancellable, callback, user_data);
+}
+
+/**
+ * mm_modem_sar_enable_sync:
+ * @self: A #MMModemSar.
+ * @enable: %TRUE to enable dynamic SAR and %FALSE to disable it.
+ * @cancellable: (allow-none): A #GCancellable or %NULL.
+ * @error: Return location for error or %NULL.
+ *
+ * Synchronously enable or disable dynamic SAR.
+ *
+ * The calling thread is blocked until a reply is received. See
+ * mm_modem_sar_enable() for the asynchronous version of this method.
+ *
+ * Returns: %TRUE if the enable was successful, %FALSE if @error is set.
+ *
+ * Since: 1.20
+ */
+gboolean
+mm_modem_sar_enable_sync (MMModemSar *self,
+ gboolean enable,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_return_val_if_fail (MM_IS_MODEM_SAR (self), FALSE);
+
+ return mm_gdbus_modem_sar_call_enable_sync (MM_GDBUS_MODEM_SAR (self), enable, cancellable, error);
+}
+
+/*****************************************************************************/
+
+/**
+ * mm_modem_sar_power_level_finish:
+ * @self: A #MMModemSar.
+ * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to
+ * mm_modem_sar_enable().
+ * @error: Return location for error or %NULL.
+ *
+ * Finishes an operation started with mm_modem_sar_set_power_level().
+ *
+ * Returns: %TRUE if set power level was successful, %FALSE if @error is set.
+ *
+ * Since: 1.20
+ */
+gboolean
+mm_modem_sar_set_power_level_finish (MMModemSar *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ g_return_val_if_fail (MM_IS_MODEM_SAR (self), FALSE);
+
+ return mm_gdbus_modem_sar_call_set_power_level_finish (MM_GDBUS_MODEM_SAR (self), res, error);
+}
+
+/**
+ * mm_modem_sar_set_power_level:
+ * @self: A #MMModemSar.
+ * @level: Index of the SAR power level mapping table
+ * @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 set current dynamic SAR power level.
+ *
+ * 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_sar_set_power_level_finish() to get the result of the operation.
+ *
+ * See mm_modem_sar_set_power_level_sync() for the synchronous, blocking version of
+ * this method.
+ *
+ * Since: 1.20
+ */
+void
+mm_modem_sar_set_power_level (MMModemSar *self,
+ guint level,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_return_if_fail (MM_IS_MODEM_SAR (self));
+
+ mm_gdbus_modem_sar_call_set_power_level (MM_GDBUS_MODEM_SAR (self), level, cancellable, callback, user_data);
+}
+
+/**
+ * mm_modem_sar_set_power_level_sync:
+ * @self: A #MMModemSar.
+ * @level: Index of the SAR power level mapping table
+ * @cancellable: (allow-none): A #GCancellable or %NULL.
+ * @error: Return location for error or %NULL.
+ *
+ * Synchronously set current dynamic SAR power level.
+ *
+ * The calling thread is blocked until a reply is received. See
+ * mm_modem_sar_set_power_level() for the asynchronous version of this method.
+ *
+ * Returns: %TRUE if set power level was successful, %FALSE if @error is set.
+ *
+ * Since: 1.20
+ */
+gboolean
+mm_modem_sar_set_power_level_sync (MMModemSar *self,
+ guint level,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_return_val_if_fail (MM_IS_MODEM_SAR (self), FALSE);
+
+ return mm_gdbus_modem_sar_call_set_power_level_sync (MM_GDBUS_MODEM_SAR (self), level, cancellable, error);
+}
+
+/*****************************************************************************/
+/**
+ * mm_modem_sar_get_state:
+ * @self: A #MMModem.
+ *
+ * Gets the state of dynamic SAR.
+ *
+ * Returns: %TRUE if dynamic SAR is enabled, %FALSE otherwise.
+ *
+ * Since: 1.20
+ */
+gboolean
+mm_modem_sar_get_state (MMModemSar *self)
+{
+ g_return_val_if_fail (MM_IS_MODEM_SAR (self), FALSE);
+
+ return mm_gdbus_modem_sar_get_state (MM_GDBUS_MODEM_SAR (self));
+}
+
+/*****************************************************************************/
+/**
+ * mm_modem_sar_get_power_level:
+ * @self: A #MMModem.
+ *
+ * Gets the index of the SAR power level mapping table.
+ *
+ * Returns: the index.
+ *
+ * Since: 1.20
+ */
+guint
+mm_modem_sar_get_power_level (MMModemSar *self)
+{
+ g_return_val_if_fail (MM_IS_MODEM_SAR (self), FALSE);
+
+ return mm_gdbus_modem_sar_get_power_level (MM_GDBUS_MODEM_SAR (self));
+}
+
+/*****************************************************************************/
+static void
+mm_modem_sar_init (MMModemSar *self)
+{
+}
+
+static void
+mm_modem_sar_class_init (MMModemSarClass *modem_class)
+{
+ /* Virtual methods */
+}
diff --git a/libmm-glib/mm-modem-sar.h b/libmm-glib/mm-modem-sar.h
new file mode 100644
index 00000000..d5784c99
--- /dev/null
+++ b/libmm-glib/mm-modem-sar.h
@@ -0,0 +1,104 @@
+/* -*- 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) 2021 Fibocom Wireless Inc.
+ */
+
+#ifndef _MM_MODEM_SAR_H_
+#define _MM_MODEM_SAR_H_
+
+#if !defined (__LIBMM_GLIB_H_INSIDE__) && !defined (LIBMM_GLIB_COMPILATION)
+#error "Only <libmm-glib.h> can be included directly."
+#endif
+
+#include <ModemManager.h>
+
+#include "mm-gdbus-modem.h"
+
+G_BEGIN_DECLS
+
+#define MM_TYPE_MODEM_SAR (mm_modem_sar_get_type ())
+#define MM_MODEM_SAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_SAR, MMModemSar))
+#define MM_MODEM_SAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_SAR, MMModemSarClass))
+#define MM_IS_MODEM_SAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_SAR))
+#define MM_IS_MODEM_SAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), MM_TYPE_MODEM_SAR))
+#define MM_MODEM_SAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_SAR, MMModemSarClass))
+
+typedef struct _MMModemSar MMModemSar;
+typedef struct _MMModemSarClass MMModemSarClass;
+
+/**
+ * MMModemSar:
+ *
+ * The #MMModemSar structure contains private data and should only be accessed
+ * using the provided API.
+ */
+struct _MMModemSar {
+ /*< private >*/
+ MmGdbusModemSarProxy parent;
+ gpointer unused;
+};
+
+struct _MMModemSarClass {
+ /*< private >*/
+ MmGdbusModemSarProxyClass parent;
+};
+
+GType mm_modem_sar_get_type (void);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (MMModemSar, g_object_unref)
+
+const gchar *mm_modem_sar_get_path (MMModemSar *self);
+gchar *mm_modem_sar_dup_path (MMModemSar *self);
+
+void mm_modem_sar_enable (MMModemSar *self,
+ gboolean enable,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+gboolean mm_modem_sar_enable_finish (MMModemSar *self,
+ GAsyncResult *res,
+ GError **error);
+
+gboolean mm_modem_sar_enable_sync (MMModemSar *self,
+ gboolean enable,
+ GCancellable *cancellable,
+ GError **error);
+
+void mm_modem_sar_set_power_level (MMModemSar *self,
+ guint level,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean mm_modem_sar_set_power_level_finish (MMModemSar *self,
+ GAsyncResult *res,
+ GError **error);
+
+gboolean mm_modem_sar_set_power_level_sync (MMModemSar *self,
+ guint level,
+ GCancellable *cancellable,
+ GError **error);
+
+gboolean mm_modem_sar_get_state (MMModemSar *self);
+guint mm_modem_sar_get_power_level (MMModemSar *self);
+
+
+G_END_DECLS
+
+#endif /* _MM_MODEM_SAR_H_ */
diff --git a/libmm-glib/mm-object.c b/libmm-glib/mm-object.c
index de446942..fd582292 100644
--- a/libmm-glib/mm-object.c
+++ b/libmm-glib/mm-object.c
@@ -596,6 +596,51 @@ mm_object_peek_modem_firmware (MMObject *self)
/*****************************************************************************/
/**
+ * mm_object_get_modem_sar:
+ * @self: A #MMObject.
+ *
+ * Gets the #MMModemSar instance for the D-Bus interface
+ * org.freedesktop.ModemManager1.Modem.Sar on @self, if any.
+ *
+ * Returns: (transfer full): A #MMModemSar that must be freed with
+ * g_object_unref() or %NULL if @self does not implement the interface.
+ *
+ * Since: 1.20
+ */
+MMModemSar *
+mm_object_get_modem_sar (MMObject *self)
+{
+ g_return_val_if_fail (MM_IS_OBJECT (MM_GDBUS_OBJECT (self)), NULL);
+
+ return (MMModemSar *)mm_gdbus_object_get_modem_sar (MM_GDBUS_OBJECT (self));
+}
+
+/**
+ * mm_object_peek_modem_sar: (skip)
+ * @self: A #MMObject.
+ *
+ * Like mm_object_get_modem_sar() 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 #MMModemSar or %NULL if @self does not
+ * implement the interface. Do not free the returned object, it is owned by
+ * @self.
+ *
+ * Since: 1.20
+ */
+MMModemSar *
+mm_object_peek_modem_sar (MMObject *self)
+{
+ g_return_val_if_fail (MM_IS_OBJECT (MM_GDBUS_OBJECT (self)), NULL);
+
+ return (MMModemSar *)mm_gdbus_object_peek_modem_sar (MM_GDBUS_OBJECT (self));
+}
+/*****************************************************************************/
+
+/**
* mm_object_get_modem_signal:
* @self: A #MMObject.
*
diff --git a/libmm-glib/mm-object.h b/libmm-glib/mm-object.h
index 817c6f32..f19c5208 100644
--- a/libmm-glib/mm-object.h
+++ b/libmm-glib/mm-object.h
@@ -42,6 +42,7 @@
#include "mm-modem-voice.h"
#include "mm-modem-time.h"
#include "mm-modem-firmware.h"
+#include "mm-modem-sar.h"
#include "mm-modem-signal.h"
#include "mm-modem-oma.h"
@@ -91,6 +92,7 @@ MMModemMessaging *mm_object_get_modem_messaging (MMObject
MMModemVoice *mm_object_get_modem_voice (MMObject *self);
MMModemTime *mm_object_get_modem_time (MMObject *self);
MMModemFirmware *mm_object_get_modem_firmware (MMObject *self);
+MMModemSar *mm_object_get_modem_sar (MMObject *self);
MMModemSignal *mm_object_get_modem_signal (MMObject *self);
MMModemOma *mm_object_get_modem_oma (MMObject *self);
@@ -105,6 +107,7 @@ MMModemMessaging *mm_object_peek_modem_messaging (MMObject
MMModemVoice *mm_object_peek_modem_voice (MMObject *self);
MMModemTime *mm_object_peek_modem_time (MMObject *self);
MMModemFirmware *mm_object_peek_modem_firmware (MMObject *self);
+MMModemSar *mm_object_peek_modem_sar (MMObject *self);
MMModemSignal *mm_object_peek_modem_signal (MMObject *self);
MMModemOma *mm_object_peek_modem_oma (MMObject *self);