trivial: Add fu_device_has_custom_flag()

This splits the custom flags and checks if one of them exists.
This commit is contained in:
Richard Hughes 2018-06-28 12:05:40 +01:00
parent 63b173046d
commit ac11be65f3
2 changed files with 33 additions and 0 deletions

View File

@ -721,6 +721,37 @@ fu_device_get_custom_flags (FuDevice *device)
return fu_device_get_metadata (device, "CustomFlags");
}
/**
* fu_device_has_custom_flag:
* @device: A #FuDevice
* @hint: A string, e.g. "bootloader"
*
* Checks if the custom flag exists for the device from the quirk system.
*
* It may be more efficient to call fu_device_get_custom_flags() and split the
* string locally if checking for lots of different flags.
*
* Returns: %TRUE if the hint exists
*
* Since: 1.1.0
**/
gboolean
fu_device_has_custom_flag (FuDevice *device, const gchar *hint)
{
const gchar *hint_str;
g_auto(GStrv) hints = NULL;
g_return_val_if_fail (FU_IS_DEVICE (device), FALSE);
g_return_val_if_fail (hint != NULL, FALSE);
/* no hint is perfectly valid */
hint_str = fu_device_get_custom_flags (device);
if (hint_str == NULL)
return FALSE;
hints = g_strsplit (hint_str, ",", -1);
return g_strv_contains ((const gchar * const *) hints, hint);
}
/**
* fu_device_set_platform_id:
* @device: A #FuDevice

View File

@ -138,6 +138,8 @@ const gchar *fu_device_get_serial (FuDevice *device);
void fu_device_set_serial (FuDevice *device,
const gchar *serial);
const gchar *fu_device_get_custom_flags (FuDevice *device);
gboolean fu_device_has_custom_flag (FuDevice *device,
const gchar *hint);
void fu_device_set_custom_flags (FuDevice *device,
const gchar *custom_flags);
void fu_device_set_name (FuDevice *device,