aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-03-05 11:43:37 +0100
committerAleksander Morgado <aleksander@lanedo.com>2012-03-16 14:53:20 +0100
commit455fc68d8ab2a003d743163f538e8e3de9558ea3 (patch)
tree855aac7a33da4413d32f05ea6ae74c2f7832a474
parentbd9d7011b9ecdd588b74f0948352a4822c8222da (diff)
libmm-common: new `MMNetworkTimezone' helper object
-rw-r--r--libmm-common/Makefile.am4
-rw-r--r--libmm-common/libmm-common.h1
-rw-r--r--libmm-common/mm-network-timezone.c216
-rw-r--r--libmm-common/mm-network-timezone.h68
4 files changed, 289 insertions, 0 deletions
diff --git a/libmm-common/Makefile.am b/libmm-common/Makefile.am
index 5a97112f..68d5642a 100644
--- a/libmm-common/Makefile.am
+++ b/libmm-common/Makefile.am
@@ -159,6 +159,7 @@ mm-bearer-ip-config.c: mm-errors-types.h
mm-location-3gpp.c: mm-errors-types.h
mm-errors-quarks.c: mm-errors-types.h
mm-unlock-retries.c: mm-enums-types.h
+mm-network-timezone.c: mm-errors-types.h
includedir = @includedir@/libmm-common
include_HEADERS = \
@@ -172,6 +173,7 @@ include_HEADERS = \
mm-bearer-ip-config.h \
mm-location-3gpp.h \
mm-unlock-retries.h \
+ mm-network-timezone.h \
mm-gdbus-manager.h \
mm-gdbus-modem.h \
mm-gdbus-bearer.h \
@@ -200,6 +202,8 @@ libmm_common_la_SOURCES = \
mm-location-3gpp.c \
mm-unlock-retries.h \
mm-unlock-retries.c \
+ mm-network-timezone.h \
+ mm-network-timezone.c \
libmm-common.h
libmm_common_la_CPPFLAGS = \
diff --git a/libmm-common/libmm-common.h b/libmm-common/libmm-common.h
index 0499f4b7..0dd3bab1 100644
--- a/libmm-common/libmm-common.h
+++ b/libmm-common/libmm-common.h
@@ -33,6 +33,7 @@
#include "mm-bearer-ip-config.h"
#include "mm-location-3gpp.h"
#include "mm-unlock-retries.h"
+#include "mm-network-timezone.h"
#include "mm-gdbus-manager.h"
#include "mm-gdbus-modem.h"
#include "mm-gdbus-bearer.h"
diff --git a/libmm-common/mm-network-timezone.c b/libmm-common/mm-network-timezone.c
new file mode 100644
index 00000000..dfb6914e
--- /dev/null
+++ b/libmm-common/mm-network-timezone.c
@@ -0,0 +1,216 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details:
+ *
+ * Copyright (C) 2012 Google, Inc.
+ */
+
+#include <string.h>
+
+#include "mm-errors-types.h"
+#include "mm-network-timezone.h"
+
+G_DEFINE_TYPE (MMNetworkTimezone, mm_network_timezone, G_TYPE_OBJECT);
+
+struct _MMNetworkTimezonePrivate {
+ gint32 offset;
+ gint32 dst_offset;
+ gint32 leap_seconds;
+};
+
+/*****************************************************************************/
+
+gint
+mm_network_timezone_get_offset (MMNetworkTimezone *self)
+{
+ g_return_val_if_fail (MM_IS_NETWORK_TIMEZONE (self),
+ MM_NETWORK_TIMEZONE_OFFSET_UNKNOWN);
+
+ return self->priv->offset;
+}
+
+gint
+mm_network_timezone_get_dst_offset (MMNetworkTimezone *self)
+{
+ g_return_val_if_fail (MM_IS_NETWORK_TIMEZONE (self),
+ MM_NETWORK_TIMEZONE_OFFSET_UNKNOWN);
+
+ return self->priv->dst_offset;
+}
+
+gint
+mm_network_timezone_get_leap_seconds (MMNetworkTimezone *self)
+{
+ g_return_val_if_fail (MM_IS_NETWORK_TIMEZONE (self),
+ MM_NETWORK_TIMEZONE_LEAP_SECONDS_UNKNOWN);
+
+ return self->priv->leap_seconds;
+}
+
+/*****************************************************************************/
+
+void
+mm_network_timezone_set_offset (MMNetworkTimezone *self,
+ gint offset)
+{
+ g_return_if_fail (MM_IS_NETWORK_TIMEZONE (self));
+
+ self->priv->offset = offset;
+}
+
+void
+mm_network_timezone_set_dst_offset (MMNetworkTimezone *self,
+ gint dst_offset)
+{
+ g_return_if_fail (MM_IS_NETWORK_TIMEZONE (self));
+
+ self->priv->dst_offset = dst_offset;
+}
+
+void
+mm_network_timezone_set_leap_seconds (MMNetworkTimezone *self,
+ gint leap_seconds)
+{
+ g_return_if_fail (MM_IS_NETWORK_TIMEZONE (self));
+
+ self->priv->leap_seconds = leap_seconds;
+}
+
+/*****************************************************************************/
+
+GVariant *
+mm_network_timezone_get_dictionary (MMNetworkTimezone *self)
+{
+ GVariantBuilder builder;
+
+ /* Allow NULL */
+ if (!self)
+ return NULL;
+
+ g_return_val_if_fail (MM_IS_NETWORK_TIMEZONE (self), NULL);
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
+
+ if (self->priv->offset != MM_NETWORK_TIMEZONE_OFFSET_UNKNOWN)
+ g_variant_builder_add (&builder,
+ "{sv}",
+ "offset",
+ g_variant_new_int32 (self->priv->offset));
+
+ if (self->priv->dst_offset != MM_NETWORK_TIMEZONE_OFFSET_UNKNOWN)
+ g_variant_builder_add (&builder,
+ "{sv}",
+ "dst-offset",
+ g_variant_new_int32 (self->priv->dst_offset));
+
+ if (self->priv->leap_seconds != MM_NETWORK_TIMEZONE_LEAP_SECONDS_UNKNOWN)
+ g_variant_builder_add (&builder,
+ "{sv}",
+ "leap-seconds",
+ g_variant_new_int32 (self->priv->leap_seconds));
+
+ return g_variant_ref_sink (g_variant_builder_end (&builder));
+}
+
+/*****************************************************************************/
+
+MMNetworkTimezone *
+mm_network_timezone_new_from_dictionary (GVariant *dictionary,
+ GError **error)
+{
+ GError *inner_error = NULL;
+ GVariantIter iter;
+ gchar *key;
+ GVariant *value;
+ MMNetworkTimezone *self;
+
+ self = mm_network_timezone_new ();
+ if (!dictionary)
+ return self;
+
+ if (!g_variant_is_of_type (dictionary, G_VARIANT_TYPE ("a{sv}"))) {
+ g_set_error (error,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_INVALID_ARGS,
+ "Cannot create Network Timezone from dictionary: "
+ "invalid variant type received");
+ g_object_unref (self);
+ return NULL;
+ }
+
+ g_variant_iter_init (&iter, dictionary);
+ while (!inner_error &&
+ g_variant_iter_next (&iter, "{sv}", &key, &value)) {
+ /* All currently supported properties are signed integers,
+ * so we just check the value type here */
+ if (!g_variant_is_of_type (value, G_VARIANT_TYPE_INT32)) {
+ /* Set inner error, will stop the loop */
+ inner_error = g_error_new (MM_CORE_ERROR,
+ MM_CORE_ERROR_INVALID_ARGS,
+ "Invalid status dictionary, unexpected value type '%s'",
+ g_variant_get_type_string (value));
+ } else if (g_str_equal (key, "offset"))
+ self->priv->offset = g_variant_get_int32 (value);
+ else if (g_str_equal (key, "dst-offset"))
+ self->priv->dst_offset = g_variant_get_int32 (value);
+ else if (g_str_equal (key, "leap-seconds"))
+ self->priv->leap_seconds = g_variant_get_int32 (value);
+ else {
+ /* Set inner error, will stop the loop */
+ inner_error = g_error_new (MM_CORE_ERROR,
+ MM_CORE_ERROR_INVALID_ARGS,
+ "Invalid status dictionary, unexpected key '%s'",
+ key);
+ }
+
+ g_free (key);
+ g_variant_unref (value);
+ }
+
+ /* If error, destroy the object */
+ if (inner_error) {
+ g_propagate_error (error, inner_error);
+ g_object_unref (self);
+ return NULL;
+ }
+
+ return self;
+}
+
+/*****************************************************************************/
+
+MMNetworkTimezone *
+mm_network_timezone_new (void)
+{
+ return (MM_NETWORK_TIMEZONE (
+ g_object_new (MM_TYPE_NETWORK_TIMEZONE, NULL)));
+}
+
+static void
+mm_network_timezone_init (MMNetworkTimezone *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self),
+ MM_TYPE_NETWORK_TIMEZONE,
+ MMNetworkTimezonePrivate);
+
+ /* Some defaults */
+ self->priv->offset = MM_NETWORK_TIMEZONE_OFFSET_UNKNOWN;
+ self->priv->dst_offset = MM_NETWORK_TIMEZONE_OFFSET_UNKNOWN;
+ self->priv->leap_seconds = MM_NETWORK_TIMEZONE_LEAP_SECONDS_UNKNOWN;
+}
+
+static void
+mm_network_timezone_class_init (MMNetworkTimezoneClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (object_class, sizeof (MMNetworkTimezonePrivate));
+}
diff --git a/libmm-common/mm-network-timezone.h b/libmm-common/mm-network-timezone.h
new file mode 100644
index 00000000..2c27fe00
--- /dev/null
+++ b/libmm-common/mm-network-timezone.h
@@ -0,0 +1,68 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details:
+ *
+ * Copyright (C) 2012 Google, Inc.
+ */
+
+#ifndef MM_NETWORK_TIMEZONE_H
+#define MM_NETWORK_TIMEZONE_H
+
+#include <ModemManager.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define MM_TYPE_NETWORK_TIMEZONE (mm_network_timezone_get_type ())
+#define MM_NETWORK_TIMEZONE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_NETWORK_TIMEZONE, MMNetworkTimezone))
+#define MM_NETWORK_TIMEZONE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_NETWORK_TIMEZONE, MMNetworkTimezoneClass))
+#define MM_IS_NETWORK_TIMEZONE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_NETWORK_TIMEZONE))
+#define MM_IS_NETWORK_TIMEZONE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_NETWORK_TIMEZONE))
+#define MM_NETWORK_TIMEZONE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_NETWORK_TIMEZONE, MMNetworkTimezoneClass))
+
+#define MM_NETWORK_TIMEZONE_OFFSET_UNKNOWN G_MAXINT32
+#define MM_NETWORK_TIMEZONE_LEAP_SECONDS_UNKNOWN G_MAXINT32
+
+typedef struct _MMNetworkTimezone MMNetworkTimezone;
+typedef struct _MMNetworkTimezoneClass MMNetworkTimezoneClass;
+typedef struct _MMNetworkTimezonePrivate MMNetworkTimezonePrivate;
+
+struct _MMNetworkTimezone {
+ GObject parent;
+ MMNetworkTimezonePrivate *priv;
+};
+
+struct _MMNetworkTimezoneClass {
+ GObjectClass parent;
+};
+
+GType mm_network_timezone_get_type (void);
+
+MMNetworkTimezone *mm_network_timezone_new (void);
+MMNetworkTimezone *mm_network_timezone_new_from_dictionary (GVariant *dictionary,
+ GError **error);
+
+gint32 mm_network_timezone_get_offset (MMNetworkTimezone *self);
+gint32 mm_network_timezone_get_dst_offset (MMNetworkTimezone *self);
+gint32 mm_network_timezone_get_leap_seconds (MMNetworkTimezone *self);
+
+void mm_network_timezone_set_offset (MMNetworkTimezone *self,
+ gint offset);
+void mm_network_timezone_set_dst_offset (MMNetworkTimezone *self,
+ gint dst_offset);
+void mm_network_timezone_set_leap_seconds (MMNetworkTimezone *self,
+ gint leap_seconds);
+
+GVariant *mm_network_timezone_get_dictionary (MMNetworkTimezone *self);
+
+G_END_DECLS
+
+#endif /* MM_NETWORK_TIMEZONE_H */