1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301 USA.
18 * Copyright 2007 - 2008 Novell, Inc.
19 * Copyright 2007 - 2014 Red Hat, Inc.
22 #include "nm-default.h"
24 #include "nm-simple-connection.h"
25 #include "nm-setting-private.h"
27 static void nm_simple_connection_interface_init (NMConnectionInterface *iface);
29 G_DEFINE_TYPE_WITH_CODE (NMSimpleConnection, nm_simple_connection, G_TYPE_OBJECT,
30 G_IMPLEMENT_INTERFACE (NM_TYPE_CONNECTION, nm_simple_connection_interface_init);
34 nm_simple_connection_init (NMSimpleConnection *self)
39 * nm_simple_connection_new:
41 * Creates a new #NMSimpleConnection object with no #NMSetting objects. An
42 * #NMSimpleConnection does not directly represent a D-Bus-exported connection,
43 * but might be used in the process of creating a new one.
45 * Returns: (transfer full): the new empty #NMConnection object
48 nm_simple_connection_new (void)
50 return (NMConnection *) g_object_new (NM_TYPE_SIMPLE_CONNECTION, NULL);
54 * _nm_simple_connection_new_from_dbus:
55 * @dict: a #GVariant of type %NM_VARIANT_TYPE_CONNECTION describing the connection
56 * @error: on unsuccessful return, an error
58 * Creates a new #NMSimpleConnection from a hash table describing the
59 * connection. See nm_connection_to_dbus() for a description of the expected
62 * Returns: (transfer full): the new #NMSimpleConnection object, populated with
63 * settings created from the values in the hash table, or %NULL if there was
67 _nm_simple_connection_new_from_dbus (GVariant *dict, NMSettingParseFlags parse_flags, GError **error)
69 NMConnection *connection;
71 g_return_val_if_fail (dict != NULL, NULL);
72 g_return_val_if_fail (g_variant_is_of_type (dict, NM_VARIANT_TYPE_CONNECTION), NULL);
73 g_return_val_if_fail (!NM_FLAGS_ANY (parse_flags, ~NM_SETTING_PARSE_FLAGS_ALL), NULL);
74 g_return_val_if_fail (!NM_FLAGS_ALL (parse_flags, NM_SETTING_PARSE_FLAGS_STRICT | NM_SETTING_PARSE_FLAGS_BEST_EFFORT), NULL);
76 connection = nm_simple_connection_new ();
77 if (!_nm_connection_replace_settings (connection, dict, parse_flags, error))
78 g_clear_object (&connection);
83 * nm_simple_connection_new_from_dbus:
84 * @dict: a #GVariant of type %NM_VARIANT_TYPE_CONNECTION describing the connection
85 * @error: on unsuccessful return, an error
87 * Creates a new #NMSimpleConnection from a hash table describing the
88 * connection and normalize the connection. See nm_connection_to_dbus() for a
89 * description of the expected hash table.
91 * Returns: (transfer full): the new #NMSimpleConnection object, populated with
92 * settings created from the values in the hash table, or %NULL if the
93 * connection failed to normalize.
96 nm_simple_connection_new_from_dbus (GVariant *dict, GError **error)
98 return _nm_simple_connection_new_from_dbus (dict,
99 NM_SETTING_PARSE_FLAGS_NORMALIZE,
104 * nm_simple_connection_new_clone:
105 * @connection: the #NMConnection to clone
107 * Clones an #NMConnection as an #NMSimpleConnection.
109 * Returns: (transfer full): a new #NMConnection containing the same settings
110 * and properties as the source #NMConnection
113 nm_simple_connection_new_clone (NMConnection *connection)
117 g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
119 clone = nm_simple_connection_new ();
120 nm_connection_set_path (clone, nm_connection_get_path (connection));
121 nm_connection_replace_settings_from_connection (clone, connection);
127 dispose (GObject *object)
129 nm_connection_clear_secrets (NM_CONNECTION (object));
131 G_OBJECT_CLASS (nm_simple_connection_parent_class)->dispose (object);
135 nm_simple_connection_class_init (NMSimpleConnectionClass *simple_class)
137 GObjectClass *object_class = G_OBJECT_CLASS (simple_class);
139 object_class->dispose = dispose;
143 nm_simple_connection_interface_init (NMConnectionInterface *iface)