diff options
author | Dan Williams <dcbw@redhat.com> | 2014-05-02 11:04:21 -0500 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2014-05-13 13:50:25 -0500 |
commit | e62ac0d4691dea8c6e2da5f750228c00ab627b75 (patch) | |
tree | 3fcbf77621bbaa864cdeb53ffcedb2faf646855f | |
parent | 92be78c905c6def01260c2b2acdba041c2edf806 (diff) | |
download | NetworkManager-e62ac0d4691dea8c6e2da5f750228c00ab627b75.tar.gz |
devices: simplify plugin type checking
Instead of having a GObject property and a factory function to get
the plugin's device type, just use the factory function, since it
always has to be around.
-rw-r--r-- | src/devices/adsl/nm-atm-manager.c | 25 | ||||
-rw-r--r-- | src/devices/bluetooth/nm-bluez-manager.c | 25 | ||||
-rw-r--r-- | src/devices/nm-device-factory.c | 8 | ||||
-rw-r--r-- | src/devices/nm-device-factory.h | 3 | ||||
-rw-r--r-- | src/devices/wifi/nm-wifi-factory.c | 25 | ||||
-rw-r--r-- | src/devices/wimax/nm-wimax-factory.c | 25 | ||||
-rw-r--r-- | src/devices/wwan/nm-wwan-factory.c | 26 | ||||
-rw-r--r-- | src/nm-manager.c | 10 |
8 files changed, 5 insertions, 142 deletions
diff --git a/src/devices/adsl/nm-atm-manager.c b/src/devices/adsl/nm-atm-manager.c index 908e961e7d..e8db3596d7 100644 --- a/src/devices/adsl/nm-atm-manager.c +++ b/src/devices/adsl/nm-atm-manager.c @@ -44,12 +44,6 @@ static void device_factory_interface_init (NMDeviceFactory *factory_iface); G_DEFINE_TYPE_EXTENDED (NMAtmManager, nm_atm_manager, G_TYPE_OBJECT, 0, G_IMPLEMENT_INTERFACE (NM_TYPE_DEVICE_FACTORY, device_factory_interface_init)) -enum { - PROP_0, - PROP_DEVICE_TYPE, - LAST_PROP -}; - /**************************************************************************/ #define PLUGIN_TYPE NM_DEVICE_TYPE_ADSL @@ -238,20 +232,6 @@ device_factory_interface_init (NMDeviceFactory *factory_iface) } static void -get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec) -{ - switch (prop_id) { - case PROP_DEVICE_TYPE: - g_value_set_uint (value, PLUGIN_TYPE); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void dispose (GObject *object) { NMAtmManager *self = NM_ATM_MANAGER (object); @@ -283,9 +263,4 @@ nm_atm_manager_class_init (NMAtmManagerClass *klass) /* virtual methods */ object_class->dispose = dispose; - object_class->get_property = get_property; - - g_object_class_override_property (object_class, - PROP_DEVICE_TYPE, - NM_DEVICE_FACTORY_DEVICE_TYPE); } diff --git a/src/devices/bluetooth/nm-bluez-manager.c b/src/devices/bluetooth/nm-bluez-manager.c index 2857cc4e17..04ffb0a476 100644 --- a/src/devices/bluetooth/nm-bluez-manager.c +++ b/src/devices/bluetooth/nm-bluez-manager.c @@ -58,12 +58,6 @@ static void device_factory_interface_init (NMDeviceFactory *factory_iface); G_DEFINE_TYPE_EXTENDED (NMBluezManager, nm_bluez_manager, G_TYPE_OBJECT, 0, G_IMPLEMENT_INTERFACE (NM_TYPE_DEVICE_FACTORY, device_factory_interface_init)) -enum { - PROP_0, - PROP_DEVICE_TYPE, - LAST_PROP -}; - static void check_bluez_and_try_setup (NMBluezManager *self); /**************************************************************************/ @@ -377,20 +371,6 @@ check_bluez_and_try_setup (NMBluezManager *self) /*********************************************************************/ static void -get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec) -{ - switch (prop_id) { - case PROP_DEVICE_TYPE: - g_value_set_uint (value, PLUGIN_TYPE); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void dispose (GObject *object) { NMBluezManager *self = NM_BLUEZ_MANAGER (object); @@ -443,11 +423,6 @@ nm_bluez_manager_class_init (NMBluezManagerClass *klass) /* virtual methods */ object_class->dispose = dispose; - object_class->get_property = get_property; object_class->constructed = constructed; - - g_object_class_override_property (object_class, - PROP_DEVICE_TYPE, - NM_DEVICE_FACTORY_DEVICE_TYPE); } diff --git a/src/devices/nm-device-factory.c b/src/devices/nm-device-factory.c index e947b9da8e..fc4d1c248a 100644 --- a/src/devices/nm-device-factory.c +++ b/src/devices/nm-device-factory.c @@ -45,14 +45,6 @@ interface_init (gpointer g_iface) if (G_LIKELY (initialized)) return; - g_object_interface_install_property - (g_iface, - g_param_spec_uint (NM_DEVICE_FACTORY_DEVICE_TYPE, - "Device type", - "Device type", - 0, G_MAXUINT32, NM_DEVICE_TYPE_UNKNOWN, - G_PARAM_READABLE)); - /* Signals */ signals[DEVICE_ADDED] = g_signal_new (NM_DEVICE_FACTORY_DEVICE_ADDED, iface_type, diff --git a/src/devices/nm-device-factory.h b/src/devices/nm-device-factory.h index 45ae77a9fb..f0e3dc1978 100644 --- a/src/devices/nm-device-factory.h +++ b/src/devices/nm-device-factory.h @@ -69,9 +69,6 @@ typedef NMDeviceType (*NMDeviceFactoryDeviceTypeFunc) (void); #define NM_IS_DEVICE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_FACTORY)) #define NM_DEVICE_FACTORY_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), NM_TYPE_DEVICE_FACTORY, NMDeviceFactory)) -/* properties */ -#define NM_DEVICE_FACTORY_DEVICE_TYPE "device-type" - /* signals */ #define NM_DEVICE_FACTORY_COMPONENT_ADDED "component-added" #define NM_DEVICE_FACTORY_DEVICE_ADDED "device-added" diff --git a/src/devices/wifi/nm-wifi-factory.c b/src/devices/wifi/nm-wifi-factory.c index e4a140a324..02ad93f46d 100644 --- a/src/devices/wifi/nm-wifi-factory.c +++ b/src/devices/wifi/nm-wifi-factory.c @@ -43,11 +43,6 @@ static void device_factory_interface_init (NMDeviceFactory *factory_iface); G_DEFINE_TYPE_EXTENDED (NMWifiFactory, nm_wifi_factory, G_TYPE_OBJECT, 0, G_IMPLEMENT_INTERFACE (NM_TYPE_DEVICE_FACTORY, device_factory_interface_init)) -enum { - PROP_0, - PROP_DEVICE_TYPE, -}; - /**************************************************************************/ #define PLUGIN_TYPE NM_DEVICE_TYPE_WIFI @@ -77,19 +72,6 @@ new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error) } static void -get_property (GObject *object, guint prop, GValue *value, GParamSpec *pspec) -{ - switch (prop) { - case PROP_DEVICE_TYPE: - g_value_set_uint (value, PLUGIN_TYPE); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop, pspec); - break; - } -} - -static void device_factory_interface_init (NMDeviceFactory *factory_iface) { factory_iface->new_link = new_link; @@ -103,12 +85,5 @@ nm_wifi_factory_init (NMWifiFactory *self) static void nm_wifi_factory_class_init (NMWifiFactoryClass *wf_class) { - GObjectClass *object_class = G_OBJECT_CLASS (wf_class); - - object_class->get_property = get_property; - - g_object_class_override_property (object_class, - PROP_DEVICE_TYPE, - NM_DEVICE_FACTORY_DEVICE_TYPE); } diff --git a/src/devices/wimax/nm-wimax-factory.c b/src/devices/wimax/nm-wimax-factory.c index d5bf57f602..ca962e6866 100644 --- a/src/devices/wimax/nm-wimax-factory.c +++ b/src/devices/wimax/nm-wimax-factory.c @@ -71,24 +71,6 @@ new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error) return (NMDevice *) nm_device_wimax_new (plink); } -enum { - PROP_0 = 0x1000, - PROP_DEVICE_TYPE, -}; - -static void -get_property (GObject *object, guint prop, GValue *value, GParamSpec *pspec) -{ - switch (prop) { - case PROP_DEVICE_TYPE: - g_value_set_uint (value, PLUGIN_TYPE); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop, pspec); - break; - } -} - static void device_factory_interface_init (NMDeviceFactory *factory_iface) { @@ -103,12 +85,5 @@ nm_wimax_factory_init (NMWimaxFactory *factory) static void nm_wimax_factory_class_init (NMWimaxFactoryClass *wf_class) { - GObjectClass *object_class = G_OBJECT_CLASS (wf_class); - - object_class->get_property = get_property; - - g_object_class_override_property (object_class, - PROP_DEVICE_TYPE, - NM_DEVICE_FACTORY_DEVICE_TYPE); } diff --git a/src/devices/wwan/nm-wwan-factory.c b/src/devices/wwan/nm-wwan-factory.c index 8a7898942e..b1e2307e6a 100644 --- a/src/devices/wwan/nm-wwan-factory.c +++ b/src/devices/wwan/nm-wwan-factory.c @@ -41,13 +41,6 @@ typedef struct { NMModemManager *mm; } NMWwanFactoryPrivate; -enum { - PROP_0, - PROP_DEVICE_TYPE, - - LAST_PROP -}; - /************************************************************************/ #define PLUGIN_TYPE NM_DEVICE_TYPE_MODEM @@ -119,20 +112,6 @@ device_factory_interface_init (NMDeviceFactory *factory_iface) } static void -get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec) -{ - switch (prop_id) { - case PROP_DEVICE_TYPE: - g_value_set_uint (value, PLUGIN_TYPE); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void dispose (GObject *object) { NMWwanFactory *self = NM_WWAN_FACTORY (object); @@ -154,9 +133,4 @@ nm_wwan_factory_class_init (NMWwanFactoryClass *klass) g_type_class_add_private (object_class, sizeof (NMWwanFactoryPrivate)); object_class->dispose = dispose; - object_class->get_property = get_property; - - g_object_class_override_property (object_class, - PROP_DEVICE_TYPE, - NM_DEVICE_FACTORY_DEVICE_TYPE); } diff --git a/src/nm-manager.c b/src/nm-manager.c index 23661a5079..43eb2caf85 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -1804,6 +1804,7 @@ factory_component_added_cb (NMDeviceFactory *factory, #define PLUGIN_PREFIX "libnm-device-plugin-" #define PLUGIN_PATH_TAG "NMManager-plugin-path" +#define PLUGIN_TYPEFUNC_TAG "typefunc" static void load_device_factories (NMManager *self) @@ -1856,12 +1857,10 @@ load_device_factories (NMManager *self) /* Make sure we don't double-load plugins */ dev_type = type_func (); for (iter = priv->factories; iter; iter = iter->next) { - NMDeviceType t = NM_DEVICE_TYPE_UNKNOWN; + NMDeviceFactoryDeviceTypeFunc loaded_type_func; - g_object_get (G_OBJECT (iter->data), - NM_DEVICE_FACTORY_DEVICE_TYPE, &t, - NULL); - if (dev_type == t) { + 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; } @@ -1902,6 +1901,7 @@ 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)); }; |