api: add additional NM daemon states

DISCONNECTING: the only active network connection is now being disconnected
LOCAL, SITE, GLOBAL: one-stop items for level of connectivity, which
we'll use to show when we think we're actually connected to the internet
or behind a captive portal or something
This commit is contained in:
Dan Williams 2011-02-14 17:55:27 -06:00
parent a661f78890
commit ec115ed442
8 changed files with 84 additions and 35 deletions

View file

@ -100,8 +100,14 @@ nm_state_to_string (NMState state)
return _("asleep");
case NM_STATE_CONNECTING:
return _("connecting");
case NM_STATE_CONNECTED:
case NM_STATE_CONNECTED_LOCAL:
return _("connected (local only)");
case NM_STATE_CONNECTED_SITE:
return _("connected (site only)");
case NM_STATE_CONNECTED_GLOBAL:
return _("connected");
case NM_STATE_DISCONNECTING:
return _("disconnecting");
case NM_STATE_DISCONNECTED:
return _("disconnected");
case NM_STATE_UNKNOWN:

View file

@ -62,13 +62,28 @@
#define NM_DBUS_INTERFACE_SECRET_AGENT NM_DBUS_INTERFACE ".SecretAgent"
#define NM_DBUS_PATH_SECRET_AGENT "/org/freedesktop/NetworkManager/SecretAgent"
/* General NetworkManager state */
/**
* NMState:
* @NM_STATE_UNKNOWN: networking state is unknown
* @NM_STATE_ASLEEP: networking is not enabled
* @NM_STATE_DISCONNECTED: there is no active network connection
* @NM_STATE_DISCONNECTING: network connections are being cleaned up
* @NM_STATE_CONNECTING: a network connection is being started
* @NM_STATE_CONNECTED_LOCAL: there is only local IPv4 and/or IPv6 connectivity
* @NM_STATE_CONNECTED_SITE: there is only site-wide IPv4 and/or IPv6 connectivity
* @NM_STATE_CONNECTED_GLOBAL: there is global IPv4 and/or IPv6 Internet connectivity
*
* #NMState values indicate the current overall networking state.
*/
typedef enum {
NM_STATE_UNKNOWN = 0,
NM_STATE_ASLEEP,
NM_STATE_CONNECTING,
NM_STATE_CONNECTED,
NM_STATE_DISCONNECTED
NM_STATE_UNKNOWN = 0,
NM_STATE_ASLEEP = 10,
NM_STATE_DISCONNECTED = 20,
NM_STATE_DISCONNECTING = 30,
NM_STATE_CONNECTING = 40,
NM_STATE_CONNECTED_LOCAL = 50,
NM_STATE_CONNECTED_SITE = 60,
NM_STATE_CONNECTED_GLOBAL = 70
} NMState;
/* Types of NetworkManager devices */

View file

@ -323,27 +323,43 @@
</tp:docstring>
<tp:enumvalue suffix="UNKNOWN" value="0">
<tp:docstring>
The NetworkManager daemon is in an unknown state.
Networking state is unknown.
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="ASLEEP" value="1">
<tp:enumvalue suffix="ASLEEP" value="10">
<tp:docstring>
The NetworkManager daemon is asleep and all interfaces managed by it are inactive.
Networking is inactive and all devices are disabled.
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="CONNECTING" value="2">
<tp:enumvalue suffix="DISCONNECTED" value="20">
<tp:docstring>
The NetworkManager daemon is connecting a device. FIXME: What does this mean when one device is active and another is connecting?
There is no active network connection.
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="CONNECTED" value="3">
<tp:enumvalue suffix="DISCONNECTING" value="30">
<tp:docstring>
The NetworkManager daemon is connected.
Network connections are being cleaned up.
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="DISCONNECTED" value="4">
<tp:enumvalue suffix="CONNECTING" value="40">
<tp:docstring>
The NetworkManager daemon is disconnected.
A network device is connecting to a network and there is no other
available network connection.
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="CONNECTED_LOCAL" value="50">
<tp:docstring>
A network device is connected, but there is only link-local connectivity.
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="CONNECTED_SITE" value="60">
<tp:docstring>
A network device is connected, but there is only site-local connectivity.
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="CONNECTED_GLOBAL" value="70">
<tp:docstring>
A network device is connected, with global network connectivity.
</tp:docstring>
</tp:enumvalue>
</tp:enum>

View file

