nm-settings-plugin.h 8.6 KB
Newer Older
Dan Williams's avatar
Dan Williams committed
1
/* NetworkManager system settings service
2 3 4 5 6 7 8 9 10 11 12
 *
 * 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.
 *
13 14 15
 * 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.
16
 *
17
 * Copyright (C) 2007 - 2018 Red Hat, Inc.
Dan Williams's avatar
Dan Williams committed
18
 * Copyright (C) 2008 Novell, Inc.
19 20
 */

21 22
#ifndef __NM_SETTINGS_PLUGIN_H__
#define __NM_SETTINGS_PLUGIN_H__
23

24
#include "nm-connection.h"
25

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#include "nm-settings-storage.h"

typedef struct _NMSettingsPlugin NMSettingsPlugin;

typedef void (*NMSettingsPluginConnectionLoadCallback) (NMSettingsPlugin *self,
                                                        NMSettingsStorage *storage,
                                                        NMConnection *connection,
                                                        gpointer user_data);

typedef struct {
	const char *filename;
	GError *error;
	bool handled:1;
} NMSettingsPluginConnectionLoadEntry;

41 42
#define NM_TYPE_SETTINGS_PLUGIN               (nm_settings_plugin_get_type ())
#define NM_SETTINGS_PLUGIN(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTINGS_PLUGIN, NMSettingsPlugin))
43
#define NM_SETTINGS_PLUGIN_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTINGS_PLUGIN, NMSettingsPluginClass))
44
#define NM_IS_SETTINGS_PLUGIN(obj)            (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTINGS_PLUGIN))
45 46
#define NM_IS_SETTINGS_PLUGIN_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTINGS_PLUGIN))
#define NM_SETTINGS_PLUGIN_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTINGS_PLUGIN, NMSettingsPluginClass))
47

48
#define NM_SETTINGS_PLUGIN_UNMANAGED_SPECS_CHANGED    "unmanaged-specs-changed"
49
#define NM_SETTINGS_PLUGIN_UNRECOGNIZED_SPECS_CHANGED "unrecognized-specs-changed"
50

51
struct _NMSettingsPlugin {
52
	GObject parent;
53
};
54

Dan Winship's avatar
Dan Winship committed
55
typedef struct {
56
	GObjectClass parent;
57

58
	/*
59 60 61 62 63
	 * Return a string list of specifications of devices which NetworkManager
	 * should not manage.  Returned list will be freed by the system settings
	 * service, and each element must be allocated using g_malloc() or its
	 * variants (g_strdup, g_strdup_printf, etc).
	 *
64 65
	 * Each string in the list must be in one of the formats recognized by
	 * nm_device_spec_match_list().
66
	 */
67
	GSList * (*get_unmanaged_specs) (NMSettingsPlugin *self);
68

69 70 71 72 73 74 75 76 77 78
	/*
	 * Return a string list of specifications of devices for which at least
	 * one non-NetworkManager-based configuration is defined. Returned list
	 * will be freed by the system settings service, and each element must be
	 * allocated using g_malloc() or its variants (g_strdup, g_strdup_printf,
	 * etc).
	 *
	 * Each string in the list must be in one of the formats recognized by
	 * nm_device_spec_match_list().
	 */
79
	GSList * (*get_unrecognized_specs) (NMSettingsPlugin *self);
80

81
	/* Requests that the plugin load/reload a set of filenames.
82
	 */
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
	void (*load_connections) (NMSettingsPlugin *self,
	                          NMSettingsPluginConnectionLoadEntry *entries,
	                          gsize n_entries,
	                          NMSettingsPluginConnectionLoadCallback callback,
	                          gpointer user_data);

	/* Requests that the plugin reload all connection files from disk,
	 * and emit signals reflecting new, changed, and removed connections.
	 */
	void (*reload_connections) (NMSettingsPlugin *self,
	                            NMSettingsPluginConnectionLoadCallback callback,
	                            gpointer user_data);

	void (*load_connections_done) (NMSettingsPlugin *self);

	gboolean (*add_connection) (NMSettingsPlugin *self,
	                            NMConnection *connection,
	                            NMSettingsStorage **out_storage,
	                            NMConnection **out_connection,
	                            GError **error);

	gboolean (*update_connection) (NMSettingsPlugin *self,
	                               NMSettingsStorage *storage,
	                               NMConnection *connection,
	                               NMSettingsStorage **out_storage,
	                               NMConnection **out_connection,
	                               GError **error);

	gboolean (*delete_connection) (NMSettingsPlugin *self,
	                               NMSettingsStorage *storage,
	                               GError **error);

	const char *plugin_name;

117
} NMSettingsPluginClass;
118

