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