mirror of
https://git.proxmox.com/git/fwupd
synced 2025-05-23 20:45:48 +00:00
Use g_usb_context_wait_for_replug()
This commit is contained in:
parent
b4572d4c8c
commit
80a77bcfd8
@ -127,7 +127,7 @@ PKG_CHECK_MODULES(GUDEV, gudev-1.0)
|
|||||||
PKG_CHECK_MODULES(POLKIT, polkit-gobject-1 >= 0.103)
|
PKG_CHECK_MODULES(POLKIT, polkit-gobject-1 >= 0.103)
|
||||||
PKG_CHECK_MODULES(GCAB, libgcab-1.0)
|
PKG_CHECK_MODULES(GCAB, libgcab-1.0)
|
||||||
PKG_CHECK_MODULES(APPSTREAM_GLIB, appstream-glib >= 0.5.10)
|
PKG_CHECK_MODULES(APPSTREAM_GLIB, appstream-glib >= 0.5.10)
|
||||||
PKG_CHECK_MODULES(GUSB, gusb >= 0.2.8)
|
PKG_CHECK_MODULES(GUSB, gusb >= 0.2.9)
|
||||||
PKG_CHECK_MODULES(SQLITE, sqlite3)
|
PKG_CHECK_MODULES(SQLITE, sqlite3)
|
||||||
PKG_CHECK_MODULES(ARCHIVE, libarchive)
|
PKG_CHECK_MODULES(ARCHIVE, libarchive)
|
||||||
PKG_CHECK_MODULES(SOUP, libsoup-2.4 >= 2.51.92)
|
PKG_CHECK_MODULES(SOUP, libsoup-2.4 >= 2.51.92)
|
||||||
|
@ -49,12 +49,10 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
FuDevice *device;
|
FuDevice *device;
|
||||||
FuProviderChug *provider_chug;
|
FuProviderChug *provider_chug;
|
||||||
GMainLoop *loop;
|
|
||||||
GUsbDevice *usb_device;
|
GUsbDevice *usb_device;
|
||||||
gboolean got_version;
|
gboolean got_version;
|
||||||
gboolean is_bootloader;
|
gboolean is_bootloader;
|
||||||
guint timeout_open_id;
|
guint timeout_open_id;
|
||||||
guint reconnect_id;
|
|
||||||
GBytes *fw_bin;
|
GBytes *fw_bin;
|
||||||
} FuProviderChugItem;
|
} FuProviderChugItem;
|
||||||
|
|
||||||
@ -87,7 +85,6 @@ fu_provider_chug_get_device_key (GUsbDevice *device)
|
|||||||
static void
|
static void
|
||||||
fu_provider_chug_device_free (FuProviderChugItem *item)
|
fu_provider_chug_device_free (FuProviderChugItem *item)
|
||||||
{
|
{
|
||||||
g_main_loop_unref (item->loop);
|
|
||||||
g_object_unref (item->device);
|
g_object_unref (item->device);
|
||||||
g_object_unref (item->provider_chug);
|
g_object_unref (item->provider_chug);
|
||||||
g_object_unref (item->usb_device);
|
g_object_unref (item->usb_device);
|
||||||
@ -95,40 +92,28 @@ fu_provider_chug_device_free (FuProviderChugItem *item)
|
|||||||
g_bytes_unref (item->fw_bin);
|
g_bytes_unref (item->fw_bin);
|
||||||
if (item->timeout_open_id != 0)
|
if (item->timeout_open_id != 0)
|
||||||
g_source_remove (item->timeout_open_id);
|
g_source_remove (item->timeout_open_id);
|
||||||
if (item->reconnect_id != 0)
|
|
||||||
g_source_remove (item->reconnect_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* fu_provider_chug_reconnect_timeout_cb:
|
|
||||||
**/
|
|
||||||
static gboolean
|
|
||||||
fu_provider_chug_reconnect_timeout_cb (gpointer user_data)
|
|
||||||
{
|
|
||||||
FuProviderChugItem *item = (FuProviderChugItem *) user_data;
|
|
||||||
item->reconnect_id = 0;
|
|
||||||
g_main_loop_quit (item->loop);
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fu_provider_chug_wait_for_connect:
|
* fu_provider_chug_wait_for_connect:
|
||||||
**/
|
**/
|
||||||
static gboolean
|
static gboolean
|
||||||
fu_provider_chug_wait_for_connect (FuProviderChugItem *item, GError **error)
|
fu_provider_chug_wait_for_connect (FuProviderChug *provider_chug,
|
||||||
|
FuProviderChugItem *item,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
item->reconnect_id = g_timeout_add (CH_DEVICE_USB_TIMEOUT,
|
FuProviderChugPrivate *priv = GET_PRIVATE (item->provider_chug);
|
||||||
fu_provider_chug_reconnect_timeout_cb, item);
|
g_autoptr(GUsbDevice) device = NULL;
|
||||||
g_main_loop_run (item->loop);
|
|
||||||
if (item->reconnect_id == 0) {
|
device = g_usb_context_wait_for_replug (priv->usb_ctx,
|
||||||
g_set_error_literal (error,
|
item->usb_device,
|
||||||
FWUPD_ERROR,
|
CH_DEVICE_USB_TIMEOUT,
|
||||||
FWUPD_ERROR_NOT_FOUND,
|
error);
|
||||||
"request timed out");
|
if (device == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
|
||||||
g_source_remove (item->reconnect_id);
|
/* update item */
|
||||||
item->reconnect_id = 0;
|
g_set_object (&item->usb_device, device);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,7 +327,7 @@ fu_provider_chug_update (FuProvider *provider,
|
|||||||
|
|
||||||
/* wait for reconnection */
|
/* wait for reconnection */
|
||||||
g_debug ("ColorHug: Waiting for bootloader");
|
g_debug ("ColorHug: Waiting for bootloader");
|
||||||
if (!fu_provider_chug_wait_for_connect (item, error))
|
if (!fu_provider_chug_wait_for_connect (provider_chug, item, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -406,7 +391,7 @@ fu_provider_chug_update (FuProvider *provider,
|
|||||||
g_usb_device_close (item->usb_device, NULL);
|
g_usb_device_close (item->usb_device, NULL);
|
||||||
|
|
||||||
/* wait for firmware mode */
|
/* wait for firmware mode */
|
||||||
if (!fu_provider_chug_wait_for_connect (item, error))
|
if (!fu_provider_chug_wait_for_connect (provider_chug, item, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (!fu_provider_chug_open (item, error))
|
if (!fu_provider_chug_open (item, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -498,7 +483,6 @@ fu_provider_chug_device_added_cb (GUsbContext *ctx,
|
|||||||
item = g_hash_table_lookup (priv->devices, device_key);
|
item = g_hash_table_lookup (priv->devices, device_key);
|
||||||
if (item == NULL) {
|
if (item == NULL) {
|
||||||
item = g_new0 (FuProviderChugItem, 1);
|
item = g_new0 (FuProviderChugItem, 1);
|
||||||
item->loop = g_main_loop_new (NULL, FALSE);
|
|
||||||
item->provider_chug = g_object_ref (provider_chug);
|
item->provider_chug = g_object_ref (provider_chug);
|
||||||
item->usb_device = g_object_ref (device);
|
item->usb_device = g_object_ref (device);
|
||||||
item->device = fu_device_new ();
|
item->device = fu_device_new ();
|
||||||
@ -562,10 +546,6 @@ fu_provider_chug_device_added_cb (GUsbContext *ctx,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fu_provider_device_add (FU_PROVIDER (provider_chug), item->device);
|
fu_provider_device_add (FU_PROVIDER (provider_chug), item->device);
|
||||||
|
|
||||||
/* are we waiting for the device to show up */
|
|
||||||
if (g_main_loop_is_running (item->loop))
|
|
||||||
g_main_loop_quit (item->loop);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user