wifi: merge branch 'th/wifi-device-creation-bgo760154'

https://bugzilla.gnome.org/show_bug.cgi?id=760154

(cherry picked from commit 06e0595401)
This commit is contained in:
Thomas Haller 2016-01-06 22:19:54 +01:00
commit a213db5113
4 changed files with 52 additions and 58 deletions

View file

@ -77,6 +77,7 @@ enum {
struct _NMDeviceOlpcMeshPrivate {
NMDevice *companion;
NMManager *manager;
gboolean stage1_waiting;
};
@ -397,7 +398,7 @@ find_companion (NMDeviceOlpcMesh *self)
nm_device_add_pending_action (NM_DEVICE (self), "waiting for companion", TRUE);
/* Try to find the companion if it's already known to the NMManager */
for (list = nm_manager_get_devices (nm_manager_get ()); list ; list = g_slist_next (list)) {
for (list = nm_manager_get_devices (priv->manager); list ; list = g_slist_next (list)) {
if (check_companion (self, NM_DEVICE (list->data))) {
nm_device_queue_recheck_available (NM_DEVICE (self),
NM_DEVICE_STATE_REASON_NONE,
@ -437,35 +438,21 @@ nm_device_olpc_mesh_init (NMDeviceOlpcMesh * self)
{
}
static GObject*
constructor (GType type,
guint n_construct_params,
GObjectConstructParam *construct_params)
static void
constructed (GObject *object)
{
GObject *object;
GObjectClass *klass;
NMDeviceOlpcMesh *self;
NMDeviceWifiCapabilities caps;
NMDeviceOlpcMesh *self = NM_DEVICE_OLPC_MESH (object);
NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self);
klass = G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class);
object = klass->constructor (type, n_construct_params, construct_params);
if (!object)
return NULL;
G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class)->constructed (object);
self = NM_DEVICE_OLPC_MESH (object);
priv->manager = g_object_ref (nm_manager_get ());
if (!nm_platform_wifi_get_capabilities (NM_PLATFORM_GET, nm_device_get_ifindex (NM_DEVICE (self)), &caps)) {
_LOGW (LOGD_HW | LOGD_OLPC, "failed to initialize WiFi driver");
g_object_unref (object);
return NULL;
}
g_signal_connect (nm_manager_get (), "device-added", G_CALLBACK (device_added_cb), self);
g_signal_connect (nm_manager_get (), "device-removed", G_CALLBACK (device_removed_cb), self);
g_signal_connect (priv->manager, "device-added", G_CALLBACK (device_added_cb), self);
g_signal_connect (priv->manager, "device-removed", G_CALLBACK (device_removed_cb), self);
/* shorter timeout for mesh connectivity */
nm_device_set_dhcp_timeout (NM_DEVICE (self), 20);
return object;
}
static void
@ -506,10 +493,15 @@ static void
dispose (GObject *object)
{
NMDeviceOlpcMesh *self = NM_DEVICE_OLPC_MESH (object);
NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self);
companion_cleanup (self);
g_signal_handlers_disconnect_by_func (nm_manager_get (), G_CALLBACK (device_added_cb), self);
g_signal_handlers_disconnect_by_func (nm_manager_get (), G_CALLBACK (device_removed_cb), self);
if (priv->manager) {
g_signal_handlers_disconnect_by_func (priv->manager, G_CALLBACK (device_added_cb), self);
g_signal_handlers_disconnect_by_func (priv->manager, G_CALLBACK (device_removed_cb), self);
g_clear_object (&priv->manager);
}
G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class)->dispose (object);
}
@ -522,7 +514,7 @@ nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *klass)
g_type_class_add_private (object_class, sizeof (NMDeviceOlpcMeshPrivate));
object_class->constructor = constructor;
object_class->constructed = constructed;
object_class->get_property = get_property;
object_class->set_property = set_property;
object_class->dispose = dispose;

View file

