diff options
-rw-r--r-- | src/devices/adsl/exports.ver | 1 | ||||
-rw-r--r-- | src/devices/adsl/nm-atm-manager.c | 31 | ||||
-rw-r--r-- | src/devices/bluetooth/exports.ver | 1 | ||||
-rw-r--r-- | src/devices/bluetooth/nm-bluez-manager.c | 33 | ||||
-rw-r--r-- | src/devices/nm-device-factory.c | 17 | ||||
-rw-r--r-- | src/devices/nm-device-factory.h | 35 | ||||
-rw-r--r-- | src/devices/team/exports.ver | 1 | ||||
-rw-r--r-- | src/devices/team/nm-team-factory.c | 40 | ||||
-rw-r--r-- | src/devices/wifi/exports.ver | 1 | ||||
-rw-r--r-- | src/devices/wifi/nm-wifi-factory.c | 15 | ||||
-rw-r--r-- | src/devices/wimax/exports.ver | 1 | ||||
-rw-r--r-- | src/devices/wimax/nm-wimax-factory.c | 15 | ||||
-rw-r--r-- | src/devices/wwan/exports.ver | 1 | ||||
-rw-r--r-- | src/devices/wwan/nm-wwan-factory.c | 25 | ||||
-rw-r--r-- | src/nm-manager.c | 49 |
15 files changed, 127 insertions, 139 deletions
diff --git a/src/devices/adsl/exports.ver b/src/devices/adsl/exports.ver index d2c451244b..24cd848ce1 100644 --- a/src/devices/adsl/exports.ver +++ b/src/devices/adsl/exports.ver @@ -1,7 +1,6 @@ { global: nm_device_factory_create; - nm_device_factory_get_device_type; local: *; }; diff --git a/src/devices/adsl/nm-atm-manager.c b/src/devices/adsl/nm-atm-manager.c index e8db3596d7..37be69c6e4 100644 --- a/src/devices/adsl/nm-atm-manager.c +++ b/src/devices/adsl/nm-atm-manager.c @@ -32,7 +32,6 @@ typedef struct { GUdevClient *client; GSList *devices; - guint start_id; } NMAtmManagerPrivate; #define NM_ATM_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_ATM_MANAGER, NMAtmManagerPrivate)) @@ -46,20 +45,12 @@ G_DEFINE_TYPE_EXTENDED (NMAtmManager, nm_atm_manager, G_TYPE_OBJECT, 0, /**************************************************************************/ -#define PLUGIN_TYPE NM_DEVICE_TYPE_ADSL - G_MODULE_EXPORT NMDeviceFactory * nm_device_factory_create (GError **error) { return (NMDeviceFactory *) g_object_new (NM_TYPE_ATM_MANAGER, NULL); } -G_MODULE_EXPORT NMDeviceType -nm_device_factory_get_device_type (void) -{ - return PLUGIN_TYPE; -} - /************************************************************************/ static gboolean @@ -163,9 +154,10 @@ adsl_remove (NMAtmManager *self, GUdevDevice *udev_device) } } -static gboolean -query_devices (NMAtmManager *self) +static void +start (NMDeviceFactory *factory) { + NMAtmManager *self = NM_ATM_MANAGER (factory); NMAtmManagerPrivate *priv = NM_ATM_MANAGER_GET_PRIVATE (self); GUdevEnumerator *enumerator; GList *devices, *iter; @@ -180,8 +172,6 @@ query_devices (NMAtmManager *self) } g_list_free (devices); g_object_unref (enumerator); - - return G_SOURCE_REMOVE; } static void @@ -212,6 +202,12 @@ handle_uevent (GUdevClient *client, adsl_remove (self, device); } +static NMDeviceType +get_device_type (NMDeviceFactory *factory) +{ + return NM_DEVICE_TYPE_ADSL; +} + /*********************************************************************/ static void @@ -222,13 +218,13 @@ nm_atm_manager_init (NMAtmManager *self) priv->client = g_udev_client_new (subsys); g_signal_connect (priv->client, "uevent", G_CALLBACK (handle_uevent), self); - - priv->start_id = g_idle_add ((GSourceFunc) query_devices, self); } static void device_factory_interface_init (NMDeviceFactory *factory_iface) { + factory_iface->get_device_type = get_device_type; + factory_iface->start = start; } static void @@ -242,11 +238,6 @@ dispose (GObject *object) g_signal_handlers_disconnect_by_func (priv->client, handle_uevent, self); g_clear_object (&priv->client); - if (priv->start_id) { - g_source_remove (priv->start_id); - priv->start_id = 0; - } - for (iter = priv->devices; iter; iter = iter->next) g_object_weak_unref (G_OBJECT (iter->data), device_destroyed, self); g_clear_pointer (&priv->devices, g_slist_free); diff --git a/src/devices/bluetooth/exports.ver b/src/devices/bluetooth/exports.ver index d2c451244b..24cd848ce1 100644 --- a/src/devices/bluetooth/exports.ver +++ b/src/devices/bluetooth/exports.ver @@ -1,7 +1,6 @@ { global: nm_device_factory_create; - nm_device_factory_get_device_type; local: *; }; diff --git a/src/devices/bluetooth/nm-bluez-manager.c b/src/devices/bluetooth/nm-bluez-manager.c index 04ffb0a476..f054e5b308 100644 --- a/src/devices/bluetooth/nm-bluez-manager.c +++ b/src/devices/bluetooth/nm-bluez-manager.c @@ -62,20 +62,12 @@ static void check_bluez_and_try_setup (NMBluezManager *self); /**************************************************************************/ -#define PLUGIN_TYPE NM_DEVICE_TYPE_BT - G_MODULE_EXPORT NMDeviceFactory * nm_device_factory_create (GError **error) { return (NMDeviceFactory *) g_object_new (NM_TYPE_BLUEZ_MANAGER, NULL); } -G_MODULE_EXPORT NMDeviceType -nm_device_factory_get_device_type (void) -{ - return PLUGIN_TYPE; -} - /************************************************************************/ struct AsyncData { @@ -368,6 +360,18 @@ check_bluez_and_try_setup (NMBluezManager *self) async_data_pack (self)); } +static void +start (NMDeviceFactory *factory) +{ + check_bluez_and_try_setup (NM_BLUEZ_MANAGER (factory)); +} + +static NMDeviceType +get_device_type (NMDeviceFactory *factory) +{ + return NM_DEVICE_TYPE_BT; +} + /*********************************************************************/ static void @@ -391,16 +395,6 @@ dispose (GObject *object) } static void -constructed (GObject *object) -{ - NMBluezManager *self = NM_BLUEZ_MANAGER (object); - - G_OBJECT_CLASS (nm_bluez_manager_parent_class)->constructed (object); - - check_bluez_and_try_setup (self); -} - -static void nm_bluez_manager_init (NMBluezManager *self) { NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE (self); @@ -412,6 +406,8 @@ nm_bluez_manager_init (NMBluezManager *self) static void device_factory_interface_init (NMDeviceFactory *factory_iface) { + factory_iface->get_device_type = get_device_type; + factory_iface->start = start; } static void @@ -423,6 +419,5 @@ nm_bluez_manager_class_init (NMBluezManagerClass *klass) /* virtual methods */ object_class->dispose = dispose; - object_class->constructed = constructed; } diff --git a/src/devices/nm-device-factory.c b/src/devices/nm-device-factory.c index 5e84531135..2e5f099204 100644 --- a/src/devices/nm-device-factory.c +++ b/src/devices/nm-device-factory.c @@ -91,6 +91,23 @@ nm_device_factory_get_type (void) return device_factory_type; } +NMDeviceType +nm_device_factory_get_device_type (NMDeviceFactory *factory) +{ + g_return_val_if_fail (factory != NULL, NM_DEVICE_TYPE_UNKNOWN); + + return NM_DEVICE_FACTORY_GET_INTERFACE (factory)->get_device_type (factory); +} + +void +nm_device_factory_start (NMDeviceFactory *factory) +{ + g_return_if_fail (factory != NULL); + + if (NM_DEVICE_FACTORY_GET_INTERFACE (factory)->start) + NM_DEVICE_FACTORY_GET_INTERFACE (factory)->start (factory); +} + NMDevice * nm_device_factory_new_link (NMDeviceFactory *factory, NMPlatformLink *plink, diff --git a/src/devices/nm-device-factory.h b/src/devices/nm-device-factory.h index 0f3871021e..e842bd7ec8 100644 --- a/src/devices/nm-device-factory.h +++ b/src/devices/nm-device-factory.h @@ -42,7 +42,7 @@ typedef struct _NMDeviceFactory NMDeviceFactory; * Creates a #GObject that implements the #NMDeviceFactory interface. This * function must not emit any signals or perform any actions that would cause * devices or components to be created immediately. Instead these should be - * deferred to an idle handler. + * deferred to the "start" interface method. * * Returns: the #GObject implementing #NMDeviceFactory or %NULL */ @@ -51,16 +51,6 @@ NMDeviceFactory *nm_device_factory_create (GError **error); /* Should match nm_device_factory_create() */ typedef NMDeviceFactory * (*NMDeviceFactoryCreateFunc) (GError **error); -/** - * nm_device_factory_get_device_type: - * - * Returns: the #NMDeviceType that this plugin creates - */ -NMDeviceType nm_device_factory_get_device_type (void); - -/* Should match nm_device_factory_get_device_type() */ -typedef NMDeviceType (*NMDeviceFactoryDeviceTypeFunc) (void); - /********************************************************************/ #define NM_TYPE_DEVICE_FACTORY (nm_device_factory_get_type ()) @@ -76,6 +66,25 @@ struct _NMDeviceFactory { GTypeInterface g_iface; /** + * get_device_type: + * @factory: the #NMDeviceFactory + * + * This function MUST be implemented. + * + * Returns: the #NMDeviceType that this plugin creates + */ + NMDeviceType (*get_device_type) (NMDeviceFactory *factory); + + /** + * start: + * @factory: the #NMDeviceFactory + * + * Start the factory and discover any existing devices that the factory + * can manage. + */ + void (*start) (NMDeviceFactory *factory); + + /** * new_link: * @factory: the #NMDeviceFactory * @link: the new link @@ -141,6 +150,10 @@ struct _NMDeviceFactory { GType nm_device_factory_get_type (void); +NMDeviceType nm_device_factory_get_device_type (NMDeviceFactory *factory); + +void nm_device_factory_start (NMDeviceFactory *factory); + NMDevice * nm_device_factory_new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error); diff --git a/src/devices/team/exports.ver b/src/devices/team/exports.ver index d2c451244b..24cd848ce1 100644 --- a/src/devices/team/exports.ver +++ b/src/devices/team/exports.ver @@ -1,7 +1,6 @@ { global: nm_device_factory_create; - nm_device_factory_get_device_type; local: *; }; diff --git a/src/devices/team/nm-team-factory.c b/src/devices/team/nm-team-factory.c index 49e5945c70..499c37795d 100644 --- a/src/devices/team/nm-team-factory.c +++ b/src/devices/team/nm-team-factory.c @@ -35,12 +35,13 @@ static void device_factory_interface_init (NMDeviceFactory *factory_iface); G_DEFINE_TYPE_EXTENDED (NMTeamFactory, nm_team_factory, G_TYPE_OBJECT, 0, G_IMPLEMENT_INTERFACE (NM_TYPE_DEVICE_FACTORY, device_factory_interface_init)) -#define NM_TEAM_FACTORY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_TEAM_FACTORY, NMTeamFactoryPrivate)) - -typedef struct { - char dummy; -} NMTeamFactoryPrivate; +/************************************************************************/ +G_MODULE_EXPORT NMDeviceFactory * +nm_device_factory_create (GError **error) +{ + return (NMDeviceFactory *) g_object_new (NM_TYPE_TEAM_FACTORY, NULL); +} /************************************************************************/ @@ -62,20 +63,10 @@ create_virtual_device_for_connection (NMDeviceFactory *factory, return NULL; } -/************************************************************************/ - -#define PLUGIN_TYPE NM_DEVICE_TYPE_TEAM - -G_MODULE_EXPORT NMDeviceFactory * -nm_device_factory_create (GError **error) -{ - return (NMDeviceFactory *) g_object_new (NM_TYPE_TEAM_FACTORY, NULL); -} - -G_MODULE_EXPORT NMDeviceType -nm_device_factory_get_device_type (void) +static NMDeviceType +get_device_type (NMDeviceFactory *factory) { - return PLUGIN_TYPE; + return NM_DEVICE_TYPE_TEAM; } /************************************************************************/ @@ -90,21 +81,10 @@ device_factory_interface_init (NMDeviceFactory *factory_iface) { factory_iface->new_link = new_link; factory_iface->create_virtual_device_for_connection = create_virtual_device_for_connection; -} - -static void -dispose (GObject *object) -{ - /* Chain up to the parent class */ - G_OBJECT_CLASS (nm_team_factory_parent_class)->dispose (object); + factory_iface->get_device_type = get_device_type; } static void nm_team_factory_class_init (NMTeamFactoryClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - g_type_class_add_private (object_class, sizeof (NMTeamFactoryPrivate)); - - object_class->dispose = dispose; } diff --git a/src/devices/wifi/exports.ver b/src/devices/wifi/exports.ver index d2c451244b..24cd848ce1 100644 --- a/src/devices/wifi/exports.ver +++ b/src/devices/wifi/exports.ver @@ -1,7 +1,6 @@ { global: nm_device_factory_create; - nm_device_factory_get_device_type; local: *; }; diff --git a/src/devices/wifi/nm-wifi-factory.c b/src/devices/wifi/nm-wifi-factory.c index 5d52d66c40..bca588e6eb 100644 --- a/src/devices/wifi/nm-wifi-factory.c +++ b/src/devices/wifi/nm-wifi-factory.c @@ -46,20 +46,12 @@ G_DEFINE_TYPE_EXTENDED (NMWifiFactory, nm_wifi_factory, G_TYPE_OBJECT, 0, /**************************************************************************/ -#define PLUGIN_TYPE NM_DEVICE_TYPE_WIFI - G_MODULE_EXPORT NMDeviceFactory * nm_device_factory_create (GError **error) { return (NMDeviceFactory *) g_object_new (NM_TYPE_WIFI_FACTORY, NULL); } -G_MODULE_EXPORT NMDeviceType -nm_device_factory_get_device_type (void) -{ - return PLUGIN_TYPE; -} - /**************************************************************************/ static NMDevice * @@ -72,10 +64,17 @@ new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error) return NULL; } +static NMDeviceType +get_device_type (NMDeviceFactory *factory) +{ + return NM_DEVICE_TYPE_WIFI; +} + static void device_factory_interface_init (NMDeviceFactory *factory_iface) { factory_iface->new_link = new_link; + factory_iface->get_device_type = get_device_type; } static void diff --git a/src/devices/wimax/exports.ver b/src/devices/wimax/exports.ver index d2c451244b..24cd848ce1 100644 --- a/src/devices/wimax/exports.ver +++ b/src/devices/wimax/exports.ver @@ -1,7 +1,6 @@ { global: nm_device_factory_create; - nm_device_factory_get_device_type; local: *; }; diff --git a/src/devices/wimax/nm-wimax-factory.c b/src/devices/wimax/nm-wimax-factory.c index e3aa0be676..9205919842 100644 --- a/src/devices/wimax/nm-wimax-factory.c +++ b/src/devices/wimax/nm-wimax-factory.c @@ -44,20 +44,12 @@ G_DEFINE_TYPE_EXTENDED (NMWimaxFactory, nm_wimax_factory, G_TYPE_OBJECT, 0, /**************************************************************************/ -#define PLUGIN_TYPE NM_DEVICE_TYPE_WIMAX - G_MODULE_EXPORT NMDeviceFactory * nm_device_factory_create (GError **error) { return (NMDeviceFactory *) g_object_new (NM_TYPE_WIMAX_FACTORY, NULL); } -G_MODULE_EXPORT NMDeviceType -nm_device_factory_get_device_type (void) -{ - return PLUGIN_TYPE; -} - /**************************************************************************/ static NMDevice * @@ -72,10 +64,17 @@ new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error) return (NMDevice *) nm_device_wimax_new (plink); } +static NMDeviceType +get_device_type (NMDeviceFactory *factory) +{ + return NM_DEVICE_TYPE_WIMAX; +} + static void device_factory_interface_init (NMDeviceFactory *factory_iface) { factory_iface->new_link = new_link; + factory_iface->get_device_type = get_device_type; } static void diff --git a/src/devices/wwan/exports.ver b/src/devices/wwan/exports.ver index d2c451244b..24cd848ce1 100644 --- a/src/devices/wwan/exports.ver +++ b/src/devices/wwan/exports.ver @@ -1,7 +1,6 @@ { global: nm_device_factory_create; - nm_device_factory_get_device_type; local: *; }; diff --git a/src/devices/wwan/nm-wwan-factory.c b/src/devices/wwan/nm-wwan-factory.c index b1e2307e6a..a2f3d3576a 100644 --- a/src/devices/wwan/nm-wwan-factory.c +++ b/src/devices/wwan/nm-wwan-factory.c @@ -43,20 +43,12 @@ typedef struct { /************************************************************************/ -#define PLUGIN_TYPE NM_DEVICE_TYPE_MODEM - G_MODULE_EXPORT NMDeviceFactory * nm_device_factory_create (GError **error) { return (NMDeviceFactory *) g_object_new (NM_TYPE_WWAN_FACTORY, NULL); } -G_MODULE_EXPORT NMDeviceType -nm_device_factory_get_device_type (void) -{ - return PLUGIN_TYPE; -} - /************************************************************************/ static void @@ -93,9 +85,17 @@ modem_added_cb (NMModemManager *manager, g_object_unref (device); } + +static NMDeviceType +get_device_type (NMDeviceFactory *factory) +{ + return NM_DEVICE_TYPE_MODEM; +} + static void -nm_wwan_factory_init (NMWwanFactory *self) +start (NMDeviceFactory *factory) { + NMWwanFactory *self = NM_WWAN_FACTORY (factory); NMWwanFactoryPrivate *priv = NM_WWAN_FACTORY_GET_PRIVATE (self); priv->mm = g_object_new (NM_TYPE_MODEM_MANAGER, NULL); @@ -107,8 +107,15 @@ nm_wwan_factory_init (NMWwanFactory *self) } static void +nm_wwan_factory_init (NMWwanFactory *self) +{ +} + +static void device_factory_interface_init (NMDeviceFactory *factory_iface) { + factory_iface->get_device_type = get_device_type; + factory_iface->start = start; } static void diff --git a/src/nm-manager.c b/src/nm-manager.c index 53cf4c26cb..5e89b59cc3 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -1873,7 +1873,6 @@ factory_component_added_cb (NMDeviceFactory *factory, #define PLUGIN_PREFIX "libnm-device-plugin-" #define PLUGIN_PATH_TAG "NMManager-plugin-path" -#define PLUGIN_TYPEFUNC_TAG "typefunc" struct read_device_factory_paths_data { char *path; @@ -1980,8 +1979,7 @@ load_device_factories (NMManager *self) GModule *plugin; NMDeviceFactory *factory; NMDeviceFactoryCreateFunc create_func; - NMDeviceFactoryDeviceTypeFunc type_func; - NMDeviceType dev_type; + NMDeviceType plugin_type; const char *found = NULL; GSList *iter; const char *item; @@ -1996,30 +1994,6 @@ load_device_factories (NMManager *self) continue; } - if (!g_module_symbol (plugin, "nm_device_factory_get_device_type", (gpointer) &type_func)) { - nm_log_warn (LOGD_HW, "(%s): failed to find device factory type: %s", item, g_module_error ()); - g_module_close (plugin); - continue; - } - - /* Make sure we don't double-load plugins */ - dev_type = type_func (); - for (iter = priv->factories; iter; iter = iter->next) { - NMDeviceFactoryDeviceTypeFunc loaded_type_func; - - loaded_type_func = g_object_get_data (G_OBJECT (iter->data), PLUGIN_TYPEFUNC_TAG); - if (dev_type == loaded_type_func ()) { - found = g_object_get_data (G_OBJECT (iter->data), PLUGIN_PATH_TAG); - break; - } - } - if (found) { - nm_log_warn (LOGD_HW, "Found multiple device plugins for same type: use '%s' instead of '%s'", - found, g_module_name (plugin)); - g_module_close (plugin); - continue; - } - if (!g_module_symbol (plugin, "nm_device_factory_create", (gpointer) &create_func)) { nm_log_warn (LOGD_HW, "(%s): failed to find device factory creator: %s", item, g_module_error ()); g_module_close (plugin); @@ -2036,6 +2010,21 @@ load_device_factories (NMManager *self) } g_clear_error (&error); + /* Make sure we don't double-register plugins */ + plugin_type = nm_device_factory_get_device_type (factory); + for (iter = priv->factories; iter; iter = iter->next) { + if (plugin_type == nm_device_factory_get_device_type (iter->data)) { + found = g_object_get_data (G_OBJECT (iter->data), PLUGIN_PATH_TAG); + break; + } + } + if (found) { + nm_log_warn (LOGD_HW, "Found multiple device plugins for same type: use '%s' instead of '%s'", + found, g_module_name (plugin)); + g_module_close (plugin); + continue; + } + g_module_make_resident (plugin); priv->factories = g_slist_prepend (priv->factories, factory); @@ -2049,7 +2038,6 @@ load_device_factories (NMManager *self) self); g_object_set_data_full (G_OBJECT (factory), PLUGIN_PATH_TAG, g_strdup (g_module_name (plugin)), g_free); - g_object_set_data (G_OBJECT (factory), PLUGIN_TYPEFUNC_TAG, type_func); nm_log_info (LOGD_HW, "Loaded device plugin: %s", g_module_name (plugin)); }; @@ -4144,6 +4132,7 @@ void nm_manager_start (NMManager *self) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); + GSList *iter; guint i; /* Set initial radio enabled/disabled state */ @@ -4174,6 +4163,10 @@ nm_manager_start (NMManager *self) system_unmanaged_devices_changed_cb (priv->settings, NULL, self); system_hostname_changed_cb (priv->settings, NULL, self); + /* Start device factories */ + for (iter = priv->factories; iter; iter = iter->next) + nm_device_factory_start (iter->data); + nm_platform_query_devices (); /* |