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