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"
27 #include "nm-setting-team-port.h"
29 #include "nm-utils-private.h"
30 #include "nm-connection-private.h"
31 #include "nm-setting-connection.h"
32 #include "nm-setting-team.h"
35 * SECTION:nm-setting-team-port
36 * @short_description: Describes connection properties for team ports
38 * The #NMSettingTeamPort object is a #NMSetting subclass that describes
39 * optional properties that apply to team ports.
42 G_DEFINE_TYPE_WITH_CODE (NMSettingTeamPort, nm_setting_team_port, NM_TYPE_SETTING,
43 _nm_register_setting (TEAM_PORT, 3))
44 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_TEAM_PORT)
46 #define NM_SETTING_TEAM_PORT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_TEAM_PORT, NMSettingTeamPortPrivate))
50 } NMSettingTeamPortPrivate;
59 * nm_setting_team_port_new:
61 * Creates a new #NMSettingTeamPort object with default values.
63 * Returns: (transfer full): the new empty #NMSettingTeamPort object
66 nm_setting_team_port_new (void)
68 return (NMSetting *) g_object_new (NM_TYPE_SETTING_TEAM_PORT, NULL);
72 * nm_setting_team_port_get_config:
73 * @setting: the #NMSettingTeamPort
75 * Returns: the #NMSettingTeamPort:config property of the setting
78 nm_setting_team_port_get_config (NMSettingTeamPort *setting)
80 g_return_val_if_fail (NM_IS_SETTING_TEAM_PORT (setting), NULL);
82 return NM_SETTING_TEAM_PORT_GET_PRIVATE (setting)->config;
86 verify (NMSetting *setting, NMConnection *connection, GError **error)
89 NMSettingConnection *s_con;
90 const char *slave_type;
92 s_con = nm_connection_get_setting_connection (connection);
96 NM_CONNECTION_ERROR_MISSING_SETTING,
97 _("missing setting"));
98 g_prefix_error (error, "%s: ", NM_SETTING_CONNECTION_SETTING_NAME);
102 slave_type = nm_setting_connection_get_slave_type (s_con);
104 && strcmp (slave_type, NM_SETTING_TEAM_SETTING_NAME)) {
107 NM_CONNECTION_ERROR_INVALID_PROPERTY,
108 _("A connection with a '%s' setting must have the slave-type set to '%s'. Instead it is '%s'"),
109 NM_SETTING_TEAM_PORT_SETTING_NAME,
110 NM_SETTING_TEAM_SETTING_NAME,
112 g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_SLAVE_TYPE);
120 nm_setting_team_port_init (NMSettingTeamPort *setting)
125 set_property (GObject *object, guint prop_id,
126 const GValue *value, GParamSpec *pspec)
128 NMSettingTeamPortPrivate *priv = NM_SETTING_TEAM_PORT_GET_PRIVATE (object);
132 g_free (priv->config);
133 priv->config = g_value_dup_string (value);
136 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
142 get_property (GObject *object, guint prop_id,
143 GValue *value, GParamSpec *pspec)
145 NMSettingTeamPort *setting = NM_SETTING_TEAM_PORT (object);
149 g_value_set_string (value, nm_setting_team_port_get_config (setting));
152 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
158 finalize (GObject *object)
160 NMSettingTeamPortPrivate *priv = NM_SETTING_TEAM_PORT_GET_PRIVATE (object);
162 g_free (priv->config);
164 G_OBJECT_CLASS (nm_setting_team_port_parent_class)->finalize (object);
168 nm_setting_team_port_class_init (NMSettingTeamPortClass *setting_class)
170 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
171 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
173 g_type_class_add_private (setting_class, sizeof (NMSettingTeamPortPrivate));
175 /* virtual methods */
176 object_class->set_property = set_property;
177 object_class->get_property = get_property;
178 object_class->finalize = finalize;
179 parent_class->verify = verify;
183 * NMSettingTeamPort:config:
185 * The JSON configuration for the team port. The property should contain raw
186 * JSON configuration data suitable for teamd, because the value is passed
187 * directly to teamd. If not specified, the default configuration is
188 * used. See man teamd.conf for the format details.
192 * variable: TEAM_PORT_CONFIG
193 * description: Team port configuration in JSON. See man teamd.conf for details.
196 g_object_class_install_property
197 (object_class, PROP_CONFIG,
198 g_param_spec_string (NM_SETTING_TEAM_PORT_CONFIG, "", "",
201 NM_SETTING_PARAM_INFERRABLE |
202 G_PARAM_STATIC_STRINGS));