diff --git a/plugins/altos/fu-altos-device.c b/plugins/altos/fu-altos-device.c index ad68b0d0c..da3c7959e 100644 --- a/plugins/altos/fu-altos-device.c +++ b/plugins/altos/fu-altos-device.c @@ -109,18 +109,6 @@ fu_altos_device_finalize (GObject *object) G_OBJECT_CLASS (fu_altos_device_parent_class)->finalize (object); } -static void -fu_altos_device_init (FuAltosDevice *device) -{ -} - -static void -fu_altos_device_class_init (FuAltosDeviceClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = fu_altos_device_finalize; -} - FuAltosDeviceKind fu_altos_device_get_kind (FuAltosDevice *device) { @@ -432,13 +420,11 @@ fu_altos_device_write_page (FuAltosDevice *device, return TRUE; } -gboolean -fu_altos_device_write_firmware (FuAltosDevice *device, - GBytes *fw, - FuAltosDeviceWriteFirmwareFlag flags, - GError **error) +static gboolean +fu_altos_device_write_firmware (FuDevice *device, GBytes *fw, GError **error) { - FuAltosDevicePrivate *priv = GET_PRIVATE (device); + FuAltosDevice *self = FU_ALTOS_DEVICE (device); + FuAltosDevicePrivate *priv = GET_PRIVATE (self); GBytes *fw_blob; const gchar *data; const gsize data_len; @@ -525,7 +511,7 @@ fu_altos_device_write_firmware (FuAltosDevice *device, } /* verify data from device */ - if (!fu_altos_device_write_page (device, + if (!fu_altos_device_write_page (self, priv->addr_base + i, buf_tmp, 0x100, @@ -533,7 +519,7 @@ fu_altos_device_write_firmware (FuAltosDevice *device, return FALSE; /* verify data written on device */ - str = fu_altos_device_read_page (device, + str = fu_altos_device_read_page (self, priv->addr_base + i, error); if (str == NULL) @@ -557,18 +543,16 @@ fu_altos_device_write_firmware (FuAltosDevice *device, } /* progress */ - fu_device_set_progress_full (FU_DEVICE (device), i, flash_len); + fu_device_set_progress_full (device, i, flash_len); g_string_append_len (buf, str->str, str->len); } /* go to application mode */ - if (flags & FU_ALTOS_DEVICE_WRITE_FIRMWARE_FLAG_REBOOT) { - if (!fu_altos_device_tty_write (device, "a\n", -1, error)) - return FALSE; - } + if (!fu_altos_device_tty_write (self, "a\n", -1, error)) + return FALSE; /* progress complete */ - fu_device_set_progress_full (FU_DEVICE (device), flash_len, flash_len); + fu_device_set_progress_full (device, flash_len, flash_len); /* success */ return TRUE; @@ -784,6 +768,20 @@ fu_altos_device_init_real (FuAltosDevice *device) } } +static void +fu_altos_device_init (FuAltosDevice *device) +{ +} + +static void +fu_altos_device_class_init (FuAltosDeviceClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + FuDeviceClass *klass_device = FU_DEVICE_CLASS (klass); + klass_device->write_firmware = fu_altos_device_write_firmware; + object_class->finalize = fu_altos_device_finalize; +} + typedef struct { guint16 vid; guint16 pid; diff --git a/plugins/altos/fu-altos-device.h b/plugins/altos/fu-altos-device.h index 9dcdbfd39..ec10000cf 100644 --- a/plugins/altos/fu-altos-device.h +++ b/plugins/altos/fu-altos-device.h @@ -58,10 +58,6 @@ const gchar *fu_altos_device_kind_to_string (FuAltosDeviceKind kind); FuAltosDeviceKind fu_altos_device_get_kind (FuAltosDevice *device); gboolean fu_altos_device_probe (FuAltosDevice *device, GError **error); -gboolean fu_altos_device_write_firmware (FuAltosDevice *device, - GBytes *fw, - FuAltosDeviceWriteFirmwareFlag flags, - GError **error); GBytes *fu_altos_device_read_firmware (FuAltosDevice *device, GError **error); diff --git a/plugins/altos/fu-altos-tool.c b/plugins/altos/fu-altos-tool.c index d7fbaab31..867a217b6 100644 --- a/plugins/altos/fu-altos-tool.c +++ b/plugins/altos/fu-altos-tool.c @@ -92,9 +92,7 @@ main (int argc, char **argv) fw = g_bytes_new (data, len); g_signal_connect (dev, "notify::progress", G_CALLBACK (fu_altos_tool_progress_cb), NULL); - if (!fu_altos_device_write_firmware (dev, fw, - FU_ALTOS_DEVICE_WRITE_FIRMWARE_FLAG_NONE, - &error)) { + if (!fu_device_write_firmware (FU_DEVICE (dev), fw, &error)) { g_print ("Failed to write firmware: %s\n", error->message); return 1; } diff --git a/plugins/altos/fu-plugin-altos.c b/plugins/altos/fu-plugin-altos.c index 28ee27483..3bbd08dfc 100644 --- a/plugins/altos/fu-plugin-altos.c +++ b/plugins/altos/fu-plugin-altos.c @@ -98,11 +98,5 @@ fu_plugin_update (FuPlugin *plugin, GError **error) { fu_device_set_status (dev, FWUPD_STATUS_DEVICE_WRITE); - if (!fu_altos_device_write_firmware (FU_ALTOS_DEVICE (dev), - blob_fw, - FU_ALTOS_DEVICE_WRITE_FIRMWARE_FLAG_REBOOT, - error)) { - return FALSE; - } - return TRUE; + return fu_device_write_firmware (dev, blob_fw, error); } diff --git a/plugins/colorhug/fu-colorhug-device.c b/plugins/colorhug/fu-colorhug-device.c index 6977c5fc6..ae1479b45 100644 --- a/plugins/colorhug/fu-colorhug-device.c +++ b/plugins/colorhug/fu-colorhug-device.c @@ -271,15 +271,16 @@ fu_colorhug_device_verify_firmware (FuColorhugDevice *device, GError **error) return TRUE; } -gboolean -fu_colorhug_device_write_firmware (FuColorhugDevice *device, GBytes *fw, GError **error) +static gboolean +fu_colorhug_device_write_firmware (FuDevice *device, GBytes *fw, GError **error) { - FuColorhugDevicePrivate *priv = GET_PRIVATE (device); + FuColorhugDevice *self = FU_COLORHUG_DEVICE (device); + FuColorhugDevicePrivate *priv = GET_PRIVATE (self); GUsbDevice *usb_device = fu_usb_device_get_dev (FU_USB_DEVICE (device)); g_autoptr(GError) error_local = NULL; /* write firmware */ - fu_device_set_status (FU_DEVICE (device), FWUPD_STATUS_DEVICE_WRITE); + fu_device_set_status (device, FWUPD_STATUS_DEVICE_WRITE); ch_device_queue_set_flash_success (priv->device_queue, usb_device, 0x00); @@ -298,7 +299,7 @@ fu_colorhug_device_write_firmware (FuColorhugDevice *device, GBytes *fw, GError } /* verify firmware */ - fu_device_set_status (FU_DEVICE (device), FWUPD_STATUS_DEVICE_VERIFY); + fu_device_set_status (device, FWUPD_STATUS_DEVICE_VERIFY); ch_device_queue_verify_firmware (priv->device_queue, usb_device, g_bytes_get_data (fw, NULL), g_bytes_get_size (fw)); @@ -330,7 +331,9 @@ static void fu_colorhug_device_class_init (FuColorhugDeviceClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + FuDeviceClass *klass_device = FU_DEVICE_CLASS (klass); FuUsbDeviceClass *klass_usb_device = FU_USB_DEVICE_CLASS (klass); + klass_device->write_firmware = fu_colorhug_device_write_firmware; object_class->finalize = fu_colorhug_device_finalize; klass_usb_device->open = fu_colorhug_device_open; klass_usb_device->probe = fu_colorhug_device_probe; diff --git a/plugins/colorhug/fu-colorhug-device.h b/plugins/colorhug/fu-colorhug-device.h index 7b90f84bc..b7a08e561 100644 --- a/plugins/colorhug/fu-colorhug-device.h +++ b/plugins/colorhug/fu-colorhug-device.h @@ -47,9 +47,6 @@ gboolean fu_colorhug_device_attach (FuColorhugDevice *device, GError **error); gboolean fu_colorhug_device_set_flash_success (FuColorhugDevice *device, GError **error); -gboolean fu_colorhug_device_write_firmware (FuColorhugDevice *device, - GBytes *fw, - GError **error); gboolean fu_colorhug_device_verify_firmware (FuColorhugDevice *device, GError **error); diff --git a/plugins/colorhug/fu-plugin-colorhug.c b/plugins/colorhug/fu-plugin-colorhug.c index 5c88700ad..d74c5bd82 100644 --- a/plugins/colorhug/fu-plugin-colorhug.c +++ b/plugins/colorhug/fu-plugin-colorhug.c @@ -163,7 +163,7 @@ fu_plugin_update (FuPlugin *plugin, locker = fu_device_locker_new (device, error); if (locker == NULL) return FALSE; - return fu_colorhug_device_write_firmware (colorhug_dev, blob_fw, error); + return fu_device_write_firmware (FU_DEVICE (colorhug_dev), blob_fw, error); } gboolean diff --git a/plugins/csr/fu-csr-device.c b/plugins/csr/fu-csr-device.c index 8e5b6d635..a0869b2a1 100644 --- a/plugins/csr/fu-csr-device.c +++ b/plugins/csr/fu-csr-device.c @@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * - * Copyright (C) 2017 Richard Hughes + * Copyright (C) 2017-2018 Richard Hughes * * Licensed under the GNU Lesser General Public License Version 2.1 * @@ -449,9 +449,10 @@ _dfu_firmware_get_default_element_data (DfuFirmware *firmware) return dfu_element_get_contents (element); } -gboolean -fu_csr_device_download (FuCsrDevice *self, GBytes *blob, GError **error) +static gboolean +fu_csr_device_download (FuDevice *device, GBytes *blob, GError **error) { + FuCsrDevice *self = FU_CSR_DEVICE (device); GBytes *blob_noftr; const guint8 *data; gsize sz = 0; @@ -461,7 +462,7 @@ fu_csr_device_download (FuCsrDevice *self, GBytes *blob, GError **error) g_autoptr(GPtrArray) packets = NULL; /* notify UI */ - fu_device_set_status (FU_DEVICE (self), FWUPD_STATUS_DEVICE_WRITE); + fu_device_set_status (device, FWUPD_STATUS_DEVICE_WRITE); /* parse the file */ if (!dfu_firmware_parse_data (dfu_firmware, blob, @@ -505,7 +506,7 @@ fu_csr_device_download (FuCsrDevice *self, GBytes *blob, GError **error) return FALSE; /* update progress */ - fu_device_set_progress_full (FU_DEVICE (self), + fu_device_set_progress_full (device, (gsize) idx, (gsize) packets->len); } @@ -515,7 +516,7 @@ fu_csr_device_download (FuCsrDevice *self, GBytes *blob, GError **error) return FALSE; /* notify UI */ - fu_device_set_status (FU_DEVICE (self), FWUPD_STATUS_IDLE); + fu_device_set_status (device, FWUPD_STATUS_IDLE); return TRUE; } @@ -594,6 +595,7 @@ fu_csr_device_class_init (FuCsrDeviceClass *klass) FuDeviceClass *klass_device = FU_DEVICE_CLASS (klass); FuUsbDeviceClass *klass_usb_device = FU_USB_DEVICE_CLASS (klass); klass_device->to_string = fu_csr_device_to_string; + klass_device->write_firmware = fu_csr_device_download; klass_usb_device->open = fu_csr_device_open; klass_usb_device->close = fu_csr_device_close; klass_usb_device->probe = fu_csr_device_probe; diff --git a/plugins/csr/fu-csr-device.h b/plugins/csr/fu-csr-device.h index 2e301521a..927009fe0 100644 --- a/plugins/csr/fu-csr-device.h +++ b/plugins/csr/fu-csr-device.h @@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * - * Copyright (C) 2017 Richard Hughes + * Copyright (C) 2017-2018 Richard Hughes * * Licensed under the GNU Lesser General Public License Version 2.1 * @@ -41,9 +41,6 @@ typedef enum { FuCsrDevice *fu_csr_device_new (GUsbDevice *usb_device); gboolean fu_csr_device_attach (FuCsrDevice *self, GError **error); -gboolean fu_csr_device_download (FuCsrDevice *self, - GBytes *blob, - GError **error); GBytes *fu_csr_device_upload (FuCsrDevice *self, GError **error); void fu_csr_device_set_quirks (FuCsrDevice *self, diff --git a/plugins/csr/fu-csr-tool.c b/plugins/csr/fu-csr-tool.c index f5b490cdb..da065461b 100644 --- a/plugins/csr/fu-csr-tool.c +++ b/plugins/csr/fu-csr-tool.c @@ -296,7 +296,7 @@ fu_csr_tool_write (FuCsrToolPrivate *priv, gchar **values, GError **error) G_CALLBACK (fu_csr_tool_progress_cb), priv); g_signal_connect (device, "notify::progress", G_CALLBACK (fu_csr_tool_progress_cb), priv); - return fu_csr_device_download (device, blob, error); + return fu_device_write_firmware (FU_DEVICE (device), blob, error); } static gboolean diff --git a/plugins/csr/fu-plugin-csr.c b/plugins/csr/fu-plugin-csr.c index 7cf78a412..55a29c889 100644 --- a/plugins/csr/fu-plugin-csr.c +++ b/plugins/csr/fu-plugin-csr.c @@ -74,7 +74,7 @@ fu_plugin_update (FuPlugin *plugin, FuDevice *device, GBytes *blob_fw, locker = fu_device_locker_new (device, error); if (locker == NULL) return FALSE; - if (!fu_csr_device_download (FU_CSR_DEVICE (device), blob_fw, error)) + if (!fu_device_write_firmware (device, blob_fw, error)) return FALSE; return fu_csr_device_attach (FU_CSR_DEVICE (device), error); } diff --git a/plugins/ebitdo/fu-ebitdo-device.c b/plugins/ebitdo/fu-ebitdo-device.c index a3846ea1b..7edf55591 100644 --- a/plugins/ebitdo/fu-ebitdo-device.c +++ b/plugins/ebitdo/fu-ebitdo-device.c @@ -367,10 +367,11 @@ fu_ebitdo_device_get_serial (FuEbitdoDevice *device) return priv->serial; } -gboolean -fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw, GError **error) +static gboolean +fu_ebitdo_device_write_firmware (FuDevice *device, GBytes *fw, GError **error) { - FuEbitdoDevicePrivate *priv = GET_PRIVATE (device); + FuEbitdoDevice *self = FU_EBITDO_DEVICE (device); + FuEbitdoDevicePrivate *priv = GET_PRIVATE (self); FuEbitdoFirmwareHeader *hdr; const guint8 *payload_data; const guint chunk_sz = 32; @@ -422,8 +423,8 @@ fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw, GError **er } /* set up the firmware header */ - fu_device_set_status (FU_DEVICE (device), FWUPD_STATUS_DEVICE_WRITE); - if (!fu_ebitdo_device_send (device, + fu_device_set_status (device, FWUPD_STATUS_DEVICE_WRITE); + if (!fu_ebitdo_device_send (self, FU_EBITDO_PKT_TYPE_USER_CMD, FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA, FU_EBITDO_PKT_CMD_FW_UPDATE_HEADER, @@ -436,7 +437,7 @@ fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw, GError **er error_local->message); return FALSE; } - if (!fu_ebitdo_device_receive (device, NULL, 0, &error_local)) { + if (!fu_ebitdo_device_receive (self, NULL, 0, &error_local)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, @@ -453,8 +454,8 @@ fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw, GError **er g_debug ("writing %u bytes to 0x%04x of 0x%04x", chunk_sz, offset, payload_len); } - fu_device_set_progress_full (FU_DEVICE (device), offset, payload_len); - if (!fu_ebitdo_device_send (device, + fu_device_set_progress_full (device, offset, payload_len); + if (!fu_ebitdo_device_send (self, FU_EBITDO_PKT_TYPE_USER_CMD, FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA, FU_EBITDO_PKT_CMD_FW_UPDATE_DATA, @@ -467,7 +468,7 @@ fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw, GError **er offset, error_local->message); return FALSE; } - if (!fu_ebitdo_device_receive (device, NULL, 0, &error_local)) { + if (!fu_ebitdo_device_receive (self, NULL, 0, &error_local)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, @@ -478,7 +479,7 @@ fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw, GError **er } /* mark as complete */ - fu_device_set_progress_full (FU_DEVICE (device), payload_len, payload_len); + fu_device_set_progress_full (device, payload_len, payload_len); /* set the "encode id" which is likely a checksum, bluetooth pairing * or maybe just security-through-obscurity -- also note: @@ -486,7 +487,7 @@ fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw, GError **er serial_new[0] = priv->serial[0] ^ app_key_index[priv->serial[0] & 0x0f]; serial_new[1] = priv->serial[1] ^ app_key_index[priv->serial[1] & 0x0f]; serial_new[2] = priv->serial[2] ^ app_key_index[priv->serial[2] & 0x0f]; - if (!fu_ebitdo_device_send (device, + if (!fu_ebitdo_device_send (self, FU_EBITDO_PKT_TYPE_USER_CMD, FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA, FU_EBITDO_PKT_CMD_FW_SET_ENCODE_ID, @@ -502,7 +503,7 @@ fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw, GError **er } /* mark flash as successful */ - if (!fu_ebitdo_device_send (device, + if (!fu_ebitdo_device_send (self, FU_EBITDO_PKT_TYPE_USER_CMD, FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA, FU_EBITDO_PKT_CMD_FW_UPDATE_OK, @@ -515,7 +516,7 @@ fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw, GError **er error_local->message); return FALSE; } - if (!fu_ebitdo_device_receive (device, NULL, 0, &error_local)) { + if (!fu_ebitdo_device_receive (self, NULL, 0, &error_local)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, @@ -525,7 +526,7 @@ fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw, GError **er } /* success! */ - fu_device_set_status (FU_DEVICE (device), FWUPD_STATUS_IDLE); + fu_device_set_status (device, FWUPD_STATUS_IDLE); return TRUE; } @@ -582,7 +583,9 @@ fu_ebitdo_device_init (FuEbitdoDevice *device) static void fu_ebitdo_device_class_init (FuEbitdoDeviceClass *klass) { + FuDeviceClass *klass_device = FU_DEVICE_CLASS (klass); FuUsbDeviceClass *klass_usb_device = FU_USB_DEVICE_CLASS (klass); + klass_device->write_firmware = fu_ebitdo_device_write_firmware; klass_usb_device->open = fu_ebitdo_device_open; klass_usb_device->probe = fu_ebitdo_device_probe; } diff --git a/plugins/ebitdo/fu-ebitdo-device.h b/plugins/ebitdo/fu-ebitdo-device.h index 5b4d1350e..23a9ca9ff 100644 --- a/plugins/ebitdo/fu-ebitdo-device.h +++ b/plugins/ebitdo/fu-ebitdo-device.h @@ -43,11 +43,6 @@ FuEbitdoDevice *fu_ebitdo_device_new (GUsbDevice *usb_device); gboolean fu_ebitdo_device_is_bootloader (FuEbitdoDevice *device); const guint32 *fu_ebitdo_device_get_serial (FuEbitdoDevice *device); -/* object methods */ -gboolean fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, - GBytes *fw, - GError **error); - G_END_DECLS #endif /* __FU_EBITDO_DEVICE_H */ diff --git a/plugins/ebitdo/fu-ebitdo-tool.c b/plugins/ebitdo/fu-ebitdo-tool.c index 368517aac..f959f9f37 100644 --- a/plugins/ebitdo/fu-ebitdo-tool.c +++ b/plugins/ebitdo/fu-ebitdo-tool.c @@ -142,7 +142,7 @@ main (int argc, char **argv) fw = g_bytes_new (data, len); g_signal_connect (dev, "notify::progress", G_CALLBACK (fu_ebitdo_tool_progress_cb), NULL); - if (!fu_ebitdo_device_write_firmware (dev, fw, &error)) { + if (!fu_device_write_firmware (FU_DEVICE (dev), fw, &error)) { g_print ("Failed to write firmware: %s\n", error->message); return 1; } diff --git a/plugins/ebitdo/fu-plugin-ebitdo.c b/plugins/ebitdo/fu-plugin-ebitdo.c index cb3967bc2..236a6c2d7 100644 --- a/plugins/ebitdo/fu-plugin-ebitdo.c +++ b/plugins/ebitdo/fu-plugin-ebitdo.c @@ -69,7 +69,7 @@ fu_plugin_update (FuPlugin *plugin, locker = fu_device_locker_new (ebitdo_dev, error); if (locker == NULL) return FALSE; - if (!fu_ebitdo_device_write_firmware (ebitdo_dev, blob_fw, error)) + if (!fu_device_write_firmware (FU_DEVICE (ebitdo_dev), blob_fw, error)) return FALSE; /* when doing a soft-reboot the device does not re-enumerate properly diff --git a/plugins/unifying/fu-plugin-unifying.c b/plugins/unifying/fu-plugin-unifying.c index 5f91f7607..06c55ff7f 100644 --- a/plugins/unifying/fu-plugin-unifying.c +++ b/plugins/unifying/fu-plugin-unifying.c @@ -186,7 +186,7 @@ fu_plugin_update (FuPlugin *plugin, /* write the firmware */ fu_device_set_status (dev, FWUPD_STATUS_DEVICE_WRITE); - if (!lu_device_write_firmware (device, blob_fw, error)) + if (!fu_device_write_firmware (dev, blob_fw, error)) return FALSE; /* success */ diff --git a/plugins/unifying/lu-device.c b/plugins/unifying/lu-device.c index e1a381591..171108516 100644 --- a/plugins/unifying/lu-device.c +++ b/plugins/unifying/lu-device.c @@ -903,10 +903,11 @@ lu_device_attach (LuDevice *device, GError **error) return TRUE; } -gboolean -lu_device_write_firmware (LuDevice *device, GBytes *fw, GError **error) +static gboolean +lu_device_write_firmware (FuDevice *device, GBytes *fw, GError **error) { - LuDeviceClass *klass = LU_DEVICE_GET_CLASS (device); + LuDevice *self = LU_DEVICE (device); + LuDeviceClass *klass = LU_DEVICE_GET_CLASS (self); g_return_val_if_fail (LU_IS_DEVICE (device), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); @@ -926,12 +927,12 @@ lu_device_write_firmware (LuDevice *device, GBytes *fw, GError **error) G_IO_ERROR, G_IO_ERROR_FAILED, "not supported in %s", - lu_device_kind_to_string (lu_device_get_kind (device))); + lu_device_kind_to_string (lu_device_get_kind (self))); return FALSE; } /* call either nordic or texas vfunc */ - return klass->write_firmware (device, fw, error); + return klass->write_firmware (self, fw, error); } #ifndef HAVE_GUDEV_232 @@ -1076,6 +1077,7 @@ lu_device_class_init (LuDeviceClass *klass) object_class->get_property = lu_device_get_property; object_class->set_property = lu_device_set_property; klass_device->to_string = lu_device_to_string; + klass_device->write_firmware = lu_device_write_firmware; pspec = g_param_spec_uint ("kind", NULL, NULL, LU_DEVICE_KIND_UNKNOWN, diff --git a/plugins/unifying/lu-device.h b/plugins/unifying/lu-device.h index d0f539313..e1f1f9766 100644 --- a/plugins/unifying/lu-device.h +++ b/plugins/unifying/lu-device.h @@ -130,9 +130,6 @@ gboolean lu_device_probe (LuDevice *device, GError **error); gboolean lu_device_poll (LuDevice *device, GError **error); -gboolean lu_device_write_firmware (LuDevice *device, - GBytes *fw, - GError **error); gboolean lu_device_hidpp_send (LuDevice *device, LuHidppMsg *msg, guint timeout, diff --git a/plugins/unifying/lu-tool.c b/plugins/unifying/lu-tool.c index 3dafd0e24..f35024421 100644 --- a/plugins/unifying/lu-tool.c +++ b/plugins/unifying/lu-tool.c @@ -351,7 +351,7 @@ lu_tool_write (FuLuToolPrivate *priv, gchar **values, GError **error) fw = g_bytes_new (data, len); g_signal_connect (device, "notify::progress", G_CALLBACK (lu_write_progress_cb), NULL); - if (!lu_device_write_firmware (device, fw, error)) + if (!fu_device_write_firmware (FU_DEVICE (device), fw, error)) return FALSE; /* detach back into runtime */ diff --git a/src/fu-device.c b/src/fu-device.c index 32cfea40f..ddcd7a559 100644 --- a/src/fu-device.c +++ b/src/fu-device.c @@ -961,6 +961,39 @@ fu_device_get_release_default (FuDevice *device) return rel; } +/** + * fu_device_write_firmware: + * @device: A #FuDevice + * @fw: A #GBytes + * @error: A #GError + * + * Writes firmware to the device by calling a plugin-specific vfunc. + * + * Returns: %TRUE on success + * + * Since: 1.0.8 + **/ +gboolean +fu_device_write_firmware (FuDevice *device, GBytes *fw, GError **error) +{ + FuDeviceClass *klass = FU_DEVICE_GET_CLASS (device); + + g_return_val_if_fail (FU_IS_DEVICE (device), FALSE); + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + /* no plugin-specific method */ + if (klass->write_firmware == NULL) { + g_set_error_literal (error, + FWUPD_ERROR, + FWUPD_ERROR_NOT_SUPPORTED, + "not supported"); + return FALSE; + } + + /* call vfunc */ + return klass->write_firmware (device, fw, error); +} + static void fu_device_class_init (FuDeviceClass *klass) { diff --git a/src/fu-device.h b/src/fu-device.h index 3e8860a15..de415a231 100644 --- a/src/fu-device.h +++ b/src/fu-device.h @@ -37,8 +37,11 @@ struct _FuDeviceClass FwupdDeviceClass parent_class; void (*to_string) (FuDevice *device, GString *str); + gboolean (*write_firmware) (FuDevice *device, + GBytes *fw, + GError **error); /*< private >*/ - gpointer padding[30]; + gpointer padding[29]; }; /** @@ -161,6 +164,9 @@ void fu_device_set_quirks (FuDevice *device, FuQuirks *quirks); FuQuirks *fu_device_get_quirks (FuDevice *device); FwupdRelease *fu_device_get_release_default (FuDevice *device); +gboolean fu_device_write_firmware (FuDevice *device, + GBytes *fw, + GError **error); G_END_DECLS