mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-08 11:19:16 +02:00
supplicant: reorganize supplicant manager class
Gets rid of prototypes and simplifies the code a bit.
This commit is contained in:
parent
0e61ddcd27
commit
edd2369eb8
1 changed files with 134 additions and 155 deletions
|
|
@ -36,8 +36,8 @@ typedef struct {
|
||||||
NMDBusManager * dbus_mgr;
|
NMDBusManager * dbus_mgr;
|
||||||
guint32 state;
|
guint32 state;
|
||||||
GHashTable * ifaces;
|
GHashTable * ifaces;
|
||||||
gboolean dispose_has_run;
|
gboolean disposed;
|
||||||
guint poke_id;
|
guint poke_id;
|
||||||
} NMSupplicantManagerPrivate;
|
} NMSupplicantManagerPrivate;
|
||||||
|
|
||||||
#define NM_SUPPLICANT_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
|
#define NM_SUPPLICANT_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
|
||||||
|
|
@ -46,41 +46,14 @@ typedef struct {
|
||||||
|
|
||||||
G_DEFINE_TYPE (NMSupplicantManager, nm_supplicant_manager, G_TYPE_OBJECT)
|
G_DEFINE_TYPE (NMSupplicantManager, nm_supplicant_manager, G_TYPE_OBJECT)
|
||||||
|
|
||||||
|
|
||||||
static void nm_supplicant_manager_name_owner_changed (NMDBusManager *dbus_mgr,
|
|
||||||
const char *name,
|
|
||||||
const char *old,
|
|
||||||
const char *new,
|
|
||||||
gpointer user_data);
|
|
||||||
|
|
||||||
static void nm_supplicant_manager_set_state (NMSupplicantManager * self,
|
|
||||||
guint32 new_state);
|
|
||||||
|
|
||||||
static gboolean nm_supplicant_manager_startup (NMSupplicantManager * self);
|
|
||||||
|
|
||||||
|
|
||||||
/* Signals */
|
/* Signals */
|
||||||
enum {
|
enum {
|
||||||
STATE, /* change in the manager's state */
|
STATE, /* change in the manager's state */
|
||||||
LAST_SIGNAL
|
LAST_SIGNAL
|
||||||
};
|
};
|
||||||
static guint nm_supplicant_manager_signals[LAST_SIGNAL] = { 0 };
|
static guint signals[LAST_SIGNAL] = { 0 };
|
||||||
|
|
||||||
|
/********************************************************************/
|
||||||
NMSupplicantManager *
|
|
||||||
nm_supplicant_manager_get (void)
|
|
||||||
{
|
|
||||||
static NMSupplicantManager * singleton = NULL;
|
|
||||||
|
|
||||||
if (!singleton) {
|
|
||||||
singleton = NM_SUPPLICANT_MANAGER (g_object_new (NM_TYPE_SUPPLICANT_MANAGER, NULL));
|
|
||||||
} else {
|
|
||||||
g_object_ref (singleton);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_assert (singleton);
|
|
||||||
return singleton;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
poke_supplicant_cb (gpointer user_data)
|
poke_supplicant_cb (gpointer user_data)
|
||||||
|
|
@ -114,117 +87,6 @@ out:
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
nm_supplicant_manager_init (NMSupplicantManager * self)
|
|
||||||
{
|
|
||||||
NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self);
|
|
||||||
gboolean running;
|
|
||||||
|
|
||||||
priv->dispose_has_run = FALSE;
|
|
||||||
priv->state = NM_SUPPLICANT_MANAGER_STATE_DOWN;
|
|
||||||
priv->dbus_mgr = nm_dbus_manager_get ();
|
|
||||||
priv->poke_id = 0;
|
|
||||||
|
|
||||||
priv->ifaces = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
|
|
||||||
|
|
||||||
running = nm_supplicant_manager_startup (self);
|
|
||||||
|
|
||||||
g_signal_connect (priv->dbus_mgr,
|
|
||||||
"name-owner-changed",
|
|
||||||
G_CALLBACK (nm_supplicant_manager_name_owner_changed),
|
|
||||||
self);
|
|
||||||
|
|
||||||
if (!running) {
|
|
||||||
/* Try to activate the supplicant */
|
|
||||||
priv->poke_id = g_idle_add (poke_supplicant_cb, (gpointer) self);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
nm_supplicant_manager_dispose (GObject *object)
|
|
||||||
{
|
|
||||||
NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (object);
|
|
||||||
|
|
||||||
if (priv->dispose_has_run) {
|
|
||||||
G_OBJECT_CLASS (nm_supplicant_manager_parent_class)->dispose (object);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
priv->dispose_has_run = TRUE;
|
|
||||||
|
|
||||||
if (priv->poke_id) {
|
|
||||||
g_source_remove (priv->poke_id);
|
|
||||||
priv->poke_id = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (priv->dbus_mgr) {
|
|
||||||
g_object_unref (G_OBJECT (priv->dbus_mgr));
|
|
||||||
priv->dbus_mgr = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Chain up to the parent class */
|
|
||||||
G_OBJECT_CLASS (nm_supplicant_manager_parent_class)->dispose (object);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
nm_supplicant_manager_class_init (NMSupplicantManagerClass *klass)
|
|
||||||
{
|
|
||||||
GObjectClass * object_class = G_OBJECT_CLASS (klass);
|
|
||||||
|
|
||||||
g_type_class_add_private (object_class, sizeof (NMSupplicantManagerPrivate));
|
|
||||||
|
|
||||||
object_class->dispose = nm_supplicant_manager_dispose;
|
|
||||||
|
|
||||||
/* Signals */
|
|
||||||
nm_supplicant_manager_signals[STATE] =
|
|
||||||
g_signal_new ("state",
|
|
||||||
G_OBJECT_CLASS_TYPE (object_class),
|
|
||||||
G_SIGNAL_RUN_LAST,
|
|
||||||
G_STRUCT_OFFSET (NMSupplicantManagerClass, state),
|
|
||||||
NULL, NULL,
|
|
||||||
_nm_marshal_VOID__UINT_UINT,
|
|
||||||
G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
nm_supplicant_manager_name_owner_changed (NMDBusManager *dbus_mgr,
|
|
||||||
const char *name,
|
|
||||||
const char *old_owner,
|
|
||||||
const char *new_owner,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
|
||||||
NMSupplicantManager * self = (NMSupplicantManager *) user_data;
|
|
||||||
NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self);
|
|
||||||
gboolean old_owner_good = (old_owner && strlen (old_owner));
|
|
||||||
gboolean new_owner_good = (new_owner && strlen (new_owner));
|
|
||||||
|
|
||||||
/* Can't handle the signal if its not from the supplicant service */
|
|
||||||
if (strcmp (WPAS_DBUS_SERVICE, name) != 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!old_owner_good && new_owner_good) {
|
|
||||||
gboolean running;
|
|
||||||
|
|
||||||
running = nm_supplicant_manager_startup (self);
|
|
||||||
|
|
||||||
if (running && priv->poke_id) {
|
|
||||||
g_source_remove (priv->poke_id);
|
|
||||||
priv->poke_id = 0;
|
|
||||||
}
|
|
||||||
} else if (old_owner_good && !new_owner_good) {
|
|
||||||
nm_supplicant_manager_set_state (self, NM_SUPPLICANT_MANAGER_STATE_DOWN);
|
|
||||||
|
|
||||||
if (priv->poke_id)
|
|
||||||
g_source_remove (priv->poke_id);
|
|
||||||
|
|
||||||
/* Poke the supplicant so that it gets activated by dbus system bus
|
|
||||||
* activation.
|
|
||||||
*/
|
|
||||||
priv->poke_id = g_idle_add (poke_supplicant_cb, (gpointer) self);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
guint32
|
guint32
|
||||||
nm_supplicant_manager_get_state (NMSupplicantManager * self)
|
nm_supplicant_manager_get_state (NMSupplicantManager * self)
|
||||||
{
|
{
|
||||||
|
|
@ -234,25 +96,20 @@ nm_supplicant_manager_get_state (NMSupplicantManager * self)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nm_supplicant_manager_set_state (NMSupplicantManager * self, guint32 new_state)
|
set_state (NMSupplicantManager *self, guint32 new_state)
|
||||||
{
|
{
|
||||||
NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self);
|
NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self);
|
||||||
guint32 old_state;
|
guint32 old_state;
|
||||||
|
|
||||||
if (new_state == priv->state)
|
if (new_state != priv->state) {
|
||||||
return;
|
old_state = priv->state;
|
||||||
|
priv->state = new_state;
|
||||||
old_state = priv->state;
|
g_signal_emit (self, signals[STATE], 0, priv->state, old_state);
|
||||||
priv->state = new_state;
|
}
|
||||||
g_signal_emit (self,
|
|
||||||
nm_supplicant_manager_signals[STATE],
|
|
||||||
0,
|
|
||||||
priv->state,
|
|
||||||
old_state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
nm_supplicant_manager_startup (NMSupplicantManager * self)
|
startup (NMSupplicantManager * self)
|
||||||
{
|
{
|
||||||
gboolean running;
|
gboolean running;
|
||||||
|
|
||||||
|
|
@ -260,7 +117,7 @@ nm_supplicant_manager_startup (NMSupplicantManager * self)
|
||||||
running = nm_dbus_manager_name_has_owner (NM_SUPPLICANT_MANAGER_GET_PRIVATE (self)->dbus_mgr,
|
running = nm_dbus_manager_name_has_owner (NM_SUPPLICANT_MANAGER_GET_PRIVATE (self)->dbus_mgr,
|
||||||
WPAS_DBUS_SERVICE);
|
WPAS_DBUS_SERVICE);
|
||||||
if (running)
|
if (running)
|
||||||
nm_supplicant_manager_set_state (self, NM_SUPPLICANT_MANAGER_STATE_IDLE);
|
set_state (self, NM_SUPPLICANT_MANAGER_STATE_IDLE);
|
||||||
|
|
||||||
return running;
|
return running;
|
||||||
}
|
}
|
||||||
|
|
@ -322,4 +179,126 @@ nm_supplicant_manager_state_to_string (guint32 state)
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
name_owner_changed (NMDBusManager *dbus_mgr,
|
||||||
|
const char *name,
|
||||||
|
const char *old_owner,
|
||||||
|
const char *new_owner,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
NMSupplicantManager * self = (NMSupplicantManager *) user_data;
|
||||||
|
NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self);
|
||||||
|
gboolean old_owner_good = (old_owner && strlen (old_owner));
|
||||||
|
gboolean new_owner_good = (new_owner && strlen (new_owner));
|
||||||
|
|
||||||
|
/* Can't handle the signal if its not from the supplicant service */
|
||||||
|
if (strcmp (WPAS_DBUS_SERVICE, name) != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!old_owner_good && new_owner_good) {
|
||||||
|
gboolean running;
|
||||||
|
|
||||||
|
running = startup (self);
|
||||||
|
|
||||||
|
if (running && priv->poke_id) {
|
||||||
|
g_source_remove (priv->poke_id);
|
||||||
|
priv->poke_id = 0;
|
||||||
|
}
|
||||||
|
} else if (old_owner_good && !new_owner_good) {
|
||||||
|
set_state (self, NM_SUPPLICANT_MANAGER_STATE_DOWN);
|
||||||
|
|
||||||
|
if (priv->poke_id)
|
||||||
|
g_source_remove (priv->poke_id);
|
||||||
|
|
||||||
|
/* Poke the supplicant so that it gets activated by dbus system bus
|
||||||
|
* activation.
|
||||||
|
*/
|
||||||
|
priv->poke_id = g_idle_add (poke_supplicant_cb, (gpointer) self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************/
|
||||||
|
|
||||||
|
NMSupplicantManager *
|
||||||
|
nm_supplicant_manager_get (void)
|
||||||
|
{
|
||||||
|
static NMSupplicantManager *singleton = NULL;
|
||||||
|
|
||||||
|
if (!singleton)
|
||||||
|
singleton = NM_SUPPLICANT_MANAGER (g_object_new (NM_TYPE_SUPPLICANT_MANAGER, NULL));
|
||||||
|
else
|
||||||
|
g_object_ref (singleton);
|
||||||
|
|
||||||
|
g_assert (singleton);
|
||||||
|
return singleton;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
nm_supplicant_manager_init (NMSupplicantManager * self)
|
||||||
|
{
|
||||||
|
NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self);
|
||||||
|
gboolean running;
|
||||||
|
|
||||||
|
priv->state = NM_SUPPLICANT_MANAGER_STATE_DOWN;
|
||||||
|
priv->dbus_mgr = nm_dbus_manager_get ();
|
||||||
|
priv->poke_id = 0;
|
||||||
|
|
||||||
|
priv->ifaces = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
|
||||||
|
|
||||||
|
running = startup (self);
|
||||||
|
|
||||||
|
g_signal_connect (priv->dbus_mgr,
|
||||||
|
"name-owner-changed",
|
||||||
|
G_CALLBACK (name_owner_changed),
|
||||||
|
self);
|
||||||
|
|
||||||
|
if (!running) {
|
||||||
|
/* Try to activate the supplicant */
|
||||||
|
priv->poke_id = g_idle_add (poke_supplicant_cb, (gpointer) self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
dispose (GObject *object)
|
||||||
|
{
|
||||||
|
NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (object);
|
||||||
|
|
||||||
|
if (priv->disposed) {
|
||||||
|
G_OBJECT_CLASS (nm_supplicant_manager_parent_class)->dispose (object);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
priv->disposed = TRUE;
|
||||||
|
|
||||||
|
if (priv->poke_id) {
|
||||||
|
g_source_remove (priv->poke_id);
|
||||||
|
priv->poke_id = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (priv->dbus_mgr) {
|
||||||
|
g_object_unref (G_OBJECT (priv->dbus_mgr));
|
||||||
|
priv->dbus_mgr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Chain up to the parent class */
|
||||||
|
G_OBJECT_CLASS (nm_supplicant_manager_parent_class)->dispose (object);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
nm_supplicant_manager_class_init (NMSupplicantManagerClass *klass)
|
||||||
|
{
|
||||||
|
GObjectClass * object_class = G_OBJECT_CLASS (klass);
|
||||||
|
|
||||||
|
g_type_class_add_private (object_class, sizeof (NMSupplicantManagerPrivate));
|
||||||
|
|
||||||
|
object_class->dispose = dispose;
|
||||||
|
|
||||||
|
/* Signals */
|
||||||
|
signals[STATE] = g_signal_new ("state",
|
||||||
|
G_OBJECT_CLASS_TYPE (object_class),
|
||||||
|
G_SIGNAL_RUN_LAST,
|
||||||
|
G_STRUCT_OFFSET (NMSupplicantManagerClass, state),
|
||||||
|
NULL, NULL,
|
||||||
|
_nm_marshal_VOID__UINT_UINT,
|
||||||
|
G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue