about summary refs log tree commit diff
path: root/src/devices/nm-device-factory.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/nm-device-factory.h')
-rw-r--r--src/devices/nm-device-factory.h125
1 files changed, 108 insertions, 17 deletions
diff --git a/src/devices/nm-device-factory.h b/src/devices/nm-device-factory.h
index f0e3dc19..ce672b8b 100644
--- a/src/devices/nm-device-factory.h
+++ b/src/devices/nm-device-factory.h
@@ -18,14 +18,13 @@
  * Copyright (C) 2007 - 2014 Red Hat, Inc.
  */
 
-#ifndef NM_DEVICE_FACTORY_H
-#define NM_DEVICE_FACTORY_H
+#ifndef __NETWORKMANAGER_DEVICE_FACTORY_H__
+#define __NETWORKMANAGER_DEVICE_FACTORY_H__
 
 #include <glib.h>
 #include <glib-object.h>
 
-#include "NetworkManager.h"
-#include "nm-platform.h"
+#include "nm-dbus-interface.h"
 #include "nm-device.h"
 
 /* WARNING: this file is private API between NetworkManager and its internal
@@ -43,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
  */
@@ -52,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 ())
@@ -77,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
@@ -95,6 +103,25 @@ struct _NMDeviceFactory {
 	                               NMPlatformLink *plink,
 	                               GError **error);
 
+	/**
+	 * create_virtual_device_for_connection:
+	 * @factory: the #NMDeviceFactory
+	 * @connection: the #NMConnection
+	 * @error: a @GError in case of failure
+	 *
+	 * Virtual device types (such as team, bond, bridge) may need to be created.
+	 * This function tries to create a device based on the given @connection.
+	 *
+	 * Returns: the newly created #NMDevice. If the factory does not support the
+	 * connection type, it should return %NULL and leave @error unset. On error
+	 * it should set @error and return %NULL.
+	 */
+	NMDevice * (*create_virtual_device_for_connection) (NMDeviceFactory *factory,
+	                                                    NMConnection *connection,
+	                                                    NMDevice *parent,
+	                                                    GError **error);
+
+
 	/* Signals */
 
 	/**
@@ -124,13 +151,77 @@ 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);
 
+NMDevice * nm_device_factory_create_virtual_device_for_connection (NMDeviceFactory *factory,
+                                                                   NMConnection *connection,
+                                                                   NMDevice *parent,
+                                                                   GError **error);
+
 /* For use by implementations */
 gboolean   nm_device_factory_emit_component_added (NMDeviceFactory *factory,
                                                    GObject *component);
 
-#endif /* NM_DEVICE_FACTORY_H */
-
+/**************************************************************************
+ * INTERNAL DEVICE FACTORY FUNCTIONS - devices provided by plugins should
+ * not use these functions.
+ **************************************************************************/
+
+#define DEFINE_DEVICE_FACTORY_INTERNAL(upper, mixed, lower, dfi_code) \
+	DEFINE_DEVICE_FACTORY_INTERNAL_WITH_DEVTYPE(upper, mixed, lower, upper, dfi_code)
+
+#define DEFINE_DEVICE_FACTORY_INTERNAL_WITH_DEVTYPE(upper, mixed, lower, devtype, dfi_code) \
+	typedef GObject NM##mixed##Factory; \
+	typedef GObjectClass NM##mixed##FactoryClass; \
+ \
+	static GType nm_##lower##_factory_get_type (void); \
+	static void device_factory_interface_init (NMDeviceFactory *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);) \
+ \
+	/* 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) \
+	{ \
+		g_type_init (); \
+		g_type_ensure (NM_TYPE_##upper##_FACTORY); \
+	} \
+ \
+	static NMDeviceType \
+	get_device_type (NMDeviceFactory *factory) \
+	{ \
+		return NM_DEVICE_TYPE_##devtype; \
+	} \
+ \
+	static void \
+	device_factory_interface_init (NMDeviceFactory *factory_iface) \
+	{ \
+		factory_iface->get_device_type = get_device_type; \
+		dfi_code \
+	} \
+ \
+	static void \
+	nm_##lower##_factory_init (NM##mixed##Factory *self) \
+	{ \
+	} \
+ \
+	static void \
+	nm_##lower##_factory_class_init (NM##mixed##FactoryClass *lower##_class) \
+	{ \
+	}
+
+void _nm_device_factory_internal_register_type (GType factory_type);
+const GSList *nm_device_factory_get_internal_factory_types (void);
+
+#endif /* __NETWORKMANAGER_DEVICE_FACTORY_H__ */