diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-01-18 10:41:26 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-15 14:14:52 +0100 |
commit | b05430cb289e058ec118be13e4b0a813c46b1fb2 (patch) | |
tree | 0417eb6c06e7267229629b9a383a3e47aceb8e09 | |
parent | 3b443b6954046cb7cc1c7576a3720af0b987d573 (diff) |
libmm-glib: include support for the Location interface
We hide the location signaling; not sure if we should even support it.
-rw-r--r-- | libmm-glib/Makefile.am | 4 | ||||
-rw-r--r-- | libmm-glib/mm-modem-location-3gpp.c | 48 | ||||
-rw-r--r-- | libmm-glib/mm-modem-location-3gpp.h | 45 | ||||
-rw-r--r-- | libmm-glib/mm-modem-location.c | 238 | ||||
-rw-r--r-- | libmm-glib/mm-modem-location.h | 78 | ||||
-rw-r--r-- | libmm-glib/mm-object.c | 34 | ||||
-rw-r--r-- | libmm-glib/mm-object.h | 3 |
7 files changed, 450 insertions, 0 deletions
diff --git a/libmm-glib/Makefile.am b/libmm-glib/Makefile.am index f11240aa..ae890596 100644 --- a/libmm-glib/Makefile.am +++ b/libmm-glib/Makefile.am @@ -28,6 +28,10 @@ libmm_glib_la_SOURCES = \ mm-modem-simple-status-properties.c \ mm-modem-simple.h \ mm-modem-simple.c \ + mm-modem-location-3gpp.h \ + mm-modem-location-3gpp.c \ + mm-modem-location.h \ + mm-modem-location.c \ mm-sim.h \ mm-sim.c \ mm-bearer-properties.h \ diff --git a/libmm-glib/mm-modem-location-3gpp.c b/libmm-glib/mm-modem-location-3gpp.c new file mode 100644 index 00000000..af090889 --- /dev/null +++ b/libmm-glib/mm-modem-location-3gpp.c @@ -0,0 +1,48 @@ +/* -*- 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 "mm-modem-location-3gpp.h" + +guint +mm_modem_location_3gpp_get_mobile_country_code (MMModemLocation3gpp *self) +{ + g_return_val_if_fail (MM_IS_COMMON_LOCATION_3GPP (self), 0); + + return mm_common_location_3gpp_get_mobile_country_code (self); +} + +guint +mm_modem_location_3gpp_get_mobile_network_code (MMModemLocation3gpp *self) +{ + g_return_val_if_fail (MM_IS_COMMON_LOCATION_3GPP (self), 0); + + return mm_common_location_3gpp_get_mobile_network_code (self); +} + +gulong +mm_modem_location_3gpp_get_location_area_code (MMModemLocation3gpp *self) +{ + g_return_val_if_fail (MM_IS_COMMON_LOCATION_3GPP (self), 0); + + return mm_common_location_3gpp_get_location_area_code (self); +} + +gulong +mm_modem_location_3gpp_get_cell_id (MMModemLocation3gpp *self) +{ + g_return_val_if_fail (MM_IS_COMMON_LOCATION_3GPP (self), 0); + + return mm_common_location_3gpp_get_cell_id (self); +} diff --git a/libmm-glib/mm-modem-location-3gpp.h b/libmm-glib/mm-modem-location-3gpp.h new file mode 100644 index 00000000..869799cb --- /dev/null +++ b/libmm-glib/mm-modem-location-3gpp.h @@ -0,0 +1,45 @@ +/* -*- 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) 2012 Google, Inc. + */ + +#ifndef _MM_MODEM_LOCATION_3GPP_H_ +#define _MM_MODEM_LOCATION_3GPP_H_ + +#include <ModemManager.h> +#include <glib-object.h> + +#include <libmm-common.h> + +G_BEGIN_DECLS + +typedef MMCommonLocation3gpp MMModemLocation3gpp; +#define MM_TYPE_MODEM_LOCATION_3GPP(o) MM_TYPE_LOCATION_3GPP (o) +#define MM_MODEM_LOCATION_3GPP(o) MM_LOCATION_3GPP(o) +#define MM_IS_MODEM_LOCATION_3GPP(o) MM_IS_LOCATION_3GPP(o) + +guint mm_modem_location_3gpp_get_mobile_country_code (MMModemLocation3gpp *self); +guint mm_modem_location_3gpp_get_mobile_network_code (MMModemLocation3gpp *self); +gulong mm_modem_location_3gpp_get_location_area_code (MMModemLocation3gpp *self); +gulong mm_modem_location_3gpp_get_cell_id (MMModemLocation3gpp *self); + +G_END_DECLS + +#endif /* _MM_MODEM_LOCATION_3GPP_H_ */ diff --git a/libmm-glib/mm-modem-location.c b/libmm-glib/mm-modem-location.c new file mode 100644 index 00000000..1f2bdbb7 --- /dev/null +++ b/libmm-glib/mm-modem-location.c @@ -0,0 +1,238 @@ +/* -*- 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) 2012 Google, Inc. + */ + +#include <gio/gio.h> + +#include "mm-helpers.h" +#include "mm-modem-location.h" + +/** + * mm_modem_location_get_path: + * @self: A #MMModemLocation. + * + * Gets the DBus path of the #MMObject which implements this interface. + * + * Returns: (transfer none): The DBus path of the #MMObject object. + */ +const gchar * +mm_modem_location_get_path (MMModemLocation *self) +{ + g_return_val_if_fail (G_IS_DBUS_PROXY (self), NULL); + + RETURN_NON_EMPTY_CONSTANT_STRING ( + g_dbus_proxy_get_object_path (G_DBUS_PROXY (self))); +} + +/** + * mm_modem_location_dup_path: + * @self: A #MMModemLocation. + * + * 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(). + */ +gchar * +mm_modem_location_dup_path (MMModemLocation *self) +{ + gchar *value; + + g_return_val_if_fail (G_IS_DBUS_PROXY (self), NULL); + + g_object_get (G_OBJECT (self), + "g-object-path", &value, + NULL); + RETURN_NON_EMPTY_STRING (value); +} + +MMModemLocationSource +mm_modem_location_get_capabilities (MMModemLocation *self) +{ + g_return_val_if_fail (MM_GDBUS_IS_MODEM_LOCATION (self), + MM_MODEM_LOCATION_SOURCE_NONE); + + return (MMModemLocationSource) mm_gdbus_modem_location_get_capabilities (self); +} + +gboolean +mm_modem_location_get_enabled (MMModemLocation *self) +{ + g_return_val_if_fail (MM_GDBUS_IS_MODEM_LOCATION (self), FALSE); + + return mm_gdbus_modem_location_get_enabled (self); +} + +gboolean +mm_modem_location_disable_finish (MMModemLocation *self, + GAsyncResult *res, + GError **error) +{ + g_return_val_if_fail (MM_GDBUS_IS_MODEM_LOCATION (self), FALSE); + + return mm_gdbus_modem_location_call_enable_finish (self, res, error); +} + +void +mm_modem_location_disable (MMModemLocation *self, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + g_return_if_fail (MM_GDBUS_IS_MODEM_LOCATION (self)); + + mm_gdbus_modem_location_call_enable (self, + FALSE, + FALSE, + cancellable, + callback, + user_data); +} + +gboolean +mm_modem_location_disable_sync (MMModemLocation *self, + GCancellable *cancellable, + GError **error) +{ + g_return_val_if_fail (MM_GDBUS_IS_MODEM_LOCATION (self), FALSE); + + return mm_gdbus_modem_location_call_enable_sync (self, + FALSE, + FALSE, + cancellable, + error); +} + +gboolean +mm_modem_location_enable_finish (MMModemLocation *self, + GAsyncResult *res, + GError **error) +{ + g_return_val_if_fail (MM_GDBUS_IS_MODEM_LOCATION (self), FALSE); + + return mm_gdbus_modem_location_call_enable_finish (self, res, error); +} + +void +mm_modem_location_enable (MMModemLocation *self, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + g_return_if_fail (MM_GDBUS_IS_MODEM_LOCATION (self)); + + mm_gdbus_modem_location_call_enable (self, + TRUE, + FALSE /* signal_location */, + cancellable, + callback, + user_data); +} + +gboolean +mm_modem_location_enable_sync (MMModemLocation *self, + GCancellable *cancellable, + GError **error) +{ + g_return_val_if_fail (MM_GDBUS_IS_MODEM_LOCATION (self), FALSE); + + return mm_gdbus_modem_location_call_enable_sync (self, + TRUE, + FALSE /* signal_location */, + cancellable, + error); +} + +static MMModemLocation3gpp * +build_3gpp_location (GVariant *dictionary, + GError **error) +{ + MMCommonLocation3gpp *location = NULL; + GError *inner_error = NULL; + GVariant *value; + guint source; + GVariantIter iter; + + if (!dictionary) + return NULL; + + g_variant_iter_init (&iter, dictionary); + while (!location && + !inner_error && + g_variant_iter_next (&iter, "{uv}", &source, &value)) { + /* If we have 3GPP LAC/CI location, build result */ + if (source == MM_MODEM_LOCATION_SOURCE_3GPP_LAC_CI) + location = mm_common_location_3gpp_new_from_string_variant (value, &inner_error); + + g_variant_unref (value); + } + + g_variant_unref (dictionary); + + if (inner_error) + g_propagate_error (error, inner_error); + + return (MMModemLocation3gpp *)location; +} + +MMModemLocation3gpp * +mm_modem_location_get_3gpp_finish (MMModemLocation *self, + GAsyncResult *res, + GError **error) +{ + + GVariant *dictionary = NULL; + + g_return_val_if_fail (MM_GDBUS_IS_MODEM_LOCATION (self), NULL); + + if (!mm_gdbus_modem_location_call_get_location_finish (self, &dictionary, res, error)) + return NULL; + + return build_3gpp_location (dictionary, error); +} + +void +mm_modem_location_get_3gpp (MMModemLocation *self, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + g_return_if_fail (MM_GDBUS_IS_MODEM_LOCATION (self)); + + mm_gdbus_modem_location_call_get_location (self, + cancellable, + callback, + user_data); +} + +MMModemLocation3gpp * +mm_modem_location_get_3gpp_sync (MMModemLocation *self, + GCancellable *cancellable, + GError **error) +{ + GVariant *dictionary = NULL; + + g_return_val_if_fail (MM_GDBUS_IS_MODEM_LOCATION (self), NULL); + + if (!mm_gdbus_modem_location_call_get_location_sync (self, &dictionary, cancellable, error)) + return NULL; + + return build_3gpp_location (dictionary, error); +} diff --git a/libmm-glib/mm-modem-location.h b/libmm-glib/mm-modem-location.h new file mode 100644 index 00000000..2c93cb45 --- /dev/null +++ b/libmm-glib/mm-modem-location.h @@ -0,0 +1,78 @@ +/* -*- 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) 2012 Google, Inc. + */ + +#ifndef _MM_MODEM_LOCATION_H_ +#define _MM_MODEM_LOCATION_H_ + +#include <ModemManager.h> +#include <mm-gdbus-modem.h> + +#include "mm-modem-location-3gpp.h" + +G_BEGIN_DECLS + +typedef MmGdbusModemLocation MMModemLocation; +#define MM_TYPE_MODEM_LOCATION(o) MM_GDBUS_TYPE_MODEM_LOCATION (o) +#define MM_MODEM_LOCATION(o) MM_GDBUS_MODEM_LOCATION(o) +#define MM_IS_MODEM_LOCATION(o) MM_GDBUS_IS_MODEM_LOCATION(o) + +const gchar *mm_modem_location_get_path (MMModemLocation *self); +gchar *mm_modem_location_dup_path (MMModemLocation *self); + +MMModemLocationSource mm_modem_location_get_capabilities (MMModemLocation *self); +gboolean mm_modem_location_get_enabled (MMModemLocation *self); + +void mm_modem_location_enable (MMModemLocation *self, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean mm_modem_location_enable_finish (MMModemLocation *self, + GAsyncResult *res, + GError **error); +gboolean mm_modem_location_enable_sync (MMModemLocation *self, + GCancellable *cancellable, + GError **error); + +void mm_modem_location_disable (MMModemLocation *self, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean mm_modem_location_disable_finish (MMModemLocation *self, + GAsyncResult *res, + GError **error); +gboolean mm_modem_location_disable_sync (MMModemLocation *self, + GCancellable *cancellable, + GError **error); + +void mm_modem_location_get_3gpp (MMModemLocation *self, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +MMModemLocation3gpp *mm_modem_location_get_3gpp_finish (MMModemLocation *self, + GAsyncResult *res, + GError **error); +MMModemLocation3gpp *mm_modem_location_get_3gpp_sync (MMModemLocation *self, + GCancellable *cancellable, + GError **error); +G_END_DECLS + +#endif /* _MM_MODEM_LOCATION_H_ */ diff --git a/libmm-glib/mm-object.c b/libmm-glib/mm-object.c index ea924370..c9ad5be8 100644 --- a/libmm-glib/mm-object.c +++ b/libmm-glib/mm-object.c @@ -125,6 +125,22 @@ mm_object_get_modem_simple (MMObject *object) } /** + * mm_object_get_modem_location: + * @object: A #MMObject. + * + * Gets the #MMModemLocation instance for the D-Bus interface <link linkend="gdbus-interface-org-freedesktop-ModemManager1-Modem-Modemlocation.top_of_page">org.freedesktop.ModemManager1.Modem.Modemlocation</link> on @object, if any. + * + * Returns: (transfer full): A #MMModemLocation that must be freed with g_object_unref() or %NULL if @object does not implement the interface. + */ +MMModemLocation * +mm_object_get_modem_location (MMObject *object) +{ + g_return_val_if_fail (MM_GDBUS_IS_OBJECT (object), NULL); + + return mm_gdbus_object_get_modem_location (object); +} + +/** * mm_object_peek_modem: (skip) * @object: A #MMObject. * @@ -177,3 +193,21 @@ mm_object_peek_modem_simple (MMObject *object) return mm_gdbus_object_peek_modem_simple (object); } + +/** + * mm_object_peek_modem_location: (skip) + * @object: A #MMObject. + * + * Like mm_object_get_modem_location() 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 #MMModemLocation or %NULL if @object does not implement the interface. Do not free the returned object, it is owned by @object. + */ +MMModemLocation * +mm_object_peek_modem_location (MMObject *object) +{ + g_return_val_if_fail (MM_GDBUS_IS_OBJECT (object), NULL); + + return mm_gdbus_object_peek_modem_location (object); +} diff --git a/libmm-glib/mm-object.h b/libmm-glib/mm-object.h index 54796455..72aed9d6 100644 --- a/libmm-glib/mm-object.h +++ b/libmm-glib/mm-object.h @@ -30,6 +30,7 @@ #include "mm-modem-3gpp.h" #include "mm-modem-cdma.h" #include "mm-modem-simple.h" +#include "mm-modem-location.h" G_BEGIN_DECLS @@ -45,11 +46,13 @@ MMModem *mm_object_get_modem (MMObject *object); MMModem3gpp *mm_object_get_modem_3gpp (MMObject *object); MMModemCdma *mm_object_get_modem_cdma (MMObject *object); MMModemSimple *mm_object_get_modem_simple (MMObject *object); +MMModemLocation *mm_object_get_modem_location (MMObject *object); MMModem *mm_object_peek_modem (MMObject *object); MMModem3gpp *mm_object_peek_modem_3gpp (MMObject *object); MMModemCdma *mm_object_peek_modem_cdma (MMObject *object); MMModemSimple *mm_object_peek_modem_simple (MMObject *object); +MMModemLocation *mm_object_peek_modem_location (MMObject *object); G_END_DECLS |