mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-06 07:20:14 +01:00
libnm/active-connection: track reason for state changes
Note that the reason tracking starts as soon as the object exists (which is immediately after GDBusObject is created), not when the asynchronous NMObject initialization finishes. That is so that we the reason changes in between are not lost. The vpn-connection should probably be doing the same.
This commit is contained in:
parent
8b649a8c84
commit
40ffb962be
5 changed files with 86 additions and 16 deletions
|
|
@ -1147,6 +1147,7 @@ global:
|
|||
libnm_1_8_0 {
|
||||
global:
|
||||
nm_active_connection_state_reason_get_type;
|
||||
nm_active_connection_get_state_reason;
|
||||
nm_connection_get_setting_dummy;
|
||||
nm_device_dummy_get_type;
|
||||
nm_ip_route_get_variant_attribute_spec;
|
||||
|
|
|
|||
|
|
@ -37,6 +37,8 @@
|
|||
#include "nm-ip6-config.h"
|
||||
#include "nm-remote-connection.h"
|
||||
|
||||
#include "introspection/org.freedesktop.NetworkManager.Connection.Active.h"
|
||||
|
||||
G_DEFINE_TYPE (NMActiveConnection, nm_active_connection, NM_TYPE_OBJECT);
|
||||
|
||||
#define NM_ACTIVE_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_ACTIVE_CONNECTION, NMActiveConnectionPrivate))
|
||||
|
|
@ -57,6 +59,7 @@ typedef struct {
|
|||
NMDhcpConfig *dhcp6_config;
|
||||
gboolean is_vpn;
|
||||
NMDevice *master;
|
||||
NMActiveConnectionStateReason reason;
|
||||
} NMActiveConnectionPrivate;
|
||||
|
||||
enum {
|
||||
|
|
@ -80,6 +83,14 @@ enum {
|
|||
LAST_PROP
|
||||
};
|
||||
|
||||
enum {
|
||||
STATE_CHANGED,
|
||||
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
/**
|
||||
* nm_active_connection_get_connection:
|
||||
* @connection: a #NMActiveConnection
|
||||
|
|
@ -204,6 +215,24 @@ nm_active_connection_get_state (NMActiveConnection *connection)
|
|||
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->state;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_active_connection_get_state_reason:
|
||||
* @connection: a #NMActiveConnection
|
||||
*
|
||||
* Gets the reason for active connection's state.
|
||||
*
|
||||
* Returns: the reason
|
||||
*
|
||||
* Since: 1.8
|
||||
**/
|
||||
NMActiveConnectionStateReason
|
||||
nm_active_connection_get_state_reason (NMActiveConnection *connection)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NM_ACTIVE_CONNECTION_STATE_REASON_UNKNOWN);
|
||||
|
||||
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_active_connection_get_default:
|
||||
* @connection: a #NMActiveConnection
|
||||
|
|
@ -350,6 +379,31 @@ nm_active_connection_init (NMActiveConnection *connection)
|
|||
priv->devices = g_ptr_array_new ();
|
||||
}
|
||||
|
||||
static void
|
||||
state_changed_proxy (NMDBusActiveConnectionProxy *proxy,
|
||||
NMActiveConnectionState state,
|
||||
NMActiveConnectionStateReason reason,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMActiveConnection *connection = NM_ACTIVE_CONNECTION (user_data);
|
||||
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (connection);
|
||||
|
||||
priv->state = state;
|
||||
priv->reason = reason;
|
||||
g_signal_emit (connection, signals[STATE_CHANGED], 0, state, reason);
|
||||
}
|
||||
|
||||
static void
|
||||
constructed (GObject *object)
|
||||
{
|
||||
GDBusProxy *proxy;
|
||||
|
||||
proxy = _nm_object_get_proxy (NM_OBJECT (object), NM_DBUS_INTERFACE_ACTIVE_CONNECTION);
|
||||
g_signal_connect (proxy, "state-changed",
|
||||
G_CALLBACK (state_changed_proxy), object);
|
||||
g_object_unref (proxy);
|
||||
}
|
||||
|
||||
static void
|
||||
dispose (GObject *object)
|
||||
{
|
||||
|
|
@ -503,6 +557,7 @@ nm_active_connection_class_init (NMActiveConnectionClass *ap_class)
|
|||
|
||||
/* virtual methods */
|
||||
object_class->get_property = get_property;
|
||||
object_class->constructed = constructed;
|
||||
object_class->dispose = dispose;
|
||||
object_class->finalize = finalize;
|
||||
|
||||
|
|
@ -693,4 +748,13 @@ nm_active_connection_class_init (NMActiveConnectionClass *ap_class)
|
|||
NM_TYPE_DEVICE,
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
/* signals */
|
||||
signals[STATE_CHANGED] =
|
||||
g_signal_new ("state-changed",
|
||||
G_OBJECT_CLASS_TYPE (object_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
0, NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 2,
|
||||
G_TYPE_UINT, G_TYPE_UINT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,21 +69,23 @@ typedef struct {
|
|||
|
||||
GType nm_active_connection_get_type (void);
|
||||
|
||||
NMRemoteConnection *nm_active_connection_get_connection (NMActiveConnection *connection);
|
||||
const char *nm_active_connection_get_id (NMActiveConnection *connection);
|
||||
const char *nm_active_connection_get_uuid (NMActiveConnection *connection);
|
||||
const char *nm_active_connection_get_connection_type (NMActiveConnection *connection);
|
||||
const char *nm_active_connection_get_specific_object_path (NMActiveConnection *connection);
|
||||
const GPtrArray *nm_active_connection_get_devices (NMActiveConnection *connection);
|
||||
NMActiveConnectionState nm_active_connection_get_state (NMActiveConnection *connection);
|
||||
NMDevice *nm_active_connection_get_master (NMActiveConnection *connection);
|
||||
gboolean nm_active_connection_get_default (NMActiveConnection *connection);
|
||||
NMIPConfig *nm_active_connection_get_ip4_config (NMActiveConnection *connection);
|
||||
NMDhcpConfig *nm_active_connection_get_dhcp4_config (NMActiveConnection *connection);
|
||||
gboolean nm_active_connection_get_default6 (NMActiveConnection *connection);
|
||||
NMIPConfig *nm_active_connection_get_ip6_config (NMActiveConnection *connection);
|
||||
NMDhcpConfig *nm_active_connection_get_dhcp6_config (NMActiveConnection *connection);
|
||||
gboolean nm_active_connection_get_vpn (NMActiveConnection *connection);
|
||||
NMRemoteConnection *nm_active_connection_get_connection (NMActiveConnection *connection);
|
||||
const char *nm_active_connection_get_id (NMActiveConnection *connection);
|
||||
const char *nm_active_connection_get_uuid (NMActiveConnection *connection);
|
||||
const char *nm_active_connection_get_connection_type (NMActiveConnection *connection);
|
||||
const char *nm_active_connection_get_specific_object_path (NMActiveConnection *connection);
|
||||
const GPtrArray *nm_active_connection_get_devices (NMActiveConnection *connection);
|
||||
NMActiveConnectionState nm_active_connection_get_state (NMActiveConnection *connection);
|
||||
NM_AVAILABLE_IN_1_8
|
||||
NMActiveConnectionStateReason nm_active_connection_get_state_reason (NMActiveConnection *connection);
|
||||
NMDevice *nm_active_connection_get_master (NMActiveConnection *connection);
|
||||
gboolean nm_active_connection_get_default (NMActiveConnection *connection);
|
||||
NMIPConfig *nm_active_connection_get_ip4_config (NMActiveConnection *connection);
|
||||
NMDhcpConfig *nm_active_connection_get_dhcp4_config (NMActiveConnection *connection);
|
||||
gboolean nm_active_connection_get_default6 (NMActiveConnection *connection);
|
||||
NMIPConfig *nm_active_connection_get_ip6_config (NMActiveConnection *connection);
|
||||
NMDhcpConfig *nm_active_connection_get_dhcp6_config (NMActiveConnection *connection);
|
||||
gboolean nm_active_connection_get_vpn (NMActiveConnection *connection);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@
|
|||
#include "introspection/org.freedesktop.NetworkManager.Settings.h"
|
||||
#include "introspection/org.freedesktop.NetworkManager.Settings.Connection.h"
|
||||
#include "introspection/org.freedesktop.NetworkManager.VPN.Connection.h"
|
||||
#include "introspection/org.freedesktop.NetworkManager.Connection.Active.h"
|
||||
|
||||
#include "nm-access-point.h"
|
||||
#include "nm-active-connection.h"
|
||||
|
|
@ -2008,6 +2009,8 @@ proxy_type (GDBusObjectManagerClient *manager,
|
|||
return NMDBUS_TYPE_DNS_MANAGER_PROXY;
|
||||
else if (strcmp (interface_name, NM_DBUS_INTERFACE_VPN_CONNECTION) == 0)
|
||||
return NMDBUS_TYPE_VPN_CONNECTION_PROXY;
|
||||
else if (strcmp (interface_name, NM_DBUS_INTERFACE_ACTIVE_CONNECTION) == 0)
|
||||
return NMDBUS_TYPE_ACTIVE_CONNECTION_PROXY;
|
||||
|
||||
/* Use a generic D-Bus Proxy whenever we can. The typed GDBusProxy
|
||||
* subclasses actually use quite some memory, so they're better avoided. */
|
||||
|
|
|
|||
|
|
@ -238,7 +238,7 @@ nm_active_connection_set_state (NMActiveConnection *self,
|
|||
old_state = priv->state;
|
||||
priv->state = new_state;
|
||||
priv->state_set = TRUE;
|
||||
g_signal_emit (self, signals[STATE_CHANGED], 0, new_state, reason);
|
||||
g_signal_emit (self, signals[STATE_CHANGED], 0, (guint) new_state, (guint) reason);
|
||||
_notify (self, PROP_STATE);
|
||||
|
||||
check_master_ready (self);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue