Richard Hughes | 02c90d8 | 2018-08-09 12:13:03 +0100 | [diff] [blame] | 1 | /* |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 2 | * Copyright (C) 2016-2018 Richard Hughes <richard@hughsie.com> |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 3 | * |
Mario Limonciello | 51308e6 | 2018-05-28 20:05:46 -0500 | [diff] [blame] | 4 | * SPDX-License-Identifier: LGPL-2.1+ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Richard Hughes | b08e7bc | 2018-09-11 10:51:13 +0100 | [diff] [blame] | 7 | #define G_LOG_DOMAIN "FuPlugin" |
| 8 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 9 | #include "config.h" |
| 10 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 11 | #include <fwupd.h> |
| 12 | #include <gmodule.h> |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 13 | #include <errno.h> |
| 14 | #include <string.h> |
Richard Hughes | 68f12dd | 2018-08-09 14:43:31 +0100 | [diff] [blame] | 15 | #include <unistd.h> |
Mario Limonciello | 6d0aa3d | 2017-02-28 08:22:27 -0600 | [diff] [blame] | 16 | #ifdef HAVE_VALGRIND |
Richard Hughes | 576c012 | 2017-02-24 09:47:00 +0000 | [diff] [blame] | 17 | #include <valgrind.h> |
Mario Limonciello | 6d0aa3d | 2017-02-28 08:22:27 -0600 | [diff] [blame] | 18 | #endif /* HAVE_VALGRIND */ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 19 | |
Richard Hughes | 9dde04f | 2017-09-13 12:07:15 +0100 | [diff] [blame] | 20 | #include "fu-device-private.h" |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 21 | #include "fu-plugin-private.h" |
Richard Hughes | 37d0943 | 2018-09-09 10:39:45 +0100 | [diff] [blame] | 22 | #include "fu-mutex.h" |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 23 | |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 24 | /** |
| 25 | * SECTION:fu-plugin |
| 26 | * @short_description: a daemon plugin |
| 27 | * |
| 28 | * An object that represents a plugin run by the daemon. |
| 29 | * |
| 30 | * See also: #FuDevice |
| 31 | */ |
| 32 | |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 33 | #define FU_PLUGIN_COLDPLUG_DELAY_MAXIMUM 3000u /* ms */ |
| 34 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 35 | static void fu_plugin_finalize (GObject *object); |
| 36 | |
| 37 | typedef struct { |
| 38 | GModule *module; |
| 39 | GUsbContext *usb_ctx; |
| 40 | gboolean enabled; |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 41 | guint order; |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 42 | guint priority; |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 43 | GPtrArray *rules[FU_PLUGIN_RULE_LAST]; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 44 | gchar *name; |
Richard Hughes | f425d29 | 2019-01-18 17:57:39 +0000 | [diff] [blame] | 45 | gchar *build_hash; |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 46 | FuHwids *hwids; |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 47 | FuQuirks *quirks; |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 48 | GHashTable *runtime_versions; |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 49 | GHashTable *compile_versions; |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 50 | GPtrArray *udev_subsystems; |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 51 | FuSmbios *smbios; |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 52 | GType device_gtype; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 53 | GHashTable *devices; /* platform_id:GObject */ |
Richard Hughes | 161e9b5 | 2019-06-12 14:22:45 +0100 | [diff] [blame] | 54 | GRWLock devices_mutex; |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 55 | GHashTable *report_metadata; /* key:value */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 56 | FuPluginData *data; |
| 57 | } FuPluginPrivate; |
| 58 | |
| 59 | enum { |
| 60 | SIGNAL_DEVICE_ADDED, |
| 61 | SIGNAL_DEVICE_REMOVED, |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 62 | SIGNAL_DEVICE_REGISTER, |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 63 | SIGNAL_RULES_CHANGED, |
Richard Hughes | 362d6d7 | 2017-01-07 21:42:14 +0000 | [diff] [blame] | 64 | SIGNAL_RECOLDPLUG, |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 65 | SIGNAL_SET_COLDPLUG_DELAY, |
Richard Hughes | aabdc37 | 2018-11-14 10:11:08 +0000 | [diff] [blame] | 66 | SIGNAL_CHECK_SUPPORTED, |
Richard Hughes | 95c98a9 | 2019-10-22 16:03:15 +0100 | [diff] [blame] | 67 | SIGNAL_ADD_FIRMWARE_GTYPE, |
Richard Hughes | 399859e | 2020-05-11 19:44:03 +0100 | [diff] [blame] | 68 | SIGNAL_SECURITY_CHANGED, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 69 | SIGNAL_LAST |
| 70 | }; |
| 71 | |
| 72 | static guint signals[SIGNAL_LAST] = { 0 }; |
| 73 | |
| 74 | G_DEFINE_TYPE_WITH_PRIVATE (FuPlugin, fu_plugin, G_TYPE_OBJECT) |
| 75 | #define GET_PRIVATE(o) (fu_plugin_get_instance_private (o)) |
| 76 | |
| 77 | typedef const gchar *(*FuPluginGetNameFunc) (void); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 78 | typedef void (*FuPluginInitFunc) (FuPlugin *self); |
| 79 | typedef gboolean (*FuPluginStartupFunc) (FuPlugin *self, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 80 | GError **error); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 81 | typedef void (*FuPluginDeviceRegisterFunc) (FuPlugin *self, |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 82 | FuDevice *device); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 83 | typedef gboolean (*FuPluginDeviceFunc) (FuPlugin *self, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 84 | FuDevice *device, |
| 85 | GError **error); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 86 | typedef gboolean (*FuPluginFlaggedDeviceFunc) (FuPlugin *self, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 87 | FwupdInstallFlags flags, |
| 88 | FuDevice *device, |
| 89 | GError **error); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 90 | typedef gboolean (*FuPluginDeviceArrayFunc) (FuPlugin *self, |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 91 | GPtrArray *devices, |
| 92 | GError **error); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 93 | typedef gboolean (*FuPluginVerifyFunc) (FuPlugin *self, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 94 | FuDevice *device, |
| 95 | FuPluginVerifyFlags flags, |
| 96 | GError **error); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 97 | typedef gboolean (*FuPluginUpdateFunc) (FuPlugin *self, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 98 | FuDevice *device, |
| 99 | GBytes *blob_fw, |
| 100 | FwupdInstallFlags flags, |
| 101 | GError **error); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 102 | typedef gboolean (*FuPluginUsbDeviceAddedFunc) (FuPlugin *self, |
Richard Hughes | ff70441 | 2018-09-04 11:28:32 +0100 | [diff] [blame] | 103 | FuUsbDevice *device, |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 104 | GError **error); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 105 | typedef gboolean (*FuPluginUdevDeviceAddedFunc) (FuPlugin *self, |
Richard Hughes | ff70441 | 2018-09-04 11:28:32 +0100 | [diff] [blame] | 106 | FuUdevDevice *device, |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 107 | GError **error); |
Richard Hughes | f58ac73 | 2020-05-12 15:23:44 +0100 | [diff] [blame^] | 108 | typedef void (*FuPluginSecurityAttrsFunc) (FuPlugin *self, |
| 109 | FuSecurityAttrs *attrs); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 110 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 111 | /** |
Mario Limonciello | 52e75ba | 2019-11-22 13:21:19 -0600 | [diff] [blame] | 112 | * fu_plugin_is_open: |
| 113 | * @self: A #FuPlugin |
| 114 | * |
| 115 | * Determines if the plugin is opened |
| 116 | * |
| 117 | * Returns: TRUE for opened, FALSE for not |
| 118 | * |
| 119 | * Since: 1.3.5 |
| 120 | **/ |
| 121 | gboolean |
| 122 | fu_plugin_is_open (FuPlugin *self) |
| 123 | { |
| 124 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 125 | return priv->module != NULL; |
| 126 | } |
| 127 | |
| 128 | /** |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 129 | * fu_plugin_get_name: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 130 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 131 | * |
| 132 | * Gets the plugin name. |
| 133 | * |
| 134 | * Returns: a plugin name, or %NULL for unknown. |
| 135 | * |
| 136 | * Since: 0.8.0 |
| 137 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 138 | const gchar * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 139 | fu_plugin_get_name (FuPlugin *self) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 140 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 141 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 142 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 143 | return priv->name; |
| 144 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 145 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 146 | /** |
| 147 | * fu_plugin_set_name: |
| 148 | * @self: A #FuPlugin |
| 149 | * @name: A string |
| 150 | * |
| 151 | * Sets the plugin name. |
| 152 | * |
| 153 | * Since: 0.8.0 |
| 154 | **/ |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 155 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 156 | fu_plugin_set_name (FuPlugin *self, const gchar *name) |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 157 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 158 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 159 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 160 | g_return_if_fail (name != NULL); |
| 161 | g_free (priv->name); |
| 162 | priv->name = g_strdup (name); |
| 163 | } |
| 164 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 165 | /** |
Richard Hughes | f425d29 | 2019-01-18 17:57:39 +0000 | [diff] [blame] | 166 | * fu_plugin_set_build_hash: |
| 167 | * @self: A #FuPlugin |
| 168 | * @build_hash: A checksum |
| 169 | * |
| 170 | * Sets the plugin build hash, typically a SHA256 checksum. All plugins must |
| 171 | * set the correct checksum to avoid the daemon being marked as tainted. |
| 172 | * |
| 173 | * Since: 1.2.4 |
| 174 | **/ |
| 175 | void |
| 176 | fu_plugin_set_build_hash (FuPlugin *self, const gchar *build_hash) |
| 177 | { |
| 178 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 179 | g_return_if_fail (FU_IS_PLUGIN (self)); |
| 180 | g_return_if_fail (build_hash != NULL); |
| 181 | g_free (priv->build_hash); |
| 182 | priv->build_hash = g_strdup (build_hash); |
| 183 | } |
| 184 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 185 | /** |
| 186 | * fu_plugin_get_build_hash: |
| 187 | * @self: A #FuPlugin |
| 188 | * |
| 189 | * Gets the build hash a plugin was generated with. |
| 190 | * |
| 191 | * Returns: (transfer none): a #gchar, or %NULL for unset. |
| 192 | * |
| 193 | * Since: 1.2.4 |
| 194 | **/ |
Richard Hughes | f425d29 | 2019-01-18 17:57:39 +0000 | [diff] [blame] | 195 | const gchar * |
| 196 | fu_plugin_get_build_hash (FuPlugin *self) |
| 197 | { |
| 198 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 199 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
| 200 | return priv->build_hash; |
| 201 | } |
| 202 | |
| 203 | /** |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 204 | * fu_plugin_cache_lookup: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 205 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 206 | * @id: the key |
| 207 | * |
| 208 | * Finds an object in the per-plugin cache. |
| 209 | * |
| 210 | * Returns: (transfer none): a #GObject, or %NULL for unfound. |
| 211 | * |
| 212 | * Since: 0.8.0 |
| 213 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 214 | gpointer |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 215 | fu_plugin_cache_lookup (FuPlugin *self, const gchar *id) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 216 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 217 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 161e9b5 | 2019-06-12 14:22:45 +0100 | [diff] [blame] | 218 | g_autoptr(GRWLockReaderLocker) locker = g_rw_lock_reader_locker_new (&priv->devices_mutex); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 219 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 220 | g_return_val_if_fail (id != NULL, NULL); |
Richard Hughes | 37d0943 | 2018-09-09 10:39:45 +0100 | [diff] [blame] | 221 | g_return_val_if_fail (locker != NULL, NULL); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 222 | return g_hash_table_lookup (priv->devices, id); |
| 223 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 224 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 225 | /** |
| 226 | * fu_plugin_cache_add: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 227 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 228 | * @id: the key |
| 229 | * @dev: a #GObject, typically a #FuDevice |
| 230 | * |
| 231 | * Adds an object to the per-plugin cache. |
| 232 | * |
| 233 | * Since: 0.8.0 |
| 234 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 235 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 236 | fu_plugin_cache_add (FuPlugin *self, const gchar *id, gpointer dev) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 237 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 238 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 0fe4914 | 2019-11-22 16:56:38 +0000 | [diff] [blame] | 239 | g_autoptr(GRWLockWriterLocker) locker = g_rw_lock_writer_locker_new (&priv->devices_mutex); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 240 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 241 | g_return_if_fail (id != NULL); |
Richard Hughes | 37d0943 | 2018-09-09 10:39:45 +0100 | [diff] [blame] | 242 | g_return_if_fail (locker != NULL); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 243 | g_hash_table_insert (priv->devices, g_strdup (id), g_object_ref (dev)); |
| 244 | } |
| 245 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 246 | /** |
| 247 | * fu_plugin_cache_remove: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 248 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 249 | * @id: the key |
| 250 | * |
| 251 | * Removes an object from the per-plugin cache. |
| 252 | * |
| 253 | * Since: 0.8.0 |
| 254 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 255 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 256 | fu_plugin_cache_remove (FuPlugin *self, const gchar *id) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 257 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 258 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 0fe4914 | 2019-11-22 16:56:38 +0000 | [diff] [blame] | 259 | g_autoptr(GRWLockWriterLocker) locker = g_rw_lock_writer_locker_new (&priv->devices_mutex); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 260 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 261 | g_return_if_fail (id != NULL); |
Richard Hughes | 37d0943 | 2018-09-09 10:39:45 +0100 | [diff] [blame] | 262 | g_return_if_fail (locker != NULL); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 263 | g_hash_table_remove (priv->devices, id); |
| 264 | } |
| 265 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 266 | /** |
| 267 | * fu_plugin_get_data: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 268 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 269 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 270 | * Gets the per-plugin allocated private data. This will return %NULL unless |
| 271 | * fu_plugin_alloc_data() has been called by the plugin. |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 272 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 273 | * Returns: (transfer none): a pointer to a structure, or %NULL for unset. |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 274 | * |
| 275 | * Since: 0.8.0 |
| 276 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 277 | FuPluginData * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 278 | fu_plugin_get_data (FuPlugin *self) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 279 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 280 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 281 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 282 | return priv->data; |
| 283 | } |
| 284 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 285 | /** |
Richard Hughes | 00f66f6 | 2019-11-27 11:42:53 +0000 | [diff] [blame] | 286 | * fu_plugin_alloc_data: (skip): |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 287 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 288 | * @data_sz: the size to allocate |
| 289 | * |
| 290 | * Allocates the per-plugin allocated private data. |
| 291 | * |
| 292 | * Returns: (transfer full): a pointer to a structure, or %NULL for unset. |
| 293 | * |
| 294 | * Since: 0.8.0 |
| 295 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 296 | FuPluginData * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 297 | fu_plugin_alloc_data (FuPlugin *self, gsize data_sz) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 298 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 299 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 300 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
Richard Hughes | 44dee88 | 2017-01-11 08:31:10 +0000 | [diff] [blame] | 301 | if (priv->data != NULL) { |
| 302 | g_critical ("fu_plugin_alloc_data() already used by plugin"); |
| 303 | return priv->data; |
| 304 | } |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 305 | priv->data = g_malloc0 (data_sz); |
| 306 | return priv->data; |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 309 | /** |
| 310 | * fu_plugin_get_usb_context: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 311 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 312 | * |
| 313 | * Gets the shared USB context that all plugins can use. |
| 314 | * |
| 315 | * Returns: (transfer none): a #GUsbContext. |
| 316 | * |
| 317 | * Since: 0.8.0 |
| 318 | **/ |
Richard Hughes | bc93e4a | 2016-12-08 17:29:51 +0000 | [diff] [blame] | 319 | GUsbContext * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 320 | fu_plugin_get_usb_context (FuPlugin *self) |
Richard Hughes | bc93e4a | 2016-12-08 17:29:51 +0000 | [diff] [blame] | 321 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 322 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 323 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 324 | return priv->usb_ctx; |
Richard Hughes | bc93e4a | 2016-12-08 17:29:51 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 327 | /** |
| 328 | * fu_plugin_set_usb_context: |
| 329 | * @self: A #FuPlugin |
| 330 | * @usb_ctx: A #FGUsbContext |
| 331 | * |
| 332 | * Sets the shared USB context for a plugin |
| 333 | * |
| 334 | * Since: 0.8.0 |
| 335 | **/ |
Richard Hughes | bc93e4a | 2016-12-08 17:29:51 +0000 | [diff] [blame] | 336 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 337 | fu_plugin_set_usb_context (FuPlugin *self, GUsbContext *usb_ctx) |
Richard Hughes | bc93e4a | 2016-12-08 17:29:51 +0000 | [diff] [blame] | 338 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 339 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 340 | g_set_object (&priv->usb_ctx, usb_ctx); |
| 341 | } |
| 342 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 343 | /** |
| 344 | * fu_plugin_get_enabled: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 345 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 346 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 347 | * Returns if the plugin is enabled. Plugins may self-disable using |
| 348 | * fu_plugin_set_enabled() or can be disabled by the daemon. |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 349 | * |
| 350 | * Returns: %TRUE if the plugin is currently enabled. |
| 351 | * |
| 352 | * Since: 0.8.0 |
| 353 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 354 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 355 | fu_plugin_get_enabled (FuPlugin *self) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 356 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 357 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 358 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 359 | return priv->enabled; |
Richard Hughes | bc93e4a | 2016-12-08 17:29:51 +0000 | [diff] [blame] | 360 | } |
| 361 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 362 | /** |
| 363 | * fu_plugin_set_enabled: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 364 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 365 | * @enabled: the enabled value |
| 366 | * |
| 367 | * Enables or disables a plugin. Plugins can self-disable at any point. |
| 368 | * |
| 369 | * Since: 0.8.0 |
| 370 | **/ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 371 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 372 | fu_plugin_set_enabled (FuPlugin *self, gboolean enabled) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 373 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 374 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 375 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 376 | priv->enabled = enabled; |
| 377 | } |
| 378 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 379 | /** |
| 380 | * fu_plugin_guess_name_from_fn: |
| 381 | * @filename: filename to guess |
| 382 | * |
| 383 | * Tries to guess the name of the plugin from a filename |
| 384 | * |
| 385 | * Returns: (transfer full): the guessed name of the plugin |
| 386 | * |
| 387 | * Since: 1.0.8 |
| 388 | **/ |
Richard Hughes | 1e456bc | 2018-05-10 20:16:16 +0100 | [diff] [blame] | 389 | gchar * |
| 390 | fu_plugin_guess_name_from_fn (const gchar *filename) |
| 391 | { |
| 392 | const gchar *prefix = "libfu_plugin_"; |
| 393 | gchar *name; |
| 394 | gchar *str = g_strstr_len (filename, -1, prefix); |
| 395 | if (str == NULL) |
| 396 | return NULL; |
| 397 | name = g_strdup (str + strlen (prefix)); |
| 398 | g_strdelimit (name, ".", '\0'); |
| 399 | return name; |
| 400 | } |
| 401 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 402 | /** |
| 403 | * fu_plugin_open: |
| 404 | * @self: A #FuPlugin |
| 405 | * @filename: The shared object filename to open |
| 406 | * @error: A #GError or NULL |
| 407 | * |
| 408 | * Opens the plugin module |
| 409 | * |
| 410 | * Returns: TRUE for success, FALSE for fail |
| 411 | * |
| 412 | * Since: 0.8.0 |
| 413 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 414 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 415 | fu_plugin_open (FuPlugin *self, const gchar *filename, GError **error) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 416 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 417 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 418 | FuPluginInitFunc func = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 419 | |
| 420 | priv->module = g_module_open (filename, 0); |
| 421 | if (priv->module == NULL) { |
| 422 | g_set_error (error, |
| 423 | G_IO_ERROR, |
| 424 | G_IO_ERROR_FAILED, |
Mario Limonciello | f560553 | 2019-11-04 07:49:50 -0600 | [diff] [blame] | 425 | "failed to open plugin %s: %s", |
| 426 | filename, g_module_error ()); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 427 | return FALSE; |
| 428 | } |
| 429 | |
| 430 | /* set automatically */ |
Richard Hughes | 1e456bc | 2018-05-10 20:16:16 +0100 | [diff] [blame] | 431 | if (priv->name == NULL) |
| 432 | priv->name = fu_plugin_guess_name_from_fn (filename); |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 433 | |
| 434 | /* optional */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 435 | g_module_symbol (priv->module, "fu_plugin_init", (gpointer *) &func); |
| 436 | if (func != NULL) { |
| 437 | g_debug ("performing init() on %s", filename); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 438 | func (self); |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 439 | } |
| 440 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 441 | return TRUE; |
| 442 | } |
| 443 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 444 | /** |
| 445 | * fu_plugin_device_add: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 446 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 447 | * @device: A #FuDevice |
| 448 | * |
| 449 | * Asks the daemon to add a device to the exported list. If this device ID |
| 450 | * has already been added by a different plugin then this request will be |
| 451 | * ignored. |
| 452 | * |
| 453 | * Plugins should use fu_plugin_device_add_delay() if they are not capable of |
| 454 | * actually flashing an image to the hardware so that higher-priority plugins |
| 455 | * can add the device themselves. |
| 456 | * |
| 457 | * Since: 0.8.0 |
| 458 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 459 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 460 | fu_plugin_device_add (FuPlugin *self, FuDevice *device) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 461 | { |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 462 | GPtrArray *children; |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 463 | g_autoptr(GError) error = NULL; |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 464 | |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 465 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 466 | g_return_if_fail (FU_IS_DEVICE (device)); |
| 467 | |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 468 | /* ensure the device ID is set from the physical and logical IDs */ |
| 469 | if (!fu_device_ensure_id (device, &error)) { |
| 470 | g_warning ("ignoring add: %s", error->message); |
| 471 | return; |
| 472 | } |
| 473 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 474 | g_debug ("emit added from %s: %s", |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 475 | fu_plugin_get_name (self), |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 476 | fu_device_get_id (device)); |
| 477 | 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] | 478 | fu_device_set_plugin (device, fu_plugin_get_name (self)); |
| 479 | g_signal_emit (self, signals[SIGNAL_DEVICE_ADDED], 0, device); |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 480 | |
Richard Hughes | 128c016 | 2018-08-10 11:00:29 +0100 | [diff] [blame] | 481 | /* add children if they have not already been added */ |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 482 | children = fu_device_get_children (device); |
| 483 | for (guint i = 0; i < children->len; i++) { |
| 484 | FuDevice *child = g_ptr_array_index (children, i); |
Richard Hughes | 128c016 | 2018-08-10 11:00:29 +0100 | [diff] [blame] | 485 | if (fu_device_get_created (child) == 0) |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 486 | fu_plugin_device_add (self, child); |
Richard Hughes | 5e44729 | 2018-04-27 14:25:54 +0100 | [diff] [blame] | 487 | } |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 488 | } |
| 489 | |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 490 | /** |
| 491 | * fu_plugin_device_register: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 492 | * @self: A #FuPlugin |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 493 | * @device: A #FuDevice |
| 494 | * |
| 495 | * Registers the device with other plugins so they can set metadata. |
| 496 | * |
| 497 | * Plugins do not have to call this manually as this is done automatically |
| 498 | * 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] | 499 | * if for instance the coldplug should be ignored based on the metadata |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 500 | * set from other plugins. |
| 501 | * |
| 502 | * Since: 0.9.7 |
| 503 | **/ |
| 504 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 505 | fu_plugin_device_register (FuPlugin *self, FuDevice *device) |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 506 | { |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 507 | g_autoptr(GError) error = NULL; |
| 508 | |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 509 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 510 | g_return_if_fail (FU_IS_DEVICE (device)); |
| 511 | |
Richard Hughes | c125ec0 | 2018-09-05 19:35:17 +0100 | [diff] [blame] | 512 | /* ensure the device ID is set from the physical and logical IDs */ |
| 513 | if (!fu_device_ensure_id (device, &error)) { |
| 514 | g_warning ("ignoring registration: %s", error->message); |
| 515 | return; |
| 516 | } |
| 517 | |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 518 | g_debug ("emit device-register from %s: %s", |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 519 | fu_plugin_get_name (self), |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 520 | fu_device_get_id (device)); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 521 | g_signal_emit (self, signals[SIGNAL_DEVICE_REGISTER], 0, device); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 522 | } |
| 523 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 524 | /** |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 525 | * fu_plugin_device_remove: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 526 | * @self: A #FuPlugin |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 527 | * @device: A #FuDevice |
| 528 | * |
| 529 | * Asks the daemon to remove a device from the exported list. |
| 530 | * |
| 531 | * Since: 0.8.0 |
| 532 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 533 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 534 | fu_plugin_device_remove (FuPlugin *self, FuDevice *device) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 535 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 536 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | ccd78a9 | 2017-01-11 16:57:41 +0000 | [diff] [blame] | 537 | g_return_if_fail (FU_IS_DEVICE (device)); |
| 538 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 539 | g_debug ("emit removed from %s: %s", |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 540 | fu_plugin_get_name (self), |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 541 | fu_device_get_id (device)); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 542 | g_signal_emit (self, signals[SIGNAL_DEVICE_REMOVED], 0, device); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 543 | } |
| 544 | |
Richard Hughes | 57d1822 | 2017-01-10 16:02:59 +0000 | [diff] [blame] | 545 | /** |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 546 | * fu_plugin_request_recoldplug: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 547 | * @self: A #FuPlugin |
Richard Hughes | 362d6d7 | 2017-01-07 21:42:14 +0000 | [diff] [blame] | 548 | * |
| 549 | * Ask all the plugins to coldplug all devices, which will include the prepare() |
| 550 | * and cleanup() phases. Duplicate devices added will be ignored. |
| 551 | * |
| 552 | * Since: 0.8.0 |
| 553 | **/ |
| 554 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 555 | fu_plugin_request_recoldplug (FuPlugin *self) |
Richard Hughes | 362d6d7 | 2017-01-07 21:42:14 +0000 | [diff] [blame] | 556 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 557 | g_return_if_fail (FU_IS_PLUGIN (self)); |
| 558 | g_signal_emit (self, signals[SIGNAL_RECOLDPLUG], 0); |
Richard Hughes | 362d6d7 | 2017-01-07 21:42:14 +0000 | [diff] [blame] | 559 | } |
| 560 | |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 561 | /** |
Richard Hughes | 399859e | 2020-05-11 19:44:03 +0100 | [diff] [blame] | 562 | * fu_plugin_security_changed: |
| 563 | * @self: A #FuPlugin |
| 564 | * |
| 565 | * Informs the daemon that the HSI state may have changed. |
| 566 | * |
| 567 | * Since: 1.5.0 |
| 568 | **/ |
| 569 | void |
| 570 | fu_plugin_security_changed (FuPlugin *self) |
| 571 | { |
| 572 | g_return_if_fail (FU_IS_PLUGIN (self)); |
| 573 | g_signal_emit (self, signals[SIGNAL_SECURITY_CHANGED], 0); |
| 574 | } |
| 575 | |
| 576 | /** |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 577 | * fu_plugin_check_hwid: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 578 | * @self: A #FuPlugin |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 579 | * @hwid: A Hardware ID GUID, e.g. `6de5d951-d755-576b-bd09-c5cf66b27234` |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 580 | * |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 581 | * Checks to see if a specific GUID exists. All hardware IDs on a |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 582 | * specific system can be shown using the `fwupdmgr hwids` command. |
| 583 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 584 | * Returns: %TRUE if the HwId is found on the system. |
| 585 | * |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 586 | * Since: 0.9.1 |
| 587 | **/ |
| 588 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 589 | fu_plugin_check_hwid (FuPlugin *self, const gchar *hwid) |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 590 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 591 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 592 | if (priv->hwids == NULL) |
| 593 | return FALSE; |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 594 | return fu_hwids_has_guid (priv->hwids, hwid); |
| 595 | } |
| 596 | |
| 597 | /** |
Patrick Rudolph | a60b547 | 2019-10-16 10:43:03 +0200 | [diff] [blame] | 598 | * fu_plugin_get_hwid_replace_value: |
| 599 | * @self: A #FuPlugin |
| 600 | * @keys: A key, e.g. `HardwareID-3` or %FU_HWIDS_KEY_PRODUCT_SKU |
| 601 | * @error: A #GError or %NULL |
| 602 | * |
| 603 | * Gets the replacement value for a specific key. All hardware IDs on a |
| 604 | * specific system can be shown using the `fwupdmgr hwids` command. |
| 605 | * |
| 606 | * Returns: (transfer full): a string, or %NULL for error. |
| 607 | * |
| 608 | * Since: 1.3.3 |
| 609 | **/ |
| 610 | gchar * |
| 611 | fu_plugin_get_hwid_replace_value (FuPlugin *self, const gchar *keys, GError **error) |
| 612 | { |
| 613 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 614 | if (priv->hwids == NULL) |
| 615 | return NULL; |
| 616 | |
| 617 | return fu_hwids_get_replace_values (priv->hwids, keys, error); |
| 618 | } |
| 619 | |
| 620 | /** |
Richard Hughes | 69a5f35 | 2018-08-08 11:58:15 +0100 | [diff] [blame] | 621 | * fu_plugin_get_hwids: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 622 | * @self: A #FuPlugin |
Richard Hughes | 69a5f35 | 2018-08-08 11:58:15 +0100 | [diff] [blame] | 623 | * |
| 624 | * Returns all the HWIDs defined in the system. All hardware IDs on a |
| 625 | * specific system can be shown using the `fwupdmgr hwids` command. |
| 626 | * |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 627 | * Returns: (transfer none) (element-type utf8): An array of GUIDs |
Richard Hughes | 69a5f35 | 2018-08-08 11:58:15 +0100 | [diff] [blame] | 628 | * |
| 629 | * Since: 1.1.1 |
| 630 | **/ |
| 631 | GPtrArray * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 632 | fu_plugin_get_hwids (FuPlugin *self) |
Richard Hughes | 69a5f35 | 2018-08-08 11:58:15 +0100 | [diff] [blame] | 633 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 634 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 69a5f35 | 2018-08-08 11:58:15 +0100 | [diff] [blame] | 635 | if (priv->hwids == NULL) |
| 636 | return NULL; |
| 637 | return fu_hwids_get_guids (priv->hwids); |
| 638 | } |
| 639 | |
| 640 | /** |
Richard Hughes | 1984180 | 2019-09-10 16:48:00 +0100 | [diff] [blame] | 641 | * fu_plugin_has_custom_flag: |
| 642 | * @self: A #FuPlugin |
| 643 | * @flag: A custom text flag, specific to the plugin, e.g. `uefi-force-enable` |
| 644 | * |
| 645 | * Returns if a per-plugin HwId custom flag exists, typically added from a DMI quirk. |
| 646 | * |
| 647 | * Returns: %TRUE if the quirk entry exists |
| 648 | * |
| 649 | * Since: 1.3.1 |
| 650 | **/ |
| 651 | gboolean |
| 652 | fu_plugin_has_custom_flag (FuPlugin *self, const gchar *flag) |
| 653 | { |
| 654 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 655 | GPtrArray *hwids = fu_plugin_get_hwids (self); |
| 656 | |
| 657 | g_return_val_if_fail (FU_IS_PLUGIN (self), FALSE); |
| 658 | g_return_val_if_fail (flag != NULL, FALSE); |
| 659 | |
| 660 | /* never set up, e.g. in tests */ |
| 661 | if (hwids == NULL) |
| 662 | return FALSE; |
| 663 | |
| 664 | /* search each hwid */ |
| 665 | for (guint i = 0; i < hwids->len; i++) { |
| 666 | const gchar *hwid = g_ptr_array_index (hwids, i); |
| 667 | const gchar *value; |
| 668 | g_autofree gchar *key = g_strdup_printf ("HwId=%s", hwid); |
| 669 | |
| 670 | /* does prefixed quirk exist */ |
| 671 | value = fu_quirks_lookup_by_id (priv->quirks, key, FU_QUIRKS_FLAGS); |
| 672 | if (value != NULL) { |
| 673 | g_auto(GStrv) quirks = g_strsplit (value, ",", -1); |
| 674 | if (g_strv_contains ((const gchar * const *) quirks, flag)) |
| 675 | return TRUE; |
| 676 | } |
| 677 | } |
| 678 | return FALSE; |
| 679 | } |
| 680 | |
| 681 | /** |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 682 | * fu_plugin_check_supported: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 683 | * @self: A #FuPlugin |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 684 | * @guid: A Hardware ID GUID, e.g. `6de5d951-d755-576b-bd09-c5cf66b27234` |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 685 | * |
| 686 | * Checks to see if a specific device GUID is supported, i.e. available in the |
| 687 | * AppStream metadata. |
| 688 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 689 | * Returns: %TRUE if the device is supported. |
| 690 | * |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 691 | * Since: 1.0.0 |
| 692 | **/ |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 693 | static gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 694 | fu_plugin_check_supported (FuPlugin *self, const gchar *guid) |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 695 | { |
Richard Hughes | aabdc37 | 2018-11-14 10:11:08 +0000 | [diff] [blame] | 696 | gboolean retval = FALSE; |
| 697 | g_signal_emit (self, signals[SIGNAL_CHECK_SUPPORTED], 0, guid, &retval); |
| 698 | return retval; |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | /** |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 702 | * fu_plugin_get_dmi_value: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 703 | * @self: A #FuPlugin |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 704 | * @dmi_id: A DMI ID, e.g. `BiosVersion` |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 705 | * |
| 706 | * Gets a hardware DMI value. |
| 707 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 708 | * Returns: The string, or %NULL |
| 709 | * |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 710 | * Since: 0.9.7 |
| 711 | **/ |
| 712 | const gchar * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 713 | fu_plugin_get_dmi_value (FuPlugin *self, const gchar *dmi_id) |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 714 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 715 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 716 | if (priv->hwids == NULL) |
Richard Hughes | 7ef96b8 | 2017-08-23 18:28:24 +0100 | [diff] [blame] | 717 | return NULL; |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 718 | return fu_hwids_get_value (priv->hwids, dmi_id); |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 719 | } |
| 720 | |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 721 | /** |
| 722 | * fu_plugin_get_smbios_string: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 723 | * @self: A #FuPlugin |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 724 | * @structure_type: A SMBIOS structure type, e.g. %FU_SMBIOS_STRUCTURE_TYPE_BIOS |
| 725 | * @offset: A SMBIOS offset |
| 726 | * |
| 727 | * Gets a hardware SMBIOS string. |
| 728 | * |
| 729 | * The @type and @offset can be referenced from the DMTF SMBIOS specification: |
| 730 | * https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.1.1.pdf |
| 731 | * |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 732 | * Returns: A string, or %NULL |
| 733 | * |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 734 | * Since: 0.9.8 |
| 735 | **/ |
| 736 | const gchar * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 737 | fu_plugin_get_smbios_string (FuPlugin *self, guint8 structure_type, guint8 offset) |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 738 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 739 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 740 | if (priv->smbios == NULL) |
| 741 | return NULL; |
| 742 | return fu_smbios_get_string (priv->smbios, structure_type, offset, NULL); |
| 743 | } |
| 744 | |
| 745 | /** |
| 746 | * fu_plugin_get_smbios_data: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 747 | * @self: A #FuPlugin |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 748 | * @structure_type: A SMBIOS structure type, e.g. %FU_SMBIOS_STRUCTURE_TYPE_BIOS |
| 749 | * |
| 750 | * Gets a hardware SMBIOS data. |
| 751 | * |
Richard Hughes | dfaca2d | 2019-08-01 08:08:03 +0100 | [diff] [blame] | 752 | * Returns: (transfer full): A #GBytes, or %NULL |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 753 | * |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 754 | * Since: 0.9.8 |
| 755 | **/ |
| 756 | GBytes * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 757 | fu_plugin_get_smbios_data (FuPlugin *self, guint8 structure_type) |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 758 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 759 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 760 | if (priv->smbios == NULL) |
| 761 | return NULL; |
| 762 | return fu_smbios_get_data (priv->smbios, structure_type, NULL); |
| 763 | } |
| 764 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 765 | /** |
| 766 | * fu_plugin_set_hwids: |
| 767 | * @self: A #FuPlugin |
| 768 | * @hwids: A #FuHwids |
| 769 | * |
| 770 | * Sets the hwids for a plugin |
| 771 | * |
| 772 | * Since: 0.9.7 |
| 773 | **/ |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 774 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 775 | fu_plugin_set_hwids (FuPlugin *self, FuHwids *hwids) |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 776 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 777 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 778 | g_set_object (&priv->hwids, hwids); |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 779 | } |
| 780 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 781 | /** |
| 782 | * fu_plugin_set_udev_subsystems: |
| 783 | * @self: A #FuPlugin |
Richard Hughes | a0d81c7 | 2019-11-27 11:41:54 +0000 | [diff] [blame] | 784 | * @udev_subsystems: (element-type utf8): A #GPtrArray |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 785 | * |
| 786 | * Sets the udev subsystems used by a plugin |
| 787 | * |
| 788 | * Since: 1.1.2 |
| 789 | **/ |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 790 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 791 | fu_plugin_set_udev_subsystems (FuPlugin *self, GPtrArray *udev_subsystems) |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 792 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 793 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 794 | if (priv->udev_subsystems != NULL) |
| 795 | g_ptr_array_unref (priv->udev_subsystems); |
| 796 | priv->udev_subsystems = g_ptr_array_ref (udev_subsystems); |
| 797 | } |
| 798 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 799 | /** |
| 800 | * fu_plugin_set_quirks: |
| 801 | * @self: A #FuPlugin |
| 802 | * @quirks: A #FuQuirks |
| 803 | * |
| 804 | * Sets the quirks for a plugin |
| 805 | * |
| 806 | * Since: 1.0.1 |
| 807 | **/ |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 808 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 809 | fu_plugin_set_quirks (FuPlugin *self, FuQuirks *quirks) |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 810 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 811 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 812 | g_set_object (&priv->quirks, quirks); |
| 813 | } |
| 814 | |
| 815 | /** |
| 816 | * fu_plugin_get_quirks: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 817 | * @self: A #FuPlugin |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 818 | * |
| 819 | * Returns the hardware database object. This can be used to discover device |
| 820 | * quirks or other device-specific settings. |
| 821 | * |
| 822 | * Returns: (transfer none): a #FuQuirks, or %NULL if not set |
| 823 | * |
| 824 | * Since: 1.0.1 |
| 825 | **/ |
| 826 | FuQuirks * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 827 | fu_plugin_get_quirks (FuPlugin *self) |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 828 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 829 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 830 | return priv->quirks; |
| 831 | } |
| 832 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 833 | /** |
| 834 | * fu_plugin_set_runtime_versions: |
| 835 | * @self: A #FuPlugin |
| 836 | * @runtime_versions: A #GHashTables |
| 837 | * |
| 838 | * Sets the runtime versions for a plugin |
| 839 | * |
| 840 | * Since: 1.0.7 |
| 841 | **/ |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 842 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 843 | fu_plugin_set_runtime_versions (FuPlugin *self, GHashTable *runtime_versions) |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 844 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 845 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 846 | priv->runtime_versions = g_hash_table_ref (runtime_versions); |
| 847 | } |
| 848 | |
| 849 | /** |
| 850 | * fu_plugin_add_runtime_version: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 851 | * @self: A #FuPlugin |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 852 | * @component_id: An AppStream component id, e.g. "org.gnome.Software" |
| 853 | * @version: A version string, e.g. "1.2.3" |
| 854 | * |
Richard Hughes | dce9120 | 2019-04-08 12:47:45 +0100 | [diff] [blame] | 855 | * Sets a runtime version of a specific dependency. |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 856 | * |
| 857 | * Since: 1.0.7 |
| 858 | **/ |
| 859 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 860 | fu_plugin_add_runtime_version (FuPlugin *self, |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 861 | const gchar *component_id, |
| 862 | const gchar *version) |
| 863 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 864 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | b01b486 | 2018-04-20 16:39:48 +0100 | [diff] [blame] | 865 | if (priv->runtime_versions == NULL) |
| 866 | return; |
Richard Hughes | 0eb123b | 2018-04-19 12:00:04 +0100 | [diff] [blame] | 867 | g_hash_table_insert (priv->runtime_versions, |
| 868 | g_strdup (component_id), |
| 869 | g_strdup (version)); |
| 870 | } |
| 871 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 872 | /** |
| 873 | * fu_plugin_set_compile_versions: |
| 874 | * @self: A #FuPlugin |
| 875 | * @compile_versions: A #GHashTables |
| 876 | * |
| 877 | * Sets the compile time versions for a plugin |
| 878 | * |
| 879 | * Since: 1.0.7 |
| 880 | **/ |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 881 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 882 | fu_plugin_set_compile_versions (FuPlugin *self, GHashTable *compile_versions) |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 883 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 884 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 885 | priv->compile_versions = g_hash_table_ref (compile_versions); |
| 886 | } |
| 887 | |
| 888 | /** |
| 889 | * fu_plugin_add_compile_version: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 890 | * @self: A #FuPlugin |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 891 | * @component_id: An AppStream component id, e.g. "org.gnome.Software" |
| 892 | * @version: A version string, e.g. "1.2.3" |
| 893 | * |
Richard Hughes | dce9120 | 2019-04-08 12:47:45 +0100 | [diff] [blame] | 894 | * Sets a compile-time version of a specific dependency. |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 895 | * |
| 896 | * Since: 1.0.7 |
| 897 | **/ |
| 898 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 899 | fu_plugin_add_compile_version (FuPlugin *self, |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 900 | const gchar *component_id, |
| 901 | const gchar *version) |
| 902 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 903 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 904 | if (priv->compile_versions == NULL) |
| 905 | return; |
| 906 | g_hash_table_insert (priv->compile_versions, |
| 907 | g_strdup (component_id), |
| 908 | g_strdup (version)); |
| 909 | } |
| 910 | |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 911 | /** |
| 912 | * fu_plugin_lookup_quirk_by_id: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 913 | * @self: A #FuPlugin |
Richard Hughes | 87fb9ff | 2018-06-28 12:55:59 +0100 | [diff] [blame] | 914 | * @group: A string, e.g. "DfuFlags" |
| 915 | * @key: An ID to match the entry, e.g. "Summary" |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 916 | * |
| 917 | * Looks up an entry in the hardware database using a string value. |
| 918 | * |
| 919 | * Returns: (transfer none): values from the database, or %NULL if not found |
| 920 | * |
| 921 | * Since: 1.0.1 |
| 922 | **/ |
| 923 | const gchar * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 924 | fu_plugin_lookup_quirk_by_id (FuPlugin *self, const gchar *group, const gchar *key) |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 925 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 926 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 927 | g_return_val_if_fail (FU_IS_PLUGIN (self), NULL); |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 928 | |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 929 | /* exact ID */ |
Richard Hughes | 87fb9ff | 2018-06-28 12:55:59 +0100 | [diff] [blame] | 930 | return fu_quirks_lookup_by_id (priv->quirks, group, key); |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | /** |
Richard Hughes | 8fe7cdd | 2018-08-23 10:02:44 +0100 | [diff] [blame] | 934 | * fu_plugin_lookup_quirk_by_id_as_uint64: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 935 | * @self: A #FuPlugin |
Richard Hughes | 8fe7cdd | 2018-08-23 10:02:44 +0100 | [diff] [blame] | 936 | * @group: A string, e.g. "DfuFlags" |
| 937 | * @key: An ID to match the entry, e.g. "Size" |
| 938 | * |
| 939 | * Looks up an entry in the hardware database using a string key, returning |
| 940 | * an integer value. Values are assumed base 10, unless prefixed with "0x" |
| 941 | * where they are parsed as base 16. |
| 942 | * |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 943 | * Returns: guint64 id or 0 if not found |
Richard Hughes | 8fe7cdd | 2018-08-23 10:02:44 +0100 | [diff] [blame] | 944 | * |
| 945 | * Since: 1.1.2 |
| 946 | **/ |
| 947 | guint64 |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 948 | fu_plugin_lookup_quirk_by_id_as_uint64 (FuPlugin *self, const gchar *group, const gchar *key) |
Richard Hughes | 8fe7cdd | 2018-08-23 10:02:44 +0100 | [diff] [blame] | 949 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 950 | return fu_common_strtoull (fu_plugin_lookup_quirk_by_id (self, group, key)); |
Richard Hughes | 8fe7cdd | 2018-08-23 10:02:44 +0100 | [diff] [blame] | 951 | } |
| 952 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 953 | /** |
| 954 | * fu_plugin_set_smbios: |
| 955 | * @self: A #FuPlugin |
| 956 | * @smbios: A #FuSmbios |
| 957 | * |
| 958 | * Sets the smbios for a plugin |
| 959 | * |
| 960 | * Since: 1.0.0 |
| 961 | **/ |
Richard Hughes | 1354ea9 | 2017-09-19 15:58:31 +0100 | [diff] [blame] | 962 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 963 | fu_plugin_set_smbios (FuPlugin *self, FuSmbios *smbios) |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 964 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 965 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 966 | g_set_object (&priv->smbios, smbios); |
| 967 | } |
| 968 | |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 969 | /** |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 970 | * fu_plugin_set_coldplug_delay: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 971 | * @self: A #FuPlugin |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 972 | * @duration: A delay in milliseconds |
| 973 | * |
Richard Hughes | 21eaeef | 2020-01-14 12:10:01 +0000 | [diff] [blame] | 974 | * Set the minimum time that should be waited in-between the call to |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 975 | * fu_plugin_coldplug_prepare() and fu_plugin_coldplug(). This is usually going |
| 976 | * to be the minimum hardware initialisation time from a datasheet. |
| 977 | * |
| 978 | * It is better to use this function rather than using a sleep() in the plugin |
| 979 | * itself as then only one delay is done in the daemon rather than waiting for |
| 980 | * each coldplug prepare in a serial way. |
| 981 | * |
| 982 | * Additionally, very long delays should be avoided as the daemon will be |
| 983 | * blocked from processing requests whilst the coldplug delay is being |
| 984 | * performed. |
| 985 | * |
| 986 | * Since: 0.8.0 |
| 987 | **/ |
| 988 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 989 | fu_plugin_set_coldplug_delay (FuPlugin *self, guint duration) |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 990 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 991 | g_return_if_fail (FU_IS_PLUGIN (self)); |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 992 | g_return_if_fail (duration > 0); |
| 993 | |
| 994 | /* check sanity */ |
| 995 | if (duration > FU_PLUGIN_COLDPLUG_DELAY_MAXIMUM) { |
| 996 | g_warning ("duration of %ums is crazy, truncating to %ums", |
| 997 | duration, |
| 998 | FU_PLUGIN_COLDPLUG_DELAY_MAXIMUM); |
| 999 | duration = FU_PLUGIN_COLDPLUG_DELAY_MAXIMUM; |
| 1000 | } |
| 1001 | |
| 1002 | /* emit */ |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1003 | g_signal_emit (self, signals[SIGNAL_SET_COLDPLUG_DELAY], 0, duration); |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 1004 | } |
| 1005 | |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1006 | static gboolean |
| 1007 | fu_plugin_device_attach (FuPlugin *self, FuDevice *device, GError **error) |
| 1008 | { |
| 1009 | g_autoptr(FuDeviceLocker) locker = NULL; |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1010 | locker = fu_device_locker_new (device, error); |
| 1011 | if (locker == NULL) |
| 1012 | return FALSE; |
| 1013 | return fu_device_attach (device, error); |
| 1014 | } |
| 1015 | |
| 1016 | static gboolean |
| 1017 | fu_plugin_device_detach (FuPlugin *self, FuDevice *device, GError **error) |
| 1018 | { |
| 1019 | g_autoptr(FuDeviceLocker) locker = NULL; |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1020 | locker = fu_device_locker_new (device, error); |
| 1021 | if (locker == NULL) |
| 1022 | return FALSE; |
| 1023 | return fu_device_detach (device, error); |
| 1024 | } |
| 1025 | |
| 1026 | static gboolean |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1027 | fu_plugin_device_activate (FuPlugin *self, FuDevice *device, GError **error) |
| 1028 | { |
| 1029 | g_autoptr(FuDeviceLocker) locker = NULL; |
| 1030 | locker = fu_device_locker_new (device, error); |
| 1031 | if (locker == NULL) |
| 1032 | return FALSE; |
| 1033 | return fu_device_activate (device, error); |
| 1034 | } |
| 1035 | |
| 1036 | static gboolean |
| 1037 | fu_plugin_device_write_firmware (FuPlugin *self, FuDevice *device, |
| 1038 | GBytes *fw, FwupdInstallFlags flags, |
| 1039 | GError **error) |
| 1040 | { |
| 1041 | g_autoptr(FuDeviceLocker) locker = NULL; |
| 1042 | locker = fu_device_locker_new (device, error); |
| 1043 | if (locker == NULL) |
| 1044 | return FALSE; |
| 1045 | return fu_device_write_firmware (device, fw, flags, error); |
| 1046 | } |
| 1047 | |
Richard Hughes | 7f67721 | 2019-10-05 16:19:40 +0100 | [diff] [blame] | 1048 | static gboolean |
| 1049 | fu_plugin_device_read_firmware (FuPlugin *self, FuDevice *device, GError **error) |
| 1050 | { |
| 1051 | g_autoptr(FuDeviceLocker) locker = NULL; |
Richard Hughes | f0eb091 | 2019-10-10 11:37:22 +0100 | [diff] [blame] | 1052 | g_autoptr(FuFirmware) firmware = NULL; |
Richard Hughes | 7f67721 | 2019-10-05 16:19:40 +0100 | [diff] [blame] | 1053 | g_autoptr(GBytes) fw = NULL; |
| 1054 | GChecksumType checksum_types[] = { |
| 1055 | G_CHECKSUM_SHA1, |
| 1056 | G_CHECKSUM_SHA256, |
| 1057 | 0 }; |
| 1058 | locker = fu_device_locker_new (device, error); |
| 1059 | if (locker == NULL) |
| 1060 | return FALSE; |
| 1061 | if (!fu_device_detach (device, error)) |
| 1062 | return FALSE; |
Richard Hughes | f0eb091 | 2019-10-10 11:37:22 +0100 | [diff] [blame] | 1063 | firmware = fu_device_read_firmware (device, error); |
| 1064 | if (firmware == NULL) { |
| 1065 | g_autoptr(GError) error_local = NULL; |
| 1066 | if (!fu_device_attach (device, &error_local)) |
| 1067 | g_debug ("ignoring attach failure: %s", error_local->message); |
| 1068 | g_prefix_error (error, "failed to read firmware: "); |
| 1069 | return FALSE; |
| 1070 | } |
| 1071 | fw = fu_firmware_write (firmware, error); |
Richard Hughes | 7f67721 | 2019-10-05 16:19:40 +0100 | [diff] [blame] | 1072 | if (fw == NULL) { |
| 1073 | g_autoptr(GError) error_local = NULL; |
| 1074 | if (!fu_device_attach (device, &error_local)) |
Richard Hughes | f0eb091 | 2019-10-10 11:37:22 +0100 | [diff] [blame] | 1075 | g_debug ("ignoring attach failure: %s", error_local->message); |
| 1076 | g_prefix_error (error, "failed to write firmware: "); |
Richard Hughes | 7f67721 | 2019-10-05 16:19:40 +0100 | [diff] [blame] | 1077 | return FALSE; |
| 1078 | } |
| 1079 | for (guint i = 0; checksum_types[i] != 0; i++) { |
| 1080 | g_autofree gchar *hash = NULL; |
| 1081 | hash = g_compute_checksum_for_bytes (checksum_types[i], fw); |
| 1082 | fu_device_add_checksum (device, hash); |
| 1083 | } |
| 1084 | return fu_device_attach (device, error); |
| 1085 | } |
| 1086 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1087 | /** |
| 1088 | * fu_plugin_runner_startup: |
| 1089 | * @self: a #FuPlugin |
| 1090 | * @error: a #GError or NULL |
| 1091 | * |
| 1092 | * Runs the startup routine for the plugin |
| 1093 | * |
| 1094 | * Returns: #TRUE for success, #FALSE for failure |
| 1095 | * |
| 1096 | * Since: 0.8.0 |
| 1097 | **/ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1098 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1099 | fu_plugin_runner_startup (FuPlugin *self, GError **error) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1100 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1101 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1102 | FuPluginStartupFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1103 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1104 | |
| 1105 | /* not enabled */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1106 | if (!priv->enabled) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1107 | return TRUE; |
| 1108 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1109 | /* no object loaded */ |
| 1110 | if (priv->module == NULL) |
| 1111 | return TRUE; |
| 1112 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1113 | /* optional */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1114 | g_module_symbol (priv->module, "fu_plugin_startup", (gpointer *) &func); |
| 1115 | if (func == NULL) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1116 | return TRUE; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1117 | g_debug ("performing startup() on %s", priv->name); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1118 | if (!func (self, &error_local)) { |
| 1119 | if (error_local == NULL) { |
| 1120 | g_critical ("unset error in plugin %s for startup()", |
| 1121 | priv->name); |
| 1122 | g_set_error_literal (&error_local, |
| 1123 | FWUPD_ERROR, |
| 1124 | FWUPD_ERROR_INTERNAL, |
| 1125 | "unspecified error"); |
| 1126 | } |
| 1127 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1128 | "failed to startup using %s: ", |
| 1129 | priv->name); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1130 | return FALSE; |
| 1131 | } |
| 1132 | return TRUE; |
| 1133 | } |
| 1134 | |
| 1135 | static gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1136 | fu_plugin_runner_device_generic (FuPlugin *self, FuDevice *device, |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1137 | const gchar *symbol_name, |
| 1138 | FuPluginDeviceFunc device_func, |
| 1139 | GError **error) |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1140 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1141 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1142 | FuPluginDeviceFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1143 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1144 | |
| 1145 | /* not enabled */ |
| 1146 | if (!priv->enabled) |
| 1147 | return TRUE; |
| 1148 | |
Richard Hughes | d3d96cc | 2017-11-14 11:34:33 +0000 | [diff] [blame] | 1149 | /* no object loaded */ |
| 1150 | if (priv->module == NULL) |
| 1151 | return TRUE; |
| 1152 | |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1153 | /* optional */ |
| 1154 | g_module_symbol (priv->module, symbol_name, (gpointer *) &func); |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1155 | if (func == NULL) { |
| 1156 | if (device_func != NULL) { |
| 1157 | g_debug ("running superclassed %s() on %s", |
| 1158 | symbol_name + 10, priv->name); |
| 1159 | return device_func (self, device, error); |
| 1160 | } |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1161 | return TRUE; |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1162 | } |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1163 | g_debug ("performing %s() on %s", symbol_name + 10, priv->name); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1164 | if (!func (self, device, &error_local)) { |
| 1165 | if (error_local == NULL) { |
| 1166 | g_critical ("unset error in plugin %s for %s()", |
| 1167 | priv->name, symbol_name + 10); |
| 1168 | g_set_error_literal (&error_local, |
| 1169 | FWUPD_ERROR, |
| 1170 | FWUPD_ERROR_INTERNAL, |
| 1171 | "unspecified error"); |
| 1172 | } |
| 1173 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1174 | "failed to %s using %s: ", |
| 1175 | symbol_name + 10, priv->name); |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1176 | return FALSE; |
| 1177 | } |
| 1178 | return TRUE; |
| 1179 | } |
| 1180 | |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1181 | static gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1182 | fu_plugin_runner_flagged_device_generic (FuPlugin *self, FwupdInstallFlags flags, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1183 | FuDevice *device, |
| 1184 | const gchar *symbol_name, GError **error) |
| 1185 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1186 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1187 | FuPluginFlaggedDeviceFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1188 | g_autoptr(GError) error_local = NULL; |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1189 | |
| 1190 | /* not enabled */ |
| 1191 | if (!priv->enabled) |
| 1192 | return TRUE; |
| 1193 | |
| 1194 | /* no object loaded */ |
| 1195 | if (priv->module == NULL) |
| 1196 | return TRUE; |
| 1197 | |
| 1198 | /* optional */ |
| 1199 | g_module_symbol (priv->module, symbol_name, (gpointer *) &func); |
| 1200 | if (func == NULL) |
| 1201 | return TRUE; |
| 1202 | g_debug ("performing %s() on %s", symbol_name + 10, priv->name); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1203 | if (!func (self, flags, device, &error_local)) { |
| 1204 | if (error_local == NULL) { |
| 1205 | g_critical ("unset error in plugin %s for %s()", |
| 1206 | priv->name, symbol_name + 10); |
| 1207 | g_set_error_literal (&error_local, |
| 1208 | FWUPD_ERROR, |
| 1209 | FWUPD_ERROR_INTERNAL, |
| 1210 | "unspecified error"); |
| 1211 | } |
| 1212 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1213 | "failed to %s using %s: ", |
| 1214 | symbol_name + 10, priv->name); |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1215 | return FALSE; |
| 1216 | } |
| 1217 | return TRUE; |
| 1218 | |
| 1219 | } |
| 1220 | |
| 1221 | static gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1222 | fu_plugin_runner_device_array_generic (FuPlugin *self, GPtrArray *devices, |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1223 | const gchar *symbol_name, GError **error) |
| 1224 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1225 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1226 | FuPluginDeviceArrayFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1227 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1228 | |
| 1229 | /* not enabled */ |
| 1230 | if (!priv->enabled) |
| 1231 | return TRUE; |
| 1232 | |
| 1233 | /* no object loaded */ |
| 1234 | if (priv->module == NULL) |
| 1235 | return TRUE; |
| 1236 | |
| 1237 | /* optional */ |
| 1238 | g_module_symbol (priv->module, symbol_name, (gpointer *) &func); |
| 1239 | if (func == NULL) |
| 1240 | return TRUE; |
| 1241 | g_debug ("performing %s() on %s", symbol_name + 10, priv->name); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1242 | if (!func (self, devices, &error_local)) { |
| 1243 | if (error_local == NULL) { |
| 1244 | g_critical ("unset error in plugin %s for %s()", |
| 1245 | priv->name, symbol_name + 10); |
| 1246 | g_set_error_literal (&error_local, |
| 1247 | FWUPD_ERROR, |
| 1248 | FWUPD_ERROR_INTERNAL, |
| 1249 | "unspecified error"); |
| 1250 | } |
| 1251 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1252 | "failed to %s using %s: ", |
| 1253 | symbol_name + 10, priv->name); |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1254 | return FALSE; |
| 1255 | } |
| 1256 | return TRUE; |
| 1257 | } |
| 1258 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1259 | /** |
| 1260 | * fu_plugin_runner_coldplug: |
| 1261 | * @self: a #FuPlugin |
| 1262 | * @error: a #GError or NULL |
| 1263 | * |
| 1264 | * Runs the coldplug routine for the plugin |
| 1265 | * |
| 1266 | * Returns: #TRUE for success, #FALSE for failure |
| 1267 | * |
| 1268 | * Since: 0.8.0 |
| 1269 | **/ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1270 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1271 | fu_plugin_runner_coldplug (FuPlugin *self, GError **error) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1272 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1273 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1274 | FuPluginStartupFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1275 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1276 | |
| 1277 | /* not enabled */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1278 | if (!priv->enabled) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1279 | return TRUE; |
| 1280 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1281 | /* no object loaded */ |
| 1282 | if (priv->module == NULL) |
| 1283 | return TRUE; |
| 1284 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1285 | /* optional */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1286 | g_module_symbol (priv->module, "fu_plugin_coldplug", (gpointer *) &func); |
| 1287 | if (func == NULL) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 1288 | return TRUE; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1289 | g_debug ("performing coldplug() on %s", priv->name); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1290 | if (!func (self, &error_local)) { |
| 1291 | if (error_local == NULL) { |
| 1292 | g_critical ("unset error in plugin %s for coldplug()", |
| 1293 | priv->name); |
| 1294 | g_set_error_literal (&error_local, |
| 1295 | FWUPD_ERROR, |
| 1296 | FWUPD_ERROR_INTERNAL, |
| 1297 | "unspecified error"); |
| 1298 | } |
| 1299 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1300 | "failed to coldplug using %s: ", priv->name); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 1301 | return FALSE; |
| 1302 | } |
| 1303 | return TRUE; |
| 1304 | } |
| 1305 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1306 | /** |
| 1307 | * fu_plugin_runner_recoldplug: |
| 1308 | * @self: a #FuPlugin |
| 1309 | * @error: a #GError or NULL |
| 1310 | * |
| 1311 | * Runs the recoldplug routine for the plugin |
| 1312 | * |
| 1313 | * Returns: #TRUE for success, #FALSE for failure |
| 1314 | * |
| 1315 | * Since: 1.0.4 |
| 1316 | **/ |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1317 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1318 | fu_plugin_runner_recoldplug (FuPlugin *self, GError **error) |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 1319 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1320 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 1321 | FuPluginStartupFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1322 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 1323 | |
| 1324 | /* not enabled */ |
| 1325 | if (!priv->enabled) |
| 1326 | return TRUE; |
| 1327 | |
| 1328 | /* no object loaded */ |
| 1329 | if (priv->module == NULL) |
| 1330 | return TRUE; |
| 1331 | |
| 1332 | /* optional */ |
| 1333 | g_module_symbol (priv->module, "fu_plugin_recoldplug", (gpointer *) &func); |
| 1334 | if (func == NULL) |
| 1335 | return TRUE; |
| 1336 | g_debug ("performing recoldplug() on %s", priv->name); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1337 | if (!func (self, &error_local)) { |
| 1338 | if (error_local == NULL) { |
| 1339 | g_critical ("unset error in plugin %s for recoldplug()", |
| 1340 | priv->name); |
| 1341 | g_set_error_literal (&error_local, |
| 1342 | FWUPD_ERROR, |
| 1343 | FWUPD_ERROR_INTERNAL, |
| 1344 | "unspecified error"); |
| 1345 | } |
| 1346 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1347 | "failed to recoldplug using %s: ", |
| 1348 | priv->name); |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 1349 | return FALSE; |
| 1350 | } |
| 1351 | return TRUE; |
| 1352 | } |
| 1353 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1354 | /** |
| 1355 | * fu_plugin_runner_coldplug_prepare: |
| 1356 | * @self: a #FuPlugin |
| 1357 | * @error: a #GError or NULL |
| 1358 | * |
| 1359 | * Runs the coldplug_prepare routine for the plugin |
| 1360 | * |
| 1361 | * Returns: #TRUE for success, #FALSE for failure |
| 1362 | * |
| 1363 | * Since: 0.8.0 |
| 1364 | **/ |
Richard Hughes | 2de8f13 | 2018-01-17 09:12:02 +0000 | [diff] [blame] | 1365 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1366 | fu_plugin_runner_coldplug_prepare (FuPlugin *self, GError **error) |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1367 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1368 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1369 | FuPluginStartupFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1370 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1371 | |
| 1372 | /* not enabled */ |
| 1373 | if (!priv->enabled) |
| 1374 | return TRUE; |
| 1375 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1376 | /* no object loaded */ |
| 1377 | if (priv->module == NULL) |
| 1378 | return TRUE; |
| 1379 | |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1380 | /* optional */ |
| 1381 | g_module_symbol (priv->module, "fu_plugin_coldplug_prepare", (gpointer *) &func); |
| 1382 | if (func == NULL) |
| 1383 | return TRUE; |
| 1384 | g_debug ("performing coldplug_prepare() on %s", priv->name); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1385 | if (!func (self, &error_local)) { |
| 1386 | if (error_local == NULL) { |
| 1387 | g_critical ("unset error in plugin %s for coldplug_prepare()", |
| 1388 | priv->name); |
| 1389 | g_set_error_literal (&error_local, |
| 1390 | FWUPD_ERROR, |
| 1391 | FWUPD_ERROR_INTERNAL, |
| 1392 | "unspecified error"); |
| 1393 | } |
| 1394 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1395 | "failed to coldplug_prepare using %s: ", |
| 1396 | priv->name); |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1397 | return FALSE; |
| 1398 | } |
| 1399 | return TRUE; |
| 1400 | } |
| 1401 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1402 | /** |
| 1403 | * fu_plugin_runner_coldplug_cleanup: |
| 1404 | * @self: a #FuPlugin |
| 1405 | * @error: a #GError or NULL |
| 1406 | * |
| 1407 | * Runs the coldplug_cleanup routine for the plugin |
| 1408 | * |
| 1409 | * Returns: #TRUE for success, #FALSE for failure |
| 1410 | * |
| 1411 | * Since: 0.8.0 |
| 1412 | **/ |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1413 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1414 | fu_plugin_runner_coldplug_cleanup (FuPlugin *self, GError **error) |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1415 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1416 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1417 | FuPluginStartupFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1418 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1419 | |
| 1420 | /* not enabled */ |
| 1421 | if (!priv->enabled) |
| 1422 | return TRUE; |
| 1423 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1424 | /* no object loaded */ |
| 1425 | if (priv->module == NULL) |
| 1426 | return TRUE; |
| 1427 | |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1428 | /* optional */ |
| 1429 | g_module_symbol (priv->module, "fu_plugin_coldplug_cleanup", (gpointer *) &func); |
| 1430 | if (func == NULL) |
| 1431 | return TRUE; |
| 1432 | g_debug ("performing coldplug_cleanup() on %s", priv->name); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1433 | if (!func (self, &error_local)) { |
| 1434 | if (error_local == NULL) { |
| 1435 | g_critical ("unset error in plugin %s for coldplug_cleanup()", |
| 1436 | priv->name); |
| 1437 | g_set_error_literal (&error_local, |
| 1438 | FWUPD_ERROR, |
| 1439 | FWUPD_ERROR_INTERNAL, |
| 1440 | "unspecified error"); |
| 1441 | } |
| 1442 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1443 | "failed to coldplug_cleanup using %s: ", |
| 1444 | priv->name); |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1445 | return FALSE; |
| 1446 | } |
| 1447 | return TRUE; |
| 1448 | } |
| 1449 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1450 | /** |
| 1451 | * fu_plugin_runner_composite_prepare: |
| 1452 | * @self: a #FuPlugin |
Richard Hughes | a0d81c7 | 2019-11-27 11:41:54 +0000 | [diff] [blame] | 1453 | * @devices: (element-type FuDevice): a #GPtrArray of devices |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1454 | * @error: a #GError or NULL |
| 1455 | * |
| 1456 | * Runs the composite_prepare routine for the plugin |
| 1457 | * |
| 1458 | * Returns: #TRUE for success, #FALSE for failure |
| 1459 | * |
| 1460 | * Since: 1.0.9 |
| 1461 | **/ |
Richard Hughes | 46487c9 | 2017-01-07 21:26:34 +0000 | [diff] [blame] | 1462 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1463 | fu_plugin_runner_composite_prepare (FuPlugin *self, GPtrArray *devices, GError **error) |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1464 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1465 | return fu_plugin_runner_device_array_generic (self, devices, |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1466 | "fu_plugin_composite_prepare", |
| 1467 | error); |
| 1468 | } |
| 1469 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1470 | /** |
| 1471 | * fu_plugin_runner_composite_cleanup: |
| 1472 | * @self: a #FuPlugin |
Richard Hughes | a0d81c7 | 2019-11-27 11:41:54 +0000 | [diff] [blame] | 1473 | * @devices: (element-type FuDevice): a #GPtrArray of devices |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1474 | * @error: a #GError or NULL |
| 1475 | * |
| 1476 | * Runs the composite_cleanup routine for the plugin |
| 1477 | * |
| 1478 | * Returns: #TRUE for success, #FALSE for failure |
| 1479 | * |
| 1480 | * Since: 1.0.9 |
| 1481 | **/ |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1482 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1483 | fu_plugin_runner_composite_cleanup (FuPlugin *self, GPtrArray *devices, GError **error) |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1484 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1485 | return fu_plugin_runner_device_array_generic (self, devices, |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1486 | "fu_plugin_composite_cleanup", |
| 1487 | error); |
| 1488 | } |
| 1489 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1490 | /** |
| 1491 | * fu_plugin_runner_update_prepare: |
| 1492 | * @self: a #FuPlugin |
| 1493 | * @error: a #GError or NULL |
| 1494 | * |
| 1495 | * Runs the update_prepare routine for the plugin |
| 1496 | * |
| 1497 | * Returns: #TRUE for success, #FALSE for failure |
| 1498 | * |
| 1499 | * Since: 1.1.2 |
| 1500 | **/ |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 1501 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1502 | fu_plugin_runner_update_prepare (FuPlugin *self, FwupdInstallFlags flags, FuDevice *device, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1503 | GError **error) |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1504 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1505 | return fu_plugin_runner_flagged_device_generic (self, flags, device, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1506 | "fu_plugin_update_prepare", |
| 1507 | error); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1508 | } |
| 1509 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1510 | /** |
| 1511 | * fu_plugin_runner_update_cleanup: |
| 1512 | * @self: a #FuPlugin |
| 1513 | * @error: a #GError or NULL |
| 1514 | * |
| 1515 | * Runs the update_cleanup routine for the plugin |
| 1516 | * |
| 1517 | * Returns: #TRUE for success, #FALSE for failure |
| 1518 | * |
| 1519 | * Since: 1.1.2 |
| 1520 | **/ |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1521 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1522 | fu_plugin_runner_update_cleanup (FuPlugin *self, FwupdInstallFlags flags, FuDevice *device, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1523 | GError **error) |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1524 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1525 | return fu_plugin_runner_flagged_device_generic (self, flags, device, |
Mario Limonciello | e3b1a3f | 2018-08-21 13:01:45 -0500 | [diff] [blame] | 1526 | "fu_plugin_update_cleanup", |
| 1527 | error); |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1528 | } |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1529 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1530 | /** |
| 1531 | * fu_plugin_runner_update_attach: |
| 1532 | * @self: a #FuPlugin |
| 1533 | * @device: a #FuDevice |
| 1534 | * @error: a #GError or NULL |
| 1535 | * |
| 1536 | * Runs the update_attach routine for the plugin |
| 1537 | * |
| 1538 | * Returns: #TRUE for success, #FALSE for failure |
| 1539 | * |
| 1540 | * Since: 1.1.2 |
| 1541 | **/ |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1542 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1543 | fu_plugin_runner_update_attach (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1544 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1545 | return fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1546 | "fu_plugin_update_attach", |
| 1547 | fu_plugin_device_attach, |
| 1548 | error); |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1549 | } |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1550 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1551 | /** |
| 1552 | * fu_plugin_runner_update_detach: |
| 1553 | * @self: a #FuPlugin |
| 1554 | * @device: A #FuDevice |
| 1555 | * @error: a #GError or NULL |
| 1556 | * |
| 1557 | * Runs the update_detach routine for the plugin |
| 1558 | * |
| 1559 | * Returns: #TRUE for success, #FALSE for failure |
| 1560 | * |
| 1561 | * Since: 1.1.2 |
| 1562 | **/ |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1563 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1564 | fu_plugin_runner_update_detach (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1565 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1566 | return fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 1567 | "fu_plugin_update_detach", |
| 1568 | fu_plugin_device_detach, |
| 1569 | error); |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1570 | } |
| 1571 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1572 | /** |
| 1573 | * fu_plugin_runner_update_reload: |
| 1574 | * @self: a #FuPlugin |
| 1575 | * @error: a #GError or NULL |
| 1576 | * |
| 1577 | * Runs reload routine for a device |
| 1578 | * |
| 1579 | * Returns: #TRUE for success, #FALSE for failure |
| 1580 | * |
| 1581 | * Since: 1.1.2 |
| 1582 | **/ |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1583 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1584 | fu_plugin_runner_update_reload (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | 0d7fdb3 | 2017-11-11 20:23:14 +0000 | [diff] [blame] | 1585 | { |
Richard Hughes | 42f33df | 2019-10-05 20:52:33 +0100 | [diff] [blame] | 1586 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 1587 | g_autoptr(FuDeviceLocker) locker = NULL; |
| 1588 | |
| 1589 | /* not enabled */ |
| 1590 | if (!priv->enabled) |
| 1591 | return TRUE; |
| 1592 | |
| 1593 | /* no object loaded */ |
| 1594 | locker = fu_device_locker_new (device, error); |
| 1595 | if (locker == NULL) |
| 1596 | return FALSE; |
| 1597 | return fu_device_reload (device, error); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 1598 | } |
| 1599 | |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1600 | /** |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 1601 | * fu_plugin_runner_add_security_attrs: |
| 1602 | * @self: a #FuPlugin |
| 1603 | * @attrs: (element-type FwupdSecurityAttr): a #GPtrArray of attributes |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 1604 | * |
Richard Hughes | f58ac73 | 2020-05-12 15:23:44 +0100 | [diff] [blame^] | 1605 | * Runs the add_security_attrs routine for the plugin |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 1606 | * |
| 1607 | * Since: 1.5.0 |
| 1608 | **/ |
Richard Hughes | f58ac73 | 2020-05-12 15:23:44 +0100 | [diff] [blame^] | 1609 | void |
| 1610 | fu_plugin_runner_add_security_attrs (FuPlugin *self, FuSecurityAttrs *attrs) |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 1611 | { |
Richard Hughes | f58ac73 | 2020-05-12 15:23:44 +0100 | [diff] [blame^] | 1612 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 1613 | FuPluginSecurityAttrsFunc func = NULL; |
| 1614 | const gchar *symbol_name = "fu_plugin_add_security_attrs"; |
| 1615 | |
| 1616 | /* no object loaded */ |
| 1617 | if (priv->module == NULL) |
| 1618 | return; |
| 1619 | |
| 1620 | /* optional, but gets called even for disabled plugins */ |
| 1621 | g_module_symbol (priv->module, symbol_name, (gpointer *) &func); |
| 1622 | if (func == NULL) |
| 1623 | return; |
| 1624 | g_debug ("performing %s() on %s", symbol_name + 10, priv->name); |
| 1625 | func (self, attrs); |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | /** |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1629 | * fu_plugin_add_udev_subsystem: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 1630 | * @self: a #FuPlugin |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1631 | * @subsystem: a subsystem name, e.g. `pciport` |
| 1632 | * |
| 1633 | * Registers the udev subsystem to be watched by the daemon. |
| 1634 | * |
| 1635 | * Plugins can use this method only in fu_plugin_init() |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1636 | * |
| 1637 | * Since: 1.1.2 |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1638 | **/ |
| 1639 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1640 | fu_plugin_add_udev_subsystem (FuPlugin *self, const gchar *subsystem) |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1641 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1642 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1643 | for (guint i = 0; i < priv->udev_subsystems->len; i++) { |
| 1644 | const gchar *subsystem_tmp = g_ptr_array_index (priv->udev_subsystems, i); |
| 1645 | if (g_strcmp0 (subsystem_tmp, subsystem) == 0) |
| 1646 | return; |
| 1647 | } |
| 1648 | g_debug ("added udev subsystem watch of %s", subsystem); |
| 1649 | g_ptr_array_add (priv->udev_subsystems, g_strdup (subsystem)); |
| 1650 | } |
| 1651 | |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1652 | /** |
| 1653 | * fu_plugin_set_device_gtype: |
| 1654 | * @self: a #FuPlugin |
| 1655 | * @device_gtype: a #GType `FU_TYPE_DEVICE` |
| 1656 | * |
| 1657 | * Sets the device #GType which is used when creating devices. |
| 1658 | * |
| 1659 | * If this method is used then fu_plugin_usb_device_added() is not called, and |
| 1660 | * instead the object is created in the daemon for the plugin. |
| 1661 | * |
| 1662 | * Plugins can use this method only in fu_plugin_init() |
| 1663 | * |
| 1664 | * Since: 1.3.3 |
| 1665 | **/ |
| 1666 | void |
| 1667 | fu_plugin_set_device_gtype (FuPlugin *self, GType device_gtype) |
| 1668 | { |
| 1669 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 1670 | priv->device_gtype = device_gtype; |
| 1671 | } |
| 1672 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1673 | /** |
| 1674 | * fu_plugin_add_firmware_gtype: |
| 1675 | * @self: a #FuPlugin |
| 1676 | * @id: A string describing the type |
| 1677 | * @gtype: a #GType `FU_TYPE_DEVICE` |
| 1678 | * |
| 1679 | * Adds a firmware #GType which is used when creating devices. |
| 1680 | * * |
| 1681 | * Plugins can use this method only in fu_plugin_init() |
| 1682 | * |
| 1683 | * Since: 1.3.3 |
| 1684 | **/ |
Richard Hughes | 95c98a9 | 2019-10-22 16:03:15 +0100 | [diff] [blame] | 1685 | void |
| 1686 | fu_plugin_add_firmware_gtype (FuPlugin *self, const gchar *id, GType gtype) |
| 1687 | { |
| 1688 | g_signal_emit (self, signals[SIGNAL_ADD_FIRMWARE_GTYPE], 0, id, gtype); |
| 1689 | } |
| 1690 | |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1691 | static gboolean |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1692 | fu_plugin_check_supported_device (FuPlugin *self, FuDevice *device) |
| 1693 | { |
| 1694 | GPtrArray *instance_ids = fu_device_get_instance_ids (device); |
| 1695 | for (guint i = 0; i < instance_ids->len; i++) { |
| 1696 | const gchar *instance_id = g_ptr_array_index (instance_ids, i); |
| 1697 | g_autofree gchar *guid = fwupd_guid_hash_string (instance_id); |
| 1698 | if (fu_plugin_check_supported (self, guid)) |
| 1699 | return TRUE; |
| 1700 | } |
| 1701 | return FALSE; |
| 1702 | } |
| 1703 | |
| 1704 | static gboolean |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1705 | fu_plugin_usb_device_added (FuPlugin *self, FuUsbDevice *device, GError **error) |
| 1706 | { |
| 1707 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1708 | GType device_gtype = fu_device_get_specialized_gtype (FU_DEVICE (device)); |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1709 | g_autoptr(FuDevice) dev = NULL; |
| 1710 | g_autoptr(FuDeviceLocker) locker = NULL; |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1711 | |
| 1712 | /* fall back to plugin default */ |
| 1713 | if (device_gtype == G_TYPE_INVALID) |
| 1714 | device_gtype = priv->device_gtype; |
| 1715 | |
| 1716 | /* create new device and incorporate existing properties */ |
| 1717 | dev = g_object_new (device_gtype, NULL); |
| 1718 | fu_device_incorporate (dev, FU_DEVICE (device)); |
Richard Hughes | 0f66a02 | 2020-02-19 18:54:38 +0000 | [diff] [blame] | 1719 | if (!fu_plugin_runner_device_created (self, dev, error)) |
| 1720 | return FALSE; |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1721 | |
| 1722 | /* there are a lot of different devices that match, but not all respond |
| 1723 | * well to opening -- so limit some ones with issued updates */ |
| 1724 | if (fu_device_has_flag (dev, FWUPD_DEVICE_FLAG_ONLY_SUPPORTED)) { |
| 1725 | if (!fu_device_probe (dev, error)) |
| 1726 | return FALSE; |
| 1727 | fu_device_convert_instance_ids (dev); |
| 1728 | if (!fu_plugin_check_supported_device (self, dev)) { |
| 1729 | g_autofree gchar *guids = fu_device_get_guids_as_str (dev); |
| 1730 | g_debug ("%s has no updates, so ignoring device", guids); |
| 1731 | return TRUE; |
| 1732 | } |
| 1733 | } |
| 1734 | |
| 1735 | /* open and add */ |
| 1736 | locker = fu_device_locker_new (dev, error); |
| 1737 | if (locker == NULL) |
| 1738 | return FALSE; |
| 1739 | fu_plugin_device_add (self, dev); |
Richard Hughes | 6a07870 | 2020-05-09 20:36:33 +0100 | [diff] [blame] | 1740 | fu_plugin_runner_device_added (self, dev); |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1741 | return TRUE; |
| 1742 | } |
| 1743 | |
| 1744 | static gboolean |
Mario Limonciello | 096e3cf | 2020-04-28 15:01:33 -0500 | [diff] [blame] | 1745 | fu_plugin_udev_device_changed (FuPlugin *self, FuUdevDevice *device, GError **error) |
| 1746 | { |
| 1747 | g_autoptr(FuDeviceLocker) locker = NULL; |
| 1748 | |
| 1749 | /* open */ |
| 1750 | locker = fu_device_locker_new (FU_DEVICE (device), error); |
| 1751 | if (locker == NULL) |
| 1752 | return FALSE; |
| 1753 | return fu_device_rescan (FU_DEVICE (device), error); |
| 1754 | } |
| 1755 | |
| 1756 | static gboolean |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1757 | fu_plugin_udev_device_added (FuPlugin *self, FuUdevDevice *device, GError **error) |
| 1758 | { |
| 1759 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 1760 | GType device_gtype = fu_device_get_specialized_gtype (FU_DEVICE (device)); |
| 1761 | g_autoptr(FuDevice) dev = NULL; |
| 1762 | g_autoptr(FuDeviceLocker) locker = NULL; |
| 1763 | |
| 1764 | /* fall back to plugin default */ |
| 1765 | if (device_gtype == G_TYPE_INVALID) |
| 1766 | device_gtype = priv->device_gtype; |
| 1767 | |
| 1768 | /* create new device and incorporate existing properties */ |
| 1769 | dev = g_object_new (device_gtype, NULL); |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1770 | fu_device_incorporate (FU_DEVICE (dev), FU_DEVICE (device)); |
Richard Hughes | 0f66a02 | 2020-02-19 18:54:38 +0000 | [diff] [blame] | 1771 | if (!fu_plugin_runner_device_created (self, dev, error)) |
| 1772 | return FALSE; |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1773 | |
| 1774 | /* there are a lot of different devices that match, but not all respond |
| 1775 | * well to opening -- so limit some ones with issued updates */ |
| 1776 | if (fu_device_has_flag (dev, FWUPD_DEVICE_FLAG_ONLY_SUPPORTED)) { |
| 1777 | if (!fu_device_probe (dev, error)) |
| 1778 | return FALSE; |
| 1779 | fu_device_convert_instance_ids (dev); |
| 1780 | if (!fu_plugin_check_supported_device (self, dev)) { |
| 1781 | g_autofree gchar *guids = fu_device_get_guids_as_str (dev); |
| 1782 | g_debug ("%s has no updates, so ignoring device", guids); |
| 1783 | return TRUE; |
| 1784 | } |
| 1785 | } |
| 1786 | |
| 1787 | /* open and add */ |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1788 | locker = fu_device_locker_new (dev, error); |
| 1789 | if (locker == NULL) |
| 1790 | return FALSE; |
| 1791 | fu_plugin_device_add (self, FU_DEVICE (dev)); |
Richard Hughes | 6a07870 | 2020-05-09 20:36:33 +0100 | [diff] [blame] | 1792 | fu_plugin_runner_device_added (self, dev); |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1793 | return TRUE; |
| 1794 | } |
| 1795 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1796 | /** |
| 1797 | * fu_plugin_runner_usb_device_added: |
| 1798 | * @self: a #FuPlugin |
| 1799 | * @device: a #FuUsbDevice |
| 1800 | * @error: a #GError or NULL |
| 1801 | * |
| 1802 | * Call the usb_device_added routine for the plugin |
| 1803 | * |
| 1804 | * Returns: #TRUE for success, #FALSE for failure |
| 1805 | * |
| 1806 | * Since: 1.0.2 |
| 1807 | **/ |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 1808 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1809 | fu_plugin_runner_usb_device_added (FuPlugin *self, FuUsbDevice *device, GError **error) |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 1810 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1811 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 1812 | FuPluginUsbDeviceAddedFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1813 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 1814 | |
| 1815 | /* not enabled */ |
| 1816 | if (!priv->enabled) |
| 1817 | return TRUE; |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 1818 | |
| 1819 | /* no object loaded */ |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 1820 | if (priv->module == NULL) |
| 1821 | return TRUE; |
| 1822 | |
| 1823 | /* optional */ |
| 1824 | g_module_symbol (priv->module, "fu_plugin_usb_device_added", (gpointer *) &func); |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1825 | if (func == NULL) { |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1826 | if (priv->device_gtype != G_TYPE_INVALID || |
| 1827 | fu_device_get_specialized_gtype (FU_DEVICE (device)) != G_TYPE_INVALID) { |
Mario Limonciello | 0e50032 | 2019-10-17 18:41:04 -0500 | [diff] [blame] | 1828 | if (!fu_plugin_usb_device_added (self, device, error)) |
Mario Limonciello | a9be536 | 2019-10-12 13:17:45 -0500 | [diff] [blame] | 1829 | return FALSE; |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1830 | } |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1831 | return TRUE; |
Richard Hughes | 989acf1 | 2019-10-05 20:16:47 +0100 | [diff] [blame] | 1832 | } |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1833 | g_debug ("performing usb_device_added() on %s", priv->name); |
| 1834 | if (!func (self, device, &error_local)) { |
| 1835 | if (error_local == NULL) { |
| 1836 | g_critical ("unset error in plugin %s for usb_device_added()", |
| 1837 | priv->name); |
| 1838 | g_set_error_literal (&error_local, |
| 1839 | FWUPD_ERROR, |
| 1840 | FWUPD_ERROR_INTERNAL, |
| 1841 | "unspecified error"); |
| 1842 | } |
| 1843 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1844 | "failed to add device using on %s: ", |
| 1845 | priv->name); |
| 1846 | return FALSE; |
Richard Hughes | 104f651 | 2017-11-24 11:44:57 +0000 | [diff] [blame] | 1847 | } |
| 1848 | return TRUE; |
| 1849 | } |
| 1850 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1851 | /** |
| 1852 | * fu_plugin_runner_udev_device_added: |
| 1853 | * @self: a #FuPlugin |
| 1854 | * @device: a #FuUdevDevice |
| 1855 | * @error: a #GError or NULL |
| 1856 | * |
| 1857 | * Call the udev_device_added routine for the plugin |
| 1858 | * |
| 1859 | * Returns: #TRUE for success, #FALSE for failure |
| 1860 | * |
| 1861 | * Since: 1.0.2 |
| 1862 | **/ |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1863 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1864 | fu_plugin_runner_udev_device_added (FuPlugin *self, FuUdevDevice *device, GError **error) |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1865 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 1866 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1867 | FuPluginUdevDeviceAddedFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1868 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1869 | |
| 1870 | /* not enabled */ |
| 1871 | if (!priv->enabled) |
| 1872 | return TRUE; |
| 1873 | |
| 1874 | /* no object loaded */ |
| 1875 | if (priv->module == NULL) |
| 1876 | return TRUE; |
| 1877 | |
| 1878 | /* optional */ |
| 1879 | g_module_symbol (priv->module, "fu_plugin_udev_device_added", (gpointer *) &func); |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1880 | if (func == NULL) { |
| 1881 | if (priv->device_gtype != G_TYPE_INVALID || |
| 1882 | fu_device_get_specialized_gtype (FU_DEVICE (device)) != G_TYPE_INVALID) { |
Mario Limonciello | 0e50032 | 2019-10-17 18:41:04 -0500 | [diff] [blame] | 1883 | if (!fu_plugin_udev_device_added (self, device, error)) |
Mario Limonciello | a9be536 | 2019-10-12 13:17:45 -0500 | [diff] [blame] | 1884 | return FALSE; |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1885 | } |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1886 | return TRUE; |
Richard Hughes | d8a8d5e | 2019-10-08 13:05:02 +0100 | [diff] [blame] | 1887 | } |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 1888 | g_debug ("performing udev_device_added() on %s", priv->name); |
| 1889 | if (!func (self, device, &error_local)) { |
| 1890 | if (error_local == NULL) { |
| 1891 | g_critical ("unset error in plugin %s for udev_device_added()", |
| 1892 | priv->name); |
| 1893 | g_set_error_literal (&error_local, |
| 1894 | FWUPD_ERROR, |
| 1895 | FWUPD_ERROR_INTERNAL, |
| 1896 | "unspecified error"); |
| 1897 | } |
| 1898 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1899 | "failed to add device using on %s: ", |
| 1900 | priv->name); |
| 1901 | return FALSE; |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 1902 | } |
| 1903 | return TRUE; |
| 1904 | } |
| 1905 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1906 | /** |
| 1907 | * fu_plugin_runner_udev_device_changed: |
| 1908 | * @self: a #FuPlugin |
| 1909 | * @device: a #FuUdevDevice |
| 1910 | * @error: a #GError or NULL |
| 1911 | * |
| 1912 | * Call the udev_device_changed routine for the plugin |
| 1913 | * |
| 1914 | * Returns: #TRUE for success, #FALSE for failure |
| 1915 | * |
| 1916 | * Since: 1.0.2 |
| 1917 | **/ |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 1918 | gboolean |
| 1919 | fu_plugin_runner_udev_device_changed (FuPlugin *self, FuUdevDevice *device, GError **error) |
| 1920 | { |
| 1921 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 1922 | FuPluginUdevDeviceAddedFunc func = NULL; |
| 1923 | g_autoptr(GError) error_local = NULL; |
| 1924 | |
| 1925 | /* not enabled */ |
| 1926 | if (!priv->enabled) |
| 1927 | return TRUE; |
| 1928 | |
| 1929 | /* no object loaded */ |
| 1930 | if (priv->module == NULL) |
| 1931 | return TRUE; |
| 1932 | |
| 1933 | /* optional */ |
| 1934 | g_module_symbol (priv->module, "fu_plugin_udev_device_changed", (gpointer *) &func); |
Mario Limonciello | 096e3cf | 2020-04-28 15:01:33 -0500 | [diff] [blame] | 1935 | if (func == NULL) { |
| 1936 | if (priv->device_gtype != G_TYPE_INVALID || |
| 1937 | fu_device_get_specialized_gtype (FU_DEVICE (device)) != G_TYPE_INVALID) { |
| 1938 | if (!fu_plugin_udev_device_changed (self, device, error)) |
| 1939 | return FALSE; |
| 1940 | } |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 1941 | return TRUE; |
Mario Limonciello | 096e3cf | 2020-04-28 15:01:33 -0500 | [diff] [blame] | 1942 | } |
Richard Hughes | 5e952ce | 2019-08-26 11:09:46 +0100 | [diff] [blame] | 1943 | g_debug ("performing udev_device_changed() on %s", priv->name); |
| 1944 | if (!func (self, device, &error_local)) { |
| 1945 | if (error_local == NULL) { |
| 1946 | g_critical ("unset error in plugin %s for udev_device_changed()", |
| 1947 | priv->name); |
| 1948 | g_set_error_literal (&error_local, |
| 1949 | FWUPD_ERROR, |
| 1950 | FWUPD_ERROR_INTERNAL, |
| 1951 | "unspecified error"); |
| 1952 | } |
| 1953 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 1954 | "failed to change device on %s: ", |
| 1955 | priv->name); |
| 1956 | return FALSE; |
| 1957 | } |
| 1958 | return TRUE; |
| 1959 | } |
| 1960 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1961 | /** |
Richard Hughes | 6a07870 | 2020-05-09 20:36:33 +0100 | [diff] [blame] | 1962 | * fu_plugin_runner_device_added: |
| 1963 | * @self: a #FuPlugin |
| 1964 | * @device: a #FuDevice |
| 1965 | * |
| 1966 | * Call the device_added routine for the plugin |
| 1967 | * |
| 1968 | * Since: 1.5.0 |
| 1969 | **/ |
| 1970 | void |
| 1971 | fu_plugin_runner_device_added (FuPlugin *self, FuDevice *device) |
| 1972 | { |
| 1973 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 1974 | FuPluginDeviceRegisterFunc func = NULL; |
| 1975 | |
| 1976 | /* not enabled */ |
| 1977 | if (!priv->enabled) |
| 1978 | return; |
| 1979 | if (priv->module == NULL) |
| 1980 | return; |
| 1981 | |
| 1982 | /* optional */ |
| 1983 | g_module_symbol (priv->module, "fu_plugin_device_added", (gpointer *) &func); |
| 1984 | if (func == NULL) |
| 1985 | return; |
| 1986 | g_debug ("performing fu_plugin_device_added() on %s", priv->name); |
| 1987 | func (self, device); |
| 1988 | } |
| 1989 | |
| 1990 | /** |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 1991 | * fu_plugin_runner_device_removed: |
| 1992 | * @self: a #FuPlugin |
| 1993 | * @device: a #FuDevice |
| 1994 | * |
| 1995 | * Call the device_removed routine for the plugin |
| 1996 | * |
| 1997 | * Since: 1.1.2 |
| 1998 | **/ |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 1999 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2000 | fu_plugin_runner_device_removed (FuPlugin *self, FuDevice *device) |
Mario Limonciello | e260ead | 2018-09-01 09:19:24 -0500 | [diff] [blame] | 2001 | { |
| 2002 | g_autoptr(GError) error_local= NULL; |
| 2003 | |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2004 | if (!fu_plugin_runner_device_generic (self, device, |
Mario Limonciello | e260ead | 2018-09-01 09:19:24 -0500 | [diff] [blame] | 2005 | "fu_plugin_device_removed", |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 2006 | NULL, |
Mario Limonciello | e260ead | 2018-09-01 09:19:24 -0500 | [diff] [blame] | 2007 | &error_local)) |
| 2008 | g_warning ("%s", error_local->message); |
| 2009 | } |
| 2010 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2011 | /** |
| 2012 | * fu_plugin_runner_device_register: |
| 2013 | * @self: a #FuPlugin |
| 2014 | * @device: a #FuDevice |
| 2015 | * |
| 2016 | * Call the device_registered routine for the plugin |
| 2017 | * |
| 2018 | * Since: 0.9.7 |
| 2019 | **/ |
Mario Limonciello | e260ead | 2018-09-01 09:19:24 -0500 | [diff] [blame] | 2020 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2021 | fu_plugin_runner_device_register (FuPlugin *self, FuDevice *device) |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 2022 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2023 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 2024 | FuPluginDeviceRegisterFunc func = NULL; |
| 2025 | |
| 2026 | /* not enabled */ |
| 2027 | if (!priv->enabled) |
| 2028 | return; |
Richard Hughes | 3483410 | 2017-11-21 21:55:00 +0000 | [diff] [blame] | 2029 | if (priv->module == NULL) |
| 2030 | return; |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 2031 | |
Mario Limonciello | 4910b24 | 2018-06-22 15:04:21 -0500 | [diff] [blame] | 2032 | /* don't notify plugins on their own devices */ |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2033 | if (g_strcmp0 (fu_device_get_plugin (device), fu_plugin_get_name (self)) == 0) |
Mario Limonciello | 4910b24 | 2018-06-22 15:04:21 -0500 | [diff] [blame] | 2034 | return; |
| 2035 | |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 2036 | /* optional */ |
| 2037 | g_module_symbol (priv->module, "fu_plugin_device_registered", (gpointer *) &func); |
| 2038 | if (func != NULL) { |
Richard Hughes | 1bf7ff9 | 2018-08-24 20:21:35 +0100 | [diff] [blame] | 2039 | g_debug ("performing fu_plugin_device_registered() on %s", priv->name); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2040 | func (self, device); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 2041 | } |
| 2042 | } |
| 2043 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2044 | /** |
Richard Hughes | 0f66a02 | 2020-02-19 18:54:38 +0000 | [diff] [blame] | 2045 | * fu_plugin_runner_device_created: |
| 2046 | * @self: a #FuPlugin |
| 2047 | * @device: a #FuDevice |
| 2048 | * @error: a #GError or NULL |
| 2049 | * |
| 2050 | * Call the device_created routine for the plugin |
| 2051 | * |
| 2052 | * Returns: #TRUE for success, #FALSE for failure |
| 2053 | * |
Mario Limonciello | 96117d1 | 2020-02-28 10:17:56 -0600 | [diff] [blame] | 2054 | * Since: 1.4.0 |
Richard Hughes | 0f66a02 | 2020-02-19 18:54:38 +0000 | [diff] [blame] | 2055 | **/ |
| 2056 | gboolean |
| 2057 | fu_plugin_runner_device_created (FuPlugin *self, FuDevice *device, GError **error) |
| 2058 | { |
| 2059 | FuPluginPrivate *priv = GET_PRIVATE (self); |
| 2060 | FuPluginDeviceFunc func = NULL; |
| 2061 | |
| 2062 | /* not enabled */ |
| 2063 | if (!priv->enabled) |
| 2064 | return TRUE; |
| 2065 | if (priv->module == NULL) |
| 2066 | return TRUE; |
| 2067 | |
| 2068 | /* optional */ |
| 2069 | g_module_symbol (priv->module, "fu_plugin_device_created", (gpointer *) &func); |
| 2070 | if (func == NULL) |
| 2071 | return TRUE; |
| 2072 | g_debug ("performing fu_plugin_device_created() on %s", priv->name); |
| 2073 | return func (self, device, error); |
| 2074 | } |
| 2075 | |
| 2076 | /** |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2077 | * fu_plugin_runner_verify: |
| 2078 | * @self: a #FuPlugin |
| 2079 | * @device: a #FuDevice |
| 2080 | * @flags: #FuPluginVerifyFlags |
| 2081 | * @error: A #GError or NULL |
| 2082 | * |
| 2083 | * Call into the plugin's verify routine |
| 2084 | * |
| 2085 | * Returns: #TRUE for success, #FALSE for failure |
| 2086 | * |
| 2087 | * Since: 0.8.0 |
| 2088 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2089 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2090 | fu_plugin_runner_verify (FuPlugin *self, |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2091 | FuDevice *device, |
| 2092 | FuPluginVerifyFlags flags, |
| 2093 | GError **error) |
| 2094 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2095 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 2096 | FuPluginVerifyFunc func = NULL; |
Richard Hughes | ababbb7 | 2017-06-15 20:18:36 +0100 | [diff] [blame] | 2097 | GPtrArray *checksums; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2098 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2099 | |
| 2100 | /* not enabled */ |
| 2101 | if (!priv->enabled) |
| 2102 | return TRUE; |
| 2103 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 2104 | /* no object loaded */ |
| 2105 | if (priv->module == NULL) |
| 2106 | return TRUE; |
| 2107 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2108 | /* optional */ |
| 2109 | g_module_symbol (priv->module, "fu_plugin_verify", (gpointer *) &func); |
Richard Hughes | 7f67721 | 2019-10-05 16:19:40 +0100 | [diff] [blame] | 2110 | if (func == NULL) { |
Richard Hughes | 7f67721 | 2019-10-05 16:19:40 +0100 | [diff] [blame] | 2111 | return fu_plugin_device_read_firmware (self, device, error); |
| 2112 | } |
Richard Hughes | 1812fc7 | 2018-12-14 11:37:54 +0000 | [diff] [blame] | 2113 | |
| 2114 | /* clear any existing verification checksums */ |
| 2115 | checksums = fu_device_get_checksums (device); |
| 2116 | g_ptr_array_set_size (checksums, 0); |
| 2117 | |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 2118 | /* run additional detach */ |
| 2119 | if (!fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 42f33df | 2019-10-05 20:52:33 +0100 | [diff] [blame] | 2120 | "fu_plugin_update_detach", |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 2121 | fu_plugin_device_detach, |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 2122 | error)) |
| 2123 | return FALSE; |
| 2124 | |
Richard Hughes | 1812fc7 | 2018-12-14 11:37:54 +0000 | [diff] [blame] | 2125 | /* run vfunc */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2126 | g_debug ("performing verify() on %s", priv->name); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2127 | if (!func (self, device, flags, &error_local)) { |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 2128 | g_autoptr(GError) error_attach = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2129 | if (error_local == NULL) { |
| 2130 | g_critical ("unset error in plugin %s for verify()", |
| 2131 | priv->name); |
| 2132 | g_set_error_literal (&error_local, |
| 2133 | FWUPD_ERROR, |
| 2134 | FWUPD_ERROR_INTERNAL, |
| 2135 | "unspecified error"); |
| 2136 | } |
| 2137 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 2138 | "failed to verify using %s: ", |
| 2139 | priv->name); |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 2140 | /* make the device "work" again, but don't prefix the error */ |
| 2141 | if (!fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 42f33df | 2019-10-05 20:52:33 +0100 | [diff] [blame] | 2142 | "fu_plugin_update_attach", |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 2143 | fu_plugin_device_attach, |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 2144 | &error_attach)) { |
| 2145 | g_warning ("failed to attach whilst aborting verify(): %s", |
| 2146 | error_attach->message); |
| 2147 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 2148 | return FALSE; |
| 2149 | } |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 2150 | |
| 2151 | /* run optional attach */ |
| 2152 | if (!fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 42f33df | 2019-10-05 20:52:33 +0100 | [diff] [blame] | 2153 | "fu_plugin_update_attach", |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 2154 | fu_plugin_device_attach, |
Richard Hughes | c9223be | 2019-03-18 08:46:42 +0000 | [diff] [blame] | 2155 | error)) |
| 2156 | return FALSE; |
| 2157 | |
| 2158 | /* success */ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 2159 | return TRUE; |
| 2160 | } |
| 2161 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2162 | /** |
| 2163 | * fu_plugin_runner_activate: |
| 2164 | * @self: a #FuPlugin |
| 2165 | * @device: a #FuDevice |
| 2166 | * @error: A #GError or NULL |
| 2167 | * |
| 2168 | * Call into the plugin's activate routine |
| 2169 | * |
| 2170 | * Returns: #TRUE for success, #FALSE for failure |
| 2171 | * |
| 2172 | * Since: 1.2.6 |
| 2173 | **/ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 2174 | gboolean |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 2175 | fu_plugin_runner_activate (FuPlugin *self, FuDevice *device, GError **error) |
| 2176 | { |
| 2177 | guint64 flags; |
| 2178 | |
| 2179 | /* final check */ |
| 2180 | flags = fu_device_get_flags (device); |
| 2181 | if ((flags & FWUPD_DEVICE_FLAG_NEEDS_ACTIVATION) == 0) { |
| 2182 | g_set_error (error, |
| 2183 | FWUPD_ERROR, |
| 2184 | FWUPD_ERROR_NOT_SUPPORTED, |
| 2185 | "Device %s does not need activation", |
| 2186 | fu_device_get_id (device)); |
| 2187 | return FALSE; |
| 2188 | } |
| 2189 | |
| 2190 | /* run vfunc */ |
| 2191 | if (!fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 2192 | "fu_plugin_activate", |
| 2193 | fu_plugin_device_activate, |
| 2194 | error)) |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 2195 | return FALSE; |
| 2196 | |
| 2197 | /* update with correct flags */ |
| 2198 | fu_device_remove_flag (device, FWUPD_DEVICE_FLAG_NEEDS_ACTIVATION); |
| 2199 | fu_device_set_modified (device, (guint64) g_get_real_time () / G_USEC_PER_SEC); |
| 2200 | return TRUE; |
| 2201 | } |
| 2202 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2203 | /** |
| 2204 | * fu_plugin_runner_unlock: |
| 2205 | * @self: a #FuPlugin |
| 2206 | * @device: a #FuDevice |
| 2207 | * @error: A #GError or NULL |
| 2208 | * |
| 2209 | * Call into the plugin's unlock routine |
| 2210 | * |
| 2211 | * Returns: #TRUE for success, #FALSE for failure |
| 2212 | * |
| 2213 | * Since: 0.8.0 |
| 2214 | **/ |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 2215 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2216 | fu_plugin_runner_unlock (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 2217 | { |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2218 | guint64 flags; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2219 | |
| 2220 | /* final check */ |
| 2221 | flags = fu_device_get_flags (device); |
| 2222 | if ((flags & FWUPD_DEVICE_FLAG_LOCKED) == 0) { |
| 2223 | g_set_error (error, |
| 2224 | FWUPD_ERROR, |
| 2225 | FWUPD_ERROR_NOT_SUPPORTED, |
| 2226 | "Device %s is not locked", |
| 2227 | fu_device_get_id (device)); |
| 2228 | return FALSE; |
| 2229 | } |
| 2230 | |
Richard Hughes | 9c4b531 | 2017-11-14 11:34:53 +0000 | [diff] [blame] | 2231 | /* run vfunc */ |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2232 | if (!fu_plugin_runner_device_generic (self, device, |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 2233 | "fu_plugin_unlock", |
| 2234 | NULL, |
| 2235 | error)) |
Richard Hughes | 9c4b531 | 2017-11-14 11:34:53 +0000 | [diff] [blame] | 2236 | return FALSE; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2237 | |
| 2238 | /* update with correct flags */ |
| 2239 | flags = fu_device_get_flags (device); |
| 2240 | fu_device_set_flags (device, flags &= ~FWUPD_DEVICE_FLAG_LOCKED); |
| 2241 | fu_device_set_modified (device, (guint64) g_get_real_time () / G_USEC_PER_SEC); |
| 2242 | return TRUE; |
| 2243 | } |
| 2244 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2245 | /** |
| 2246 | * fu_plugin_runner_update: |
| 2247 | * @self: a #FuPlugin |
| 2248 | * @device: a #FuDevice |
| 2249 | * @blob_fw: A #GBytes |
| 2250 | * @flags: A #FwupdInstallFlags |
| 2251 | * @error: A #GError or NULL |
| 2252 | * |
| 2253 | * Call into the plugin's update routine |
| 2254 | * |
| 2255 | * Returns: #TRUE for success, #FALSE for failure |
| 2256 | * |
| 2257 | * Since: 0.8.0 |
| 2258 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2259 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2260 | fu_plugin_runner_update (FuPlugin *self, |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 2261 | FuDevice *device, |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 2262 | GBytes *blob_fw, |
| 2263 | FwupdInstallFlags flags, |
| 2264 | GError **error) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2265 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2266 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 2267 | FuPluginUpdateFunc update_func; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2268 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2269 | |
| 2270 | /* not enabled */ |
Richard Hughes | 41c1548 | 2018-02-01 22:07:21 +0000 | [diff] [blame] | 2271 | if (!priv->enabled) { |
| 2272 | g_debug ("plugin not enabled, skipping"); |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 2273 | return TRUE; |
Richard Hughes | 41c1548 | 2018-02-01 22:07:21 +0000 | [diff] [blame] | 2274 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 2275 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 2276 | /* no object loaded */ |
Richard Hughes | 41c1548 | 2018-02-01 22:07:21 +0000 | [diff] [blame] | 2277 | if (priv->module == NULL) { |
| 2278 | g_debug ("module not enabled, skipping"); |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 2279 | return TRUE; |
Richard Hughes | 41c1548 | 2018-02-01 22:07:21 +0000 | [diff] [blame] | 2280 | } |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 2281 | |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 2282 | /* optional */ |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 2283 | g_module_symbol (priv->module, "fu_plugin_update", (gpointer *) &update_func); |
| 2284 | if (update_func == NULL) { |
Richard Hughes | 4b30380 | 2019-10-04 13:22:51 +0100 | [diff] [blame] | 2285 | g_debug ("running superclassed write_firmware() on %s", priv->name); |
| 2286 | return fu_plugin_device_write_firmware (self, device, blob_fw, flags, error); |
Richard Hughes | a785a1c | 2017-08-25 16:00:58 +0100 | [diff] [blame] | 2287 | } |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 2288 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2289 | /* online */ |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2290 | if (!update_func (self, device, blob_fw, flags, &error_local)) { |
| 2291 | if (error_local == NULL) { |
| 2292 | g_critical ("unset error in plugin %s for update()", |
| 2293 | priv->name); |
| 2294 | g_set_error_literal (&error_local, |
Richard Hughes | 3c8ada3 | 2018-10-12 10:08:58 +0100 | [diff] [blame] | 2295 | FWUPD_ERROR, |
| 2296 | FWUPD_ERROR_INTERNAL, |
| 2297 | "unspecified error"); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2298 | return FALSE; |
Richard Hughes | 3c8ada3 | 2018-10-12 10:08:58 +0100 | [diff] [blame] | 2299 | } |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2300 | fu_device_set_update_error (device, error_local->message); |
| 2301 | g_propagate_error (error, g_steal_pointer (&error_local)); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2302 | return FALSE; |
| 2303 | } |
| 2304 | |
Richard Hughes | f556d37 | 2017-06-15 19:49:18 +0100 | [diff] [blame] | 2305 | /* no longer valid */ |
Richard Hughes | f803964 | 2019-01-16 12:22:22 +0000 | [diff] [blame] | 2306 | if (!fu_device_has_flag (device, FWUPD_DEVICE_FLAG_NEEDS_REBOOT) && |
| 2307 | !fu_device_has_flag (device, FWUPD_DEVICE_FLAG_NEEDS_SHUTDOWN)) { |
Richard Hughes | 0843516 | 2018-12-12 10:34:16 +0000 | [diff] [blame] | 2308 | GPtrArray *checksums = fu_device_get_checksums (device); |
| 2309 | g_ptr_array_set_size (checksums, 0); |
| 2310 | } |
Richard Hughes | f556d37 | 2017-06-15 19:49:18 +0100 | [diff] [blame] | 2311 | |
Richard Hughes | 019a1bc | 2019-11-26 10:19:33 +0000 | [diff] [blame] | 2312 | /* success */ |
Richard Hughes | d090514 | 2016-03-13 09:46:49 +0000 | [diff] [blame] | 2313 | return TRUE; |
| 2314 | } |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2315 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2316 | /** |
| 2317 | * fu_plugin_runner_clear_results: |
| 2318 | * @self: a #FuPlugin |
| 2319 | * @device: a #FuDevice |
| 2320 | * @error: A #GError or NULL |
| 2321 | * |
| 2322 | * Call into the plugin's clear results routine |
| 2323 | * |
| 2324 | * Returns: #TRUE for success, #FALSE for failure |
| 2325 | * |
| 2326 | * Since: 0.8.0 |
| 2327 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2328 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2329 | fu_plugin_runner_clear_results (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2330 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2331 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 2332 | FuPluginDeviceFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2333 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2334 | |
| 2335 | /* not enabled */ |
| 2336 | if (!priv->enabled) |
| 2337 | return TRUE; |
| 2338 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 2339 | /* no object loaded */ |
| 2340 | if (priv->module == NULL) |
| 2341 | return TRUE; |
| 2342 | |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 2343 | /* optional */ |
Richard Hughes | cd64490 | 2019-11-01 12:35:17 +0000 | [diff] [blame] | 2344 | g_module_symbol (priv->module, "fu_plugin_clear_results", (gpointer *) &func); |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 2345 | if (func == NULL) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2346 | return TRUE; |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 2347 | g_debug ("performing clear_result() on %s", priv->name); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2348 | if (!func (self, device, &error_local)) { |
| 2349 | if (error_local == NULL) { |
| 2350 | g_critical ("unset error in plugin %s for clear_result()", |
| 2351 | priv->name); |
| 2352 | g_set_error_literal (&error_local, |
| 2353 | FWUPD_ERROR, |
| 2354 | FWUPD_ERROR_INTERNAL, |
| 2355 | "unspecified error"); |
| 2356 | } |
| 2357 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 2358 | "failed to clear_result using %s: ", |
| 2359 | priv->name); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2360 | return FALSE; |
| 2361 | } |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 2362 | return TRUE; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2363 | } |
| 2364 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2365 | /** |
| 2366 | * fu_plugin_runner_get_results: |
| 2367 | * @self: a #FuPlugin |
| 2368 | * @device: a #FuDevice |
| 2369 | * @error: A #GError or NULL |
| 2370 | * |
| 2371 | * Call into the plugin's get results routine |
| 2372 | * |
| 2373 | * Returns: #TRUE for success, #FALSE for failure |
| 2374 | * |
| 2375 | * Since: 0.8.0 |
| 2376 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2377 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2378 | fu_plugin_runner_get_results (FuPlugin *self, FuDevice *device, GError **error) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2379 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2380 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | 7b8b202 | 2016-12-12 16:15:03 +0000 | [diff] [blame] | 2381 | FuPluginDeviceFunc func = NULL; |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2382 | g_autoptr(GError) error_local = NULL; |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2383 | |
| 2384 | /* not enabled */ |
| 2385 | if (!priv->enabled) |
| 2386 | return TRUE; |
| 2387 | |
Richard Hughes | 639da47 | 2018-01-06 22:35:04 +0000 | [diff] [blame] | 2388 | /* no object loaded */ |
| 2389 | if (priv->module == NULL) |
| 2390 | return TRUE; |
| 2391 | |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 2392 | /* optional */ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2393 | g_module_symbol (priv->module, "fu_plugin_get_results", (gpointer *) &func); |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 2394 | if (func == NULL) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2395 | return TRUE; |
Richard Hughes | 65e44ca | 2018-01-30 17:26:30 +0000 | [diff] [blame] | 2396 | g_debug ("performing get_results() on %s", priv->name); |
Richard Hughes | cd2fb3e | 2018-11-29 19:58:09 +0000 | [diff] [blame] | 2397 | if (!func (self, device, &error_local)) { |
| 2398 | if (error_local == NULL) { |
| 2399 | g_critical ("unset error in plugin %s for get_results()", |
| 2400 | priv->name); |
| 2401 | g_set_error_literal (&error_local, |
| 2402 | FWUPD_ERROR, |
| 2403 | FWUPD_ERROR_INTERNAL, |
| 2404 | "unspecified error"); |
| 2405 | } |
| 2406 | g_propagate_prefixed_error (error, g_steal_pointer (&error_local), |
| 2407 | "failed to get_results using %s: ", |
| 2408 | priv->name); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2409 | return FALSE; |
| 2410 | } |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2411 | return TRUE; |
| 2412 | } |
| 2413 | |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2414 | /** |
| 2415 | * fu_plugin_get_order: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2416 | * @self: a #FuPlugin |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2417 | * |
| 2418 | * Gets the plugin order, where higher numbers are run after lower |
| 2419 | * numbers. |
| 2420 | * |
| 2421 | * Returns: the integer value |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2422 | * |
| 2423 | * Since: 1.0.0 |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2424 | **/ |
| 2425 | guint |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2426 | fu_plugin_get_order (FuPlugin *self) |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2427 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2428 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2429 | return priv->order; |
| 2430 | } |
| 2431 | |
| 2432 | /** |
| 2433 | * fu_plugin_set_order: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2434 | * @self: a #FuPlugin |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2435 | * @order: a integer value |
| 2436 | * |
| 2437 | * Sets the plugin order, where higher numbers are run after lower |
| 2438 | * numbers. |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2439 | * |
| 2440 | * Since: 1.0.0 |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2441 | **/ |
| 2442 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2443 | fu_plugin_set_order (FuPlugin *self, guint order) |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2444 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2445 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2446 | priv->order = order; |
| 2447 | } |
| 2448 | |
| 2449 | /** |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2450 | * fu_plugin_get_priority: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2451 | * @self: a #FuPlugin |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2452 | * |
| 2453 | * Gets the plugin priority, where higher numbers are better. |
| 2454 | * |
| 2455 | * Returns: the integer value |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2456 | * |
| 2457 | * Since: 1.1.1 |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2458 | **/ |
| 2459 | guint |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2460 | fu_plugin_get_priority (FuPlugin *self) |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2461 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2462 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2463 | return priv->priority; |
| 2464 | } |
| 2465 | |
| 2466 | /** |
| 2467 | * fu_plugin_set_priority: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2468 | * @self: a #FuPlugin |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2469 | * @priority: a integer value |
| 2470 | * |
| 2471 | * Sets the plugin priority, where higher numbers are better. |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2472 | * |
| 2473 | * Since: 1.0.0 |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2474 | **/ |
| 2475 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2476 | fu_plugin_set_priority (FuPlugin *self, guint priority) |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2477 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2478 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 81c427c | 2018-08-06 15:20:17 +0100 | [diff] [blame] | 2479 | priv->priority = priority; |
| 2480 | } |
| 2481 | |
| 2482 | /** |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2483 | * fu_plugin_add_rule: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2484 | * @self: a #FuPlugin |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2485 | * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 2486 | * @name: a plugin name, e.g. `upower` |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2487 | * |
| 2488 | * If the plugin name is found, the rule will be used to sort the plugin list, |
| 2489 | * for example the plugin specified by @name will be ordered after this plugin |
| 2490 | * when %FU_PLUGIN_RULE_RUN_AFTER is used. |
| 2491 | * |
| 2492 | * NOTE: The depsolver is iterative and may not solve overly-complicated rules; |
| 2493 | * If depsolving fails then fwupd will not start. |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2494 | * |
| 2495 | * Since: 1.0.0 |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2496 | **/ |
| 2497 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2498 | fu_plugin_add_rule (FuPlugin *self, FuPluginRule rule, const gchar *name) |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2499 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2500 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2501 | g_ptr_array_add (priv->rules[rule], g_strdup (name)); |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 2502 | g_signal_emit (self, signals[SIGNAL_RULES_CHANGED], 0); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2503 | } |
| 2504 | |
| 2505 | /** |
| 2506 | * fu_plugin_get_rules: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2507 | * @self: a #FuPlugin |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2508 | * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS |
| 2509 | * |
| 2510 | * Gets the plugin IDs that should be run after this plugin. |
| 2511 | * |
| 2512 | * Returns: (element-type utf8) (transfer none): the list of plugin names, e.g. ['appstream'] |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2513 | * |
| 2514 | * Since: 1.0.0 |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2515 | **/ |
| 2516 | GPtrArray * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2517 | fu_plugin_get_rules (FuPlugin *self, FuPluginRule rule) |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2518 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2519 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | dad3597 | 2019-12-06 11:00:25 +0000 | [diff] [blame] | 2520 | g_return_val_if_fail (rule < FU_PLUGIN_RULE_LAST, NULL); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2521 | return priv->rules[rule]; |
| 2522 | } |
| 2523 | |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2524 | /** |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 2525 | * fu_plugin_has_rule: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2526 | * @self: a #FuPlugin |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 2527 | * @rule: a #FuPluginRule, e.g. %FU_PLUGIN_RULE_CONFLICTS |
| 2528 | * @name: a plugin name, e.g. `upower` |
| 2529 | * |
Richard Hughes | 87fb9ff | 2018-06-28 12:55:59 +0100 | [diff] [blame] | 2530 | * Gets the plugin IDs that should be run after this plugin. |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 2531 | * |
| 2532 | * Returns: %TRUE if the name exists for the specific rule |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2533 | * |
| 2534 | * Since: 1.0.0 |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 2535 | **/ |
| 2536 | gboolean |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2537 | fu_plugin_has_rule (FuPlugin *self, FuPluginRule rule, const gchar *name) |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 2538 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2539 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 5f3a56b | 2018-06-28 12:13:59 +0100 | [diff] [blame] | 2540 | for (guint i = 0; i < priv->rules[rule]->len; i++) { |
| 2541 | const gchar *tmp = g_ptr_array_index (priv->rules[rule], i); |
| 2542 | if (g_strcmp0 (tmp, name) == 0) |
| 2543 | return TRUE; |
| 2544 | } |
| 2545 | return FALSE; |
| 2546 | } |
| 2547 | |
| 2548 | /** |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2549 | * fu_plugin_add_report_metadata: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2550 | * @self: a #FuPlugin |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2551 | * @key: a string, e.g. `FwupdateVersion` |
| 2552 | * @value: a string, e.g. `10` |
| 2553 | * |
| 2554 | * Sets any additional metadata to be included in the firmware report to aid |
| 2555 | * debugging problems. |
| 2556 | * |
| 2557 | * Any data included here will be sent to the metadata server after user |
| 2558 | * confirmation. |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2559 | * |
| 2560 | * Since: 1.0.4 |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2561 | **/ |
| 2562 | void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2563 | 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] | 2564 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2565 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2566 | g_hash_table_insert (priv->report_metadata, g_strdup (key), g_strdup (value)); |
| 2567 | } |
| 2568 | |
| 2569 | /** |
| 2570 | * fu_plugin_get_report_metadata: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2571 | * @self: a #FuPlugin |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2572 | * |
| 2573 | * Returns the list of additional metadata to be added when filing a report. |
| 2574 | * |
| 2575 | * Returns: (transfer none): the map of report metadata |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2576 | * |
| 2577 | * Since: 1.0.4 |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2578 | **/ |
| 2579 | GHashTable * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2580 | fu_plugin_get_report_metadata (FuPlugin *self) |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2581 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2582 | FuPluginPrivate *priv = fu_plugin_get_instance_private (self); |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2583 | return priv->report_metadata; |
| 2584 | } |
| 2585 | |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 2586 | /** |
| 2587 | * fu_plugin_get_config_value: |
Richard Hughes | 2c0635a | 2018-09-04 14:52:46 +0100 | [diff] [blame] | 2588 | * @self: a #FuPlugin |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 2589 | * @key: A settings key |
| 2590 | * |
| 2591 | * Return the value of a key if it's been configured |
| 2592 | * |
| 2593 | * Since: 1.0.6 |
| 2594 | **/ |
| 2595 | gchar * |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2596 | fu_plugin_get_config_value (FuPlugin *self, const gchar *key) |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 2597 | { |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 2598 | g_autofree gchar *conf_dir = NULL; |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 2599 | g_autofree gchar *conf_file = NULL; |
| 2600 | g_autofree gchar *conf_path = NULL; |
| 2601 | g_autoptr(GKeyFile) keyfile = NULL; |
| 2602 | const gchar *plugin_name; |
| 2603 | |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 2604 | conf_dir = fu_common_get_path (FU_PATH_KIND_SYSCONFDIR_PKG); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2605 | plugin_name = fu_plugin_get_name (self); |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 2606 | conf_file = g_strdup_printf ("%s.conf", plugin_name); |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 2607 | conf_path = g_build_filename (conf_dir, conf_file, NULL); |
Mario Limonciello | 963dc42 | 2018-02-27 14:26:58 -0600 | [diff] [blame] | 2608 | if (!g_file_test (conf_path, G_FILE_TEST_IS_REGULAR)) |
| 2609 | return NULL; |
| 2610 | keyfile = g_key_file_new (); |
| 2611 | if (!g_key_file_load_from_file (keyfile, conf_path, |
| 2612 | G_KEY_FILE_NONE, NULL)) |
| 2613 | return NULL; |
| 2614 | return g_key_file_get_string (keyfile, plugin_name, key, NULL); |
| 2615 | } |
| 2616 | |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 2617 | /** |
Richard Hughes | 334ba79 | 2020-02-19 20:44:56 +0000 | [diff] [blame] | 2618 | * fu_plugin_get_config_value_boolean: |
| 2619 | * @self: a #FuPlugin |
| 2620 | * @key: A settings key |
| 2621 | * |
| 2622 | * Return the boolean value of a key if it's been configured |
| 2623 | * |
| 2624 | * Returns: %TRUE if the value is `true` (case insensitive), %FALSE otherwise |
| 2625 | * |
Mario Limonciello | 96117d1 | 2020-02-28 10:17:56 -0600 | [diff] [blame] | 2626 | * Since: 1.4.0 |
Richard Hughes | 334ba79 | 2020-02-19 20:44:56 +0000 | [diff] [blame] | 2627 | **/ |
| 2628 | gboolean |
| 2629 | fu_plugin_get_config_value_boolean (FuPlugin *self, const gchar *key) |
| 2630 | { |
| 2631 | g_autofree gchar *tmp = fu_plugin_get_config_value (self, key); |
| 2632 | if (tmp == NULL) |
| 2633 | return FALSE; |
Richard Hughes | 5337a43 | 2020-02-21 12:04:32 +0000 | [diff] [blame] | 2634 | return g_ascii_strcasecmp (tmp, "true") == 0; |
Richard Hughes | 334ba79 | 2020-02-19 20:44:56 +0000 | [diff] [blame] | 2635 | } |
| 2636 | |
| 2637 | /** |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 2638 | * fu_plugin_name_compare: |
| 2639 | * @plugin1: first #FuPlugin to compare. |
| 2640 | * @plugin2: second #FuPlugin to compare. |
| 2641 | * |
| 2642 | * Compares two plugins by their names. |
| 2643 | * |
| 2644 | * 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] | 2645 | * |
| 2646 | * Since: 1.0.8 |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 2647 | **/ |
| 2648 | gint |
| 2649 | fu_plugin_name_compare (FuPlugin *plugin1, FuPlugin *plugin2) |
| 2650 | { |
| 2651 | FuPluginPrivate *priv1 = fu_plugin_get_instance_private (plugin1); |
| 2652 | FuPluginPrivate *priv2 = fu_plugin_get_instance_private (plugin2); |
| 2653 | return g_strcmp0 (priv1->name, priv2->name); |
| 2654 | } |
| 2655 | |
| 2656 | /** |
| 2657 | * fu_plugin_order_compare: |
| 2658 | * @plugin1: first #FuPlugin to compare. |
| 2659 | * @plugin2: second #FuPlugin to compare. |
| 2660 | * |
| 2661 | * Compares two plugins by their depsolved order. |
| 2662 | * |
| 2663 | * 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] | 2664 | * |
| 2665 | * Since: 1.0.8 |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 2666 | **/ |
| 2667 | gint |
| 2668 | fu_plugin_order_compare (FuPlugin *plugin1, FuPlugin *plugin2) |
| 2669 | { |
| 2670 | FuPluginPrivate *priv1 = fu_plugin_get_instance_private (plugin1); |
| 2671 | FuPluginPrivate *priv2 = fu_plugin_get_instance_private (plugin2); |
| 2672 | if (priv1->order < priv2->order) |
| 2673 | return -1; |
| 2674 | if (priv1->order > priv2->order) |
| 2675 | return 1; |
| 2676 | return 0; |
| 2677 | } |
| 2678 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2679 | static void |
| 2680 | fu_plugin_class_init (FuPluginClass *klass) |
| 2681 | { |
| 2682 | GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 2683 | object_class->finalize = fu_plugin_finalize; |
| 2684 | signals[SIGNAL_DEVICE_ADDED] = |
| 2685 | g_signal_new ("device-added", |
| 2686 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2687 | G_STRUCT_OFFSET (FuPluginClass, device_added), |
| 2688 | NULL, NULL, g_cclosure_marshal_VOID__OBJECT, |
| 2689 | G_TYPE_NONE, 1, FU_TYPE_DEVICE); |
| 2690 | signals[SIGNAL_DEVICE_REMOVED] = |
| 2691 | g_signal_new ("device-removed", |
| 2692 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2693 | G_STRUCT_OFFSET (FuPluginClass, device_removed), |
| 2694 | NULL, NULL, g_cclosure_marshal_VOID__OBJECT, |
| 2695 | G_TYPE_NONE, 1, FU_TYPE_DEVICE); |
Richard Hughes | e1fd34d | 2017-08-24 14:19:51 +0100 | [diff] [blame] | 2696 | signals[SIGNAL_DEVICE_REGISTER] = |
| 2697 | g_signal_new ("device-register", |
| 2698 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2699 | G_STRUCT_OFFSET (FuPluginClass, device_register), |
| 2700 | NULL, NULL, g_cclosure_marshal_VOID__OBJECT, |
| 2701 | G_TYPE_NONE, 1, FU_TYPE_DEVICE); |
Richard Hughes | 362d6d7 | 2017-01-07 21:42:14 +0000 | [diff] [blame] | 2702 | signals[SIGNAL_RECOLDPLUG] = |
| 2703 | g_signal_new ("recoldplug", |
| 2704 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2705 | G_STRUCT_OFFSET (FuPluginClass, recoldplug), |
| 2706 | NULL, NULL, g_cclosure_marshal_VOID__VOID, |
| 2707 | G_TYPE_NONE, 0); |
Richard Hughes | 399859e | 2020-05-11 19:44:03 +0100 | [diff] [blame] | 2708 | signals[SIGNAL_SECURITY_CHANGED] = |
| 2709 | g_signal_new ("security-changed", |
| 2710 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2711 | G_STRUCT_OFFSET (FuPluginClass, security_changed), |
| 2712 | NULL, NULL, g_cclosure_marshal_VOID__VOID, |
| 2713 | G_TYPE_NONE, 0); |
Richard Hughes | b082903 | 2017-01-10 09:27:08 +0000 | [diff] [blame] | 2714 | signals[SIGNAL_SET_COLDPLUG_DELAY] = |
| 2715 | g_signal_new ("set-coldplug-delay", |
| 2716 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2717 | G_STRUCT_OFFSET (FuPluginClass, set_coldplug_delay), |
| 2718 | NULL, NULL, g_cclosure_marshal_VOID__UINT, |
| 2719 | G_TYPE_NONE, 1, G_TYPE_UINT); |
Richard Hughes | aabdc37 | 2018-11-14 10:11:08 +0000 | [diff] [blame] | 2720 | signals[SIGNAL_CHECK_SUPPORTED] = |
| 2721 | g_signal_new ("check-supported", |
| 2722 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2723 | G_STRUCT_OFFSET (FuPluginClass, check_supported), |
| 2724 | NULL, NULL, g_cclosure_marshal_generic, |
| 2725 | G_TYPE_BOOLEAN, 1, G_TYPE_STRING); |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 2726 | signals[SIGNAL_RULES_CHANGED] = |
| 2727 | g_signal_new ("rules-changed", |
| 2728 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2729 | G_STRUCT_OFFSET (FuPluginClass, rules_changed), |
| 2730 | NULL, NULL, g_cclosure_marshal_VOID__VOID, |
| 2731 | G_TYPE_NONE, 0); |
Richard Hughes | 95c98a9 | 2019-10-22 16:03:15 +0100 | [diff] [blame] | 2732 | signals[SIGNAL_ADD_FIRMWARE_GTYPE] = |
| 2733 | g_signal_new ("add-firmware-gtype", |
| 2734 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 2735 | G_STRUCT_OFFSET (FuPluginClass, add_firmware_gtype), |
| 2736 | NULL, NULL, g_cclosure_marshal_generic, |
| 2737 | G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_GTYPE); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2738 | } |
| 2739 | |
| 2740 | static void |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2741 | fu_plugin_init (FuPlugin *self) |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2742 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2743 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2744 | priv->enabled = TRUE; |
Richard Hughes | b106542 | 2019-08-15 16:44:34 +0100 | [diff] [blame] | 2745 | priv->udev_subsystems = g_ptr_array_new_with_free_func (g_free); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2746 | priv->devices = g_hash_table_new_full (g_str_hash, g_str_equal, |
| 2747 | g_free, (GDestroyNotify) g_object_unref); |
Richard Hughes | 161e9b5 | 2019-06-12 14:22:45 +0100 | [diff] [blame] | 2748 | g_rw_lock_init (&priv->devices_mutex); |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2749 | priv->report_metadata = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2750 | for (guint i = 0; i < FU_PLUGIN_RULE_LAST; i++) |
| 2751 | priv->rules[i] = g_ptr_array_new_with_free_func (g_free); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2752 | } |
| 2753 | |
| 2754 | static void |
| 2755 | fu_plugin_finalize (GObject *object) |
| 2756 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2757 | FuPlugin *self = FU_PLUGIN (object); |
| 2758 | FuPluginPrivate *priv = GET_PRIVATE (self); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2759 | FuPluginInitFunc func = NULL; |
| 2760 | |
| 2761 | /* optional */ |
| 2762 | if (priv->module != NULL) { |
| 2763 | g_module_symbol (priv->module, "fu_plugin_destroy", (gpointer *) &func); |
| 2764 | if (func != NULL) { |
| 2765 | g_debug ("performing destroy() on %s", priv->name); |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2766 | func (self); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2767 | } |
| 2768 | } |
| 2769 | |
Richard Hughes | 08a3799 | 2017-09-12 12:57:43 +0100 | [diff] [blame] | 2770 | for (guint i = 0; i < FU_PLUGIN_RULE_LAST; i++) |
| 2771 | g_ptr_array_unref (priv->rules[i]); |
| 2772 | |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2773 | if (priv->usb_ctx != NULL) |
| 2774 | g_object_unref (priv->usb_ctx); |
Richard Hughes | b8f8db2 | 2017-04-25 15:56:00 +0100 | [diff] [blame] | 2775 | if (priv->hwids != NULL) |
Richard Hughes | d7704d4 | 2017-08-08 20:29:09 +0100 | [diff] [blame] | 2776 | g_object_unref (priv->hwids); |
Richard Hughes | 9c028f0 | 2017-10-28 21:14:28 +0100 | [diff] [blame] | 2777 | if (priv->quirks != NULL) |
| 2778 | g_object_unref (priv->quirks); |
Richard Hughes | 9d6e0e7 | 2018-08-24 20:20:17 +0100 | [diff] [blame] | 2779 | if (priv->udev_subsystems != NULL) |
| 2780 | g_ptr_array_unref (priv->udev_subsystems); |
Richard Hughes | 49e5e05 | 2017-09-03 12:15:41 +0100 | [diff] [blame] | 2781 | if (priv->smbios != NULL) |
| 2782 | g_object_unref (priv->smbios); |
Richard Hughes | 275d3b4 | 2018-04-20 16:40:37 +0100 | [diff] [blame] | 2783 | if (priv->runtime_versions != NULL) |
| 2784 | g_hash_table_unref (priv->runtime_versions); |
Richard Hughes | 34e0dab | 2018-04-20 16:43:00 +0100 | [diff] [blame] | 2785 | if (priv->compile_versions != NULL) |
| 2786 | g_hash_table_unref (priv->compile_versions); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2787 | g_hash_table_unref (priv->devices); |
Richard Hughes | 80b79bb | 2018-01-11 21:11:06 +0000 | [diff] [blame] | 2788 | g_hash_table_unref (priv->report_metadata); |
Richard Hughes | 161e9b5 | 2019-06-12 14:22:45 +0100 | [diff] [blame] | 2789 | g_rw_lock_clear (&priv->devices_mutex); |
Richard Hughes | 8499930 | 2019-05-02 10:18:32 +0100 | [diff] [blame] | 2790 | g_free (priv->build_hash); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2791 | g_free (priv->name); |
| 2792 | g_free (priv->data); |
Mario Limonciello | 3f9a1c1 | 2018-06-06 14:06:40 -0500 | [diff] [blame] | 2793 | /* Must happen as the last step to avoid prematurely |
| 2794 | * freeing memory held by the plugin */ |
| 2795 | #ifndef RUNNING_ON_VALGRIND |
| 2796 | if (priv->module != NULL) |
| 2797 | g_module_close (priv->module); |
| 2798 | #endif |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2799 | |
| 2800 | G_OBJECT_CLASS (fu_plugin_parent_class)->finalize (object); |
| 2801 | } |
| 2802 | |
Mario Limonciello | 1a680f3 | 2019-11-25 19:44:53 -0600 | [diff] [blame] | 2803 | /** |
| 2804 | * fu_plugin_new: |
| 2805 | * |
| 2806 | * Creates a new #FuPlugin |
| 2807 | * |
| 2808 | * Since: 0.8.0 |
| 2809 | **/ |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2810 | FuPlugin * |
| 2811 | fu_plugin_new (void) |
| 2812 | { |
Richard Hughes | 1272485 | 2018-09-04 13:53:44 +0100 | [diff] [blame] | 2813 | return FU_PLUGIN (g_object_new (FU_TYPE_PLUGIN, NULL)); |
Richard Hughes | cff38bc | 2016-12-12 12:03:37 +0000 | [diff] [blame] | 2814 | } |