altos: Rename FuDeviceAltos to FuAltosDevice

This is what most programmers expect and makes it clear what it derives.
This commit is contained in:
Richard Hughes 2017-11-13 13:58:37 +00:00
parent ba6391e98d
commit a142bb15b6
5 changed files with 130 additions and 130 deletions

View File

@ -29,12 +29,12 @@
#include <termios.h> #include <termios.h>
#include <errno.h> #include <errno.h>
#include "fu-altos-device.h"
#include "fu-altos-firmware.h" #include "fu-altos-firmware.h"
#include "fu-device-altos.h"
typedef struct typedef struct
{ {
FuDeviceAltosKind kind; FuAltosDeviceKind kind;
GUsbDevice *usb_device; GUsbDevice *usb_device;
guint32 serial[9]; guint32 serial[9];
gchar *guid; gchar *guid;
@ -44,39 +44,39 @@ typedef struct
guint64 addr_bound; guint64 addr_bound;
struct termios tty_termios; struct termios tty_termios;
gint tty_fd; gint tty_fd;
} FuDeviceAltosPrivate; } FuAltosDevicePrivate;
G_DEFINE_TYPE_WITH_PRIVATE (FuDeviceAltos, fu_device_altos, FU_TYPE_DEVICE) G_DEFINE_TYPE_WITH_PRIVATE (FuAltosDevice, fu_altos_device, FU_TYPE_DEVICE)
#define GET_PRIVATE(o) (fu_device_altos_get_instance_private (o)) #define GET_PRIVATE(o) (fu_altos_device_get_instance_private (o))
#ifndef HAVE_GUDEV_232 #ifndef HAVE_GUDEV_232
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GUdevClient, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC(GUdevClient, g_object_unref)
#endif #endif
/** /**
* fu_device_altos_kind_from_string: * fu_altos_device_kind_from_string:
* @kind: the string. * @kind: the string.
* *
* Converts the text representation to an enumerated value. * Converts the text representation to an enumerated value.
* *
* Returns: (transfer full): a #FuDeviceAltosKind, or %FU_DEVICE_ALTOS_KIND_UNKNOWN for unknown. * Returns: (transfer full): a #FuAltosDeviceKind, or %FU_ALTOS_DEVICE_KIND_UNKNOWN for unknown.
* *
* Since: 0.1.0 * Since: 0.1.0
**/ **/
FuDeviceAltosKind FuAltosDeviceKind
fu_device_altos_kind_from_string (const gchar *kind) fu_altos_device_kind_from_string (const gchar *kind)
{ {
if (g_strcmp0 (kind, "BOOTLOADER") == 0) if (g_strcmp0 (kind, "BOOTLOADER") == 0)
return FU_DEVICE_ALTOS_KIND_BOOTLOADER; return FU_ALTOS_DEVICE_KIND_BOOTLOADER;
if (g_strcmp0 (kind, "CHAOSKEY") == 0) if (g_strcmp0 (kind, "CHAOSKEY") == 0)
return FU_DEVICE_ALTOS_KIND_CHAOSKEY; return FU_ALTOS_DEVICE_KIND_CHAOSKEY;
return FU_DEVICE_ALTOS_KIND_UNKNOWN; return FU_ALTOS_DEVICE_KIND_UNKNOWN;
} }
/** /**
* fu_device_altos_kind_to_string: * fu_altos_device_kind_to_string:
* @kind: the #FuDeviceAltosKind. * @kind: the #FuAltosDeviceKind.
* *
* Converts the enumerated value to an text representation. * Converts the enumerated value to an text representation.
* *
@ -85,20 +85,20 @@ fu_device_altos_kind_from_string (const gchar *kind)
* Since: 0.1.0 * Since: 0.1.0
**/ **/
const gchar * const gchar *
fu_device_altos_kind_to_string (FuDeviceAltosKind kind) fu_altos_device_kind_to_string (FuAltosDeviceKind kind)
{ {
if (kind == FU_DEVICE_ALTOS_KIND_BOOTLOADER) if (kind == FU_ALTOS_DEVICE_KIND_BOOTLOADER)
return "BOOTLOADER"; return "BOOTLOADER";
if (kind == FU_DEVICE_ALTOS_KIND_CHAOSKEY) if (kind == FU_ALTOS_DEVICE_KIND_CHAOSKEY)
return "CHAOSKEY"; return "CHAOSKEY";
return NULL; return NULL;
} }
static void static void
fu_device_altos_finalize (GObject *object) fu_altos_device_finalize (GObject *object)
{ {
FuDeviceAltos *device = FU_DEVICE_ALTOS (object); FuAltosDevice *device = FU_ALTOS_DEVICE (object);
FuDeviceAltosPrivate *priv = GET_PRIVATE (device); FuAltosDevicePrivate *priv = GET_PRIVATE (device);
g_free (priv->guid); g_free (priv->guid);
g_free (priv->tty); g_free (priv->tty);
@ -106,32 +106,32 @@ fu_device_altos_finalize (GObject *object)
if (priv->usb_device != NULL) if (priv->usb_device != NULL)
g_object_unref (priv->usb_device); g_object_unref (priv->usb_device);
G_OBJECT_CLASS (fu_device_altos_parent_class)->finalize (object); G_OBJECT_CLASS (fu_altos_device_parent_class)->finalize (object);
} }
static void static void
fu_device_altos_init (FuDeviceAltos *device) fu_altos_device_init (FuAltosDevice *device)
{ {
} }
static void static void
fu_device_altos_class_init (FuDeviceAltosClass *klass) fu_altos_device_class_init (FuAltosDeviceClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = fu_device_altos_finalize; object_class->finalize = fu_altos_device_finalize;
} }
FuDeviceAltosKind FuAltosDeviceKind
fu_device_altos_get_kind (FuDeviceAltos *device) fu_altos_device_get_kind (FuAltosDevice *device)
{ {
FuDeviceAltosPrivate *priv = GET_PRIVATE (device); FuAltosDevicePrivate *priv = GET_PRIVATE (device);
return priv->kind; return priv->kind;
} }
static gboolean static gboolean
fu_device_altos_find_tty (FuDeviceAltos *device, GError **error) fu_altos_device_find_tty (FuAltosDevice *device, GError **error)
{ {
FuDeviceAltosPrivate *priv = GET_PRIVATE (device); FuAltosDevicePrivate *priv = GET_PRIVATE (device);
g_autoptr(GList) devices = NULL; g_autoptr(GList) devices = NULL;
g_autoptr(GUdevClient) gudev_client = g_udev_client_new (NULL); g_autoptr(GUdevClient) gudev_client = g_udev_client_new (NULL);
@ -177,12 +177,12 @@ fu_device_altos_find_tty (FuDeviceAltos *device, GError **error)
} }
static gboolean static gboolean
fu_device_altos_tty_write (FuDeviceAltos *device, fu_altos_device_tty_write (FuAltosDevice *device,
const gchar *data, const gchar *data,
gssize data_len, gssize data_len,
GError **error) GError **error)
{ {
FuDeviceAltosPrivate *priv = GET_PRIVATE (device); FuAltosDevicePrivate *priv = GET_PRIVATE (device);
gint rc; gint rc;
gssize idx = 0; gssize idx = 0;
guint timeout_ms = 500; guint timeout_ms = 500;
@ -240,12 +240,12 @@ fu_device_altos_tty_write (FuDeviceAltos *device,
} }
static GString * static GString *
fu_device_altos_tty_read (FuDeviceAltos *device, fu_altos_device_tty_read (FuAltosDevice *device,
guint timeout_ms, guint timeout_ms,
gssize max_size, gssize max_size,
GError **error) GError **error)
{ {
FuDeviceAltosPrivate *priv = GET_PRIVATE (device); FuAltosDevicePrivate *priv = GET_PRIVATE (device);
gint rc; gint rc;
struct pollfd fds; struct pollfd fds;
g_autoptr(GString) str = g_string_new (NULL); g_autoptr(GString) str = g_string_new (NULL);
@ -333,9 +333,9 @@ fu_device_altos_tty_read (FuDeviceAltos *device,
} }
static gboolean static gboolean
fu_device_altos_tty_open (FuDeviceAltos *device, GError **error) fu_altos_device_tty_open (FuAltosDevice *device, GError **error)
{ {
FuDeviceAltosPrivate *priv = GET_PRIVATE (device); FuAltosDevicePrivate *priv = GET_PRIVATE (device);
struct termios termios; struct termios termios;
g_autoptr(GString) str = NULL; g_autoptr(GString) str = NULL;
@ -385,7 +385,7 @@ fu_device_altos_tty_open (FuDeviceAltos *device, GError **error)
} }
/* dump any pending input */ /* dump any pending input */
str = fu_device_altos_tty_read (device, 50, -1, NULL); str = fu_altos_device_tty_read (device, 50, -1, NULL);
if (str != NULL) if (str != NULL)
g_debug ("dumping pending buffer: %s", str->str); g_debug ("dumping pending buffer: %s", str->str);
@ -393,9 +393,9 @@ fu_device_altos_tty_open (FuDeviceAltos *device, GError **error)
} }
static gboolean static gboolean
fu_device_altos_tty_close (FuDeviceAltos *device, GError **error) fu_altos_device_tty_close (FuAltosDevice *device, GError **error)
{ {
FuDeviceAltosPrivate *priv = GET_PRIVATE (device); FuAltosDevicePrivate *priv = GET_PRIVATE (device);
tcsetattr (priv->tty_fd, TCSAFLUSH, &priv->tty_termios); tcsetattr (priv->tty_fd, TCSAFLUSH, &priv->tty_termios);
close (priv->tty_fd); close (priv->tty_fd);
@ -404,42 +404,42 @@ fu_device_altos_tty_close (FuDeviceAltos *device, GError **error)
} }
static GString * static GString *
fu_device_altos_read_page (FuDeviceAltos *device, guint address, GError **error) fu_altos_device_read_page (FuAltosDevice *device, guint address, GError **error)
{ {
g_autoptr(GString) str = NULL; g_autoptr(GString) str = NULL;
g_autofree gchar *cmd = g_strdup_printf ("R %x\n", address); g_autofree gchar *cmd = g_strdup_printf ("R %x\n", address);
if (!fu_device_altos_tty_write (device, cmd, -1, error)) if (!fu_altos_device_tty_write (device, cmd, -1, error))
return NULL; return NULL;
str = fu_device_altos_tty_read (device, 1500, 256, error); str = fu_altos_device_tty_read (device, 1500, 256, error);
if (str == NULL) if (str == NULL)
return NULL; return NULL;
return g_steal_pointer (&str); return g_steal_pointer (&str);
} }
static gboolean static gboolean
fu_device_altos_write_page (FuDeviceAltos *device, fu_altos_device_write_page (FuAltosDevice *device,
guint address, guint address,
const guint8 *data, const guint8 *data,
guint data_len, guint data_len,
GError **error) GError **error)
{ {
g_autofree gchar *cmd = g_strdup_printf ("W %x\n", address); g_autofree gchar *cmd = g_strdup_printf ("W %x\n", address);
if (!fu_device_altos_tty_write (device, cmd, -1, error)) if (!fu_altos_device_tty_write (device, cmd, -1, error))
return FALSE; return FALSE;
if (!fu_device_altos_tty_write (device, (const gchar *) data, data_len, error)) if (!fu_altos_device_tty_write (device, (const gchar *) data, data_len, error))
return FALSE; return FALSE;
return TRUE; return TRUE;
} }
gboolean gboolean
fu_device_altos_write_firmware (FuDeviceAltos *device, fu_altos_device_write_firmware (FuAltosDevice *device,
GBytes *fw, GBytes *fw,
FuDeviceAltosWriteFirmwareFlag flags, FuAltosDeviceWriteFirmwareFlag flags,
GFileProgressCallback progress_cb, GFileProgressCallback progress_cb,
gpointer progress_data, gpointer progress_data,
GError **error) GError **error)
{ {
FuDeviceAltosPrivate *priv = GET_PRIVATE (device); FuAltosDevicePrivate *priv = GET_PRIVATE (device);
GBytes *fw_blob; GBytes *fw_blob;
const gchar *data; const gchar *data;
const gsize data_len; const gsize data_len;
@ -449,7 +449,7 @@ fu_device_altos_write_firmware (FuDeviceAltos *device,
g_autoptr(GString) buf = g_string_new (NULL); g_autoptr(GString) buf = g_string_new (NULL);
/* check kind */ /* check kind */
if (priv->kind != FU_DEVICE_ALTOS_KIND_BOOTLOADER) { if (priv->kind != FU_ALTOS_DEVICE_KIND_BOOTLOADER) {
g_set_error_literal (error, g_set_error_literal (error,
FWUPD_ERROR, FWUPD_ERROR,
FWUPD_ERROR_NOT_SUPPORTED, FWUPD_ERROR_NOT_SUPPORTED,
@ -507,8 +507,8 @@ fu_device_altos_write_firmware (FuDeviceAltos *device,
/* open tty for download */ /* open tty for download */
locker = fu_device_locker_new_full (device, locker = fu_device_locker_new_full (device,
(FuDeviceLockerFunc) fu_device_altos_tty_open, (FuDeviceLockerFunc) fu_altos_device_tty_open,
(FuDeviceLockerFunc) fu_device_altos_tty_close, (FuDeviceLockerFunc) fu_altos_device_tty_close,
error); error);
if (locker == NULL) if (locker == NULL)
return FALSE; return FALSE;
@ -526,7 +526,7 @@ fu_device_altos_write_firmware (FuDeviceAltos *device,
} }
/* verify data from device */ /* verify data from device */
if (!fu_device_altos_write_page (device, if (!fu_altos_device_write_page (device,
priv->addr_base + i, priv->addr_base + i,
buf_tmp, buf_tmp,
0x100, 0x100,
@ -534,7 +534,7 @@ fu_device_altos_write_firmware (FuDeviceAltos *device,
return FALSE; return FALSE;
/* verify data written on device */ /* verify data written on device */
str = fu_device_altos_read_page (device, str = fu_altos_device_read_page (device,
priv->addr_base + i, priv->addr_base + i,
error); error);
if (str == NULL) if (str == NULL)
@ -567,8 +567,8 @@ fu_device_altos_write_firmware (FuDeviceAltos *device,
} }
/* go to application mode */ /* go to application mode */
if (flags & FU_DEVICE_ALTOS_WRITE_FIRMWARE_FLAG_REBOOT) { if (flags & FU_ALTOS_DEVICE_WRITE_FIRMWARE_FLAG_REBOOT) {
if (!fu_device_altos_tty_write (device, "a\n", -1, error)) if (!fu_altos_device_tty_write (device, "a\n", -1, error))
return FALSE; return FALSE;
} }
@ -584,18 +584,18 @@ fu_device_altos_write_firmware (FuDeviceAltos *device,
} }
GBytes * GBytes *
fu_device_altos_read_firmware (FuDeviceAltos *device, fu_altos_device_read_firmware (FuAltosDevice *device,
GFileProgressCallback progress_cb, GFileProgressCallback progress_cb,
gpointer progress_data, gpointer progress_data,
GError **error) GError **error)
{ {
FuDeviceAltosPrivate *priv = GET_PRIVATE (device); FuAltosDevicePrivate *priv = GET_PRIVATE (device);
guint flash_len; guint flash_len;
g_autoptr(FuDeviceLocker) locker = NULL; g_autoptr(FuDeviceLocker) locker = NULL;
g_autoptr(GString) buf = g_string_new (NULL); g_autoptr(GString) buf = g_string_new (NULL);
/* check kind */ /* check kind */
if (priv->kind != FU_DEVICE_ALTOS_KIND_BOOTLOADER) { if (priv->kind != FU_ALTOS_DEVICE_KIND_BOOTLOADER) {
g_set_error_literal (error, g_set_error_literal (error,
FWUPD_ERROR, FWUPD_ERROR,
FWUPD_ERROR_NOT_SUPPORTED, FWUPD_ERROR_NOT_SUPPORTED,
@ -624,8 +624,8 @@ fu_device_altos_read_firmware (FuDeviceAltos *device,
/* open tty for download */ /* open tty for download */
locker = fu_device_locker_new_full (device, locker = fu_device_locker_new_full (device,
(FuDeviceLockerFunc) fu_device_altos_tty_open, (FuDeviceLockerFunc) fu_altos_device_tty_open,
(FuDeviceLockerFunc) fu_device_altos_tty_close, (FuDeviceLockerFunc) fu_altos_device_tty_close,
error); error);
if (locker == NULL) if (locker == NULL)
return NULL; return NULL;
@ -633,7 +633,7 @@ fu_device_altos_read_firmware (FuDeviceAltos *device,
g_autoptr(GString) str = NULL; g_autoptr(GString) str = NULL;
/* request data from device */ /* request data from device */
str = fu_device_altos_read_page (device, i, error); str = fu_altos_device_read_page (device, i, error);
if (str == NULL) if (str == NULL)
return NULL; return NULL;
@ -651,27 +651,27 @@ fu_device_altos_read_firmware (FuDeviceAltos *device,
} }
static gboolean static gboolean
fu_device_altos_probe_bootloader (FuDeviceAltos *device, GError **error) fu_altos_device_probe_bootloader (FuAltosDevice *device, GError **error)
{ {
FuDeviceAltosPrivate *priv = GET_PRIVATE (device); FuAltosDevicePrivate *priv = GET_PRIVATE (device);
g_autoptr(FuDeviceLocker) locker = NULL; g_autoptr(FuDeviceLocker) locker = NULL;
g_auto(GStrv) lines = NULL; g_auto(GStrv) lines = NULL;
g_autoptr(GString) str = NULL; g_autoptr(GString) str = NULL;
/* get tty for upload */ /* get tty for upload */
if (!fu_device_altos_find_tty (device, error)) if (!fu_altos_device_find_tty (device, error))
return FALSE; return FALSE;
locker = fu_device_locker_new_full (device, locker = fu_device_locker_new_full (device,
(FuDeviceLockerFunc) fu_device_altos_tty_open, (FuDeviceLockerFunc) fu_altos_device_tty_open,
(FuDeviceLockerFunc) fu_device_altos_tty_close, (FuDeviceLockerFunc) fu_altos_device_tty_close,
error); error);
if (locker == NULL) if (locker == NULL)
return FALSE; return FALSE;
/* get the version information */ /* get the version information */
if (!fu_device_altos_tty_write (device, "v\n", -1, error)) if (!fu_altos_device_tty_write (device, "v\n", -1, error))
return FALSE; return FALSE;
str = fu_device_altos_tty_read (device, 100, -1, error); str = fu_altos_device_tty_read (device, 100, -1, error);
if (str == NULL) if (str == NULL)
return FALSE; return FALSE;
@ -719,16 +719,16 @@ fu_device_altos_probe_bootloader (FuDeviceAltos *device, GError **error)
} }
gboolean gboolean
fu_device_altos_probe (FuDeviceAltos *device, GError **error) fu_altos_device_probe (FuAltosDevice *device, GError **error)
{ {
FuDeviceAltosPrivate *priv = GET_PRIVATE (device); FuAltosDevicePrivate *priv = GET_PRIVATE (device);
/* bootloader uses tty */ /* bootloader uses tty */
if (priv->kind == FU_DEVICE_ALTOS_KIND_BOOTLOADER) if (priv->kind == FU_ALTOS_DEVICE_KIND_BOOTLOADER)
return fu_device_altos_probe_bootloader (device, error); return fu_altos_device_probe_bootloader (device, error);
/* get version */ /* get version */
if (priv->kind == FU_DEVICE_ALTOS_KIND_CHAOSKEY) { if (priv->kind == FU_ALTOS_DEVICE_KIND_CHAOSKEY) {
const gchar *version_prefix = "ChaosKey-hw-1.0-sw-"; const gchar *version_prefix = "ChaosKey-hw-1.0-sw-";
guint8 version_idx; guint8 version_idx;
g_autofree gchar *version = NULL; g_autofree gchar *version = NULL;
@ -763,9 +763,9 @@ fu_device_altos_probe (FuDeviceAltos *device, GError **error)
/* now with kind and usb_device set */ /* now with kind and usb_device set */
static void static void
fu_device_altos_init_real (FuDeviceAltos *device) fu_altos_device_init_real (FuAltosDevice *device)
{ {
FuDeviceAltosPrivate *priv = GET_PRIVATE (device); FuAltosDevicePrivate *priv = GET_PRIVATE (device);
g_autofree gchar *devid1 = NULL; g_autofree gchar *devid1 = NULL;
g_autofree gchar *vendor_id = NULL; g_autofree gchar *vendor_id = NULL;
@ -782,10 +782,10 @@ fu_device_altos_init_real (FuDeviceAltos *device)
/* set name */ /* set name */
switch (priv->kind) { switch (priv->kind) {
case FU_DEVICE_ALTOS_KIND_BOOTLOADER: case FU_ALTOS_DEVICE_KIND_BOOTLOADER:
fu_device_set_name (FU_DEVICE (device), "Altos [bootloader]"); fu_device_set_name (FU_DEVICE (device), "Altos [bootloader]");
break; break;
case FU_DEVICE_ALTOS_KIND_CHAOSKEY: case FU_ALTOS_DEVICE_KIND_CHAOSKEY:
fu_device_set_name (FU_DEVICE (device), "Altos ChaosKey"); fu_device_set_name (FU_DEVICE (device), "Altos ChaosKey");
break; break;
default: default:
@ -805,7 +805,7 @@ fu_device_altos_init_real (FuDeviceAltos *device)
g_debug ("saving runtime GUID of %s", devid1); g_debug ("saving runtime GUID of %s", devid1);
/* only the bootloader can do the update */ /* only the bootloader can do the update */
if (priv->kind != FU_DEVICE_ALTOS_KIND_BOOTLOADER) { if (priv->kind != FU_ALTOS_DEVICE_KIND_BOOTLOADER) {
fu_device_add_flag (FU_DEVICE (device), fu_device_add_flag (FU_DEVICE (device),
FWUPD_DEVICE_FLAG_NEEDS_BOOTLOADER); FWUPD_DEVICE_FLAG_NEEDS_BOOTLOADER);
} }
@ -814,18 +814,18 @@ fu_device_altos_init_real (FuDeviceAltos *device)
typedef struct { typedef struct {
guint16 vid; guint16 vid;
guint16 pid; guint16 pid;
FuDeviceAltosKind kind; FuAltosDeviceKind kind;
} FuDeviceAltosVidPid; } FuAltosDeviceVidPid;
FuDeviceAltos * FuAltosDevice *
fu_device_altos_new (GUsbDevice *usb_device) fu_altos_device_new (GUsbDevice *usb_device)
{ {
FuDeviceAltos *device; FuAltosDevice *device;
FuDeviceAltosPrivate *priv; FuAltosDevicePrivate *priv;
const FuDeviceAltosVidPid vidpids[] = { const FuAltosDeviceVidPid vidpids[] = {
{ 0xfffe, 0x000a, FU_DEVICE_ALTOS_KIND_BOOTLOADER }, { 0xfffe, 0x000a, FU_ALTOS_DEVICE_KIND_BOOTLOADER },
{ 0x1d50, 0x60c6, FU_DEVICE_ALTOS_KIND_CHAOSKEY }, { 0x1d50, 0x60c6, FU_ALTOS_DEVICE_KIND_CHAOSKEY },
{ 0x0000, 0x0000, FU_DEVICE_ALTOS_KIND_UNKNOWN } { 0x0000, 0x0000, FU_ALTOS_DEVICE_KIND_UNKNOWN }
}; };
/* set kind */ /* set kind */
@ -834,11 +834,11 @@ fu_device_altos_new (GUsbDevice *usb_device)
continue; continue;
if (g_usb_device_get_pid (usb_device) != vidpids[j].pid) if (g_usb_device_get_pid (usb_device) != vidpids[j].pid)
continue; continue;
device = g_object_new (FU_TYPE_DEVICE_ALTOS, NULL); device = g_object_new (FU_TYPE_ALTOS_DEVICE, NULL);
priv = GET_PRIVATE (device); priv = GET_PRIVATE (device);
priv->kind = vidpids[j].kind; priv->kind = vidpids[j].kind;
priv->usb_device = g_object_ref (usb_device); priv->usb_device = g_object_ref (usb_device);
fu_device_altos_init_real (device); fu_altos_device_init_real (device);
return device; return device;
} }
return NULL; return NULL;

View File

@ -19,8 +19,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#ifndef __FU_DEVICE_ALTOS_H #ifndef __FU_ALTOS_DEVICE_H
#define __FU_DEVICE_ALTOS_H #define __FU_ALTOS_DEVICE_H
#include <glib-object.h> #include <glib-object.h>
#include <gusb.h> #include <gusb.h>
@ -29,46 +29,46 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define FU_TYPE_DEVICE_ALTOS (fu_device_altos_get_type ()) #define FU_TYPE_ALTOS_DEVICE (fu_altos_device_get_type ())
G_DECLARE_DERIVABLE_TYPE (FuDeviceAltos, fu_device_altos, FU, DEVICE_ALTOS, FuDevice) G_DECLARE_DERIVABLE_TYPE (FuAltosDevice, fu_altos_device, FU, ALTOS_DEVICE, FuDevice)
struct _FuDeviceAltosClass struct _FuAltosDeviceClass
{ {
FuDeviceClass parent_class; FuDeviceClass parent_class;
}; };
typedef enum { typedef enum {
FU_DEVICE_ALTOS_KIND_UNKNOWN, FU_ALTOS_DEVICE_KIND_UNKNOWN,
FU_DEVICE_ALTOS_KIND_BOOTLOADER, FU_ALTOS_DEVICE_KIND_BOOTLOADER,
FU_DEVICE_ALTOS_KIND_CHAOSKEY, FU_ALTOS_DEVICE_KIND_CHAOSKEY,
/*< private >*/ /*< private >*/
FU_DEVICE_ALTOS_KIND_LAST FU_ALTOS_DEVICE_KIND_LAST
} FuDeviceAltosKind; } FuAltosDeviceKind;
typedef enum { typedef enum {
FU_DEVICE_ALTOS_WRITE_FIRMWARE_FLAG_NONE = 0, FU_ALTOS_DEVICE_WRITE_FIRMWARE_FLAG_NONE = 0,
FU_DEVICE_ALTOS_WRITE_FIRMWARE_FLAG_REBOOT = 1 << 0, FU_ALTOS_DEVICE_WRITE_FIRMWARE_FLAG_REBOOT = 1 << 0,
/*< private >*/ /*< private >*/
FU_DEVICE_ALTOS_WRITE_FIRMWARE_FLAG_LAST FU_ALTOS_DEVICE_WRITE_FIRMWARE_FLAG_LAST
} FuDeviceAltosWriteFirmwareFlag; } FuAltosDeviceWriteFirmwareFlag;
FuDeviceAltos *fu_device_altos_new (GUsbDevice *usb_device); FuAltosDevice *fu_altos_device_new (GUsbDevice *usb_device);
FuDeviceAltosKind fu_device_altos_kind_from_string (const gchar *kind); FuAltosDeviceKind fu_altos_device_kind_from_string (const gchar *kind);
const gchar *fu_device_altos_kind_to_string (FuDeviceAltosKind kind); const gchar *fu_altos_device_kind_to_string (FuAltosDeviceKind kind);
FuDeviceAltosKind fu_device_altos_get_kind (FuDeviceAltos *device); FuAltosDeviceKind fu_altos_device_get_kind (FuAltosDevice *device);
gboolean fu_device_altos_probe (FuDeviceAltos *device, gboolean fu_altos_device_probe (FuAltosDevice *device,
GError **error); GError **error);
gboolean fu_device_altos_write_firmware (FuDeviceAltos *device, gboolean fu_altos_device_write_firmware (FuAltosDevice *device,
GBytes *fw, GBytes *fw,
FuDeviceAltosWriteFirmwareFlag flags, FuAltosDeviceWriteFirmwareFlag flags,
GFileProgressCallback progress_cb, GFileProgressCallback progress_cb,
gpointer progress_data, gpointer progress_data,
GError **error); GError **error);
GBytes *fu_device_altos_read_firmware (FuDeviceAltos *device, GBytes *fu_altos_device_read_firmware (FuAltosDevice *device,
GFileProgressCallback progress_cb, GFileProgressCallback progress_cb,
gpointer progress_data, gpointer progress_data,
GError **error); GError **error);
G_END_DECLS G_END_DECLS
#endif /* __FU_DEVICE_ALTOS_H */ #endif /* __FU_ALTOS_DEVICE_H */

View File

@ -21,7 +21,7 @@
#include "config.h" #include "config.h"
#include "fu-device-altos.h" #include "fu-altos-device.h"
static void static void
fu_altos_tool_write_progress_cb (goffset current, goffset total, gpointer user_data) fu_altos_tool_write_progress_cb (goffset current, goffset total, gpointer user_data)
@ -38,7 +38,7 @@ main (int argc, char **argv)
{ {
gsize len; gsize len;
g_autofree guint8 *data = NULL; g_autofree guint8 *data = NULL;
g_autoptr(FuDeviceAltos) dev = NULL; g_autoptr(FuAltosDevice) dev = NULL;
g_autoptr(GBytes) fw = NULL; g_autoptr(GBytes) fw = NULL;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
g_autoptr(GPtrArray) devices = NULL; g_autoptr(GPtrArray) devices = NULL;
@ -62,10 +62,10 @@ main (int argc, char **argv)
devices = g_usb_context_get_devices (usb_ctx); devices = g_usb_context_get_devices (usb_ctx);
for (guint i = 0; i < devices->len; i++) { for (guint i = 0; i < devices->len; i++) {
GUsbDevice *usb_dev_tmp = g_ptr_array_index (devices, i); GUsbDevice *usb_dev_tmp = g_ptr_array_index (devices, i);
g_autoptr(FuDeviceAltos) dev_tmp = fu_device_altos_new (usb_dev_tmp); g_autoptr(FuAltosDevice) dev_tmp = fu_altos_device_new (usb_dev_tmp);
if (dev_tmp == NULL) if (dev_tmp == NULL)
continue; continue;
if (fu_device_altos_get_kind (dev_tmp) == FU_DEVICE_ALTOS_KIND_BOOTLOADER) { if (fu_altos_device_get_kind (dev_tmp) == FU_ALTOS_DEVICE_KIND_BOOTLOADER) {
dev = g_object_ref (dev_tmp); dev = g_object_ref (dev_tmp);
break; break;
} }
@ -77,10 +77,10 @@ main (int argc, char **argv)
return 1; return 1;
} }
g_debug ("found %s", g_debug ("found %s",
fu_device_altos_kind_to_string (fu_device_altos_get_kind (dev))); fu_altos_device_kind_to_string (fu_altos_device_get_kind (dev)));
/* open device */ /* open device */
if (!fu_device_altos_probe (dev, &error)) { if (!fu_altos_device_probe (dev, &error)) {
g_print ("Failed to probe device: %s\n", error->message); g_print ("Failed to probe device: %s\n", error->message);
return 1; return 1;
} }
@ -94,8 +94,8 @@ main (int argc, char **argv)
/* update with data blob */ /* update with data blob */
fw = g_bytes_new (data, len); fw = g_bytes_new (data, len);
if (!fu_device_altos_write_firmware (dev, fw, if (!fu_altos_device_write_firmware (dev, fw,
FU_DEVICE_ALTOS_WRITE_FIRMWARE_FLAG_NONE, FU_ALTOS_DEVICE_WRITE_FIRMWARE_FLAG_NONE,
fu_altos_tool_write_progress_cb, NULL, fu_altos_tool_write_progress_cb, NULL,
&error)) { &error)) {
g_print ("Failed to write firmware: %s\n", error->message); g_print ("Failed to write firmware: %s\n", error->message);

View File

@ -26,7 +26,7 @@
#include "fu-plugin.h" #include "fu-plugin.h"
#include "fu-plugin-vfuncs.h" #include "fu-plugin-vfuncs.h"
#include "fu-device-altos.h" #include "fu-altos-device.h"
static gboolean static gboolean
fu_plugin_altos_device_added (FuPlugin *plugin, fu_plugin_altos_device_added (FuPlugin *plugin,
@ -37,7 +37,7 @@ fu_plugin_altos_device_added (FuPlugin *plugin,
g_autofree gchar *runtime_id = NULL; g_autofree gchar *runtime_id = NULL;
g_autoptr(AsProfile) profile = as_profile_new (); g_autoptr(AsProfile) profile = as_profile_new ();
g_autoptr(AsProfileTask) ptask = NULL; g_autoptr(AsProfileTask) ptask = NULL;
g_autoptr(FuDeviceAltos) dev = NULL; g_autoptr(FuAltosDevice) dev = NULL;
/* profile */ /* profile */
ptask = as_profile_start (profile, "FuPluginAltos:added{%04x:%04x}", ptask = as_profile_start (profile, "FuPluginAltos:added{%04x:%04x}",
@ -46,7 +46,7 @@ fu_plugin_altos_device_added (FuPlugin *plugin,
g_assert (ptask != NULL); g_assert (ptask != NULL);
/* get kind */ /* get kind */
dev = fu_device_altos_new (usb_device); dev = fu_altos_device_new (usb_device);
if (dev == NULL) { if (dev == NULL) {
g_set_error_literal (error, g_set_error_literal (error,
FWUPD_ERROR, FWUPD_ERROR,
@ -60,12 +60,12 @@ fu_plugin_altos_device_added (FuPlugin *plugin,
fu_device_set_id (FU_DEVICE (dev), platform_id); fu_device_set_id (FU_DEVICE (dev), platform_id);
/* get device properties */ /* get device properties */
if (!fu_device_altos_probe (dev, error)) if (!fu_altos_device_probe (dev, error))
return FALSE; return FALSE;
/* only the bootloader can do the update */ /* only the bootloader can do the update */
runtime_id = g_strdup_printf ("%s-runtime", platform_id); runtime_id = g_strdup_printf ("%s-runtime", platform_id);
if (fu_device_altos_get_kind (dev) == FU_DEVICE_ALTOS_KIND_BOOTLOADER) { if (fu_altos_device_get_kind (dev) == FU_ALTOS_DEVICE_KIND_BOOTLOADER) {
FuDevice *dev_runtime; FuDevice *dev_runtime;
dev_runtime = fu_plugin_cache_lookup (plugin, runtime_id); dev_runtime = fu_plugin_cache_lookup (plugin, runtime_id);
if (dev_runtime != NULL) { if (dev_runtime != NULL) {
@ -111,7 +111,7 @@ fu_plugin_verify (FuPlugin *plugin,
/* get data */ /* get data */
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_VERIFY); fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_VERIFY);
blob_fw = fu_device_altos_read_firmware (FU_DEVICE_ALTOS (dev), blob_fw = fu_altos_device_read_firmware (FU_ALTOS_DEVICE (dev),
fu_plugin_altos_progress_cb, fu_plugin_altos_progress_cb,
plugin, plugin,
error); error);
@ -134,9 +134,9 @@ fu_plugin_update (FuPlugin *plugin,
GError **error) GError **error)
{ {
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_WRITE); fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_WRITE);
if (!fu_device_altos_write_firmware (FU_DEVICE_ALTOS (dev), if (!fu_altos_device_write_firmware (FU_ALTOS_DEVICE (dev),
blob_fw, blob_fw,
FU_DEVICE_ALTOS_WRITE_FIRMWARE_FLAG_REBOOT, FU_ALTOS_DEVICE_WRITE_FIRMWARE_FLAG_REBOOT,
fu_plugin_altos_progress_cb, fu_plugin_altos_progress_cb,
plugin, plugin,
error)) { error)) {

View File

@ -2,9 +2,9 @@ cargs = ['-DG_LOG_DOMAIN="FuPluginAltos"']
shared_module('fu_plugin_altos', shared_module('fu_plugin_altos',
sources : [ sources : [
'fu-altos-device.c',
'fu-altos-firmware.c', 'fu-altos-firmware.c',
'fu-plugin-altos.c', 'fu-plugin-altos.c',
'fu-device-altos.c',
], ],
include_directories : [ include_directories : [
include_directories('../..'), include_directories('../..'),
@ -24,9 +24,9 @@ shared_module('fu_plugin_altos',
executable( executable(
'fu-altos-tool', 'fu-altos-tool',
sources : [ sources : [
'fu-altos-device.c',
'fu-altos-firmware.c', 'fu-altos-firmware.c',
'fu-altos-tool.c', 'fu-altos-tool.c',
'fu-device-altos.c',
], ],
include_directories : [ include_directories : [
include_directories('../..'), include_directories('../..'),