aboutsummaryrefslogtreecommitdiff
path: root/libmm-glib
diff options
context:
space:
mode:
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/meson.build2
-rw-r--r--libmm-glib/mm-cell-info.c224
-rw-r--r--libmm-glib/mm-cell-info.h93
5 files changed, 323 insertions, 0 deletions
diff --git a/libmm-glib/Makefile.am b/libmm-glib/Makefile.am
index ff44074b..4fa050ee 100644
--- a/libmm-glib/Makefile.am
+++ b/libmm-glib/Makefile.am
@@ -101,6 +101,8 @@ libmm_glib_la_SOURCES = \
mm-signal-threshold-properties.c \
mm-nr5g-registration-settings.h \
mm-nr5g-registration-settings.c \
+ mm-cell-info.h \
+ mm-cell-info.c \
mm-compat.h \
mm-compat.c \
$(NULL)
@@ -180,6 +182,7 @@ include_HEADERS = \
mm-3gpp-profile.h \
mm-signal-threshold-properties.h \
mm-nr5g-registration-settings.h \
+ mm-cell-info.h \
mm-compat.h \
$(NULL)
diff --git a/libmm-glib/libmm-glib.h b/libmm-glib/libmm-glib.h
index fa47fa68..cf0e93f7 100644
--- a/libmm-glib/libmm-glib.h
+++ b/libmm-glib/libmm-glib.h
@@ -86,6 +86,7 @@
#include <mm-3gpp-profile.h>
#include <mm-signal-threshold-properties.h>
#include <mm-nr5g-registration-settings.h>
+#include <mm-cell-info.h>
#include <mm-compat.h>
/* generated */
diff --git a/libmm-glib/meson.build b/libmm-glib/meson.build
index 30500eca..1a906db2 100644
--- a/libmm-glib/meson.build
+++ b/libmm-glib/meson.build
@@ -16,6 +16,7 @@ headers = files(
'mm-call.h',
'mm-call-properties.h',
'mm-cdma-manual-activation-properties.h',
+ 'mm-cell-info.h',
'mm-compat.h',
'mm-firmware-properties.h',
'mm-firmware-update-settings.h',
@@ -71,6 +72,7 @@ sources = files(
'mm-call.c',
'mm-call-properties.c',
'mm-cdma-manual-activation-properties.c',
+ 'mm-cell-info.c',
'mm-common-helpers.c',
'mm-compat.c',
'mm-firmware-properties.c',
diff --git a/libmm-glib/mm-cell-info.c b/libmm-glib/mm-cell-info.c
new file mode 100644
index 00000000..e733c769
--- /dev/null
+++ b/libmm-glib/mm-cell-info.c
@@ -0,0 +1,224 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * libmm-glib -- 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) 2022 Aleksander Morgado <aleksander@aleksander.es>
+ */
+
+#include "mm-cell-info.h"
+
+#include "mm-enums-types.h"
+#include "mm-errors-types.h"
+
+/**
+ * SECTION: mm-cell-info
+ * @title: MMCellInfo
+ * @short_description: Helper base object to report cell info
+ *
+ * The #MMCellInfo is a base object used to report cell information.
+ *
+ * This object is retrieved from the #MMModem object with
+ * mm_modem_get_cell_info() or mm_modem_get_cell_info_sync().
+ */
+
+G_DEFINE_TYPE (MMCellInfo, mm_cell_info, G_TYPE_OBJECT)
+
+#define PROPERTY_CELL_TYPE "cell-type"
+#define PROPERTY_SERVING "serving"
+
+struct _MMCellInfoPrivate {
+ MMCellType cell_type;
+ gboolean serving;
+};
+
+/*****************************************************************************/
+
+static void
+ensure_cell_type (MMCellInfo *self)
+{
+ if (self->priv->cell_type != MM_CELL_TYPE_UNKNOWN)
+ return;
+
+ /* MM_CELL_TYPE_CDMA; */
+ /* MM_CELL_TYPE_GSM; */
+ /* MM_CELL_TYPE_UMTS; */
+ /* MM_CELL_TYPE_TDSCDMA; */
+ /* MM_CELL_TYPE_LTE; */
+ /* MM_CELL_TYPE_5GNR; */
+}
+
+/**
+ * mm_cell_info_get_cell_type:
+ * @self: a #MMCellInfo.
+ *
+ * Get the type of cell.
+ *
+ * Returns: a #MMCellType.
+ *
+ * Since: 1.20
+ */
+MMCellType
+mm_cell_info_get_cell_type (MMCellInfo *self)
+{
+ g_return_val_if_fail (MM_IS_CELL_INFO (self), MM_CELL_TYPE_UNKNOWN);
+
+ ensure_cell_type (self);
+
+ return self->priv->cell_type;
+}
+
+/**
+ * mm_cell_info_get_serving:
+ * @self: a #MMCellInfo.
+ *
+ * Get whether the cell is a serving cell or a neighboring cell.a
+ *
+ * Returns: %TRUE if the cell is a serving cell, %FALSE otherwise.
+ *
+ * Since: 1.20
+ */
+gboolean
+mm_cell_info_get_serving (MMCellInfo *self)
+{
+ g_return_val_if_fail (MM_IS_CELL_INFO (self), FALSE);
+
+ return self->priv->serving;
+}
+
+/**
+ * mm_cell_info_set_serving: (skip)
+ */
+void
+mm_cell_info_set_serving (MMCellInfo *self,
+ gboolean serving)
+{
+ g_return_if_fail (MM_IS_CELL_INFO (self));
+
+ self->priv->serving = serving;
+}
+
+/*****************************************************************************/
+
+/**
+ * mm_cell_info_get_dictionary: (skip)
+ */
+GVariant *
+mm_cell_info_get_dictionary (MMCellInfo *self)
+{
+ g_autoptr(GVariantDict) dict = NULL;
+
+ dict = MM_CELL_INFO_GET_CLASS (self)->get_dictionary (self);
+ g_assert (dict);
+
+ g_variant_dict_insert_value (dict, PROPERTY_SERVING, g_variant_new_boolean (self->priv->serving));
+ g_variant_dict_insert_value (dict, PROPERTY_CELL_TYPE, g_variant_new_uint32 (mm_cell_info_get_cell_type (self)));
+
+ return g_variant_ref_sink (g_variant_dict_end (dict));
+}
+
+/*****************************************************************************/
+
+/**
+ * mm_cell_info_new_from_dictionary: (skip)
+ */
+MMCellInfo *
+mm_cell_info_new_from_dictionary (GVariant *dictionary,
+ GError **error)
+{
+ g_autoptr(MMCellInfo) self = NULL;
+ g_autoptr(GVariantDict) dict = NULL;
+ GVariant *aux;
+
+ dict = g_variant_dict_new (dictionary);
+
+ aux = g_variant_dict_lookup_value (dict, PROPERTY_CELL_TYPE, G_VARIANT_TYPE_UINT32);
+ if (!aux) {
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS,
+ "missing '" PROPERTY_CELL_TYPE "' key in cell info");
+ return NULL;
+ }
+ switch (g_variant_get_uint32 (aux)) {
+ case MM_CELL_TYPE_CDMA:
+ case MM_CELL_TYPE_GSM:
+ case MM_CELL_TYPE_UMTS:
+ case MM_CELL_TYPE_TDSCDMA:
+ case MM_CELL_TYPE_LTE:
+ case MM_CELL_TYPE_5GNR:
+ default:
+ break;
+ }
+ g_variant_unref (aux);
+
+ if (!self) {
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS,
+ "unknown '" PROPERTY_CELL_TYPE "' key value in cell info");
+ return NULL;
+ }
+
+ aux = g_variant_dict_lookup_value (dict, PROPERTY_SERVING, G_VARIANT_TYPE_BOOLEAN);
+ if (aux) {
+ mm_cell_info_set_serving (self, g_variant_get_boolean (aux));
+ g_variant_unref (aux);
+ }
+
+ return g_steal_pointer (&self);
+}
+
+/*****************************************************************************/
+
+/**
+ * mm_cell_info_build_string: (skip)
+ */
+gchar *
+mm_cell_info_build_string (MMCellInfo *self)
+{
+ GString *str;
+ GString *substr;
+
+ substr = MM_CELL_INFO_GET_CLASS (self)->build_string (self);
+ g_assert (substr);
+
+ ensure_cell_type (self);
+
+ str = g_string_new (NULL);
+ g_string_append_printf (str, "cell type: %s, serving: %s",
+ mm_cell_type_get_string (self->priv->cell_type),
+ self->priv->serving ? "yes" : "no");
+ g_string_append_len (str, substr->str, (gssize)substr->len);
+
+ g_string_free (substr, TRUE);
+
+ return g_string_free (str, FALSE);
+}
+
+/*****************************************************************************/
+
+static void
+mm_cell_info_init (MMCellInfo *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, MM_TYPE_CELL_INFO, MMCellInfoPrivate);
+ self->priv->cell_type = MM_CELL_TYPE_UNKNOWN;
+}
+
+static void
+mm_cell_info_class_init (MMCellInfoClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (object_class, sizeof (MMCellInfoPrivate));
+}
diff --git a/libmm-glib/mm-cell-info.h b/libmm-glib/mm-cell-info.h
new file mode 100644
index 00000000..b41c677e
--- /dev/null
+++ b/libmm-glib/mm-cell-info.h
@@ -0,0 +1,93 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * libmm-glib -- 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) 2022 Aleksander Morgado <aleksander@aleksander.es>
+ */
+
+#ifndef MM_CELL_INFO_H
+#define MM_CELL_INFO_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 <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define MM_TYPE_CELL_INFO (mm_cell_info_get_type ())
+#define MM_CELL_INFO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_CELL_INFO, MMCellInfo))
+#define MM_CELL_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_CELL_INFO, MMCellInfoClass))
+#define MM_IS_CELL_INFO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_CELL_INFO))
+#define MM_IS_CELL_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_CELL_INFO))
+#define MM_CELL_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_CELL_INFO, MMCellInfoClass))
+
+typedef struct _MMCellInfo MMCellInfo;
+typedef struct _MMCellInfoClass MMCellInfoClass;
+typedef struct _MMCellInfoPrivate MMCellInfoPrivate;
+
+/**
+ * MMCellInfo:
+ *
+ * The #MMCellInfo structure contains private data and should only be
+ * accessed using the provided API.
+ */
+struct _MMCellInfo {
+ /*< private >*/
+ GObject parent;
+ MMCellInfoPrivate *priv;
+};
+
+struct _MMCellInfoClass {
+ /*< private >*/
+ GObjectClass parent;
+
+ GVariantDict * (* get_dictionary) (MMCellInfo *self);
+ GString * (* build_string) (MMCellInfo *self);
+
+ /* class padding */
+ gpointer padding [5];
+};
+
+GType mm_cell_info_get_type (void);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (MMCellInfo, g_object_unref)
+
+MMCellType mm_cell_info_get_cell_type (MMCellInfo *self);
+gboolean mm_cell_info_get_serving (MMCellInfo *self);
+
+/*****************************************************************************/
+/* ModemManager/libmm-glib/mmcli specific methods */
+
+#if defined (_LIBMM_INSIDE_MM) || \
+ defined (_LIBMM_INSIDE_MMCLI) || \
+ defined (LIBMM_GLIB_COMPILATION)
+
+void mm_cell_info_set_serving (MMCellInfo *self,
+ gboolean serving);
+GVariant *mm_cell_info_get_dictionary (MMCellInfo *self);
+MMCellInfo *mm_cell_info_new_from_dictionary (GVariant *dictionary,
+ GError **error);
+gchar *mm_cell_info_build_string (MMCellInfo *self);
+
+#endif
+
+G_END_DECLS
+
+#endif /* MM_CELL_INFO_H */