2011-11-18 15:52:42 -06:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
|
|
|
|
/* NetworkManager -- Network link manager
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*
|
2014-02-09 10:22:19 -06:00
|
|
|
* Copyright (C) 2007 - 2014 Red Hat, Inc.
|
2011-11-18 15:52:42 -06:00
|
|
|
*/
|
|
|
|
|
|
all: fix up multiple-include-guard defines
Previously, src/nm-ip4-config.h, libnm/nm-ip4-config.h, and
libnm-glib/nm-ip4-config.h all used "NM_IP4_CONFIG_H" as an include
guard, which meant that nm-test-utils.h could not tell which of them
was being included (and so, eg, if you tried to include
nm-ip4-config.h in a libnm test, it would fail to compile because
nm-test-utils.h was referring to symbols in src/nm-ip4-config.h).
Fix this by changing the include guards in the non-API-stable parts of
the tree:
- libnm-glib/nm-ip4-config.h remains NM_IP4_CONFIG_H
- libnm/nm-ip4-config.h now uses __NM_IP4_CONFIG_H__
- src/nm-ip4-config.h now uses __NETWORKMANAGER_IP4_CONFIG_H__
And likewise for all other headers.
The two non-"nm"-prefixed headers, libnm/NetworkManager.h and
src/NetworkManagerUtils.h are now __NETWORKMANAGER_H__ and
__NETWORKMANAGER_UTILS_H__ respectively, which, while not entirely
consistent with the general scheme, do still mostly make sense in
isolation.
2014-08-13 14:10:11 -04:00
|
|
|
#ifndef __NETWORKMANAGER_DEVICE_FACTORY_H__
|
|
|
|
|
#define __NETWORKMANAGER_DEVICE_FACTORY_H__
|
2011-11-18 15:52:42 -06:00
|
|
|
|
2014-07-05 16:23:30 -04:00
|
|
|
#include "nm-dbus-interface.h"
|
2014-02-09 10:22:19 -06:00
|
|
|
#include "nm-device.h"
|
2011-11-18 15:52:42 -06:00
|
|
|
|
|
|
|
|
/* WARNING: this file is private API between NetworkManager and its internal
|
|
|
|
|
* device plugins. Its API can change at any time and is not guaranteed to be
|
|
|
|
|
* stable. NM and device plugins are distributed together and this API is
|
|
|
|
|
* not meant to enable third-party plugins.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-10-07 16:05:43 +02:00
|
|
|
#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))
|
2014-02-09 10:22:19 -06:00
|
|
|
|
|
|
|
|
#define NM_DEVICE_FACTORY_COMPONENT_ADDED "component-added"
|
|
|
|
|
#define NM_DEVICE_FACTORY_DEVICE_ADDED "device-added"
|
|
|
|
|
|
core: fix interface type names
A GObject interface, like a class, has two different C types
associated with it; the type of the "class" struct (eg, GObjectClass,
GFileIface), and the type of instances of that class/interface (eg,
GObject, GFile).
NetworkManager was doing this wrong though, and using the same C type
to point to both the interface's class struct and to instances of the
interface. This ends up not actually breaking anything, since for
interface types, the instance type is a non-dereferenceable dummy type
anyway. But it's wrong, since if, eg, NMDeviceFactory is a struct type
containing members "start", "device_added", etc, then you should not
be using an NMDeviceFactory* to point to an object that does not
contain those members.
Fix this by splitting NMDeviceFactory into NMDeviceFactoryInterface
and NMDeviceFactory; by splitting NMConnectionProvider into
NMConnectionProviderInterface and NMConnectionProvider; and by
splitting NMSettingsPlugin into NMSettingsPluginInterface and
NMSettingsPlugin; and then use the right types in the right places.
As a bonus, this also lets us now use G_DEFINE_INTERFACE.
2015-04-16 09:05:49 -04:00
|
|
|
typedef struct {
|
2016-10-07 16:05:43 +02:00
|
|
|
GObject parent;
|
|
|
|
|
} NMDeviceFactory;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
GObjectClass parent;
|
2014-02-09 10:22:19 -06:00
|
|
|
|
2014-09-05 14:48:21 -05:00
|
|
|
/**
|
2014-09-17 14:17:30 -05:00
|
|
|
* get_supported_types:
|
2014-09-05 14:48:21 -05:00
|
|
|
* @factory: the #NMDeviceFactory
|
2014-09-17 14:17:30 -05:00
|
|
|
* @out_link_types: on return, a %NM_LINK_TYPE_NONE terminated
|
|
|
|
|
* list of #NMLinkType that the plugin supports
|
|
|
|
|
* @out_setting_types: on return, a %NULL terminated list of
|
|
|
|
|
* base-type #NMSetting names that the plugin can create devices for
|
2014-09-05 14:48:21 -05:00
|
|
|
*
|
2014-09-17 14:17:30 -05:00
|
|
|
* Returns the #NMLinkType and #NMSetting names that this plugin
|
|
|
|
|
* supports. This function MUST be implemented.
|
2014-09-05 14:48:21 -05:00
|
|
|
*/
|
2014-09-17 14:17:30 -05:00
|
|
|
void (*get_supported_types) (NMDeviceFactory *factory,
|
|
|
|
|
const NMLinkType **out_link_types,
|
2016-11-13 14:39:57 +01:00
|
|
|
const char *const**out_setting_types);
|
2014-09-05 14:48:21 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* start:
|
|
|
|
|
* @factory: the #NMDeviceFactory
|
|
|
|
|
*
|
|
|
|
|
* Start the factory and discover any existing devices that the factory
|
|
|
|
|
* can manage.
|
|
|
|
|
*/
|
2014-09-05 08:50:02 -05:00
|
|
|
void (*start) (NMDeviceFactory *factory);
|
2014-06-19 08:42:35 +02:00
|
|
|
|
2017-06-30 16:33:07 +02:00
|
|
|
/**
|
|
|
|
|
* match_connection:
|
|
|
|
|
* @connection: the #NMConnection
|
|
|
|
|
*
|
|
|
|
|
* Check if the factory supports the given connection.
|
|
|
|
|
*/
|
|
|
|
|
gboolean (*match_connection) (NMDeviceFactory *factory, NMConnection *connection);
|
|
|
|
|
|
2014-09-18 17:50:47 -05:00
|
|
|
/**
|
|
|
|
|
* get_connection_parent:
|
|
|
|
|
* @factory: the #NMDeviceFactory
|
|
|
|
|
* @connection: the #NMConnection to return the parent name for, if supported
|
|
|
|
|
*
|
2017-05-28 17:34:31 +03:00
|
|
|
* Given a connection, returns the parent interface name, parent connection
|
2016-06-15 13:43:34 +02:00
|
|
|
* UUID, or parent device permanent hardware address for @connection.
|
2014-09-18 17:50:47 -05:00
|
|
|
*
|
|
|
|
|
* Returns: the parent interface name, parent connection UUID, parent
|
2016-06-15 13:43:34 +02:00
|
|
|
* device permenent hardware address, or %NULL
|
2014-09-18 17:50:47 -05:00
|
|
|
*/
|
|
|
|
|
const char * (*get_connection_parent) (NMDeviceFactory *factory,
|
|
|
|
|
NMConnection *connection);
|
|
|
|
|
|
|
|
|
|
/**
|
2016-02-17 15:11:02 +01:00
|
|
|
* get_connection_iface:
|
2014-09-18 17:50:47 -05:00
|
|
|
* @factory: the #NMDeviceFactory
|
2016-02-17 15:11:02 +01:00
|
|
|
* @connection: the #NMConnection to return the interface name for
|
|
|
|
|
* @parent_iface: optional parent interface name for virtual devices
|
2014-09-18 17:50:47 -05:00
|
|
|
*
|
|
|
|
|
* Given a connection, returns the interface name that a device activating
|
|
|
|
|
* that connection would have.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the interface name, or %NULL
|
|
|
|
|
*/
|
2016-02-17 15:11:02 +01:00
|
|
|
char * (*get_connection_iface) (NMDeviceFactory *factory,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
const char *parent_iface);
|
2014-06-19 08:42:35 +02:00
|
|
|
|
2014-09-05 08:50:02 -05:00
|
|
|
/**
|
|
|
|
|
* create_device:
|
|
|
|
|
* @factory: the #NMDeviceFactory
|
|
|
|
|
* @iface: the interface name of the device
|
|
|
|
|
* @plink: the #NMPlatformLink if backed by a kernel device
|
|
|
|
|
* @connection: the #NMConnection if not backed by a kernel device
|
|
|
|
|
* @out_ignore: on return, %TRUE if the link should be ignored
|
|
|
|
|
*
|
|
|
|
|
* The plugin should create a new unrealized device using the details given
|
|
|
|
|
* by @iface and @plink or @connection. If both @iface and @plink are given,
|
|
|
|
|
* they are guaranteed to match. If both @iface and @connection are given,
|
|
|
|
|
* @iface is guaranteed to be the interface name that @connection specifies.
|
|
|
|
|
*
|
|
|
|
|
* If the plugin cannot create a #NMDevice for the link and wants the
|
|
|
|
|
* core to ignore it, set @out_ignore to %TRUE and return %NULL.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the new unrealized #NMDevice, or %NULL
|
|
|
|
|
*/
|
|
|
|
|
NMDevice * (*create_device) (NMDeviceFactory *factory,
|
|
|
|
|
const char *iface,
|
2016-01-10 15:13:20 +01:00
|
|
|
const NMPlatformLink *plink,
|
2014-09-05 08:50:02 -05:00
|
|
|
NMConnection *connection,
|
|
|
|
|
gboolean *out_ignore);
|
|
|
|
|
|
2014-02-09 10:22:19 -06:00
|
|
|
/* Signals */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* device_added:
|
|
|
|
|
* @factory: the #NMDeviceFactory
|
|
|
|
|
* @device: the new #NMDevice subclass
|
|
|
|
|
*
|
|
|
|
|
* The factory emits this signal if it finds a new device by itself.
|
|
|
|
|
*/
|
|
|
|
|
void (*device_added) (NMDeviceFactory *factory, NMDevice *device);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* component_added:
|
|
|
|
|
* @factory: the #NMDeviceFactory
|
|
|
|
|
* @component: a new component which existing devices may wish to claim
|
|
|
|
|
*
|
2017-05-24 16:35:03 +02:00
|
|
|
* The factory emits this signal when an appearance of some component
|
|
|
|
|
* native to it could be interesting to some of the already existing devices.
|
|
|
|
|
* The devices then indicate if they took interest in claiming the component.
|
|
|
|
|
*
|
|
|
|
|
* For example, the WWAN factory may indicate that a new modem is available,
|
|
|
|
|
* which an existing Bluetooth device may wish to claim. It emits a signal
|
|
|
|
|
* passing the modem instance around to see if any device claims it.
|
|
|
|
|
* If no device claims the component, the plugin is allowed to create a new
|
|
|
|
|
* #NMDevice instance for that component and emit the "device-added" signal.
|
2014-02-09 10:22:19 -06:00
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the component was claimed by a device, %FALSE if not
|
|
|
|
|
*/
|
|
|
|
|
gboolean (*component_added) (NMDeviceFactory *factory, GObject *component);
|
2016-10-07 16:05:43 +02:00
|
|
|
|
|
|
|
|
} NMDeviceFactoryClass;
|
2014-02-09 10:22:19 -06:00
|
|
|
|
|
|
|
|
GType nm_device_factory_get_type (void);
|
|
|
|
|
|
2016-10-07 16:05:43 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2014-09-18 17:50:47 -05:00
|
|
|
const char *nm_device_factory_get_connection_parent (NMDeviceFactory *factory,
|
|
|
|
|
NMConnection *connection);
|
|
|
|
|
|
2016-02-17 15:11:02 +01:00
|
|
|
char * nm_device_factory_get_connection_iface (NMDeviceFactory *factory,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
const char *parent_iface,
|
|
|
|
|
GError **error);
|
2014-09-18 17:50:47 -05:00
|
|
|
|
2016-10-07 16:05:43 +02:00
|
|
|
void nm_device_factory_start (NMDeviceFactory *factory);
|
2014-09-05 14:48:21 -05:00
|
|
|
|
2014-09-05 08:50:02 -05:00
|
|
|
NMDevice * nm_device_factory_create_device (NMDeviceFactory *factory,
|
|
|
|
|
const char *iface,
|
2016-01-10 15:13:20 +01:00
|
|
|
const NMPlatformLink *plink,
|
2014-09-05 08:50:02 -05:00
|
|
|
NMConnection *connection,
|
|
|
|
|
gboolean *out_ignore,
|
|
|
|
|
GError **error);
|
2014-06-19 08:42:35 +02:00
|
|
|
|
2014-02-09 10:22:19 -06:00
|
|
|
/* For use by implementations */
|
|
|
|
|
gboolean nm_device_factory_emit_component_added (NMDeviceFactory *factory,
|
|
|
|
|
GObject *component);
|
2011-11-18 15:52:42 -06:00
|
|
|
|
2014-09-17 14:17:30 -05:00
|
|
|
#define NM_DEVICE_FACTORY_DECLARE_LINK_TYPES(...) \
|
2016-11-13 14:39:57 +01:00
|
|
|
{ static NMLinkType const _link_types_declared[] = { __VA_ARGS__, NM_LINK_TYPE_NONE }; _link_types = _link_types_declared; }
|
2014-09-17 14:17:30 -05:00
|
|
|
#define NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES(...) \
|
2016-11-13 14:39:57 +01:00
|
|
|
{ static const char *const _setting_types_declared[] = { __VA_ARGS__, NULL }; _setting_types = _setting_types_declared; }
|
2014-09-17 14:17:30 -05:00
|
|
|
|
|
|
|
|
#define NM_DEVICE_FACTORY_DECLARE_TYPES(...) \
|
|
|
|
|
static void \
|
|
|
|
|
get_supported_types (NMDeviceFactory *factory, \
|
|
|
|
|
const NMLinkType **out_link_types, \
|
2016-11-13 14:39:57 +01:00
|
|
|
const char *const**out_setting_types) \
|
2014-09-17 14:17:30 -05:00
|
|
|
{ \
|
2016-11-13 14:39:57 +01:00
|
|
|
static NMLinkType const _link_types_null[1] = { NM_LINK_TYPE_NONE }; \
|
|
|
|
|
static const char *const _setting_types_null[1] = { NULL }; \
|
|
|
|
|
\
|
|
|
|
|
const NMLinkType *_link_types = _link_types_null; \
|
|
|
|
|
const char *const*_setting_types = _setting_types_null; \
|
|
|
|
|
\
|
2014-09-17 14:17:30 -05:00
|
|
|
{ __VA_ARGS__; } \
|
2016-11-13 14:39:57 +01:00
|
|
|
\
|
|
|
|
|
NM_SET_OUT (out_link_types, _link_types); \
|
|
|
|
|
NM_SET_OUT (out_setting_types, _setting_types); \
|
|
|
|
|
}
|
2014-09-17 14:17:30 -05:00
|
|
|
|
2014-09-05 15:57:40 -05:00
|
|
|
/**************************************************************************
|
|
|
|
|
* INTERNAL DEVICE FACTORY FUNCTIONS - devices provided by plugins should
|
|
|
|
|
* not use these functions.
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
2014-09-17 14:17:30 -05:00
|
|
|
#define NM_DEVICE_FACTORY_DEFINE_INTERNAL(upper, mixed, lower, st_code, dfi_code) \
|
2016-10-07 16:05:43 +02:00
|
|
|
typedef struct { \
|
|
|
|
|
NMDeviceFactory parent; \
|
2016-10-07 17:00:59 +02:00
|
|
|
} NM##mixed##DeviceFactory; \
|
2016-10-07 16:05:43 +02:00
|
|
|
typedef struct { \
|
|
|
|
|
NMDeviceFactoryClass parent; \
|
2016-10-07 17:00:59 +02:00
|
|
|
} NM##mixed##DeviceFactoryClass; \
|
2014-09-05 15:57:40 -05:00
|
|
|
\
|
2016-10-07 16:48:41 +02:00
|
|
|
GType nm_##lower##_device_factory_get_type (void); \
|
2014-09-05 15:57:40 -05:00
|
|
|
\
|
2016-10-07 16:48:41 +02:00
|
|
|
G_DEFINE_TYPE (NM##mixed##DeviceFactory, nm_##lower##_device_factory, NM_TYPE_DEVICE_FACTORY) \
|
2014-09-05 15:57:40 -05:00
|
|
|
\
|
2014-09-17 14:17:30 -05:00
|
|
|
NM_DEVICE_FACTORY_DECLARE_TYPES(st_code) \
|
2014-09-05 15:57:40 -05:00
|
|
|
\
|
|
|
|
|
static void \
|
2016-10-07 17:00:59 +02:00
|
|
|
nm_##lower##_device_factory_init (NM##mixed##DeviceFactory *self) \
|
2014-09-05 15:57:40 -05:00
|
|
|
{ \
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
static void \
|
2016-10-07 17:00:59 +02:00
|
|
|
nm_##lower##_device_factory_class_init (NM##mixed##DeviceFactoryClass *klass) \
|
2014-09-05 15:57:40 -05:00
|
|
|
{ \
|
2016-10-07 16:05:43 +02:00
|
|
|
NMDeviceFactoryClass *factory_class = NM_DEVICE_FACTORY_CLASS (klass); \
|
|
|
|
|
\
|
|
|
|
|
factory_class->get_supported_types = get_supported_types; \
|
|
|
|
|
dfi_code \
|
2014-09-05 15:57:40 -05:00
|
|
|
}
|
|
|
|
|
|
2014-09-17 14:17:30 -05:00
|
|
|
/**************************************************************************
|
|
|
|
|
* PRIVATE FACTORY FUNCTIONS - for factory consumers (eg, NMManager).
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
typedef void (*NMDeviceFactoryManagerFactoryFunc) (NMDeviceFactory *factory,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
|
|
|
|
void nm_device_factory_manager_load_factories (NMDeviceFactoryManagerFactoryFunc callback,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
|
|
|
|
NMDeviceFactory * nm_device_factory_manager_find_factory_for_link_type (NMLinkType link_type);
|
|
|
|
|
|
|
|
|
|
NMDeviceFactory * nm_device_factory_manager_find_factory_for_connection (NMConnection *connection);
|
|
|
|
|
|
|
|
|
|
void nm_device_factory_manager_for_each_factory (NMDeviceFactoryManagerFactoryFunc callback,
|
|
|
|
|
gpointer user_data);
|
2011-11-18 15:52:42 -06:00
|
|
|
|
2014-09-05 15:57:40 -05:00
|
|
|
#endif /* __NETWORKMANAGER_DEVICE_FACTORY_H__ */
|