Run vendor plugins as required

This allows us to run plugins from AppStream metadata values.
This commit is contained in:
Richard Hughes 2016-03-13 09:56:54 +00:00
parent 80a77bcfd8
commit dad1e193cd
5 changed files with 67 additions and 4 deletions

View File

@ -61,6 +61,9 @@ struct _FuDeviceClass
#define FU_DEVICE_KEY_CREATED "Created" /* t */
#define FU_DEVICE_KEY_MODIFIED "Modified" /* t */
/* private */
#define FU_DEVICE_KEY_FWUPD_PLUGIN "fwupd::plugin" /* s */
FuDevice *fu_device_new (void);
/* accessors */

View File

@ -236,6 +236,21 @@ fu_main_load_plugins (GHashTable *plugins, GError **error)
return TRUE;
}
/**
* fu_main_get_plugin_for_device:
**/
static FuPlugin *
fu_main_get_plugin_for_device (GHashTable *plugins, FuDevice *device)
{
const gchar *tmp;
/* does a vendor plugin exist */
tmp = fu_device_get_metadata (device, FU_DEVICE_KEY_FWUPD_PLUGIN);
if (tmp == NULL)
return NULL;
return g_hash_table_lookup (plugins, tmp);
}
/**
* fu_main_item_free:
**/
@ -461,6 +476,7 @@ static gboolean
fu_main_provider_update_authenticated (FuMainAuthHelper *helper, GError **error)
{
FuDeviceItem *item;
FuPlugin *plugin;
/* check the device still exists */
item = fu_main_get_item_by_id (helper->priv, fu_device_get_id (helper->device));
@ -486,10 +502,13 @@ fu_main_provider_update_authenticated (FuMainAuthHelper *helper, GError **error)
}
/* run the correct provider that added this */
plugin = fu_main_get_plugin_for_device (helper->priv->plugins,
item->device);
if (!fu_provider_update (item->provider,
item->device,
helper->blob_cab,
helper->blob_fw,
plugin,
helper->flags,
error))
return FALSE;
@ -1907,6 +1926,9 @@ cd_main_provider_device_added_cb (FuProvider *provider,
{
FuMainPrivate *priv = (FuMainPrivate *) user_data;
FuDeviceItem *item;
AsApp *app;
FuPlugin *plugin;
g_autoptr(GError) error = NULL;
/* remove any fake device */
item = fu_main_get_item_by_id (priv, fu_device_get_id (device));
@ -1923,6 +1945,32 @@ cd_main_provider_device_added_cb (FuProvider *provider,
item->device = g_object_ref (device);
item->provider = g_object_ref (provider);
g_ptr_array_add (priv->devices, item);
/* does this match anything in the AppStream data */
app = as_store_get_app_by_provide (priv->store,
AS_PROVIDE_KIND_FIRMWARE_FLASHED,
fu_device_get_guid (item->device));
if (app != NULL) {
const gchar *tmp;
tmp = as_app_get_metadata_item (app, FU_DEVICE_KEY_FWUPD_PLUGIN);
if (tmp != NULL) {
g_debug ("setting plugin: %s", tmp);
fu_device_set_metadata (item->device,
FU_DEVICE_KEY_FWUPD_PLUGIN,
tmp);
}
}
/* run any plugins */
plugin = fu_main_get_plugin_for_device (priv->plugins, device);
if (plugin != NULL) {
if (!fu_plugin_run_device_probe (plugin, device, &error)) {
g_warning ("failed to probe %s: %s",
fu_device_get_id (item->device),
error->message);
}
}
fu_main_emit_changed (priv);
}

View File

@ -31,6 +31,7 @@
#include "fu-device.h"
#include "fu-pending.h"
#include "fu-plugin.h"
#include "fu-provider-uefi.h"
static void fu_provider_finalize (GObject *object);
@ -229,6 +230,7 @@ fu_provider_update (FuProvider *provider,
FuDevice *device,
GBytes *blob_cab,
GBytes *blob_fw,
FuPlugin *plugin,
FuProviderFlags flags,
GError **error)
{
@ -251,6 +253,14 @@ fu_provider_update (FuProvider *provider,
if (!fu_provider_offline_invalidate (error))
return FALSE;
/* we have support using a plugin */
if (plugin != NULL) {
return fu_plugin_run_device_update (plugin,
device,
blob_fw,
error);
}
/* online */
if (klass->update_online == NULL) {
g_set_error_literal (error,

View File

@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2015 Richard Hughes <richard@hughsie.com>
* Copyright (C) 2015-2016 Richard Hughes <richard@hughsie.com>
*
* Licensed under the GNU General Public License Version 2
*
@ -25,6 +25,7 @@
#include <glib-object.h>
#include "fu-device.h"
#include "fu-plugin.h"
#include "fu-provider.h"
G_BEGIN_DECLS
@ -101,6 +102,7 @@ gboolean fu_provider_update (FuProvider *provider,
FuDevice *device,
GBytes *blob_cab,
GBytes *blob_fw,
FuPlugin *plugin,
FuProviderFlags flags,
GError **error);
gboolean fu_provider_verify (FuProvider *provider,

View File

@ -214,7 +214,7 @@ fu_provider_func (void)
g_assert_no_error (error);
g_assert (mapped_file != NULL);
blob_cab = g_mapped_file_get_bytes (mapped_file);
ret = fu_provider_update (provider, device, blob_cab, NULL,
ret = fu_provider_update (provider, device, blob_cab, NULL, NULL,
FU_PROVIDER_UPDATE_FLAG_OFFLINE, &error);
g_assert_no_error (error);
g_assert (ret);
@ -234,7 +234,7 @@ fu_provider_func (void)
g_object_unref (device_tmp);
/* lets do this online */
ret = fu_provider_update (provider, device, blob_cab, NULL,
ret = fu_provider_update (provider, device, blob_cab, NULL, NULL,
FU_PROVIDER_UPDATE_FLAG_NONE, &error);
g_assert_no_error (error);
g_assert (ret);
@ -327,7 +327,7 @@ fu_provider_rpi_func (void)
g_assert_no_error (error);
g_assert (mapped_file != NULL);
blob_fw = g_mapped_file_get_bytes (mapped_file);
ret = fu_provider_update (provider, device, NULL, blob_fw,
ret = fu_provider_update (provider, device, NULL, blob_fw, NULL,
FU_PROVIDER_UPDATE_FLAG_NONE, &error);
g_assert_no_error (error);
g_assert (ret);