Rename the source file and private data of modular plugins

This would allow us to convert more easily to a built-in plugin in the future
and means we match the source style used in 97% of the other plugins.

No logic changes.
This commit is contained in:
Richard Hughes 2022-09-30 10:41:27 +01:00
parent fc3cfbad92
commit 1f261ba283
6 changed files with 228 additions and 214 deletions

View File

@ -948,7 +948,7 @@ fu_plugin_runner_startup(FuPlugin *self, FuProgress *progress, GError **error)
* fu_plugin_runner_init: * fu_plugin_runner_init:
* @self: a #FuPlugin * @self: a #FuPlugin
* *
* Runs the init routine for the plugin, if enabled. * Runs the constructed routine for the plugin, if enabled.
* *
* Since: 1.8.1 * Since: 1.8.1
**/ **/
@ -969,9 +969,9 @@ fu_plugin_runner_init(FuPlugin *self)
return; return;
/* optional */ /* optional */
if (vfuncs->init != NULL) { if (vfuncs->constructed != NULL) {
g_debug("init(%s)", fu_plugin_get_name(self)); g_debug("constructed(%s)", fu_plugin_get_name(self));
vfuncs->init(self); vfuncs->constructed(G_OBJECT(self));
priv->done_init = TRUE; priv->done_init = TRUE;
} }
} }
@ -2797,9 +2797,9 @@ fu_plugin_finalize(GObject *object)
g_rw_lock_clear(&priv->cache_mutex); g_rw_lock_clear(&priv->cache_mutex);
/* optional */ /* optional */
if (priv->done_init && vfuncs->destroy != NULL) { if (priv->done_init && vfuncs->finalize != NULL) {
g_debug("destroy(%s)", fu_plugin_get_name(self)); g_debug("finalize(%s)", fu_plugin_get_name(self));
vfuncs->destroy(self); vfuncs->finalize(G_OBJECT(self));
} }
for (guint i = 0; i < FU_PLUGIN_RULE_LAST; i++) { for (guint i = 0; i < FU_PLUGIN_RULE_LAST; i++) {

View File

@ -70,22 +70,22 @@ struct _FuPluginClass {
* init: * init:
* @self: A #FuPlugin * @self: A #FuPlugin
* *
* Initializes the plugin. * Initializes the modular plugin.
* Sets up any static data structures for the plugin. * Sets up any static data structures for the plugin.
* *
* Since: 1.7.2 * Since: 1.7.2
**/ **/
void (*init)(FuPlugin *self); void (*constructed)(GObject *obj);
/** /**
* destroy: * finalize:
* @self: a plugin * @self: a plugin
* *
* Destroys the plugin. * Destroys the modular plugin.
* Any allocated memory should be freed here. * Any allocated memory should be freed here.
* *
* Since: 1.7.2 * Since: 1.7.2
**/ **/
void (*destroy)(FuPlugin *self); void (*finalize)(GObject *obj);
/** /**
* startup: * startup:
* @self: a #FuPlugin * @self: a #FuPlugin

View File

@ -22,37 +22,19 @@ struct FuPluginData {
gchar *guid; /* GUID from quirks that activated this plugin */ gchar *guid; /* GUID from quirks that activated this plugin */
}; };
static void typedef FuPluginData FuFlashromPlugin;
fu_plugin_flashrom_init(FuPlugin *plugin) #define FU_FLASHROM_PLUGIN(o) fu_plugin_get_data(FU_PLUGIN(o))
{
(void)fu_plugin_alloc_data(plugin, sizeof(FuPluginData));
fu_plugin_add_rule(plugin, FU_PLUGIN_RULE_METADATA_SOURCE, "linux_lockdown");
fu_plugin_add_rule(plugin, FU_PLUGIN_RULE_CONFLICTS, "coreboot"); /* obsoleted */
fu_plugin_add_flag(plugin, FWUPD_PLUGIN_FLAG_REQUIRE_HWID);
}
static void static void
fu_plugin_flashrom_destroy(FuPlugin *plugin) fu_flashrom_plugin_to_string(FuPlugin *plugin, guint idt, GString *str)
{ {
FuPluginData *priv = fu_plugin_get_data(plugin); FuFlashromPlugin *self = FU_FLASHROM_PLUGIN(plugin);
if (priv->flashctx != NULL) if (self->guid != NULL)
flashrom_flash_release(priv->flashctx); fu_string_append(str, idt, "Guid", self->guid);
if (priv->flashprog != NULL)
flashrom_programmer_shutdown(priv->flashprog);
g_free(priv->guid);
}
static void
fu_plugin_flashrom_to_string(FuPlugin *plugin, guint idt, GString *str)
{
FuPluginData *priv = fu_plugin_get_data(plugin);
if (priv->guid != NULL)
fu_string_append(str, idt, "Guid", priv->guid);
} }
static int static int
fu_plugin_flashrom_debug_cb(enum flashrom_log_level lvl, const char *fmt, va_list args) fu_flashrom_plugin_debug_cb(enum flashrom_log_level lvl, const char *fmt, va_list args)
{ {
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-nonliteral" #pragma clang diagnostic ignored "-Wformat-nonliteral"
@ -83,7 +65,7 @@ fu_plugin_flashrom_debug_cb(enum flashrom_log_level lvl, const char *fmt, va_lis
} }
static void static void
fu_plugin_flashrom_device_set_version(FuPlugin *plugin, FuDevice *device) fu_flashrom_plugin_device_set_version(FuPlugin *plugin, FuDevice *device)
{ {
FuContext *ctx = fu_plugin_get_context(plugin); FuContext *ctx = fu_plugin_get_context(plugin);
const gchar *version; const gchar *version;
@ -114,7 +96,7 @@ fu_plugin_flashrom_device_set_version(FuPlugin *plugin, FuDevice *device)
} }
} }
static void static void
fu_plugin_flashrom_device_set_bios_info(FuPlugin *plugin, FuDevice *device) fu_flashrom_plugin_device_set_bios_info(FuPlugin *plugin, FuDevice *device)
{ {
FuContext *ctx = fu_plugin_get_context(plugin); FuContext *ctx = fu_plugin_get_context(plugin);
const guint8 *buf; const guint8 *buf;
@ -148,7 +130,7 @@ fu_plugin_flashrom_device_set_bios_info(FuPlugin *plugin, FuDevice *device)
} }
static void static void
fu_plugin_flashrom_device_set_hwids(FuPlugin *plugin, FuDevice *device) fu_flashrom_plugin_device_set_hwids(FuPlugin *plugin, FuDevice *device)
{ {
FuContext *ctx = fu_plugin_get_context(plugin); FuContext *ctx = fu_plugin_get_context(plugin);
static const gchar *hwids[] = { static const gchar *hwids[] = {
@ -171,19 +153,19 @@ fu_plugin_flashrom_device_set_hwids(FuPlugin *plugin, FuDevice *device)
} }
static FuDevice * static FuDevice *
fu_plugin_flashrom_add_device(FuPlugin *plugin, fu_flashrom_plugin_add_device(FuPlugin *plugin,
const gchar *guid, const gchar *guid,
FuIfdRegion region, FuIfdRegion region,
GError **error) GError **error)
{ {
FuContext *ctx = fu_plugin_get_context(plugin); FuContext *ctx = fu_plugin_get_context(plugin);
FuPluginData *priv = fu_plugin_get_data(plugin); FuFlashromPlugin *self = FU_FLASHROM_PLUGIN(plugin);
const gchar *dmi_vendor; const gchar *dmi_vendor;
const gchar *product = fu_context_get_hwid_value(ctx, FU_HWIDS_KEY_PRODUCT_NAME); const gchar *product = fu_context_get_hwid_value(ctx, FU_HWIDS_KEY_PRODUCT_NAME);
const gchar *vendor = fu_context_get_hwid_value(ctx, FU_HWIDS_KEY_MANUFACTURER); const gchar *vendor = fu_context_get_hwid_value(ctx, FU_HWIDS_KEY_MANUFACTURER);
const gchar *region_str = fu_ifd_region_to_string(region); const gchar *region_str = fu_ifd_region_to_string(region);
g_autofree gchar *name = g_strdup_printf("%s (%s)", product, region_str); g_autofree gchar *name = g_strdup_printf("%s (%s)", product, region_str);
g_autoptr(FuDevice) device = fu_flashrom_device_new(ctx, priv->flashctx, region); g_autoptr(FuDevice) device = fu_flashrom_device_new(ctx, self->flashctx, region);
fu_device_set_name(device, name); fu_device_set_name(device, name);
fu_device_set_vendor(device, vendor); fu_device_set_vendor(device, vendor);
@ -211,9 +193,9 @@ fu_plugin_flashrom_add_device(FuPlugin *plugin,
g_autofree gchar *vendor_id = g_strdup_printf("DMI:%s", dmi_vendor); g_autofree gchar *vendor_id = g_strdup_printf("DMI:%s", dmi_vendor);
fu_device_add_vendor_id(FU_DEVICE(device), vendor_id); fu_device_add_vendor_id(FU_DEVICE(device), vendor_id);
} }
fu_plugin_flashrom_device_set_version(plugin, device); fu_flashrom_plugin_device_set_version(plugin, device);
fu_plugin_flashrom_device_set_hwids(plugin, device); fu_flashrom_plugin_device_set_hwids(plugin, device);
fu_plugin_flashrom_device_set_bios_info(plugin, device); fu_flashrom_plugin_device_set_bios_info(plugin, device);
if (!fu_device_setup(device, error)) if (!fu_device_setup(device, error))
return NULL; return NULL;
@ -223,10 +205,10 @@ fu_plugin_flashrom_add_device(FuPlugin *plugin,
} }
static void static void
fu_plugin_flashrom_device_registered(FuPlugin *plugin, FuDevice *device) fu_flashrom_plugin_device_registered(FuPlugin *plugin, FuDevice *device)
{ {
g_autoptr(FuDevice) me_device = NULL; g_autoptr(FuDevice) me_device = NULL;
FuPluginData *priv = fu_plugin_get_data(plugin); FuFlashromPlugin *self = FU_FLASHROM_PLUGIN(plugin);
const gchar *me_region_str = fu_ifd_region_to_string(FU_IFD_REGION_ME); const gchar *me_region_str = fu_ifd_region_to_string(FU_IFD_REGION_ME);
/* we're only interested in a device from intel-spi plugin that corresponds to ME /* we're only interested in a device from intel-spi plugin that corresponds to ME
@ -236,7 +218,7 @@ fu_plugin_flashrom_device_registered(FuPlugin *plugin, FuDevice *device)
if (g_strcmp0(fu_device_get_logical_id(device), me_region_str) != 0) if (g_strcmp0(fu_device_get_logical_id(device), me_region_str) != 0)
return; return;
me_device = fu_plugin_flashrom_add_device(plugin, priv->guid, FU_IFD_REGION_ME, NULL); me_device = fu_flashrom_plugin_add_device(plugin, self->guid, FU_IFD_REGION_ME, NULL);
if (me_device == NULL) if (me_device == NULL)
return; return;
@ -246,17 +228,17 @@ fu_plugin_flashrom_device_registered(FuPlugin *plugin, FuDevice *device)
} }
static gboolean static gboolean
fu_plugin_flashrom_coldplug(FuPlugin *plugin, FuProgress *progress, GError **error) fu_flashrom_plugin_coldplug(FuPlugin *plugin, FuProgress *progress, GError **error)
{ {
FuPluginData *priv = fu_plugin_get_data(plugin); FuFlashromPlugin *self = FU_FLASHROM_PLUGIN(plugin);
g_autoptr(FuDevice) device = g_autoptr(FuDevice) device =
fu_plugin_flashrom_add_device(plugin, priv->guid, FU_IFD_REGION_BIOS, error); fu_flashrom_plugin_add_device(plugin, self->guid, FU_IFD_REGION_BIOS, error);
return (device != NULL); return (device != NULL);
} }
/* finds GUID that activated this plugin */ /* finds GUID that activated this plugin */
static const gchar * static const gchar *
fu_plugin_flashrom_find_guid(FuPlugin *plugin, GError **error) fu_flashrom_plugin_find_guid(FuPlugin *plugin, GError **error)
{ {
FuContext *ctx = fu_plugin_get_context(plugin); FuContext *ctx = fu_plugin_get_context(plugin);
GPtrArray *hwids = fu_context_get_hwid_guids(ctx); GPtrArray *hwids = fu_context_get_hwid_guids(ctx);
@ -274,11 +256,11 @@ fu_plugin_flashrom_find_guid(FuPlugin *plugin, GError **error)
} }
static gboolean static gboolean
fu_plugin_flashrom_startup(FuPlugin *plugin, FuProgress *progress, GError **error) fu_flashrom_plugin_startup(FuPlugin *plugin, FuProgress *progress, GError **error)
{ {
gint rc; gint rc;
const gchar *guid; const gchar *guid;
FuPluginData *priv = fu_plugin_get_data(plugin); FuFlashromPlugin *self = FU_FLASHROM_PLUGIN(plugin);
/* progress */ /* progress */
fu_progress_set_id(progress, G_STRLOC); fu_progress_set_id(progress, G_STRLOC);
@ -286,12 +268,12 @@ fu_plugin_flashrom_startup(FuPlugin *plugin, FuProgress *progress, GError **erro
fu_progress_add_step(progress, FWUPD_STATUS_LOADING, 90, "init"); fu_progress_add_step(progress, FWUPD_STATUS_LOADING, 90, "init");
fu_progress_add_step(progress, FWUPD_STATUS_LOADING, 5, "probe"); fu_progress_add_step(progress, FWUPD_STATUS_LOADING, 5, "probe");
guid = fu_plugin_flashrom_find_guid(plugin, error); guid = fu_flashrom_plugin_find_guid(plugin, error);
if (guid == NULL) if (guid == NULL)
return FALSE; return FALSE;
fu_progress_step_done(progress); fu_progress_step_done(progress);
priv->guid = g_strdup(guid); self->guid = g_strdup(guid);
if (flashrom_init(SELFCHECK_TRUE)) { if (flashrom_init(SELFCHECK_TRUE)) {
g_set_error_literal(error, g_set_error_literal(error,
@ -300,10 +282,10 @@ fu_plugin_flashrom_startup(FuPlugin *plugin, FuProgress *progress, GError **erro
"flashrom initialization error"); "flashrom initialization error");
return FALSE; return FALSE;
} }
flashrom_set_log_callback(fu_plugin_flashrom_debug_cb); flashrom_set_log_callback(fu_flashrom_plugin_debug_cb);
fu_progress_step_done(progress); fu_progress_step_done(progress);
if (flashrom_programmer_init(&priv->flashprog, "internal", NULL)) { if (flashrom_programmer_init(&self->flashprog, "internal", NULL)) {
g_set_error_literal(error, g_set_error_literal(error,
FWUPD_ERROR, FWUPD_ERROR,
FWUPD_ERROR_NOT_SUPPORTED, FWUPD_ERROR_NOT_SUPPORTED,
@ -311,7 +293,7 @@ fu_plugin_flashrom_startup(FuPlugin *plugin, FuProgress *progress, GError **erro
return FALSE; return FALSE;
} }
rc = flashrom_flash_probe(&priv->flashctx, priv->flashprog, NULL); rc = flashrom_flash_probe(&self->flashctx, self->flashprog, NULL);
if (rc == 3) { if (rc == 3) {
g_set_error_literal(error, g_set_error_literal(error,
FWUPD_ERROR, FWUPD_ERROR,
@ -339,19 +321,44 @@ fu_plugin_flashrom_startup(FuPlugin *plugin, FuProgress *progress, GError **erro
} }
static gboolean static gboolean
fu_plugin_flashrom_unlock(FuPlugin *self, FuDevice *device, GError **error) fu_flashrom_plugin_unlock(FuPlugin *self, FuDevice *device, GError **error)
{ {
return fu_flashrom_device_unlock(FU_FLASHROM_DEVICE(device), error); return fu_flashrom_device_unlock(FU_FLASHROM_DEVICE(device), error);
} }
static void
fu_flashrom_plugin_constructed(GObject *obj)
{
FuPlugin *plugin = FU_PLUGIN(obj);
(void)fu_plugin_alloc_data(plugin, sizeof(FuFlashromPlugin));
fu_plugin_add_rule(plugin, FU_PLUGIN_RULE_METADATA_SOURCE, "linux_lockdown");
fu_plugin_add_rule(plugin, FU_PLUGIN_RULE_CONFLICTS, "coreboot"); /* obsoleted */
fu_plugin_add_flag(plugin, FWUPD_PLUGIN_FLAG_REQUIRE_HWID);
}
static void
fu_flashrom_plugin_finalize(GObject *obj)
{
FuPlugin *plugin = FU_PLUGIN(obj);
FuFlashromPlugin *self = FU_FLASHROM_PLUGIN(plugin);
if (self->flashctx != NULL)
flashrom_flash_release(self->flashctx);
if (self->flashprog != NULL)
flashrom_programmer_shutdown(self->flashprog);
g_free(self->guid);
/* G_OBJECT_CLASS(fu_flashrom_plugin_parent_class)->finalize() not required as modular */
}
void void
fu_plugin_init_vfuncs(FuPluginVfuncs *vfuncs) fu_plugin_init_vfuncs(FuPluginVfuncs *vfuncs)
{ {
vfuncs->init = fu_plugin_flashrom_init; vfuncs->constructed = fu_flashrom_plugin_constructed;
vfuncs->destroy = fu_plugin_flashrom_destroy; vfuncs->finalize = fu_flashrom_plugin_finalize;
vfuncs->to_string = fu_plugin_flashrom_to_string; vfuncs->to_string = fu_flashrom_plugin_to_string;
vfuncs->device_registered = fu_plugin_flashrom_device_registered; vfuncs->device_registered = fu_flashrom_plugin_device_registered;
vfuncs->startup = fu_plugin_flashrom_startup; vfuncs->startup = fu_flashrom_plugin_startup;
vfuncs->coldplug = fu_plugin_flashrom_coldplug; vfuncs->coldplug = fu_flashrom_plugin_coldplug;
vfuncs->unlock = fu_plugin_flashrom_unlock; vfuncs->unlock = fu_flashrom_plugin_unlock;
} }

View File

@ -7,7 +7,7 @@ plugin_quirks += files('flashrom.quirk')
shared_module('fu_plugin_flashrom', shared_module('fu_plugin_flashrom',
sources: [ sources: [
'fu-flashrom-device.c', 'fu-flashrom-device.c',
'fu-plugin-flashrom.c', 'fu-flashrom-plugin.c',
'fu-flashrom-cmos.c', 'fu-flashrom-cmos.c',
], ],
include_directories: plugin_incdirs, include_directories: plugin_incdirs,

View File

@ -34,78 +34,81 @@ struct FuPluginData {
FuMmDevice *shadow_device; FuMmDevice *shadow_device;
}; };
typedef FuPluginData FuModemManagerPlugin;
#define FU_MODEM_MANAGER_PLUGIN(o) fu_plugin_get_data(FU_PLUGIN(o))
static void static void
fu_plugin_mm_to_string(FuPlugin *plugin, guint idt, GString *str) fu_mm_plugin_to_string(FuPlugin *plugin, guint idt, GString *str)
{ {
FuPluginData *priv = fu_plugin_get_data(plugin); FuModemManagerPlugin *self = FU_MODEM_MANAGER_PLUGIN(plugin);
fu_string_append_kb(str, idt, "ManagerReady", priv->manager_ready); fu_string_append_kb(str, idt, "ManagerReady", self->manager_ready);
if (priv->shadow_device != NULL) if (self->shadow_device != NULL)
fu_string_append(str, idt, "ShadowDevice", fu_device_get_id(priv->shadow_device)); fu_string_append(str, idt, "ShadowDevice", fu_device_get_id(self->shadow_device));
} }
static void static void
fu_plugin_mm_load(FuContext *ctx) fu_mm_plugin_load(FuContext *ctx)
{ {
fu_context_add_quirk_key(ctx, "ModemManagerBranchAtCommand"); fu_context_add_quirk_key(ctx, "ModemManagerBranchAtCommand");
} }
static void static void
fu_plugin_mm_udev_device_removed(FuPlugin *plugin) fu_mm_plugin_udev_device_removed(FuPlugin *plugin)
{ {
FuPluginData *priv = fu_plugin_get_data(plugin); FuModemManagerPlugin *self = FU_MODEM_MANAGER_PLUGIN(plugin);
FuMmDevice *dev; FuMmDevice *dev;
if (priv->shadow_device == NULL) if (self->shadow_device == NULL)
return; return;
dev = fu_plugin_cache_lookup(plugin, dev = fu_plugin_cache_lookup(plugin,
fu_device_get_physical_id(FU_DEVICE(priv->shadow_device))); fu_device_get_physical_id(FU_DEVICE(self->shadow_device)));
if (dev == NULL) if (dev == NULL)
return; return;
/* once the first port is gone, consider device is gone */ /* once the first port is gone, consider device is gone */
fu_plugin_cache_remove(plugin, fu_device_get_physical_id(FU_DEVICE(priv->shadow_device))); fu_plugin_cache_remove(plugin, fu_device_get_physical_id(FU_DEVICE(self->shadow_device)));
fu_plugin_device_remove(plugin, FU_DEVICE(dev)); fu_plugin_device_remove(plugin, FU_DEVICE(dev));
/* no need to wait for more ports, cancel that right away */ /* no need to wait for more ports, cancel that right away */
if (priv->udev_timeout_id != 0) { if (self->udev_timeout_id != 0) {
g_source_remove(priv->udev_timeout_id); g_source_remove(self->udev_timeout_id);
priv->udev_timeout_id = 0; self->udev_timeout_id = 0;
} }
} }
static void static void
fu_plugin_mm_uninhibit_device(FuPlugin *plugin) fu_mm_plugin_uninhibit_device(FuPlugin *plugin)
{ {
FuPluginData *priv = fu_plugin_get_data(plugin); FuModemManagerPlugin *self = FU_MODEM_MANAGER_PLUGIN(plugin);
g_autoptr(FuMmDevice) shadow_device = NULL; g_autoptr(FuMmDevice) shadow_device = NULL;
g_clear_object(&priv->udev_client); g_clear_object(&self->udev_client);
/* get the device removed from the plugin cache before uninhibiting */ /* get the device removed from the plugin cache before uninhibiting */
fu_plugin_mm_udev_device_removed(plugin); fu_mm_plugin_udev_device_removed(plugin);
shadow_device = g_steal_pointer(&priv->shadow_device); shadow_device = g_steal_pointer(&self->shadow_device);
if (priv->manager != NULL && shadow_device != NULL) { if (self->manager != NULL && shadow_device != NULL) {
const gchar *inhibition_uid = fu_mm_device_get_inhibition_uid(shadow_device); const gchar *inhibition_uid = fu_mm_device_get_inhibition_uid(shadow_device);
g_debug("uninhibit modemmanager device with uid %s", inhibition_uid); g_debug("uninhibit modemmanager device with uid %s", inhibition_uid);
mm_manager_uninhibit_device_sync(priv->manager, inhibition_uid, NULL, NULL); mm_manager_uninhibit_device_sync(self->manager, inhibition_uid, NULL, NULL);
} }
} }
static gboolean static gboolean
fu_plugin_mm_udev_device_ports_timeout(gpointer user_data) fu_mm_plugin_udev_device_ports_timeout(gpointer user_data)
{ {
FuPlugin *plugin = user_data; FuPlugin *plugin = user_data;
FuPluginData *priv = fu_plugin_get_data(plugin); FuModemManagerPlugin *self = FU_MODEM_MANAGER_PLUGIN(plugin);
FuMmDevice *dev; FuMmDevice *dev;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
g_return_val_if_fail(priv->shadow_device != NULL, G_SOURCE_REMOVE); g_return_val_if_fail(self->shadow_device != NULL, G_SOURCE_REMOVE);
priv->udev_timeout_id = 0; self->udev_timeout_id = 0;
dev = fu_plugin_cache_lookup(plugin, dev = fu_plugin_cache_lookup(plugin,
fu_device_get_physical_id(FU_DEVICE(priv->shadow_device))); fu_device_get_physical_id(FU_DEVICE(self->shadow_device)));
if (dev != NULL) { if (dev != NULL) {
if (!fu_device_probe(FU_DEVICE(dev), &error)) { if (!fu_device_probe(FU_DEVICE(dev), &error)) {
g_debug("failed to probe MM device: %s", error->message); g_debug("failed to probe MM device: %s", error->message);
@ -118,59 +121,59 @@ fu_plugin_mm_udev_device_ports_timeout(gpointer user_data)
} }
static void static void
fu_plugin_mm_udev_device_ports_timeout_reset(FuPlugin *plugin) fu_mm_plugin_udev_device_ports_timeout_reset(FuPlugin *plugin)
{ {
FuPluginData *priv = fu_plugin_get_data(plugin); FuModemManagerPlugin *self = FU_MODEM_MANAGER_PLUGIN(plugin);
g_return_if_fail(priv->shadow_device != NULL); g_return_if_fail(self->shadow_device != NULL);
if (priv->udev_timeout_id != 0) if (self->udev_timeout_id != 0)
g_source_remove(priv->udev_timeout_id); g_source_remove(self->udev_timeout_id);
priv->udev_timeout_id = g_timeout_add_seconds(FU_MM_UDEV_DEVICE_PORTS_TIMEOUT, self->udev_timeout_id = g_timeout_add_seconds(FU_MM_UDEV_DEVICE_PORTS_TIMEOUT,
fu_plugin_mm_udev_device_ports_timeout, fu_mm_plugin_udev_device_ports_timeout,
plugin); plugin);
} }
static void static void
fu_plugin_mm_udev_device_port_added(FuPlugin *plugin, fu_mm_plugin_udev_device_port_added(FuPlugin *plugin,
const gchar *subsystem, const gchar *subsystem,
const gchar *path, const gchar *path,
gint ifnum) gint ifnum)
{ {
FuPluginData *priv = fu_plugin_get_data(plugin); FuModemManagerPlugin *self = FU_MODEM_MANAGER_PLUGIN(plugin);
FuMmDevice *existing; FuMmDevice *existing;
g_autoptr(FuMmDevice) dev = NULL; g_autoptr(FuMmDevice) dev = NULL;
g_return_if_fail(priv->shadow_device != NULL); g_return_if_fail(self->shadow_device != NULL);
existing = existing =
fu_plugin_cache_lookup(plugin, fu_plugin_cache_lookup(plugin,
fu_device_get_physical_id(FU_DEVICE(priv->shadow_device))); fu_device_get_physical_id(FU_DEVICE(self->shadow_device)));
if (existing != NULL) { if (existing != NULL) {
/* add port to existing device */ /* add port to existing device */
fu_mm_device_udev_add_port(existing, subsystem, path, ifnum); fu_mm_device_udev_add_port(existing, subsystem, path, ifnum);
fu_plugin_mm_udev_device_ports_timeout_reset(plugin); fu_mm_plugin_udev_device_ports_timeout_reset(plugin);
return; return;
} }
/* create device and add to cache */ /* create device and add to cache */
dev = fu_mm_device_udev_new(fu_plugin_get_context(plugin), dev = fu_mm_device_udev_new(fu_plugin_get_context(plugin),
priv->manager, self->manager,
priv->shadow_device); self->shadow_device);
fu_mm_device_udev_add_port(dev, subsystem, path, ifnum); fu_mm_device_udev_add_port(dev, subsystem, path, ifnum);
fu_plugin_cache_add(plugin, fu_device_get_physical_id(FU_DEVICE(priv->shadow_device)), dev); fu_plugin_cache_add(plugin, fu_device_get_physical_id(FU_DEVICE(self->shadow_device)), dev);
/* wait a bit before probing, in case more ports get added */ /* wait a bit before probing, in case more ports get added */
fu_plugin_mm_udev_device_ports_timeout_reset(plugin); fu_mm_plugin_udev_device_ports_timeout_reset(plugin);
} }
static gboolean static gboolean
fu_plugin_mm_udev_uevent_cb(GUdevClient *udev, fu_mm_plugin_udev_uevent_cb(GUdevClient *udev,
const gchar *action, const gchar *action,
GUdevDevice *device, GUdevDevice *device,
gpointer user_data) gpointer user_data)
{ {
FuPlugin *plugin = FU_PLUGIN(user_data); FuPlugin *plugin = FU_PLUGIN(user_data);
FuPluginData *priv = fu_plugin_get_data(plugin); FuModemManagerPlugin *self = FU_MODEM_MANAGER_PLUGIN(plugin);
const gchar *subsystem = g_udev_device_get_subsystem(device); const gchar *subsystem = g_udev_device_get_subsystem(device);
const gchar *name = g_udev_device_get_name(device); const gchar *name = g_udev_device_get_name(device);
g_autofree gchar *path = NULL; g_autofree gchar *path = NULL;
@ -178,7 +181,7 @@ fu_plugin_mm_udev_uevent_cb(GUdevClient *udev,
g_autofree gchar *device_bus = NULL; g_autofree gchar *device_bus = NULL;
gint ifnum = -1; gint ifnum = -1;
if (action == NULL || subsystem == NULL || priv->shadow_device == NULL || name == NULL) if (action == NULL || subsystem == NULL || self->shadow_device == NULL || name == NULL)
return TRUE; return TRUE;
/* ignore if loading port info fails */ /* ignore if loading port info fails */
@ -191,49 +194,49 @@ fu_plugin_mm_udev_uevent_cb(GUdevClient *udev,
/* ignore all events for ports not owned by our device */ /* ignore all events for ports not owned by our device */
if (g_strcmp0(device_sysfs_path, if (g_strcmp0(device_sysfs_path,
fu_device_get_physical_id(FU_DEVICE(priv->shadow_device))) != 0) fu_device_get_physical_id(FU_DEVICE(self->shadow_device))) != 0)
return TRUE; return TRUE;
path = g_strdup_printf("/dev/%s", name); path = g_strdup_printf("/dev/%s", name);
if ((g_str_equal(action, "add")) || (g_str_equal(action, "change"))) { if ((g_str_equal(action, "add")) || (g_str_equal(action, "change"))) {
g_debug("added port to shadow_device modem: %s (ifnum %d)", path, ifnum); g_debug("added port to shadow_device modem: %s (ifnum %d)", path, ifnum);
fu_plugin_mm_udev_device_port_added(plugin, subsystem, path, ifnum); fu_mm_plugin_udev_device_port_added(plugin, subsystem, path, ifnum);
} else if (g_str_equal(action, "remove")) { } else if (g_str_equal(action, "remove")) {
g_debug("removed port from shadow_device modem: %s", path); g_debug("removed port from shadow_device modem: %s", path);
fu_plugin_mm_udev_device_removed(plugin); fu_mm_plugin_udev_device_removed(plugin);
} }
return TRUE; return TRUE;
} }
static gboolean static gboolean
fu_plugin_mm_inhibit_device(FuPlugin *plugin, FuDevice *device, GError **error) fu_mm_plugin_inhibit_device(FuPlugin *plugin, FuDevice *device, GError **error)
{ {
const gchar *inhibition_uid; const gchar *inhibition_uid;
static const gchar *subsystems[] = {"tty", "usbmisc", "wwan", NULL}; static const gchar *subsystems[] = {"tty", "usbmisc", "wwan", NULL};
FuPluginData *priv = fu_plugin_get_data(plugin); FuModemManagerPlugin *self = FU_MODEM_MANAGER_PLUGIN(plugin);
g_autoptr(FuMmDevice) shadow_device = NULL; g_autoptr(FuMmDevice) shadow_device = NULL;
fu_plugin_mm_uninhibit_device(plugin); fu_mm_plugin_uninhibit_device(plugin);
shadow_device = fu_mm_shadow_device_new(FU_MM_DEVICE(device)); shadow_device = fu_mm_shadow_device_new(FU_MM_DEVICE(device));
inhibition_uid = fu_mm_device_get_inhibition_uid(shadow_device); inhibition_uid = fu_mm_device_get_inhibition_uid(shadow_device);
g_debug("inhibit modemmanager device with uid %s", inhibition_uid); g_debug("inhibit modemmanager device with uid %s", inhibition_uid);
if (!mm_manager_inhibit_device_sync(priv->manager, inhibition_uid, NULL, error)) if (!mm_manager_inhibit_device_sync(self->manager, inhibition_uid, NULL, error))
return FALSE; return FALSE;
/* setup shadow_device device info */ /* setup shadow_device device info */
priv->shadow_device = g_steal_pointer(&shadow_device); self->shadow_device = g_steal_pointer(&shadow_device);
/* only do modem port monitoring using udev if the module is expected /* only do modem port monitoring using udev if the module is expected
* to reset itself into a fully different layout, e.g. a fastboot device */ * to reset itself into a fully different layout, e.g. a fastboot device */
if (fu_mm_device_get_update_methods(FU_MM_DEVICE(device)) & if (fu_mm_device_get_update_methods(FU_MM_DEVICE(device)) &
MM_MODEM_FIRMWARE_UPDATE_METHOD_FASTBOOT) { MM_MODEM_FIRMWARE_UPDATE_METHOD_FASTBOOT) {
priv->udev_client = g_udev_client_new(subsystems); self->udev_client = g_udev_client_new(subsystems);
g_signal_connect(G_UDEV_CLIENT(priv->udev_client), g_signal_connect(G_UDEV_CLIENT(self->udev_client),
"uevent", "uevent",
G_CALLBACK(fu_plugin_mm_udev_uevent_cb), G_CALLBACK(fu_mm_plugin_udev_uevent_cb),
plugin); plugin);
} }
@ -241,7 +244,7 @@ fu_plugin_mm_inhibit_device(FuPlugin *plugin, FuDevice *device, GError **error)
} }
static void static void
fu_plugin_mm_ensure_modem_power_inhibit(FuPlugin *plugin, FuDevice *device) fu_mm_plugin_ensure_modem_power_inhibit(FuPlugin *plugin, FuDevice *device)
{ {
if (g_file_test(MODEM_POWER_SYSFS_PATH, G_FILE_TEST_EXISTS)) { if (g_file_test(MODEM_POWER_SYSFS_PATH, G_FILE_TEST_EXISTS)) {
fu_device_inhibit(device, fu_device_inhibit(device,
@ -253,9 +256,9 @@ fu_plugin_mm_ensure_modem_power_inhibit(FuPlugin *plugin, FuDevice *device)
} }
static void static void
fu_plugin_mm_device_add(FuPlugin *plugin, MMObject *modem) fu_mm_plugin_device_add(FuPlugin *plugin, MMObject *modem)
{ {
FuPluginData *priv = fu_plugin_get_data(plugin); FuModemManagerPlugin *self = FU_MODEM_MANAGER_PLUGIN(plugin);
const gchar *object_path = mm_object_get_path(modem); const gchar *object_path = mm_object_get_path(modem);
g_autoptr(FuMmDevice) dev = NULL; g_autoptr(FuMmDevice) dev = NULL;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
@ -266,25 +269,25 @@ fu_plugin_mm_device_add(FuPlugin *plugin, MMObject *modem)
g_warning("MM device already added, ignoring"); g_warning("MM device already added, ignoring");
return; return;
} }
dev = fu_mm_device_new(fu_plugin_get_context(plugin), priv->manager, modem); dev = fu_mm_device_new(fu_plugin_get_context(plugin), self->manager, modem);
if (!fu_device_setup(FU_DEVICE(dev), &error)) { if (!fu_device_setup(FU_DEVICE(dev), &error)) {
g_debug("failed to probe MM device: %s", error->message); g_debug("failed to probe MM device: %s", error->message);
return; return;
} }
fu_plugin_mm_ensure_modem_power_inhibit(plugin, FU_DEVICE(dev)); fu_mm_plugin_ensure_modem_power_inhibit(plugin, FU_DEVICE(dev));
fu_plugin_device_add(plugin, FU_DEVICE(dev)); fu_plugin_device_add(plugin, FU_DEVICE(dev));
fu_plugin_cache_add(plugin, object_path, dev); fu_plugin_cache_add(plugin, object_path, dev);
fu_plugin_cache_add(plugin, fu_device_get_physical_id(FU_DEVICE(dev)), dev); fu_plugin_cache_add(plugin, fu_device_get_physical_id(FU_DEVICE(dev)), dev);
} }
static void static void
fu_plugin_mm_device_added_cb(MMManager *manager, MMObject *modem, FuPlugin *plugin) fu_mm_plugin_device_added_cb(MMManager *manager, MMObject *modem, FuPlugin *plugin)
{ {
fu_plugin_mm_device_add(plugin, modem); fu_mm_plugin_device_add(plugin, modem);
} }
static void static void
fu_plugin_mm_device_removed_cb(MMManager *manager, MMObject *modem, FuPlugin *plugin) fu_mm_plugin_device_removed_cb(MMManager *manager, MMObject *modem, FuPlugin *plugin)
{ {
const gchar *object_path = mm_object_get_path(modem); const gchar *object_path = mm_object_get_path(modem);
FuMmDevice *dev = fu_plugin_cache_lookup(plugin, object_path); FuMmDevice *dev = fu_plugin_cache_lookup(plugin, object_path);
@ -311,27 +314,27 @@ fu_plugin_mm_device_removed_cb(MMManager *manager, MMObject *modem, FuPlugin *pl
} }
static void static void
fu_plugin_mm_teardown_manager(FuPlugin *plugin) fu_mm_plugin_teardown_manager(FuPlugin *plugin)
{ {
FuPluginData *priv = fu_plugin_get_data(plugin); FuModemManagerPlugin *self = FU_MODEM_MANAGER_PLUGIN(plugin);
if (priv->manager_ready) { if (self->manager_ready) {
g_debug("ModemManager no longer available"); g_debug("ModemManager no longer available");
g_signal_handlers_disconnect_by_func(priv->manager, g_signal_handlers_disconnect_by_func(self->manager,
G_CALLBACK(fu_plugin_mm_device_added_cb), G_CALLBACK(fu_mm_plugin_device_added_cb),
plugin); plugin);
g_signal_handlers_disconnect_by_func(priv->manager, g_signal_handlers_disconnect_by_func(self->manager,
G_CALLBACK(fu_plugin_mm_device_removed_cb), G_CALLBACK(fu_mm_plugin_device_removed_cb),
plugin); plugin);
priv->manager_ready = FALSE; self->manager_ready = FALSE;
} }
} }
static void static void
fu_plugin_mm_setup_manager(FuPlugin *plugin) fu_mm_plugin_setup_manager(FuPlugin *plugin)
{ {
FuPluginData *priv = fu_plugin_get_data(plugin); FuModemManagerPlugin *self = FU_MODEM_MANAGER_PLUGIN(plugin);
const gchar *version = mm_manager_get_version(priv->manager); const gchar *version = mm_manager_get_version(self->manager);
GList *list; GList *list;
if (fu_version_compare(version, MM_REQUIRED_VERSION, FWUPD_VERSION_FORMAT_TRIPLET) < 0) { if (fu_version_compare(version, MM_REQUIRED_VERSION, FWUPD_VERSION_FORMAT_TRIPLET) < 0) {
@ -343,53 +346,53 @@ fu_plugin_mm_setup_manager(FuPlugin *plugin)
g_debug("ModemManager %s is available", version); g_debug("ModemManager %s is available", version);
g_signal_connect(G_DBUS_OBJECT_MANAGER(priv->manager), g_signal_connect(G_DBUS_OBJECT_MANAGER(self->manager),
"object-added", "object-added",
G_CALLBACK(fu_plugin_mm_device_added_cb), G_CALLBACK(fu_mm_plugin_device_added_cb),
plugin); plugin);
g_signal_connect(G_DBUS_OBJECT_MANAGER(priv->manager), g_signal_connect(G_DBUS_OBJECT_MANAGER(self->manager),
"object-removed", "object-removed",
G_CALLBACK(fu_plugin_mm_device_removed_cb), G_CALLBACK(fu_mm_plugin_device_removed_cb),
plugin); plugin);
list = g_dbus_object_manager_get_objects(G_DBUS_OBJECT_MANAGER(priv->manager)); list = g_dbus_object_manager_get_objects(G_DBUS_OBJECT_MANAGER(self->manager));
for (GList *l = list; l != NULL; l = g_list_next(l)) { for (GList *l = list; l != NULL; l = g_list_next(l)) {
MMObject *modem = MM_OBJECT(l->data); MMObject *modem = MM_OBJECT(l->data);
fu_plugin_mm_device_add(plugin, modem); fu_mm_plugin_device_add(plugin, modem);
g_object_unref(modem); g_object_unref(modem);
} }
g_list_free(list); g_list_free(list);
priv->manager_ready = TRUE; self->manager_ready = TRUE;
} }
static void static void
fu_plugin_mm_name_owner_updated(FuPlugin *plugin) fu_mm_plugin_name_owner_updated(FuPlugin *plugin)
{ {
FuPluginData *priv = fu_plugin_get_data(plugin); FuModemManagerPlugin *self = FU_MODEM_MANAGER_PLUGIN(plugin);
g_autofree gchar *name_owner = NULL; g_autofree gchar *name_owner = NULL;
name_owner = g_dbus_object_manager_client_get_name_owner( name_owner = g_dbus_object_manager_client_get_name_owner(
G_DBUS_OBJECT_MANAGER_CLIENT(priv->manager)); G_DBUS_OBJECT_MANAGER_CLIENT(self->manager));
if (name_owner != NULL) if (name_owner != NULL)
fu_plugin_mm_setup_manager(plugin); fu_mm_plugin_setup_manager(plugin);
else else
fu_plugin_mm_teardown_manager(plugin); fu_mm_plugin_teardown_manager(plugin);
} }
static gboolean static gboolean
fu_plugin_mm_coldplug(FuPlugin *plugin, FuProgress *progress, GError **error) fu_mm_plugin_coldplug(FuPlugin *plugin, FuProgress *progress, GError **error)
{ {
FuPluginData *priv = fu_plugin_get_data(plugin); FuModemManagerPlugin *self = FU_MODEM_MANAGER_PLUGIN(plugin);
g_signal_connect_swapped(MM_MANAGER(priv->manager), g_signal_connect_swapped(MM_MANAGER(self->manager),
"notify::name-owner", "notify::name-owner",
G_CALLBACK(fu_plugin_mm_name_owner_updated), G_CALLBACK(fu_mm_plugin_name_owner_updated),
plugin); plugin);
fu_plugin_mm_name_owner_updated(plugin); fu_mm_plugin_name_owner_updated(plugin);
return TRUE; return TRUE;
} }
static void static void
fu_plugin_mm_modem_power_changed_cb(GFileMonitor *monitor, fu_mm_plugin_modem_power_changed_cb(GFileMonitor *monitor,
GFile *file, GFile *file,
GFile *other_file, GFile *other_file,
GFileMonitorEvent event_type, GFileMonitorEvent event_type,
@ -399,66 +402,43 @@ fu_plugin_mm_modem_power_changed_cb(GFileMonitor *monitor,
GPtrArray *devices = fu_plugin_get_devices(plugin); GPtrArray *devices = fu_plugin_get_devices(plugin);
for (guint i = 0; i < devices->len; i++) { for (guint i = 0; i < devices->len; i++) {
FuDevice *device = g_ptr_array_index(devices, i); FuDevice *device = g_ptr_array_index(devices, i);
fu_plugin_mm_ensure_modem_power_inhibit(plugin, device); fu_mm_plugin_ensure_modem_power_inhibit(plugin, device);
} }
} }
static gboolean static gboolean
fu_plugin_mm_startup(FuPlugin *plugin, FuProgress *progress, GError **error) fu_mm_plugin_startup(FuPlugin *plugin, FuProgress *progress, GError **error)
{ {
FuPluginData *priv = fu_plugin_get_data(plugin); FuModemManagerPlugin *self = FU_MODEM_MANAGER_PLUGIN(plugin);
g_autoptr(GDBusConnection) connection = NULL; g_autoptr(GDBusConnection) connection = NULL;
g_autoptr(GFile) file = g_file_new_for_path(MODEM_POWER_SYSFS_PATH); g_autoptr(GFile) file = g_file_new_for_path(MODEM_POWER_SYSFS_PATH);
connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, error); connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, error);
if (connection == NULL) if (connection == NULL)
return FALSE; return FALSE;
priv->manager = mm_manager_new_sync(connection, self->manager = mm_manager_new_sync(connection,
G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START, G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START,
NULL, NULL,
error); error);
if (priv->manager == NULL) if (self->manager == NULL)
return FALSE; return FALSE;
/* detect presence of unsupported modem-power driver */ /* detect presence of unsupported modem-power driver */
priv->modem_power_monitor = g_file_monitor(file, G_FILE_MONITOR_NONE, NULL, error); self->modem_power_monitor = g_file_monitor(file, G_FILE_MONITOR_NONE, NULL, error);
if (priv->modem_power_monitor == NULL) if (self->modem_power_monitor == NULL)
return FALSE; return FALSE;
g_signal_connect(priv->modem_power_monitor, g_signal_connect(self->modem_power_monitor,
"changed", "changed",
G_CALLBACK(fu_plugin_mm_modem_power_changed_cb), G_CALLBACK(fu_mm_plugin_modem_power_changed_cb),
plugin); plugin);
return TRUE; return TRUE;
} }
static void
fu_plugin_mm_init(FuPlugin *plugin)
{
fu_plugin_alloc_data(plugin, sizeof(FuPluginData));
}
static void
fu_plugin_mm_destroy(FuPlugin *plugin)
{
FuPluginData *priv = fu_plugin_get_data(plugin);
fu_plugin_mm_uninhibit_device(plugin);
if (priv->udev_timeout_id)
g_source_remove(priv->udev_timeout_id);
if (priv->udev_client)
g_object_unref(priv->udev_client);
if (priv->manager != NULL)
g_object_unref(priv->manager);
if (priv->modem_power_monitor != NULL)
g_object_unref(priv->modem_power_monitor);
}
static gboolean static gboolean
fu_plugin_mm_detach(FuPlugin *plugin, FuDevice *device, FuProgress *progress, GError **error) fu_mm_plugin_detach(FuPlugin *plugin, FuDevice *device, FuProgress *progress, GError **error)
{ {
FuPluginData *priv = fu_plugin_get_data(plugin); FuModemManagerPlugin *self = FU_MODEM_MANAGER_PLUGIN(plugin);
g_autoptr(FuDeviceLocker) locker = NULL; g_autoptr(FuDeviceLocker) locker = NULL;
/* open device */ /* open device */
@ -470,14 +450,14 @@ fu_plugin_mm_detach(FuPlugin *plugin, FuDevice *device, FuProgress *progress, GE
* lifetime of the FuMmDevice, because that object will only exist for * lifetime of the FuMmDevice, because that object will only exist for
* as long as the ModemManager device exists, and inhibiting will * as long as the ModemManager device exists, and inhibiting will
* implicitly remove the device from ModemManager. */ * implicitly remove the device from ModemManager. */
if (priv->shadow_device == NULL) { if (self->shadow_device == NULL) {
if (!fu_plugin_mm_inhibit_device(plugin, device, error)) if (!fu_mm_plugin_inhibit_device(plugin, device, error))
return FALSE; return FALSE;
} }
/* reset */ /* reset */
if (!fu_device_detach_full(device, progress, error)) { if (!fu_device_detach_full(device, progress, error)) {
fu_plugin_mm_uninhibit_device(plugin); fu_mm_plugin_uninhibit_device(plugin);
return FALSE; return FALSE;
} }
@ -486,14 +466,14 @@ fu_plugin_mm_detach(FuPlugin *plugin, FuDevice *device, FuProgress *progress, GE
} }
static void static void
fu_plugin_mm_device_attach_finished(gpointer user_data) fu_mm_plugin_device_attach_finished(gpointer user_data)
{ {
FuPlugin *plugin = FU_PLUGIN(user_data); FuPlugin *plugin = FU_PLUGIN(user_data);
fu_plugin_mm_uninhibit_device(plugin); fu_mm_plugin_uninhibit_device(plugin);
} }
static gboolean static gboolean
fu_plugin_mm_attach(FuPlugin *plugin, FuDevice *device, FuProgress *progress, GError **error) fu_mm_plugin_attach(FuPlugin *plugin, FuDevice *device, FuProgress *progress, GError **error)
{ {
g_autoptr(FuDeviceLocker) locker = NULL; g_autoptr(FuDeviceLocker) locker = NULL;
@ -512,14 +492,14 @@ fu_plugin_mm_attach(FuPlugin *plugin, FuDevice *device, FuProgress *progress, GE
/* this signal will always be emitted asynchronously */ /* this signal will always be emitted asynchronously */
g_signal_connect_swapped(FU_DEVICE(device), g_signal_connect_swapped(FU_DEVICE(device),
"attach-finished", "attach-finished",
G_CALLBACK(fu_plugin_mm_device_attach_finished), G_CALLBACK(fu_mm_plugin_device_attach_finished),
plugin); plugin);
return TRUE; return TRUE;
} }
static gboolean static gboolean
fu_plugin_mm_backend_device_added(FuPlugin *plugin, FuDevice *device, GError **error) fu_mm_plugin_backend_device_added(FuPlugin *plugin, FuDevice *device, GError **error)
{ {
FuDevice *device_tmp; FuDevice *device_tmp;
g_autoptr(GUdevDevice) udev_device = NULL; g_autoptr(GUdevDevice) udev_device = NULL;
@ -545,16 +525,43 @@ fu_plugin_mm_backend_device_added(FuPlugin *plugin, FuDevice *device, GError **e
return TRUE; return TRUE;
} }
static void
fu_mm_plugin_constructed(GObject *obj)
{
FuPlugin *plugin = FU_PLUGIN(obj);
(void)fu_plugin_alloc_data(plugin, sizeof(FuModemManagerPlugin));
}
static void
fu_mm_plugin_finalize(GObject *obj)
{
FuPlugin *plugin = FU_PLUGIN(obj);
FuModemManagerPlugin *self = FU_MODEM_MANAGER_PLUGIN(plugin);
fu_mm_plugin_uninhibit_device(plugin);
if (self->udev_timeout_id)
g_source_remove(self->udev_timeout_id);
if (self->udev_client)
g_object_unref(self->udev_client);
if (self->manager != NULL)
g_object_unref(self->manager);
if (self->modem_power_monitor != NULL)
g_object_unref(self->modem_power_monitor);
/* G_OBJECT_CLASS(fu_mm_plugin_parent_class)->finalize() not required as modular */
}
void void
fu_plugin_init_vfuncs(FuPluginVfuncs *vfuncs) fu_plugin_init_vfuncs(FuPluginVfuncs *vfuncs)
{ {
vfuncs->load = fu_plugin_mm_load; vfuncs->load = fu_mm_plugin_load;
vfuncs->init = fu_plugin_mm_init; vfuncs->constructed = fu_mm_plugin_constructed;
vfuncs->destroy = fu_plugin_mm_destroy; vfuncs->finalize = fu_mm_plugin_finalize;
vfuncs->to_string = fu_plugin_mm_to_string; vfuncs->to_string = fu_mm_plugin_to_string;
vfuncs->startup = fu_plugin_mm_startup; vfuncs->startup = fu_mm_plugin_startup;
vfuncs->coldplug = fu_plugin_mm_coldplug; vfuncs->coldplug = fu_mm_plugin_coldplug;
vfuncs->attach = fu_plugin_mm_attach; vfuncs->attach = fu_mm_plugin_attach;
vfuncs->detach = fu_plugin_mm_detach; vfuncs->detach = fu_mm_plugin_detach;
vfuncs->backend_device_added = fu_plugin_mm_backend_device_added; vfuncs->backend_device_added = fu_mm_plugin_backend_device_added;
} }

View File

@ -15,7 +15,7 @@ plugin_quirks += files('modem-manager.quirk')
shared_module('fu_plugin_modem_manager', shared_module('fu_plugin_modem_manager',
sources: [ sources: [
'fu-plugin-modem-manager.c', 'fu-mm-plugin.c',
'fu-mm-device.c', 'fu-mm-device.c',
'fu-qmi-pdc-updater.c', 'fu-qmi-pdc-updater.c',
'fu-mbim-qdu-updater.c', 'fu-mbim-qdu-updater.c',