mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-26 20:30:08 +01:00
* introspection/nm-device.xml - The 'Activate' method now takes 3 arguments, a service name for the settings service (user or system), the object path of the connection to activate, and the specific object to activate, if any * src/nm-device-interface.c - (nm_device_interface_error_quark, nm_device_interface_error_get_type): Add error bits - (impl_device_activate): adapt to new Activate arguments; validate the service name and get the Connection object from the NMManager before starting to activate the device with the specified connection * src/nm-device-802-3-ethernet.c - (real_get_best_connection): find the best connection, or create a default one if no existing connections can be used * src/NetworkManagerPolicy.c - (nm_policy_auto_get_best_device): Get the device's best connection and only pick the device if it has one - (nm_policy_device_change_check): disable wireless bits for now until wireless get_best_connection() can be implemented (replacing "best_ap"); don't create a default connection here as the device subclass will do that if needed * src/nm-manager.h src/nm-manager.c - (nm_manager_get): make NMManager a singleton and expose the getter internally - Rework internal NMManager connection handling to use the same routines for both the system and user settings services. Most calls take a new NMConnectionType argument specifying either system or user connections - (nm_manager_get_connection_by_object_path): new function; get a connection keyed on its object path * src/NetworkManager.c - (main): use nm_manager_get() git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2776 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
250 lines
6.6 KiB
C
250 lines
6.6 KiB
C
|
|
#include "nm-device-interface.h"
|
|
#include "nm-ip4-config.h"
|
|
#include "nm-manager.h"
|
|
|
|
static gboolean impl_device_activate (NMDeviceInterface *device,
|
|
const char *service_name,
|
|
const char *connection_path,
|
|
const char *specific_object,
|
|
GError **err);
|
|
|
|
static gboolean impl_device_deactivate (NMDeviceInterface *device, GError **err);
|
|
|
|
#include "nm-device-interface-glue.h"
|
|
|
|
GQuark
|
|
nm_device_interface_error_quark (void)
|
|
{
|
|
static GQuark quark = 0;
|
|
if (!quark)
|
|
quark = g_quark_from_static_string ("nm_device_interface_error");
|
|
return quark;
|
|
}
|
|
|
|
/* This should really be standard. */
|
|
#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
|
|
|
|
GType
|
|
nm_device_interface_error_get_type (void)
|
|
{
|
|
static GType etype = 0;
|
|
|
|
if (etype == 0) {
|
|
static const GEnumValue values[] = {
|
|
ENUM_ENTRY (NM_DEVICE_INTERFACE_ERROR_UNKNOWN_CONNECTION, "UnknownConnection"),
|
|
{ 0, 0, 0 }
|
|
};
|
|
etype = g_enum_register_static ("NMDeviceInterfaceError", values);
|
|
}
|
|
return etype;
|
|
}
|
|
|
|
|
|
static void
|
|
nm_device_interface_init (gpointer g_iface)
|
|
{
|
|
GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
|
|
static gboolean initialized = FALSE;
|
|
|
|
if (initialized)
|
|
return;
|
|
|
|
/* Properties */
|
|
g_object_interface_install_property
|
|
(g_iface,
|
|
g_param_spec_string (NM_DEVICE_INTERFACE_UDI,
|
|
"Udi",
|
|
"HAL Udi",
|
|
NULL,
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
g_object_interface_install_property
|
|
(g_iface,
|
|
g_param_spec_uint (NM_DEVICE_INTERFACE_INDEX,
|
|
"Index",
|
|
"Index",
|
|
0, G_MAXUINT32, 0, /* FIXME */
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
g_object_interface_install_property
|
|
(g_iface,
|
|
g_param_spec_string (NM_DEVICE_INTERFACE_IFACE,
|
|
"Interface",
|
|
"Interface",
|
|
NULL,
|
|
G_PARAM_READABLE));
|
|
|
|
g_object_interface_install_property
|
|
(g_iface,
|
|
g_param_spec_string (NM_DEVICE_INTERFACE_DRIVER,
|
|
"Driver",
|
|
"Driver",
|
|
NULL,
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
g_object_interface_install_property
|
|
(g_iface,
|
|
g_param_spec_uint (NM_DEVICE_INTERFACE_CAPABILITIES,
|
|
"Capabilities",
|
|
"Capabilities",
|
|
0, G_MAXUINT32, NM_DEVICE_CAP_NONE,
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
g_object_interface_install_property
|
|
(g_iface,
|
|
g_param_spec_uint (NM_DEVICE_INTERFACE_IP4_ADDRESS,
|
|
"IP4 address",
|
|
"IP4 address",
|
|
0, G_MAXUINT32, 0, /* FIXME */
|
|
G_PARAM_READWRITE));
|
|
|
|
g_object_interface_install_property
|
|
(g_iface,
|
|
g_param_spec_object (NM_DEVICE_INTERFACE_IP4_CONFIG,
|
|
"IP4 Config",
|
|
"IP4 Config",
|
|
G_TYPE_OBJECT,
|
|
G_PARAM_READWRITE));
|
|
|
|
g_object_interface_install_property
|
|
(g_iface,
|
|
g_param_spec_uint (NM_DEVICE_INTERFACE_STATE,
|
|
"State",
|
|
"State",
|
|
0, G_MAXUINT32, NM_DEVICE_STATE_UNKNOWN,
|
|
G_PARAM_READABLE));
|
|
|
|
g_object_interface_install_property
|
|
(g_iface,
|
|
g_param_spec_uint (NM_DEVICE_INTERFACE_DEVICE_TYPE,
|
|
"DeviceType",
|
|
"DeviceType",
|
|
0, G_MAXUINT32, DEVICE_TYPE_UNKNOWN,
|
|
G_PARAM_READABLE));
|
|
|
|
/* Signals */
|
|
g_signal_new ("state-changed",
|
|
iface_type,
|
|
G_SIGNAL_RUN_FIRST,
|
|
G_STRUCT_OFFSET (NMDeviceInterface, state_changed),
|
|
NULL, NULL,
|
|
g_cclosure_marshal_VOID__UINT,
|
|
G_TYPE_NONE, 1,
|
|
G_TYPE_UINT);
|
|
|
|
g_signal_new ("carrier-changed",
|
|
iface_type,
|
|
G_SIGNAL_RUN_FIRST,
|
|
G_STRUCT_OFFSET (NMDeviceInterface, carrier_changed),
|
|
NULL, NULL,
|
|
g_cclosure_marshal_VOID__BOOLEAN,
|
|
G_TYPE_NONE, 1,
|
|
G_TYPE_BOOLEAN);
|
|
|
|
dbus_g_object_type_install_info (iface_type,
|
|
&dbus_glib_nm_device_interface_object_info);
|
|
|
|
initialized = TRUE;
|
|
}
|
|
|
|
|
|
GType
|
|
nm_device_interface_get_type (void)
|
|
{
|
|
static GType device_interface_type = 0;
|
|
|
|
if (!device_interface_type) {
|
|
const GTypeInfo device_interface_info = {
|
|
sizeof (NMDeviceInterface), /* class_size */
|
|
nm_device_interface_init, /* base_init */
|
|
NULL, /* base_finalize */
|
|
NULL,
|
|
NULL, /* class_finalize */
|
|
NULL, /* class_data */
|
|
0,
|
|
0, /* n_preallocs */
|
|
NULL
|
|
};
|
|
|
|
device_interface_type = g_type_register_static (G_TYPE_INTERFACE,
|
|
"NMDeviceInterface",
|
|
&device_interface_info, 0);
|
|
|
|
g_type_interface_add_prerequisite (device_interface_type, G_TYPE_OBJECT);
|
|
}
|
|
|
|
return device_interface_type;
|
|
}
|
|
|
|
void
|
|
nm_device_interface_activate (NMDeviceInterface *device,
|
|
NMConnection *connection,
|
|
const char *specific_object,
|
|
gboolean user_requested)
|
|
{
|
|
g_return_if_fail (NM_IS_DEVICE_INTERFACE (device));
|
|
g_return_if_fail (connection != NULL);
|
|
|
|
NM_DEVICE_INTERFACE_GET_INTERFACE (device)->activate (device,
|
|
connection,
|
|
specific_object,
|
|
user_requested);
|
|
}
|
|
|
|
static gboolean
|
|
impl_device_activate (NMDeviceInterface *device,
|
|
const char *service_name,
|
|
const char *connection_path,
|
|
const char *specific_object,
|
|
GError **err)
|
|
{
|
|
NMManager *manager;
|
|
NMConnection *connection;
|
|
gboolean success = FALSE;
|
|
|
|
manager = nm_manager_get ();
|
|
if (!strcmp (service_name, NM_DBUS_SERVICE_USER_SETTINGS)) {
|
|
connection = nm_manager_get_connection_by_object_path (manager,
|
|
NM_CONNECTION_TYPE_USER,
|
|
connection_path);
|
|
} else if (!strcmp (service_name, NM_DBUS_SERVICE_USER_SETTINGS)) {
|
|
connection = nm_manager_get_connection_by_object_path (manager,
|
|
NM_CONNECTION_TYPE_SYSTEM,
|
|
connection_path);
|
|
}
|
|
|
|
if (connection == NULL) {
|
|
g_set_error (err,
|
|
NM_DEVICE_INTERFACE_ERROR,
|
|
NM_DEVICE_INTERFACE_ERROR_UNKNOWN_CONNECTION,
|
|
"%s",
|
|
"Connection object or service unknown");
|
|
goto out;
|
|
}
|
|
|
|
nm_connection_dump (connection);
|
|
nm_device_interface_activate (device, connection, specific_object, TRUE);
|
|
success = TRUE;
|
|
|
|
out:
|
|
return success;
|
|
}
|
|
|
|
void
|
|
nm_device_interface_deactivate (NMDeviceInterface *device)
|
|
{
|
|
g_return_if_fail (NM_IS_DEVICE_INTERFACE (device));
|
|
|
|
NM_DEVICE_INTERFACE_GET_INTERFACE (device)->deactivate (device);
|
|
}
|
|
|
|
static gboolean
|
|
impl_device_deactivate (NMDeviceInterface *device, GError **err)
|
|
{
|
|
g_return_val_if_fail (NM_IS_DEVICE_INTERFACE (device), FALSE);
|
|
|
|
nm_device_interface_deactivate (device);
|
|
|
|
return TRUE;
|
|
}
|