@ -193,18 +193,18 @@ libnm_glib_update_state (libnm_glib_ctx *ctx,
g_return_if_fail (ctx != NULL);
old_state = ctx->nm_state;
switch (state)
{
case NM_STATE_CONNECTED:
switch (state) {
case NM_STATE_CONNECTED_LOCAL:
case NM_STATE_CONNECTED_SITE:
case NM_STATE_CONNECTED_GLOBAL:
ctx->nm_state = LIBNM_ACTIVE_NETWORK_CONNECTION;
break;
case NM_STATE_ASLEEP:
case NM_STATE_CONNECTING:
case NM_STATE_DISCONNECTED:
case NM_STATE_DISCONNECTING:
ctx->nm_state = LIBNM_NO_NETWORK_CONNECTION;
break;
case NM_STATE_UNKNOWN:
default:
ctx->nm_state = LIBNM_NO_NETWORKMANAGER;

View file

@ -725,7 +725,7 @@ nm_client_class_init (NMClientClass *client_class)
g_param_spec_uint (NM_CLIENT_STATE,
"State",
"NetworkManager state",
NM_STATE_UNKNOWN, NM_STATE_DISCONNECTED, NM_STATE_UNKNOWN,
NM_STATE_UNKNOWN, NM_STATE_CONNECTED_GLOBAL, NM_STATE_UNKNOWN,
G_PARAM_READABLE));
/**

View file

@ -438,6 +438,7 @@ nm_manager_update_state (NMManager *manager)
{
NMManagerPrivate *priv;
NMState new_state = NM_STATE_DISCONNECTED;
GSList *iter;
g_return_if_fail (NM_IS_MANAGER (manager));
@ -446,16 +447,21 @@ nm_manager_update_state (NMManager *manager)
if (manager_sleeping (manager))
new_state = NM_STATE_ASLEEP;
else {
GSList *iter;
for (iter = priv->devices; iter; iter = iter->next) {
NMDevice *dev = NM_DEVICE (iter->data);
NMDeviceState state = nm_device_get_state (dev);
if (nm_device_get_state (dev) == NM_DEVICE_STATE_ACTIVATED) {
new_state = NM_STATE_CONNECTED;
if (state == NM_DEVICE_STATE_ACTIVATED) {
/* FIXME: handle local-only and site too */
new_state = NM_STATE_CONNECTED_GLOBAL;
break;
} else if (nm_device_is_activating (dev)) {
}
if (nm_device_is_activating (dev))
new_state = NM_STATE_CONNECTING;
else if (new_state != NM_STATE_CONNECTING) {
if (state == NM_DEVICE_STATE_DEACTIVATING)
new_state = NM_STATE_DISCONNECTING;
}
}
}

View file

@ -66,7 +66,9 @@ static DBusHandlerResult dbus_filter (DBusConnection *connection G_GNUC_UNUSED,
if (!dbus_message_get_args (message, NULL, DBUS_TYPE_UINT32, &state, DBUS_TYPE_INVALID))
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
if (state == NM_STATE_CONNECTED)
if ( state == NM_STATE_CONNECTED_LOCAL
|| state == NM_STATE_CONNECTED_SITE
|| state == NM_STATE_CONNECTED_GLOBAL)
g_main_loop_quit (loop);
return DBUS_HANDLER_RESULT_HANDLED;
@ -193,7 +195,9 @@ int main (int argc, char *argv[])
/* Check after we setup the filter to ensure that we cannot race. */
state = check_online (connection);
if (state == NM_STATE_CONNECTED)
if ( state == NM_STATE_CONNECTED_LOCAL
|| state == NM_STATE_CONNECTED_SITE
|| state == NM_STATE_CONNECTED_GLOBAL)
return 0;
if (exit_no_nm && (state != NM_STATE_CONNECTING))
return 1;

View file

@ -71,19 +71,21 @@ get_nm_state (NMClient *client)
case NM_STATE_ASLEEP:
state_string = "asleep";
break;
case NM_STATE_CONNECTING:
state_string = "connecting";
break;
case NM_STATE_CONNECTED:
state_string = "connected";
case NM_STATE_CONNECTED_LOCAL:
state_string = "connected (local only)";
break;
case NM_STATE_CONNECTED_SITE:
state_string = "connected (site only)";
break;
case NM_STATE_CONNECTED_GLOBAL:
state_string = "connected (global)";
break;
case NM_STATE_DISCONNECTED:
state_string = "disconnected";
break;
case NM_STATE_UNKNOWN:
default:
state_string = "unknown";