summaryrefslogtreecommitdiff
path: root/libnm-glib
diff options
context:
space:
mode:
Diffstat (limited to 'libnm-glib')
-rw-r--r--libnm-glib/nm-client.c70
-rw-r--r--libnm-glib/nm-client.h4
-rw-r--r--libnm-glib/nm-vpn-connection.c26
-rw-r--r--libnm-glib/nm-vpn-connection.h6
4 files changed, 60 insertions, 46 deletions
diff --git a/libnm-glib/nm-client.c b/libnm-glib/nm-client.c
index 98ed2884b9..8c0b08f1c8 100644
--- a/libnm-glib/nm-client.c
+++ b/libnm-glib/nm-client.c
@@ -21,7 +21,7 @@ typedef struct {
GHashTable *devices;
DBusGProxy *vpn_proxy;
- NMVPNActStage vpn_state;
+ NMVPNConnectionState vpn_state;
gboolean have_vpn_connections;
GHashTable *vpn_connections;
} NMClientPrivate;
@@ -64,12 +64,9 @@ nm_client_init (NMClient *client)
(GDestroyNotify) g_free,
(GDestroyNotify) g_object_unref);
- priv->vpn_connections = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- (GDestroyNotify) g_object_unref);
+ priv->vpn_connections = g_hash_table_new (g_str_hash, g_str_equal);
- priv->vpn_state = NM_VPN_ACT_STAGE_UNKNOWN;
+ priv->vpn_state = NM_VPN_CONNECTION_STATE_UNKNOWN;
}
static GObject*
@@ -284,13 +281,22 @@ proxy_name_owner_changed (DBusGProxy *proxy,
{
if (name && !strcmp (name, NM_DBUS_SERVICE)) {
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (user_data);
-
- if (new_owner && strlen (new_owner) > 0)
- priv->manager_running = TRUE;
- else
- priv->manager_running = FALSE;
-
- g_signal_emit (NM_CLIENT (user_data), signals[MANAGER_RUNNING], 0, priv->manager_running);
+ gboolean old_good = (old_owner && strlen (old_owner));
+ gboolean new_good = (new_owner && strlen (new_owner));
+ gboolean new_running = FALSE;
+
+ if (!old_good && new_good)
+ new_running = TRUE;
+ else if (old_good && !new_good)
+ new_running = FALSE;
+
+ if (new_running != priv->manager_running) {
+ priv->manager_running = new_running;
+ g_signal_emit (NM_CLIENT (user_data),
+ signals[MANAGER_RUNNING],
+ 0,
+ priv->manager_running);
+ }
}
}
@@ -499,16 +505,16 @@ nm_client_sleep (NMClient *client, gboolean sleep)
* For the exact state, each connection has it's own state which' changes
* are also signalled.
*/
-static NMVPNActStage
+static NMVPNConnectionState
nm_client_get_best_vpn_state (NMClient *client)
{
GSList *iter;
- NMVPNActStage state;
- NMVPNActStage best_state = NM_VPN_ACT_STAGE_UNKNOWN;
+ NMVPNConnectionState state;
+ NMVPNConnectionState best_state = NM_VPN_CONNECTION_STATE_UNKNOWN;
for (iter = nm_client_get_vpn_connections (client); iter; iter = iter->next) {
state = nm_vpn_connection_get_state (NM_VPN_CONNECTION (iter->data));
- if (state > best_state && state < NM_VPN_ACT_STAGE_FAILED)
+ if (state > best_state && state < NM_VPN_CONNECTION_STATE_FAILED)
best_state = state;
}
@@ -516,12 +522,15 @@ nm_client_get_best_vpn_state (NMClient *client)
}
static void
-proxy_vpn_state_change (DBusGProxy *proxy, char *connection_name, NMVPNActStage state, gpointer user_data)
+proxy_vpn_state_change (DBusGProxy *proxy,
+ char *connection_name,
+ NMVPNConnectionState state,
+ gpointer user_data)
{
NMClient *client = NM_CLIENT (user_data);
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client);
NMVPNConnection *connection;
- NMVPNActStage best_state;
+ NMVPNConnectionState best_state;
connection = nm_client_get_vpn_connection_by_name (client, connection_name);
if (connection)
@@ -540,6 +549,7 @@ proxy_vpn_connection_added (DBusGProxy *proxy, char *name, gpointer user_data)
NMClient *client = NM_CLIENT (user_data);
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client);
NMVPNConnection *connection;
+ const char * vpn_name;
if (g_hash_table_lookup (priv->vpn_connections, name))
return;
@@ -553,7 +563,11 @@ proxy_vpn_connection_added (DBusGProxy *proxy, char *name, gpointer user_data)
return;
}
- g_hash_table_insert (priv->vpn_connections, name, connection);
+ /* Use the vpn connection object's name to insert into the hash table
+ * so that it's lifetime is the same as the vpn connection object.
+ */
+ vpn_name = nm_vpn_connection_get_name (connection);
+ g_hash_table_insert (priv->vpn_connections, (char *) vpn_name, connection);
g_signal_emit (client, signals[VPN_CONNECTION_ADDED], 0, connection);
}
@@ -638,8 +652,8 @@ get_connections (NMClient *client)
}
static void
-clear_one_vpn_connection (gpointer data,
- gpointer user_data)
+signal_one_vpn_connection_removed (gpointer data,
+ gpointer user_data)
{
NMClient * client = NM_CLIENT (user_data);
NMVPNConnection * connection = NM_VPN_CONNECTION (data);
@@ -658,9 +672,9 @@ clear_vpn_connections (NMClient * client)
priv = NM_CLIENT_GET_PRIVATE (client);
list = nm_client_get_vpn_connections (client);
- g_hash_table_steal_all (priv->vpn_connections);
+ g_hash_table_remove_all (priv->vpn_connections);
- g_slist_foreach (list, clear_one_vpn_connection, client);
+ g_slist_foreach (list, signal_one_vpn_connection_removed, client);
g_slist_foreach (list, (GFunc) g_object_unref, NULL);
g_slist_free (list);
}
@@ -751,21 +765,21 @@ nm_client_remove_vpn_connection (NMClient *client, NMVPNConnection *connection)
return;
}
- g_hash_table_steal (priv->vpn_connections, info.found_key);
+ g_hash_table_remove (priv->vpn_connections, info.found_key);
g_signal_emit (client, signals[VPN_CONNECTION_REMOVED], 0, connection);
g_object_unref (connection);
}
-NMVPNActStage
+NMVPNConnectionState
nm_client_get_vpn_state (NMClient *client)
{
NMClientPrivate *priv;
- g_return_val_if_fail (NM_IS_CLIENT (client), NM_VPN_ACT_STAGE_UNKNOWN);
+ g_return_val_if_fail (NM_IS_CLIENT (client), NM_VPN_CONNECTION_STATE_UNKNOWN);
priv = NM_CLIENT_GET_PRIVATE (client);
- if (priv->vpn_state == NM_VPN_ACT_STAGE_UNKNOWN)
+ if (priv->vpn_state == NM_VPN_CONNECTION_STATE_UNKNOWN)
priv->vpn_state = nm_client_get_best_vpn_state (client);
return priv->vpn_state;
diff --git a/libnm-glib/nm-client.h b/libnm-glib/nm-client.h
index 3c78352798..f6cb3375b9 100644
--- a/libnm-glib/nm-client.h
+++ b/libnm-glib/nm-client.h
@@ -35,7 +35,7 @@ typedef struct {
void (*vpn_connection_added) (NMClient *client, NMVPNConnection *connection);
void (*vpn_connection_removed) (NMClient *client, NMVPNConnection *connection);
- void (*vpn_state_change) (NMClient *client, NMVPNActStage state);
+ void (*vpn_state_change) (NMClient *client, NMVPNConnectionState state);
} NMClientClass;
GType nm_client_get_type (void);
@@ -62,7 +62,7 @@ NMVPNConnection *nm_client_get_vpn_connection_by_name (NMClient *client,
void nm_client_remove_vpn_connection (NMClient *client,
NMVPNConnection *connection);
-NMVPNActStage nm_client_get_vpn_state (NMClient *client);
+NMVPNConnectionState nm_client_get_vpn_state (NMClient *client);
G_END_DECLS
diff --git a/libnm-glib/nm-vpn-connection.c b/libnm-glib/nm-vpn-connection.c
index b77152f8e0..1f6c10d70a 100644
--- a/libnm-glib/nm-vpn-connection.c
+++ b/libnm-glib/nm-vpn-connection.c
@@ -31,7 +31,7 @@ typedef struct {
char *name;
char *user_name;
char *service;
- NMVPNActStage state;
+ NMVPNConnectionState state;
} NMVPNConnectionPrivate;
enum {
@@ -48,7 +48,7 @@ nm_vpn_connection_init (NMVPNConnection *connection)
{
NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);
- priv->state = NM_VPN_ACT_STAGE_UNKNOWN;
+ priv->state = NM_VPN_CONNECTION_STATE_UNKNOWN;
}
static void
@@ -99,7 +99,7 @@ update_properties (NMVPNConnection *connection)
char *name = NULL;
char *user_name = NULL;
char *service = NULL;
- NMVPNActStage state;
+ NMVPNConnectionState state;
GError *err = NULL;
priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);
@@ -125,7 +125,7 @@ update_properties (NMVPNConnection *connection)
priv->user_name = user_name;
priv->service = service;
- nm_vpn_connection_set_state (connection, (NMVPNActStage) state);
+ nm_vpn_connection_set_state (connection, (NMVPNConnectionState) state);
return TRUE;
}
@@ -192,16 +192,16 @@ nm_vpn_connection_get_service (NMVPNConnection *vpn)
return NM_VPN_CONNECTION_GET_PRIVATE (vpn)->service;
}
-NMVPNActStage
+NMVPNConnectionState
nm_vpn_connection_get_state (NMVPNConnection *vpn)
{
- g_return_val_if_fail (NM_IS_VPN_CONNECTION (vpn), NM_VPN_ACT_STAGE_UNKNOWN);
+ g_return_val_if_fail (NM_IS_VPN_CONNECTION (vpn), NM_VPN_CONNECTION_STATE_UNKNOWN);
return NM_VPN_CONNECTION_GET_PRIVATE (vpn)->state;
}
void
-nm_vpn_connection_set_state (NMVPNConnection *vpn, NMVPNActStage state)
+nm_vpn_connection_set_state (NMVPNConnection *vpn, NMVPNConnectionState state)
{
NMVPNConnectionPrivate *priv;
@@ -217,14 +217,14 @@ nm_vpn_connection_set_state (NMVPNConnection *vpn, NMVPNActStage state)
gboolean
nm_vpn_connection_is_activating (NMVPNConnection *vpn)
{
- NMVPNActStage state;
+ NMVPNConnectionState state;
g_return_val_if_fail (NM_IS_VPN_CONNECTION (vpn), FALSE);
state = nm_vpn_connection_get_state (vpn);
- if (state == NM_VPN_ACT_STAGE_PREPARE ||
- state == NM_VPN_ACT_STAGE_CONNECT ||
- state == NM_VPN_ACT_STAGE_IP_CONFIG_GET)
+ if (state == NM_VPN_CONNECTION_STATE_PREPARE ||
+ state == NM_VPN_CONNECTION_STATE_CONNECT ||
+ state == NM_VPN_CONNECTION_STATE_IP_CONFIG_GET)
return TRUE;
return FALSE;
@@ -240,7 +240,7 @@ nm_vpn_connection_activate (NMVPNConnection *vpn, GSList *passwords)
g_return_val_if_fail (NM_IS_VPN_CONNECTION (vpn), FALSE);
g_return_val_if_fail (passwords != NULL, FALSE);
- if (nm_vpn_connection_get_state (vpn) != NM_VPN_ACT_STAGE_DISCONNECTED) {
+ if (nm_vpn_connection_get_state (vpn) != NM_VPN_CONNECTION_STATE_DISCONNECTED) {
g_warning ("VPN connection is already connected or connecting");
return FALSE;
}
@@ -269,7 +269,7 @@ nm_vpn_connection_deactivate (NMVPNConnection *vpn)
{
g_return_val_if_fail (NM_IS_VPN_CONNECTION (vpn), FALSE);
- if (nm_vpn_connection_get_state (vpn) != NM_VPN_ACT_STAGE_ACTIVATED &&
+ if (nm_vpn_connection_get_state (vpn) != NM_VPN_CONNECTION_STATE_ACTIVATED &&
!nm_vpn_connection_is_activating (vpn)) {
g_warning ("VPN connection isn't activated");
return FALSE;
diff --git a/libnm-glib/nm-vpn-connection.h b/libnm-glib/nm-vpn-connection.h
index 0a02253da1..ade2d6de03 100644
--- a/libnm-glib/nm-vpn-connection.h
+++ b/libnm-glib/nm-vpn-connection.h
@@ -45,7 +45,7 @@ typedef struct {
/* Signals */
void (*updated) (NMVPNConnection *connection);
- void (*state_changed) (NMVPNConnection *connection, NMVPNActStage state);
+ void (*state_changed) (NMVPNConnection *connection, NMVPNConnectionState state);
} NMVPNConnectionClass;
GType nm_vpn_connection_get_type (void);
@@ -57,7 +57,7 @@ gboolean nm_vpn_connection_update (NMVPNConnection *vpn);
const char *nm_vpn_connection_get_name (NMVPNConnection *vpn);
const char *nm_vpn_connection_get_user_name (NMVPNConnection *vpn);
const char *nm_vpn_connection_get_service (NMVPNConnection *vpn);
-NMVPNActStage nm_vpn_connection_get_state (NMVPNConnection *vpn);
+NMVPNConnectionState nm_vpn_connection_get_state (NMVPNConnection *vpn);
gboolean nm_vpn_connection_is_activating (NMVPNConnection *vpn);
gboolean nm_vpn_connection_activate (NMVPNConnection *vpn,
@@ -65,7 +65,7 @@ gboolean nm_vpn_connection_activate (NMVPNConnection *vpn,
gboolean nm_vpn_connection_deactivate (NMVPNConnection *vpn);
-void nm_vpn_connection_set_state (NMVPNConnection *vpn, NMVPNActStage state);
+void nm_vpn_connection_set_state (NMVPNConnection *vpn, NMVPNConnectionState state);
G_END_DECLS