mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-26 05:20:08 +01:00
core: allow connections to participate in NMManager:startup-complete
Add an NMSettingsConnection:ready property, which indicates if the connection is ready to use. Add NMSettings:startup-complete, which is TRUE when all connections are ready. Make NMManager:startup-complete take NMSettings:startup-complete into account.
This commit is contained in:
parent
c27074bf43
commit
b067ca7034
5 changed files with 118 additions and 4 deletions
|
|
@ -687,6 +687,11 @@ check_if_startup_complete (NMManager *self)
|
|||
if (!priv->startup)
|
||||
return;
|
||||
|
||||
if (!nm_settings_get_startup_complete (priv->settings)) {
|
||||
nm_log_dbg (LOGD_CORE, "check_if_startup_complete returns FALSE because of NMSettings");
|
||||
return;
|
||||
}
|
||||
|
||||
for (iter = priv->devices; iter; iter = iter->next) {
|
||||
NMDevice *dev = iter->data;
|
||||
|
||||
|
|
@ -721,6 +726,14 @@ device_has_pending_action_changed (NMDevice *device,
|
|||
check_if_startup_complete (self);
|
||||
}
|
||||
|
||||
static void
|
||||
settings_startup_complete_changed (NMSettings *settings,
|
||||
GParamSpec *pspec,
|
||||
NMManager *self)
|
||||
{
|
||||
check_if_startup_complete (self);
|
||||
}
|
||||
|
||||
static void
|
||||
remove_device (NMManager *manager,
|
||||
NMDevice *device,
|
||||
|
|
@ -4716,6 +4729,8 @@ nm_manager_new (NMSettings *settings,
|
|||
priv->prop_filter_added = TRUE;
|
||||
|
||||
priv->settings = g_object_ref (settings);
|
||||
g_signal_connect (priv->settings, "notify::" NM_SETTINGS_STARTUP_COMPLETE,
|
||||
G_CALLBACK (settings_startup_complete_changed), singleton);
|
||||
|
||||
priv->state_file = g_strdup (state_file);
|
||||
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ enum {
|
|||
PROP_0 = 0,
|
||||
PROP_VISIBLE,
|
||||
PROP_UNSAVED,
|
||||
PROP_READY,
|
||||
PROP_FLAGS,
|
||||
};
|
||||
|
||||
|
|
@ -98,6 +99,7 @@ typedef struct {
|
|||
guint session_changed_id;
|
||||
|
||||
NMSettingsConnectionFlags flags;
|
||||
gboolean ready;
|
||||
|
||||
guint updated_idle_id;
|
||||
|
||||
|
|
@ -2167,6 +2169,25 @@ nm_settings_connection_get_nm_generated_assumed (NMSettingsConnection *connectio
|
|||
return NM_FLAGS_HAS (nm_settings_connection_get_flags (connection), NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED_ASSUMED);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_settings_connection_get_ready (NMSettingsConnection *connection)
|
||||
{
|
||||
return NM_SETTINGS_CONNECTION_GET_PRIVATE (connection)->ready;
|
||||
}
|
||||
|
||||
void
|
||||
nm_settings_connection_set_ready (NMSettingsConnection *connection,
|
||||
gboolean ready)
|
||||
{
|
||||
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (connection);
|
||||
|
||||
ready = !!ready;
|
||||
if (priv->ready != ready) {
|
||||
priv->ready = ready;
|
||||
g_object_notify (G_OBJECT (connection), NM_SETTINGS_CONNECTION_READY);
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************/
|
||||
|
||||
static void
|
||||
|
|
@ -2175,6 +2196,7 @@ nm_settings_connection_init (NMSettingsConnection *self)
|
|||
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
|
||||
|
||||
priv->visible = FALSE;
|
||||
priv->ready = TRUE;
|
||||
|
||||
priv->session_changed_id = nm_session_monitor_connect (session_changed_cb, self);
|
||||
|
||||
|
|
@ -2249,6 +2271,9 @@ get_property (GObject *object, guint prop_id,
|
|||
case PROP_UNSAVED:
|
||||
g_value_set_boolean (value, nm_settings_connection_get_unsaved (self));
|
||||
break;
|
||||
case PROP_READY:
|
||||
g_value_set_boolean (value, nm_settings_connection_get_ready (self));
|
||||
break;
|
||||
case PROP_FLAGS:
|
||||
g_value_set_uint (value, nm_settings_connection_get_flags (self));
|
||||
break;
|
||||
|
|
@ -2265,6 +2290,9 @@ set_property (GObject *object, guint prop_id,
|
|||
NMSettingsConnection *self = NM_SETTINGS_CONNECTION (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_READY:
|
||||
nm_settings_connection_set_ready (self, g_value_get_boolean (value));
|
||||
break;
|
||||
case PROP_FLAGS:
|
||||
nm_settings_connection_set_flags_all (self, g_value_get_uint (value));
|
||||
break;
|
||||
|
|
@ -2305,6 +2333,13 @@ nm_settings_connection_class_init (NMSettingsConnectionClass *class)
|
|||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_READY,
|
||||
g_param_spec_boolean (NM_SETTINGS_CONNECTION_READY, "", "",
|
||||
TRUE,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_FLAGS,
|
||||
g_param_spec_uint (NM_SETTINGS_CONNECTION_FLAGS, "", "",
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ G_BEGIN_DECLS
|
|||
/* Properties */
|
||||
#define NM_SETTINGS_CONNECTION_VISIBLE "visible"
|
||||
#define NM_SETTINGS_CONNECTION_UNSAVED "unsaved"
|
||||
#define NM_SETTINGS_CONNECTION_READY "ready"
|
||||
#define NM_SETTINGS_CONNECTION_FLAGS "flags"
|
||||
|
||||
|
||||
|
|
@ -196,6 +197,10 @@ gboolean nm_settings_connection_can_autoconnect (NMSettingsConnection *connectio
|
|||
gboolean nm_settings_connection_get_nm_generated (NMSettingsConnection *connection);
|
||||
gboolean nm_settings_connection_get_nm_generated_assumed (NMSettingsConnection *connection);
|
||||
|
||||
gboolean nm_settings_connection_get_ready (NMSettingsConnection *connection);
|
||||
void nm_settings_connection_set_ready (NMSettingsConnection *connection,
|
||||
gboolean ready);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __NETWORKMANAGER_SETTINGS_CONNECTION_H__ */
|
||||
|
|
|
|||
|
|
@ -151,6 +151,8 @@ typedef struct {
|
|||
GSList *unmanaged_specs;
|
||||
GSList *unrecognized_specs;
|
||||
GSList *get_connections_cache;
|
||||
|
||||
gboolean startup_complete;
|
||||
} NMSettingsPrivate;
|
||||
|
||||
#define NM_SETTINGS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTINGS, NMSettingsPrivate))
|
||||
|
|
@ -175,10 +177,42 @@ enum {
|
|||
PROP_HOSTNAME,
|
||||
PROP_CAN_MODIFY,
|
||||
PROP_CONNECTIONS,
|
||||
PROP_STARTUP_COMPLETE,
|
||||
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
static void
|
||||
check_startup_complete (NMSettings *self)
|
||||
{
|
||||
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
|
||||
GHashTableIter iter;
|
||||
NMSettingsConnection *conn;
|
||||
|
||||
if (priv->startup_complete)
|
||||
return;
|
||||
|
||||
g_hash_table_iter_init (&iter, priv->connections);
|
||||
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &conn)) {
|
||||
if (!nm_settings_connection_get_ready (conn))
|
||||
return;
|
||||
}
|
||||
|
||||
priv->startup_complete = TRUE;
|
||||
g_object_notify (G_OBJECT (self), NM_SETTINGS_STARTUP_COMPLETE);
|
||||
}
|
||||
|
||||
static void
|
||||
connection_ready_changed (NMSettingsConnection *conn,
|
||||
GParamSpec *pspec,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMSettings *self = NM_SETTINGS (user_data);
|
||||
|
||||
if (nm_settings_connection_get_ready (conn))
|
||||
check_startup_complete (self);
|
||||
}
|
||||
|
||||
static void
|
||||
plugin_connection_added (NMSystemConfigInterface *config,
|
||||
NMSettingsConnection *connection,
|
||||
|
|
@ -771,6 +805,7 @@ connection_removed (NMSettingsConnection *connection, gpointer user_data)
|
|||
g_signal_handlers_disconnect_by_func (connection, G_CALLBACK (connection_updated), self);
|
||||
g_signal_handlers_disconnect_by_func (connection, G_CALLBACK (connection_updated_by_user), self);
|
||||
g_signal_handlers_disconnect_by_func (connection, G_CALLBACK (connection_visibility_changed), self);
|
||||
g_signal_handlers_disconnect_by_func (connection, G_CALLBACK (connection_ready_changed), self);
|
||||
|
||||
/* Forget about the connection internally */
|
||||
g_hash_table_remove (NM_SETTINGS_GET_PRIVATE (user_data)->connections,
|
||||
|
|
@ -783,6 +818,8 @@ connection_removed (NMSettingsConnection *connection, gpointer user_data)
|
|||
g_signal_emit_by_name (self, NM_CP_SIGNAL_CONNECTION_REMOVED, connection);
|
||||
g_object_notify (G_OBJECT (self), NM_SETTINGS_CONNECTIONS);
|
||||
|
||||
check_startup_complete (self);
|
||||
|
||||
g_object_unref (connection);
|
||||
}
|
||||
|
||||
|
|
@ -888,6 +925,11 @@ claim_connection (NMSettings *self,
|
|||
g_signal_connect (connection, "notify::" NM_SETTINGS_CONNECTION_VISIBLE,
|
||||
G_CALLBACK (connection_visibility_changed),
|
||||
self);
|
||||
if (!priv->startup_complete) {
|
||||
g_signal_connect (connection, "notify::" NM_SETTINGS_CONNECTION_READY,
|
||||
G_CALLBACK (connection_ready_changed),
|
||||
self);
|
||||
}
|
||||
|
||||
/* Export the connection over D-Bus */
|
||||
g_warn_if_fail (nm_connection_get_path (NM_CONNECTION (connection)) == NULL);
|
||||
|
|
@ -1778,6 +1820,16 @@ cp_get_connection_by_uuid (NMConnectionProvider *provider, const char *uuid)
|
|||
|
||||
/***************************************************************/
|
||||
|
||||
gboolean
|
||||
nm_settings_get_startup_complete (NMSettings *self)
|
||||
{
|
||||
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
|
||||
|
||||
return priv->startup_complete;
|
||||
}
|
||||
|
||||
/***************************************************************/
|
||||
|
||||
NMSettings *
|
||||
nm_settings_new (GError **error)
|
||||
{
|
||||
|
|
@ -1798,6 +1850,7 @@ nm_settings_new (GError **error)
|
|||
}
|
||||
|
||||
load_connections (self);
|
||||
check_startup_complete (self);
|
||||
|
||||
nm_dbus_manager_register_object (priv->dbus_mgr, NM_DBUS_PATH_SETTINGS, self);
|
||||
return self;
|
||||
|
|
@ -1898,6 +1951,9 @@ get_property (GObject *object, guint prop_id,
|
|||
g_ptr_array_add (array, g_strdup (path));
|
||||
g_value_take_boxed (value, array);
|
||||
break;
|
||||
case PROP_STARTUP_COMPLETE:
|
||||
g_value_set_boolean (value, nm_settings_get_startup_complete (self));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -37,10 +37,11 @@
|
|||
#define NM_IS_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTINGS))
|
||||
#define NM_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTINGS, NMSettingsClass))
|
||||
|
||||
#define NM_SETTINGS_UNMANAGED_SPECS "unmanaged-specs"
|
||||
#define NM_SETTINGS_HOSTNAME "hostname"
|
||||
#define NM_SETTINGS_CAN_MODIFY "can-modify"
|
||||
#define NM_SETTINGS_CONNECTIONS "connections"
|
||||
#define NM_SETTINGS_UNMANAGED_SPECS "unmanaged-specs"
|
||||
#define NM_SETTINGS_HOSTNAME "hostname"
|
||||
#define NM_SETTINGS_CAN_MODIFY "can-modify"
|
||||
#define NM_SETTINGS_CONNECTIONS "connections"
|
||||
#define NM_SETTINGS_STARTUP_COMPLETE "connections"
|
||||
|
||||
#define NM_SETTINGS_SIGNAL_CONNECTION_ADDED "connection-added"
|
||||
#define NM_SETTINGS_SIGNAL_CONNECTION_UPDATED "connection-updated"
|
||||
|
|
@ -120,4 +121,6 @@ void nm_settings_device_removed (NMSettings *self, NMDevice *device, gboolean qu
|
|||
|
||||
gint nm_settings_sort_connections (gconstpointer a, gconstpointer b);
|
||||
|
||||
gboolean nm_settings_get_startup_complete (NMSettings *self);
|
||||
|
||||
#endif /* __NM_SETTINGS_H__ */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue