mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-05 00:38:07 +02:00
core: sync with NETWORKMANAGER_0_7 branch device creation changes
Reduce the diff between head and the 0.7 stable branch. Shouldn't result in any functional changes.
This commit is contained in:
parent
73659e724c
commit
f33b7627fe
4 changed files with 94 additions and 56 deletions
|
|
@ -11,7 +11,7 @@ VOID:UINT,UINT,UINT
|
|||
VOID:STRING,STRING
|
||||
VOID:STRING,UCHAR
|
||||
VOID:STRING,OBJECT
|
||||
VOID:STRING,STRING,POINTER
|
||||
VOID:STRING,STRING,POINTER,POINTER
|
||||
VOID:OBJECT,UINT,UINT
|
||||
VOID:STRING,INT
|
||||
VOID:STRING,UINT
|
||||
|
|
|
|||
|
|
@ -99,8 +99,9 @@ static gboolean poll_killswitches (gpointer user_data);
|
|||
/* Device creators */
|
||||
|
||||
typedef struct {
|
||||
char *device_type_name;
|
||||
GType device_type;
|
||||
char *capability_str;
|
||||
char *category;
|
||||
gboolean (*is_device_fn) (NMHalManager *self, const char *udi);
|
||||
NMDeviceCreatorFn creator_fn;
|
||||
} DeviceCreator;
|
||||
|
|
@ -128,24 +129,15 @@ get_creator (NMHalManager *self, const char *udi)
|
|||
/* Common helpers for built-in device creators */
|
||||
|
||||
static char *
|
||||
nm_get_device_driver_name (LibHalContext *ctx, const char *udi)
|
||||
nm_get_device_driver_name (LibHalContext *ctx, const char *origdev_udi)
|
||||
{
|
||||
char *origdev_udi;
|
||||
char *driver_name = NULL;
|
||||
|
||||
origdev_udi = libhal_device_get_property_string (ctx, udi, "net.originating_device", NULL);
|
||||
if (!origdev_udi) {
|
||||
/* Older HAL uses 'physical_device' */
|
||||
origdev_udi = libhal_device_get_property_string (ctx, udi, "net.physical_device", NULL);
|
||||
}
|
||||
|
||||
if (origdev_udi && libhal_device_property_exists (ctx, origdev_udi, "info.linux.driver", NULL)) {
|
||||
char *drv = libhal_device_get_property_string (ctx, origdev_udi, "info.linux.driver", NULL);
|
||||
driver_name = g_strdup (drv);
|
||||
libhal_free_string (drv);
|
||||
}
|
||||
libhal_free_string (origdev_udi);
|
||||
|
||||
return driver_name;
|
||||
}
|
||||
|
||||
|
|
@ -172,7 +164,10 @@ is_wired_device (NMHalManager *self, const char *udi)
|
|||
}
|
||||
|
||||
static GObject *
|
||||
wired_device_creator (NMHalManager *self, const char *udi, gboolean managed)
|
||||
wired_device_creator (NMHalManager *self,
|
||||
const char *udi,
|
||||
const char *origdev_udi,
|
||||
gboolean managed)
|
||||
{
|
||||
NMHalManagerPrivate *priv = NM_HAL_MANAGER_GET_PRIVATE (self);
|
||||
GObject *device;
|
||||
|
|
@ -185,7 +180,7 @@ wired_device_creator (NMHalManager *self, const char *udi, gboolean managed)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
driver = nm_get_device_driver_name (priv->hal_ctx, udi);
|
||||
driver = nm_get_device_driver_name (priv->hal_ctx, origdev_udi);
|
||||
device = (GObject *) nm_device_ethernet_new (udi, iface, driver, managed);
|
||||
|
||||
libhal_free_string (iface);
|
||||
|
|
@ -217,7 +212,10 @@ is_wireless_device (NMHalManager *self, const char *udi)
|
|||
}
|
||||
|
||||
static GObject *
|
||||
wireless_device_creator (NMHalManager *self, const char *udi, gboolean managed)
|
||||
wireless_device_creator (NMHalManager *self,
|
||||
const char *udi,
|
||||
const char *origdev_udi,
|
||||
gboolean managed)
|
||||
{
|
||||
NMHalManagerPrivate *priv = NM_HAL_MANAGER_GET_PRIVATE (self);
|
||||
GObject *device;
|
||||
|
|
@ -230,7 +228,7 @@ wireless_device_creator (NMHalManager *self, const char *udi, gboolean managed)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
driver = nm_get_device_driver_name (priv->hal_ctx, udi);
|
||||
driver = nm_get_device_driver_name (priv->hal_ctx, origdev_udi);
|
||||
device = (GObject *) nm_device_wifi_new (udi, iface, driver, managed);
|
||||
|
||||
libhal_free_string (iface);
|
||||
|
|
@ -247,36 +245,66 @@ register_built_in_creators (NMHalManager *self)
|
|||
|
||||
/* Wired device */
|
||||
creator = g_slice_new0 (DeviceCreator);
|
||||
creator->device_type_name = g_strdup ("Ethernet");
|
||||
creator->device_type = NM_TYPE_DEVICE_ETHERNET;
|
||||
creator->capability_str = g_strdup ("net.80203");
|
||||
creator->category = g_strdup ("net");
|
||||
creator->is_device_fn = is_wired_device;
|
||||
creator->creator_fn = wired_device_creator;
|
||||
priv->device_creators = g_slist_append (priv->device_creators, creator);
|
||||
|
||||
/* Wireless device */
|
||||
creator = g_slice_new0 (DeviceCreator);
|
||||
creator->device_type_name = g_strdup ("802.11 WiFi");
|
||||
creator->device_type = NM_TYPE_DEVICE_WIFI;
|
||||
creator->capability_str = g_strdup ("net.80211");
|
||||
creator->category = g_strdup ("net");
|
||||
creator->is_device_fn = is_wireless_device;
|
||||
creator->creator_fn = wireless_device_creator;
|
||||
priv->device_creators = g_slist_append (priv->device_creators, creator);
|
||||
}
|
||||
|
||||
static void
|
||||
emit_udi_added (NMHalManager *self, const char *udi, DeviceCreator *creator)
|
||||
{
|
||||
NMHalManagerPrivate *priv = NM_HAL_MANAGER_GET_PRIVATE (self);
|
||||
char *od, *tmp;
|
||||
|
||||
g_return_if_fail (self != NULL);
|
||||
g_return_if_fail (udi != NULL);
|
||||
g_return_if_fail (creator != NULL);
|
||||
|
||||
tmp = g_strdup_printf ("%s.originating_device", creator->category);
|
||||
od = libhal_device_get_property_string (priv->hal_ctx, udi, tmp, NULL);
|
||||
g_free (tmp);
|
||||
|
||||
if (!od) {
|
||||
/* Older HAL uses 'physical_device' */
|
||||
tmp = g_strdup_printf ("%s.physical_device", creator->category);
|
||||
od = libhal_device_get_property_string (priv->hal_ctx, udi, tmp, NULL);
|
||||
g_free (tmp);
|
||||
}
|
||||
|
||||
g_signal_emit (self, signals[UDI_ADDED], 0,
|
||||
udi,
|
||||
od,
|
||||
GSIZE_TO_POINTER (creator->device_type),
|
||||
creator->creator_fn);
|
||||
|
||||
libhal_free_string (od);
|
||||
}
|
||||
|
||||
static void
|
||||
device_added (LibHalContext *ctx, const char *udi)
|
||||
{
|
||||
NMHalManager *self = NM_HAL_MANAGER (libhal_ctx_get_user_data (ctx));
|
||||
DeviceCreator *creator;
|
||||
|
||||
// nm_debug ("New device added (hal udi is '%s').", udi );
|
||||
|
||||
/* Sometimes the device's properties (like net.interface) are not set up yet,
|
||||
* so this call will fail, and it will actually be added when hal sets the device's
|
||||
* capabilities a bit later on.
|
||||
/* If not all the device's properties are set up yet (like net.interface),
|
||||
* the device will actually get added later when HAL signals new device
|
||||
* capabilties.
|
||||
*/
|
||||
creator = get_creator (self, udi);
|
||||
if (creator)
|
||||
g_signal_emit (self, signals[UDI_ADDED], 0, udi, creator->device_type_name, creator->creator_fn);
|
||||
emit_udi_added (self, udi, creator);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -284,8 +312,6 @@ device_removed (LibHalContext *ctx, const char *udi)
|
|||
{
|
||||
NMHalManager *self = NM_HAL_MANAGER (libhal_ctx_get_user_data (ctx));
|
||||
|
||||
// nm_debug ("Device removed (hal udi is '%s').", udi );
|
||||
|
||||
g_signal_emit (self, signals[UDI_REMOVED], 0, udi);
|
||||
}
|
||||
|
||||
|
|
@ -295,11 +321,9 @@ device_new_capability (LibHalContext *ctx, const char *udi, const char *capabili
|
|||
NMHalManager *self = NM_HAL_MANAGER (libhal_ctx_get_user_data (ctx));
|
||||
DeviceCreator *creator;
|
||||
|
||||
// nm_debug ("nm_hal_device_new_capability() called with udi = %s, capability = %s", udi, capability );
|
||||
|
||||
creator = get_creator (self, udi);
|
||||
if (creator)
|
||||
g_signal_emit (self, signals[UDI_ADDED], 0, udi, creator->device_type_name, creator->creator_fn);
|
||||
emit_udi_added (self, udi, creator);
|
||||
}
|
||||
|
||||
static RfKillState
|
||||
|
|
@ -387,21 +411,20 @@ add_initial_devices (NMHalManager *self)
|
|||
|
||||
dbus_error_init (&err);
|
||||
devices = libhal_find_device_by_capability (priv->hal_ctx,
|
||||
creator->capability_str,
|
||||
&num_devices,
|
||||
&err);
|
||||
|
||||
creator->capability_str,
|
||||
&num_devices,
|
||||
&err);
|
||||
if (dbus_error_is_set (&err)) {
|
||||
nm_warning ("could not find existing devices: %s", err.message);
|
||||
dbus_error_free (&err);
|
||||
continue;
|
||||
}
|
||||
if (!devices)
|
||||
continue;
|
||||
|
||||
if (devices) {
|
||||
for (i = 0; i < num_devices; i++) {
|
||||
if (!creator->is_device_fn (self, devices[i]))
|
||||
continue;
|
||||
g_signal_emit (self, signals[UDI_ADDED], 0, devices[i], creator->device_type_name, creator->creator_fn);
|
||||
}
|
||||
for (i = 0; i < num_devices; i++) {
|
||||
if (creator->is_device_fn (self, devices[i]))
|
||||
emit_udi_added (self, devices[i], creator);
|
||||
}
|
||||
|
||||
libhal_free_string_array (devices);
|
||||
|
|
@ -828,8 +851,8 @@ destroy_creator (gpointer data, gpointer user_data)
|
|||
{
|
||||
DeviceCreator *creator = (DeviceCreator *) data;
|
||||
|
||||
g_free (creator->device_type_name);
|
||||
g_free (creator->capability_str);
|
||||
g_free (creator->category);
|
||||
g_slice_free (DeviceCreator, data);
|
||||
}
|
||||
|
||||
|
|
@ -884,9 +907,9 @@ nm_hal_manager_class_init (NMHalManagerClass *klass)
|
|||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (NMHalManagerClass, udi_added),
|
||||
NULL, NULL,
|
||||
_nm_marshal_VOID__STRING_STRING_POINTER,
|
||||
G_TYPE_NONE, 3,
|
||||
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
|
||||
_nm_marshal_VOID__STRING_STRING_POINTER_POINTER,
|
||||
G_TYPE_NONE, 4,
|
||||
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_POINTER);
|
||||
|
||||
signals[UDI_REMOVED] =
|
||||
g_signal_new ("udi-removed",
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ typedef struct {
|
|||
|
||||
typedef GObject *(*NMDeviceCreatorFn) (NMHalManager *manager,
|
||||
const char *udi,
|
||||
const char *origdev_udi,
|
||||
gboolean managed);
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -54,7 +55,8 @@ typedef struct {
|
|||
/* Virtual functions */
|
||||
void (*udi_added) (NMHalManager *manager,
|
||||
const char *udi,
|
||||
const char *type_name,
|
||||
const char *originating_device,
|
||||
gpointer general_device_type,
|
||||
NMDeviceCreatorFn creator_fn);
|
||||
|
||||
void (*udi_removed) (NMHalManager *manager, const char *udi);
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
#include "nm-modem-manager.h"
|
||||
#include "nm-device-interface.h"
|
||||
#include "nm-device-private.h"
|
||||
#include "nm-device-ethernet.h"
|
||||
#include "nm-device-wifi.h"
|
||||
#include "NetworkManagerSystem.h"
|
||||
#include "nm-properties-changed-signal.h"
|
||||
|
|
@ -78,7 +79,8 @@ static void connection_added_default_handler (NMManager *manager,
|
|||
|
||||
static void hal_manager_udi_added_cb (NMHalManager *hal_mgr,
|
||||
const char *udi,
|
||||
const char *type_name,
|
||||
const char *originating_device,
|
||||
gpointer general_type_ptr,
|
||||
NMDeviceCreatorFn creator_fn,
|
||||
gpointer user_data);
|
||||
|
||||
|
|
@ -97,10 +99,11 @@ static void system_settings_properties_changed_cb (DBusGProxy *proxy,
|
|||
GHashTable *properties,
|
||||
gpointer user_data);
|
||||
|
||||
static void add_device (NMManager *self, NMDevice *device, const char *type_name);
|
||||
static void add_device (NMManager *self, NMDevice *device);
|
||||
static void remove_one_device (NMManager *manager, NMDevice *device);
|
||||
|
||||
#define SSD_POKE_INTERVAL 120
|
||||
#define ORIGDEV_TAG "originating-device"
|
||||
|
||||
typedef struct {
|
||||
DBusGMethodInvocation *context;
|
||||
|
|
@ -265,7 +268,7 @@ modem_added (NMModemManager *modem_manager,
|
|||
else
|
||||
type_name = "Unknown modem";
|
||||
|
||||
add_device (NM_MANAGER (user_data), NM_DEVICE (g_object_ref (modem)), type_name);
|
||||
add_device (NM_MANAGER (user_data), NM_DEVICE (g_object_ref (modem)));
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -1699,7 +1702,7 @@ next:
|
|||
}
|
||||
|
||||
static void
|
||||
add_device (NMManager *self, NMDevice *device, const char *type_name)
|
||||
add_device (NMManager *self, NMDevice *device)
|
||||
{
|
||||
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
|
||||
const char *iface;
|
||||
|
|
@ -1707,23 +1710,32 @@ add_device (NMManager *self, NMDevice *device, const char *type_name)
|
|||
priv->devices = g_slist_append (priv->devices, device);
|
||||
|
||||
g_signal_connect (device, "state-changed",
|
||||
G_CALLBACK (manager_device_state_changed),
|
||||
self);
|
||||
G_CALLBACK (manager_device_state_changed),
|
||||
self);
|
||||
|
||||
/* Attach to the access-point-added signal so that the manager can fill
|
||||
* non-SSID-broadcasting APs with an SSID.
|
||||
*/
|
||||
if (NM_IS_DEVICE_WIFI (device)) {
|
||||
g_signal_connect (device, "hidden-ap-found",
|
||||
G_CALLBACK (manager_hidden_ap_found),
|
||||
self);
|
||||
G_CALLBACK (manager_hidden_ap_found),
|
||||
self);
|
||||
|
||||
/* Set initial rfkill state */
|
||||
nm_device_wifi_set_enabled (NM_DEVICE_WIFI (device), priv->wireless_enabled);
|
||||
}
|
||||
|
||||
iface = nm_device_get_iface (device);
|
||||
nm_info ("Found new %s device '%s'.", type_name, iface);
|
||||
if (NM_IS_DEVICE_ETHERNET (device))
|
||||
nm_info ("Found new Ethernet device '%s'.", iface);
|
||||
else if (NM_IS_DEVICE_WIFI (device))
|
||||
nm_info ("Found new 802.11 WiFi device '%s'.", iface);
|
||||
else if (nm_device_get_device_type (device) == NM_DEVICE_TYPE_GSM)
|
||||
nm_info ("Found new GSM device '%s'.", iface);
|
||||
else if (nm_device_get_device_type (device) == NM_DEVICE_TYPE_CDMA)
|
||||
nm_info ("Found new CDMA device '%s'.", iface);
|
||||
else
|
||||
g_assert_not_reached ();
|
||||
|
||||
dbus_g_connection_register_g_object (nm_dbus_manager_get_connection (priv->dbus_mgr),
|
||||
nm_device_get_udi (NM_DEVICE (device)),
|
||||
|
|
@ -1736,7 +1748,8 @@ add_device (NMManager *self, NMDevice *device, const char *type_name)
|
|||
static void
|
||||
hal_manager_udi_added_cb (NMHalManager *hal_mgr,
|
||||
const char *udi,
|
||||
const char *type_name,
|
||||
const char *originating_device,
|
||||
gpointer general_type_ptr,
|
||||
NMDeviceCreatorFn creator_fn,
|
||||
gpointer user_data)
|
||||
{
|
||||
|
|
@ -1751,11 +1764,11 @@ hal_manager_udi_added_cb (NMHalManager *hal_mgr,
|
|||
if (nm_manager_get_device_by_udi (self, udi))
|
||||
return;
|
||||
|
||||
device = creator_fn (hal_mgr, udi, nm_manager_udi_is_managed (self, udi));
|
||||
device = creator_fn (hal_mgr, udi, originating_device, nm_manager_udi_is_managed (self, udi));
|
||||
if (!device)
|
||||
return;
|
||||
|
||||
add_device (self, NM_DEVICE (device), type_name);
|
||||
add_device (self, NM_DEVICE (device));
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue