fp-device: Support variadic arguments to error functions

Make possible to generate a formatted message when creating an error from
a device, without having save it first.
This commit is contained in:
Marco Trevisan (Treviño) 2019-11-25 21:22:47 +01:00 committed by Benjamin Berg
parent 3b72b925b0
commit f6559ba8b1
2 changed files with 26 additions and 6 deletions

View file

@ -243,9 +243,18 @@ fpi_device_error_new (FpDeviceError error)
* and similar calls. * and similar calls.
*/ */
GError * GError *
fpi_device_retry_new_msg (FpDeviceRetry error, const gchar *msg) fpi_device_retry_new_msg (FpDeviceRetry device_error,
const gchar *msg,
...)
{ {
return g_error_new_literal (FP_DEVICE_RETRY, error, msg); GError *error;
va_list args;
va_start (args, msg);
error = g_error_new_valist (FP_DEVICE_RETRY, device_error, msg, args);
va_end (args);
return error;
} }
/** /**
@ -257,9 +266,18 @@ fpi_device_retry_new_msg (FpDeviceRetry error, const gchar *msg)
* and similar calls. * and similar calls.
*/ */
GError * GError *
fpi_device_error_new_msg (FpDeviceError error, const gchar *msg) fpi_device_error_new_msg (FpDeviceError device_error,
const gchar *msg,
...)
{ {
return g_error_new_literal (FP_DEVICE_ERROR, error, msg); GError *error;
va_list args;
va_start (args, msg);
error = g_error_new_valist (FP_DEVICE_ERROR, device_error, msg, args);
va_end (args);
return error;
} }
static gboolean static gboolean

View file

@ -181,9 +181,11 @@ GError * fpi_device_retry_new (FpDeviceRetry error);
GError * fpi_device_error_new (FpDeviceError error); GError * fpi_device_error_new (FpDeviceError error);
GError * fpi_device_retry_new_msg (FpDeviceRetry error, GError * fpi_device_retry_new_msg (FpDeviceRetry error,
const gchar *msg); const gchar *msg,
...) G_GNUC_PRINTF (2, 3);
GError * fpi_device_error_new_msg (FpDeviceError error, GError * fpi_device_error_new_msg (FpDeviceError error,
const gchar *msg); const gchar *msg,
...) G_GNUC_PRINTF (2, 3);
guint64 fpi_device_get_driver_data (FpDevice *device); guint64 fpi_device_get_driver_data (FpDevice *device);