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 2013 Jiri Pirko <jiri@resnulli.us>
21 #include "nm-default.h"
25 #include <dbus/dbus-glib.h>
27 #include "nm-setting-team.h"
28 #include "nm-param-spec-specialized.h"
30 #include "nm-utils-private.h"
31 #include "nm-dbus-glib-types.h"
32 #include "nm-setting-private.h"
35 * SECTION:nm-setting-team
36 * @short_description: Describes connection properties for teams
37 * @include: nm-setting-team.h
39 * The #NMSettingTeam object is a #NMSetting subclass that describes properties
40 * necessary for team connections.
46 * nm_setting_team_error_quark:
48 * Registers an error quark for #NMSettingTeam if necessary.
50 * Returns: the error quark used for #NMSettingTeam errors.
55 nm_setting_team_error_quark (void)
59 if (G_UNLIKELY (!quark))
60 quark = g_quark_from_static_string ("nm-setting-team-error-quark");
65 G_DEFINE_TYPE_WITH_CODE (NMSettingTeam, nm_setting_team, NM_TYPE_SETTING,
66 _nm_register_setting (NM_SETTING_TEAM_SETTING_NAME,
69 NM_SETTING_TEAM_ERROR))
70 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_TEAM)
72 #define NM_SETTING_TEAM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_TEAM, NMSettingTeamPrivate))
77 } NMSettingTeamPrivate;
87 * nm_setting_team_new:
89 * Creates a new #NMSettingTeam object with default values.
91 * Returns: (transfer full): the new empty #NMSettingTeam object
96 nm_setting_team_new (void)
98 return (NMSetting *) g_object_new (NM_TYPE_SETTING_TEAM, NULL);
102 * nm_setting_team_get_interface_name:
103 * @setting: the #NMSettingTeam
105 * Returns: the #NMSettingTeam:interface-name property of the setting
110 nm_setting_team_get_interface_name (NMSettingTeam *setting)
112 g_return_val_if_fail (NM_IS_SETTING_TEAM (setting), NULL);
114 return NM_SETTING_TEAM_GET_PRIVATE (setting)->interface_name;
118 * nm_setting_team_get_config:
119 * @setting: the #NMSettingTeam
121 * Returns: the #NMSettingTeam:config property of the setting
126 nm_setting_team_get_config (NMSettingTeam *setting)
128 g_return_val_if_fail (NM_IS_SETTING_TEAM (setting), NULL);
130 return NM_SETTING_TEAM_GET_PRIVATE (setting)->config;
134 verify (NMSetting *setting, GSList *all_settings, GError **error)
136 NMSettingTeamPrivate *priv = NM_SETTING_TEAM_GET_PRIVATE (setting);
138 return _nm_setting_verify_deprecated_virtual_iface_name (
139 priv->interface_name, FALSE,
140 NM_SETTING_TEAM_SETTING_NAME, NM_SETTING_TEAM_INTERFACE_NAME,
141 NM_SETTING_TEAM_ERROR,
142 NM_SETTING_TEAM_ERROR_INVALID_PROPERTY,
143 NM_SETTING_TEAM_ERROR_MISSING_PROPERTY,
144 all_settings, error);
148 get_virtual_iface_name (NMSetting *setting)
150 NMSettingTeam *self = NM_SETTING_TEAM (setting);
152 return nm_setting_team_get_interface_name (self);
156 nm_setting_team_init (NMSettingTeam *setting)
161 finalize (GObject *object)
163 NMSettingTeamPrivate *priv = NM_SETTING_TEAM_GET_PRIVATE (object);
165 g_free (priv->interface_name);
166 g_free (priv->config);
168 G_OBJECT_CLASS (nm_setting_team_parent_class)->finalize (object);
172 set_property (GObject *object, guint prop_id,
173 const GValue *value, GParamSpec *pspec)
175 NMSettingTeamPrivate *priv = NM_SETTING_TEAM_GET_PRIVATE (object);
178 case PROP_INTERFACE_NAME:
179 g_free (priv->interface_name);
180 priv->interface_name = g_value_dup_string (value);
183 g_free (priv->config);
184 priv->config = g_value_dup_string (value);
187 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
193 get_property (GObject *object, guint prop_id,
194 GValue *value, GParamSpec *pspec)
196 NMSettingTeam *setting = NM_SETTING_TEAM (object);
199 case PROP_INTERFACE_NAME:
200 g_value_set_string (value, nm_setting_team_get_interface_name (setting));
203 g_value_set_string (value, nm_setting_team_get_config (setting));
206 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
212 nm_setting_team_class_init (NMSettingTeamClass *setting_class)
214 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
215 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
217 g_type_class_add_private (setting_class, sizeof (NMSettingTeamPrivate));
219 /* virtual methods */
220 object_class->set_property = set_property;
221 object_class->get_property = get_property;
222 object_class->finalize = finalize;
223 parent_class->verify = verify;
224 parent_class->get_virtual_iface_name = get_virtual_iface_name;
228 * NMSettingTeam:interface-name:
230 * The name of the virtual in-kernel team network interface
232 g_object_class_install_property
233 (object_class, PROP_INTERFACE_NAME,
234 g_param_spec_string (NM_SETTING_TEAM_INTERFACE_NAME, "", "",
237 NM_SETTING_PARAM_INFERRABLE |
238 G_PARAM_STATIC_STRINGS));
241 * NMSettingTeam:config:
243 * The JSON configuration for the team network interface. The property
244 * should contain raw JSON configuration data suitable for teamd, because
245 * the value is passed directly to teamd. If not specified, the default
246 * configuration is used. See man teamd.conf for the format details.
248 g_object_class_install_property
249 (object_class, PROP_CONFIG,
250 g_param_spec_string (NM_SETTING_TEAM_CONFIG, "", "",
253 NM_SETTING_PARAM_INFERRABLE |
254 G_PARAM_STATIC_STRINGS));