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