api,libmm-glib: use a 'unique-id' as ID of the firmware image, not a 'name'

Also, make only the 'unique-id' mandatory.
This commit is contained in:
Aleksander Morgado
2012-10-04 16:43:43 +02:00
parent d84b4f634e
commit 0d00ee28be
7 changed files with 43 additions and 82 deletions

View File

@@ -54,7 +54,7 @@ static GOptionEntry entries[] = {
},
{ "firmware-select", 0, 0, G_OPTION_ARG_STRING, &select_str,
"Select a given firmware image",
"[NAME]"
"[Unique ID]"
},
{ NULL }
};
@@ -157,17 +157,15 @@ list_process_reply (MMFirmwareProperties *selected,
MMFirmwareProperties *props = MM_FIRMWARE_PROPERTIES (l->data);
g_print ("\t[%u] %s%s\n"
"\t\t Type: '%s'\n"
"\t\tVersion: '%s'\n",
"\t\t Type: '%s'\n",
i,
mm_firmware_properties_get_name (props),
mm_firmware_properties_get_unique_id (props),
((selected &&
g_str_equal (mm_firmware_properties_get_name (props),
mm_firmware_properties_get_name (selected))) ?
g_str_equal (mm_firmware_properties_get_unique_id (props),
mm_firmware_properties_get_unique_id (selected))) ?
" (CURRENT)" : ""),
mm_firmware_image_type_get_string (
mm_firmware_properties_get_image_type (props)),
mm_firmware_properties_get_version (props));
mm_firmware_properties_get_image_type (props)));
g_object_unref (props);
}
g_list_free (result);

View File

@@ -532,8 +532,7 @@ mm_modem_firmware_get_type
MMFirmwareProperties
<SUBSECTION Getters>
mm_firmware_properties_get_image_type
mm_firmware_properties_get_name
mm_firmware_properties_get_version
mm_firmware_properties_get_unique_id
<SUBSECTION Private>
mm_firmware_properties_new
mm_firmware_properties_new_from_dictionary

View File

@@ -34,15 +34,15 @@
will only expose only the mandatory properties.
</listitem>
</varlistentry>
<varlistentry><term><literal>"name"</literal></term>
<varlistentry><term><literal>"unique-id"</literal></term>
<listitem>
(Required) A user-readable name for the firmware image, given as a
(Required) A user-readable unique ID for the firmware image, given as a
string value (signature <literal>"s"</literal>).
</listitem>
</varlistentry>
<varlistentry><term><literal>"version"</literal></term>
<listitem>
(Required) The version of the firmware, given as a string value
(Optional) The version of the firmware, given as a string value
(signature <literal>"s"</literal>). The format is
unspecified; tools attempting to upgrade firmware automatically must
understand the versioning scheme used by the modem driver they are
@@ -72,7 +72,7 @@
<!--
Select:
@name: The unique name of the firmware image to select.
@uniqueid: The unique ID of the firmware image to select.
Selects a different firmware image to use, and immediately resets the
modem so that it begins using the new firmware image.
@@ -83,7 +83,7 @@
or if the image could not be selected for some reason.
-->
<method name="Select">
<arg name="name" type="s" direction="in" />
<arg name="uniqueid" type="s" direction="in" />
</method>
<!--

View File

