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 2012 Red Hat, Inc.
21 #include "nm-default.h"
25 #include "nm-setting-connection.h"
26 #include "nm-setting-bridge.h"
29 #include "nm-device-bridge.h"
30 #include "nm-device-private.h"
31 #include "nm-object-private.h"
32 #include "nm-core-internal.h"
34 G_DEFINE_TYPE (NMDeviceBridge, nm_device_bridge, NM_TYPE_DEVICE)
36 #define NM_DEVICE_BRIDGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_BRIDGE, NMDeviceBridgePrivate))
42 } NMDeviceBridgePrivate;
54 * nm_device_bridge_get_hw_address:
55 * @device: a #NMDeviceBridge
57 * Gets the hardware (MAC) address of the #NMDeviceBridge
59 * Returns: the hardware address. This is the internal string used by the
60 * device, and must not be modified.
63 nm_device_bridge_get_hw_address (NMDeviceBridge *device)
65 g_return_val_if_fail (NM_IS_DEVICE_BRIDGE (device), NULL);
67 return NM_DEVICE_BRIDGE_GET_PRIVATE (device)->hw_address;
71 * nm_device_bridge_get_carrier:
72 * @device: a #NMDeviceBridge
74 * Whether the device has carrier.
76 * Returns: %TRUE if the device has carrier
79 nm_device_bridge_get_carrier (NMDeviceBridge *device)
81 g_return_val_if_fail (NM_IS_DEVICE_BRIDGE (device), FALSE);
83 return NM_DEVICE_BRIDGE_GET_PRIVATE (device)->carrier;
87 * nm_device_bridge_get_slaves:
88 * @device: a #NMDeviceBridge
90 * Gets the devices currently slaved 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_bridge_get_slaves (NMDeviceBridge *device)
99 g_return_val_if_fail (NM_IS_DEVICE_BRIDGE (device), FALSE);
101 return NM_DEVICE_BRIDGE_GET_PRIVATE (device)->slaves;
105 connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
107 if (!NM_DEVICE_CLASS (nm_device_bridge_parent_class)->connection_compatible (device, connection, error))
110 if (!nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME)) {
111 g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
112 _("The connection was not a bridge connection."));
116 /* FIXME: check ports? */
122 get_setting_type (NMDevice *device)
124 return NM_TYPE_SETTING_BRIDGE;
128 get_hw_address (NMDevice *device)
130 return nm_device_bridge_get_hw_address (NM_DEVICE_BRIDGE (device));
133 /***********************************************************/
136 nm_device_bridge_init (NMDeviceBridge *device)
138 NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (device);
140 _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_BRIDGE);
142 priv->slaves = g_ptr_array_new ();
146 init_dbus (NMObject *object)
148 NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (object);
149 const NMPropertiesInfo property_info[] = {
150 { NM_DEVICE_BRIDGE_HW_ADDRESS, &priv->hw_address },
151 { NM_DEVICE_BRIDGE_CARRIER, &priv->carrier },
152 { NM_DEVICE_BRIDGE_SLAVES, &priv->slaves, NULL, NM_TYPE_DEVICE },
156 NM_OBJECT_CLASS (nm_device_bridge_parent_class)->init_dbus (object);
158 _nm_object_register_properties (object,
159 NM_DBUS_INTERFACE_DEVICE_BRIDGE,
164 dispose (GObject *object)
166 NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (object);
168 g_clear_pointer (&priv->slaves, g_ptr_array_unref);
170 G_OBJECT_CLASS (nm_device_bridge_parent_class)->dispose (object);
174 finalize (GObject *object)
176 NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (object);
178 g_free (priv->hw_address);
180 G_OBJECT_CLASS (nm_device_bridge_parent_class)->finalize (object);
184 get_property (GObject *object,
189 NMDeviceBridge *device = NM_DEVICE_BRIDGE (object);
192 case PROP_HW_ADDRESS:
193 g_value_set_string (value, nm_device_bridge_get_hw_address (device));
196 g_value_set_boolean (value, nm_device_bridge_get_carrier (device));
199 g_value_take_boxed (value, _nm_utils_copy_object_array (nm_device_bridge_get_slaves (device)));
202 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
208 nm_device_bridge_class_init (NMDeviceBridgeClass *bridge_class)
210 GObjectClass *object_class = G_OBJECT_CLASS (bridge_class);
211 NMObjectClass *nm_object_class = NM_OBJECT_CLASS (bridge_class);
212 NMDeviceClass *device_class = NM_DEVICE_CLASS (bridge_class);
214 g_type_class_add_private (bridge_class, sizeof (NMDeviceBridgePrivate));
216 _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_BRIDGE);
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 * NMDeviceBridge: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_BRIDGE_HW_ADDRESS, "", "",
241 G_PARAM_STATIC_STRINGS));
244 * NMDeviceBridge: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_BRIDGE_CARRIER, "", "",
253 G_PARAM_STATIC_STRINGS));
256 * NMDeviceBridge:slaves:
258 * The devices slaved to the bridge device.
260 * Element-type: NMDevice
262 g_object_class_install_property
263 (object_class, PROP_SLAVES,
264 g_param_spec_boxed (NM_DEVICE_BRIDGE_SLAVES, "", "",
267 G_PARAM_STATIC_STRINGS));