119 120
/*****************************************************************************/

121
GType nm_settings_plugin_get_type (void);
122

123
/*****************************************************************************/
124

125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
#define NM_SETTINGS_STORAGE_PRINT_FMT \
	NM_HASH_OBFUSCATE_PTR_FMT"/%s"

#define NM_SETTINGS_STORAGE_PRINT_ARG(storage)  \
	NM_HASH_OBFUSCATE_PTR (storage), \
	nm_settings_plugin_get_plugin_name (nm_settings_storage_get_plugin (storage))

static inline const char *
nm_settings_plugin_get_plugin_name (NMSettingsPlugin *self)
{
	NMSettingsPluginClass *klass;

	nm_assert (NM_SETTINGS_PLUGIN (self));

	klass = NM_SETTINGS_PLUGIN_GET_CLASS (self);

	nm_assert (klass && klass->plugin_name && strlen (klass->plugin_name) > 0);

	return klass->plugin_name;
}

/*****************************************************************************/
147

148 149
GSList *nm_settings_plugin_get_unmanaged_specs (NMSettingsPlugin *self);
GSList *nm_settings_plugin_get_unrecognized_specs (NMSettingsPlugin *self);
150

151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
void nm_settings_plugin_reload_connections (NMSettingsPlugin *self,
                                            NMSettingsPluginConnectionLoadCallback callback,
                                            gpointer user_data);

NMSettingsPluginConnectionLoadEntry *nm_settings_plugin_create_connection_load_entries (const char *const*filenames,
                                                                                        gsize *out_len);

void nm_settings_plugin_load_connections (NMSettingsPlugin *self,
                                          NMSettingsPluginConnectionLoadEntry *entries,
                                          gsize n_entries,
                                          NMSettingsPluginConnectionLoadCallback callback,
                                          gpointer user_data);

void nm_settings_plugin_load_connections_done (NMSettingsPlugin *self);

gboolean nm_settings_plugin_add_connection (NMSettingsPlugin *self,
                                            NMConnection *connection,
                                            NMSettingsStorage **out_storage,
                                            NMConnection **out_connection,
                                            GError **error);

gboolean nm_settings_plugin_update_connection (NMSettingsPlugin *self,
                                               NMSettingsStorage *storage,
                                               NMConnection *connection,
                                               NMSettingsStorage **out_storage,
                                               NMConnection **out_connection,
                                               GError **error);

gboolean nm_settings_plugin_delete_connection (NMSettingsPlugin *self,
                                               NMSettingsStorage *storage,
                                               GError **error);

/*****************************************************************************/

typedef NMSettingsPlugin *(*NMSettingsPluginFactoryFunc) (void);

NMSettingsPlugin *nm_settings_plugin_factory (void);
188

189 190 191
/*****************************************************************************
 * Internal API
 *****************************************************************************/
192

193
void _nm_settings_plugin_emit_signal_unmanaged_specs_changed (NMSettingsPlugin *self);
194

195
void _nm_settings_plugin_emit_signal_unrecognized_specs_changed (NMSettingsPlugin *self);
196

197
/*****************************************************************************/
198

199 200 201
/* forward declare this function from NMSettings. It's used by the ifcfg-rh plugin,
 * but that shouldn't include all "nm-settings.h" header. */
NMSettings *nm_settings_get (void);
202

203 204
const char *nm_settings_get_dbus_path_for_uuid (NMSettings *self,
                                                const char *uuid);
205 206

#endif /* __NM_SETTINGS_PLUGIN_H__ */