docs,libmm-glib: add SAR user-level api

This commit is contained in:
lvmaorui
2021-03-26 16:38:45 +08:00
committed by Aleksander Morgado
parent dbd95e30c4
commit 8e67d2375c
8 changed files with 490 additions and 0 deletions

View File

@@ -860,6 +860,33 @@ MM_TYPE_MODEM_SIMPLE
mm_modem_simple_get_type
</SECTION>
<SECTION>
<FILE>mm-modem-sar</FILE>
<TITLE>MMModemSar</TITLE>
MMModemSar
<SUBSECTION Getters>
mm_modem_sar_get_path
mm_modem_sar_dup_path
<SUBSECTION Methods>
mm_modem_sar_enable
mm_modem_sar_enable_finish
mm_modem_sar_enable_sync
mm_modem_sar_set_power_level
mm_modem_sar_set_power_level_finish
mm_modem_sar_set_power_level_sync
mm_modem_sar_get_state
mm_modem_sar_get_power_level
<SUBSECTION Standard>
MMModemSarClass
MM_IS_MODEM_SAR
MM_IS_MODEM_SAR_CLASS
MM_MODEM_SAR
MM_MODEM_SAR_CLASS
MM_MODEM_SAR_GET_CLASS
MM_TYPE_MODEM_SAR
mm_modem_sar_get_type
</SECTION>
<SECTION>
<FILE>mm-simple-connect-properties</FILE>
<TITLE>MMSimpleConnectProperties</TITLE>

View File

@@ -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 \

View File

@@ -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) || \

View File

@@ -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));

306
libmm-glib/mm-modem-sar.c Normal file
View File

@@ -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 */
}

104
libmm-glib/mm-modem-sar.h Normal file
View File

@@ -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_ */

View File

@@ -595,6 +595,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.

View File

@@ -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);