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