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