@@ -33,15 +33,13 @@
G_DEFINE_TYPE (MMFirmwareProperties, mm_firmware_properties, G_TYPE_OBJECT);
#define PROPERTY_NAME "name"
#define PROPERTY_VERSION "version"
#define PROPERTY_UNIQUE_ID "unique-id"
#define PROPERTY_IMAGE_TYPE "image-type"
struct _MMFirmwarePropertiesPrivate {
/* Mandatory parameters */
MMFirmwareImageType image_type;
gchar *name;
gchar *version;
gchar *unique_id;
};
static MMFirmwareProperties *firmware_properties_new_empty (void);
@@ -49,37 +47,19 @@ static MMFirmwareProperties *firmware_properties_new_empty (void);
/*****************************************************************************/
/**
* mm_firmware_properties_get_name:
* mm_firmware_properties_get_unique_id:
* @self: A #MMFirmwareProperties.
*
* Gets the unique name of the firmare image.
* Gets the unique ID of the firmare image.
*
* Returns: (transfer none): The name of the image. Do not free the returned value, it is owned by @self.
* Returns: (transfer none): The ID of the image. Do not free the returned value, it is owned by @self.
*/
const gchar *
mm_firmware_properties_get_name (MMFirmwareProperties *self)
mm_firmware_properties_get_unique_id (MMFirmwareProperties *self)
{
g_return_val_if_fail (MM_IS_FIRMWARE_PROPERTIES (self), NULL);
return self->priv->name;
}
/*****************************************************************************/
/**
* mm_firmware_properties_get_version:
* @self: A #MMFirmwareProperties.
*
* Gets the version string of the firmare image.
*
* Returns: (transfer none): The version of the image. Do not free the returned value, it is owned by @self.
*/
const gchar *
mm_firmware_properties_get_version (MMFirmwareProperties *self)
{
g_return_val_if_fail (MM_IS_FIRMWARE_PROPERTIES (self), NULL);
return self->priv->version;
return self->priv->unique_id;
}
/*****************************************************************************/
@@ -127,13 +107,8 @@ mm_firmware_properties_get_dictionary (MMFirmwareProperties *self)
g_variant_builder_add (&builder,
"{sv}",
PROPERTY_NAME,
g_variant_new_string (self->priv->name));
g_variant_builder_add (&builder,
"{sv}",
PROPERTY_VERSION,
g_variant_new_string (self->priv->version));
PROPERTY_UNIQUE_ID,
g_variant_new_string (self->priv->unique_id));
g_variant_builder_add (&builder,
"{sv}",
@@ -151,12 +126,9 @@ consume_variant (MMFirmwareProperties *self,
GVariant *value,
GError **error)
{
if (g_str_equal (key, PROPERTY_NAME)) {
g_free (self->priv->name);
self->priv->name = g_variant_dup_string (value, NULL);
} else if (g_str_equal (key, PROPERTY_VERSION)) {
g_free (self->priv->version);
self->priv->version = g_variant_dup_string (value, NULL);
if (g_str_equal (key, PROPERTY_UNIQUE_ID)) {
g_free (self->priv->unique_id);
self->priv->unique_id = g_variant_dup_string (value, NULL);
} else if (g_str_equal (key, PROPERTY_IMAGE_TYPE))
self->priv->image_type = g_variant_get_uint32 (value);
else {
@@ -230,8 +202,7 @@ mm_firmware_properties_new_from_dictionary (GVariant *dictionary,
}
/* If mandatory properties missing, destroy the object */
if (!self->priv->name ||
!self->priv->version ||
if (!self->priv->unique_id ||
self->priv->image_type == MM_FIRMWARE_IMAGE_TYPE_UNKNOWN) {
g_set_error (error,
MM_CORE_ERROR,
@@ -250,8 +221,7 @@ mm_firmware_properties_new_from_dictionary (GVariant *dictionary,
/**
* mm_firmware_properties_new:
* @image_type: A #MMFirmwareImageType specifying the type of the image.
* @name: The unique name of the image.
* @version: The version of the image.
* @unique_id: The unique ID of the image.
*
* Creates a new #MMFirmwareProperties object with the properties specified.
*
@@ -259,19 +229,16 @@ mm_firmware_properties_new_from_dictionary (GVariant *dictionary,
*/
MMFirmwareProperties *
mm_firmware_properties_new (MMFirmwareImageType image_type,
const gchar *name,
const gchar *version)
const gchar *unique_id)
{
MMFirmwareProperties *self;
g_return_val_if_fail (image_type != MM_FIRMWARE_IMAGE_TYPE_UNKNOWN, NULL);
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (version != NULL, NULL);
g_return_val_if_fail (unique_id != NULL, NULL);
self = firmware_properties_new_empty ();
self->priv->image_type = image_type;
self->priv->name = g_strdup (name);
self->priv->version = g_strdup (version);
self->priv->unique_id = g_strdup (unique_id);
return self;
}
@@ -299,8 +266,7 @@ finalize (GObject *object)
{
MMFirmwareProperties *self = MM_FIRMWARE_PROPERTIES (object);
g_free (self->priv->name);
g_free (self->priv->version);
g_free (self->priv->unique_id);
G_OBJECT_CLASS (mm_firmware_properties_parent_class)->finalize (object);
}

View File

@@ -55,8 +55,7 @@ struct _MMFirmwarePropertiesClass {
GType mm_firmware_properties_get_type (void);
const gchar *mm_firmware_properties_get_name (MMFirmwareProperties *self);
const gchar *mm_firmware_properties_get_version (MMFirmwareProperties *self);
const gchar *mm_firmware_properties_get_unique_id (MMFirmwareProperties *self);
MMFirmwareImageType mm_firmware_properties_get_image_type (MMFirmwareProperties *self);
/*****************************************************************************/
@@ -67,8 +66,7 @@ MMFirmwareImageType mm_firmware_properties_get_image_type (MMFirmwareProperties
defined (LIBMM_GLIB_COMPILATION)
MMFirmwareProperties *mm_firmware_properties_new (MMFirmwareImageType image_type,
const gchar *name,
const gchar *version);
const gchar *unique_id);
MMFirmwareProperties *mm_firmware_properties_new_from_dictionary (GVariant *dictionary,
GError **error);

View File

@@ -105,7 +105,7 @@ mm_modem_firmware_select_finish (MMModemFirmware *self,
/**
* mm_modem_firmware_select:
* @self: A #MMModemFirmware.
* @name: Unique name of the firmware image to select.
* @unique_id: Unique ID 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.
@@ -122,21 +122,21 @@ mm_modem_firmware_select_finish (MMModemFirmware *self,
*/
void
mm_modem_firmware_select (MMModemFirmware *self,
const gchar *name,
const gchar *unique_id,
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');
g_return_if_fail (unique_id != NULL || unique_id[0] == '\0');
mm_gdbus_modem_firmware_call_select (MM_GDBUS_MODEM_FIRMWARE (self), name, cancellable, callback, user_data);
mm_gdbus_modem_firmware_call_select (MM_GDBUS_MODEM_FIRMWARE (self), unique_id, cancellable, callback, user_data);
}
/**
* mm_modem_firmware_select_sync:
* @self: A #MMModemFirmware.
* @name: Unique name of the firmware image to select.
* @unique_id: Unique ID of the firmware image to select.
* @cancellable: (allow-none): A #GCancellable or %NULL.
* @error: Return location for error or %NULL.
*
@@ -152,14 +152,14 @@ mm_modem_firmware_select (MMModemFirmware *self,
*/
gboolean
mm_modem_firmware_select_sync (MMModemFirmware *self,
const gchar *name,
const gchar *unique_id,
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);
g_return_val_if_fail (unique_id != NULL || unique_id[0] == '\0', FALSE);
return mm_gdbus_modem_firmware_call_select_sync (MM_GDBUS_MODEM_FIRMWARE (self), name, cancellable, error);
return mm_gdbus_modem_firmware_call_select_sync (MM_GDBUS_MODEM_FIRMWARE (self), unique_id, cancellable, error);
}
/*****************************************************************************/
@@ -218,7 +218,7 @@ build_results (const gchar *str_selected,
*installed = g_list_append (*installed, firmware);
if (str_selected &&
g_str_equal (mm_firmware_properties_get_name (firmware), str_selected))
g_str_equal (mm_firmware_properties_get_unique_id (firmware), str_selected))
*selected = g_object_ref (firmware);
}
}

View File

@@ -82,7 +82,7 @@ gboolean mm_modem_firmware_list_sync (MMModemFirmware *self,
GError **error);
void mm_modem_firmware_select (MMModemFirmware *self,
const gchar *name,
const gchar *unique_id,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
@@ -90,7 +90,7 @@ gboolean mm_modem_firmware_select_finish (MMModemFirmware *self,
GAsyncResult *res,
GError **error);
gboolean mm_modem_firmware_select_sync (MMModemFirmware *self,
const gchar *name,
const gchar *unique_id,
GCancellable *cancellable,
GError **error);