mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-06 04:23:33 +00:00
trivial: Add some parameter guards to FuDevice
Not actually fixing any bug, but it means we crash before we do any damage...
This commit is contained in:
parent
c8bfb40527
commit
3b89ab1dee
@ -212,6 +212,7 @@ guint
|
||||
fu_device_get_order (FuDevice *self)
|
||||
{
|
||||
FuDevicePrivate *priv = GET_PRIVATE (self);
|
||||
g_return_val_if_fail (FU_IS_DEVICE (self), 0);
|
||||
return priv->order;
|
||||
}
|
||||
|
||||
@ -229,6 +230,7 @@ void
|
||||
fu_device_set_order (FuDevice *self, guint order)
|
||||
{
|
||||
FuDevicePrivate *priv = GET_PRIVATE (self);
|
||||
g_return_if_fail (FU_IS_DEVICE (self));
|
||||
priv->order = order;
|
||||
}
|
||||
|
||||
@ -246,6 +248,7 @@ guint
|
||||
fu_device_get_priority (FuDevice *self)
|
||||
{
|
||||
FuDevicePrivate *priv = GET_PRIVATE (self);
|
||||
g_return_val_if_fail (FU_IS_DEVICE (self), 0);
|
||||
return priv->priority;
|
||||
}
|
||||
|
||||
@ -262,6 +265,7 @@ void
|
||||
fu_device_set_priority (FuDevice *self, guint priority)
|
||||
{
|
||||
FuDevicePrivate *priv = GET_PRIVATE (self);
|
||||
g_return_if_fail (FU_IS_DEVICE (self));
|
||||
priv->priority = priority;
|
||||
}
|
||||
|
||||
@ -393,6 +397,8 @@ fu_device_set_parent (FuDevice *self, FuDevice *parent)
|
||||
{
|
||||
FuDevicePrivate *priv = GET_PRIVATE (self);
|
||||
|
||||
g_return_if_fail (FU_IS_DEVICE (self));
|
||||
|
||||
g_object_add_weak_pointer (G_OBJECT (parent), (gpointer *) &priv->parent);
|
||||
priv->parent = parent;
|
||||
|
||||
@ -542,6 +548,7 @@ fu_device_add_parent_guid (FuDevice *self, const gchar *guid)
|
||||
{
|
||||
FuDevicePrivate *priv = GET_PRIVATE (self);
|
||||
g_autoptr(FuMutexLocker) locker = NULL;
|
||||
|
||||
g_return_if_fail (FU_IS_DEVICE (self));
|
||||
g_return_if_fail (guid != NULL);
|
||||
|
||||
@ -852,6 +859,9 @@ fu_device_add_guid_safe (FuDevice *self, const gchar *guid)
|
||||
gboolean
|
||||
fu_device_has_guid (FuDevice *self, const gchar *guid)
|
||||
{
|
||||
g_return_val_if_fail (FU_IS_DEVICE (self), FALSE);
|
||||
g_return_val_if_fail (guid != NULL, FALSE);
|
||||
|
||||
/* make valid */
|
||||
if (!fwupd_guid_is_valid (guid)) {
|
||||
g_autofree gchar *tmp = fwupd_guid_hash_string (guid);
|
||||
@ -916,6 +926,8 @@ fu_device_add_instance_id (FuDevice *self, const gchar *instance_id)
|
||||
void
|
||||
fu_device_add_guid (FuDevice *self, const gchar *guid)
|
||||
{
|
||||
g_return_if_fail (FU_IS_DEVICE (self));
|
||||
g_return_if_fail (guid != NULL);
|
||||
if (!fwupd_guid_is_valid (guid)) {
|
||||
fu_device_add_instance_id (self, guid);
|
||||
return;
|
||||
@ -940,6 +952,9 @@ fu_device_add_guid (FuDevice *self, const gchar *guid)
|
||||
void
|
||||
fu_device_add_counterpart_guid (FuDevice *self, const gchar *guid)
|
||||
{
|
||||
g_return_if_fail (FU_IS_DEVICE (self));
|
||||
g_return_if_fail (guid != NULL);
|
||||
|
||||
/* make valid */
|
||||
if (!fwupd_guid_is_valid (guid)) {
|
||||
g_autofree gchar *tmp = fwupd_guid_hash_string (guid);
|
||||
@ -965,8 +980,13 @@ fu_device_add_counterpart_guid (FuDevice *self, const gchar *guid)
|
||||
gchar *
|
||||
fu_device_get_guids_as_str (FuDevice *self)
|
||||
{
|
||||
GPtrArray *guids = fu_device_get_guids (self);
|
||||
g_autofree gchar **tmp = g_new0 (gchar *, guids->len + 1);
|
||||
GPtrArray *guids;
|
||||
g_autofree gchar **tmp = NULL;
|
||||
|
||||
g_return_val_if_fail (FU_IS_DEVICE (self), NULL);
|
||||
|
||||
guids = fu_device_get_guids (self);
|
||||
tmp = g_new0 (gchar *, guids->len + 1);
|
||||
for (guint i = 0; i < guids->len; i++)
|
||||
tmp[i] = g_ptr_array_index (guids, i);
|
||||
return g_strjoinv (",", tmp);
|
||||
@ -1011,9 +1031,11 @@ fu_device_get_metadata_boolean (FuDevice *self, const gchar *key)
|
||||
FuDevicePrivate *priv = GET_PRIVATE (self);
|
||||
const gchar *tmp;
|
||||
g_autoptr(FuMutexLocker) locker = fu_mutex_read_locker_new (priv->metadata_mutex);
|
||||
|
||||
g_return_val_if_fail (FU_IS_DEVICE (self), FALSE);
|
||||
g_return_val_if_fail (key != NULL, FALSE);
|
||||
g_return_val_if_fail (locker != NULL, FALSE);
|
||||
|
||||
tmp = g_hash_table_lookup (priv->metadata, key);
|
||||
if (tmp == NULL)
|
||||
return FALSE;
|
||||
@ -1091,6 +1113,9 @@ fu_device_set_metadata (FuDevice *self, const gchar *key, const gchar *value)
|
||||
void
|
||||
fu_device_set_metadata_boolean (FuDevice *self, const gchar *key, gboolean value)
|
||||
{
|
||||
g_return_if_fail (FU_IS_DEVICE (self));
|
||||
g_return_if_fail (key != NULL);
|
||||
|
||||
fu_device_set_metadata (self, key, value ? "true" : "false");
|
||||
}
|
||||
|
||||
@ -1109,6 +1134,10 @@ void
|
||||
fu_device_set_metadata_integer (FuDevice *self, const gchar *key, guint value)
|
||||
{
|
||||
g_autofree gchar *tmp = g_strdup_printf ("%u", value);
|
||||
|
||||
g_return_if_fail (FU_IS_DEVICE (self));
|
||||
g_return_if_fail (key != NULL);
|
||||
|
||||
fu_device_set_metadata (self, key, tmp);
|
||||
}
|
||||
|
||||
@ -1126,6 +1155,9 @@ fu_device_set_name (FuDevice *self, const gchar *value)
|
||||
{
|
||||
g_autoptr(GString) new = g_string_new (value);
|
||||
|
||||
g_return_if_fail (FU_IS_DEVICE (self));
|
||||
g_return_if_fail (value != NULL);
|
||||
|
||||
/* overwriting? */
|
||||
if (g_strcmp0 (value, fu_device_get_name (self)) == 0) {
|
||||
const gchar *id = fu_device_get_id (self);
|
||||
@ -1236,6 +1268,9 @@ fu_device_ensure_id (FuDevice *self, GError **error)
|
||||
{
|
||||
g_autofree gchar *device_id = NULL;
|
||||
|
||||
g_return_val_if_fail (FU_IS_DEVICE (self), FALSE);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
/* already set */
|
||||
if (fu_device_get_id (self) != NULL)
|
||||
return TRUE;
|
||||
@ -1581,6 +1616,7 @@ void
|
||||
fu_device_set_progress_full (FuDevice *self, gsize progress_done, gsize progress_total)
|
||||
{
|
||||
gdouble percentage = 0.f;
|
||||
g_return_if_fail (FU_IS_DEVICE (self));
|
||||
if (progress_total > 0)
|
||||
percentage = (100.f * (gdouble) progress_done) / (gdouble) progress_total;
|
||||
fu_device_set_progress (self, (guint) percentage);
|
||||
@ -1691,6 +1727,7 @@ FwupdRelease *
|
||||
fu_device_get_release_default (FuDevice *self)
|
||||
{
|
||||
g_autoptr(FwupdRelease) rel = NULL;
|
||||
g_return_val_if_fail (FU_IS_DEVICE (self), NULL);
|
||||
if (fwupd_device_get_release_default (FWUPD_DEVICE (self)) != NULL)
|
||||
return fwupd_device_get_release_default (FWUPD_DEVICE (self));
|
||||
rel = fwupd_release_new ();
|
||||
@ -2233,12 +2270,14 @@ fu_device_incorporate (FuDevice *self, FuDevice *donor)
|
||||
* Since: 1.2.4
|
||||
**/
|
||||
void
|
||||
fu_device_incorporate_from_component (FuDevice *device, XbNode *component)
|
||||
fu_device_incorporate_from_component (FuDevice *self, XbNode *component)
|
||||
{
|
||||
const gchar *tmp;
|
||||
g_return_if_fail (FU_IS_DEVICE (self));
|
||||
g_return_if_fail (XB_IS_NODE (component));
|
||||
tmp = xb_node_query_text (component, "custom/value[@key='LVFS::UpdateMessage']", NULL);
|
||||
if (tmp != NULL)
|
||||
fwupd_device_set_update_message (FWUPD_DEVICE (device), tmp);
|
||||
fwupd_device_set_update_message (FWUPD_DEVICE (self), tmp);
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user