1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA.
19 * Copyright 2007 - 2011 Red Hat, Inc.
20 * Copyright 2007 - 2008 Novell, Inc.
23 #include "nm-default.h"
27 #include "nm-setting-serial.h"
28 #include "nm-setting-private.h"
31 * SECTION:nm-setting-serial
32 * @short_description: Describes connection properties for devices that use
33 * serial communications
35 * The #NMSettingSerial object is a #NMSetting subclass that describes
36 * properties necessary for connections that may use serial communications,
37 * such as mobile broadband or analog telephone connections.
40 G_DEFINE_TYPE_WITH_CODE (NMSettingSerial, nm_setting_serial, NM_TYPE_SETTING,
41 _nm_register_setting (SERIAL, 2))
42 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_SERIAL)
44 #define NM_SETTING_SERIAL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_SERIAL, NMSettingSerialPrivate))
52 } NMSettingSerialPrivate;
67 * nm_setting_serial_new:
69 * Creates a new #NMSettingSerial object with default values.
71 * Returns: (transfer full): the new empty #NMSettingSerial object
74 nm_setting_serial_new (void)
76 return (NMSetting *) g_object_new (NM_TYPE_SETTING_SERIAL, NULL);
80 * nm_setting_serial_get_baud:
81 * @setting: the #NMSettingSerial
83 * Returns: the #NMSettingSerial:baud property of the setting
86 nm_setting_serial_get_baud (NMSettingSerial *setting)
88 g_return_val_if_fail (NM_IS_SETTING_SERIAL (setting), 0);
90 return NM_SETTING_SERIAL_GET_PRIVATE (setting)->baud;
94 * nm_setting_serial_get_bits:
95 * @setting: the #NMSettingSerial
97 * Returns: the #NMSettingSerial:bits property of the setting
100 nm_setting_serial_get_bits (NMSettingSerial *setting)
102 g_return_val_if_fail (NM_IS_SETTING_SERIAL (setting), 0);
104 return NM_SETTING_SERIAL_GET_PRIVATE (setting)->bits;
108 * nm_setting_serial_get_parity:
109 * @setting: the #NMSettingSerial
111 * Returns: the #NMSettingSerial:parity property of the setting
113 NMSettingSerialParity
114 nm_setting_serial_get_parity (NMSettingSerial *setting)
116 g_return_val_if_fail (NM_IS_SETTING_SERIAL (setting), 0);
118 return NM_SETTING_SERIAL_GET_PRIVATE (setting)->parity;
122 * nm_setting_serial_get_stopbits:
123 * @setting: the #NMSettingSerial
125 * Returns: the #NMSettingSerial:stopbits property of the setting
128 nm_setting_serial_get_stopbits (NMSettingSerial *setting)
130 g_return_val_if_fail (NM_IS_SETTING_SERIAL (setting), 0);
132 return NM_SETTING_SERIAL_GET_PRIVATE (setting)->stopbits;
136 * nm_setting_serial_get_send_delay:
137 * @setting: the #NMSettingSerial
139 * Returns: the #NMSettingSerial:send-delay property of the setting
142 nm_setting_serial_get_send_delay (NMSettingSerial *setting)
144 g_return_val_if_fail (NM_IS_SETTING_SERIAL (setting), 0);
146 return NM_SETTING_SERIAL_GET_PRIVATE (setting)->send_delay;
150 verify (NMSetting *setting, NMConnection *connection, GError **error)
156 nm_setting_serial_init (NMSettingSerial *setting)
161 parity_to_dbus (const GValue *from)
163 switch (g_value_get_enum (from)) {
164 case NM_SETTING_SERIAL_PARITY_EVEN:
165 return g_variant_new_byte ('E');
166 case NM_SETTING_SERIAL_PARITY_ODD:
167 return g_variant_new_byte ('o');
168 case NM_SETTING_SERIAL_PARITY_NONE:
170 return g_variant_new_byte ('n');
175 parity_from_dbus (GVariant *from, GValue *to)
177 switch (g_variant_get_byte (from)) {
179 g_value_set_enum (to, NM_SETTING_SERIAL_PARITY_EVEN);
182 g_value_set_enum (to, NM_SETTING_SERIAL_PARITY_ODD);
186 g_value_set_enum (to, NM_SETTING_SERIAL_PARITY_NONE);
192 set_property (GObject *object, guint prop_id,
193 const GValue *value, GParamSpec *pspec)
195 NMSettingSerialPrivate *priv = NM_SETTING_SERIAL_GET_PRIVATE (object);
199 priv->baud = g_value_get_uint (value);
202 priv->bits = g_value_get_uint (value);
205 priv->parity = g_value_get_enum (value);
208 priv->stopbits = g_value_get_uint (value);
210 case PROP_SEND_DELAY:
211 priv->send_delay = g_value_get_uint64 (value);
214 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
220 get_property (GObject *object, guint prop_id,
221 GValue *value, GParamSpec *pspec)
223 NMSettingSerial *setting = NM_SETTING_SERIAL (object);
227 g_value_set_uint (value, nm_setting_serial_get_baud (setting));
230 g_value_set_uint (value, nm_setting_serial_get_bits (setting));
233 g_value_set_enum (value, nm_setting_serial_get_parity (setting));
236 g_value_set_uint (value, nm_setting_serial_get_stopbits (setting));
238 case PROP_SEND_DELAY:
239 g_value_set_uint64 (value, nm_setting_serial_get_send_delay (setting));
242 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
248 nm_setting_serial_class_init (NMSettingSerialClass *setting_class)
250 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
251 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
253 g_type_class_add_private (setting_class, sizeof (NMSettingSerialPrivate));
255 /* virtual methods */
256 object_class->set_property = set_property;
257 object_class->get_property = get_property;
258 parent_class->verify = verify;
263 * NMSettingSerial:baud:
265 * Speed to use for communication over the serial port. Note that this
266 * value usually has no effect for mobile broadband modems as they generally
267 * ignore speed settings and use the highest available speed.
269 g_object_class_install_property
270 (object_class, PROP_BAUD,
271 g_param_spec_uint (NM_SETTING_SERIAL_BAUD, "", "",
275 G_PARAM_STATIC_STRINGS));
278 * NMSettingSerial:bits:
280 * Byte-width of the serial communication. The 8 in "8n1" for example.
282 g_object_class_install_property
283 (object_class, PROP_BITS,
284 g_param_spec_uint (NM_SETTING_SERIAL_BITS, "", "",
288 G_PARAM_STATIC_STRINGS));
291 * NMSettingSerial:parity:
293 * Parity setting of the serial port.
297 * format: 'e', 'o', or 'n'
298 * description: The connection parity; even, odd, or none. Note that older
299 * versions of NetworkManager stored this as an integer: 69 ('E') for even,
300 * 111 ('o') for odd, or 110 ('n') for none.
306 * description: The connection parity: 69 (ASCII 'E') for even parity,
307 * 111 (ASCII 'o') for odd, 110 (ASCII 'n') for none.
310 g_object_class_install_property
311 (object_class, PROP_PARITY,
312 g_param_spec_enum (NM_SETTING_SERIAL_PARITY, "", "",
313 NM_TYPE_SETTING_SERIAL_PARITY,
314 NM_SETTING_SERIAL_PARITY_NONE,
317 G_PARAM_STATIC_STRINGS));
318 _nm_setting_class_transform_property (parent_class,
319 NM_SETTING_SERIAL_PARITY,
325 * NMSettingSerial:stopbits:
327 * Number of stop bits for communication on the serial port. Either 1 or 2.
328 * The 1 in "8n1" for example.
330 g_object_class_install_property
331 (object_class, PROP_STOPBITS,
332 g_param_spec_uint (NM_SETTING_SERIAL_STOPBITS, "", "",
336 G_PARAM_STATIC_STRINGS));
339 * NMSettingSerial:send-delay:
341 * Time to delay between each byte sent to the modem, in microseconds.
343 g_object_class_install_property
344 (object_class, PROP_SEND_DELAY,
345 g_param_spec_uint64 (NM_SETTING_SERIAL_SEND_DELAY, "", "",
349 G_PARAM_STATIC_STRINGS));