Richard Hughes | 02c90d8 | 2018-08-09 12:13:03 +0100 | [diff] [blame] | 1 | /* |
Richard Hughes | 5c9b1fc | 2021-01-07 14:20:49 +0000 | [diff] [blame] | 2 | * Copyright (C) 2016 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 | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 16 | |
Richard Hughes | b333e00 | 2021-04-01 10:40:02 +0100 | [diff] [blame] | 17 | #include "fu-context-private.h" |
Richard Hughes | 9dde04f | 2017-09-13 12:07:15 +0100 | [diff] [blame] | 18 | #include "fu-device-private.h" |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 19 | #include "fu-plugin-private.h" |
Richard Hughes | 37d0943 | 2018-09-09 10:39:45 +0100 | [diff] [blame] | 20 | #include "fu-mutex.h" |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 21 | |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 22 | /** |
| 23 | * SECTION:fu-plugin |
| 24 | * @short_description: a daemon plugin |
| 25 | * |
| 26 | * An object that represents a plugin run by the daemon. |
| 27 | * |
| 28 | * See also: #FuDevice |
| 29 | */ |
| 30 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 31 | static void fu_plugin_finalize (GObject *object); |
| 32 | |
| 33 | typedef struct { |
| 34 | GModule *module; |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 35 | guint order; |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 36 | guint priority; |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 37 | GPtrArray *rules[FU_PLUGIN_RULE_LAST]; |
Richard Hughes | 68ab1e4 | 2021-01-13 14:01:17 +0000 | [diff] [blame] | 38 | GPtrArray *devices; /* (nullable) (element-type FuDevice) */ |
Richard Hughes | f425d29 | 2019-01-18 17:57:39 +0000 | [diff] [blame] | 39 | gchar *build_hash; |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 40 | GHashTable *runtime_versions; |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 41 | GHashTable *compile_versions; |
Richard Hughes | b333e00 | 2021-04-01 10:40:02 +0100 | [diff] [blame] | 42 | FuContext *ctx; |
Richard Hughes | faa35e4 | 2021-04-15 09:38:03 +0100 | [diff] [blame] | 43 | GArray *device_gtypes; /* (nullable): of #GType */ |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 44 | GHashTable *cache; /* (nullable): platform_id:GObject */ |
| 45 | GRWLock cache_mutex; |
Richard Hughes | 1d900f7 | 2020-06-22 15:17:39 +0100 | [diff] [blame] | 46 | GHashTable *report_metadata; /* (nullable): key:value */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 47 | FuPluginData *data; |
| 48 | } FuPluginPrivate; |
| 49 | |
| 50 | enum { |
| 51 | SIGNAL_DEVICE_ADDED, |
| 52 | SIGNAL_DEVICE_REMOVED, |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 53 | SIGNAL_DEVICE_REGISTER, |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 54 | SIGNAL_RULES_CHANGED, |
Richard Hughes | aabdc37 | 2018-11-14 10:11:08 +0000 | [diff] [blame] | 55 | SIGNAL_CHECK_SUPPORTED, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 56 | SIGNAL_LAST |
| 57 | }; |
| 58 | |
| 59 | static guint signals[SIGNAL_LAST] = { 0 }; |
| 60 | |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 61 | G_DEFINE_TYPE_WITH_PRIVATE (FuPlugin, fu_plugin, FWUPD_TYPE_PLUGIN) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 62 | #define GET_PRIVATE(o) (fu_plugin_get_instance_private (o)) |
| 63 | |
| 64 | typedef const gchar *(*FuPluginGetNameFunc) (void); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 65 | typedef void (*FuPluginInitFunc) (FuPlugin *self); |
| 66 | typedef gboolean (*FuPluginStartupFunc) (FuPlugin *self, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 67 | GError **error); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 68 | typedef void (*FuPluginDeviceRegisterFunc) (FuPlugin *self, |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 69 | FuDevice *device); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 70 | typedef gboolean (*FuPluginDeviceFunc) (FuPlugin *self, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 71 | FuDevice *device, |
| 72 | GError **error); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 73 | typedef gboolean (*FuPluginFlaggedDeviceFunc) (FuPlugin *self, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 74 | FwupdInstallFlags flags, |
| 75 | FuDevice *device, |
| 76 | GError **error); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 77 | typedef gboolean (*FuPluginDeviceArrayFunc) (FuPlugin *self, |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 78 | GPtrArray *devices, |
| 79 | GError **error); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 80 | typedef gboolean (*FuPluginVerifyFunc) (FuPlugin *self, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 81 | FuDevice *device, |
| 82 | FuPluginVerifyFlags flags, |
| 83 | GError **error); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 84 | typedef gboolean (*FuPluginUpdateFunc) (FuPlugin *self, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 85 | FuDevice *device, |
| 86 | GBytes *blob_fw, |
| 87 | FwupdInstallFlags flags, |
| 88 | GError **error); |
Richard Hughes | f58ac73 | 2020-05-12 15:23:44 +0100 | [diff] [blame] | 89 | typedef void (*FuPluginSecurityAttrsFunc) (FuPlugin *self, |
| 90 | FuSecurityAttrs *attrs); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 91 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 92 | /** |
Mario Limonciello | 52e75ba | 2019-11-22 13:21:19 -0600 | [diff] [blame] | 93 | * fu_plugin_is_open: |
| 94 | * @self: A #FuPlugin |
| 95 | * |
| 96 | * Determines if the plugin is opened |
| 97 | * |
| 98 | * Returns: TRUE for opened, FALSE for not |
| 99 | * |
| 100 | * Since: 1.3.5 |
| 101 | **/ |
| 102 | gboolean |
| 103 | fu_plugin_is_open (FuPlugin *self) |
| 104 | { |
| 105 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 106 | return priv->module != NULL; |
| 107 | } |
| 108 | |
| 109 | /** |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 110 | * fu_plugin_get_name: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 111 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 112 | * |
| 113 | * Gets the plugin name. |
| 114 | * |
| 115 | * Returns: a plugin name, or %NULL for unknown. |
| 116 | * |
| 117 | * Since: 0.8.0 |
| 118 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 119 | const gchar * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 120 | fu_plugin_get_name (FuPlugin *self) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 121 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 122 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 123 | return fwupd_plugin_get_name (FWUPD_PLUGIN (self)); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 124 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 125 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 126 | /** |
| 127 | * fu_plugin_set_name: |
| 128 | * @self: A #FuPlugin |
| 129 | * @name: A string |
| 130 | * |
| 131 | * Sets the plugin name. |
| 132 | * |
| 133 | * Since: 0.8.0 |
| 134 | **/ |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 135 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 136 | fu_plugin_set_name (FuPlugin *self, const gchar *name) |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 137 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 138 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 139 | fwupd_plugin_set_name (FWUPD_PLUGIN (self), name); |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 142 | /** |
Richard Hughes | f425d29 | 2019-01-18 17:57:39 +0000 | [diff] [blame] | 143 | * fu_plugin_set_build_hash: |
| 144 | * @self: A #FuPlugin |
| 145 | * @build_hash: A checksum |
| 146 | * |
| 147 | * Sets the plugin build hash, typically a SHA256 checksum. All plugins must |
| 148 | * set the correct checksum to avoid the daemon being marked as tainted. |
| 149 | * |
| 150 | * Since: 1.2.4 |
| 151 | **/ |
| 152 | void |
| 153 | fu_plugin_set_build_hash (FuPlugin *self, const gchar *build_hash) |
| 154 | { |
| 155 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 156 | g_return_if_fail (FU_IS_PLUGIN (self)); |
| 157 | g_return_if_fail (build_hash != NULL); |
Richard Hughes | 382524d | 2021-01-28 13:14:35 +0000 | [diff] [blame] | 158 | |
| 159 | /* not changed */ |
| 160 | if (g_strcmp0 (priv->build_hash, build_hash) == 0) |
| 161 | return; |
| 162 | |
Richard Hughes | f425d29 | 2019-01-18 17:57:39 +0000 | [diff] [blame] | 163 | g_free (priv->build_hash); |
| 164 | priv->build_hash = g_strdup (build_hash); |
| 165 | } |
| 166 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 167 | /** |
| 168 | * fu_plugin_get_build_hash: |
| 169 | * @self: A #FuPlugin |
| 170 | * |
| 171 | * Gets the build hash a plugin was generated with. |
| 172 | * |
| 173 | * Returns: (transfer none): a #gchar, or %NULL for unset. |
| 174 | * |
| 175 | * Since: 1.2.4 |
| 176 | **/ |
Richard Hughes | f425d29 | 2019-01-18 17:57:39 +0000 | [diff] [blame] | 177 | const gchar * |
| 178 | fu_plugin_get_build_hash (FuPlugin *self) |
| 179 | { |
| 180 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 181 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
| 182 | return priv->build_hash; |
| 183 | } |
| 184 | |
| 185 | /** |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 186 | * fu_plugin_cache_lookup: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 187 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 188 | * @id: the key |
| 189 | * |
| 190 | * Finds an object in the per-plugin cache. |
| 191 | * |
| 192 | * Returns: (transfer none): a #GObject, or %NULL for unfound. |
| 193 | * |
| 194 | * Since: 0.8.0 |
| 195 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 196 | gpointer |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 197 | fu_plugin_cache_lookup (FuPlugin *self, const gchar *id) |
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 | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 200 | g_autoptr(GRWLockReaderLocker) locker = g_rw_lock_reader_locker_new (&priv->cache_mutex); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 201 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 202 | g_return_val_if_fail (id != NULL, NULL); |
Richard Hughes | 37d0943 | 2018-09-09 10:39:45 +0100 | [diff] [blame] | 203 | g_return_val_if_fail (locker != NULL, NULL); |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 204 | if (priv->cache == NULL) |
Richard Hughes | 371f6b2 | 2020-06-22 15:21:17 +0100 | [diff] [blame] | 205 | return NULL; |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 206 | return g_hash_table_lookup (priv->cache, id); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 207 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 208 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 209 | /** |
| 210 | * fu_plugin_cache_add: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 211 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 212 | * @id: the key |
| 213 | * @dev: a #GObject, typically a #FuDevice |
| 214 | * |
| 215 | * Adds an object to the per-plugin cache. |
| 216 | * |
| 217 | * Since: 0.8.0 |
| 218 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 219 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 220 | fu_plugin_cache_add (FuPlugin *self, const gchar *id, gpointer dev) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 221 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 222 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 223 | g_autoptr(GRWLockWriterLocker) locker = g_rw_lock_writer_locker_new (&priv->cache_mutex); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 224 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 225 | g_return_if_fail (id != NULL); |
Richard Hughes | 46f86a5 | 2021-04-20 11:47:46 +0100 | [diff] [blame] | 226 | g_return_if_fail (G_IS_OBJECT (dev)); |
Richard Hughes | 37d0943 | 2018-09-09 10:39:45 +0100 | [diff] [blame] | 227 | g_return_if_fail (locker != NULL); |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 228 | if (priv->cache == NULL) { |
| 229 | priv->cache = g_hash_table_new_full (g_str_hash, |
| 230 | g_str_equal, |
| 231 | g_free, |
| 232 | (GDestroyNotify) g_object_unref); |
Richard Hughes | 371f6b2 | 2020-06-22 15:21:17 +0100 | [diff] [blame] | 233 | } |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 234 | g_hash_table_insert (priv->cache, g_strdup (id), g_object_ref (dev)); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 235 | } |
| 236 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 237 | /** |
| 238 | * fu_plugin_cache_remove: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 239 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 240 | * @id: the key |
| 241 | * |
| 242 | * Removes an object from the per-plugin cache. |
| 243 | * |
| 244 | * Since: 0.8.0 |
| 245 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 246 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 247 | fu_plugin_cache_remove (FuPlugin *self, const gchar *id) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 248 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 249 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 250 | g_autoptr(GRWLockWriterLocker) locker = g_rw_lock_writer_locker_new (&priv->cache_mutex); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 251 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 252 | g_return_if_fail (id != NULL); |
Richard Hughes | 37d0943 | 2018-09-09 10:39:45 +0100 | [diff] [blame] | 253 | g_return_if_fail (locker != NULL); |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 254 | if (priv->cache == NULL) |
Richard Hughes | 371f6b2 | 2020-06-22 15:21:17 +0100 | [diff] [blame] | 255 | return; |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 256 | g_hash_table_remove (priv->cache, id); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 259 | /** |
| 260 | * fu_plugin_get_data: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 261 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 262 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 263 | * Gets the per-plugin allocated private data. This will return %NULL unless |
| 264 | * fu_plugin_alloc_data() has been called by the plugin. |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 265 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 266 | * Returns: (transfer none): a pointer to a structure, or %NULL for unset. |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 267 | * |
| 268 | * Since: 0.8.0 |
| 269 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 270 | FuPluginData * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 271 | fu_plugin_get_data (FuPlugin *self) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 272 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 273 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 274 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 275 | return priv->data; |
| 276 | } |
| 277 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 278 | /** |
Richard Hughes | 00f66f6 | 2019-11-27 11:42:53 +0000 | [diff] [blame] | 279 | * fu_plugin_alloc_data: (skip): |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 280 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 281 | * @data_sz: the size to allocate |
| 282 | * |
| 283 | * Allocates the per-plugin allocated private data. |
| 284 | * |
| 285 | * Returns: (transfer full): a pointer to a structure, or %NULL for unset. |
| 286 | * |
| 287 | * Since: 0.8.0 |
| 288 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 289 | FuPluginData * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 290 | fu_plugin_alloc_data (FuPlugin *self, gsize data_sz) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 291 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 292 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 293 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
Richard Hughes | 44dee88 | 2017-01-11 08:31:10 +0000 | [diff] [blame] | 294 | if (priv->data != NULL) { |
| 295 | g_critical ("fu_plugin_alloc_data() already used by plugin"); |
| 296 | return priv->data; |
| 297 | } |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 298 | priv->data = g_malloc0 (data_sz); |
| 299 | return priv->data; |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 302 | /** |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 303 | * fu_plugin_guess_name_from_fn: |
| 304 | * @filename: filename to guess |
| 305 | * |
| 306 | * Tries to guess the name of the plugin from a filename |
| 307 | * |
| 308 | * Returns: (transfer full): the guessed name of the plugin |
| 309 | * |
| 310 | * Since: 1.0.8 |
| 311 | **/ |
Richard Hughes | 1e456bc | 2018-05-10 20:16:16 +0100 | [diff] [blame] | 312 | gchar * |
| 313 | fu_plugin_guess_name_from_fn (const gchar *filename) |
| 314 | { |
| 315 | const gchar *prefix = "libfu_plugin_"; |
| 316 | gchar *name; |
| 317 | gchar *str = g_strstr_len (filename, -1, prefix); |
| 318 | if (str == NULL) |
| 319 | return NULL; |
| 320 | name = g_strdup (str + strlen (prefix)); |
| 321 | g_strdelimit (name, ".", '\0'); |
| 322 | return name; |
| 323 | } |
| 324 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 325 | /** |
| 326 | * fu_plugin_open: |
| 327 | * @self: A #FuPlugin |
| 328 | * @filename: The shared object filename to open |
| 329 | * @error: A #GError or NULL |
| 330 | * |
| 331 | * Opens the plugin module |
| 332 | * |
| 333 | * Returns: TRUE for success, FALSE for fail |
| 334 | * |
| 335 | * Since: 0.8.0 |
| 336 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 337 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 338 | fu_plugin_open (FuPlugin *self, const gchar *filename, GError **error) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 339 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 340 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 341 | FuPluginInitFunc func = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 342 | |
Richard Hughes | 6a489a9 | 2020-12-22 10:32:06 +0000 | [diff] [blame] | 343 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
| 344 | g_return_val_if_fail (filename != NULL, FALSE); |
| 345 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 346 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 347 | priv->module = g_module_open (filename, 0); |
| 348 | if (priv->module == NULL) { |
| 349 | g_set_error (error, |
| 350 | G_IO_ERROR, |
| 351 | G_IO_ERROR_FAILED, |
Mario Limonciello | f560553 | 2019-11-04 07:49:50 -0600 | [diff] [blame] | 352 | "failed to open plugin %s: %s", |
| 353 | filename, g_module_error ()); |
Mario Limonciello | c3a8173 | 2020-10-20 09:16:18 -0500 | [diff] [blame] | 354 | fu_plugin_add_flag (self, FWUPD_PLUGIN_FLAG_FAILED_OPEN); |
| 355 | fu_plugin_add_flag (self, FWUPD_PLUGIN_FLAG_USER_WARNING); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 356 | return FALSE; |
| 357 | } |
| 358 | |
| 359 | /* set automatically */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 360 | if (fu_plugin_get_name (self) == NULL) { |
| 361 | g_autofree gchar *str = fu_plugin_guess_name_from_fn (filename); |
| 362 | fu_plugin_set_name (self, str); |
| 363 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 364 | |
| 365 | /* optional */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 366 | g_module_symbol (priv->module, "fu_plugin_init", (gpointer *) &func); |
| 367 | if (func != NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 368 | g_debug ("init(%s)", filename); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 369 | func (self); |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 370 | } |
| 371 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 372 | return TRUE; |
| 373 | } |
| 374 | |
Richard Hughes | 203ed84 | 2020-11-02 14:25:13 +0000 | [diff] [blame] | 375 | /* order of usefulness to the user */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 376 | static const gchar * |
| 377 | fu_plugin_build_device_update_error (FuPlugin *self) |
| 378 | { |
| 379 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_NO_HARDWARE)) |
| 380 | return "Not updatable as required hardware was not found"; |
| 381 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_LEGACY_BIOS)) |
| 382 | return "Not updatable in legacy BIOS mode"; |
| 383 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_CAPSULES_UNSUPPORTED)) |
Mario Limonciello | 797da4f | 2021-01-12 12:38:51 -0600 | [diff] [blame] | 384 | return "Not updatable as UEFI capsule updates not enabled in firmware setup"; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 385 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_UNLOCK_REQUIRED)) |
| 386 | return "Not updatable as requires unlock"; |
| 387 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_EFIVAR_NOT_MOUNTED)) |
| 388 | return "Not updatable as efivarfs was not found"; |
| 389 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_ESP_NOT_FOUND)) |
| 390 | return "Not updatable as UEFI ESP partition not detected"; |
| 391 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
| 392 | return "Not updatable as plugin was disabled"; |
| 393 | return NULL; |
| 394 | } |
| 395 | |
Richard Hughes | 68ab1e4 | 2021-01-13 14:01:17 +0000 | [diff] [blame] | 396 | static void |
| 397 | fu_plugin_ensure_devices (FuPlugin *self) |
| 398 | { |
| 399 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 400 | if (priv->devices != NULL) |
| 401 | return; |
| 402 | priv->devices = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); |
| 403 | } |
| 404 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 405 | /** |
| 406 | * fu_plugin_device_add: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 407 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 408 | * @device: A #FuDevice |
| 409 | * |
| 410 | * Asks the daemon to add a device to the exported list. If this device ID |
| 411 | * has already been added by a different plugin then this request will be |
| 412 | * ignored. |
| 413 | * |
| 414 | * Plugins should use fu_plugin_device_add_delay() if they are not capable of |
| 415 | * actually flashing an image to the hardware so that higher-priority plugins |
| 416 | * can add the device themselves. |
| 417 | * |
| 418 | * Since: 0.8.0 |
| 419 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 420 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 421 | fu_plugin_device_add (FuPlugin *self, FuDevice *device) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 422 | { |
Richard Hughes | 68ab1e4 | 2021-01-13 14:01:17 +0000 | [diff] [blame] | 423 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 424 | GPtrArray *children; |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 425 | g_autoptr(GError) error = NULL; |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 426 | |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 427 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 428 | g_return_if_fail (FU_IS_DEVICE (device)); |
| 429 | |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 430 | /* ensure the device ID is set from the physical and logical IDs */ |
| 431 | if (!fu_device_ensure_id (device, &error)) { |
| 432 | g_warning ("ignoring add: %s", error->message); |
| 433 | return; |
| 434 | } |
| 435 | |
Richard Hughes | 68ab1e4 | 2021-01-13 14:01:17 +0000 | [diff] [blame] | 436 | /* add to array */ |
| 437 | fu_plugin_ensure_devices (self); |
| 438 | g_ptr_array_add (priv->devices, g_object_ref (device)); |
| 439 | |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 440 | /* proxy to device where required */ |
| 441 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_CLEAR_UPDATABLE)) { |
| 442 | g_debug ("plugin %s has _CLEAR_UPDATABLE, so removing from %s", |
| 443 | fu_plugin_get_name (self), |
| 444 | fu_device_get_id (device)); |
| 445 | fu_device_remove_flag (device, FWUPD_DEVICE_FLAG_UPDATABLE); |
| 446 | } |
| 447 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_USER_WARNING) && |
| 448 | fu_device_get_update_error (device) == NULL) { |
| 449 | const gchar *tmp = fu_plugin_build_device_update_error (self); |
| 450 | g_debug ("setting %s update error to '%s' from %s", |
| 451 | fu_device_get_id (device), tmp, fu_plugin_get_name (self)); |
| 452 | fu_device_set_update_error (device, tmp); |
| 453 | } |
| 454 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 455 | g_debug ("emit added from %s: %s", |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 456 | fu_plugin_get_name (self), |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 457 | fu_device_get_id (device)); |
| 458 | 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] | 459 | fu_device_set_plugin (device, fu_plugin_get_name (self)); |
| 460 | g_signal_emit (self, signals[SIGNAL_DEVICE_ADDED], 0, device); |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 461 | |
Richard Hughes | 128c016 | 2018-08-10 11:00:29 +0100 | [diff] [blame] | 462 | /* add children if they have not already been added */ |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 463 | children = fu_device_get_children (device); |
| 464 | for (guint i = 0; i < children->len; i++) { |
| 465 | FuDevice *child = g_ptr_array_index (children, i); |
Richard Hughes | 128c016 | 2018-08-10 11:00:29 +0100 | [diff] [blame] | 466 | if (fu_device_get_created (child) == 0) |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 467 | fu_plugin_device_add (self, child); |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 468 | } |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 469 | } |
| 470 | |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 471 | /** |
Richard Hughes | 68ab1e4 | 2021-01-13 14:01:17 +0000 | [diff] [blame] | 472 | * fu_plugin_get_devices: |
| 473 | * @self: A #FuPlugin |
| 474 | * |
| 475 | * Returns all devices added by the plugin using fu_plugin_device_add() and |
| 476 | * not yet removed with fu_plugin_device_remove(). |
| 477 | * |
| 478 | * Returns: (transfer none) (element-type FuDevice): devices |
| 479 | * |
| 480 | * Since: 1.5.6 |
| 481 | **/ |
| 482 | GPtrArray * |
| 483 | fu_plugin_get_devices (FuPlugin *self) |
| 484 | { |
| 485 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 486 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
| 487 | fu_plugin_ensure_devices (self); |
| 488 | return priv->devices; |
| 489 | } |
| 490 | |
| 491 | /** |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 492 | * fu_plugin_device_register: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 493 | * @self: A #FuPlugin |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 494 | * @device: A #FuDevice |
| 495 | * |
| 496 | * Registers the device with other plugins so they can set metadata. |
| 497 | * |
| 498 | * Plugins do not have to call this manually as this is done automatically |
| 499 | * when using fu_plugin_device_add(). They may wish to use this manually |
Richard Hughes | 21eaeef | 2020-01-14 12:10:01 +0000 | [diff] [blame] | 500 | * if for instance the coldplug should be ignored based on the metadata |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 501 | * set from other plugins. |
| 502 | * |
| 503 | * Since: 0.9.7 |
| 504 | **/ |
| 505 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 506 | fu_plugin_device_register (FuPlugin *self, FuDevice *device) |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 507 | { |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 508 | g_autoptr(GError) error = NULL; |
| 509 | |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 510 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 511 | g_return_if_fail (FU_IS_DEVICE (device)); |
| 512 | |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 513 | /* ensure the device ID is set from the physical and logical IDs */ |
| 514 | if (!fu_device_ensure_id (device, &error)) { |
| 515 | g_warning ("ignoring registration: %s", error->message); |
| 516 | return; |
| 517 | } |
| 518 | |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 519 | g_debug ("emit device-register from %s: %s", |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 520 | fu_plugin_get_name (self), |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 521 | fu_device_get_id (device)); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 522 | g_signal_emit (self, signals[SIGNAL_DEVICE_REGISTER], 0, device); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 523 | } |
| 524 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 525 | /** |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 526 | * fu_plugin_device_remove: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 527 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 528 | * @device: A #FuDevice |
| 529 | * |
| 530 | * Asks the daemon to remove a device from the exported list. |
| 531 | * |
| 532 | * Since: 0.8.0 |
| 533 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 534 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 535 | fu_plugin_device_remove (FuPlugin *self, FuDevice *device) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 536 | { |
Richard Hughes | 68ab1e4 | 2021-01-13 14:01:17 +0000 | [diff] [blame] | 537 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 538 | |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 539 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 540 | g_return_if_fail (FU_IS_DEVICE (device)); |
| 541 | |
Richard Hughes | 68ab1e4 | 2021-01-13 14:01:17 +0000 | [diff] [blame] | 542 | /* remove from array */ |
| 543 | if (priv->devices != NULL) |
| 544 | g_ptr_array_remove (priv->devices, device); |
| 545 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 546 | g_debug ("emit removed from %s: %s", |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 547 | fu_plugin_get_name (self), |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 548 | fu_device_get_id (device)); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 549 | g_signal_emit (self, signals[SIGNAL_DEVICE_REMOVED], 0, device); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 550 | } |
| 551 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 552 | /** |
Richard Hughes | 1984180 | 2019-09-10 16:48:00 +0100 | [diff] [blame] | 553 | * fu_plugin_has_custom_flag: |
| 554 | * @self: A #FuPlugin |
| 555 | * @flag: A custom text flag, specific to the plugin, e.g. `uefi-force-enable` |
| 556 | * |
| 557 | * Returns if a per-plugin HwId custom flag exists, typically added from a DMI quirk. |
| 558 | * |
| 559 | * Returns: %TRUE if the quirk entry exists |
| 560 | * |
| 561 | * Since: 1.3.1 |
| 562 | **/ |
| 563 | gboolean |
| 564 | fu_plugin_has_custom_flag (FuPlugin *self, const gchar *flag) |
| 565 | { |
| 566 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | b333e00 | 2021-04-01 10:40:02 +0100 | [diff] [blame] | 567 | GPtrArray *guids; |
Richard Hughes | 1984180 | 2019-09-10 16:48:00 +0100 | [diff] [blame] | 568 | |
| 569 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
| 570 | g_return_val_if_fail (flag != NULL, FALSE); |
| 571 | |
| 572 | /* never set up, e.g. in tests */ |
Richard Hughes | b333e00 | 2021-04-01 10:40:02 +0100 | [diff] [blame] | 573 | if (priv->ctx == NULL) |
Richard Hughes | 1984180 | 2019-09-10 16:48:00 +0100 | [diff] [blame] | 574 | return FALSE; |
| 575 | |
| 576 | /* search each hwid */ |
Richard Hughes | b333e00 | 2021-04-01 10:40:02 +0100 | [diff] [blame] | 577 | guids = fu_context_get_hwid_guids (priv->ctx); |
| 578 | for (guint i = 0; i < guids->len; i++) { |
| 579 | const gchar *guid = g_ptr_array_index (guids, i); |
Richard Hughes | 1984180 | 2019-09-10 16:48:00 +0100 | [diff] [blame] | 580 | const gchar *value; |
Richard Hughes | 1984180 | 2019-09-10 16:48:00 +0100 | [diff] [blame] | 581 | |
| 582 | /* does prefixed quirk exist */ |
Richard Hughes | b333e00 | 2021-04-01 10:40:02 +0100 | [diff] [blame] | 583 | value = fu_context_lookup_quirk_by_id (priv->ctx, guid, FU_QUIRKS_FLAGS); |
Richard Hughes | 1984180 | 2019-09-10 16:48:00 +0100 | [diff] [blame] | 584 | if (value != NULL) { |
Richard Hughes | b333e00 | 2021-04-01 10:40:02 +0100 | [diff] [blame] | 585 | g_auto(GStrv) values = g_strsplit (value, ",", -1); |
| 586 | if (g_strv_contains ((const gchar * const *) values, flag)) |
Richard Hughes | 1984180 | 2019-09-10 16:48:00 +0100 | [diff] [blame] | 587 | return TRUE; |
| 588 | } |
| 589 | } |
| 590 | return FALSE; |
| 591 | } |
| 592 | |
| 593 | /** |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 594 | * fu_plugin_check_supported: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 595 | * @self: A #FuPlugin |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 596 | * @guid: A Hardware ID GUID, e.g. `6de5d951-d755-576b-bd09-c5cf66b27234` |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 597 | * |
| 598 | * Checks to see if a specific device GUID is supported, i.e. available in the |
| 599 | * AppStream metadata. |
| 600 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 601 | * Returns: %TRUE if the device is supported. |
| 602 | * |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 603 | * Since: 1.0.0 |
| 604 | **/ |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 605 | static gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 606 | fu_plugin_check_supported (FuPlugin *self, const gchar *guid) |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 607 | { |
Richard Hughes | aabdc37 | 2018-11-14 10:11:08 +0000 | [diff] [blame] | 608 | gboolean retval = FALSE; |
| 609 | g_signal_emit (self, signals[SIGNAL_CHECK_SUPPORTED], 0, guid, &retval); |
| 610 | return retval; |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | /** |
Richard Hughes | b333e00 | 2021-04-01 10:40:02 +0100 | [diff] [blame] | 614 | * fu_plugin_get_context: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 615 | * @self: A #FuPlugin |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 616 | * |
Richard Hughes | b333e00 | 2021-04-01 10:40:02 +0100 | [diff] [blame] | 617 | * Gets the context for a plugin. |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 618 | * |
Richard Hughes | b333e00 | 2021-04-01 10:40:02 +0100 | [diff] [blame] | 619 | * Returns: (transfer none): a #FuContext or %NULL if not set |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 620 | * |
Richard Hughes | b333e00 | 2021-04-01 10:40:02 +0100 | [diff] [blame] | 621 | * Since: 1.6.0 |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 622 | **/ |
Richard Hughes | b333e00 | 2021-04-01 10:40:02 +0100 | [diff] [blame] | 623 | FuContext * |
| 624 | fu_plugin_get_context (FuPlugin *self) |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 625 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 626 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | b333e00 | 2021-04-01 10:40:02 +0100 | [diff] [blame] | 627 | return priv->ctx; |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 628 | } |
| 629 | |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 630 | static gboolean |
| 631 | fu_plugin_device_attach (FuPlugin *self, FuDevice *device, GError **error) |
| 632 | { |
| 633 | g_autoptr(FuDeviceLocker) locker = NULL; |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 634 | locker = fu_device_locker_new (device, error); |
| 635 | if (locker == NULL) |
| 636 | return FALSE; |
| 637 | return fu_device_attach (device, error); |
| 638 | } |
| 639 | |
| 640 | static gboolean |
| 641 | fu_plugin_device_detach (FuPlugin *self, FuDevice *device, GError **error) |
| 642 | { |
| 643 | g_autoptr(FuDeviceLocker) locker = NULL; |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 644 | locker = fu_device_locker_new (device, error); |
| 645 | if (locker == NULL) |
| 646 | return FALSE; |
| 647 | return fu_device_detach (device, error); |
| 648 | } |
| 649 | |
| 650 | static gboolean |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 651 | fu_plugin_device_activate (FuPlugin *self, FuDevice *device, GError **error) |
| 652 | { |
| 653 | g_autoptr(FuDeviceLocker) locker = NULL; |
| 654 | locker = fu_device_locker_new (device, error); |
| 655 | if (locker == NULL) |
| 656 | return FALSE; |
| 657 | return fu_device_activate (device, error); |
| 658 | } |
| 659 | |
| 660 | static gboolean |
| 661 | fu_plugin_device_write_firmware (FuPlugin *self, FuDevice *device, |
| 662 | GBytes *fw, FwupdInstallFlags flags, |
| 663 | GError **error) |
| 664 | { |
| 665 | g_autoptr(FuDeviceLocker) locker = NULL; |
| 666 | locker = fu_device_locker_new (device, error); |
| 667 | if (locker == NULL) |
| 668 | return FALSE; |
Richard Hughes | 1a61258 | 2020-09-29 19:39:38 +0100 | [diff] [blame] | 669 | |
| 670 | /* back the old firmware up to /var/lib/fwupd */ |
| 671 | if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_BACKUP_BEFORE_INSTALL)) { |
| 672 | g_autoptr(GBytes) fw_old = NULL; |
| 673 | g_autofree gchar *path = NULL; |
| 674 | g_autofree gchar *fn = NULL; |
| 675 | g_autofree gchar *localstatedir = NULL; |
| 676 | |
| 677 | fw_old = fu_device_dump_firmware (device, error); |
| 678 | if (fw_old == NULL) { |
| 679 | g_prefix_error (error, "failed to backup old firmware: "); |
| 680 | return FALSE; |
| 681 | } |
| 682 | localstatedir = fu_common_get_path (FU_PATH_KIND_LOCALSTATEDIR_PKG); |
| 683 | fn = g_strdup_printf ("%s.bin", fu_device_get_version (device)); |
| 684 | path = g_build_filename (localstatedir, |
| 685 | "backup", |
| 686 | fu_device_get_id (device), |
| 687 | fu_device_get_serial (device) != NULL ? |
| 688 | fu_device_get_serial (device) : |
| 689 | "default", |
| 690 | fn, NULL); |
| 691 | if (!fu_common_set_contents_bytes (path, fw_old, error)) |
| 692 | return FALSE; |
| 693 | } |
| 694 | |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 695 | return fu_device_write_firmware (device, fw, flags, error); |
| 696 | } |
| 697 | |
Richard Hughes | 7f67721 | 2019-10-05 16:19:40 +0100 | [diff] [blame] | 698 | static gboolean |
| 699 | fu_plugin_device_read_firmware (FuPlugin *self, FuDevice *device, GError **error) |
| 700 | { |
| 701 | g_autoptr(FuDeviceLocker) locker = NULL; |
Richard Hughes | f0eb091 | 2019-10-10 11:37:22 +0100 | [diff] [blame] | 702 | g_autoptr(FuFirmware) firmware = NULL; |
Richard Hughes | 7f67721 | 2019-10-05 16:19:40 +0100 | [diff] [blame] | 703 | g_autoptr(GBytes) fw = NULL; |
| 704 | GChecksumType checksum_types[] = { |
| 705 | G_CHECKSUM_SHA1, |
| 706 | G_CHECKSUM_SHA256, |
| 707 | 0 }; |
| 708 | locker = fu_device_locker_new (device, error); |
| 709 | if (locker == NULL) |
| 710 | return FALSE; |
| 711 | if (!fu_device_detach (device, error)) |
| 712 | return FALSE; |
Richard Hughes | f0eb091 | 2019-10-10 11:37:22 +0100 | [diff] [blame] | 713 | firmware = fu_device_read_firmware (device, error); |
| 714 | if (firmware == NULL) { |
| 715 | g_autoptr(GError) error_local = NULL; |
| 716 | if (!fu_device_attach (device, &error_local)) |
| 717 | g_debug ("ignoring attach failure: %s", error_local->message); |
| 718 | g_prefix_error (error, "failed to read firmware: "); |
| 719 | return FALSE; |
| 720 | } |
| 721 | fw = fu_firmware_write (firmware, error); |
Richard Hughes | 7f67721 | 2019-10-05 16:19:40 +0100 | [diff] [blame] | 722 | if (fw == NULL) { |
| 723 | g_autoptr(GError) error_local = NULL; |
| 724 | if (!fu_device_attach (device, &error_local)) |
Richard Hughes | f0eb091 | 2019-10-10 11:37:22 +0100 | [diff] [blame] | 725 | g_debug ("ignoring attach failure: %s", error_local->message); |
| 726 | g_prefix_error (error, "failed to write firmware: "); |
Richard Hughes | 7f67721 | 2019-10-05 16:19:40 +0100 | [diff] [blame] | 727 | return FALSE; |
| 728 | } |
| 729 | for (guint i = 0; checksum_types[i] != 0; i++) { |
| 730 | g_autofree gchar *hash = NULL; |
| 731 | hash = g_compute_checksum_for_bytes (checksum_types[i], fw); |
| 732 | fu_device_add_checksum (device, hash); |
| 733 | } |
| 734 | return fu_device_attach (device, error); |
| 735 | } |
| 736 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 737 | /** |
| 738 | * fu_plugin_runner_startup: |
| 739 | * @self: a #FuPlugin |
| 740 | * @error: a #GError or NULL |
| 741 | * |
| 742 | * Runs the startup routine for the plugin |
| 743 | * |
| 744 | * Returns: #TRUE for success, #FALSE for failure |
| 745 | * |
| 746 | * Since: 0.8.0 |
| 747 | **/ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 748 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 749 | fu_plugin_runner_startup (FuPlugin *self, GError **error) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 750 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 751 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 752 | FuPluginStartupFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 753 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 754 | |
| 755 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 756 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 757 | return TRUE; |
| 758 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 759 | /* no object loaded */ |
| 760 | if (priv->module == NULL) |
| 761 | return TRUE; |
| 762 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 763 | /* optional */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 764 | g_module_symbol (priv->module, "fu_plugin_startup", (gpointer *) &func); |
| 765 | if (func == NULL) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 766 | return TRUE; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 767 | g_debug ("startup(%s)", fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 768 | if (!func (self, &error_local)) { |
| 769 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 770 | g_critical ("unset plugin error in startup(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 771 | fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 772 | g_set_error_literal (&error_local, |
| 773 | FWUPD_ERROR, |
| 774 | FWUPD_ERROR_INTERNAL, |
| 775 | "unspecified error"); |
| 776 | } |
| 777 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 778 | "failed to startup using %s: ", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 779 | fu_plugin_get_name (self)); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 780 | return FALSE; |
| 781 | } |
| 782 | return TRUE; |
| 783 | } |
| 784 | |
| 785 | static gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 786 | fu_plugin_runner_device_generic (FuPlugin *self, FuDevice *device, |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 787 | const gchar *symbol_name, |
| 788 | FuPluginDeviceFunc device_func, |
| 789 | GError **error) |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 790 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 791 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 792 | FuPluginDeviceFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 793 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 794 | |
| 795 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 796 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 797 | return TRUE; |
| 798 | |
Richard Hughes | d3d96cc | 2017-11-14 11:34:33 +0000 | [diff] [blame] | 799 | /* no object loaded */ |
| 800 | if (priv->module == NULL) |
| 801 | return TRUE; |
| 802 | |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 803 | /* optional */ |
| 804 | g_module_symbol (priv->module, symbol_name, (gpointer *) &func); |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 805 | if (func == NULL) { |
| 806 | if (device_func != NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 807 | g_debug ("running superclassed %s(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 808 | symbol_name + 10, fu_plugin_get_name (self)); |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 809 | return device_func (self, device, error); |
| 810 | } |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 811 | return TRUE; |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 812 | } |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 813 | g_debug ("%s(%s)", symbol_name + 10, fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 814 | if (!func (self, device, &error_local)) { |
| 815 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 816 | g_critical ("unset plugin error in %s(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 817 | fu_plugin_get_name (self), symbol_name + 10); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 818 | g_set_error_literal (&error_local, |
| 819 | FWUPD_ERROR, |
| 820 | FWUPD_ERROR_INTERNAL, |
| 821 | "unspecified error"); |
| 822 | } |
| 823 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 824 | "failed to %s using %s: ", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 825 | symbol_name + 10, fu_plugin_get_name (self)); |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 826 | return FALSE; |
| 827 | } |
| 828 | return TRUE; |
| 829 | } |
| 830 | |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 831 | static gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 832 | fu_plugin_runner_flagged_device_generic (FuPlugin *self, FwupdInstallFlags flags, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 833 | FuDevice *device, |
| 834 | const gchar *symbol_name, GError **error) |
| 835 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 836 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 837 | FuPluginFlaggedDeviceFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 838 | g_autoptr(GError) error_local = NULL; |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 839 | |
| 840 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 841 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 842 | return TRUE; |
| 843 | |
| 844 | /* no object loaded */ |
| 845 | if (priv->module == NULL) |
| 846 | return TRUE; |
| 847 | |
| 848 | /* optional */ |
| 849 | g_module_symbol (priv->module, symbol_name, (gpointer *) &func); |
| 850 | if (func == NULL) |
| 851 | return TRUE; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 852 | g_debug ("%s(%s)", symbol_name + 10, fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 853 | if (!func (self, flags, device, &error_local)) { |
| 854 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 855 | g_critical ("unset plugin error in %s(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 856 | fu_plugin_get_name (self), symbol_name + 10); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 857 | g_set_error_literal (&error_local, |
| 858 | FWUPD_ERROR, |
| 859 | FWUPD_ERROR_INTERNAL, |
| 860 | "unspecified error"); |
| 861 | } |
| 862 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 863 | "failed to %s using %s: ", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 864 | symbol_name + 10, fu_plugin_get_name (self)); |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 865 | return FALSE; |
| 866 | } |
| 867 | return TRUE; |
| 868 | |
| 869 | } |
| 870 | |
| 871 | static gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 872 | fu_plugin_runner_device_array_generic (FuPlugin *self, GPtrArray *devices, |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 873 | const gchar *symbol_name, GError **error) |
| 874 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 875 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 876 | FuPluginDeviceArrayFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 877 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 878 | |
| 879 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 880 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 881 | return TRUE; |
| 882 | |
| 883 | /* no object loaded */ |
| 884 | if (priv->module == NULL) |
| 885 | return TRUE; |
| 886 | |
| 887 | /* optional */ |
| 888 | g_module_symbol (priv->module, symbol_name, (gpointer *) &func); |
| 889 | if (func == NULL) |
| 890 | return TRUE; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 891 | g_debug ("%s(%s)", symbol_name + 10, fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 892 | if (!func (self, devices, &error_local)) { |
| 893 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 894 | g_critical ("unset plugin error in for %s(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 895 | fu_plugin_get_name (self), symbol_name + 10); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 896 | g_set_error_literal (&error_local, |
| 897 | FWUPD_ERROR, |
| 898 | FWUPD_ERROR_INTERNAL, |
| 899 | "unspecified error"); |
| 900 | } |
| 901 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 902 | "failed to %s using %s: ", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 903 | symbol_name + 10, fu_plugin_get_name (self)); |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 904 | return FALSE; |
| 905 | } |
| 906 | return TRUE; |
| 907 | } |
| 908 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 909 | /** |
| 910 | * fu_plugin_runner_coldplug: |
| 911 | * @self: a #FuPlugin |
| 912 | * @error: a #GError or NULL |
| 913 | * |
| 914 | * Runs the coldplug routine for the plugin |
| 915 | * |
| 916 | * Returns: #TRUE for success, #FALSE for failure |
| 917 | * |
| 918 | * Since: 0.8.0 |
| 919 | **/ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 920 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 921 | fu_plugin_runner_coldplug (FuPlugin *self, GError **error) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 922 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 923 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 924 | FuPluginStartupFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 925 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 926 | |
| 927 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 928 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 929 | return TRUE; |
| 930 | |
Daniel Campello | 0b9b7ec | 2021-04-08 16:32:25 -0600 | [diff] [blame] | 931 | /* no HwId */ |
| 932 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_REQUIRE_HWID)) |
| 933 | return TRUE; |
| 934 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 935 | /* no object loaded */ |
| 936 | if (priv->module == NULL) |
| 937 | return TRUE; |
| 938 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 939 | /* optional */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 940 | g_module_symbol (priv->module, "fu_plugin_coldplug", (gpointer *) &func); |
| 941 | if (func == NULL) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 942 | return TRUE; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 943 | g_debug ("coldplug(%s)", fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 944 | if (!func (self, &error_local)) { |
| 945 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 946 | g_critical ("unset plugin error in coldplug(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 947 | fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 948 | g_set_error_literal (&error_local, |
| 949 | FWUPD_ERROR, |
| 950 | FWUPD_ERROR_INTERNAL, |
| 951 | "unspecified error"); |
| 952 | } |
| 953 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 954 | "failed to coldplug using %s: ", fu_plugin_get_name (self)); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 955 | return FALSE; |
| 956 | } |
| 957 | return TRUE; |
| 958 | } |
| 959 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 960 | /** |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 961 | * fu_plugin_runner_coldplug_prepare: |
| 962 | * @self: a #FuPlugin |
| 963 | * @error: a #GError or NULL |
| 964 | * |
| 965 | * Runs the coldplug_prepare routine for the plugin |
| 966 | * |
| 967 | * Returns: #TRUE for success, #FALSE for failure |
| 968 | * |
| 969 | * Since: 0.8.0 |
| 970 | **/ |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 971 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 972 | fu_plugin_runner_coldplug_prepare (FuPlugin *self, GError **error) |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 973 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 974 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 975 | FuPluginStartupFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 976 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 977 | |
| 978 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 979 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 980 | return TRUE; |
| 981 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 982 | /* no object loaded */ |
| 983 | if (priv->module == NULL) |
| 984 | return TRUE; |
| 985 | |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 986 | /* optional */ |
| 987 | g_module_symbol (priv->module, "fu_plugin_coldplug_prepare", (gpointer *) &func); |
| 988 | if (func == NULL) |
| 989 | return TRUE; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 990 | g_debug ("coldplug_prepare(%s)", fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 991 | if (!func (self, &error_local)) { |
| 992 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 993 | g_critical ("unset plugin error in coldplug_prepare(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 994 | fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 995 | g_set_error_literal (&error_local, |
| 996 | FWUPD_ERROR, |
| 997 | FWUPD_ERROR_INTERNAL, |
| 998 | "unspecified error"); |
| 999 | } |
| 1000 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1001 | "failed to coldplug_prepare using %s: ", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1002 | fu_plugin_get_name (self)); |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1003 | return FALSE; |
| 1004 | } |
| 1005 | return TRUE; |
| 1006 | } |
| 1007 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1008 | /** |
| 1009 | * fu_plugin_runner_coldplug_cleanup: |
| 1010 | * @self: a #FuPlugin |
| 1011 | * @error: a #GError or NULL |
| 1012 | * |
| 1013 | * Runs the coldplug_cleanup routine for the plugin |
| 1014 | * |
| 1015 | * Returns: #TRUE for success, #FALSE for failure |
| 1016 | * |
| 1017 | * Since: 0.8.0 |
| 1018 | **/ |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1019 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1020 | fu_plugin_runner_coldplug_cleanup (FuPlugin *self, GError **error) |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1021 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1022 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1023 | FuPluginStartupFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1024 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1025 | |
| 1026 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1027 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1028 | return TRUE; |
| 1029 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1030 | /* no object loaded */ |
| 1031 | if (priv->module == NULL) |
| 1032 | return TRUE; |
| 1033 | |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1034 | /* optional */ |
| 1035 | g_module_symbol (priv->module, "fu_plugin_coldplug_cleanup", (gpointer *) &func); |
| 1036 | if (func == NULL) |
| 1037 | return TRUE; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1038 | g_debug ("coldplug_cleanup(%s)", fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1039 | if (!func (self, &error_local)) { |
| 1040 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 1041 | g_critical ("unset plugin error in coldplug_cleanup(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1042 | fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1043 | g_set_error_literal (&error_local, |
| 1044 | FWUPD_ERROR, |
| 1045 | FWUPD_ERROR_INTERNAL, |
| 1046 | "unspecified error"); |
| 1047 | } |
| 1048 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1049 | "failed to coldplug_cleanup using %s: ", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1050 | fu_plugin_get_name (self)); |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1051 | return FALSE; |
| 1052 | } |
| 1053 | return TRUE; |
| 1054 | } |
| 1055 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1056 | /** |
| 1057 | * fu_plugin_runner_composite_prepare: |
| 1058 | * @self: a #FuPlugin |
Richard Hughes | a0d81c7 | 2019-11-27 11:41:54 +0000 | [diff] [blame] | 1059 | * @devices: (element-type FuDevice): a #GPtrArray of devices |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1060 | * @error: a #GError or NULL |
| 1061 | * |
| 1062 | * Runs the composite_prepare routine for the plugin |
| 1063 | * |
| 1064 | * Returns: #TRUE for success, #FALSE for failure |
| 1065 | * |
| 1066 | * Since: 1.0.9 |
| 1067 | **/ |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1068 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1069 | fu_plugin_runner_composite_prepare (FuPlugin *self, GPtrArray *devices, GError **error) |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1070 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1071 | return fu_plugin_runner_device_array_generic (self, devices, |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1072 | "fu_plugin_composite_prepare", |
| 1073 | error); |
| 1074 | } |
| 1075 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1076 | /** |
| 1077 | * fu_plugin_runner_composite_cleanup: |
| 1078 | * @self: a #FuPlugin |
Richard Hughes | a0d81c7 | 2019-11-27 11:41:54 +0000 | [diff] [blame] | 1079 | * @devices: (element-type FuDevice): a #GPtrArray of devices |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1080 | * @error: a #GError or NULL |
| 1081 | * |
| 1082 | * Runs the composite_cleanup routine for the plugin |
| 1083 | * |
| 1084 | * Returns: #TRUE for success, #FALSE for failure |
| 1085 | * |
| 1086 | * Since: 1.0.9 |
| 1087 | **/ |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1088 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1089 | fu_plugin_runner_composite_cleanup (FuPlugin *self, GPtrArray *devices, GError **error) |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1090 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1091 | return fu_plugin_runner_device_array_generic (self, devices, |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1092 | "fu_plugin_composite_cleanup", |
| 1093 | error); |
| 1094 | } |
| 1095 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1096 | /** |
| 1097 | * fu_plugin_runner_update_prepare: |
| 1098 | * @self: a #FuPlugin |
Richard Hughes | 2bbb7d2 | 2020-11-30 09:18:45 +0000 | [diff] [blame] | 1099 | * @flags: #FwupdInstallFlags |
| 1100 | * @device: a #FuDevice |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1101 | * @error: a #GError or NULL |
| 1102 | * |
| 1103 | * Runs the update_prepare routine for the plugin |
| 1104 | * |
| 1105 | * Returns: #TRUE for success, #FALSE for failure |
| 1106 | * |
| 1107 | * Since: 1.1.2 |
| 1108 | **/ |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1109 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1110 | fu_plugin_runner_update_prepare (FuPlugin *self, FwupdInstallFlags flags, FuDevice *device, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1111 | GError **error) |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1112 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1113 | return fu_plugin_runner_flagged_device_generic (self, flags, device, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1114 | "fu_plugin_update_prepare", |
| 1115 | error); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1118 | /** |
| 1119 | * fu_plugin_runner_update_cleanup: |
| 1120 | * @self: a #FuPlugin |
Richard Hughes | 2bbb7d2 | 2020-11-30 09:18:45 +0000 | [diff] [blame] | 1121 | * @flags: #FwupdInstallFlags |
| 1122 | * @device: a #FuDevice |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1123 | * @error: a #GError or NULL |
| 1124 | * |
| 1125 | * Runs the update_cleanup routine for the plugin |
| 1126 | * |
| 1127 | * Returns: #TRUE for success, #FALSE for failure |
| 1128 | * |
| 1129 | * Since: 1.1.2 |
| 1130 | **/ |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1131 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1132 | fu_plugin_runner_update_cleanup (FuPlugin *self, FwupdInstallFlags flags, FuDevice *device, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1133 | GError **error) |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1134 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1135 | return fu_plugin_runner_flagged_device_generic (self, flags, device, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1136 | "fu_plugin_update_cleanup", |
| 1137 | error); |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1138 | } |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1139 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1140 | /** |
| 1141 | * fu_plugin_runner_update_attach: |
| 1142 | * @self: a #FuPlugin |
| 1143 | * @device: a #FuDevice |
| 1144 | * @error: a #GError or NULL |
| 1145 | * |
| 1146 | * Runs the update_attach routine for the plugin |
| 1147 | * |
| 1148 | * Returns: #TRUE for success, #FALSE for failure |
| 1149 | * |
| 1150 | * Since: 1.1.2 |
| 1151 | **/ |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1152 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1153 | fu_plugin_runner_update_attach (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1154 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1155 | return fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1156 | "fu_plugin_update_attach", |
| 1157 | fu_plugin_device_attach, |
| 1158 | error); |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1159 | } |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1160 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1161 | /** |
| 1162 | * fu_plugin_runner_update_detach: |
| 1163 | * @self: a #FuPlugin |
| 1164 | * @device: A #FuDevice |
| 1165 | * @error: a #GError or NULL |
| 1166 | * |
| 1167 | * Runs the update_detach routine for the plugin |
| 1168 | * |
| 1169 | * Returns: #TRUE for success, #FALSE for failure |
| 1170 | * |
| 1171 | * Since: 1.1.2 |
| 1172 | **/ |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1173 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1174 | fu_plugin_runner_update_detach (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1175 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1176 | return fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1177 | "fu_plugin_update_detach", |
| 1178 | fu_plugin_device_detach, |
| 1179 | error); |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1182 | /** |
| 1183 | * fu_plugin_runner_update_reload: |
| 1184 | * @self: a #FuPlugin |
Richard Hughes | 2bbb7d2 | 2020-11-30 09:18:45 +0000 | [diff] [blame] | 1185 | * @device: A #FuDevice |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1186 | * @error: a #GError or NULL |
| 1187 | * |
| 1188 | * Runs reload routine for a device |
| 1189 | * |
| 1190 | * Returns: #TRUE for success, #FALSE for failure |
| 1191 | * |
| 1192 | * Since: 1.1.2 |
| 1193 | **/ |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1194 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1195 | fu_plugin_runner_update_reload (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1196 | { |
Richard Hughes | 42f33df | 2019-10-05 20:52:33 +0100 | [diff] [blame] | 1197 | g_autoptr(FuDeviceLocker) locker = NULL; |
| 1198 | |
| 1199 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1200 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | 42f33df | 2019-10-05 20:52:33 +0100 | [diff] [blame] | 1201 | return TRUE; |
| 1202 | |
| 1203 | /* no object loaded */ |
| 1204 | locker = fu_device_locker_new (device, error); |
| 1205 | if (locker == NULL) |
| 1206 | return FALSE; |
| 1207 | return fu_device_reload (device, error); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1208 | } |
| 1209 | |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1210 | /** |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 1211 | * fu_plugin_runner_add_security_attrs: |
| 1212 | * @self: a #FuPlugin |
Richard Hughes | 3ecd22c | 2020-05-19 20:13:47 +0100 | [diff] [blame] | 1213 | * @attrs: a #FuSecurityAttrs |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 1214 | * |
Richard Hughes | 3ecd22c | 2020-05-19 20:13:47 +0100 | [diff] [blame] | 1215 | * Runs the `add_security_attrs()` routine for the plugin |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 1216 | * |
| 1217 | * Since: 1.5.0 |
| 1218 | **/ |
Richard Hughes | f58ac73 | 2020-05-12 15:23:44 +0100 | [diff] [blame] | 1219 | void |
| 1220 | fu_plugin_runner_add_security_attrs (FuPlugin *self, FuSecurityAttrs *attrs) |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 1221 | { |
Richard Hughes | f58ac73 | 2020-05-12 15:23:44 +0100 | [diff] [blame] | 1222 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 1223 | FuPluginSecurityAttrsFunc func = NULL; |
| 1224 | const gchar *symbol_name = "fu_plugin_add_security_attrs"; |
| 1225 | |
| 1226 | /* no object loaded */ |
| 1227 | if (priv->module == NULL) |
| 1228 | return; |
| 1229 | |
| 1230 | /* optional, but gets called even for disabled plugins */ |
| 1231 | g_module_symbol (priv->module, symbol_name, (gpointer *) &func); |
| 1232 | if (func == NULL) |
| 1233 | return; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1234 | g_debug ("%s(%s)", symbol_name + 10, fu_plugin_get_name (self)); |
Richard Hughes | f58ac73 | 2020-05-12 15:23:44 +0100 | [diff] [blame] | 1235 | func (self, attrs); |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | /** |
Richard Hughes | faa35e4 | 2021-04-15 09:38:03 +0100 | [diff] [blame] | 1239 | * fu_plugin_add_device_gtype: |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1240 | * @self: a #FuPlugin |
| 1241 | * @device_gtype: a #GType `FU_TYPE_DEVICE` |
| 1242 | * |
Richard Hughes | faa35e4 | 2021-04-15 09:38:03 +0100 | [diff] [blame] | 1243 | * Adds the device #GType which is used when creating devices. |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1244 | * |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1245 | * If this method is used then fu_plugin_backend_device_added() is not called, and |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1246 | * instead the object is created in the daemon for the plugin. |
| 1247 | * |
| 1248 | * Plugins can use this method only in fu_plugin_init() |
| 1249 | * |
Richard Hughes | faa35e4 | 2021-04-15 09:38:03 +0100 | [diff] [blame] | 1250 | * Since: 1.6.0 |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1251 | **/ |
| 1252 | void |
Richard Hughes | faa35e4 | 2021-04-15 09:38:03 +0100 | [diff] [blame] | 1253 | fu_plugin_add_device_gtype (FuPlugin *self, GType device_gtype) |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1254 | { |
| 1255 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | faa35e4 | 2021-04-15 09:38:03 +0100 | [diff] [blame] | 1256 | |
| 1257 | /* create as required */ |
| 1258 | if (priv->device_gtypes == NULL) |
| 1259 | priv->device_gtypes = g_array_new (FALSE, FALSE, sizeof(GType)); |
| 1260 | |
| 1261 | /* ensure (to allow quirks to use it) then add */ |
| 1262 | g_type_ensure (device_gtype); |
| 1263 | g_array_append_val (priv->device_gtypes, device_gtype); |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1264 | } |
| 1265 | |
Richard Hughes | 9f71fe3 | 2021-01-03 20:35:36 +0000 | [diff] [blame] | 1266 | static gchar * |
| 1267 | fu_common_string_uncamelcase (const gchar *str) |
| 1268 | { |
| 1269 | GString *tmp = g_string_new (NULL); |
| 1270 | for (guint i = 0; str[i] != '\0'; i++) { |
| 1271 | if (g_ascii_islower (str[i]) || |
| 1272 | g_ascii_isdigit (str[i])) { |
| 1273 | g_string_append_c (tmp, str[i]); |
| 1274 | continue; |
| 1275 | } |
| 1276 | if (i > 0) |
| 1277 | g_string_append_c (tmp, '-'); |
| 1278 | g_string_append_c (tmp, g_ascii_tolower (str[i])); |
| 1279 | } |
| 1280 | return g_string_free (tmp, FALSE); |
| 1281 | } |
| 1282 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1283 | /** |
| 1284 | * fu_plugin_add_firmware_gtype: |
| 1285 | * @self: a #FuPlugin |
Richard Hughes | 9f71fe3 | 2021-01-03 20:35:36 +0000 | [diff] [blame] | 1286 | * @id: (nullable): An optional string describing the type, e.g. "ihex" |
| 1287 | * @gtype: a #GType e.g. `FU_TYPE_FOO_FIRMWARE` |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1288 | * |
Richard Hughes | 9f71fe3 | 2021-01-03 20:35:36 +0000 | [diff] [blame] | 1289 | * Adds a firmware #GType which is used when creating devices. If @id is not |
| 1290 | * specified then it is guessed using the #GType name. |
| 1291 | * |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1292 | * Plugins can use this method only in fu_plugin_init() |
| 1293 | * |
| 1294 | * Since: 1.3.3 |
| 1295 | **/ |
Richard Hughes | 95c98a9 | 2019-10-22 16:03:15 +0100 | [diff] [blame] | 1296 | void |
| 1297 | fu_plugin_add_firmware_gtype (FuPlugin *self, const gchar *id, GType gtype) |
| 1298 | { |
Richard Hughes | b333e00 | 2021-04-01 10:40:02 +0100 | [diff] [blame] | 1299 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 9f71fe3 | 2021-01-03 20:35:36 +0000 | [diff] [blame] | 1300 | g_autofree gchar *id_safe = NULL; |
| 1301 | if (id != NULL) { |
| 1302 | id_safe = g_strdup (id); |
| 1303 | } else { |
Richard Hughes | ebb10a5 | 2021-01-05 13:34:39 +0000 | [diff] [blame] | 1304 | g_autoptr(GString) str = g_string_new (g_type_name (gtype)); |
Richard Hughes | 9f71fe3 | 2021-01-03 20:35:36 +0000 | [diff] [blame] | 1305 | if (g_str_has_prefix (str->str, "Fu")) |
| 1306 | g_string_erase (str, 0, 2); |
| 1307 | fu_common_string_replace (str, "Firmware", ""); |
| 1308 | id_safe = fu_common_string_uncamelcase (str->str); |
| 1309 | } |
Richard Hughes | b333e00 | 2021-04-01 10:40:02 +0100 | [diff] [blame] | 1310 | fu_context_add_firmware_gtype (priv->ctx, id_safe, gtype); |
Richard Hughes | 95c98a9 | 2019-10-22 16:03:15 +0100 | [diff] [blame] | 1311 | } |
| 1312 | |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1313 | static gboolean |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1314 | fu_plugin_check_supported_device (FuPlugin *self, FuDevice *device) |
| 1315 | { |
| 1316 | GPtrArray *instance_ids = fu_device_get_instance_ids (device); |
| 1317 | for (guint i = 0; i < instance_ids->len; i++) { |
| 1318 | const gchar *instance_id = g_ptr_array_index (instance_ids, i); |
| 1319 | g_autofree gchar *guid = fwupd_guid_hash_string (instance_id); |
| 1320 | if (fu_plugin_check_supported (self, guid)) |
| 1321 | return TRUE; |
| 1322 | } |
| 1323 | return FALSE; |
| 1324 | } |
| 1325 | |
| 1326 | static gboolean |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1327 | fu_plugin_backend_device_added (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1328 | { |
| 1329 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1330 | GType device_gtype = fu_device_get_specialized_gtype (FU_DEVICE (device)); |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1331 | g_autoptr(FuDevice) dev = NULL; |
| 1332 | g_autoptr(FuDeviceLocker) locker = NULL; |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1333 | |
| 1334 | /* fall back to plugin default */ |
Richard Hughes | faa35e4 | 2021-04-15 09:38:03 +0100 | [diff] [blame] | 1335 | if (device_gtype == G_TYPE_INVALID) { |
| 1336 | if (priv->device_gtypes->len > 1) { |
| 1337 | g_set_error_literal (error, |
| 1338 | FWUPD_ERROR, |
| 1339 | FWUPD_ERROR_INTERNAL, |
| 1340 | "too many GTypes to choose a default"); |
| 1341 | return FALSE; |
| 1342 | } |
| 1343 | device_gtype = g_array_index (priv->device_gtypes, GType, 0); |
| 1344 | } |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1345 | |
| 1346 | /* create new device and incorporate existing properties */ |
| 1347 | dev = g_object_new (device_gtype, NULL); |
| 1348 | fu_device_incorporate (dev, FU_DEVICE (device)); |
Richard Hughes | 0f66a02 | 2020-02-19 18:54:38 +0000 | [diff] [blame] | 1349 | if (!fu_plugin_runner_device_created (self, dev, error)) |
| 1350 | return FALSE; |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1351 | |
| 1352 | /* there are a lot of different devices that match, but not all respond |
| 1353 | * well to opening -- so limit some ones with issued updates */ |
Richard Hughes | cf10029 | 2021-01-04 10:36:37 +0000 | [diff] [blame] | 1354 | if (fu_device_has_internal_flag (dev, FU_DEVICE_INTERNAL_FLAG_ONLY_SUPPORTED)) { |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1355 | if (!fu_device_probe (dev, error)) |
| 1356 | return FALSE; |
| 1357 | fu_device_convert_instance_ids (dev); |
| 1358 | if (!fu_plugin_check_supported_device (self, dev)) { |
| 1359 | g_autofree gchar *guids = fu_device_get_guids_as_str (dev); |
| 1360 | g_debug ("%s has no updates, so ignoring device", guids); |
| 1361 | return TRUE; |
| 1362 | } |
| 1363 | } |
| 1364 | |
| 1365 | /* open and add */ |
| 1366 | locker = fu_device_locker_new (dev, error); |
| 1367 | if (locker == NULL) |
| 1368 | return FALSE; |
| 1369 | fu_plugin_device_add (self, dev); |
Richard Hughes | 6a07870 | 2020-05-09 20:36:33 +0100 | [diff] [blame] | 1370 | fu_plugin_runner_device_added (self, dev); |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1371 | return TRUE; |
| 1372 | } |
| 1373 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1374 | /** |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1375 | * fu_plugin_runner_backend_device_added: |
| 1376 | * @self: a #FuPlugin |
| 1377 | * @device: a #FuDevice |
| 1378 | * @error: a #GError or NULL |
| 1379 | * |
| 1380 | * Call the backend_device_added routine for the plugin |
| 1381 | * |
| 1382 | * Returns: #TRUE for success, #FALSE for failure |
| 1383 | * |
| 1384 | * Since: 1.5.6 |
| 1385 | **/ |
| 1386 | gboolean |
| 1387 | fu_plugin_runner_backend_device_added (FuPlugin *self, FuDevice *device, GError **error) |
| 1388 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1389 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1390 | FuPluginDeviceFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1391 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1392 | |
Richard Hughes | 6a489a9 | 2020-12-22 10:32:06 +0000 | [diff] [blame] | 1393 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1394 | g_return_val_if_fail (FU_IS_DEVICE (device), FALSE); |
Richard Hughes | 6a489a9 | 2020-12-22 10:32:06 +0000 | [diff] [blame] | 1395 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 1396 | |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1397 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1398 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1399 | return TRUE; |
| 1400 | |
| 1401 | /* no object loaded */ |
| 1402 | if (priv->module == NULL) |
| 1403 | return TRUE; |
| 1404 | |
| 1405 | /* optional */ |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1406 | g_module_symbol (priv->module, "fu_plugin_backend_device_added", (gpointer *) &func); |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1407 | if (func == NULL) { |
Richard Hughes | faa35e4 | 2021-04-15 09:38:03 +0100 | [diff] [blame] | 1408 | if (priv->device_gtypes != NULL || |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1409 | fu_device_get_specialized_gtype (device) != G_TYPE_INVALID) { |
| 1410 | return fu_plugin_backend_device_added (self, device, error); |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1411 | } |
Richard Hughes | a21e025 | 2020-12-01 12:21:33 +0000 | [diff] [blame] | 1412 | g_set_error_literal (error, |
| 1413 | FWUPD_ERROR, |
| 1414 | FWUPD_ERROR_INTERNAL, |
| 1415 | "No device GType set"); |
| 1416 | return FALSE; |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1417 | } |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1418 | g_debug ("backend_device_added(%s)", fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1419 | if (!func (self, device, &error_local)) { |
| 1420 | if (error_local == NULL) { |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1421 | g_critical ("unset plugin error in backend_device_added(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1422 | fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1423 | g_set_error_literal (&error_local, |
| 1424 | FWUPD_ERROR, |
| 1425 | FWUPD_ERROR_INTERNAL, |
| 1426 | "unspecified error"); |
| 1427 | } |
| 1428 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1429 | "failed to add device using on %s: ", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1430 | fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1431 | return FALSE; |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1432 | } |
| 1433 | return TRUE; |
| 1434 | } |
| 1435 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1436 | /** |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1437 | * fu_plugin_runner_backend_device_changed: |
| 1438 | * @self: a #FuPlugin |
| 1439 | * @device: a #FuDevice |
| 1440 | * @error: a #GError or NULL |
| 1441 | * |
| 1442 | * Call the backend_device_changed routine for the plugin |
| 1443 | * |
| 1444 | * Returns: #TRUE for success, #FALSE for failure |
| 1445 | * |
| 1446 | * Since: 1.5.6 |
| 1447 | **/ |
| 1448 | gboolean |
| 1449 | fu_plugin_runner_backend_device_changed (FuPlugin *self, FuDevice *device, GError **error) |
| 1450 | { |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 1451 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1452 | FuPluginDeviceFunc func = NULL; |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 1453 | g_autoptr(GError) error_local = NULL; |
| 1454 | |
Richard Hughes | 6a489a9 | 2020-12-22 10:32:06 +0000 | [diff] [blame] | 1455 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1456 | g_return_val_if_fail (FU_IS_DEVICE (device), FALSE); |
Richard Hughes | 6a489a9 | 2020-12-22 10:32:06 +0000 | [diff] [blame] | 1457 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 1458 | |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 1459 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1460 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 1461 | return TRUE; |
| 1462 | |
| 1463 | /* no object loaded */ |
| 1464 | if (priv->module == NULL) |
| 1465 | return TRUE; |
| 1466 | |
| 1467 | /* optional */ |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1468 | g_module_symbol (priv->module, "fu_plugin_backend_device_changed", (gpointer *) &func); |
Mario Limonciello | 6d23514 | 2020-09-10 21:35:17 -0500 | [diff] [blame] | 1469 | if (func == NULL) |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 1470 | return TRUE; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1471 | g_debug ("udev_device_changed(%s)", fu_plugin_get_name (self)); |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 1472 | if (!func (self, device, &error_local)) { |
| 1473 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 1474 | g_critical ("unset plugin error in udev_device_changed(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1475 | fu_plugin_get_name (self)); |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 1476 | g_set_error_literal (&error_local, |
| 1477 | FWUPD_ERROR, |
| 1478 | FWUPD_ERROR_INTERNAL, |
| 1479 | "unspecified error"); |
| 1480 | } |
| 1481 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1482 | "failed to change device on %s: ", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1483 | fu_plugin_get_name (self)); |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 1484 | return FALSE; |
| 1485 | } |
| 1486 | return TRUE; |
| 1487 | } |
| 1488 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1489 | /** |
Richard Hughes | 6a07870 | 2020-05-09 20:36:33 +0100 | [diff] [blame] | 1490 | * fu_plugin_runner_device_added: |
| 1491 | * @self: a #FuPlugin |
| 1492 | * @device: a #FuDevice |
| 1493 | * |
| 1494 | * Call the device_added routine for the plugin |
| 1495 | * |
| 1496 | * Since: 1.5.0 |
| 1497 | **/ |
| 1498 | void |
| 1499 | fu_plugin_runner_device_added (FuPlugin *self, FuDevice *device) |
| 1500 | { |
| 1501 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 1502 | FuPluginDeviceRegisterFunc func = NULL; |
| 1503 | |
| 1504 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1505 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | 6a07870 | 2020-05-09 20:36:33 +0100 | [diff] [blame] | 1506 | return; |
| 1507 | if (priv->module == NULL) |
| 1508 | return; |
| 1509 | |
| 1510 | /* optional */ |
| 1511 | g_module_symbol (priv->module, "fu_plugin_device_added", (gpointer *) &func); |
| 1512 | if (func == NULL) |
| 1513 | return; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1514 | g_debug ("fu_plugin_device_added(%s)", fu_plugin_get_name (self)); |
Richard Hughes | 6a07870 | 2020-05-09 20:36:33 +0100 | [diff] [blame] | 1515 | func (self, device); |
| 1516 | } |
| 1517 | |
| 1518 | /** |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1519 | * fu_plugin_runner_device_removed: |
| 1520 | * @self: a #FuPlugin |
| 1521 | * @device: a #FuDevice |
| 1522 | * |
| 1523 | * Call the device_removed routine for the plugin |
| 1524 | * |
| 1525 | * Since: 1.1.2 |
| 1526 | **/ |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 1527 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1528 | fu_plugin_runner_device_removed (FuPlugin *self, FuDevice *device) |
Mario Limonciello | e260ead | 2018-09-01 09:19:24 -0500 | [diff] [blame] | 1529 | { |
| 1530 | g_autoptr(GError) error_local= NULL; |
| 1531 | |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1532 | if (!fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 525f71f | 2021-02-09 14:52:47 +0000 | [diff] [blame] | 1533 | "fu_plugin_backend_device_removed", |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1534 | NULL, |
Mario Limonciello | e260ead | 2018-09-01 09:19:24 -0500 | [diff] [blame] | 1535 | &error_local)) |
| 1536 | g_warning ("%s", error_local->message); |
| 1537 | } |
| 1538 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1539 | /** |
| 1540 | * fu_plugin_runner_device_register: |
| 1541 | * @self: a #FuPlugin |
| 1542 | * @device: a #FuDevice |
| 1543 | * |
| 1544 | * Call the device_registered routine for the plugin |
| 1545 | * |
| 1546 | * Since: 0.9.7 |
| 1547 | **/ |
Mario Limonciello | e260ead | 2018-09-01 09:19:24 -0500 | [diff] [blame] | 1548 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1549 | fu_plugin_runner_device_register (FuPlugin *self, FuDevice *device) |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 1550 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1551 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 1552 | FuPluginDeviceRegisterFunc func = NULL; |
| 1553 | |
| 1554 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1555 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 1556 | return; |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 1557 | if (priv->module == NULL) |
| 1558 | return; |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 1559 | |
| 1560 | /* optional */ |
| 1561 | g_module_symbol (priv->module, "fu_plugin_device_registered", (gpointer *) &func); |
| 1562 | if (func != NULL) { |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1563 | g_debug ("fu_plugin_device_registered(%s)", fu_plugin_get_name (self)); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1564 | func (self, device); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 1565 | } |
| 1566 | } |
| 1567 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1568 | /** |
Richard Hughes | 0f66a02 | 2020-02-19 18:54:38 +0000 | [diff] [blame] | 1569 | * fu_plugin_runner_device_created: |
| 1570 | * @self: a #FuPlugin |
| 1571 | * @device: a #FuDevice |
| 1572 | * @error: a #GError or NULL |
| 1573 | * |
| 1574 | * Call the device_created routine for the plugin |
| 1575 | * |
| 1576 | * Returns: #TRUE for success, #FALSE for failure |
| 1577 | * |
Mario Limonciello | 96117d1 | 2020-02-28 10:17:56 -0600 | [diff] [blame] | 1578 | * Since: 1.4.0 |
Richard Hughes | 0f66a02 | 2020-02-19 18:54:38 +0000 | [diff] [blame] | 1579 | **/ |
| 1580 | gboolean |
| 1581 | fu_plugin_runner_device_created (FuPlugin *self, FuDevice *device, GError **error) |
| 1582 | { |
| 1583 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 1584 | FuPluginDeviceFunc func = NULL; |
| 1585 | |
Richard Hughes | 6a489a9 | 2020-12-22 10:32:06 +0000 | [diff] [blame] | 1586 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
| 1587 | g_return_val_if_fail (FU_IS_DEVICE (device), FALSE); |
| 1588 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 1589 | |
Richard Hughes | 0f66a02 | 2020-02-19 18:54:38 +0000 | [diff] [blame] | 1590 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1591 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | 0f66a02 | 2020-02-19 18:54:38 +0000 | [diff] [blame] | 1592 | return TRUE; |
| 1593 | if (priv->module == NULL) |
| 1594 | return TRUE; |
| 1595 | |
| 1596 | /* optional */ |
| 1597 | g_module_symbol (priv->module, "fu_plugin_device_created", (gpointer *) &func); |
| 1598 | if (func == NULL) |
| 1599 | return TRUE; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1600 | g_debug ("fu_plugin_device_created(%s)", fu_plugin_get_name (self)); |
Richard Hughes | 0f66a02 | 2020-02-19 18:54:38 +0000 | [diff] [blame] | 1601 | return func (self, device, error); |
| 1602 | } |
| 1603 | |
| 1604 | /** |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1605 | * fu_plugin_runner_verify: |
| 1606 | * @self: a #FuPlugin |
| 1607 | * @device: a #FuDevice |
| 1608 | * @flags: #FuPluginVerifyFlags |
| 1609 | * @error: A #GError or NULL |
| 1610 | * |
| 1611 | * Call into the plugin's verify routine |
| 1612 | * |
| 1613 | * Returns: #TRUE for success, #FALSE for failure |
| 1614 | * |
| 1615 | * Since: 0.8.0 |
| 1616 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1617 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1618 | fu_plugin_runner_verify (FuPlugin *self, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1619 | FuDevice *device, |
| 1620 | FuPluginVerifyFlags flags, |
| 1621 | GError **error) |
| 1622 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1623 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1624 | FuPluginVerifyFunc func = NULL; |
Richard Hughes | ababbb7 | 2017-06-15 20:18:36 +0100 | [diff] [blame] | 1625 | GPtrArray *checksums; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1626 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1627 | |
Richard Hughes | 6a489a9 | 2020-12-22 10:32:06 +0000 | [diff] [blame] | 1628 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
| 1629 | g_return_val_if_fail (FU_IS_DEVICE (device), FALSE); |
| 1630 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 1631 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1632 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1633 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1634 | return TRUE; |
| 1635 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1636 | /* no object loaded */ |
| 1637 | if (priv->module == NULL) |
| 1638 | return TRUE; |
| 1639 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1640 | /* optional */ |
| 1641 | g_module_symbol (priv->module, "fu_plugin_verify", (gpointer *) &func); |
Richard Hughes | 7f67721 | 2019-10-05 16:19:40 +0100 | [diff] [blame] | 1642 | if (func == NULL) { |
Richard Hughes | 53de7e2 | 2021-02-23 14:28:28 +0000 | [diff] [blame] | 1643 | if (!fu_device_has_flag (device, FWUPD_DEVICE_FLAG_CAN_VERIFY)) { |
| 1644 | g_set_error (error, |
| 1645 | FWUPD_ERROR, |
| 1646 | FWUPD_ERROR_NOT_SUPPORTED, |
| 1647 | "device %s does not support verification", |
| 1648 | fu_device_get_id (device)); |
| 1649 | return FALSE; |
| 1650 | } |
Richard Hughes | 7f67721 | 2019-10-05 16:19:40 +0100 | [diff] [blame] | 1651 | return fu_plugin_device_read_firmware (self, device, error); |
| 1652 | } |
Richard Hughes | 1812fc7 | 2018-12-14 11:37:54 +0000 | [diff] [blame] | 1653 | |
| 1654 | /* clear any existing verification checksums */ |
| 1655 | checksums = fu_device_get_checksums (device); |
| 1656 | g_ptr_array_set_size (checksums, 0); |
| 1657 | |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 1658 | /* run additional detach */ |
| 1659 | if (!fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 42f33df | 2019-10-05 20:52:33 +0100 | [diff] [blame] | 1660 | "fu_plugin_update_detach", |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1661 | fu_plugin_device_detach, |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 1662 | error)) |
| 1663 | return FALSE; |
| 1664 | |
Richard Hughes | 1812fc7 | 2018-12-14 11:37:54 +0000 | [diff] [blame] | 1665 | /* run vfunc */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1666 | g_debug ("verify(%s)", fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1667 | if (!func (self, device, flags, &error_local)) { |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 1668 | g_autoptr(GError) error_attach = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1669 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 1670 | g_critical ("unset plugin error in verify(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1671 | fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1672 | g_set_error_literal (&error_local, |
| 1673 | FWUPD_ERROR, |
| 1674 | FWUPD_ERROR_INTERNAL, |
| 1675 | "unspecified error"); |
| 1676 | } |
| 1677 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1678 | "failed to verify using %s: ", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1679 | fu_plugin_get_name (self)); |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 1680 | /* make the device "work" again, but don't prefix the error */ |
| 1681 | if (!fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 42f33df | 2019-10-05 20:52:33 +0100 | [diff] [blame] | 1682 | "fu_plugin_update_attach", |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1683 | fu_plugin_device_attach, |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 1684 | &error_attach)) { |
| 1685 | g_warning ("failed to attach whilst aborting verify(): %s", |
| 1686 | error_attach->message); |
| 1687 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1688 | return FALSE; |
| 1689 | } |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 1690 | |
| 1691 | /* run optional attach */ |
| 1692 | if (!fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 42f33df | 2019-10-05 20:52:33 +0100 | [diff] [blame] | 1693 | "fu_plugin_update_attach", |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1694 | fu_plugin_device_attach, |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 1695 | error)) |
| 1696 | return FALSE; |
| 1697 | |
| 1698 | /* success */ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1699 | return TRUE; |
| 1700 | } |
| 1701 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1702 | /** |
| 1703 | * fu_plugin_runner_activate: |
| 1704 | * @self: a #FuPlugin |
| 1705 | * @device: a #FuDevice |
| 1706 | * @error: A #GError or NULL |
| 1707 | * |
| 1708 | * Call into the plugin's activate routine |
| 1709 | * |
| 1710 | * Returns: #TRUE for success, #FALSE for failure |
| 1711 | * |
| 1712 | * Since: 1.2.6 |
| 1713 | **/ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1714 | gboolean |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 1715 | fu_plugin_runner_activate (FuPlugin *self, FuDevice *device, GError **error) |
| 1716 | { |
| 1717 | guint64 flags; |
| 1718 | |
Richard Hughes | 6a489a9 | 2020-12-22 10:32:06 +0000 | [diff] [blame] | 1719 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
| 1720 | g_return_val_if_fail (FU_IS_DEVICE (device), FALSE); |
| 1721 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 1722 | |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 1723 | /* final check */ |
| 1724 | flags = fu_device_get_flags (device); |
| 1725 | if ((flags & FWUPD_DEVICE_FLAG_NEEDS_ACTIVATION) == 0) { |
| 1726 | g_set_error (error, |
| 1727 | FWUPD_ERROR, |
| 1728 | FWUPD_ERROR_NOT_SUPPORTED, |
| 1729 | "Device %s does not need activation", |
| 1730 | fu_device_get_id (device)); |
| 1731 | return FALSE; |
| 1732 | } |
| 1733 | |
| 1734 | /* run vfunc */ |
| 1735 | if (!fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1736 | "fu_plugin_activate", |
| 1737 | fu_plugin_device_activate, |
| 1738 | error)) |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 1739 | return FALSE; |
| 1740 | |
| 1741 | /* update with correct flags */ |
| 1742 | fu_device_remove_flag (device, FWUPD_DEVICE_FLAG_NEEDS_ACTIVATION); |
| 1743 | fu_device_set_modified (device, (guint64) g_get_real_time () / G_USEC_PER_SEC); |
| 1744 | return TRUE; |
| 1745 | } |
| 1746 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1747 | /** |
| 1748 | * fu_plugin_runner_unlock: |
| 1749 | * @self: a #FuPlugin |
| 1750 | * @device: a #FuDevice |
| 1751 | * @error: A #GError or NULL |
| 1752 | * |
| 1753 | * Call into the plugin's unlock routine |
| 1754 | * |
| 1755 | * Returns: #TRUE for success, #FALSE for failure |
| 1756 | * |
| 1757 | * Since: 0.8.0 |
| 1758 | **/ |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 1759 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1760 | fu_plugin_runner_unlock (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1761 | { |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1762 | guint64 flags; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1763 | |
Richard Hughes | 6a489a9 | 2020-12-22 10:32:06 +0000 | [diff] [blame] | 1764 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
| 1765 | g_return_val_if_fail (FU_IS_DEVICE (device), FALSE); |
| 1766 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 1767 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1768 | /* final check */ |
| 1769 | flags = fu_device_get_flags (device); |
| 1770 | if ((flags & FWUPD_DEVICE_FLAG_LOCKED) == 0) { |
| 1771 | g_set_error (error, |
| 1772 | FWUPD_ERROR, |
| 1773 | FWUPD_ERROR_NOT_SUPPORTED, |
| 1774 | "Device %s is not locked", |
| 1775 | fu_device_get_id (device)); |
| 1776 | return FALSE; |
| 1777 | } |
| 1778 | |
Richard Hughes | 9c4b531 | 2017-11-14 11:34:53 +0000 | [diff] [blame] | 1779 | /* run vfunc */ |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1780 | if (!fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1781 | "fu_plugin_unlock", |
| 1782 | NULL, |
| 1783 | error)) |
Richard Hughes | 9c4b531 | 2017-11-14 11:34:53 +0000 | [diff] [blame] | 1784 | return FALSE; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1785 | |
| 1786 | /* update with correct flags */ |
Richard Hughes | ed0af24 | 2021-02-22 21:27:16 +0000 | [diff] [blame] | 1787 | fu_device_remove_flag (device, FWUPD_DEVICE_FLAG_LOCKED); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1788 | fu_device_set_modified (device, (guint64) g_get_real_time () / G_USEC_PER_SEC); |
| 1789 | return TRUE; |
| 1790 | } |
| 1791 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1792 | /** |
| 1793 | * fu_plugin_runner_update: |
| 1794 | * @self: a #FuPlugin |
| 1795 | * @device: a #FuDevice |
| 1796 | * @blob_fw: A #GBytes |
| 1797 | * @flags: A #FwupdInstallFlags |
| 1798 | * @error: A #GError or NULL |
| 1799 | * |
| 1800 | * Call into the plugin's update routine |
| 1801 | * |
| 1802 | * Returns: #TRUE for success, #FALSE for failure |
| 1803 | * |
| 1804 | * Since: 0.8.0 |
| 1805 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1806 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1807 | fu_plugin_runner_update (FuPlugin *self, |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 1808 | FuDevice *device, |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 1809 | GBytes *blob_fw, |
| 1810 | FwupdInstallFlags flags, |
| 1811 | GError **error) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1812 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1813 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 1814 | FuPluginUpdateFunc update_func; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1815 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1816 | |
Richard Hughes | 6a489a9 | 2020-12-22 10:32:06 +0000 | [diff] [blame] | 1817 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
| 1818 | g_return_val_if_fail (FU_IS_DEVICE (device), FALSE); |
| 1819 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 1820 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1821 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1822 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) { |
Richard Hughes | 41c1548 | 2018-02-01 22:07:21 +0000 | [diff] [blame] | 1823 | g_debug ("plugin not enabled, skipping"); |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1824 | return TRUE; |
Richard Hughes | 41c1548 | 2018-02-01 22:07:21 +0000 | [diff] [blame] | 1825 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1826 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1827 | /* no object loaded */ |
Richard Hughes | 41c1548 | 2018-02-01 22:07:21 +0000 | [diff] [blame] | 1828 | if (priv->module == NULL) { |
| 1829 | g_debug ("module not enabled, skipping"); |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1830 | return TRUE; |
Richard Hughes | 41c1548 | 2018-02-01 22:07:21 +0000 | [diff] [blame] | 1831 | } |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1832 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1833 | /* optional */ |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 1834 | g_module_symbol (priv->module, "fu_plugin_update", (gpointer *) &update_func); |
| 1835 | if (update_func == NULL) { |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1836 | g_debug ("superclassed write_firmware(%s)", fu_plugin_get_name (self)); |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1837 | return fu_plugin_device_write_firmware (self, device, blob_fw, flags, error); |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 1838 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1839 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1840 | /* online */ |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1841 | if (!update_func (self, device, blob_fw, flags, &error_local)) { |
| 1842 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 1843 | g_critical ("unset plugin error in update(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1844 | fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1845 | g_set_error_literal (&error_local, |
Richard Hughes | 3c8ada3 | 2018-10-12 10:08:58 +0100 | [diff] [blame] | 1846 | FWUPD_ERROR, |
| 1847 | FWUPD_ERROR_INTERNAL, |
| 1848 | "unspecified error"); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1849 | return FALSE; |
Richard Hughes | 3c8ada3 | 2018-10-12 10:08:58 +0100 | [diff] [blame] | 1850 | } |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1851 | fu_device_set_update_error (device, error_local->message); |
| 1852 | g_propagate_error (error, g_steal_pointer (&error_local)); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1853 | return FALSE; |
| 1854 | } |
| 1855 | |
Richard Hughes | f556d37 | 2017-06-15 19:49:18 +0100 | [diff] [blame] | 1856 | /* no longer valid */ |
Richard Hughes | f803964 | 2019-01-16 12:22:22 +0000 | [diff] [blame] | 1857 | if (!fu_device_has_flag (device, FWUPD_DEVICE_FLAG_NEEDS_REBOOT) && |
| 1858 | !fu_device_has_flag (device, FWUPD_DEVICE_FLAG_NEEDS_SHUTDOWN)) { |
Richard Hughes | 0843516 | 2018-12-12 10:34:16 +0000 | [diff] [blame] | 1859 | GPtrArray *checksums = fu_device_get_checksums (device); |
| 1860 | g_ptr_array_set_size (checksums, 0); |
| 1861 | } |
Richard Hughes | f556d37 | 2017-06-15 19:49:18 +0100 | [diff] [blame] | 1862 | |
Richard Hughes | 019a1bc | 2019-11-26 10:19:33 +0000 | [diff] [blame] | 1863 | /* success */ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1864 | return TRUE; |
| 1865 | } |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1866 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1867 | /** |
| 1868 | * fu_plugin_runner_clear_results: |
| 1869 | * @self: a #FuPlugin |
| 1870 | * @device: a #FuDevice |
| 1871 | * @error: A #GError or NULL |
| 1872 | * |
| 1873 | * Call into the plugin's clear results routine |
| 1874 | * |
| 1875 | * Returns: #TRUE for success, #FALSE for failure |
| 1876 | * |
| 1877 | * Since: 0.8.0 |
| 1878 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1879 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1880 | fu_plugin_runner_clear_results (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1881 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1882 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1883 | FuPluginDeviceFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1884 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1885 | |
Richard Hughes | 6a489a9 | 2020-12-22 10:32:06 +0000 | [diff] [blame] | 1886 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
| 1887 | g_return_val_if_fail (FU_IS_DEVICE (device), FALSE); |
| 1888 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 1889 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1890 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1891 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1892 | return TRUE; |
| 1893 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1894 | /* no object loaded */ |
| 1895 | if (priv->module == NULL) |
| 1896 | return TRUE; |
| 1897 | |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 1898 | /* optional */ |
Richard Hughes | cd64490 | 2019-11-01 12:35:17 +0000 | [diff] [blame] | 1899 | g_module_symbol (priv->module, "fu_plugin_clear_results", (gpointer *) &func); |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 1900 | if (func == NULL) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1901 | return TRUE; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1902 | g_debug ("clear_result(%s)", fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1903 | if (!func (self, device, &error_local)) { |
| 1904 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 1905 | g_critical ("unset plugin error in clear_result(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1906 | fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1907 | g_set_error_literal (&error_local, |
| 1908 | FWUPD_ERROR, |
| 1909 | FWUPD_ERROR_INTERNAL, |
| 1910 | "unspecified error"); |
| 1911 | } |
| 1912 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1913 | "failed to clear_result using %s: ", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1914 | fu_plugin_get_name (self)); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1915 | return FALSE; |
| 1916 | } |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 1917 | return TRUE; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1918 | } |
| 1919 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1920 | /** |
| 1921 | * fu_plugin_runner_get_results: |
| 1922 | * @self: a #FuPlugin |
| 1923 | * @device: a #FuDevice |
| 1924 | * @error: A #GError or NULL |
| 1925 | * |
| 1926 | * Call into the plugin's get results routine |
| 1927 | * |
| 1928 | * Returns: #TRUE for success, #FALSE for failure |
| 1929 | * |
| 1930 | * Since: 0.8.0 |
| 1931 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1932 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1933 | fu_plugin_runner_get_results (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1934 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1935 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1936 | FuPluginDeviceFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1937 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1938 | |
Richard Hughes | 6a489a9 | 2020-12-22 10:32:06 +0000 | [diff] [blame] | 1939 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
| 1940 | g_return_val_if_fail (FU_IS_DEVICE (device), FALSE); |
| 1941 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 1942 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1943 | /* not enabled */ |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1944 | if (fu_plugin_has_flag (self, FWUPD_PLUGIN_FLAG_DISABLED)) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1945 | return TRUE; |
| 1946 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1947 | /* no object loaded */ |
| 1948 | if (priv->module == NULL) |
| 1949 | return TRUE; |
| 1950 | |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 1951 | /* optional */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1952 | g_module_symbol (priv->module, "fu_plugin_get_results", (gpointer *) &func); |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 1953 | if (func == NULL) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1954 | return TRUE; |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1955 | g_debug ("get_results(%s)", fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1956 | if (!func (self, device, &error_local)) { |
| 1957 | if (error_local == NULL) { |
Mario Limonciello | 67a8b89 | 2020-09-28 13:44:39 -0500 | [diff] [blame] | 1958 | g_critical ("unset plugin error in get_results(%s)", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1959 | fu_plugin_get_name (self)); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1960 | g_set_error_literal (&error_local, |
| 1961 | FWUPD_ERROR, |
| 1962 | FWUPD_ERROR_INTERNAL, |
| 1963 | "unspecified error"); |
| 1964 | } |
| 1965 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1966 | "failed to get_results using %s: ", |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 1967 | fu_plugin_get_name (self)); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1968 | return FALSE; |
| 1969 | } |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1970 | return TRUE; |
| 1971 | } |
| 1972 | |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1973 | /** |
| 1974 | * fu_plugin_get_order: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 1975 | * @self: a #FuPlugin |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1976 | * |
| 1977 | * Gets the plugin order, where higher numbers are run after lower |
| 1978 | * numbers. |
| 1979 | * |
| 1980 | * Returns: the integer value |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1981 | * |
| 1982 | * Since: 1.0.0 |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1983 | **/ |
| 1984 | guint |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1985 | fu_plugin_get_order (FuPlugin *self) |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1986 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1987 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1988 | return priv->order; |
| 1989 | } |
| 1990 | |
| 1991 | /** |
| 1992 | * fu_plugin_set_order: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 1993 | * @self: a #FuPlugin |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 1994 | * @order: a integer value |
| 1995 | * |
| 1996 | * Sets the plugin order, where higher numbers are run after lower |
| 1997 | * numbers. |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1998 | * |
| 1999 | * Since: 1.0.0 |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2000 | **/ |
| 2001 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2002 | fu_plugin_set_order (FuPlugin *self, guint order) |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2003 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2004 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2005 | priv->order = order; |
| 2006 | } |
| 2007 | |
| 2008 | /** |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2009 | * fu_plugin_get_priority: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2010 | * @self: a #FuPlugin |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2011 | * |
| 2012 | * Gets the plugin priority, where higher numbers are better. |
| 2013 | * |
| 2014 | * Returns: the integer value |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2015 | * |
| 2016 | * Since: 1.1.1 |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2017 | **/ |
| 2018 | guint |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2019 | fu_plugin_get_priority (FuPlugin *self) |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2020 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2021 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2022 | return priv->priority; |
| 2023 | } |
| 2024 | |
| 2025 | /** |
| 2026 | * fu_plugin_set_priority: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2027 | * @self: a #FuPlugin |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2028 | * @priority: a integer value |
| 2029 | * |
| 2030 | * Sets the plugin priority, where higher numbers are better. |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2031 | * |
| 2032 | * Since: 1.0.0 |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2033 | **/ |
| 2034 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2035 | fu_plugin_set_priority (FuPlugin *self, guint priority) |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2036 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2037 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2038 | priv->priority = priority; |
| 2039 | } |
| 2040 | |
| 2041 | /** |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2042 | * fu_plugin_add_rule: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2043 | * @self: a #FuPlugin |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2044 | * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 2045 | * @name: a plugin name, e.g. `upower` |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2046 | * |
| 2047 | * If the plugin name is found, the rule will be used to sort the plugin list, |
| 2048 | * for example the plugin specified by @name will be ordered after this plugin |
| 2049 | * when %FU_PLUGIN_RULE_RUN_AFTER is used. |
| 2050 | * |
| 2051 | * NOTE: The depsolver is iterative and may not solve overly-complicated rules; |
| 2052 | * If depsolving fails then fwupd will not start. |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2053 | * |
| 2054 | * Since: 1.0.0 |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2055 | **/ |
| 2056 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2057 | fu_plugin_add_rule (FuPlugin *self, FuPluginRule rule, const gchar *name) |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2058 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2059 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 11c5941 | 2020-06-22 15:29:48 +0100 | [diff] [blame] | 2060 | if (priv->rules[rule] == NULL) |
| 2061 | priv->rules[rule] = g_ptr_array_new_with_free_func (g_free); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2062 | g_ptr_array_add (priv->rules[rule], g_strdup (name)); |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 2063 | g_signal_emit (self, signals[SIGNAL_RULES_CHANGED], 0); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | /** |
| 2067 | * fu_plugin_get_rules: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2068 | * @self: a #FuPlugin |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2069 | * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS |
| 2070 | * |
| 2071 | * Gets the plugin IDs that should be run after this plugin. |
| 2072 | * |
Richard Hughes | 11c5941 | 2020-06-22 15:29:48 +0100 | [diff] [blame] | 2073 | * Returns: (element-type utf8) (transfer none) (nullable): the list of plugin names, e.g. ['appstream'] |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2074 | * |
| 2075 | * Since: 1.0.0 |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2076 | **/ |
| 2077 | GPtrArray * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2078 | fu_plugin_get_rules (FuPlugin *self, FuPluginRule rule) |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2079 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2080 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | dad3597 | 2019-12-06 11:00:25 +0000 | [diff] [blame] | 2081 | g_return_val_if_fail (rule < FU_PLUGIN_RULE_LAST, NULL); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2082 | return priv->rules[rule]; |
| 2083 | } |
| 2084 | |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2085 | /** |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 2086 | * fu_plugin_has_rule: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2087 | * @self: a #FuPlugin |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 2088 | * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS |
| 2089 | * @name: a plugin name, e.g. `upower` |
| 2090 | * |
Richard Hughes | 87fb9ff | 2018-06-28 12:55:59 +0100 | [diff] [blame] | 2091 | * Gets the plugin IDs that should be run after this plugin. |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 2092 | * |
| 2093 | * Returns: %TRUE if the name exists for the specific rule |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2094 | * |
| 2095 | * Since: 1.0.0 |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 2096 | **/ |
| 2097 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2098 | fu_plugin_has_rule (FuPlugin *self, FuPluginRule rule, const gchar *name) |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 2099 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2100 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 11c5941 | 2020-06-22 15:29:48 +0100 | [diff] [blame] | 2101 | if (priv->rules[rule] == NULL) |
| 2102 | return FALSE; |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 2103 | for (guint i = 0; i < priv->rules[rule]->len; i++) { |
| 2104 | const gchar *tmp = g_ptr_array_index (priv->rules[rule], i); |
| 2105 | if (g_strcmp0 (tmp, name) == 0) |
| 2106 | return TRUE; |
| 2107 | } |
| 2108 | return FALSE; |
| 2109 | } |
| 2110 | |
| 2111 | /** |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2112 | * fu_plugin_add_report_metadata: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2113 | * @self: a #FuPlugin |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2114 | * @key: a string, e.g. `FwupdateVersion` |
| 2115 | * @value: a string, e.g. `10` |
| 2116 | * |
| 2117 | * Sets any additional metadata to be included in the firmware report to aid |
| 2118 | * debugging problems. |
| 2119 | * |
| 2120 | * Any data included here will be sent to the metadata server after user |
| 2121 | * confirmation. |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2122 | * |
| 2123 | * Since: 1.0.4 |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2124 | **/ |
| 2125 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2126 | 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] | 2127 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2128 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 1d900f7 | 2020-06-22 15:17:39 +0100 | [diff] [blame] | 2129 | if (priv->report_metadata == NULL) { |
| 2130 | priv->report_metadata = g_hash_table_new_full (g_str_hash, |
| 2131 | g_str_equal, |
| 2132 | g_free, |
| 2133 | g_free); |
| 2134 | } |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2135 | g_hash_table_insert (priv->report_metadata, g_strdup (key), g_strdup (value)); |
| 2136 | } |
| 2137 | |
| 2138 | /** |
| 2139 | * fu_plugin_get_report_metadata: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2140 | * @self: a #FuPlugin |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2141 | * |
| 2142 | * Returns the list of additional metadata to be added when filing a report. |
| 2143 | * |
Richard Hughes | 1d900f7 | 2020-06-22 15:17:39 +0100 | [diff] [blame] | 2144 | * Returns: (transfer none) (nullable): the map of report metadata |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2145 | * |
| 2146 | * Since: 1.0.4 |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2147 | **/ |
| 2148 | GHashTable * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2149 | fu_plugin_get_report_metadata (FuPlugin *self) |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2150 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2151 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2152 | return priv->report_metadata; |
| 2153 | } |
| 2154 | |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 2155 | /** |
| 2156 | * fu_plugin_get_config_value: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2157 | * @self: a #FuPlugin |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 2158 | * @key: A settings key |
| 2159 | * |
| 2160 | * Return the value of a key if it's been configured |
| 2161 | * |
| 2162 | * Since: 1.0.6 |
| 2163 | **/ |
| 2164 | gchar * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2165 | fu_plugin_get_config_value (FuPlugin *self, const gchar *key) |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 2166 | { |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 2167 | g_autofree gchar *conf_dir = NULL; |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 2168 | g_autofree gchar *conf_file = NULL; |
| 2169 | g_autofree gchar *conf_path = NULL; |
| 2170 | g_autoptr(GKeyFile) keyfile = NULL; |
| 2171 | const gchar *plugin_name; |
| 2172 | |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 2173 | conf_dir = fu_common_get_path (FU_PATH_KIND_SYSCONFDIR_PKG); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2174 | plugin_name = fu_plugin_get_name (self); |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 2175 | conf_file = g_strdup_printf ("%s.conf", plugin_name); |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 2176 | conf_path = g_build_filename (conf_dir, conf_file, NULL); |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 2177 | if (!g_file_test (conf_path, G_FILE_TEST_IS_REGULAR)) |
| 2178 | return NULL; |
| 2179 | keyfile = g_key_file_new (); |
| 2180 | if (!g_key_file_load_from_file (keyfile, conf_path, |
| 2181 | G_KEY_FILE_NONE, NULL)) |
| 2182 | return NULL; |
| 2183 | return g_key_file_get_string (keyfile, plugin_name, key, NULL); |
| 2184 | } |
| 2185 | |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 2186 | /** |
Richard Hughes | 334ba79 | 2020-02-19 20:44:56 +0000 | [diff] [blame] | 2187 | * fu_plugin_get_config_value_boolean: |
| 2188 | * @self: a #FuPlugin |
| 2189 | * @key: A settings key |
| 2190 | * |
| 2191 | * Return the boolean value of a key if it's been configured |
| 2192 | * |
| 2193 | * Returns: %TRUE if the value is `true` (case insensitive), %FALSE otherwise |
| 2194 | * |
Mario Limonciello | 96117d1 | 2020-02-28 10:17:56 -0600 | [diff] [blame] | 2195 | * Since: 1.4.0 |
Richard Hughes | 334ba79 | 2020-02-19 20:44:56 +0000 | [diff] [blame] | 2196 | **/ |
| 2197 | gboolean |
| 2198 | fu_plugin_get_config_value_boolean (FuPlugin *self, const gchar *key) |
| 2199 | { |
| 2200 | g_autofree gchar *tmp = fu_plugin_get_config_value (self, key); |
| 2201 | if (tmp == NULL) |
| 2202 | return FALSE; |
Richard Hughes | 5337a43 | 2020-02-21 12:04:32 +0000 | [diff] [blame] | 2203 | return g_ascii_strcasecmp (tmp, "true") == 0; |
Richard Hughes | 334ba79 | 2020-02-19 20:44:56 +0000 | [diff] [blame] | 2204 | } |
| 2205 | |
| 2206 | /** |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 2207 | * fu_plugin_name_compare: |
| 2208 | * @plugin1: first #FuPlugin to compare. |
| 2209 | * @plugin2: second #FuPlugin to compare. |
| 2210 | * |
| 2211 | * Compares two plugins by their names. |
| 2212 | * |
| 2213 | * Returns: 1, 0 or -1 if @plugin1 is greater, equal, or less than @plugin2. |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2214 | * |
| 2215 | * Since: 1.0.8 |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 2216 | **/ |
| 2217 | gint |
| 2218 | fu_plugin_name_compare (FuPlugin *plugin1, FuPlugin *plugin2) |
| 2219 | { |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2220 | return g_strcmp0 (fu_plugin_get_name (plugin1), fu_plugin_get_name (plugin2)); |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 2221 | } |
| 2222 | |
| 2223 | /** |
| 2224 | * fu_plugin_order_compare: |
| 2225 | * @plugin1: first #FuPlugin to compare. |
| 2226 | * @plugin2: second #FuPlugin to compare. |
| 2227 | * |
| 2228 | * Compares two plugins by their depsolved order. |
| 2229 | * |
| 2230 | * Returns: 1, 0 or -1 if @plugin1 is greater, equal, or less than @plugin2. |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2231 | * |
| 2232 | * Since: 1.0.8 |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 2233 | **/ |
| 2234 | gint |
| 2235 | fu_plugin_order_compare (FuPlugin *plugin1, FuPlugin *plugin2) |
| 2236 | { |
| 2237 | FuPluginPrivate *priv1 = fu_plugin_get_instance_private (plugin1); |
| 2238 | FuPluginPrivate *priv2 = fu_plugin_get_instance_private (plugin2); |
| 2239 | if (priv1->order < priv2->order) |
| 2240 | return -1; |
| 2241 | if (priv1->order > priv2->order) |
| 2242 | return 1; |
| 2243 | return 0; |
| 2244 | } |
| 2245 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2246 | static void |
| 2247 | fu_plugin_class_init (FuPluginClass *klass) |
| 2248 | { |
| 2249 | GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 2250 | object_class->finalize = fu_plugin_finalize; |
| 2251 | signals[SIGNAL_DEVICE_ADDED] = |
| 2252 | g_signal_new ("device-added", |
| 2253 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2254 | G_STRUCT_OFFSET (FuPluginClass, device_added), |
| 2255 | NULL, NULL, g_cclosure_marshal_VOID__OBJECT, |
| 2256 | G_TYPE_NONE, 1, FU_TYPE_DEVICE); |
| 2257 | signals[SIGNAL_DEVICE_REMOVED] = |
| 2258 | g_signal_new ("device-removed", |
| 2259 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2260 | G_STRUCT_OFFSET (FuPluginClass, device_removed), |
| 2261 | NULL, NULL, g_cclosure_marshal_VOID__OBJECT, |
| 2262 | G_TYPE_NONE, 1, FU_TYPE_DEVICE); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 2263 | signals[SIGNAL_DEVICE_REGISTER] = |
| 2264 | g_signal_new ("device-register", |
| 2265 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2266 | G_STRUCT_OFFSET (FuPluginClass, device_register), |
| 2267 | NULL, NULL, g_cclosure_marshal_VOID__OBJECT, |
| 2268 | G_TYPE_NONE, 1, FU_TYPE_DEVICE); |
Richard Hughes | aabdc37 | 2018-11-14 10:11:08 +0000 | [diff] [blame] | 2269 | signals[SIGNAL_CHECK_SUPPORTED] = |
| 2270 | g_signal_new ("check-supported", |
| 2271 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2272 | G_STRUCT_OFFSET (FuPluginClass, check_supported), |
| 2273 | NULL, NULL, g_cclosure_marshal_generic, |
| 2274 | G_TYPE_BOOLEAN, 1, G_TYPE_STRING); |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 2275 | signals[SIGNAL_RULES_CHANGED] = |
| 2276 | g_signal_new ("rules-changed", |
| 2277 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2278 | G_STRUCT_OFFSET (FuPluginClass, rules_changed), |
| 2279 | NULL, NULL, g_cclosure_marshal_VOID__VOID, |
| 2280 | G_TYPE_NONE, 0); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2281 | } |
| 2282 | |
| 2283 | static void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2284 | fu_plugin_init (FuPlugin *self) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2285 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2286 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 2287 | g_rw_lock_init (&priv->cache_mutex); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2288 | } |
| 2289 | |
| 2290 | static void |
| 2291 | fu_plugin_finalize (GObject *object) |
| 2292 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2293 | FuPlugin *self = FU_PLUGIN (object); |
| 2294 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2295 | FuPluginInitFunc func = NULL; |
| 2296 | |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 2297 | g_rw_lock_clear (&priv->cache_mutex); |
Richard Hughes | aae22e4 | 2020-06-22 21:32:59 +0100 | [diff] [blame] | 2298 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2299 | /* optional */ |
| 2300 | if (priv->module != NULL) { |
| 2301 | g_module_symbol (priv->module, "fu_plugin_destroy", (gpointer *) &func); |
| 2302 | if (func != NULL) { |
Richard Hughes | 7bcb8d4 | 2020-10-08 15:47:47 +0100 | [diff] [blame] | 2303 | g_debug ("destroy(%s)", fu_plugin_get_name (self)); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2304 | func (self); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2305 | } |
| 2306 | } |
| 2307 | |
Richard Hughes | 11c5941 | 2020-06-22 15:29:48 +0100 | [diff] [blame] | 2308 | for (guint i = 0; i < FU_PLUGIN_RULE_LAST; i++) { |
| 2309 | if (priv->rules[i] != NULL) |
| 2310 | g_ptr_array_unref (priv->rules[i]); |
| 2311 | } |
Richard Hughes | 68ab1e4 | 2021-01-13 14:01:17 +0000 | [diff] [blame] | 2312 | if (priv->devices != NULL) |
| 2313 | g_ptr_array_unref (priv->devices); |
Richard Hughes | b333e00 | 2021-04-01 10:40:02 +0100 | [diff] [blame] | 2314 | if (priv->ctx != NULL) |
| 2315 | g_object_unref (priv->ctx); |
Richard Hughes | 275d3b4 | 2018-04-20 16:40:37 +0100 | [diff] [blame] | 2316 | if (priv->runtime_versions != NULL) |
| 2317 | g_hash_table_unref (priv->runtime_versions); |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 2318 | if (priv->compile_versions != NULL) |
| 2319 | g_hash_table_unref (priv->compile_versions); |
Richard Hughes | 1d900f7 | 2020-06-22 15:17:39 +0100 | [diff] [blame] | 2320 | if (priv->report_metadata != NULL) |
| 2321 | g_hash_table_unref (priv->report_metadata); |
Richard Hughes | faf2afe | 2021-01-13 14:00:20 +0000 | [diff] [blame] | 2322 | if (priv->cache != NULL) |
| 2323 | g_hash_table_unref (priv->cache); |
Richard Hughes | faa35e4 | 2021-04-15 09:38:03 +0100 | [diff] [blame] | 2324 | if (priv->device_gtypes != NULL) |
| 2325 | g_array_unref (priv->device_gtypes); |
Richard Hughes | 8499930 | 2019-05-02 10:18:32 +0100 | [diff] [blame] | 2326 | g_free (priv->build_hash); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2327 | g_free (priv->data); |
| 2328 | |
| 2329 | G_OBJECT_CLASS (fu_plugin_parent_class)->finalize (object); |
| 2330 | } |
| 2331 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2332 | /** |
| 2333 | * fu_plugin_new: |
| 2334 | * |
| 2335 | * Creates a new #FuPlugin |
| 2336 | * |
| 2337 | * Since: 0.8.0 |
| 2338 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2339 | FuPlugin * |
Richard Hughes | b333e00 | 2021-04-01 10:40:02 +0100 | [diff] [blame] | 2340 | fu_plugin_new (FuContext *ctx) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2341 | { |
Richard Hughes | b333e00 | 2021-04-01 10:40:02 +0100 | [diff] [blame] | 2342 | FuPlugin *self = FU_PLUGIN (g_object_new (FU_TYPE_PLUGIN, NULL)); |
| 2343 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 2344 | if (ctx != NULL) |
| 2345 | priv->ctx = g_object_ref (ctx); |
| 2346 | return self; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2347 | } |