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 "nm-setting-connection.h"
26 #include "nm-setting-team.h"
29 #include "nm-device-team.h"
30 #include "nm-device-private.h"
31 #include "nm-object-private.h"
32 #include "nm-core-internal.h"
34 G_DEFINE_TYPE (NMDeviceTeam, nm_device_team, NM_TYPE_DEVICE)
36 #define NM_DEVICE_TEAM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_TEAM, NMDeviceTeamPrivate))
42 } NMDeviceTeamPrivate;
54 * nm_device_team_get_hw_address:
55 * @device: a #NMDeviceTeam
57 * Gets the hardware (MAC) address of the #NMDeviceTeam
59 * Returns: the hardware address. This is the internal string used by the
60 * device, and must not be modified.
63 nm_device_team_get_hw_address (NMDeviceTeam *device)
65 g_return_val_if_fail (NM_IS_DEVICE_TEAM (device), NULL);
67 return NM_DEVICE_TEAM_GET_PRIVATE (device)->hw_address;
71 * nm_device_team_get_carrier:
72 * @device: a #NMDeviceTeam
74 * Whether the device has carrier.
76 * Returns: %TRUE if the device has carrier
79 nm_device_team_get_carrier (NMDeviceTeam *device)
81 g_return_val_if_fail (NM_IS_DEVICE_TEAM (device), FALSE);
83 return NM_DEVICE_TEAM_GET_PRIVATE (device)->carrier;
87 * nm_device_team_get_slaves:
88 * @device: a #NMDeviceTeam
90 * Gets the devices currently enslaved to @device.
92 * Returns: (element-type NMDevice): the #GPtrArray containing
93 * #NMDevices that are slaves of @device. This is the internal
94 * copy used by the device, and must not be modified.
97 nm_device_team_get_slaves (NMDeviceTeam *device)
99 g_return_val_if_fail (NM_IS_DEVICE_TEAM (device), FALSE);
101 return NM_DEVICE_TEAM_GET_PRIVATE (device)->slaves;
105 get_hw_address (NMDevice *device)
107 return nm_device_team_get_hw_address (NM_DEVICE_TEAM (device));
111 connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
113 if (!NM_DEVICE_CLASS (nm_device_team_parent_class)->connection_compatible (device, connection, error))
116 if (!nm_connection_is_type (connection, NM_SETTING_TEAM_SETTING_NAME)) {
117 g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION,
118 _("The connection was not a team connection."));
122 /* FIXME: check slaves? */
128 get_setting_type (NMDevice *device)
130 return NM_TYPE_SETTING_TEAM;
133 /***********************************************************/
136 nm_device_team_init (NMDeviceTeam *device)
138 NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (device);
140 _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_TEAM);
142 priv->slaves = g_ptr_array_new ();
146 init_dbus (NMObject *object)
148 NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (object);
149 const NMPropertiesInfo property_info[] = {
150 { NM_DEVICE_TEAM_HW_ADDRESS, &priv->hw_address },
151 { NM_DEVICE_TEAM_CARRIER, &priv->carrier },
152 { NM_DEVICE_TEAM_SLAVES, &priv->slaves, NULL, NM_TYPE_DEVICE },
156 NM_OBJECT_CLASS (nm_device_team_parent_class)->init_dbus (object);
158 _nm_object_register_properties (object,
159 NM_DBUS_INTERFACE_DEVICE_TEAM,
164 dispose (GObject *object)
166 NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (object);
168 g_clear_pointer (&priv->slaves, g_ptr_array_unref);
170 G_OBJECT_CLASS (nm_device_team_parent_class)->dispose (object);
174 finalize (GObject *object)
176 NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (object);
178 g_free (priv->hw_address);
180 G_OBJECT_CLASS (nm_device_team_parent_class)->finalize (object);
184 get_property (GObject *object,
189 NMDeviceTeam *device = NM_DEVICE_TEAM (object);
192 case PROP_HW_ADDRESS:
193 g_value_set_string (value, nm_device_team_get_hw_address (device));
196 g_value_set_boolean (value, nm_device_team_get_carrier (device));
199 g_value_take_boxed (value, _nm_utils_copy_object_array (nm_device_team_get_slaves (device)));
202 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
208 nm_device_team_class_init (NMDeviceTeamClass *team_class)
210 GObjectClass *object_class = G_OBJECT_CLASS (team_class);
211 NMObjectClass *nm_object_class = NM_OBJECT_CLASS (team_class);
212 NMDeviceClass *device_class = NM_DEVICE_CLASS (team_class);
214 g_type_class_add_private (team_class, sizeof (NMDeviceTeamPrivate));
216 _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_TEAM);
218 /* virtual methods */
219 object_class->dispose = dispose;
220 object_class->finalize = finalize;
221 object_class->get_property = get_property;
223 nm_object_class->init_dbus = init_dbus;
225 device_class->connection_compatible = connection_compatible;
226 device_class->get_setting_type = get_setting_type;
227 device_class->get_hw_address = get_hw_address;
232 * NMDeviceTeam:hw-address:
234 * The hardware (MAC) address of the device.
236 g_object_class_install_property
237 (object_class, PROP_HW_ADDRESS,
238 g_param_spec_string (NM_DEVICE_TEAM_HW_ADDRESS, "", "",
241 G_PARAM_STATIC_STRINGS));
244 * NMDeviceTeam:carrier:
246 * Whether the device has carrier.
248 g_object_class_install_property
249 (object_class, PROP_CARRIER,
250 g_param_spec_boolean (NM_DEVICE_TEAM_CARRIER, "", "",
253 G_PARAM_STATIC_STRINGS));
256 * NMDeviceTeam:slaves:
258 * The devices enslaved to the team device.
260 * Element-type: NMDevice
262 g_object_class_install_property
263 (object_class, PROP_SLAVES,
264 g_param_spec_boxed (NM_DEVICE_TEAM_SLAVES, "", "",
267 G_PARAM_STATIC_STRINGS));