device: make NMDeviceFactory a class instead of an interface

An interface would make sense to allow the actual device-factory to inherit
from another type.

However, glib interfaces make code much harder to follow and less
efficient. The device factory shall be a very simple type with meta data
about supported device types and the ability to create device instances.
There is no need to make this an interface implementation, instead just
let the factories inherit from NM_TYPE_DEVICE_FACTORY directly.
This commit is contained in:
Thomas Haller 2016-10-07 16:05:43 +02:00
parent 05e6d155ba
commit 18660604aa
18 changed files with 221 additions and 268 deletions

View file

@ -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,12 +237,18 @@ 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)
{
@ -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;
}

View file

@ -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;
}

View file

@ -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;
);

View file

@ -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;
);

View file

@ -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;
);

View file

@ -46,7 +46,7 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_INTERFACE (NMDeviceFactory, nm_device_factory, G_TYPE_OBJECT)
G_DEFINE_ABSTRACT_TYPE (NMDeviceFactory, nm_device_factory, G_TYPE_OBJECT)
/*****************************************************************************/
@ -55,6 +55,9 @@ nm_device_factory_emit_component_added (NMDeviceFactory *factory, GObject *compo
{
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;
}
@ -67,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
@ -84,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 *
@ -96,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;
@ -142,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) {
@ -176,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;
}
@ -187,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)
@ -225,20 +228,26 @@ nm_device_factory_get_connection_iface (NMDeviceFactory *factory,
/*****************************************************************************/
static void
nm_device_factory_default_init (NMDeviceFactoryInterface *factory_iface)
nm_device_factory_init (NMDeviceFactory *self)
{
/* Signals */
}
static void
nm_device_factory_class_init (NMDeviceFactoryClass *klass)
{
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);
}

View file

@ -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,15 +226,17 @@ 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##Factory; \
typedef struct { \
NMDeviceFactoryClass parent; \
} NM##mixed##FactoryClass; \
\
static GType nm_##lower##_factory_get_type (void); \
static void device_factory_interface_init (NMDeviceFactoryInterface *factory_iface); \
\
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);) \
G_DEFINE_TYPE_WITH_CODE (NM##mixed##Factory, nm_##lower##_factory, NM_TYPE_DEVICE_FACTORY, \
_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() \
@ -242,13 +250,6 @@ extern const char *_nm_device_factory_no_default_settings[];
} \
\
NM_DEVICE_FACTORY_DECLARE_TYPES(st_code) \
\
static void \
device_factory_interface_init (NMDeviceFactoryInterface *factory_iface) \
{ \
factory_iface->get_supported_types = get_supported_types; \
dfi_code \
} \
\
static void \
nm_##lower##_factory_init (NM##mixed##Factory *self) \
@ -256,8 +257,12 @@ extern const char *_nm_device_factory_no_default_settings[];
} \
\
static void \
nm_##lower##_factory_class_init (NM##mixed##FactoryClass *lower##_class) \
nm_##lower##_factory_class_init (NM##mixed##FactoryClass *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);

View file

@ -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;
);

View file

@ -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;
);

View file

@ -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;
);

View file

@ -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;
);

View file

@ -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;
);

View file

@ -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;
);

View file

@ -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;
);

View file

@ -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;
typedef struct {
NMDeviceFactoryClass parent;
} NMTeamFactoryClass;
static GType nm_team_factory_get_type (void);
G_DEFINE_TYPE (NMTeamFactory, nm_team_factory, NM_TYPE_DEVICE_FACTORY)
/*****************************************************************************/
struct _NMTeamFactory {
GObject parent;
};
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)
)
struct _NMTeamFactoryClass {
GObjectClass parent;
};
static void device_factory_interface_init (NMDeviceFactoryInterface *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))
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)
{
}
NMDeviceFactoryClass *factory_class = NM_DEVICE_FACTORY_CLASS (klass);
static void
device_factory_interface_init (NMDeviceFactoryInterface *factory_iface)
{
factory_iface->create_device = create_device;
factory_iface->get_supported_types = get_supported_types;
}
/*****************************************************************************/
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;
}

View file

@ -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;
typedef struct {
NMDeviceFactoryClass parent;
} NMWifiFactoryClass;
static GType nm_wifi_factory_get_type (void);
G_DEFINE_TYPE (NMWifiFactory, nm_wifi_factory, NM_TYPE_DEVICE_FACTORY)
/*****************************************************************************/
struct _NMWifiFactory {
GObject parent;
};
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)
)
struct _NMWifiFactoryClass {
GObjectClass parent;
};
static void device_factory_interface_init (NMDeviceFactoryInterface *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))
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)
nm_wifi_factory_class_init (NMWifiFactoryClass *klass)
{
}
NMDeviceFactoryClass *factory_class = NM_DEVICE_FACTORY_CLASS (klass);
static void
device_factory_interface_init (NMDeviceFactoryInterface *factory_iface)
{
factory_iface->create_device = create_device;
factory_iface->get_supported_types = get_supported_types;
}
/*****************************************************************************/
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;
}

View file

@ -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;
}

View file

@ -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) {