Richard Hughes | 02c90d8 | 2018-08-09 12:13:03 +0100 | [diff] [blame] | 1 | /* |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 2 | * Copyright (C) 2016-2018 Richard Hughes <richard@hughsie.com> |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 3 | * |
Mario Limonciello | 51308e6 | 2018-05-28 20:05:46 -0500 | [diff] [blame] | 4 | * SPDX-License-Identifier: LGPL-2.1+ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include "config.h" |
| 8 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 9 | #include <fwupd.h> |
| 10 | #include <gmodule.h> |
| 11 | #include <appstream-glib.h> |
| 12 | #include <errno.h> |
| 13 | #include <string.h> |
Richard Hughes | 68f12dd | 2018-08-09 14:43:31 +0100 | [diff] [blame^] | 14 | #include <unistd.h> |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 15 | #include <gio/gunixinputstream.h> |
Mario Limonciello | 6d0aa3d | 2017-02-28 08:22:27 -0600 | [diff] [blame] | 16 | #ifdef HAVE_VALGRIND |
Richard Hughes | 576c012 | 2017-02-24 09:47:00 +0000 | [diff] [blame] | 17 | #include <valgrind.h> |
Mario Limonciello | 6d0aa3d | 2017-02-28 08:22:27 -0600 | [diff] [blame] | 18 | #endif /* HAVE_VALGRIND */ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 19 | |
Richard Hughes | 9dde04f | 2017-09-13 12:07:15 +0100 | [diff] [blame] | 20 | #include "fu-device-private.h" |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 21 | #include "fu-plugin-private.h" |
Richard Hughes | bc3a4e1 | 2018-01-06 22:41:47 +0000 | [diff] [blame] | 22 | #include "fu-history.h" |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 23 | |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 24 | /** |
| 25 | * SECTION:fu-plugin |
| 26 | * @short_description: a daemon plugin |
| 27 | * |
| 28 | * An object that represents a plugin run by the daemon. |
| 29 | * |
| 30 | * See also: #FuDevice |
| 31 | */ |
| 32 | |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 33 | #define FU_PLUGIN_COLDPLUG_DELAY_MAXIMUM 3000u /* ms */ |
| 34 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 35 | static void fu_plugin_finalize (GObject *object); |
| 36 | |
| 37 | typedef struct { |
| 38 | GModule *module; |
| 39 | GUsbContext *usb_ctx; |
| 40 | gboolean enabled; |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 41 | guint order; |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 42 | guint priority; |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 43 | GPtrArray *rules[FU_PLUGIN_RULE_LAST]; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 44 | gchar *name; |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 45 | FuHwids *hwids; |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 46 | FuQuirks *quirks; |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 47 | GHashTable *runtime_versions; |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 48 | GHashTable *compile_versions; |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 49 | GPtrArray *supported_guids; |
| 50 | FuSmbios *smbios; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 51 | GHashTable *devices; /* platform_id:GObject */ |
Richard Hughes | ae3d65f | 2016-12-16 09:38:01 +0000 | [diff] [blame] | 52 | GHashTable *devices_delay; /* FuDevice:FuPluginHelper */ |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 53 | GHashTable *report_metadata; /* key:value */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 54 | FuPluginData *data; |
| 55 | } FuPluginPrivate; |
| 56 | |
| 57 | enum { |
| 58 | SIGNAL_DEVICE_ADDED, |
| 59 | SIGNAL_DEVICE_REMOVED, |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 60 | SIGNAL_DEVICE_REGISTER, |
Richard Hughes | 362d6d7 | 2017-01-07 21:42:14 +0000 | [diff] [blame] | 61 | SIGNAL_RECOLDPLUG, |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 62 | SIGNAL_SET_COLDPLUG_DELAY, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 63 | SIGNAL_LAST |
| 64 | }; |
| 65 | |
| 66 | static guint signals[SIGNAL_LAST] = { 0 }; |
| 67 | |
| 68 | G_DEFINE_TYPE_WITH_PRIVATE (FuPlugin, fu_plugin, G_TYPE_OBJECT) |
| 69 | #define GET_PRIVATE(o) (fu_plugin_get_instance_private (o)) |
| 70 | |
| 71 | typedef const gchar *(*FuPluginGetNameFunc) (void); |
| 72 | typedef void (*FuPluginInitFunc) (FuPlugin *plugin); |
| 73 | typedef gboolean (*FuPluginStartupFunc) (FuPlugin *plugin, |
| 74 | GError **error); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 75 | typedef void (*FuPluginDeviceRegisterFunc) (FuPlugin *plugin, |
| 76 | FuDevice *device); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 77 | typedef gboolean (*FuPluginDeviceFunc) (FuPlugin *plugin, |
| 78 | FuDevice *device, |
| 79 | GError **error); |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 80 | typedef gboolean (*FuPluginDeviceArrayFunc) (FuPlugin *plugin, |
| 81 | GPtrArray *devices, |
| 82 | GError **error); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 83 | typedef gboolean (*FuPluginVerifyFunc) (FuPlugin *plugin, |
| 84 | FuDevice *device, |
| 85 | FuPluginVerifyFlags flags, |
| 86 | GError **error); |
| 87 | typedef gboolean (*FuPluginUpdateFunc) (FuPlugin *plugin, |
| 88 | FuDevice *device, |
| 89 | GBytes *blob_fw, |
| 90 | FwupdInstallFlags flags, |
| 91 | GError **error); |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 92 | typedef gboolean (*FuPluginUsbDeviceAddedFunc) (FuPlugin *plugin, |
| 93 | GUsbDevice *usb_device, |
| 94 | GError **error); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 95 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 96 | /** |
| 97 | * fu_plugin_get_name: |
| 98 | * @plugin: A #FuPlugin |
| 99 | * |
| 100 | * Gets the plugin name. |
| 101 | * |
| 102 | * Returns: a plugin name, or %NULL for unknown. |
| 103 | * |
| 104 | * Since: 0.8.0 |
| 105 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 106 | const gchar * |
| 107 | fu_plugin_get_name (FuPlugin *plugin) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 108 | { |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 109 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 110 | g_return_val_if_fail (FU_IS_PLUGIN (plugin), NULL); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 111 | return priv->name; |
| 112 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 113 | |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 114 | void |
| 115 | fu_plugin_set_name (FuPlugin *plugin, const gchar *name) |
| 116 | { |
| 117 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 118 | g_return_if_fail (FU_IS_PLUGIN (plugin)); |
| 119 | g_return_if_fail (name != NULL); |
| 120 | g_free (priv->name); |
| 121 | priv->name = g_strdup (name); |
| 122 | } |
| 123 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 124 | /** |
| 125 | * fu_plugin_cache_lookup: |
| 126 | * @plugin: A #FuPlugin |
| 127 | * @id: the key |
| 128 | * |
| 129 | * Finds an object in the per-plugin cache. |
| 130 | * |
| 131 | * Returns: (transfer none): a #GObject, or %NULL for unfound. |
| 132 | * |
| 133 | * Since: 0.8.0 |
| 134 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 135 | gpointer |
| 136 | fu_plugin_cache_lookup (FuPlugin *plugin, const gchar *id) |
| 137 | { |
| 138 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 139 | g_return_val_if_fail (FU_IS_PLUGIN (plugin), NULL); |
| 140 | g_return_val_if_fail (id != NULL, NULL); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 141 | return g_hash_table_lookup (priv->devices, id); |
| 142 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 143 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 144 | /** |
| 145 | * fu_plugin_cache_add: |
| 146 | * @plugin: A #FuPlugin |
| 147 | * @id: the key |
| 148 | * @dev: a #GObject, typically a #FuDevice |
| 149 | * |
| 150 | * Adds an object to the per-plugin cache. |
| 151 | * |
| 152 | * Since: 0.8.0 |
| 153 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 154 | void |
| 155 | fu_plugin_cache_add (FuPlugin *plugin, const gchar *id, gpointer dev) |
| 156 | { |
| 157 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 158 | g_return_if_fail (FU_IS_PLUGIN (plugin)); |
| 159 | g_return_if_fail (id != NULL); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 160 | g_hash_table_insert (priv->devices, g_strdup (id), g_object_ref (dev)); |
| 161 | } |
| 162 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 163 | /** |
| 164 | * fu_plugin_cache_remove: |
| 165 | * @plugin: A #FuPlugin |
| 166 | * @id: the key |
| 167 | * |
| 168 | * Removes an object from the per-plugin cache. |
| 169 | * |
| 170 | * Since: 0.8.0 |
| 171 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 172 | void |
| 173 | fu_plugin_cache_remove (FuPlugin *plugin, const gchar *id) |
| 174 | { |
| 175 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 176 | g_return_if_fail (FU_IS_PLUGIN (plugin)); |
| 177 | g_return_if_fail (id != NULL); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 178 | g_hash_table_remove (priv->devices, id); |
| 179 | } |
| 180 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 181 | /** |
| 182 | * fu_plugin_get_data: |
| 183 | * @plugin: A #FuPlugin |
| 184 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 185 | * Gets the per-plugin allocated private data. This will return %NULL unless |
| 186 | * fu_plugin_alloc_data() has been called by the plugin. |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 187 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 188 | * Returns: (transfer none): a pointer to a structure, or %NULL for unset. |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 189 | * |
| 190 | * Since: 0.8.0 |
| 191 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 192 | FuPluginData * |
| 193 | fu_plugin_get_data (FuPlugin *plugin) |
| 194 | { |
| 195 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 196 | g_return_val_if_fail (FU_IS_PLUGIN (plugin), NULL); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 197 | return priv->data; |
| 198 | } |
| 199 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 200 | /** |
| 201 | * fu_plugin_alloc_data: |
| 202 | * @plugin: A #FuPlugin |
| 203 | * @data_sz: the size to allocate |
| 204 | * |
| 205 | * Allocates the per-plugin allocated private data. |
| 206 | * |
| 207 | * Returns: (transfer full): a pointer to a structure, or %NULL for unset. |
| 208 | * |
| 209 | * Since: 0.8.0 |
| 210 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 211 | FuPluginData * |
| 212 | fu_plugin_alloc_data (FuPlugin *plugin, gsize data_sz) |
| 213 | { |
| 214 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 215 | g_return_val_if_fail (FU_IS_PLUGIN (plugin), NULL); |
Richard Hughes | 44dee88 | 2017-01-11 08:31:10 +0000 | [diff] [blame] | 216 | if (priv->data != NULL) { |
| 217 | g_critical ("fu_plugin_alloc_data() already used by plugin"); |
| 218 | return priv->data; |
| 219 | } |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 220 | priv->data = g_malloc0 (data_sz); |
| 221 | return priv->data; |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 224 | /** |
| 225 | * fu_plugin_get_usb_context: |
| 226 | * @plugin: A #FuPlugin |
| 227 | * |
| 228 | * Gets the shared USB context that all plugins can use. |
| 229 | * |
| 230 | * Returns: (transfer none): a #GUsbContext. |
| 231 | * |
| 232 | * Since: 0.8.0 |
| 233 | **/ |
Richard Hughes | bc93e4a | 2016-12-08 17:29:51 +0000 | [diff] [blame] | 234 | GUsbContext * |
| 235 | fu_plugin_get_usb_context (FuPlugin *plugin) |
| 236 | { |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 237 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 238 | g_return_val_if_fail (FU_IS_PLUGIN (plugin), NULL); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 239 | return priv->usb_ctx; |
Richard Hughes | bc93e4a | 2016-12-08 17:29:51 +0000 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | void |
| 243 | fu_plugin_set_usb_context (FuPlugin *plugin, GUsbContext *usb_ctx) |
| 244 | { |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 245 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 246 | g_set_object (&priv->usb_ctx, usb_ctx); |
| 247 | } |
| 248 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 249 | /** |
| 250 | * fu_plugin_get_enabled: |
| 251 | * @plugin: A #FuPlugin |
| 252 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 253 | * Returns if the plugin is enabled. Plugins may self-disable using |
| 254 | * fu_plugin_set_enabled() or can be disabled by the daemon. |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 255 | * |
| 256 | * Returns: %TRUE if the plugin is currently enabled. |
| 257 | * |
| 258 | * Since: 0.8.0 |
| 259 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 260 | gboolean |
| 261 | fu_plugin_get_enabled (FuPlugin *plugin) |
| 262 | { |
| 263 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 264 | g_return_val_if_fail (FU_IS_PLUGIN (plugin), FALSE); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 265 | return priv->enabled; |
Richard Hughes | bc93e4a | 2016-12-08 17:29:51 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 268 | /** |
| 269 | * fu_plugin_set_enabled: |
| 270 | * @plugin: A #FuPlugin |
| 271 | * @enabled: the enabled value |
| 272 | * |
| 273 | * Enables or disables a plugin. Plugins can self-disable at any point. |
| 274 | * |
| 275 | * Since: 0.8.0 |
| 276 | **/ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 277 | void |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 278 | fu_plugin_set_enabled (FuPlugin *plugin, gboolean enabled) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 279 | { |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 280 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 281 | g_return_if_fail (FU_IS_PLUGIN (plugin)); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 282 | priv->enabled = enabled; |
| 283 | } |
| 284 | |
Richard Hughes | 1e456bc | 2018-05-10 20:16:16 +0100 | [diff] [blame] | 285 | gchar * |
| 286 | fu_plugin_guess_name_from_fn (const gchar *filename) |
| 287 | { |
| 288 | const gchar *prefix = "libfu_plugin_"; |
| 289 | gchar *name; |
| 290 | gchar *str = g_strstr_len (filename, -1, prefix); |
| 291 | if (str == NULL) |
| 292 | return NULL; |
| 293 | name = g_strdup (str + strlen (prefix)); |
| 294 | g_strdelimit (name, ".", '\0'); |
| 295 | return name; |
| 296 | } |
| 297 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 298 | gboolean |
| 299 | fu_plugin_open (FuPlugin *plugin, const gchar *filename, GError **error) |
| 300 | { |
| 301 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 302 | FuPluginInitFunc func = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 303 | |
| 304 | priv->module = g_module_open (filename, 0); |
| 305 | if (priv->module == NULL) { |
| 306 | g_set_error (error, |
| 307 | G_IO_ERROR, |
| 308 | G_IO_ERROR_FAILED, |
| 309 | "failed to open plugin: %s", |
| 310 | g_module_error ()); |
| 311 | return FALSE; |
| 312 | } |
| 313 | |
| 314 | /* set automatically */ |
Richard Hughes | 1e456bc | 2018-05-10 20:16:16 +0100 | [diff] [blame] | 315 | if (priv->name == NULL) |
| 316 | priv->name = fu_plugin_guess_name_from_fn (filename); |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 317 | |
| 318 | /* optional */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 319 | g_module_symbol (priv->module, "fu_plugin_init", (gpointer *) &func); |
| 320 | if (func != NULL) { |
| 321 | g_debug ("performing init() on %s", filename); |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 322 | func (plugin); |
| 323 | } |
| 324 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 325 | return TRUE; |
| 326 | } |
| 327 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 328 | /** |
| 329 | * fu_plugin_device_add: |
| 330 | * @plugin: A #FuPlugin |
| 331 | * @device: A #FuDevice |
| 332 | * |
| 333 | * Asks the daemon to add a device to the exported list. If this device ID |
| 334 | * has already been added by a different plugin then this request will be |
| 335 | * ignored. |
| 336 | * |
| 337 | * Plugins should use fu_plugin_device_add_delay() if they are not capable of |
| 338 | * actually flashing an image to the hardware so that higher-priority plugins |
| 339 | * can add the device themselves. |
| 340 | * |
| 341 | * Since: 0.8.0 |
| 342 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 343 | void |
| 344 | fu_plugin_device_add (FuPlugin *plugin, FuDevice *device) |
| 345 | { |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 346 | GPtrArray *children; |
| 347 | |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 348 | g_return_if_fail (FU_IS_PLUGIN (plugin)); |
| 349 | g_return_if_fail (FU_IS_DEVICE (device)); |
| 350 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 351 | g_debug ("emit added from %s: %s", |
| 352 | fu_plugin_get_name (plugin), |
| 353 | fu_device_get_id (device)); |
| 354 | fu_device_set_created (device, (guint64) g_get_real_time () / G_USEC_PER_SEC); |
| 355 | fu_device_set_plugin (device, fu_plugin_get_name (plugin)); |
| 356 | g_signal_emit (plugin, signals[SIGNAL_DEVICE_ADDED], 0, device); |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 357 | |
| 358 | /* add children */ |
| 359 | children = fu_device_get_children (device); |
| 360 | for (guint i = 0; i < children->len; i++) { |
| 361 | FuDevice *child = g_ptr_array_index (children, i); |
| 362 | fu_plugin_device_add (plugin, child); |
| 363 | } |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 364 | } |
| 365 | |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 366 | /** |
| 367 | * fu_plugin_device_register: |
| 368 | * @plugin: A #FuPlugin |
| 369 | * @device: A #FuDevice |
| 370 | * |
| 371 | * Registers the device with other plugins so they can set metadata. |
| 372 | * |
| 373 | * Plugins do not have to call this manually as this is done automatically |
| 374 | * when using fu_plugin_device_add(). They may wish to use this manually |
| 375 | * if for intance the coldplug should be ignored based on the metadata |
| 376 | * set from other plugins. |
| 377 | * |
| 378 | * Since: 0.9.7 |
| 379 | **/ |
| 380 | void |
| 381 | fu_plugin_device_register (FuPlugin *plugin, FuDevice *device) |
| 382 | { |
| 383 | g_return_if_fail (FU_IS_PLUGIN (plugin)); |
| 384 | g_return_if_fail (FU_IS_DEVICE (device)); |
| 385 | |
| 386 | g_debug ("emit device-register from %s: %s", |
| 387 | fu_plugin_get_name (plugin), |
| 388 | fu_device_get_id (device)); |
| 389 | g_signal_emit (plugin, signals[SIGNAL_DEVICE_REGISTER], 0, device); |
| 390 | } |
| 391 | |
Richard Hughes | ae3d65f | 2016-12-16 09:38:01 +0000 | [diff] [blame] | 392 | typedef struct { |
| 393 | FuPlugin *plugin; |
| 394 | FuDevice *device; |
| 395 | guint timeout_id; |
Richard Hughes | d4184cf | 2016-12-21 16:05:17 +0000 | [diff] [blame] | 396 | GHashTable *devices; |
Richard Hughes | ae3d65f | 2016-12-16 09:38:01 +0000 | [diff] [blame] | 397 | } FuPluginHelper; |
| 398 | |
| 399 | static void |
| 400 | fu_plugin_helper_free (FuPluginHelper *helper) |
| 401 | { |
| 402 | g_object_unref (helper->plugin); |
| 403 | g_object_unref (helper->device); |
Richard Hughes | d4184cf | 2016-12-21 16:05:17 +0000 | [diff] [blame] | 404 | g_hash_table_unref (helper->devices); |
Richard Hughes | ae3d65f | 2016-12-16 09:38:01 +0000 | [diff] [blame] | 405 | g_free (helper); |
| 406 | } |
| 407 | |
| 408 | static gboolean |
| 409 | fu_plugin_device_add_delay_cb (gpointer user_data) |
| 410 | { |
| 411 | FuPluginHelper *helper = (FuPluginHelper *) user_data; |
| 412 | fu_plugin_device_add (helper->plugin, helper->device); |
Richard Hughes | 0dec274 | 2017-09-18 11:07:39 +0100 | [diff] [blame] | 413 | g_hash_table_remove (helper->devices, helper->device); |
Richard Hughes | ae3d65f | 2016-12-16 09:38:01 +0000 | [diff] [blame] | 414 | fu_plugin_helper_free (helper); |
| 415 | return FALSE; |
| 416 | } |
| 417 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 418 | /** |
Richard Hughes | f0a799e | 2017-01-17 20:13:30 +0000 | [diff] [blame] | 419 | * fu_plugin_has_device_delay: |
| 420 | * @plugin: A #FuPlugin |
| 421 | * |
| 422 | * Returns if the device has a pending device that is waiting to be added. |
| 423 | * |
| 424 | * Returns: %TRUE if a device is waiting to be added |
| 425 | * |
| 426 | * Since: 0.8.0 |
| 427 | **/ |
| 428 | gboolean |
| 429 | fu_plugin_has_device_delay (FuPlugin *plugin) |
| 430 | { |
| 431 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 432 | return g_hash_table_size (priv->devices_delay) > 0; |
| 433 | } |
| 434 | |
| 435 | /** |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 436 | * fu_plugin_device_add_delay: |
| 437 | * @plugin: A #FuPlugin |
| 438 | * @device: A #FuDevice |
| 439 | * |
| 440 | * Asks the daemon to add a device to the exported list after a small delay. |
| 441 | * |
| 442 | * Since: 0.8.0 |
| 443 | **/ |
Richard Hughes | ae3d65f | 2016-12-16 09:38:01 +0000 | [diff] [blame] | 444 | void |
| 445 | fu_plugin_device_add_delay (FuPlugin *plugin, FuDevice *device) |
| 446 | { |
| 447 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 448 | FuPluginHelper *helper; |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 449 | |
| 450 | g_return_if_fail (FU_IS_PLUGIN (plugin)); |
| 451 | g_return_if_fail (FU_IS_DEVICE (device)); |
| 452 | |
Richard Hughes | 6ad951d | 2017-02-03 10:12:12 +0000 | [diff] [blame] | 453 | /* already waiting for add */ |
| 454 | helper = g_hash_table_lookup (priv->devices_delay, device); |
| 455 | if (helper != NULL) { |
Richard Hughes | 3cca1c6 | 2017-07-21 13:38:20 +0100 | [diff] [blame] | 456 | g_debug ("ignoring add-delay as device %s already pending", |
| 457 | fu_device_get_id (device)); |
Richard Hughes | 6ad951d | 2017-02-03 10:12:12 +0000 | [diff] [blame] | 458 | return; |
| 459 | } |
| 460 | |
| 461 | /* add after a small delay */ |
Richard Hughes | ae3d65f | 2016-12-16 09:38:01 +0000 | [diff] [blame] | 462 | g_debug ("waiting a small time for other plugins"); |
| 463 | helper = g_new0 (FuPluginHelper, 1); |
| 464 | helper->plugin = g_object_ref (plugin); |
| 465 | helper->device = g_object_ref (device); |
| 466 | helper->timeout_id = g_timeout_add (500, fu_plugin_device_add_delay_cb, helper); |
Richard Hughes | d4184cf | 2016-12-21 16:05:17 +0000 | [diff] [blame] | 467 | helper->devices = g_hash_table_ref (priv->devices_delay); |
| 468 | g_hash_table_insert (helper->devices, device, helper); |
Richard Hughes | ae3d65f | 2016-12-16 09:38:01 +0000 | [diff] [blame] | 469 | } |
| 470 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 471 | /** |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 472 | * fu_plugin_device_remove: |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 473 | * @plugin: A #FuPlugin |
| 474 | * @device: A #FuDevice |
| 475 | * |
| 476 | * Asks the daemon to remove a device from the exported list. |
| 477 | * |
| 478 | * Since: 0.8.0 |
| 479 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 480 | void |
| 481 | fu_plugin_device_remove (FuPlugin *plugin, FuDevice *device) |
| 482 | { |
Richard Hughes | ae3d65f | 2016-12-16 09:38:01 +0000 | [diff] [blame] | 483 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 484 | FuPluginHelper *helper; |
| 485 | |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 486 | g_return_if_fail (FU_IS_PLUGIN (plugin)); |
| 487 | g_return_if_fail (FU_IS_DEVICE (device)); |
| 488 | |
Richard Hughes | ae3d65f | 2016-12-16 09:38:01 +0000 | [diff] [blame] | 489 | /* waiting for add */ |
| 490 | helper = g_hash_table_lookup (priv->devices_delay, device); |
| 491 | if (helper != NULL) { |
| 492 | g_debug ("ignoring remove from delayed addition"); |
| 493 | g_source_remove (helper->timeout_id); |
Richard Hughes | d4184cf | 2016-12-21 16:05:17 +0000 | [diff] [blame] | 494 | g_hash_table_remove (priv->devices_delay, helper->device); |
Richard Hughes | ae3d65f | 2016-12-16 09:38:01 +0000 | [diff] [blame] | 495 | fu_plugin_helper_free (helper); |
| 496 | return; |
| 497 | } |
| 498 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 499 | g_debug ("emit removed from %s: %s", |
| 500 | fu_plugin_get_name (plugin), |
| 501 | fu_device_get_id (device)); |
| 502 | g_signal_emit (plugin, signals[SIGNAL_DEVICE_REMOVED], 0, device); |
| 503 | } |
| 504 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 505 | /** |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 506 | * fu_plugin_request_recoldplug: |
Richard Hughes | 362d6d7 | 2017-01-07 21:42:14 +0000 | [diff] [blame] | 507 | * @plugin: A #FuPlugin |
| 508 | * |
| 509 | * Ask all the plugins to coldplug all devices, which will include the prepare() |
| 510 | * and cleanup() phases. Duplicate devices added will be ignored. |
| 511 | * |
| 512 | * Since: 0.8.0 |
| 513 | **/ |
| 514 | void |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 515 | fu_plugin_request_recoldplug (FuPlugin *plugin) |
Richard Hughes | 362d6d7 | 2017-01-07 21:42:14 +0000 | [diff] [blame] | 516 | { |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 517 | g_return_if_fail (FU_IS_PLUGIN (plugin)); |
Richard Hughes | 362d6d7 | 2017-01-07 21:42:14 +0000 | [diff] [blame] | 518 | g_signal_emit (plugin, signals[SIGNAL_RECOLDPLUG], 0); |
| 519 | } |
| 520 | |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 521 | /** |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 522 | * fu_plugin_check_hwid: |
| 523 | * @plugin: A #FuPlugin |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 524 | * @hwid: A Hardware ID GUID, e.g. `6de5d951-d755-576b-bd09-c5cf66b27234` |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 525 | * |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 526 | * Checks to see if a specific GUID exists. All hardware IDs on a |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 527 | * specific system can be shown using the `fwupdmgr hwids` command. |
| 528 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 529 | * Returns: %TRUE if the HwId is found on the system. |
| 530 | * |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 531 | * Since: 0.9.1 |
| 532 | **/ |
| 533 | gboolean |
| 534 | fu_plugin_check_hwid (FuPlugin *plugin, const gchar *hwid) |
| 535 | { |
| 536 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 537 | if (priv->hwids == NULL) |
| 538 | return FALSE; |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 539 | return fu_hwids_has_guid (priv->hwids, hwid); |
| 540 | } |
| 541 | |
| 542 | /** |
Richard Hughes | 69a5f35 | 2018-08-08 11:58:15 +0100 | [diff] [blame] | 543 | * fu_plugin_get_hwids: |
| 544 | * @plugin: A #FuPlugin |
| 545 | * |
| 546 | * Returns all the HWIDs defined in the system. All hardware IDs on a |
| 547 | * specific system can be shown using the `fwupdmgr hwids` command. |
| 548 | * |
| 549 | * Returns: (transfer none) (element-type utf-8): An array of GUIDs |
| 550 | * |
| 551 | * Since: 1.1.1 |
| 552 | **/ |
| 553 | GPtrArray * |
| 554 | fu_plugin_get_hwids (FuPlugin *plugin) |
| 555 | { |
| 556 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 557 | if (priv->hwids == NULL) |
| 558 | return NULL; |
| 559 | return fu_hwids_get_guids (priv->hwids); |
| 560 | } |
| 561 | |
| 562 | /** |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 563 | * fu_plugin_check_supported: |
| 564 | * @plugin: A #FuPlugin |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 565 | * @guid: A Hardware ID GUID, e.g. `6de5d951-d755-576b-bd09-c5cf66b27234` |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 566 | * |
| 567 | * Checks to see if a specific device GUID is supported, i.e. available in the |
| 568 | * AppStream metadata. |
| 569 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 570 | * Returns: %TRUE if the device is supported. |
| 571 | * |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 572 | * Since: 1.0.0 |
| 573 | **/ |
| 574 | gboolean |
| 575 | fu_plugin_check_supported (FuPlugin *plugin, const gchar *guid) |
| 576 | { |
| 577 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 578 | if (priv->supported_guids == NULL) |
| 579 | return FALSE; |
| 580 | for (guint i = 0; i < priv->supported_guids->len; i++) { |
| 581 | const gchar *guid_tmp = g_ptr_array_index (priv->supported_guids, i); |
| 582 | if (g_strcmp0 (guid, guid_tmp) == 0) |
| 583 | return TRUE; |
| 584 | } |
| 585 | return FALSE; |
| 586 | } |
| 587 | |
| 588 | /** |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 589 | * fu_plugin_get_dmi_value: |
| 590 | * @plugin: A #FuPlugin |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 591 | * @dmi_id: A DMI ID, e.g. `BiosVersion` |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 592 | * |
| 593 | * Gets a hardware DMI value. |
| 594 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 595 | * Returns: The string, or %NULL |
| 596 | * |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 597 | * Since: 0.9.7 |
| 598 | **/ |
| 599 | const gchar * |
| 600 | fu_plugin_get_dmi_value (FuPlugin *plugin, const gchar *dmi_id) |
| 601 | { |
| 602 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 603 | if (priv->hwids == NULL) |
Richard Hughes | 7ef96b8 | 2017-08-23 18:28:24 +0100 | [diff] [blame] | 604 | return NULL; |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 605 | return fu_hwids_get_value (priv->hwids, dmi_id); |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 606 | } |
| 607 | |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 608 | /** |
| 609 | * fu_plugin_get_smbios_string: |
| 610 | * @plugin: A #FuPlugin |
| 611 | * @structure_type: A SMBIOS structure type, e.g. %FU_SMBIOS_STRUCTURE_TYPE_BIOS |
| 612 | * @offset: A SMBIOS offset |
| 613 | * |
| 614 | * Gets a hardware SMBIOS string. |
| 615 | * |
| 616 | * The @type and @offset can be referenced from the DMTF SMBIOS specification: |
| 617 | * https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.1.1.pdf |
| 618 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 619 | * Returns: A string, or %NULL |
| 620 | * |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 621 | * Since: 0.9.8 |
| 622 | **/ |
| 623 | const gchar * |
| 624 | fu_plugin_get_smbios_string (FuPlugin *plugin, guint8 structure_type, guint8 offset) |
| 625 | { |
| 626 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 627 | if (priv->smbios == NULL) |
| 628 | return NULL; |
| 629 | return fu_smbios_get_string (priv->smbios, structure_type, offset, NULL); |
| 630 | } |
| 631 | |
| 632 | /** |
| 633 | * fu_plugin_get_smbios_data: |
| 634 | * @plugin: A #FuPlugin |
| 635 | * @structure_type: A SMBIOS structure type, e.g. %FU_SMBIOS_STRUCTURE_TYPE_BIOS |
| 636 | * |
| 637 | * Gets a hardware SMBIOS data. |
| 638 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 639 | * Returns: (transfer none): A #GBytes, or %NULL |
| 640 | * |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 641 | * Since: 0.9.8 |
| 642 | **/ |
| 643 | GBytes * |
| 644 | fu_plugin_get_smbios_data (FuPlugin *plugin, guint8 structure_type) |
| 645 | { |
| 646 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 647 | if (priv->smbios == NULL) |
| 648 | return NULL; |
| 649 | return fu_smbios_get_data (priv->smbios, structure_type, NULL); |
| 650 | } |
| 651 | |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 652 | void |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 653 | fu_plugin_set_hwids (FuPlugin *plugin, FuHwids *hwids) |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 654 | { |
| 655 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 656 | g_set_object (&priv->hwids, hwids); |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 657 | } |
| 658 | |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 659 | void |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 660 | fu_plugin_set_supported (FuPlugin *plugin, GPtrArray *supported_guids) |
| 661 | { |
| 662 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 663 | if (priv->supported_guids != NULL) |
| 664 | g_ptr_array_unref (priv->supported_guids); |
| 665 | priv->supported_guids = g_ptr_array_ref (supported_guids); |
| 666 | } |
| 667 | |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 668 | void |
| 669 | fu_plugin_set_quirks (FuPlugin *plugin, FuQuirks *quirks) |
| 670 | { |
| 671 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 672 | g_set_object (&priv->quirks, quirks); |
| 673 | } |
| 674 | |
| 675 | /** |
| 676 | * fu_plugin_get_quirks: |
| 677 | * @plugin: A #FuPlugin |
| 678 | * |
| 679 | * Returns the hardware database object. This can be used to discover device |
| 680 | * quirks or other device-specific settings. |
| 681 | * |
| 682 | * Returns: (transfer none): a #FuQuirks, or %NULL if not set |
| 683 | * |
| 684 | * Since: 1.0.1 |
| 685 | **/ |
| 686 | FuQuirks * |
| 687 | fu_plugin_get_quirks (FuPlugin *plugin) |
| 688 | { |
| 689 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 690 | return priv->quirks; |
| 691 | } |
| 692 | |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 693 | void |
| 694 | fu_plugin_set_runtime_versions (FuPlugin *plugin, GHashTable *runtime_versions) |
| 695 | { |
| 696 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 697 | priv->runtime_versions = g_hash_table_ref (runtime_versions); |
| 698 | } |
| 699 | |
| 700 | /** |
| 701 | * fu_plugin_add_runtime_version: |
| 702 | * @plugin: A #FuPlugin |
| 703 | * @component_id: An AppStream component id, e.g. "org.gnome.Software" |
| 704 | * @version: A version string, e.g. "1.2.3" |
| 705 | * |
| 706 | * Sets a runtime version of a specific dependancy. |
| 707 | * |
| 708 | * Since: 1.0.7 |
| 709 | **/ |
| 710 | void |
| 711 | fu_plugin_add_runtime_version (FuPlugin *plugin, |
| 712 | const gchar *component_id, |
| 713 | const gchar *version) |
| 714 | { |
| 715 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
Richard Hughes | b01b486 | 2018-04-20 16:39:48 +0100 | [diff] [blame] | 716 | if (priv->runtime_versions == NULL) |
| 717 | return; |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 718 | g_hash_table_insert (priv->runtime_versions, |
| 719 | g_strdup (component_id), |
| 720 | g_strdup (version)); |
| 721 | } |
| 722 | |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 723 | void |
| 724 | fu_plugin_set_compile_versions (FuPlugin *plugin, GHashTable *compile_versions) |
| 725 | { |
| 726 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 727 | priv->compile_versions = g_hash_table_ref (compile_versions); |
| 728 | } |
| 729 | |
| 730 | /** |
| 731 | * fu_plugin_add_compile_version: |
| 732 | * @plugin: A #FuPlugin |
| 733 | * @component_id: An AppStream component id, e.g. "org.gnome.Software" |
| 734 | * @version: A version string, e.g. "1.2.3" |
| 735 | * |
| 736 | * Sets a compile-time version of a specific dependancy. |
| 737 | * |
| 738 | * Since: 1.0.7 |
| 739 | **/ |
| 740 | void |
| 741 | fu_plugin_add_compile_version (FuPlugin *plugin, |
| 742 | const gchar *component_id, |
| 743 | const gchar *version) |
| 744 | { |
| 745 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 746 | if (priv->compile_versions == NULL) |
| 747 | return; |
| 748 | g_hash_table_insert (priv->compile_versions, |
| 749 | g_strdup (component_id), |
| 750 | g_strdup (version)); |
| 751 | } |
| 752 | |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 753 | /** |
| 754 | * fu_plugin_lookup_quirk_by_id: |
| 755 | * @plugin: A #FuPlugin |
Richard Hughes | 87fb9ff | 2018-06-28 12:55:59 +0100 | [diff] [blame] | 756 | * @group: A string, e.g. "DfuFlags" |
| 757 | * @key: An ID to match the entry, e.g. "Summary" |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 758 | * |
| 759 | * Looks up an entry in the hardware database using a string value. |
| 760 | * |
| 761 | * Returns: (transfer none): values from the database, or %NULL if not found |
| 762 | * |
| 763 | * Since: 1.0.1 |
| 764 | **/ |
| 765 | const gchar * |
Richard Hughes | 87fb9ff | 2018-06-28 12:55:59 +0100 | [diff] [blame] | 766 | fu_plugin_lookup_quirk_by_id (FuPlugin *plugin, const gchar *group, const gchar *key) |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 767 | { |
| 768 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 769 | g_return_val_if_fail (FU_IS_PLUGIN (plugin), NULL); |
| 770 | |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 771 | /* exact ID */ |
Richard Hughes | 87fb9ff | 2018-06-28 12:55:59 +0100 | [diff] [blame] | 772 | return fu_quirks_lookup_by_id (priv->quirks, group, key); |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | /** |
| 776 | * fu_plugin_lookup_quirk_by_usb_device: |
| 777 | * @plugin: A #FuPlugin |
| 778 | * @prefix: A string prefix that matches the quirks file basename, e.g. "dfu-quirks" |
Richard Hughes | 87fb9ff | 2018-06-28 12:55:59 +0100 | [diff] [blame] | 779 | * @usb_device: A #GUsbDevice |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 780 | * |
| 781 | * Looks up an entry in the hardware database using various keys generated |
| 782 | * from @dev. |
| 783 | * |
| 784 | * Returns: (transfer none): values from the database, or %NULL if not found |
| 785 | * |
| 786 | * Since: 1.0.1 |
| 787 | **/ |
| 788 | const gchar * |
Richard Hughes | 87fb9ff | 2018-06-28 12:55:59 +0100 | [diff] [blame] | 789 | fu_plugin_lookup_quirk_by_usb_device (FuPlugin *plugin, |
| 790 | GUsbDevice *usb_device, |
| 791 | const gchar *prefix) |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 792 | { |
| 793 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 794 | g_return_val_if_fail (FU_IS_PLUGIN (plugin), NULL); |
Richard Hughes | 87fb9ff | 2018-06-28 12:55:59 +0100 | [diff] [blame] | 795 | return fu_quirks_lookup_by_usb_device (priv->quirks, usb_device, prefix); |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 796 | } |
| 797 | |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 798 | /** |
| 799 | * fu_plugin_get_supported: |
| 800 | * @plugin: A #FuPlugin |
| 801 | * |
| 802 | * Gets all the device GUIDs supported by the daemon. |
| 803 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 804 | * Returns: (element-type utf8) (transfer none): GUIDs |
| 805 | * |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 806 | * Since: 1.0.0 |
| 807 | **/ |
| 808 | GPtrArray * |
| 809 | fu_plugin_get_supported (FuPlugin *plugin) |
| 810 | { |
| 811 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 812 | return priv->supported_guids; |
| 813 | } |
| 814 | |
| 815 | void |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 816 | fu_plugin_set_smbios (FuPlugin *plugin, FuSmbios *smbios) |
| 817 | { |
| 818 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 819 | g_set_object (&priv->smbios, smbios); |
| 820 | } |
| 821 | |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 822 | /** |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 823 | * fu_plugin_set_coldplug_delay: |
| 824 | * @plugin: A #FuPlugin |
| 825 | * @duration: A delay in milliseconds |
| 826 | * |
| 827 | * Set the minimum time that should be waited inbetween the call to |
| 828 | * fu_plugin_coldplug_prepare() and fu_plugin_coldplug(). This is usually going |
| 829 | * to be the minimum hardware initialisation time from a datasheet. |
| 830 | * |
| 831 | * It is better to use this function rather than using a sleep() in the plugin |
| 832 | * itself as then only one delay is done in the daemon rather than waiting for |
| 833 | * each coldplug prepare in a serial way. |
| 834 | * |
| 835 | * Additionally, very long delays should be avoided as the daemon will be |
| 836 | * blocked from processing requests whilst the coldplug delay is being |
| 837 | * performed. |
| 838 | * |
| 839 | * Since: 0.8.0 |
| 840 | **/ |
| 841 | void |
| 842 | fu_plugin_set_coldplug_delay (FuPlugin *plugin, guint duration) |
| 843 | { |
| 844 | g_return_if_fail (FU_IS_PLUGIN (plugin)); |
| 845 | g_return_if_fail (duration > 0); |
| 846 | |
| 847 | /* check sanity */ |
| 848 | if (duration > FU_PLUGIN_COLDPLUG_DELAY_MAXIMUM) { |
| 849 | g_warning ("duration of %ums is crazy, truncating to %ums", |
| 850 | duration, |
| 851 | FU_PLUGIN_COLDPLUG_DELAY_MAXIMUM); |
| 852 | duration = FU_PLUGIN_COLDPLUG_DELAY_MAXIMUM; |
| 853 | } |
| 854 | |
| 855 | /* emit */ |
| 856 | g_signal_emit (plugin, signals[SIGNAL_SET_COLDPLUG_DELAY], 0, duration); |
| 857 | } |
| 858 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 859 | gboolean |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 860 | fu_plugin_runner_startup (FuPlugin *plugin, GError **error) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 861 | { |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 862 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 863 | FuPluginStartupFunc func = NULL; |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 864 | |
| 865 | /* not enabled */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 866 | if (!priv->enabled) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 867 | return TRUE; |
| 868 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 869 | /* no object loaded */ |
| 870 | if (priv->module == NULL) |
| 871 | return TRUE; |
| 872 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 873 | /* optional */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 874 | g_module_symbol (priv->module, "fu_plugin_startup", (gpointer *) &func); |
| 875 | if (func == NULL) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 876 | return TRUE; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 877 | g_debug ("performing startup() on %s", priv->name); |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 878 | if (!func (plugin, error)) { |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 879 | g_prefix_error (error, "failed to startup %s: ", priv->name); |
| 880 | return FALSE; |
| 881 | } |
| 882 | return TRUE; |
| 883 | } |
| 884 | |
| 885 | static gboolean |
| 886 | fu_plugin_runner_offline_invalidate (GError **error) |
| 887 | { |
| 888 | g_autoptr(GError) error_local = NULL; |
| 889 | g_autoptr(GFile) file1 = NULL; |
| 890 | |
| 891 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 892 | |
| 893 | file1 = g_file_new_for_path (FU_OFFLINE_TRIGGER_FILENAME); |
| 894 | if (!g_file_query_exists (file1, NULL)) |
| 895 | return TRUE; |
| 896 | if (!g_file_delete (file1, NULL, &error_local)) { |
| 897 | g_set_error (error, |
| 898 | FWUPD_ERROR, |
| 899 | FWUPD_ERROR_INTERNAL, |
| 900 | "Cannot delete %s: %s", |
| 901 | FU_OFFLINE_TRIGGER_FILENAME, |
| 902 | error_local->message); |
| 903 | return FALSE; |
| 904 | } |
| 905 | return TRUE; |
| 906 | } |
| 907 | |
| 908 | static gboolean |
| 909 | fu_plugin_runner_offline_setup (GError **error) |
| 910 | { |
| 911 | gint rc; |
| 912 | |
| 913 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 914 | |
| 915 | /* create symlink for the systemd-system-update-generator */ |
| 916 | rc = symlink ("/var/lib/fwupd", FU_OFFLINE_TRIGGER_FILENAME); |
| 917 | if (rc < 0) { |
| 918 | g_set_error (error, |
| 919 | FWUPD_ERROR, |
| 920 | FWUPD_ERROR_INTERNAL, |
| 921 | "Failed to create symlink %s to %s: %s", |
| 922 | FU_OFFLINE_TRIGGER_FILENAME, |
| 923 | "/var/lib", strerror (errno)); |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 924 | return FALSE; |
| 925 | } |
| 926 | return TRUE; |
| 927 | } |
| 928 | |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 929 | static gboolean |
| 930 | fu_plugin_runner_device_generic (FuPlugin *plugin, FuDevice *device, |
| 931 | const gchar *symbol_name, GError **error) |
| 932 | { |
| 933 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 934 | FuPluginDeviceFunc func = NULL; |
| 935 | |
| 936 | /* not enabled */ |
| 937 | if (!priv->enabled) |
| 938 | return TRUE; |
| 939 | |
Richard Hughes | d3d96cc | 2017-11-14 11:34:33 +0000 | [diff] [blame] | 940 | /* no object loaded */ |
| 941 | if (priv->module == NULL) |
| 942 | return TRUE; |
| 943 | |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 944 | /* optional */ |
| 945 | g_module_symbol (priv->module, symbol_name, (gpointer *) &func); |
| 946 | if (func == NULL) |
| 947 | return TRUE; |
| 948 | g_debug ("performing %s() on %s", symbol_name + 10, priv->name); |
| 949 | if (!func (plugin, device, error)) { |
Richard Hughes | 83e54e4 | 2018-01-31 23:27:30 +0000 | [diff] [blame] | 950 | g_prefix_error (error, "failed to run %s() on %s: ", |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 951 | symbol_name + 10, |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 952 | priv->name); |
| 953 | return FALSE; |
| 954 | } |
| 955 | return TRUE; |
| 956 | } |
| 957 | |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 958 | static gboolean |
| 959 | fu_plugin_runner_device_array_generic (FuPlugin *plugin, GPtrArray *devices, |
| 960 | const gchar *symbol_name, GError **error) |
| 961 | { |
| 962 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 963 | FuPluginDeviceArrayFunc func = NULL; |
| 964 | |
| 965 | /* not enabled */ |
| 966 | if (!priv->enabled) |
| 967 | return TRUE; |
| 968 | |
| 969 | /* no object loaded */ |
| 970 | if (priv->module == NULL) |
| 971 | return TRUE; |
| 972 | |
| 973 | /* optional */ |
| 974 | g_module_symbol (priv->module, symbol_name, (gpointer *) &func); |
| 975 | if (func == NULL) |
| 976 | return TRUE; |
| 977 | g_debug ("performing %s() on %s", symbol_name + 10, priv->name); |
| 978 | if (!func (plugin, devices, error)) { |
| 979 | g_prefix_error (error, "failed to run %s() on %s: ", |
| 980 | symbol_name + 10, |
| 981 | priv->name); |
| 982 | return FALSE; |
| 983 | } |
| 984 | return TRUE; |
| 985 | } |
| 986 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 987 | gboolean |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 988 | fu_plugin_runner_coldplug (FuPlugin *plugin, GError **error) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 989 | { |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 990 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 991 | FuPluginStartupFunc func = NULL; |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 992 | |
| 993 | /* not enabled */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 994 | if (!priv->enabled) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 995 | return TRUE; |
| 996 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 997 | /* no object loaded */ |
| 998 | if (priv->module == NULL) |
| 999 | return TRUE; |
| 1000 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1001 | /* optional */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1002 | g_module_symbol (priv->module, "fu_plugin_coldplug", (gpointer *) &func); |
| 1003 | if (func == NULL) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1004 | return TRUE; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1005 | g_debug ("performing coldplug() on %s", priv->name); |
| 1006 | if (!func (plugin, error)) { |
| 1007 | g_prefix_error (error, "failed to coldplug %s: ", priv->name); |
| 1008 | return FALSE; |
| 1009 | } |
| 1010 | return TRUE; |
| 1011 | } |
| 1012 | |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1013 | gboolean |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 1014 | fu_plugin_runner_recoldplug (FuPlugin *plugin, GError **error) |
| 1015 | { |
| 1016 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 1017 | FuPluginStartupFunc func = NULL; |
| 1018 | |
| 1019 | /* not enabled */ |
| 1020 | if (!priv->enabled) |
| 1021 | return TRUE; |
| 1022 | |
| 1023 | /* no object loaded */ |
| 1024 | if (priv->module == NULL) |
| 1025 | return TRUE; |
| 1026 | |
| 1027 | /* optional */ |
| 1028 | g_module_symbol (priv->module, "fu_plugin_recoldplug", (gpointer *) &func); |
| 1029 | if (func == NULL) |
| 1030 | return TRUE; |
| 1031 | g_debug ("performing recoldplug() on %s", priv->name); |
| 1032 | if (!func (plugin, error)) { |
| 1033 | g_prefix_error (error, "failed to recoldplug %s: ", priv->name); |
| 1034 | return FALSE; |
| 1035 | } |
| 1036 | return TRUE; |
| 1037 | } |
| 1038 | |
| 1039 | gboolean |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1040 | fu_plugin_runner_coldplug_prepare (FuPlugin *plugin, GError **error) |
| 1041 | { |
| 1042 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 1043 | FuPluginStartupFunc func = NULL; |
| 1044 | |
| 1045 | /* not enabled */ |
| 1046 | if (!priv->enabled) |
| 1047 | return TRUE; |
| 1048 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1049 | /* no object loaded */ |
| 1050 | if (priv->module == NULL) |
| 1051 | return TRUE; |
| 1052 | |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1053 | /* optional */ |
| 1054 | g_module_symbol (priv->module, "fu_plugin_coldplug_prepare", (gpointer *) &func); |
| 1055 | if (func == NULL) |
| 1056 | return TRUE; |
| 1057 | g_debug ("performing coldplug_prepare() on %s", priv->name); |
| 1058 | if (!func (plugin, error)) { |
| 1059 | g_prefix_error (error, "failed to prepare for coldplug %s: ", priv->name); |
| 1060 | return FALSE; |
| 1061 | } |
| 1062 | return TRUE; |
| 1063 | } |
| 1064 | |
| 1065 | gboolean |
| 1066 | fu_plugin_runner_coldplug_cleanup (FuPlugin *plugin, GError **error) |
| 1067 | { |
| 1068 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 1069 | FuPluginStartupFunc func = NULL; |
| 1070 | |
| 1071 | /* not enabled */ |
| 1072 | if (!priv->enabled) |
| 1073 | return TRUE; |
| 1074 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1075 | /* no object loaded */ |
| 1076 | if (priv->module == NULL) |
| 1077 | return TRUE; |
| 1078 | |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1079 | /* optional */ |
| 1080 | g_module_symbol (priv->module, "fu_plugin_coldplug_cleanup", (gpointer *) &func); |
| 1081 | if (func == NULL) |
| 1082 | return TRUE; |
| 1083 | g_debug ("performing coldplug_cleanup() on %s", priv->name); |
| 1084 | if (!func (plugin, error)) { |
| 1085 | g_prefix_error (error, "failed to cleanup coldplug %s: ", priv->name); |
| 1086 | return FALSE; |
| 1087 | } |
| 1088 | return TRUE; |
| 1089 | } |
| 1090 | |
| 1091 | gboolean |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1092 | fu_plugin_runner_composite_prepare (FuPlugin *plugin, GPtrArray *devices, GError **error) |
| 1093 | { |
| 1094 | return fu_plugin_runner_device_array_generic (plugin, devices, |
| 1095 | "fu_plugin_composite_prepare", |
| 1096 | error); |
| 1097 | } |
| 1098 | |
| 1099 | gboolean |
| 1100 | fu_plugin_runner_composite_cleanup (FuPlugin *plugin, GPtrArray *devices, GError **error) |
| 1101 | { |
| 1102 | return fu_plugin_runner_device_array_generic (plugin, devices, |
| 1103 | "fu_plugin_composite_cleanup", |
| 1104 | error); |
| 1105 | } |
| 1106 | |
| 1107 | gboolean |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1108 | fu_plugin_runner_update_prepare (FuPlugin *plugin, FuDevice *device, GError **error) |
| 1109 | { |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1110 | return fu_plugin_runner_device_generic (plugin, device, |
| 1111 | "fu_plugin_update_prepare", error); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | gboolean |
| 1115 | fu_plugin_runner_update_cleanup (FuPlugin *plugin, FuDevice *device, GError **error) |
| 1116 | { |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1117 | return fu_plugin_runner_device_generic (plugin, device, |
| 1118 | "fu_plugin_update_cleanup", error); |
| 1119 | } |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1120 | |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1121 | gboolean |
| 1122 | fu_plugin_runner_update_attach (FuPlugin *plugin, FuDevice *device, GError **error) |
| 1123 | { |
| 1124 | return fu_plugin_runner_device_generic (plugin, device, |
| 1125 | "fu_plugin_update_attach", error); |
| 1126 | } |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1127 | |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1128 | gboolean |
| 1129 | fu_plugin_runner_update_detach (FuPlugin *plugin, FuDevice *device, GError **error) |
| 1130 | { |
| 1131 | return fu_plugin_runner_device_generic (plugin, device, |
| 1132 | "fu_plugin_update_detach", error); |
| 1133 | } |
| 1134 | |
| 1135 | gboolean |
| 1136 | fu_plugin_runner_update_reload (FuPlugin *plugin, FuDevice *device, GError **error) |
| 1137 | { |
| 1138 | return fu_plugin_runner_device_generic (plugin, device, |
| 1139 | "fu_plugin_update_reload", error); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1140 | } |
| 1141 | |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 1142 | gboolean |
| 1143 | fu_plugin_runner_usb_device_added (FuPlugin *plugin, GUsbDevice *usb_device, GError **error) |
| 1144 | { |
| 1145 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 1146 | FuPluginUsbDeviceAddedFunc func = NULL; |
| 1147 | |
| 1148 | /* not enabled */ |
| 1149 | if (!priv->enabled) |
| 1150 | return TRUE; |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1151 | |
| 1152 | /* no object loaded */ |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 1153 | if (priv->module == NULL) |
| 1154 | return TRUE; |
| 1155 | |
| 1156 | /* optional */ |
| 1157 | g_module_symbol (priv->module, "fu_plugin_usb_device_added", (gpointer *) &func); |
| 1158 | if (func != NULL) { |
| 1159 | g_debug ("performing usb_device_added() on %s", priv->name); |
| 1160 | return func (plugin, usb_device, error); |
| 1161 | } |
| 1162 | return TRUE; |
| 1163 | } |
| 1164 | |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 1165 | void |
| 1166 | fu_plugin_runner_device_register (FuPlugin *plugin, FuDevice *device) |
| 1167 | { |
| 1168 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 1169 | FuPluginDeviceRegisterFunc func = NULL; |
| 1170 | |
| 1171 | /* not enabled */ |
| 1172 | if (!priv->enabled) |
| 1173 | return; |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 1174 | if (priv->module == NULL) |
| 1175 | return; |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 1176 | |
Mario Limonciello | 4910b24 | 2018-06-22 15:04:21 -0500 | [diff] [blame] | 1177 | /* don't notify plugins on their own devices */ |
| 1178 | if (g_strcmp0 (fu_device_get_plugin (device), fu_plugin_get_name (plugin)) == 0) |
| 1179 | return; |
| 1180 | |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 1181 | /* optional */ |
| 1182 | g_module_symbol (priv->module, "fu_plugin_device_registered", (gpointer *) &func); |
| 1183 | if (func != NULL) { |
| 1184 | g_debug ("performing device_added() on %s", priv->name); |
| 1185 | func (plugin, device); |
| 1186 | } |
| 1187 | } |
| 1188 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1189 | static gboolean |
| 1190 | fu_plugin_runner_schedule_update (FuPlugin *plugin, |
| 1191 | FuDevice *device, |
| 1192 | GBytes *blob_cab, |
| 1193 | GError **error) |
| 1194 | { |
Richard Hughes | 38fb56c | 2018-02-01 22:07:52 +0000 | [diff] [blame] | 1195 | FwupdRelease *release; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1196 | gchar tmpname[] = {"XXXXXX.cap"}; |
| 1197 | g_autofree gchar *dirname = NULL; |
| 1198 | g_autofree gchar *filename = NULL; |
Richard Hughes | 68982c6 | 2017-09-13 15:40:14 +0100 | [diff] [blame] | 1199 | g_autoptr(FuDevice) res_tmp = NULL; |
Richard Hughes | 780ef3f | 2018-01-12 16:20:31 +0000 | [diff] [blame] | 1200 | g_autoptr(FuHistory) history = NULL; |
Richard Hughes | 38fb56c | 2018-02-01 22:07:52 +0000 | [diff] [blame] | 1201 | g_autoptr(FwupdRelease) release_tmp = fwupd_release_new (); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1202 | g_autoptr(GFile) file = NULL; |
| 1203 | |
| 1204 | /* id already exists */ |
Richard Hughes | 780ef3f | 2018-01-12 16:20:31 +0000 | [diff] [blame] | 1205 | history = fu_history_new (); |
Richard Hughes | 0b9d996 | 2018-01-12 16:31:28 +0000 | [diff] [blame] | 1206 | res_tmp = fu_history_get_device_by_id (history, fu_device_get_id (device), NULL); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1207 | if (res_tmp != NULL) { |
| 1208 | g_set_error (error, |
| 1209 | FWUPD_ERROR, |
| 1210 | FWUPD_ERROR_ALREADY_PENDING, |
| 1211 | "%s is already scheduled to be updated", |
| 1212 | fu_device_get_id (device)); |
| 1213 | return FALSE; |
| 1214 | } |
| 1215 | |
| 1216 | /* create directory */ |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 1217 | dirname = fu_common_get_path (FU_PATH_KIND_LOCALSTATEDIR_PKG); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1218 | file = g_file_new_for_path (dirname); |
| 1219 | if (!g_file_query_exists (file, NULL)) { |
| 1220 | if (!g_file_make_directory_with_parents (file, NULL, error)) |
| 1221 | return FALSE; |
| 1222 | } |
| 1223 | |
| 1224 | /* get a random filename */ |
| 1225 | for (guint i = 0; i < 6; i++) |
| 1226 | tmpname[i] = (gchar) g_random_int_range ('A', 'Z'); |
| 1227 | filename = g_build_filename (dirname, tmpname, NULL); |
| 1228 | |
| 1229 | /* just copy to the temp file */ |
Richard Hughes | 23135eb | 2017-11-30 21:01:25 +0000 | [diff] [blame] | 1230 | fu_device_set_status (device, FWUPD_STATUS_SCHEDULING); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1231 | if (!g_file_set_contents (filename, |
| 1232 | g_bytes_get_data (blob_cab, NULL), |
| 1233 | (gssize) g_bytes_get_size (blob_cab), |
| 1234 | error)) |
| 1235 | return FALSE; |
| 1236 | |
| 1237 | /* schedule for next boot */ |
| 1238 | g_debug ("schedule %s to be installed to %s on next boot", |
| 1239 | filename, fu_device_get_id (device)); |
Richard Hughes | 38fb56c | 2018-02-01 22:07:52 +0000 | [diff] [blame] | 1240 | release = fu_device_get_release_default (device); |
| 1241 | fwupd_release_set_version (release_tmp, fwupd_release_get_version (release)); |
| 1242 | fwupd_release_set_filename (release_tmp, filename); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1243 | |
| 1244 | /* add to database */ |
Richard Hughes | 3e90a58 | 2018-01-06 22:38:09 +0000 | [diff] [blame] | 1245 | fu_device_set_update_state (device, FWUPD_UPDATE_STATE_PENDING); |
Richard Hughes | 38fb56c | 2018-02-01 22:07:52 +0000 | [diff] [blame] | 1246 | if (!fu_history_add_device (history, device, release_tmp, error)) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1247 | return FALSE; |
| 1248 | |
| 1249 | /* next boot we run offline */ |
| 1250 | return fu_plugin_runner_offline_setup (error); |
| 1251 | } |
| 1252 | |
| 1253 | gboolean |
| 1254 | fu_plugin_runner_verify (FuPlugin *plugin, |
| 1255 | FuDevice *device, |
| 1256 | FuPluginVerifyFlags flags, |
| 1257 | GError **error) |
| 1258 | { |
| 1259 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1260 | FuPluginVerifyFunc func = NULL; |
Richard Hughes | ababbb7 | 2017-06-15 20:18:36 +0100 | [diff] [blame] | 1261 | GPtrArray *checksums; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1262 | |
| 1263 | /* not enabled */ |
| 1264 | if (!priv->enabled) |
| 1265 | return TRUE; |
| 1266 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1267 | /* no object loaded */ |
| 1268 | if (priv->module == NULL) |
| 1269 | return TRUE; |
| 1270 | |
Richard Hughes | ababbb7 | 2017-06-15 20:18:36 +0100 | [diff] [blame] | 1271 | /* clear any existing verification checksums */ |
| 1272 | checksums = fu_device_get_checksums (device); |
| 1273 | g_ptr_array_set_size (checksums, 0); |
| 1274 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1275 | /* optional */ |
| 1276 | g_module_symbol (priv->module, "fu_plugin_verify", (gpointer *) &func); |
| 1277 | if (func == NULL) |
| 1278 | return TRUE; |
| 1279 | g_debug ("performing verify() on %s", priv->name); |
| 1280 | if (!func (plugin, device, flags, error)) { |
| 1281 | g_prefix_error (error, "failed to verify %s: ", priv->name); |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1282 | return FALSE; |
| 1283 | } |
| 1284 | return TRUE; |
| 1285 | } |
| 1286 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1287 | gboolean |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1288 | fu_plugin_runner_unlock (FuPlugin *plugin, FuDevice *device, GError **error) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1289 | { |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1290 | guint64 flags; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1291 | |
| 1292 | /* final check */ |
| 1293 | flags = fu_device_get_flags (device); |
| 1294 | if ((flags & FWUPD_DEVICE_FLAG_LOCKED) == 0) { |
| 1295 | g_set_error (error, |
| 1296 | FWUPD_ERROR, |
| 1297 | FWUPD_ERROR_NOT_SUPPORTED, |
| 1298 | "Device %s is not locked", |
| 1299 | fu_device_get_id (device)); |
| 1300 | return FALSE; |
| 1301 | } |
| 1302 | |
Richard Hughes | 9c4b531 | 2017-11-14 11:34:53 +0000 | [diff] [blame] | 1303 | /* run vfunc */ |
| 1304 | if (!fu_plugin_runner_device_generic (plugin, device, |
| 1305 | "fu_plugin_unlock", error)) |
| 1306 | return FALSE; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1307 | |
| 1308 | /* update with correct flags */ |
| 1309 | flags = fu_device_get_flags (device); |
| 1310 | fu_device_set_flags (device, flags &= ~FWUPD_DEVICE_FLAG_LOCKED); |
| 1311 | fu_device_set_modified (device, (guint64) g_get_real_time () / G_USEC_PER_SEC); |
| 1312 | return TRUE; |
| 1313 | } |
| 1314 | |
| 1315 | gboolean |
| 1316 | fu_plugin_runner_update (FuPlugin *plugin, |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 1317 | FuDevice *device, |
| 1318 | GBytes *blob_cab, |
| 1319 | GBytes *blob_fw, |
| 1320 | FwupdInstallFlags flags, |
| 1321 | GError **error) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1322 | { |
| 1323 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 1324 | FuPluginUpdateFunc update_func; |
Richard Hughes | 780ef3f | 2018-01-12 16:20:31 +0000 | [diff] [blame] | 1325 | g_autoptr(FuHistory) history = NULL; |
Richard Hughes | 68982c6 | 2017-09-13 15:40:14 +0100 | [diff] [blame] | 1326 | g_autoptr(FuDevice) device_pending = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1327 | GError *error_update = NULL; |
Richard Hughes | f556d37 | 2017-06-15 19:49:18 +0100 | [diff] [blame] | 1328 | GPtrArray *checksums; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1329 | |
| 1330 | /* not enabled */ |
Richard Hughes | 41c1548 | 2018-02-01 22:07:21 +0000 | [diff] [blame] | 1331 | if (!priv->enabled) { |
| 1332 | g_debug ("plugin not enabled, skipping"); |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1333 | return TRUE; |
Richard Hughes | 41c1548 | 2018-02-01 22:07:21 +0000 | [diff] [blame] | 1334 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1335 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1336 | /* no object loaded */ |
Richard Hughes | 41c1548 | 2018-02-01 22:07:21 +0000 | [diff] [blame] | 1337 | if (priv->module == NULL) { |
| 1338 | g_debug ("module not enabled, skipping"); |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1339 | return TRUE; |
Richard Hughes | 41c1548 | 2018-02-01 22:07:21 +0000 | [diff] [blame] | 1340 | } |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1341 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1342 | /* optional */ |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 1343 | g_module_symbol (priv->module, "fu_plugin_update", (gpointer *) &update_func); |
| 1344 | if (update_func == NULL) { |
| 1345 | g_set_error_literal (error, |
| 1346 | FWUPD_ERROR, |
| 1347 | FWUPD_ERROR_NOT_SUPPORTED, |
| 1348 | "No update possible"); |
| 1349 | return FALSE; |
| 1350 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1351 | |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 1352 | /* just schedule this for the next reboot */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1353 | if (flags & FWUPD_INSTALL_FLAG_OFFLINE) { |
Richard Hughes | 026cdd8 | 2018-05-18 10:23:19 +0100 | [diff] [blame] | 1354 | if (blob_cab == NULL) { |
| 1355 | g_set_error_literal (error, |
| 1356 | FWUPD_ERROR, |
| 1357 | FWUPD_ERROR_NOT_SUPPORTED, |
| 1358 | "No cabinet archive to schedule"); |
| 1359 | return FALSE; |
| 1360 | } |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 1361 | return fu_plugin_runner_schedule_update (plugin, |
| 1362 | device, |
| 1363 | blob_cab, |
| 1364 | error); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | /* cancel the pending action */ |
| 1368 | if (!fu_plugin_runner_offline_invalidate (error)) |
| 1369 | return FALSE; |
| 1370 | |
| 1371 | /* online */ |
Richard Hughes | 780ef3f | 2018-01-12 16:20:31 +0000 | [diff] [blame] | 1372 | history = fu_history_new (); |
Richard Hughes | 0b9d996 | 2018-01-12 16:31:28 +0000 | [diff] [blame] | 1373 | device_pending = fu_history_get_device_by_id (history, fu_device_get_id (device), NULL); |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 1374 | if (!update_func (plugin, device, blob_fw, flags, &error_update)) { |
Richard Hughes | c0cd023 | 2018-01-31 15:02:00 +0000 | [diff] [blame] | 1375 | fu_device_set_update_error (device, error_update->message); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1376 | g_propagate_error (error, error_update); |
| 1377 | return FALSE; |
| 1378 | } |
| 1379 | |
Richard Hughes | f556d37 | 2017-06-15 19:49:18 +0100 | [diff] [blame] | 1380 | /* no longer valid */ |
| 1381 | checksums = fu_device_get_checksums (device); |
| 1382 | g_ptr_array_set_size (checksums, 0); |
| 1383 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1384 | /* cleanup */ |
Richard Hughes | 68982c6 | 2017-09-13 15:40:14 +0100 | [diff] [blame] | 1385 | if (device_pending != NULL) { |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1386 | const gchar *tmp; |
Richard Hughes | bc3a4e1 | 2018-01-06 22:41:47 +0000 | [diff] [blame] | 1387 | FwupdRelease *release; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1388 | |
Richard Hughes | 780ef3f | 2018-01-12 16:20:31 +0000 | [diff] [blame] | 1389 | /* update history database */ |
Richard Hughes | c0cd023 | 2018-01-31 15:02:00 +0000 | [diff] [blame] | 1390 | fu_device_set_update_state (device, FWUPD_UPDATE_STATE_SUCCESS); |
| 1391 | if (!fu_history_modify_device (history, device, |
| 1392 | FU_HISTORY_FLAGS_MATCH_NEW_VERSION, |
| 1393 | error)) |
Richard Hughes | 0b9d996 | 2018-01-12 16:31:28 +0000 | [diff] [blame] | 1394 | return FALSE; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1395 | |
| 1396 | /* delete cab file */ |
Richard Hughes | bc3a4e1 | 2018-01-06 22:41:47 +0000 | [diff] [blame] | 1397 | release = fu_device_get_release_default (device_pending); |
| 1398 | tmp = fwupd_release_get_filename (release); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1399 | if (tmp != NULL && g_str_has_prefix (tmp, LIBEXECDIR)) { |
| 1400 | g_autoptr(GError) error_local = NULL; |
| 1401 | g_autoptr(GFile) file = NULL; |
| 1402 | file = g_file_new_for_path (tmp); |
| 1403 | if (!g_file_delete (file, NULL, &error_local)) { |
| 1404 | g_set_error (error, |
| 1405 | FWUPD_ERROR, |
| 1406 | FWUPD_ERROR_INVALID_FILE, |
| 1407 | "Failed to delete %s: %s", |
| 1408 | tmp, error_local->message); |
| 1409 | return FALSE; |
| 1410 | } |
| 1411 | } |
| 1412 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1413 | return TRUE; |
| 1414 | } |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1415 | |
| 1416 | gboolean |
| 1417 | fu_plugin_runner_clear_results (FuPlugin *plugin, FuDevice *device, GError **error) |
| 1418 | { |
| 1419 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1420 | FuPluginDeviceFunc func = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1421 | |
| 1422 | /* not enabled */ |
| 1423 | if (!priv->enabled) |
| 1424 | return TRUE; |
| 1425 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1426 | /* no object loaded */ |
| 1427 | if (priv->module == NULL) |
| 1428 | return TRUE; |
| 1429 | |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 1430 | /* optional */ |
| 1431 | g_module_symbol (priv->module, "fu_plugin_get_results", (gpointer *) &func); |
| 1432 | if (func == NULL) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1433 | return TRUE; |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 1434 | g_debug ("performing clear_result() on %s", priv->name); |
| 1435 | if (!func (plugin, device, error)) { |
| 1436 | g_prefix_error (error, "failed to clear_result %s: ", priv->name); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1437 | return FALSE; |
| 1438 | } |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 1439 | return TRUE; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1440 | } |
| 1441 | |
| 1442 | gboolean |
| 1443 | fu_plugin_runner_get_results (FuPlugin *plugin, FuDevice *device, GError **error) |
| 1444 | { |
| 1445 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1446 | FuPluginDeviceFunc func = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1447 | |
| 1448 | /* not enabled */ |
| 1449 | if (!priv->enabled) |
| 1450 | return TRUE; |
| 1451 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1452 | /* no object loaded */ |
| 1453 | if (priv->module == NULL) |
| 1454 | return TRUE; |
| 1455 | |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 1456 | /* optional */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1457 | g_module_symbol (priv->module, "fu_plugin_get_results", (gpointer *) &func); |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 1458 | if (func == NULL) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1459 | return TRUE; |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 1460 | g_debug ("performing get_results() on %s", priv->name); |
| 1461 | if (!func (plugin, device, error)) { |
| 1462 | g_prefix_error (error, "failed to get_results %s: ", priv->name); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1463 | return FALSE; |
| 1464 | } |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1465 | return TRUE; |
| 1466 | } |
| 1467 | |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1468 | /** |
| 1469 | * fu_plugin_get_order: |
| 1470 | * @plugin: a #FuPlugin |
| 1471 | * |
| 1472 | * Gets the plugin order, where higher numbers are run after lower |
| 1473 | * numbers. |
| 1474 | * |
| 1475 | * Returns: the integer value |
| 1476 | **/ |
| 1477 | guint |
| 1478 | fu_plugin_get_order (FuPlugin *plugin) |
| 1479 | { |
| 1480 | FuPluginPrivate *priv = fu_plugin_get_instance_private (plugin); |
| 1481 | return priv->order; |
| 1482 | } |
| 1483 | |
| 1484 | /** |
| 1485 | * fu_plugin_set_order: |
| 1486 | * @plugin: a #FuPlugin |
| 1487 | * @order: a integer value |
| 1488 | * |
| 1489 | * Sets the plugin order, where higher numbers are run after lower |
| 1490 | * numbers. |
| 1491 | **/ |
| 1492 | void |
| 1493 | fu_plugin_set_order (FuPlugin *plugin, guint order) |
| 1494 | { |
| 1495 | FuPluginPrivate *priv = fu_plugin_get_instance_private (plugin); |
| 1496 | priv->order = order; |
| 1497 | } |
| 1498 | |
| 1499 | /** |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 1500 | * fu_plugin_get_priority: |
| 1501 | * @plugin: a #FuPlugin |
| 1502 | * |
| 1503 | * Gets the plugin priority, where higher numbers are better. |
| 1504 | * |
| 1505 | * Returns: the integer value |
| 1506 | **/ |
| 1507 | guint |
| 1508 | fu_plugin_get_priority (FuPlugin *plugin) |
| 1509 | { |
| 1510 | FuPluginPrivate *priv = fu_plugin_get_instance_private (plugin); |
| 1511 | return priv->priority; |
| 1512 | } |
| 1513 | |
| 1514 | /** |
| 1515 | * fu_plugin_set_priority: |
| 1516 | * @plugin: a #FuPlugin |
| 1517 | * @priority: a integer value |
| 1518 | * |
| 1519 | * Sets the plugin priority, where higher numbers are better. |
| 1520 | **/ |
| 1521 | void |
| 1522 | fu_plugin_set_priority (FuPlugin *plugin, guint priority) |
| 1523 | { |
| 1524 | FuPluginPrivate *priv = fu_plugin_get_instance_private (plugin); |
| 1525 | priv->priority = priority; |
| 1526 | } |
| 1527 | |
| 1528 | /** |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1529 | * fu_plugin_add_rule: |
| 1530 | * @plugin: a #FuPlugin |
| 1531 | * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 1532 | * @name: a plugin name, e.g. `upower` |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1533 | * |
| 1534 | * If the plugin name is found, the rule will be used to sort the plugin list, |
| 1535 | * for example the plugin specified by @name will be ordered after this plugin |
| 1536 | * when %FU_PLUGIN_RULE_RUN_AFTER is used. |
| 1537 | * |
| 1538 | * NOTE: The depsolver is iterative and may not solve overly-complicated rules; |
| 1539 | * If depsolving fails then fwupd will not start. |
| 1540 | **/ |
| 1541 | void |
| 1542 | fu_plugin_add_rule (FuPlugin *plugin, FuPluginRule rule, const gchar *name) |
| 1543 | { |
| 1544 | FuPluginPrivate *priv = fu_plugin_get_instance_private (plugin); |
| 1545 | g_ptr_array_add (priv->rules[rule], g_strdup (name)); |
| 1546 | } |
| 1547 | |
| 1548 | /** |
| 1549 | * fu_plugin_get_rules: |
| 1550 | * @plugin: a #FuPlugin |
| 1551 | * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS |
| 1552 | * |
| 1553 | * Gets the plugin IDs that should be run after this plugin. |
| 1554 | * |
| 1555 | * Returns: (element-type utf8) (transfer none): the list of plugin names, e.g. ['appstream'] |
| 1556 | **/ |
| 1557 | GPtrArray * |
| 1558 | fu_plugin_get_rules (FuPlugin *plugin, FuPluginRule rule) |
| 1559 | { |
| 1560 | FuPluginPrivate *priv = fu_plugin_get_instance_private (plugin); |
| 1561 | return priv->rules[rule]; |
| 1562 | } |
| 1563 | |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 1564 | /** |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 1565 | * fu_plugin_has_rule: |
| 1566 | * @plugin: a #FuPlugin |
| 1567 | * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS |
| 1568 | * @name: a plugin name, e.g. `upower` |
| 1569 | * |
Richard Hughes | 87fb9ff | 2018-06-28 12:55:59 +0100 | [diff] [blame] | 1570 | * Gets the plugin IDs that should be run after this plugin. |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 1571 | * |
| 1572 | * Returns: %TRUE if the name exists for the specific rule |
| 1573 | **/ |
| 1574 | gboolean |
| 1575 | fu_plugin_has_rule (FuPlugin *plugin, FuPluginRule rule, const gchar *name) |
| 1576 | { |
| 1577 | FuPluginPrivate *priv = fu_plugin_get_instance_private (plugin); |
| 1578 | for (guint i = 0; i < priv->rules[rule]->len; i++) { |
| 1579 | const gchar *tmp = g_ptr_array_index (priv->rules[rule], i); |
| 1580 | if (g_strcmp0 (tmp, name) == 0) |
| 1581 | return TRUE; |
| 1582 | } |
| 1583 | return FALSE; |
| 1584 | } |
| 1585 | |
| 1586 | /** |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 1587 | * fu_plugin_add_report_metadata: |
| 1588 | * @plugin: a #FuPlugin |
| 1589 | * @key: a string, e.g. `FwupdateVersion` |
| 1590 | * @value: a string, e.g. `10` |
| 1591 | * |
| 1592 | * Sets any additional metadata to be included in the firmware report to aid |
| 1593 | * debugging problems. |
| 1594 | * |
| 1595 | * Any data included here will be sent to the metadata server after user |
| 1596 | * confirmation. |
| 1597 | **/ |
| 1598 | void |
| 1599 | fu_plugin_add_report_metadata (FuPlugin *plugin, const gchar *key, const gchar *value) |
| 1600 | { |
| 1601 | FuPluginPrivate *priv = fu_plugin_get_instance_private (plugin); |
| 1602 | g_hash_table_insert (priv->report_metadata, g_strdup (key), g_strdup (value)); |
| 1603 | } |
| 1604 | |
| 1605 | /** |
| 1606 | * fu_plugin_get_report_metadata: |
| 1607 | * @plugin: a #FuPlugin |
| 1608 | * |
| 1609 | * Returns the list of additional metadata to be added when filing a report. |
| 1610 | * |
| 1611 | * Returns: (transfer none): the map of report metadata |
| 1612 | **/ |
| 1613 | GHashTable * |
| 1614 | fu_plugin_get_report_metadata (FuPlugin *plugin) |
| 1615 | { |
| 1616 | FuPluginPrivate *priv = fu_plugin_get_instance_private (plugin); |
| 1617 | return priv->report_metadata; |
| 1618 | } |
| 1619 | |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 1620 | /** |
| 1621 | * fu_plugin_get_config_value: |
| 1622 | * @plugin: a #FuPlugin |
| 1623 | * @key: A settings key |
| 1624 | * |
| 1625 | * Return the value of a key if it's been configured |
| 1626 | * |
| 1627 | * Since: 1.0.6 |
| 1628 | **/ |
| 1629 | gchar * |
| 1630 | fu_plugin_get_config_value (FuPlugin *plugin, const gchar *key) |
| 1631 | { |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 1632 | g_autofree gchar *conf_dir = NULL; |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 1633 | g_autofree gchar *conf_file = NULL; |
| 1634 | g_autofree gchar *conf_path = NULL; |
| 1635 | g_autoptr(GKeyFile) keyfile = NULL; |
| 1636 | const gchar *plugin_name; |
| 1637 | |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 1638 | conf_dir = fu_common_get_path (FU_PATH_KIND_SYSCONFDIR_PKG); |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 1639 | plugin_name = fu_plugin_get_name (plugin); |
| 1640 | conf_file = g_strdup_printf ("%s.conf", plugin_name); |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 1641 | conf_path = g_build_filename (conf_dir, conf_file, NULL); |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 1642 | if (!g_file_test (conf_path, G_FILE_TEST_IS_REGULAR)) |
| 1643 | return NULL; |
| 1644 | keyfile = g_key_file_new (); |
| 1645 | if (!g_key_file_load_from_file (keyfile, conf_path, |
| 1646 | G_KEY_FILE_NONE, NULL)) |
| 1647 | return NULL; |
| 1648 | return g_key_file_get_string (keyfile, plugin_name, key, NULL); |
| 1649 | } |
| 1650 | |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 1651 | /** |
| 1652 | * fu_plugin_name_compare: |
| 1653 | * @plugin1: first #FuPlugin to compare. |
| 1654 | * @plugin2: second #FuPlugin to compare. |
| 1655 | * |
| 1656 | * Compares two plugins by their names. |
| 1657 | * |
| 1658 | * Returns: 1, 0 or -1 if @plugin1 is greater, equal, or less than @plugin2. |
| 1659 | **/ |
| 1660 | gint |
| 1661 | fu_plugin_name_compare (FuPlugin *plugin1, FuPlugin *plugin2) |
| 1662 | { |
| 1663 | FuPluginPrivate *priv1 = fu_plugin_get_instance_private (plugin1); |
| 1664 | FuPluginPrivate *priv2 = fu_plugin_get_instance_private (plugin2); |
| 1665 | return g_strcmp0 (priv1->name, priv2->name); |
| 1666 | } |
| 1667 | |
| 1668 | /** |
| 1669 | * fu_plugin_order_compare: |
| 1670 | * @plugin1: first #FuPlugin to compare. |
| 1671 | * @plugin2: second #FuPlugin to compare. |
| 1672 | * |
| 1673 | * Compares two plugins by their depsolved order. |
| 1674 | * |
| 1675 | * Returns: 1, 0 or -1 if @plugin1 is greater, equal, or less than @plugin2. |
| 1676 | **/ |
| 1677 | gint |
| 1678 | fu_plugin_order_compare (FuPlugin *plugin1, FuPlugin *plugin2) |
| 1679 | { |
| 1680 | FuPluginPrivate *priv1 = fu_plugin_get_instance_private (plugin1); |
| 1681 | FuPluginPrivate *priv2 = fu_plugin_get_instance_private (plugin2); |
| 1682 | if (priv1->order < priv2->order) |
| 1683 | return -1; |
| 1684 | if (priv1->order > priv2->order) |
| 1685 | return 1; |
| 1686 | return 0; |
| 1687 | } |
| 1688 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1689 | static void |
| 1690 | fu_plugin_class_init (FuPluginClass *klass) |
| 1691 | { |
| 1692 | GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 1693 | object_class->finalize = fu_plugin_finalize; |
| 1694 | signals[SIGNAL_DEVICE_ADDED] = |
| 1695 | g_signal_new ("device-added", |
| 1696 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 1697 | G_STRUCT_OFFSET (FuPluginClass, device_added), |
| 1698 | NULL, NULL, g_cclosure_marshal_VOID__OBJECT, |
| 1699 | G_TYPE_NONE, 1, FU_TYPE_DEVICE); |
| 1700 | signals[SIGNAL_DEVICE_REMOVED] = |
| 1701 | g_signal_new ("device-removed", |
| 1702 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 1703 | G_STRUCT_OFFSET (FuPluginClass, device_removed), |
| 1704 | NULL, NULL, g_cclosure_marshal_VOID__OBJECT, |
| 1705 | G_TYPE_NONE, 1, FU_TYPE_DEVICE); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 1706 | signals[SIGNAL_DEVICE_REGISTER] = |
| 1707 | g_signal_new ("device-register", |
| 1708 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 1709 | G_STRUCT_OFFSET (FuPluginClass, device_register), |
| 1710 | NULL, NULL, g_cclosure_marshal_VOID__OBJECT, |
| 1711 | G_TYPE_NONE, 1, FU_TYPE_DEVICE); |
Richard Hughes | 362d6d7 | 2017-01-07 21:42:14 +0000 | [diff] [blame] | 1712 | signals[SIGNAL_RECOLDPLUG] = |
| 1713 | g_signal_new ("recoldplug", |
| 1714 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 1715 | G_STRUCT_OFFSET (FuPluginClass, recoldplug), |
| 1716 | NULL, NULL, g_cclosure_marshal_VOID__VOID, |
| 1717 | G_TYPE_NONE, 0); |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 1718 | signals[SIGNAL_SET_COLDPLUG_DELAY] = |
| 1719 | g_signal_new ("set-coldplug-delay", |
| 1720 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 1721 | G_STRUCT_OFFSET (FuPluginClass, set_coldplug_delay), |
| 1722 | NULL, NULL, g_cclosure_marshal_VOID__UINT, |
| 1723 | G_TYPE_NONE, 1, G_TYPE_UINT); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | static void |
| 1727 | fu_plugin_init (FuPlugin *plugin) |
| 1728 | { |
| 1729 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 1730 | priv->enabled = TRUE; |
| 1731 | priv->devices = g_hash_table_new_full (g_str_hash, g_str_equal, |
| 1732 | g_free, (GDestroyNotify) g_object_unref); |
Richard Hughes | e8b5db6 | 2017-07-17 14:18:22 +0100 | [diff] [blame] | 1733 | priv->devices_delay = g_hash_table_new (g_direct_hash, g_direct_equal); |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 1734 | priv->report_metadata = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1735 | for (guint i = 0; i < FU_PLUGIN_RULE_LAST; i++) |
| 1736 | priv->rules[i] = g_ptr_array_new_with_free_func (g_free); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | static void |
| 1740 | fu_plugin_finalize (GObject *object) |
| 1741 | { |
| 1742 | FuPlugin *plugin = FU_PLUGIN (object); |
| 1743 | FuPluginPrivate *priv = GET_PRIVATE (plugin); |
| 1744 | FuPluginInitFunc func = NULL; |
| 1745 | |
| 1746 | /* optional */ |
| 1747 | if (priv->module != NULL) { |
| 1748 | g_module_symbol (priv->module, "fu_plugin_destroy", (gpointer *) &func); |
| 1749 | if (func != NULL) { |
| 1750 | g_debug ("performing destroy() on %s", priv->name); |
| 1751 | func (plugin); |
| 1752 | } |
| 1753 | } |
| 1754 | |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1755 | for (guint i = 0; i < FU_PLUGIN_RULE_LAST; i++) |
| 1756 | g_ptr_array_unref (priv->rules[i]); |
| 1757 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1758 | if (priv->usb_ctx != NULL) |
| 1759 | g_object_unref (priv->usb_ctx); |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 1760 | if (priv->hwids != NULL) |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 1761 | g_object_unref (priv->hwids); |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 1762 | if (priv->quirks != NULL) |
| 1763 | g_object_unref (priv->quirks); |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 1764 | if (priv->supported_guids != NULL) |
| 1765 | g_ptr_array_unref (priv->supported_guids); |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 1766 | if (priv->smbios != NULL) |
| 1767 | g_object_unref (priv->smbios); |
Richard Hughes | 275d3b4 | 2018-04-20 16:40:37 +0100 | [diff] [blame] | 1768 | if (priv->runtime_versions != NULL) |
| 1769 | g_hash_table_unref (priv->runtime_versions); |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 1770 | if (priv->compile_versions != NULL) |
| 1771 | g_hash_table_unref (priv->compile_versions); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1772 | g_hash_table_unref (priv->devices); |
Richard Hughes | ae3d65f | 2016-12-16 09:38:01 +0000 | [diff] [blame] | 1773 | g_hash_table_unref (priv->devices_delay); |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 1774 | g_hash_table_unref (priv->report_metadata); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1775 | g_free (priv->name); |
| 1776 | g_free (priv->data); |
Mario Limonciello | 3f9a1c1 | 2018-06-06 14:06:40 -0500 | [diff] [blame] | 1777 | /* Must happen as the last step to avoid prematurely |
| 1778 | * freeing memory held by the plugin */ |
| 1779 | #ifndef RUNNING_ON_VALGRIND |
| 1780 | if (priv->module != NULL) |
| 1781 | g_module_close (priv->module); |
| 1782 | #endif |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1783 | |
| 1784 | G_OBJECT_CLASS (fu_plugin_parent_class)->finalize (object); |
| 1785 | } |
| 1786 | |
| 1787 | FuPlugin * |
| 1788 | fu_plugin_new (void) |
| 1789 | { |
| 1790 | FuPlugin *plugin; |
| 1791 | plugin = g_object_new (FU_TYPE_PLUGIN, NULL); |
| 1792 | return plugin; |
| 1793 | } |