summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-07-11 17:57:20 +0200
committerThomas Haller <thaller@redhat.com>2015-02-03 13:01:53 +0100
commit076478505dd1c278898d64d389184d7fb2b6c158 (patch)
tree62ea9eba1172f175b8e739788c3c313d2d5b0720
parent1ff5154369f69f1e266521dd5f2ed53c37baa84f (diff)
downloadNetworkManager-076478505dd1c278898d64d389184d7fb2b6c158.tar.gz
config: add new NMConfigData class
The NMConfig class should be immutable and its properties should not change, with one exception: the NMConfigData property. Later, when changing/reloading a configuration, NMConfig will only swap the NMConfigData instance. The NMConfigData instance itself is also immutable.
-rw-r--r--src/Makefile.am2
-rw-r--r--src/nm-config-data.c183
-rw-r--r--src/nm-config-data.h65
-rw-r--r--src/nm-types.h1
4 files changed, 251 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index a5a40fba35..e0ed6f3f66 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -287,6 +287,8 @@ nm_sources = \
nm-active-connection.h \
nm-config.c \
nm-config.h \
+ nm-config-data.c \
+ nm-config-data.h \
nm-connection-provider.c \
nm-connection-provider.h \
nm-connectivity.c \
diff --git a/src/nm-config-data.c b/src/nm-config-data.c
new file mode 100644
index 0000000000..a5722453ed
--- /dev/null
+++ b/src/nm-config-data.c
@@ -0,0 +1,183 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager -- Network link manager
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2011 Red Hat, Inc.
+ * Copyright (C) 2013 Thomas Bechtold <thomasbechtold@jpberlin.de>
+ */
+
+#include "nm-config-data.h"
+
+typedef struct {
+ struct {
+ char *uri;
+ char *response;
+ guint interval;
+ } connectivity;
+} NMConfigDataPrivate;
+
+
+enum {
+ PROP_0,
+ PROP_CONNECTIVITY_URI,
+ PROP_CONNECTIVITY_INTERVAL,
+ PROP_CONNECTIVITY_RESPONSE,
+
+ LAST_PROP
+};
+
+G_DEFINE_TYPE (NMConfigData, nm_config_data, G_TYPE_OBJECT)
+
+#define NM_CONFIG_DATA_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_CONFIG_DATA, NMConfigDataPrivate))
+
+/************************************************************************/
+
+const char *
+nm_config_data_get_connectivity_uri (const NMConfigData *self)
+{
+ g_return_val_if_fail (self, NULL);
+
+ return NM_CONFIG_DATA_GET_PRIVATE (self)->connectivity.uri;
+}
+
+const guint
+nm_config_data_get_connectivity_interval (const NMConfigData *self)
+{
+ g_return_val_if_fail (self, 0);
+
+ return MAX (NM_CONFIG_DATA_GET_PRIVATE (self)->connectivity.interval, 0);
+}
+
+const char *
+nm_config_data_get_connectivity_response (const NMConfigData *self)
+{
+ g_return_val_if_fail (self != NULL, NULL);
+
+ return NM_CONFIG_DATA_GET_PRIVATE (self)->connectivity.response;
+}
+
+
+/************************************************************************/
+
+static void
+get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ NMConfigData *self = NM_CONFIG_DATA (object);
+
+ switch (prop_id) {
+ case PROP_CONNECTIVITY_URI:
+ g_value_set_string (value, nm_config_data_get_connectivity_uri (self));
+ break;
+ case PROP_CONNECTIVITY_INTERVAL:
+ g_value_set_uint (value, nm_config_data_get_connectivity_interval (self));
+ break;
+ case PROP_CONNECTIVITY_RESPONSE:
+ g_value_set_string (value, nm_config_data_get_connectivity_response (self));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ NMConfigData *self = NM_CONFIG_DATA (object);
+ NMConfigDataPrivate *priv = NM_CONFIG_DATA_GET_PRIVATE (self);
+
+ /* This type is immutable. All properties are construct only. */
+ switch (prop_id) {
+ case PROP_CONNECTIVITY_URI:
+ priv->connectivity.uri = g_value_dup_string (value);
+ break;
+ case PROP_CONNECTIVITY_INTERVAL:
+ priv->connectivity.interval = g_value_get_uint (value);
+ break;
+ case PROP_CONNECTIVITY_RESPONSE:
+ priv->connectivity.response = g_value_dup_string (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+dispose (GObject *object)
+{
+}
+
+static void
+finalize (GObject *gobject)
+{
+ NMConfigDataPrivate *priv = NM_CONFIG_DATA_GET_PRIVATE (gobject);
+
+ g_free (priv->connectivity.uri);
+ g_free (priv->connectivity.response);
+
+ G_OBJECT_CLASS (nm_config_data_parent_class)->finalize (gobject);
+}
+
+static void
+nm_config_data_init (NMConfigData *self)
+{
+}
+
+static void
+nm_config_data_class_init (NMConfigDataClass *config_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (config_class);
+
+ g_type_class_add_private (config_class, sizeof (NMConfigDataPrivate));
+
+ object_class->dispose = dispose;
+ object_class->finalize = finalize;
+ object_class->get_property = get_property;
+ object_class->set_property = set_property;
+
+ g_object_class_install_property
+ (object_class, PROP_CONNECTIVITY_URI,
+ g_param_spec_string (NM_CONFIG_DATA_CONNECTIVITY_URI, "", "",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property
+ (object_class, PROP_CONNECTIVITY_INTERVAL,
+ g_param_spec_uint (NM_CONFIG_DATA_CONNECTIVITY_INTERVAL, "", "",
+ 0, G_MAXUINT, 0,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property
+ (object_class, PROP_CONNECTIVITY_RESPONSE,
+ g_param_spec_string (NM_CONFIG_DATA_CONNECTIVITY_RESPONSE, "", "",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+}
+
diff --git a/src/nm-config-data.h b/src/nm-config-data.h
new file mode 100644
index 0000000000..1437781e7d
--- /dev/null
+++ b/src/nm-config-data.h
@@ -0,0 +1,65 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager -- Network link manager
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ */
+
+#ifndef NM_CONFIG_DATA_H
+#define NM_CONFIG_DATA_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include "nm-types.h"
+
+G_BEGIN_DECLS
+
+#define NM_TYPE_CONFIG_DATA (nm_config_data_get_type ())
+#define NM_CONFIG_DATA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_CONFIG_DATA, NMConfigData))
+#define NM_CONFIG_DATA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_CONFIG_DATA, NMConfigDataClass))
+#define NM_IS_CONFIG_DATA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_CONFIG_DATA))
+#define NM_IS_CONFIG_DATA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_CONFIG_DATA))
+#define NM_CONFIG_DATA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_CONFIG_DATA, NMConfigDataClass))
+
+
+#define NM_CONFIG_DATA_CONNECTIVITY_URI "connectivity-uri"
+#define NM_CONFIG_DATA_CONNECTIVITY_INTERVAL "connectivity-interval"
+#define NM_CONFIG_DATA_CONNECTIVITY_RESPONSE "connectivity-response"
+
+struct _NMConfigData {
+ GObject parent;
+};
+
+typedef struct {
+ GObjectClass parent;
+} NMConfigDataClass;
+
+GType nm_config_data_get_type (void);
+
+const char *nm_config_data_get_connectivity_uri (const NMConfigData *config_data);
+const guint nm_config_data_get_connectivity_interval (const NMConfigData *config_data);
+const char *nm_config_data_get_connectivity_response (const NMConfigData *config_data);
+
+#include "nm-config.h"
+
+/* private function: internal use only */
+void _nm_config_data_set_config (NMConfigData *config_data, NMConfig *config);
+
+G_END_DECLS
+
+#endif /* NM_CONFIG_DATA_H */
+
diff --git a/src/nm-types.h b/src/nm-types.h
index bbdfce9b79..7229eba8b0 100644
--- a/src/nm-types.h
+++ b/src/nm-types.h
@@ -27,6 +27,7 @@ typedef struct _NMVpnConnection NMVpnConnection;
typedef struct _NMActRequest NMActRequest;
typedef struct _NMAuthSubject NMAuthSubject;
typedef struct _NMConfig NMConfig;
+typedef struct _NMConfigData NMConfigData;
typedef struct _NMConnectionProvider NMConnectionProvider;
typedef struct _NMConnectivity NMConnectivity;
typedef struct _NMDBusManager NMDBusManager;