diff options
author | Thomas Haller <thaller@redhat.com> | 2016-10-11 12:00:05 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-10-11 12:00:05 +0200 |
commit | 6ee7f429aa34c9379cd8583dd645bdec06a10064 (patch) | |
tree | c4f12ab0145e6085547711935abab8f8bead8a0c | |
parent | 85fe39e549bf33f04f5f20569a36e95573d810ee (diff) | |
parent | 2c26e3e7f9c2bb9afbf5d59a1ccc5622034e5cce (diff) | |
download | NetworkManager-6ee7f429aa34c9379cd8583dd645bdec06a10064.tar.gz |
device: merge branch 'th/device-factory-bgo772579'
https://bugzilla.gnome.org/show_bug.cgi?id=772579
-rw-r--r-- | src/Makefile.am | 57 | ||||
-rw-r--r-- | src/devices/adsl/nm-atm-manager.c | 63 | ||||
-rw-r--r-- | src/devices/bluetooth/nm-bluez-manager.c | 61 | ||||
-rw-r--r-- | src/devices/nm-device-bond.c | 6 | ||||
-rw-r--r-- | src/devices/nm-device-bridge.c | 6 | ||||
-rw-r--r-- | src/devices/nm-device-ethernet.c | 9 | ||||
-rw-r--r-- | src/devices/nm-device-factory.c | 108 | ||||
-rw-r--r-- | src/devices/nm-device-factory.h | 105 | ||||
-rw-r--r-- | src/devices/nm-device-infiniband.c | 12 | ||||
-rw-r--r-- | src/devices/nm-device-ip-tunnel.c | 10 | ||||
-rw-r--r-- | src/devices/nm-device-macvlan.c | 10 | ||||
-rw-r--r-- | src/devices/nm-device-tun.c | 7 | ||||
-rw-r--r-- | src/devices/nm-device-veth.c | 9 | ||||
-rw-r--r-- | src/devices/nm-device-vlan.c | 10 | ||||
-rw-r--r-- | src/devices/nm-device-vxlan.c | 11 | ||||
-rw-r--r-- | src/devices/team/nm-team-factory.c | 55 | ||||
-rw-r--r-- | src/devices/wifi/nm-wifi-factory.c | 55 | ||||
-rw-r--r-- | src/devices/wwan/nm-wwan-factory.c | 61 | ||||
-rw-r--r-- | src/nm-manager.c | 2 | ||||
-rw-r--r-- | src/tests/Makefile.am | 16 |
20 files changed, 300 insertions, 373 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 7d2a37f1b5..e1a0510346 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -259,38 +259,6 @@ libNetworkManagerBase_la_LIBADD = \ ############################################################################### -# These source files have a attribute((constructor)) to register their factories. -# This gets stripped out from the resulting binary if we add them to libNetworkManager.la. -# Instead, add them to the binary. An alternative would be to link with --as-needed. - -nm_device_sources = \ - devices/nm-device-bond.c \ - devices/nm-device-bridge.c \ - devices/nm-device-ethernet.c \ - devices/nm-device-infiniband.c \ - devices/nm-device-ip-tunnel.c \ - devices/nm-device-macvlan.c \ - devices/nm-device-tun.c \ - devices/nm-device-veth.c \ - devices/nm-device-vlan.c \ - devices/nm-device-vxlan.c \ - $(NULL) - -nm_device_headers = \ - devices/nm-device-bond.h \ - devices/nm-device-bridge.h \ - devices/nm-device-ethernet.h \ - devices/nm-device-infiniband.h \ - devices/nm-device-ip-tunnel.h \ - devices/nm-device-macvlan.h \ - devices/nm-device-tun.h \ - devices/nm-device-veth.h \ - devices/nm-device-vlan.h \ - devices/nm-device-vxlan.h \ - $(NULL) - -############################################################################### - libNetworkManager_la_SOURCES = \ \ nm-checkpoint-manager.c \ @@ -313,6 +281,27 @@ libNetworkManager_la_SOURCES = \ devices/nm-device-logging.h \ devices/nm-device-private.h \ \ + devices/nm-device-bond.c \ + devices/nm-device-bond.h \ + devices/nm-device-bridge.c \ + devices/nm-device-bridge.h \ + devices/nm-device-ethernet.c \ + devices/nm-device-ethernet.h \ + devices/nm-device-infiniband.c \ + devices/nm-device-infiniband.h \ + devices/nm-device-ip-tunnel.c \ + devices/nm-device-ip-tunnel.h \ + devices/nm-device-macvlan.c \ + devices/nm-device-macvlan.h \ + devices/nm-device-tun.c \ + devices/nm-device-tun.h \ + devices/nm-device-veth.c \ + devices/nm-device-veth.h \ + devices/nm-device-vlan.c \ + devices/nm-device-vlan.h \ + devices/nm-device-vxlan.c \ + devices/nm-device-vxlan.h \ + \ dhcp-manager/nm-dhcp-client.c \ dhcp-manager/nm-dhcp-client.h \ dhcp-manager/nm-dhcp-client-logging.h \ @@ -513,10 +502,6 @@ libNetworkManagerTest_la_LIBADD = \ ############################################################################### NetworkManager_SOURCES = \ - \ - $(nm_device_sources) \ - $(nm_device_headers) \ - \ main-utils.c \ main-utils.h \ main.c diff --git a/src/devices/adsl/nm-atm-manager.c b/src/devices/adsl/nm-atm-manager.c index 36f9635266..c70a6601b1 100644 --- a/src/devices/adsl/nm-atm-manager.c +++ b/src/devices/adsl/nm-atm-manager.c @@ -38,36 +38,32 @@ #define NM_IS_ATM_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_ATM_MANAGER)) #define NM_ATM_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_ATM_MANAGER, NMAtmManagerClass)) -typedef struct _NMAtmManager NMAtmManager; -typedef struct _NMAtmManagerClass NMAtmManagerClass; - -static GType nm_atm_manager_get_type (void); - -/*****************************************************************************/ - typedef struct { GUdevClient *client; GSList *devices; } NMAtmManagerPrivate; -struct _NMAtmManager { - GObject parent; +typedef struct { + NMDeviceFactory parent; NMAtmManagerPrivate _priv; -}; +} NMAtmManager; -struct _NMAtmManagerClass { - GObjectClass parent; -}; +typedef struct { + NMDeviceFactoryClass parent; +} NMAtmManagerClass; -static void device_factory_interface_init (NMDeviceFactoryInterface *factory_iface); +static GType nm_atm_manager_get_type (void); -G_DEFINE_TYPE_EXTENDED (NMAtmManager, nm_atm_manager, G_TYPE_OBJECT, 0, - G_IMPLEMENT_INTERFACE (NM_TYPE_DEVICE_FACTORY, device_factory_interface_init)) +G_DEFINE_TYPE (NMAtmManager, nm_atm_manager, NM_TYPE_DEVICE_FACTORY); #define NM_ATM_MANAGER_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMAtmManager, NM_IS_ATM_MANAGER) /*****************************************************************************/ +NM_DEVICE_FACTORY_DECLARE_TYPES ( + NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_ADSL_SETTING_NAME) +); + G_MODULE_EXPORT NMDeviceFactory * nm_device_factory_create (GError **error) { @@ -241,13 +237,19 @@ handle_uevent (GUdevClient *client, adsl_remove (self, device); } -NM_DEVICE_FACTORY_DECLARE_TYPES ( - NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_ADSL_SETTING_NAME) -) - /*****************************************************************************/ static void +nm_atm_manager_init (NMAtmManager *self) +{ + NMAtmManagerPrivate *priv = NM_ATM_MANAGER_GET_PRIVATE (self); + const char *subsys[] = { "atm", NULL }; + + priv->client = g_udev_client_new (subsys); + g_signal_connect (priv->client, "uevent", G_CALLBACK (handle_uevent), self); +} + +static void dispose (GObject *object) { NMAtmManager *self = NM_ATM_MANAGER (object); @@ -270,25 +272,10 @@ static void nm_atm_manager_class_init (NMAtmManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMDeviceFactoryClass *factory_class = NM_DEVICE_FACTORY_CLASS (klass); object_class->dispose = dispose; -} -/*****************************************************************************/ - -static void -nm_atm_manager_init (NMAtmManager *self) -{ - NMAtmManagerPrivate *priv = NM_ATM_MANAGER_GET_PRIVATE (self); - const char *subsys[] = { "atm", NULL }; - - priv->client = g_udev_client_new (subsys); - g_signal_connect (priv->client, "uevent", G_CALLBACK (handle_uevent), self); -} - -static void -device_factory_interface_init (NMDeviceFactoryInterface *factory_iface) -{ - factory_iface->get_supported_types = get_supported_types; - factory_iface->start = start; + factory_class->get_supported_types = get_supported_types; + factory_class->start = start; } diff --git a/src/devices/bluetooth/nm-bluez-manager.c b/src/devices/bluetooth/nm-bluez-manager.c index bc262eebdd..94e9ac387c 100644 --- a/src/devices/bluetooth/nm-bluez-manager.c +++ b/src/devices/bluetooth/nm-bluez-manager.c @@ -46,13 +46,6 @@ #define NM_IS_BLUEZ_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_BLUEZ_MANAGER)) #define NM_BLUEZ_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_BLUEZ_MANAGER, NMBluezManagerClass)) -typedef struct _NMBluezManager NMBluezManager; -typedef struct _NMBluezManagerClass NMBluezManagerClass; - -static GType nm_bluez_manager_get_type (void); - -/*****************************************************************************/ - typedef struct { int bluez_version; @@ -66,24 +59,36 @@ typedef struct { GCancellable *async_cancellable; } NMBluezManagerPrivate; -struct _NMBluezManager { - GObject parent; +typedef struct { + NMDeviceFactory parent; NMBluezManagerPrivate _priv; -}; +} NMBluezManager; -struct _NMBluezManagerClass { - GObjectClass parent; -}; +typedef struct { + NMDeviceFactoryClass parent; +} NMBluezManagerClass; -static void device_factory_interface_init (NMDeviceFactoryInterface *factory_iface); +static GType nm_bluez_manager_get_type (void); -G_DEFINE_TYPE_EXTENDED (NMBluezManager, nm_bluez_manager, G_TYPE_OBJECT, 0, - G_IMPLEMENT_INTERFACE (NM_TYPE_DEVICE_FACTORY, device_factory_interface_init)) +G_DEFINE_TYPE (NMBluezManager, nm_bluez_manager, NM_TYPE_DEVICE_FACTORY); #define NM_BLUEZ_MANAGER_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMBluezManager, NM_IS_BLUEZ_MANAGER) /*****************************************************************************/ +NM_DEVICE_FACTORY_DECLARE_TYPES ( + NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_BNEP) + NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_BLUETOOTH_SETTING_NAME) +) + +G_MODULE_EXPORT NMDeviceFactory * +nm_device_factory_create (GError **error) +{ + return (NMDeviceFactory *) g_object_new (NM_TYPE_BLUEZ_MANAGER, NULL); +} + +/*****************************************************************************/ + #define _NMLOG_DOMAIN LOGD_BT #define _NMLOG_PREFIX_NAME "bluez" #define _NMLOG(level, ...) \ @@ -411,11 +416,6 @@ create_device (NMDeviceFactory *factory, return NULL; } -NM_DEVICE_FACTORY_DECLARE_TYPES ( - NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_BNEP) - NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_BLUETOOTH_SETTING_NAME) -) - /*****************************************************************************/ static void @@ -454,22 +454,11 @@ static void nm_bluez_manager_class_init (NMBluezManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMDeviceFactoryClass *factory_class = NM_DEVICE_FACTORY_CLASS (klass); object_class->dispose = dispose; -} -static void -device_factory_interface_init (NMDeviceFactoryInterface *factory_iface) -{ - factory_iface->get_supported_types = get_supported_types; - factory_iface->create_device = create_device; - factory_iface->start = start; -} - -/*****************************************************************************/ - -G_MODULE_EXPORT NMDeviceFactory * -nm_device_factory_create (GError **error) -{ - return (NMDeviceFactory *) g_object_new (NM_TYPE_BLUEZ_MANAGER, NULL); + factory_class->get_supported_types = get_supported_types; + factory_class->create_device = create_device; + factory_class->start = start; } diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c index 2d1b986d87..ae029438c8 100644 --- a/src/devices/nm-device-bond.c +++ b/src/devices/nm-device-bond.c @@ -523,8 +523,8 @@ nm_device_bond_class_init (NMDeviceBondClass *klass) /*****************************************************************************/ -#define NM_TYPE_BOND_FACTORY (nm_bond_factory_get_type ()) -#define NM_BOND_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_BOND_FACTORY, NMBondFactory)) +#define NM_TYPE_BOND_DEVICE_FACTORY (nm_bond_device_factory_get_type ()) +#define NM_BOND_DEVICE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_BOND_DEVICE_FACTORY, NMBondDeviceFactory)) static NMDevice * create_device (NMDeviceFactory *factory, @@ -546,5 +546,5 @@ create_device (NMDeviceFactory *factory, NM_DEVICE_FACTORY_DEFINE_INTERNAL (BOND, Bond, bond, NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_BOND) NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_BOND_SETTING_NAME), - factory_iface->create_device = create_device; + factory_class->create_device = create_device; ); diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c index f5c236bd80..682c260b17 100644 --- a/src/devices/nm-device-bridge.c +++ b/src/devices/nm-device-bridge.c @@ -451,8 +451,8 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *klass) /*****************************************************************************/ -#define NM_TYPE_BRIDGE_FACTORY (nm_bridge_factory_get_type ()) -#define NM_BRIDGE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_BRIDGE_FACTORY, NMBridgeFactory)) +#define NM_TYPE_BRIDGE_DEVICE_FACTORY (nm_bridge_device_factory_get_type ()) +#define NM_BRIDGE_DEVICE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_BRIDGE_DEVICE_FACTORY, NMBridgeDeviceFactory)) static NMDevice * create_device (NMDeviceFactory *factory, @@ -474,5 +474,5 @@ create_device (NMDeviceFactory *factory, NM_DEVICE_FACTORY_DEFINE_INTERNAL (BRIDGE, Bridge, bridge, NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_BRIDGE) NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_BRIDGE_SETTING_NAME), - factory_iface->create_device = create_device; + factory_class->create_device = create_device; ); diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index 83d0af1fe6..a4a560f049 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -1677,8 +1677,8 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass) /*****************************************************************************/ -#define NM_TYPE_ETHERNET_FACTORY (nm_ethernet_factory_get_type ()) -#define NM_ETHERNET_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_ETHERNET_FACTORY, NMEthernetFactory)) +#define NM_TYPE_ETHERNET_DEVICE_FACTORY (nm_ethernet_device_factory_get_type ()) +#define NM_ETHERNET_DEVICE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_ETHERNET_DEVICE_FACTORY, NMEthernetDeviceFactory)) static NMDevice * create_device (NMDeviceFactory *factory, @@ -1698,6 +1698,5 @@ create_device (NMDeviceFactory *factory, NM_DEVICE_FACTORY_DEFINE_INTERNAL (ETHERNET, Ethernet, ethernet, NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_ETHERNET) NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_PPPOE_SETTING_NAME), - factory_iface->create_device = create_device; - ) - + factory_class->create_device = create_device; +); diff --git a/src/devices/nm-device-factory.c b/src/devices/nm-device-factory.c index d75de4963c..1f65300861 100644 --- a/src/devices/nm-device-factory.c +++ b/src/devices/nm-device-factory.c @@ -19,33 +19,45 @@ */ #include "nm-default.h" + +#include "nm-device-factory.h" + #include <sys/types.h> #include <sys/stat.h> #include <errno.h> #include <string.h> #include <gmodule.h> -#include "nm-device-factory.h" #include "nm-platform.h" #include "nm-utils.h" +/*****************************************************************************/ + const NMLinkType _nm_device_factory_no_default_links[] = { NM_LINK_TYPE_NONE }; const char *_nm_device_factory_no_default_settings[] = { NULL }; -G_DEFINE_INTERFACE (NMDeviceFactory, nm_device_factory, G_TYPE_OBJECT) +/*****************************************************************************/ enum { DEVICE_ADDED, COMPONENT_ADDED, LAST_SIGNAL }; + static guint signals[LAST_SIGNAL] = { 0 }; +G_DEFINE_ABSTRACT_TYPE (NMDeviceFactory, nm_device_factory, G_TYPE_OBJECT) + +/*****************************************************************************/ + gboolean nm_device_factory_emit_component_added (NMDeviceFactory *factory, GObject *component) { gboolean consumed = FALSE; + g_return_val_if_fail (NM_IS_DEVICE_FACTORY (factory), FALSE); + g_return_val_if_fail (G_IS_OBJECT (component), FALSE); + g_signal_emit (factory, signals[COMPONENT_ADDED], 0, component, &consumed); return consumed; } @@ -58,16 +70,16 @@ nm_device_factory_get_supported_types (NMDeviceFactory *factory, const NMLinkType *link_types_fallback; const char **setting_types_fallback; - g_return_if_fail (factory != NULL); + g_return_if_fail (NM_IS_DEVICE_FACTORY (factory)); if (!out_link_types) out_link_types = &link_types_fallback; if (!out_setting_types) out_setting_types = &setting_types_fallback; - NM_DEVICE_FACTORY_GET_INTERFACE (factory)->get_supported_types (factory, - out_link_types, - out_setting_types); + NM_DEVICE_FACTORY_GET_CLASS (factory)->get_supported_types (factory, + out_link_types, + out_setting_types); } void @@ -75,8 +87,8 @@ 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); + if (NM_DEVICE_FACTORY_GET_CLASS (factory)->start) + NM_DEVICE_FACTORY_GET_CLASS (factory)->start (factory); } NMDevice * @@ -87,7 +99,7 @@ nm_device_factory_create_device (NMDeviceFactory *factory, gboolean *out_ignore, GError **error) { - NMDeviceFactoryInterface *interface; + NMDeviceFactoryClass *klass; const NMLinkType *link_types = NULL; const char **setting_types = NULL; int i; @@ -133,15 +145,15 @@ nm_device_factory_create_device (NMDeviceFactory *factory, } } - interface = NM_DEVICE_FACTORY_GET_INTERFACE (factory); - if (!interface->create_device) { + klass = NM_DEVICE_FACTORY_GET_CLASS (factory); + if (!klass->create_device) { g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED, "Device factory %s cannot manage new devices", G_OBJECT_TYPE_NAME (factory)); return NULL; } - device = interface->create_device (factory, iface, plink, connection, &ignore); + device = klass->create_device (factory, iface, plink, connection, &ignore); NM_SET_OUT (out_ignore, ignore); if (!device) { if (ignore) { @@ -167,8 +179,8 @@ nm_device_factory_get_connection_parent (NMDeviceFactory *factory, if (!nm_connection_is_virtual (connection)) return NULL; - if (NM_DEVICE_FACTORY_GET_INTERFACE (factory)->get_connection_parent) - return NM_DEVICE_FACTORY_GET_INTERFACE (factory)->get_connection_parent (factory, connection); + if (NM_DEVICE_FACTORY_GET_CLASS (factory)->get_connection_parent) + return NM_DEVICE_FACTORY_GET_CLASS (factory)->get_connection_parent (factory, connection); return NULL; } @@ -178,14 +190,14 @@ nm_device_factory_get_connection_iface (NMDeviceFactory *factory, const char *parent_iface, GError **error) { - NMDeviceFactoryInterface *klass; + NMDeviceFactoryClass *klass; char *ifname; g_return_val_if_fail (factory != NULL, NULL); g_return_val_if_fail (connection != NULL, NULL); g_return_val_if_fail (!error || !*error, NULL); - klass = NM_DEVICE_FACTORY_GET_INTERFACE (factory); + klass = NM_DEVICE_FACTORY_GET_CLASS (factory); ifname = g_strdup (nm_connection_get_interface_name (connection)); if (!ifname && klass->get_connection_iface) @@ -216,41 +228,38 @@ nm_device_factory_get_connection_iface (NMDeviceFactory *factory, /*****************************************************************************/ static void -nm_device_factory_default_init (NMDeviceFactoryInterface *factory_iface) +nm_device_factory_init (NMDeviceFactory *self) +{ +} + +static void +nm_device_factory_class_init (NMDeviceFactoryClass *klass) { - /* Signals */ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + signals[DEVICE_ADDED] = g_signal_new (NM_DEVICE_FACTORY_DEVICE_ADDED, - NM_TYPE_DEVICE_FACTORY, + G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMDeviceFactoryInterface, device_added), + G_STRUCT_OFFSET (NMDeviceFactoryClass, device_added), NULL, NULL, NULL, G_TYPE_NONE, 1, NM_TYPE_DEVICE); signals[COMPONENT_ADDED] = g_signal_new (NM_DEVICE_FACTORY_COMPONENT_ADDED, - NM_TYPE_DEVICE_FACTORY, + G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (NMDeviceFactoryInterface, component_added), + G_STRUCT_OFFSET (NMDeviceFactoryClass, component_added), g_signal_accumulator_true_handled, NULL, NULL, G_TYPE_BOOLEAN, 1, G_TYPE_OBJECT); } /*****************************************************************************/ -static GSList *internal_types = NULL; static GHashTable *factories_by_link = NULL; static GHashTable *factories_by_setting = NULL; -void -_nm_device_factory_internal_register_type (GType factory_type) -{ - g_return_if_fail (g_slist_find (internal_types, GUINT_TO_POINTER (factory_type)) == NULL); - internal_types = g_slist_prepend (internal_types, GUINT_TO_POINTER (factory_type)); -} - static void __attribute__((destructor)) _cleanup (void) { - g_clear_pointer (&internal_types, g_slist_free); g_clear_pointer (&factories_by_link, g_hash_table_unref); g_clear_pointer (&factories_by_setting, g_hash_table_unref); } @@ -463,12 +472,22 @@ _add_factory (NMDeviceFactory *factory, return TRUE; } +static void +_load_internal_factory (GType factory_gtype, + NMDeviceFactoryManagerFactoryFunc callback, + gpointer user_data) +{ + NMDeviceFactory *factory; + + factory = (NMDeviceFactory *) g_object_new (factory_gtype, NULL); + _add_factory (factory, FALSE, "internal", callback, user_data); +} + void nm_device_factory_manager_load_factories (NMDeviceFactoryManagerFactoryFunc callback, gpointer user_data) { NMDeviceFactory *factory; - const GSList *iter; GError *error = NULL; char **path, **paths; @@ -478,14 +497,23 @@ nm_device_factory_manager_load_factories (NMDeviceFactoryManagerFactoryFunc call factories_by_link = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref); factories_by_setting = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); - /* Register internal factories first */ - for (iter = internal_types; iter; iter = iter->next) { - GType ftype = (GType) GPOINTER_TO_SIZE (iter->data); - - factory = (NMDeviceFactory *) g_object_new (ftype, NULL); - g_assert (factory); - _add_factory (factory, FALSE, "internal", callback, user_data); - } +#define _ADD_INTERNAL(get_type_fcn) \ + G_STMT_START { \ + GType get_type_fcn (void); \ + _load_internal_factory (get_type_fcn (), \ + callback, user_data); \ + } G_STMT_END + + _ADD_INTERNAL (nm_bond_device_factory_get_type); + _ADD_INTERNAL (nm_bridge_device_factory_get_type); + _ADD_INTERNAL (nm_ethernet_device_factory_get_type); + _ADD_INTERNAL (nm_infiniband_device_factory_get_type); + _ADD_INTERNAL (nm_ip_tunnel_device_factory_get_type); + _ADD_INTERNAL (nm_macvlan_device_factory_get_type); + _ADD_INTERNAL (nm_tun_device_factory_get_type); + _ADD_INTERNAL (nm_veth_device_factory_get_type); + _ADD_INTERNAL (nm_vlan_device_factory_get_type); + _ADD_INTERNAL (nm_vxlan_device_factory_get_type); paths = read_device_factory_paths (); if (!paths) diff --git a/src/devices/nm-device-factory.h b/src/devices/nm-device-factory.h index 0179e85534..2faaad9df6 100644 --- a/src/devices/nm-device-factory.h +++ b/src/devices/nm-device-factory.h @@ -30,37 +30,22 @@ * not meant to enable third-party plugins. */ -typedef struct _NMDeviceFactory NMDeviceFactory; +#define NM_TYPE_DEVICE_FACTORY (nm_device_factory_get_type ()) +#define NM_DEVICE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_FACTORY, NMDeviceFactory)) +#define NM_DEVICE_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_FACTORY, NMDeviceFactoryClass)) +#define NM_IS_DEVICE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_FACTORY)) +#define NM_IS_DEVICE_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_FACTORY)) +#define NM_DEVICE_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_FACTORY, NMDeviceFactoryClass)) -/** - * nm_device_factory_create: - * @error: an error if creation of the factory failed, or %NULL - * - * 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 the "start" interface method. - * - * Returns: the #GObject implementing #NMDeviceFactory or %NULL - */ -NMDeviceFactory *nm_device_factory_create (GError **error); - -/* Should match nm_device_factory_create() */ -typedef NMDeviceFactory * (*NMDeviceFactoryCreateFunc) (GError **error); - -/*****************************************************************************/ - -#define NM_TYPE_DEVICE_FACTORY (nm_device_factory_get_type ()) -#define NM_DEVICE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_FACTORY, NMDeviceFactory)) -#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, NMDeviceFactoryInterface)) - -/* signals */ #define NM_DEVICE_FACTORY_COMPONENT_ADDED "component-added" #define NM_DEVICE_FACTORY_DEVICE_ADDED "device-added" typedef struct { - GTypeInterface g_iface; + GObject parent; +} NMDeviceFactory; + +typedef struct { + GObjectClass parent; /** * get_supported_types: @@ -164,10 +149,31 @@ typedef struct { * Returns: %TRUE if the component was claimed by a device, %FALSE if not */ gboolean (*component_added) (NMDeviceFactory *factory, GObject *component); -} NMDeviceFactoryInterface; + +} NMDeviceFactoryClass; GType nm_device_factory_get_type (void); +/*****************************************************************************/ + +/** + * nm_device_factory_create: + * @error: an error if creation of the factory failed, or %NULL + * + * 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 the "start" interface method. + * + * Returns: the #GObject implementing #NMDeviceFactory or %NULL + */ +NMDeviceFactory *nm_device_factory_create (GError **error); + +/* Should match nm_device_factory_create() */ +typedef NMDeviceFactory * (*NMDeviceFactoryCreateFunc) (GError **error); + +/*****************************************************************************/ + void nm_device_factory_get_supported_types (NMDeviceFactory *factory, const NMLinkType **out_link_types, const char ***out_setting_types); @@ -180,7 +186,7 @@ char * nm_device_factory_get_connection_iface (NMDeviceFactory *factory, const char *parent_iface, GError **error); -void nm_device_factory_start (NMDeviceFactory *factory); +void nm_device_factory_start (NMDeviceFactory *factory); NMDevice * nm_device_factory_create_device (NMDeviceFactory *factory, const char *iface, @@ -220,48 +226,33 @@ extern const char *_nm_device_factory_no_default_settings[]; **************************************************************************/ #define NM_DEVICE_FACTORY_DEFINE_INTERNAL(upper, mixed, lower, st_code, dfi_code) \ - typedef GObject NM##mixed##Factory; \ - typedef GObjectClass NM##mixed##FactoryClass; \ + typedef struct { \ + NMDeviceFactory parent; \ + } NM##mixed##DeviceFactory; \ + typedef struct { \ + NMDeviceFactoryClass parent; \ + } NM##mixed##DeviceFactoryClass; \ \ - static GType nm_##lower##_factory_get_type (void); \ - static void device_factory_interface_init (NMDeviceFactoryInterface *factory_iface); \ + GType nm_##lower##_device_factory_get_type (void); \ \ - G_DEFINE_TYPE_EXTENDED (NM##mixed##Factory, nm_##lower##_factory, G_TYPE_OBJECT, 0, \ - G_IMPLEMENT_INTERFACE (NM_TYPE_DEVICE_FACTORY, device_factory_interface_init) \ - _nm_device_factory_internal_register_type (g_define_type_id);) \ - \ - /* Use a module constructor to register the factory's GType at load \ - * time, which then calls _nm_device_factory_internal_register_type() \ - * to register the factory's GType with the Manager. \ - */ \ - static void __attribute__((constructor)) \ - register_device_factory_internal_##lower (void) \ - { \ - nm_g_type_init (); \ - g_type_ensure (NM_TYPE_##upper##_FACTORY); \ - } \ + G_DEFINE_TYPE (NM##mixed##DeviceFactory, nm_##lower##_device_factory, NM_TYPE_DEVICE_FACTORY) \ \ NM_DEVICE_FACTORY_DECLARE_TYPES(st_code) \ \ static void \ - device_factory_interface_init (NMDeviceFactoryInterface *factory_iface) \ + nm_##lower##_device_factory_init (NM##mixed##DeviceFactory *self) \ { \ - factory_iface->get_supported_types = get_supported_types; \ - dfi_code \ } \ \ static void \ - nm_##lower##_factory_init (NM##mixed##Factory *self) \ - { \ - } \ - \ - static void \ - nm_##lower##_factory_class_init (NM##mixed##FactoryClass *lower##_class) \ + nm_##lower##_device_factory_class_init (NM##mixed##DeviceFactoryClass *klass) \ { \ + NMDeviceFactoryClass *factory_class = NM_DEVICE_FACTORY_CLASS (klass); \ + \ + factory_class->get_supported_types = get_supported_types; \ + dfi_code \ } -void _nm_device_factory_internal_register_type (GType factory_type); - /************************************************************************** * PRIVATE FACTORY FUNCTIONS - for factory consumers (eg, NMManager). **************************************************************************/ diff --git a/src/devices/nm-device-infiniband.c b/src/devices/nm-device-infiniband.c index 56bdcb6de0..bc6051569c 100644 --- a/src/devices/nm-device-infiniband.c +++ b/src/devices/nm-device-infiniband.c @@ -402,8 +402,8 @@ nm_device_infiniband_class_init (NMDeviceInfinibandClass *klass) /*****************************************************************************/ -#define NM_TYPE_INFINIBAND_FACTORY (nm_infiniband_factory_get_type ()) -#define NM_INFINIBAND_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_INFINIBAND_FACTORY, NMInfinibandFactory)) +#define NM_TYPE_INFINIBAND_DEVICE_FACTORY (nm_infiniband_device_factory_get_type ()) +#define NM_INFINIBAND_DEVICE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_INFINIBAND_DEVICE_FACTORY, NMInfinibandDeviceFactory)) static NMDevice * create_device (NMDeviceFactory *factory, @@ -472,7 +472,7 @@ get_connection_iface (NMDeviceFactory *factory, NM_DEVICE_FACTORY_DEFINE_INTERNAL (INFINIBAND, Infiniband, infiniband, NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_INFINIBAND) NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_INFINIBAND_SETTING_NAME), - factory_iface->create_device = create_device; - factory_iface->get_connection_parent = get_connection_parent; - factory_iface->get_connection_iface = get_connection_iface; -) + factory_class->create_device = create_device; + factory_class->get_connection_parent = get_connection_parent; + factory_class->get_connection_iface = get_connection_iface; +); diff --git a/src/devices/nm-device-ip-tunnel.c b/src/devices/nm-device-ip-tunnel.c index 036e3ea4d7..0aef9d2ef9 100644 --- a/src/devices/nm-device-ip-tunnel.c +++ b/src/devices/nm-device-ip-tunnel.c @@ -981,8 +981,8 @@ nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *klass) /*****************************************************************************/ -#define NM_TYPE_IP_TUNNEL_FACTORY (nm_ip_tunnel_factory_get_type ()) -#define NM_IP_TUNNEL_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_IP_TUNNEL_FACTORY, NMIPTunnelFactory)) +#define NM_TYPE_IP_TUNNEL_DEVICE_FACTORY (nm_ip_tunnel_device_factory_get_type ()) +#define NM_IP_TUNNEL_DEVICE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_IP_TUNNEL_DEVICE_FACTORY, NMIPTunnelDeviceFactory)) static NMDevice * create_device (NMDeviceFactory *factory, @@ -1053,7 +1053,7 @@ get_connection_iface (NMDeviceFactory *factory, NM_DEVICE_FACTORY_DEFINE_INTERNAL (IP_TUNNEL, IPTunnel, ip_tunnel, NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_GRE, NM_LINK_TYPE_SIT, NM_LINK_TYPE_IPIP) NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_IP_TUNNEL_SETTING_NAME), - factory_iface->create_device = create_device; - factory_iface->get_connection_parent = get_connection_parent; - factory_iface->get_connection_iface = get_connection_iface; + factory_class->create_device = create_device; + factory_class->get_connection_parent = get_connection_parent; + factory_class->get_connection_iface = get_connection_iface; ); diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c index 2cfd2492a6..9e32694ffd 100644 --- a/src/devices/nm-device-macvlan.c +++ b/src/devices/nm-device-macvlan.c @@ -658,8 +658,8 @@ nm_device_macvlan_class_init (NMDeviceMacvlanClass *klass) /*****************************************************************************/ -#define NM_TYPE_MACVLAN_FACTORY (nm_macvlan_factory_get_type ()) -#define NM_MACVLAN_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_MACVLAN_FACTORY, NMMacvlanFactory)) +#define NM_TYPE_MACVLAN_DEVICE_FACTORY (nm_macvlan_device_factory_get_type ()) +#define NM_MACVLAN_DEVICE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_MACVLAN_DEVICE_FACTORY, NMMacvlanDeviceFactory)) static NMDevice * create_device (NMDeviceFactory *factory, @@ -739,7 +739,7 @@ get_connection_iface (NMDeviceFactory *factory, NM_DEVICE_FACTORY_DEFINE_INTERNAL (MACVLAN, Macvlan, macvlan, NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_MACVLAN, NM_LINK_TYPE_MACVTAP) NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_MACVLAN_SETTING_NAME), - factory_iface->create_device = create_device; - factory_iface->get_connection_parent = get_connection_parent; - factory_iface->get_connection_iface = get_connection_iface; + factory_class->create_device = create_device; + factory_class->get_connection_parent = get_connection_parent; + factory_class->get_connection_iface = get_connection_iface; ); diff --git a/src/devices/nm-device-tun.c b/src/devices/nm-device-tun.c index 2bed672b5f..d32caa402d 100644 --- a/src/devices/nm-device-tun.c +++ b/src/devices/nm-device-tun.c @@ -485,8 +485,8 @@ nm_device_tun_class_init (NMDeviceTunClass *klass) /*****************************************************************************/ -#define NM_TYPE_TUN_FACTORY (nm_tun_factory_get_type ()) -#define NM_TUN_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_TUN_FACTORY, NMTunFactory)) +#define NM_TYPE_TUN_DEVICE_FACTORY (nm_tun_device_factory_get_type ()) +#define NM_TUN_DEVICE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_TUN_DEVICE_FACTORY, NMTunDeviceFactory)) static NMDevice * create_device (NMDeviceFactory *factory, @@ -532,6 +532,5 @@ create_device (NMDeviceFactory *factory, NM_DEVICE_FACTORY_DEFINE_INTERNAL (TUN, Tun, tun, NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_TUN, NM_LINK_TYPE_TAP) NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_TUN_SETTING_NAME), - factory_iface->create_device = create_device; + factory_class->create_device = create_device; ); - diff --git a/src/devices/nm-device-veth.c b/src/devices/nm-device-veth.c index 0407c2a47e..bb23fdaa6c 100644 --- a/src/devices/nm-device-veth.c +++ b/src/devices/nm-device-veth.c @@ -182,8 +182,8 @@ nm_device_veth_class_init (NMDeviceVethClass *klass) /*****************************************************************************/ -#define NM_TYPE_VETH_FACTORY (nm_veth_factory_get_type ()) -#define NM_VETH_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VETH_FACTORY, NMVethFactory)) +#define NM_TYPE_VETH_DEVICE_FACTORY (nm_veth_device_factory_get_type ()) +#define NM_VETH_DEVICE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VETH_DEVICE_FACTORY, NMVethDeviceFactory)) static NMDevice * create_device (NMDeviceFactory *factory, @@ -202,6 +202,5 @@ create_device (NMDeviceFactory *factory, NM_DEVICE_FACTORY_DEFINE_INTERNAL (VETH, Veth, veth, NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_VETH), - factory_iface->create_device = create_device; - ) - + factory_class->create_device = create_device; +); diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c index 1c2f6dd70a..0f241e8388 100644 --- a/src/devices/nm-device-vlan.c +++ b/src/devices/nm-device-vlan.c @@ -688,8 +688,8 @@ nm_device_vlan_class_init (NMDeviceVlanClass *klass) /*****************************************************************************/ -#define NM_TYPE_VLAN_FACTORY (nm_vlan_factory_get_type ()) -#define NM_VLAN_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VLAN_FACTORY, NMVlanFactory)) +#define NM_TYPE_VLAN_DEVICE_FACTORY (nm_vlan_device_factory_get_type ()) +#define NM_VLAN_DEVICE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VLAN_DEVICE_FACTORY, NMVlanDeviceFactory)) static NMDevice * create_device (NMDeviceFactory *factory, @@ -761,7 +761,7 @@ get_connection_iface (NMDeviceFactory *factory, NM_DEVICE_FACTORY_DEFINE_INTERNAL (VLAN, Vlan, vlan, NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_VLAN) NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_VLAN_SETTING_NAME), - factory_iface->create_device = create_device; - factory_iface->get_connection_parent = get_connection_parent; - factory_iface->get_connection_iface = get_connection_iface; + factory_class->create_device = create_device; + factory_class->get_connection_parent = get_connection_parent; + factory_class->get_connection_iface = get_connection_iface; ); diff --git a/src/devices/nm-device-vxlan.c b/src/devices/nm-device-vxlan.c index 1113a5b8b1..a49e64c6af 100644 --- a/src/devices/nm-device-vxlan.c +++ b/src/devices/nm-device-vxlan.c @@ -763,8 +763,8 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *klass) /*****************************************************************************/ -#define NM_TYPE_VXLAN_FACTORY (nm_vxlan_factory_get_type ()) -#define NM_VXLAN_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VXLAN_FACTORY, NMVxlanFactory)) +#define NM_TYPE_VXLAN_DEVICE_FACTORY (nm_vxlan_device_factory_get_type ()) +#define NM_VXLAN_DEVICE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VXLAN_DEVICE_FACTORY, NMVxlanDeviceFactory)) static NMDevice * create_device (NMDeviceFactory *factory, @@ -817,8 +817,7 @@ get_connection_iface (NMDeviceFactory *factory, NM_DEVICE_FACTORY_DEFINE_INTERNAL (VXLAN, Vxlan, vxlan, NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_VXLAN) NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_VXLAN_SETTING_NAME), - factory_iface->create_device = create_device; - factory_iface->get_connection_parent = get_connection_parent; - factory_iface->get_connection_iface = get_connection_iface; + factory_class->create_device = create_device; + factory_class->get_connection_parent = get_connection_parent; + factory_class->get_connection_iface = get_connection_iface; ); - diff --git a/src/devices/team/nm-team-factory.c b/src/devices/team/nm-team-factory.c index 97275f7ef7..4a6f7b54c1 100644 --- a/src/devices/team/nm-team-factory.c +++ b/src/devices/team/nm-team-factory.c @@ -38,25 +38,31 @@ #define NM_IS_TEAM_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_TEAM_FACTORY)) #define NM_TEAM_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_TEAM_FACTORY, NMTeamFactoryClass)) -typedef struct _NMTeamFactory NMTeamFactory; -typedef struct _NMTeamFactoryClass NMTeamFactoryClass; +typedef struct { + NMDeviceFactory parent; +} NMTeamFactory; -static GType nm_team_factory_get_type (void); +typedef struct { + NMDeviceFactoryClass parent; +} NMTeamFactoryClass; -/*****************************************************************************/ +static GType nm_team_factory_get_type (void); -struct _NMTeamFactory { - GObject parent; -}; +G_DEFINE_TYPE (NMTeamFactory, nm_team_factory, NM_TYPE_DEVICE_FACTORY) -struct _NMTeamFactoryClass { - GObjectClass parent; -}; +/*****************************************************************************/ -static void device_factory_interface_init (NMDeviceFactoryInterface *factory_iface); +NM_DEVICE_FACTORY_DECLARE_TYPES ( + NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_TEAM) + NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_TEAM_SETTING_NAME) +) -G_DEFINE_TYPE_EXTENDED (NMTeamFactory, nm_team_factory, G_TYPE_OBJECT, 0, - G_IMPLEMENT_INTERFACE (NM_TYPE_DEVICE_FACTORY, device_factory_interface_init)) +G_MODULE_EXPORT NMDeviceFactory * +nm_device_factory_create (GError **error) +{ + nm_manager_set_capability (nm_manager_get (), NM_CAPABILITY_TEAM); + return (NMDeviceFactory *) g_object_new (NM_TYPE_TEAM_FACTORY, NULL); +} /*****************************************************************************/ @@ -70,11 +76,6 @@ create_device (NMDeviceFactory *factory, return nm_device_team_new (iface); } -NM_DEVICE_FACTORY_DECLARE_TYPES ( - NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_TEAM) - NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_TEAM_SETTING_NAME) -) - /*****************************************************************************/ static void @@ -85,20 +86,8 @@ nm_team_factory_init (NMTeamFactory *self) static void nm_team_factory_class_init (NMTeamFactoryClass *klass) { -} - -static void -device_factory_interface_init (NMDeviceFactoryInterface *factory_iface) -{ - factory_iface->create_device = create_device; - factory_iface->get_supported_types = get_supported_types; -} + NMDeviceFactoryClass *factory_class = NM_DEVICE_FACTORY_CLASS (klass); -/*****************************************************************************/ - -G_MODULE_EXPORT NMDeviceFactory * -nm_device_factory_create (GError **error) -{ - nm_manager_set_capability (nm_manager_get (), NM_CAPABILITY_TEAM); - return (NMDeviceFactory *) g_object_new (NM_TYPE_TEAM_FACTORY, NULL); + factory_class->create_device = create_device; + factory_class->get_supported_types = get_supported_types; } diff --git a/src/devices/wifi/nm-wifi-factory.c b/src/devices/wifi/nm-wifi-factory.c index 0622a834b4..64ecca0827 100644 --- a/src/devices/wifi/nm-wifi-factory.c +++ b/src/devices/wifi/nm-wifi-factory.c @@ -39,25 +39,30 @@ #define NM_IS_WIFI_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_WIFI_FACTORY)) #define NM_WIFI_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_WIFI_FACTORY, NMWifiFactoryClass)) -typedef struct _NMWifiFactory NMWifiFactory; -typedef struct _NMWifiFactoryClass NMWifiFactoryClass; +typedef struct { + NMDeviceFactory parent; +} NMWifiFactory; -static GType nm_wifi_factory_get_type (void); +typedef struct { + NMDeviceFactoryClass parent; +} NMWifiFactoryClass; -/*****************************************************************************/ +static GType nm_wifi_factory_get_type (void); -struct _NMWifiFactory { - GObject parent; -}; +G_DEFINE_TYPE (NMWifiFactory, nm_wifi_factory, NM_TYPE_DEVICE_FACTORY) -struct _NMWifiFactoryClass { - GObjectClass parent; -}; +/*****************************************************************************/ -static void device_factory_interface_init (NMDeviceFactoryInterface *factory_iface); +NM_DEVICE_FACTORY_DECLARE_TYPES ( + NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_WIFI, NM_LINK_TYPE_OLPC_MESH) + NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_OLPC_MESH_SETTING_NAME) +) -G_DEFINE_TYPE_EXTENDED (NMWifiFactory, nm_wifi_factory, G_TYPE_OBJECT, 0, - G_IMPLEMENT_INTERFACE (NM_TYPE_DEVICE_FACTORY, device_factory_interface_init)) +G_MODULE_EXPORT NMDeviceFactory * +nm_device_factory_create (GError **error) +{ + return (NMDeviceFactory *) g_object_new (NM_TYPE_WIFI_FACTORY, NULL); +} /*****************************************************************************/ @@ -99,11 +104,6 @@ create_device (NMDeviceFactory *factory, return nm_device_olpc_mesh_new (iface); } -NM_DEVICE_FACTORY_DECLARE_TYPES ( - NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_WIFI, NM_LINK_TYPE_OLPC_MESH) - NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_OLPC_MESH_SETTING_NAME) -) - /*****************************************************************************/ static void @@ -112,21 +112,10 @@ nm_wifi_factory_init (NMWifiFactory *self) } static void -nm_wifi_factory_class_init (NMWifiFactoryClass *wf_class) -{ -} - -static void -device_factory_interface_init (NMDeviceFactoryInterface *factory_iface) +nm_wifi_factory_class_init (NMWifiFactoryClass *klass) { - factory_iface->create_device = create_device; - factory_iface->get_supported_types = get_supported_types; -} - -/*****************************************************************************/ + NMDeviceFactoryClass *factory_class = NM_DEVICE_FACTORY_CLASS (klass); -G_MODULE_EXPORT NMDeviceFactory * -nm_device_factory_create (GError **error) -{ - return (NMDeviceFactory *) g_object_new (NM_TYPE_WIFI_FACTORY, NULL); + factory_class->create_device = create_device; + factory_class->get_supported_types = get_supported_types; } diff --git a/src/devices/wwan/nm-wwan-factory.c b/src/devices/wwan/nm-wwan-factory.c index c9f6cc12fb..458ab2e17a 100644 --- a/src/devices/wwan/nm-wwan-factory.c +++ b/src/devices/wwan/nm-wwan-factory.c @@ -39,35 +39,40 @@ #define NM_IS_WWAN_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_WWAN_FACTORY)) #define NM_WWAN_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_WWAN_FACTORY, NMWwanFactoryClass)) -typedef struct _NMWwanFactory NMWwanFactory; -typedef struct _NMWwanFactoryClass NMWwanFactoryClass; - -static GType nm_wwan_factory_get_type (void); - -/*****************************************************************************/ - typedef struct { NMModemManager *mm; } NMWwanFactoryPrivate; -struct _NMWwanFactory { - GObject parent; +typedef struct { + NMDeviceFactory parent; NMWwanFactoryPrivate _priv; -}; +} NMWwanFactory; -struct _NMWwanFactoryClass { - GObjectClass parent; -}; +typedef struct { + NMDeviceFactoryClass parent; +} NMWwanFactoryClass; -static void device_factory_interface_init (NMDeviceFactoryInterface *factory_iface); +static GType nm_wwan_factory_get_type (void); -G_DEFINE_TYPE_EXTENDED (NMWwanFactory, nm_wwan_factory, G_TYPE_OBJECT, 0, - G_IMPLEMENT_INTERFACE (NM_TYPE_DEVICE_FACTORY, device_factory_interface_init)) +G_DEFINE_TYPE (NMWwanFactory, nm_wwan_factory, NM_TYPE_DEVICE_FACTORY) #define NM_WWAN_FACTORY_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMWwanFactory, NM_IS_WWAN_FACTORY) /*****************************************************************************/ +NM_DEVICE_FACTORY_DECLARE_TYPES ( + NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_WWAN_NET) + NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_GSM_SETTING_NAME, NM_SETTING_CDMA_SETTING_NAME) +) + +G_MODULE_EXPORT NMDeviceFactory * +nm_device_factory_create (GError **error) +{ + return (NMDeviceFactory *) g_object_new (NM_TYPE_WWAN_FACTORY, NULL); +} + +/*****************************************************************************/ + static void modem_added_cb (NMModemManager *manager, NMModem *modem, @@ -103,11 +108,6 @@ modem_added_cb (NMModemManager *manager, } -NM_DEVICE_FACTORY_DECLARE_TYPES ( - NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_WWAN_NET) - NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_GSM_SETTING_NAME, NM_SETTING_CDMA_SETTING_NAME) -) - static NMDevice * create_device (NMDeviceFactory *factory, const char *iface, @@ -160,22 +160,11 @@ static void nm_wwan_factory_class_init (NMWwanFactoryClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMDeviceFactoryClass *factory_class = NM_DEVICE_FACTORY_CLASS (klass); object_class->dispose = dispose; -} - -static void -device_factory_interface_init (NMDeviceFactoryInterface *factory_iface) -{ - factory_iface->get_supported_types = get_supported_types; - factory_iface->create_device = create_device; - factory_iface->start = start; -} - -/*****************************************************************************/ -G_MODULE_EXPORT NMDeviceFactory * -nm_device_factory_create (GError **error) -{ - return (NMDeviceFactory *) g_object_new (NM_TYPE_WWAN_FACTORY, NULL); + factory_class->get_supported_types = get_supported_types; + factory_class->create_device = create_device; + factory_class->start = start; } diff --git a/src/nm-manager.c b/src/nm-manager.c index 74efb5dda4..5ce72acf4d 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -1112,7 +1112,7 @@ nm_manager_get_connection_iface (NMManager *self, } if ( !out_parent - && !NM_DEVICE_FACTORY_GET_INTERFACE (factory)->get_connection_iface) { + && !NM_DEVICE_FACTORY_GET_CLASS (factory)->get_connection_iface) { /* optimization. Shortcut lookup of the partent device. */ iface = g_strdup (nm_connection_get_interface_name (connection)); if (!iface) { diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index c11e7a0b5f..35c70d2103 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -168,19 +168,3 @@ TESTS = \ test-wired-defname \ test-utils - -if ENABLE_TESTS - -check-local: - @for t in bond bridge ethernet infiniband ip_tunnel macvlan tun veth vlan vxlan; do \ - # Ensure the device subclass factory registration constructors exist \ - # which could inadvertently break if src/Makefile.am gets changed \ - if ! LC_ALL=C nm $(top_builddir)/src/NetworkManager | LC_ALL=C grep -q "register_device_factory_internal_$$t" ; then \ - echo "Testing device factory symbols... FAILED" ; \ - exit 1 ; \ - fi \ - done - @echo "Testing device factory symbols... PASSED" - -endif - |