libmm-glib,firmware: new `MMModemFirmware' type to handle the Firmware interface

This commit is contained in:
Aleksander Morgado
2012-10-02 11:37:01 +02:00
parent a795772e3d
commit 715a775949
7 changed files with 514 additions and 1 deletions

View File

@@ -63,6 +63,7 @@
<xi:include href="xml/mm-modem-location.xml"/> <xi:include href="xml/mm-modem-location.xml"/>
<xi:include href="xml/mm-modem-messaging.xml"/> <xi:include href="xml/mm-modem-messaging.xml"/>
<xi:include href="xml/mm-modem-time.xml"/> <xi:include href="xml/mm-modem-time.xml"/>
<xi:include href="xml/mm-modem-firmware.xml"/>
<xi:include href="xml/mm-modem-simple.xml"/> <xi:include href="xml/mm-modem-simple.xml"/>
</chapter> </chapter>

View File

@@ -30,6 +30,8 @@ libmm_glib_la_SOURCES = \
mm-modem-location.c \ mm-modem-location.c \
mm-modem-time.h \ mm-modem-time.h \
mm-modem-time.c \ mm-modem-time.c \
mm-modem-firmware.h \
mm-modem-firmware.c \
mm-sim.h \ mm-sim.h \
mm-sim.c \ mm-sim.c \
mm-sms.h \ mm-sms.h \
@@ -55,6 +57,7 @@ include_HEADERS = \
mm-modem-messaging.h \ mm-modem-messaging.h \
mm-modem-location.h \ mm-modem-location.h \
mm-modem-time.h \ mm-modem-time.h \
mm-modem-firmware.h \
mm-modem-simple.h \ mm-modem-simple.h \
mm-sim.h \ mm-sim.h \
mm-sms.h \ mm-sms.h \

View File

@@ -76,7 +76,7 @@ get_proxy_type (GDBusObjectManagerClient *manager,
g_hash_table_insert (lookup_hash, "org.freedesktop.ModemManager1.Modem.Messaging", GSIZE_TO_POINTER (MM_TYPE_MODEM_MESSAGING)); g_hash_table_insert (lookup_hash, "org.freedesktop.ModemManager1.Modem.Messaging", GSIZE_TO_POINTER (MM_TYPE_MODEM_MESSAGING));
g_hash_table_insert (lookup_hash, "org.freedesktop.ModemManager1.Modem.Location", GSIZE_TO_POINTER (MM_TYPE_MODEM_LOCATION)); g_hash_table_insert (lookup_hash, "org.freedesktop.ModemManager1.Modem.Location", GSIZE_TO_POINTER (MM_TYPE_MODEM_LOCATION));
g_hash_table_insert (lookup_hash, "org.freedesktop.ModemManager1.Modem.Time", GSIZE_TO_POINTER (MM_TYPE_MODEM_TIME)); g_hash_table_insert (lookup_hash, "org.freedesktop.ModemManager1.Modem.Time", GSIZE_TO_POINTER (MM_TYPE_MODEM_TIME));
g_hash_table_insert (lookup_hash, "org.freedesktop.ModemManager1.Modem.Firmware", GSIZE_TO_POINTER (MM_GDBUS_TYPE_MODEM_FIRMWARE_PROXY)); g_hash_table_insert (lookup_hash, "org.freedesktop.ModemManager1.Modem.Firmware", GSIZE_TO_POINTER (MM_TYPE_MODEM_FIRMWARE));
g_hash_table_insert (lookup_hash, "org.freedesktop.ModemManager1.Modem.Contacts", GSIZE_TO_POINTER (MM_GDBUS_TYPE_MODEM_CONTACTS_PROXY)); g_hash_table_insert (lookup_hash, "org.freedesktop.ModemManager1.Modem.Contacts", GSIZE_TO_POINTER (MM_GDBUS_TYPE_MODEM_CONTACTS_PROXY));
g_hash_table_insert (lookup_hash, "org.freedesktop.ModemManager1.Modem.ModemCdma", GSIZE_TO_POINTER (MM_TYPE_MODEM_CDMA)); g_hash_table_insert (lookup_hash, "org.freedesktop.ModemManager1.Modem.ModemCdma", GSIZE_TO_POINTER (MM_TYPE_MODEM_CDMA));
g_hash_table_insert (lookup_hash, "org.freedesktop.ModemManager1.Modem.Modem3gpp", GSIZE_TO_POINTER (MM_TYPE_MODEM_3GPP)); g_hash_table_insert (lookup_hash, "org.freedesktop.ModemManager1.Modem.Modem3gpp", GSIZE_TO_POINTER (MM_TYPE_MODEM_3GPP));

View File

@@ -0,0 +1,377 @@
/* -*- 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.
* Copyright (C) 2012 Lanedo GmbH <aleksander@lanedo.com>
*/
#include <gio/gio.h>
#include "mm-helpers.h"
#include "mm-modem-firmware.h"
/**
* SECTION: mm-modem-firmware
* @title: MMModemFirmware
* @short_description: The Firmware interface
*
* The #MMModemFirmware is an object providing access to the methods, signals and
* properties of the Firmware interface.
*
* The Firmware interface is exposed whenever a modem has firmware capabilities.
*/
G_DEFINE_TYPE (MMModemFirmware, mm_modem_firmware, MM_GDBUS_TYPE_MODEM_FIRMWARE_PROXY)
/*****************************************************************************/
/**
* mm_modem_firmware_get_path:
* @self: A #MMModemFirmware.
*
* 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_firmware_get_path (MMModemFirmware *self)
{
g_return_val_if_fail (MM_IS_MODEM_FIRMWARE (self), NULL);
RETURN_NON_EMPTY_CONSTANT_STRING (
g_dbus_proxy_get_object_path (G_DBUS_PROXY (self)));
}
/**
* mm_modem_firmware_dup_path:
* @self: A #MMModemFirmware.
*
* 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_firmware_dup_path (MMModemFirmware *self)
{
gchar *value;
g_return_val_if_fail (MM_IS_MODEM_FIRMWARE (self), NULL);
g_object_get (G_OBJECT (self),
"g-object-path", &value,
NULL);
RETURN_NON_EMPTY_STRING (value);
}
/*****************************************************************************/
/**
* mm_modem_firmware_select_finish:
* @self: A #MMModemFirmware.
* @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to mm_modem_firmware_select().
* @error: Return location for error or %NULL.
*
* Finishes an operation started with mm_modem_firmware_select().
*
* Returns: %TRUE if the selection was successful, %FALSE if @error is set.
*/
gboolean
mm_modem_firmware_select_finish (MMModemFirmware *self,
GAsyncResult *res,
GError **error)
{
g_return_val_if_fail (MM_IS_MODEM_FIRMWARE (self), FALSE);
return mm_gdbus_modem_firmware_call_select_finish (MM_GDBUS_MODEM_FIRMWARE (self), res, error);
}
/**
* mm_modem_firmware_select:
* @self: A #MMModemFirmware.
* @name: Unique name of the firmware image to select.
* @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 selects a firmware image to boot.
*
* <warning>The modem will possibly disappear once this action is run, as it
* needs to reboot in order to select the new image.</warning>
*
* 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_firmware_select_finish() to get the result of the operation.
*
* See mm_modem_firmware_select_sync() for the synchronous, blocking version of this method.
*/
void
mm_modem_firmware_select (MMModemFirmware *self,
const gchar *name,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_FIRMWARE (self));
g_return_if_fail (name != NULL || name[0] == '\0');
mm_gdbus_modem_firmware_call_select (MM_GDBUS_MODEM_FIRMWARE (self), name, cancellable, callback, user_data);
}
/**
* mm_modem_firmware_select_sync:
* @self: A #MMModemFirmware.
* @name: Unique name of the firmware image to select.
* @cancellable: (allow-none): A #GCancellable or %NULL.
* @error: Return location for error or %NULL.
*
* Synchronously selects a firmware image to boot.
*
* <warning>The modem will possibly disappear once this action is run, as it
* needs to reboot in order to select the new image.</warning>
*
* The calling thread is blocked until a reply is received. See mm_modem_firmware_select()
* for the asynchronous version of this method.
*
* Returns: %TRUE if the selection was successful, %FALSE if @error is set.
*/
gboolean
mm_modem_firmware_select_sync (MMModemFirmware *self,
const gchar *name,
GCancellable *cancellable,
GError **error)
{
g_return_val_if_fail (MM_IS_MODEM_FIRMWARE (self), FALSE);
g_return_val_if_fail (name != NULL || name[0] == '\0', FALSE);
return mm_gdbus_modem_firmware_call_select_sync (MM_GDBUS_MODEM_FIRMWARE (self), name, cancellable, error);
}
/*****************************************************************************/
static gboolean
build_results (const gchar *str_selected,
GVariant *dictionaries_installed,
MMFirmwareProperties **selected,
GList **installed,
GError **error)
{
GError *saved_error = NULL;
GVariantIter iter;
guint n;
g_assert (selected != NULL);
g_assert (installed != NULL);
*installed = NULL;
*selected = NULL;
if (!dictionaries_installed) {
if (str_selected) {
g_set_error (error,
MM_CORE_ERROR,
MM_CORE_ERROR_INVALID_ARGS,
"Selected image specified but no installed images listed");
return FALSE;
}
/* Nothing else to do */
return TRUE;
}
/* Parse array of dictionaries */
g_variant_iter_init (&iter, dictionaries_installed);
n = g_variant_iter_n_children (&iter);
if (n > 0) {
GVariant *dictionary = NULL;
while (g_variant_iter_loop (&iter, "a{sv}", &dictionary)) {
MMFirmwareProperties *firmware;
GError *inner_error = NULL;
firmware = mm_firmware_properties_new_from_dictionary (dictionary, &inner_error);
if (!firmware) {
g_warning ("Couldn't create firmware properties: %s",
inner_error->message);
if (!saved_error)
saved_error = inner_error;
else
g_error_free (inner_error);
} else {
/* Save the firmware properties */
*installed = g_list_append (*installed, firmware);
if (str_selected &&
g_str_equal (mm_firmware_properties_get_name (firmware), str_selected))
*selected = g_object_ref (firmware);
}
}
}
if (str_selected && *selected == NULL)
g_warning ("Selected image '%s' was not found in the list of installed images",
str_selected);
if (saved_error) {
if (*installed == NULL) {
g_propagate_error (error, saved_error);
return FALSE;
}
g_error_free (saved_error);
}
return TRUE;
}
/**
* mm_modem_firmware_list_finish:
* @self: A #MMModemFirmware.
* @selected: (out) (allow-none) (transfer full): The selected firmware slot, or NULL if no slot is selected (such as if all slots are empty, or no slots exist). The returned value should be freed with g_object_unref().
* @installed: (out) (allow-none) (transfer full): A list of #MMFirmwareProperties objects specifying the installed images. The returned value should be freed with g_list_free_full() using g_object_unref() as #GDestroyNotify.
* @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to mm_modem_firmware_list().
* @error: Return location for error or %NULL.
*
* Finishes an operation started with mm_modem_firmware_list().
*
* Returns: %TRUE if the list was correctly retrieved, %FALSE if @error is set.
*/
gboolean
mm_modem_firmware_list_finish (MMModemFirmware *self,
GAsyncResult *res,
MMFirmwareProperties **selected,
GList **installed,
GError **error)
{
gboolean parsed;
GVariant *dictionaries_installed = NULL;
gchar *str_selected = NULL;
g_return_val_if_fail (MM_IS_MODEM_FIRMWARE (self), FALSE);
g_return_val_if_fail (selected != NULL, FALSE);
g_return_val_if_fail (installed != NULL, FALSE);
if (!mm_gdbus_modem_firmware_call_list_finish (MM_GDBUS_MODEM_FIRMWARE (self),
&str_selected,
&dictionaries_installed,
res,
error))
return FALSE;
parsed = build_results (str_selected,
dictionaries_installed,
selected,
installed,
error);
if (dictionaries_installed)
g_variant_unref (dictionaries_installed);
g_free (str_selected);
return parsed;
}
/**
* mm_modem_firmware_list:
* @self: A #MMModemFirmware.
* @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 gets the list of available firmware images.
*
* 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_firmware_list_finish() to get the result of the operation.
*
* See mm_modem_firmware_list_sync() for the synchronous, blocking version of this method.
*/
void
mm_modem_firmware_list (MMModemFirmware *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_FIRMWARE (self));
mm_gdbus_modem_firmware_call_list (MM_GDBUS_MODEM_FIRMWARE (self),
cancellable,
callback,
user_data);
}
/**
* mm_modem_firmware_list_sync:
* @self: A #MMModemFirmware.
* @selected: (out) (allow-none) (transfer full): The selected firmware slot, or NULL if no slot is selected (such as if all slots are empty, or no slots exist). The returned value should be freed with g_object_unref().
* @installed: (out) (allow-none) (transfer full): A list of #MMFirmwareProperties objects specifying the installed images. The returned value should be freed with g_list_free_full() using g_object_unref() as #GDestroyNotify.
* @cancellable: (allow-none): A #GCancellable or %NULL.
* @error: Return firmware for error or %NULL.
*
* Synchronously gets the list of available firmware images.
*
* The calling thread is blocked until a reply is received. See mm_modem_firmware_list()
* for the asynchronous version of this method.
*
* Returns: %TRUE if the list was correctly retrieved, %FALSE if @error is set.
*/
gboolean
mm_modem_firmware_list_sync (MMModemFirmware *self,
MMFirmwareProperties **selected,
GList **installed,
GCancellable *cancellable,
GError **error)
{
GVariant *dictionaries_installed = NULL;
gchar *str_selected = NULL;
gboolean parsed;
g_return_val_if_fail (MM_IS_MODEM_FIRMWARE (self), FALSE);
g_return_val_if_fail (selected != NULL, FALSE);
g_return_val_if_fail (installed != NULL, FALSE);
if (!mm_gdbus_modem_firmware_call_list_sync (MM_GDBUS_MODEM_FIRMWARE (self),
&str_selected,
&dictionaries_installed,
cancellable,
error))
return FALSE;
parsed = build_results (str_selected,
dictionaries_installed,
selected,
installed,
error);
if (dictionaries_installed)
g_variant_unref (dictionaries_installed);
g_free (str_selected);
return parsed;
}
/*****************************************************************************/
static void
mm_modem_firmware_init (MMModemFirmware *self)
{
}
static void
mm_modem_firmware_class_init (MMModemFirmwareClass *modem_class)
{
}

View File

@@ -0,0 +1,93 @@
/* -*- 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_FIRMWARE_H_
#define _MM_MODEM_FIRMWARE_H_
#include <ModemManager.h>
#include <libmm-common.h>
G_BEGIN_DECLS
#define MM_TYPE_MODEM_FIRMWARE (mm_modem_firmware_get_type ())
#define MM_MODEM_FIRMWARE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_FIRMWARE, MMModemFirmware))
#define MM_MODEM_FIRMWARE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_FIRMWARE, MMModemFirmwareClass))
#define MM_IS_MODEM_FIRMWARE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_FIRMWARE))
#define MM_IS_MODEM_FIRMWARE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), MM_TYPE_MODEM_FIRMWARE))
#define MM_MODEM_FIRMWARE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_FIRMWARE, MMModemFirmwareClass))
typedef struct _MMModemFirmware MMModemFirmware;
typedef struct _MMModemFirmwareClass MMModemFirmwareClass;
/**
* MMModemFirmware:
*
* The #MMModemFirmware structure contains private data and should only be accessed
* using the provided API.
*/
struct _MMModemFirmware {
/*< private >*/
MmGdbusModemFirmwareProxy parent;
gpointer unused;
};
struct _MMModemFirmwareClass {
/*< private >*/
MmGdbusModemFirmwareProxyClass parent;
};
GType mm_modem_firmware_get_type (void);
const gchar *mm_modem_firmware_get_path (MMModemFirmware *self);
gchar *mm_modem_firmware_dup_path (MMModemFirmware *self);
void mm_modem_firmware_list (MMModemFirmware *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean mm_modem_firmware_list_finish (MMModemFirmware *self,
GAsyncResult *res,
MMFirmwareProperties **selected,
GList **installed,
GError **error);
gboolean mm_modem_firmware_list_sync (MMModemFirmware *self,
MMFirmwareProperties **selected,
GList **installed,
GCancellable *cancellable,
GError **error);
void mm_modem_firmware_select (MMModemFirmware *self,
const gchar *name,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean mm_modem_firmware_select_finish (MMModemFirmware *self,
GAsyncResult *res,
GError **error);
gboolean mm_modem_firmware_select_sync (MMModemFirmware *self,
const gchar *name,
GCancellable *cancellable,
GError **error);
G_END_DECLS
#endif /* _MM_MODEM_FIRMWARE_H_ */

View File

@@ -375,6 +375,42 @@ mm_object_peek_modem_time (MMObject *self)
/*****************************************************************************/ /*****************************************************************************/
/**
* mm_object_get_modem_firmware:
* @self: A #MMObject.
*
* Gets the #MMModemFirmware instance for the D-Bus interface org.freedesktop.ModemManager1.Modem.Firmware on @self, if any.
*
* Returns: (transfer full): A #MMModemFirmware that must be freed with g_object_unref() or %NULL if @self does not implement the interface.
*/
MMModemFirmware *
mm_object_get_modem_firmware (MMObject *self)
{
g_return_val_if_fail (MM_IS_OBJECT (MM_GDBUS_OBJECT (self)), NULL);
return (MMModemFirmware *)mm_gdbus_object_get_modem_firmware (MM_GDBUS_OBJECT (self));
}
/**
* mm_object_peek_modem_firmware: (skip)
* @self: A #MMObject.
*
* Like mm_object_get_modem_firmware() 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 #MMModemFirmware or %NULL if @self does not implement the interface. Do not free the returned object, it is owned by @self.
*/
MMModemFirmware *
mm_object_peek_modem_firmware (MMObject *self)
{
g_return_val_if_fail (MM_IS_OBJECT (MM_GDBUS_OBJECT (self)), NULL);
return (MMModemFirmware *)mm_gdbus_object_peek_modem_firmware (MM_GDBUS_OBJECT (self));
}
/*****************************************************************************/
static void static void
mm_object_init (MMObject *self) mm_object_init (MMObject *self)
{ {

View File

@@ -35,6 +35,7 @@
#include "mm-modem-location.h" #include "mm-modem-location.h"
#include "mm-modem-messaging.h" #include "mm-modem-messaging.h"
#include "mm-modem-time.h" #include "mm-modem-time.h"
#include "mm-modem-firmware.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@@ -78,6 +79,7 @@ MMModemSimple *mm_object_get_modem_simple (MMObject *self);
MMModemLocation *mm_object_get_modem_location (MMObject *self); MMModemLocation *mm_object_get_modem_location (MMObject *self);
MMModemMessaging *mm_object_get_modem_messaging (MMObject *self); MMModemMessaging *mm_object_get_modem_messaging (MMObject *self);
MMModemTime *mm_object_get_modem_time (MMObject *self); MMModemTime *mm_object_get_modem_time (MMObject *self);
MMModemFirmware *mm_object_get_modem_firmware (MMObject *self);
MMModem *mm_object_peek_modem (MMObject *self); MMModem *mm_object_peek_modem (MMObject *self);
MMModem3gpp *mm_object_peek_modem_3gpp (MMObject *self); MMModem3gpp *mm_object_peek_modem_3gpp (MMObject *self);
@@ -87,6 +89,7 @@ MMModemSimple *mm_object_peek_modem_simple (MMObject *self);
MMModemLocation *mm_object_peek_modem_location (MMObject *self); MMModemLocation *mm_object_peek_modem_location (MMObject *self);
MMModemMessaging *mm_object_peek_modem_messaging (MMObject *self); MMModemMessaging *mm_object_peek_modem_messaging (MMObject *self);
MMModemTime *mm_object_peek_modem_time (MMObject *self); MMModemTime *mm_object_peek_modem_time (MMObject *self);
MMModemFirmware *mm_object_peek_modem_firmware (MMObject *self);
G_END_DECLS G_END_DECLS