2007-09-26 15:38:51 +00:00
|
|
|
/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
|
2007-02-05 12:14:09 +00:00
|
|
|
|
|
|
|
|
#include "nm-device-interface.h"
|
2007-02-16 11:23:49 +00:00
|
|
|
#include "nm-ip4-config.h"
|
2007-09-21 03:48:00 +00:00
|
|
|
#include "nm-utils.h"
|
2007-02-05 12:14:09 +00:00
|
|
|
|
2007-05-07 15:17:45 +00:00
|
|
|
static gboolean impl_device_activate (NMDeviceInterface *device,
|
2007-09-09 22:18:42 +00:00
|
|
|
const char *service_name,
|
|
|
|
|
const char *connection_path,
|
|
|
|
|
const char *specific_object,
|
|
|
|
|
GError **err);
|
2007-05-07 15:17:45 +00:00
|
|
|
|
2007-02-12 09:23:43 +00:00
|
|
|
static gboolean impl_device_deactivate (NMDeviceInterface *device, GError **err);
|
|
|
|
|
|
|
|
|
|
#include "nm-device-interface-glue.h"
|
|
|
|
|
|
2007-09-09 22:18:42 +00:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-02-05 12:14:09 +00:00
|
|
|
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));
|
|
|
|
|
|
2007-08-26 15:55:27 +00:00
|
|
|
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));
|
|
|
|
|
|
2007-02-05 12:14:09 +00:00
|
|
|
g_object_interface_install_property
|
|
|
|
|
(g_iface,
|
|
|
|
|
g_param_spec_string (NM_DEVICE_INTERFACE_IFACE,
|
|
|
|
|
"Interface",
|
|
|
|
|
"Interface",
|
|
|
|
|
NULL,
|
2007-08-26 15:55:27 +00:00
|
|
|
G_PARAM_READABLE));
|
2007-02-05 12:14:09 +00:00
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
2007-02-16 11:23:49 +00:00
|
|
|
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));
|
|
|
|
|
|
2007-02-05 12:14:09 +00:00
|
|
|
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));
|
|
|
|
|
|
2007-09-25 17:30:01 +00:00
|
|
|
g_object_interface_install_property
|
|
|
|
|
(g_iface,
|
|
|
|
|
g_param_spec_boolean (NM_DEVICE_INTERFACE_CARRIER,
|
|
|
|
|
"Carrier",
|
|
|
|
|
"Carrier",
|
|
|
|
|
FALSE,
|
|
|
|
|
G_PARAM_READABLE));
|
|
|
|
|
|
2007-02-05 12:14:09 +00:00
|
|
|
/* Signals */
|
2007-02-08 15:34:26 +00:00
|
|
|
g_signal_new ("state-changed",
|
2007-02-05 12:14:09 +00:00
|
|
|
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);
|
|
|
|
|
|
2007-02-08 15:34:26 +00:00
|
|
|
g_signal_new ("carrier-changed",
|
2007-02-05 12:14:09 +00:00
|
|
|
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);
|
|
|
|
|
|
2007-02-12 09:23:43 +00:00
|
|
|
dbus_g_object_type_install_info (iface_type,
|
|
|
|
|
&dbus_glib_nm_device_interface_object_info);
|
|
|
|
|
|
2007-02-05 12:14:09 +00:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-14 19:51:04 +00:00
|
|
|
/* Pass _either_ connection_path or connection. Passing 'connection' is
|
|
|
|
|
* meant for internal use only.
|
|
|
|
|
*/
|
2007-05-07 15:17:45 +00:00
|
|
|
void
|
|
|
|
|
nm_device_interface_activate (NMDeviceInterface *device,
|
2007-09-14 19:51:04 +00:00
|
|
|
const char *service_name,
|
|
|
|
|
const char *connection_path,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
const char *specific_object,
|
|
|
|
|
gboolean user_requested)
|
2007-05-07 15:17:45 +00:00
|
|
|
{
|
|
|
|
|
g_return_if_fail (NM_IS_DEVICE_INTERFACE (device));
|
|
|
|
|
|
2007-08-28 14:47:31 +00:00
|
|
|
NM_DEVICE_INTERFACE_GET_INTERFACE (device)->activate (device,
|
2007-09-14 19:51:04 +00:00
|
|
|
service_name,
|
|
|
|
|
connection_path,
|
2007-08-28 14:47:31 +00:00
|
|
|
connection,
|
|
|
|
|
specific_object,
|
|
|
|
|
user_requested);
|
2007-05-07 15:17:45 +00:00
|
|
|
}
|
|
|
|
|
|
2007-09-26 15:38:51 +00:00
|
|
|
/* FIXME: This should be public and nm_device_get_iface() should be removed. */
|
|
|
|
|
static const char *
|
|
|
|
|
nm_device_interface_get_iface (NMDeviceInterface *device)
|
|
|
|
|
{
|
|
|
|
|
const char *iface = NULL;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (NM_IS_DEVICE_INTERFACE (device), NULL);
|
|
|
|
|
|
|
|
|
|
g_object_get (device, NM_DEVICE_INTERFACE_IFACE, &iface, NULL);
|
|
|
|
|
|
|
|
|
|
return iface;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-07 15:17:45 +00:00
|
|
|
static gboolean
|
|
|
|
|
impl_device_activate (NMDeviceInterface *device,
|
2007-09-09 22:18:42 +00:00
|
|
|
const char *service_name,
|
|
|
|
|
const char *connection_path,
|
|
|
|
|
const char *specific_object,
|
|
|
|
|
GError **err)
|
2007-05-07 15:17:45 +00:00
|
|
|
{
|
2007-09-26 15:38:51 +00:00
|
|
|
nm_info ("User request for activation of %s.", nm_device_interface_get_iface (device));
|
2007-09-14 19:51:04 +00:00
|
|
|
nm_device_interface_activate (device,
|
|
|
|
|
service_name,
|
|
|
|
|
connection_path,
|
|
|
|
|
NULL,
|
|
|
|
|
specific_object,
|
|
|
|
|
TRUE);
|
|
|
|
|
return TRUE;
|
2007-05-07 15:17:45 +00:00
|
|
|
}
|
|
|
|
|
|
2007-02-05 12:14:09 +00:00
|
|
|
void
|
|
|
|
|
nm_device_interface_deactivate (NMDeviceInterface *device)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (NM_IS_DEVICE_INTERFACE (device));
|
|
|
|
|
|
|
|
|
|
NM_DEVICE_INTERFACE_GET_INTERFACE (device)->deactivate (device);
|
|
|
|
|
}
|
2007-02-12 09:23:43 +00:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|