diff options
author | Thomas Haller <thaller@redhat.com> | 2014-07-09 19:05:54 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2014-09-25 10:42:19 +0200 |
commit | 4c8378c0bc07de7f9d93c513b89a7ea9228f0741 (patch) | |
tree | 0a98e4742fa771eba57f9af9e1927a6429e48507 | |
parent | b1c5f6a090528d54c125e5a0e07045d30e002fbd (diff) | |
download | NetworkManager-th/rh1066697_reload_config-2.tar.gz |
config: implement reloading of connectivity parametersth/rh1066697_reload_config-2
Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r-- | src/nm-config.c | 7 | ||||
-rw-r--r-- | src/nm-config.h | 2 | ||||
-rw-r--r-- | src/nm-connectivity.c | 83 | ||||
-rw-r--r-- | src/nm-connectivity.h | 4 | ||||
-rw-r--r-- | src/nm-manager.c | 2 |
5 files changed, 89 insertions, 9 deletions
diff --git a/src/nm-config.c b/src/nm-config.c index 93e321abcd..dfcd58d220 100644 --- a/src/nm-config.c +++ b/src/nm-config.c @@ -532,7 +532,12 @@ nm_config_reload (NMConfig *self) /* reloading configuration means we have to carefully check every single option * that we want to support and take specific actions. */ - /* FIXME: no actual reloading implemented yet */ + if ( nm_config_data_get_connectivity_interval (old_data) != nm_config_data_get_connectivity_interval (new_data) + || g_strcmp0 (nm_config_data_get_connectivity_uri (old_data), nm_config_data_get_connectivity_uri (new_data)) + || g_strcmp0 (nm_config_data_get_connectivity_response (old_data), nm_config_data_get_connectivity_response (new_data))) { + nm_log_dbg (LOGD_CORE, "config: reload: change '" NM_CONFIG_CHANGES_CONNECTIVITY "'"); + g_hash_table_insert (changes, NM_CONFIG_CHANGES_CONNECTIVITY, NULL); + } if (g_hash_table_size (changes)) new_data = g_object_ref (new_data); diff --git a/src/nm-config.h b/src/nm-config.h index b95560f947..462c5c8bb4 100644 --- a/src/nm-config.h +++ b/src/nm-config.h @@ -40,6 +40,8 @@ G_BEGIN_DECLS /* Signals */ #define NM_CONFIG_SIGNAL_CONFIG_CHANGED "config-changed" +#define NM_CONFIG_CHANGES_CONNECTIVITY "connectivity" + typedef struct _NMConfigCmdLineOptions NMConfigCmdLineOptions; struct _NMConfig { diff --git a/src/nm-connectivity.c b/src/nm-connectivity.c index 112df1a931..044c491983 100644 --- a/src/nm-connectivity.c +++ b/src/nm-connectivity.c @@ -38,6 +38,8 @@ G_DEFINE_TYPE (NMConnectivity, nm_connectivity, G_TYPE_OBJECT) #define DEFAULT_RESPONSE "NetworkManager is online" /* NOT LOCALIZED */ typedef struct { + NMConfig *config; + char *uri; char *response; guint interval; @@ -365,19 +367,84 @@ _set_property_response (NMConnectivity *self, const char *response) /**************************************************************************/ +static void +_config_changed_cb (NMConfig *config, GHashTable *changes, NMConfigData *old_data, NMConnectivity *self) +{ + gboolean changed = FALSE; + NMConfigData *new_data; + + g_return_if_fail (NM_CONNECTIVITY_GET_PRIVATE (self)->config == config); + + new_data = nm_config_get_data (config); + + g_object_freeze_notify (G_OBJECT (self)); + changed |= _set_property_uri (self, nm_config_data_get_connectivity_uri (new_data)); + changed |= _set_property_interval (self, nm_config_data_get_connectivity_interval (new_data), FALSE); + changed |= _set_property_response (self, nm_config_data_get_connectivity_response (new_data)); + + if (changed) { +#if WITH_CONCHECK + NMConnectivityPrivate *priv = NM_CONNECTIVITY_GET_PRIVATE (self); + + if (priv->check_id) { + if (!priv->running) + run_check (self); + else + priv->run_again = TRUE; + } +#endif + } + + g_object_thaw_notify (G_OBJECT (self)); +} + +static void +_clear_config (NMConnectivity *self) +{ + NMConnectivityPrivate *priv = NM_CONNECTIVITY_GET_PRIVATE (self); + + if (priv->config) { + g_object_remove_weak_pointer (G_OBJECT (priv->config), (gpointer *) &priv->config); + g_signal_handlers_disconnect_by_func (priv->config, _config_changed_cb, self); + priv->config = NULL; + } +} + NMConnectivity * -nm_connectivity_new (void) +nm_connectivity_new_with_config (NMConfig *config) { - NMConfigData *config_data = nm_config_get_data (nm_config_get ()); + NMConnectivity *self; + NMConnectivityPrivate *priv; + NMConfigData *config_data; - /* NMConnectivity is (almost) independent from NMConfig and works - * fine without it. As convenience, the default constructor nm_connectivity_new() - * uses the parameters from NMConfig to create an instance. */ - return g_object_new (NM_TYPE_CONNECTIVITY, + g_return_val_if_fail (config, NULL); + + config_data = nm_config_get_data (config); + self = g_object_new (NM_TYPE_CONNECTIVITY, NM_CONNECTIVITY_URI, nm_config_data_get_connectivity_uri (config_data), NM_CONNECTIVITY_INTERVAL, nm_config_data_get_connectivity_interval (config_data), NM_CONNECTIVITY_RESPONSE, nm_config_data_get_connectivity_response (config_data), NULL); + priv = NM_CONNECTIVITY_GET_PRIVATE (self); + + /* Creating an instance with nm_connectivity_new_with_config() connects + * the instance to the NMConfig instance. When the connectivity parameters + * of the NMConfig object change, the parameters propagate to the connectivity + * object. + * + * When resetting one of the properties externally, the connection + * to the NMConfig instance is released and the NMConnectivity instance + * again becomes entirely independent from NMConfig. + * + * Also, the instance only keeps a weak reference to the NMConfig instance. + */ + priv->config = config; + g_object_add_weak_pointer (G_OBJECT (config), (gpointer *) &priv->config); + g_signal_connect (G_OBJECT (config), + NM_CONFIG_SIGNAL_CONFIG_CHANGED, + G_CALLBACK (_config_changed_cb), + self); + return self; } static void @@ -388,12 +455,15 @@ set_property (GObject *object, guint property_id, switch (property_id) { case PROP_URI: + _clear_config (self); _set_property_uri (self, g_value_get_string (value)); break; case PROP_INTERVAL: + _clear_config (self); _set_property_interval (self, g_value_get_uint (value), TRUE); break; case PROP_RESPONSE: + _clear_config (self); _set_property_response (self, g_value_get_string (value)); break; default: @@ -461,6 +531,7 @@ dispose (GObject *object) _run_check_cancel (self); #endif + _clear_config (self); } diff --git a/src/nm-connectivity.h b/src/nm-connectivity.h index 771abdc237..611d1cbaf3 100644 --- a/src/nm-connectivity.h +++ b/src/nm-connectivity.h @@ -28,6 +28,8 @@ #include "nm-dbus-interface.h" #include "nm-types.h" +#include "nm-config.h" + #define NM_TYPE_CONNECTIVITY (nm_connectivity_get_type ()) #define NM_CONNECTIVITY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_CONNECTIVITY, NMConnectivity)) #define NM_CONNECTIVITY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_CONNECTIVITY, NMConnectivityClass)) @@ -51,7 +53,7 @@ typedef struct { GType nm_connectivity_get_type (void); -NMConnectivity *nm_connectivity_new (void); +NMConnectivity *nm_connectivity_new_with_config (NMConfig *config); void nm_connectivity_set_online (NMConnectivity *self, gboolean online); diff --git a/src/nm-manager.c b/src/nm-manager.c index 55ad180d24..48aa875f7a 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -4705,7 +4705,7 @@ nm_manager_new (NMSettings *settings, g_signal_connect (priv->policy, "notify::" NM_POLICY_ACTIVATING_IP6_DEVICE, G_CALLBACK (policy_activating_device_changed), singleton); - priv->connectivity = nm_connectivity_new (); + priv->connectivity = nm_connectivity_new_with_config (nm_config_get ()); g_signal_connect (priv->connectivity, "notify::" NM_CONNECTIVITY_STATE, G_CALLBACK (connectivity_changed), singleton); |