@ -189,39 +189,19 @@ static void remove_supplicant_interface_error_handler (NMDeviceWifi *self);
/*****************************************************************/
static GObject*
constructor (GType type,
guint n_construct_params,
GObjectConstructParam *construct_params)
static void
constructed (GObject *object)
{
GObject *object;
GObjectClass *klass;
NMDeviceWifi *self;
NMDeviceWifiPrivate *priv;
NMDeviceWifi *self = NM_DEVICE_WIFI (object);
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
klass = G_OBJECT_CLASS (nm_device_wifi_parent_class);
object = klass->constructor (type, n_construct_params, construct_params);
if (!object)
return NULL;
self = NM_DEVICE_WIFI (object);
priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
if (!nm_platform_wifi_get_capabilities (NM_PLATFORM_GET,
nm_device_get_ifindex (NM_DEVICE (self)),
&priv->capabilities)) {
_LOGW (LOGD_HW | LOGD_WIFI, "failed to initialize WiFi driver");
g_object_unref (object);
return NULL;
}
G_OBJECT_CLASS (nm_device_wifi_parent_class)->constructed (object);
if (priv->capabilities & NM_WIFI_DEVICE_CAP_AP)
_LOGI (LOGD_HW | LOGD_WIFI, "driver supports Access Point (AP) mode");
/* Connect to the supplicant manager */
priv->sup_mgr = g_object_ref (nm_supplicant_manager_get ());
return object;
}
static gboolean
@ -3196,7 +3176,7 @@ set_enabled (NMDevice *device, gboolean enabled)
/********************************************************************/
NMDevice *
nm_device_wifi_new (NMPlatformLink *platform_device)
nm_device_wifi_new (NMPlatformLink *platform_device, NMDeviceWifiCapabilities capabilities)
{
g_return_val_if_fail (platform_device != NULL, NULL);
@ -3205,6 +3185,7 @@ nm_device_wifi_new (NMPlatformLink *platform_device)
NM_DEVICE_TYPE_DESC, "802.11 WiFi",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_WIFI,
NM_DEVICE_RFKILL_TYPE, RFKILL_TYPE_WLAN,
NM_DEVICE_WIFI_CAPABILITIES, (guint) capabilities,
NULL);
}
@ -3296,7 +3277,14 @@ static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMDeviceWifi *device = NM_DEVICE_WIFI (object);
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device);
switch (prop_id) {
case PROP_CAPABILITIES:
/* construct-only */
priv->capabilities = g_value_get_uint (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -3312,7 +3300,7 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
g_type_class_add_private (object_class, sizeof (NMDeviceWifiPrivate));
object_class->constructor = constructor;
object_class->constructed = constructed;
object_class->get_property = get_property;
object_class->set_property = set_property;
object_class->dispose = dispose;
@ -3381,7 +3369,8 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
(object_class, PROP_CAPABILITIES,
g_param_spec_uint (NM_DEVICE_WIFI_CAPABILITIES, "", "",
0, G_MAXUINT32, NM_WIFI_DEVICE_CAP_NONE,
G_PARAM_READABLE |
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property

View file

@ -75,7 +75,7 @@ struct _NMDeviceWifiClass
GType nm_device_wifi_get_type (void);
NMDevice *nm_device_wifi_new (NMPlatformLink *platform_device);
NMDevice *nm_device_wifi_new (NMPlatformLink *platform_device, NMDeviceWifiCapabilities capabilities);
G_END_DECLS

View file

@ -29,6 +29,8 @@
#include "nm-device-olpc-mesh.h"
#include "nm-settings-connection.h"
#include "nm-platform.h"
#include "nm-macros-internal.h"
#include "nm-logging.h"
#define NM_TYPE_WIFI_FACTORY (nm_wifi_factory_get_type ())
#define NM_WIFI_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_WIFI_FACTORY, NMWifiFactory))
@ -61,11 +63,22 @@ nm_device_factory_create (GError **error)
static NMDevice *
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, gboolean *out_ignore, GError **error)
{
NMDeviceWifiCapabilities capabilities;
g_return_val_if_fail (plink != NULL, NULL);
g_return_val_if_fail (NM_IN_SET (plink->type, NM_LINK_TYPE_WIFI, NM_LINK_TYPE_OLPC_MESH), NULL);
if (!nm_platform_wifi_get_capabilities (NM_PLATFORM_GET,
plink->ifindex,
&capabilities)) {
nm_log_warn (LOGD_HW | LOGD_WIFI, "(%s) failed to initialize Wi-Fi driver for ifindex %d", plink->name, plink->ifindex);
return NULL;
}
if (plink->type == NM_LINK_TYPE_WIFI)
return nm_device_wifi_new (plink);
else if (plink->type == NM_LINK_TYPE_OLPC_MESH)
return nm_device_wifi_new (plink, capabilities);
else
return nm_device_olpc_mesh_new (plink);
g_assert_not_reached ();
}
NM_DEVICE_FACTORY_DECLARE_TYPES (