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
34 * @include: nm-setting-serial.h
36 * The #NMSettingSerial object is a #NMSetting subclass that describes
37 * properties necessary for connections that may use serial communications,
38 * such as mobile broadband or analog telephone connections.
42 * nm_setting_serial_error_quark:
44 * Registers an error quark for #NMSettingSerial if necessary.
46 * Returns: the error quark used for #NMSettingSerial errors.
49 nm_setting_serial_error_quark (void)
53 if (G_UNLIKELY (!quark))
54 quark = g_quark_from_static_string ("nm-setting-serial-error-quark");
59 G_DEFINE_TYPE_WITH_CODE (NMSettingSerial, nm_setting_serial, NM_TYPE_SETTING,
60 _nm_register_setting (NM_SETTING_SERIAL_SETTING_NAME,
63 NM_SETTING_SERIAL_ERROR))
64 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_SERIAL)
66 #define NM_SETTING_SERIAL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_SERIAL, NMSettingSerialPrivate))
74 } NMSettingSerialPrivate;
89 * nm_setting_serial_new:
91 * Creates a new #NMSettingSerial object with default values.
93 * Returns: (transfer full): the new empty #NMSettingSerial object
96 nm_setting_serial_new (void)
98 return (NMSetting *) g_object_new (NM_TYPE_SETTING_SERIAL, NULL);
102 * nm_setting_serial_get_baud:
103 * @setting: the #NMSettingSerial
105 * Returns: the #NMSettingSerial:baud property of the setting
108 nm_setting_serial_get_baud (NMSettingSerial *setting)
110 g_return_val_if_fail (NM_IS_SETTING_SERIAL (setting), 0);
112 return NM_SETTING_SERIAL_GET_PRIVATE (setting)->baud;
116 * nm_setting_serial_get_bits:
117 * @setting: the #NMSettingSerial
119 * Returns: the #NMSettingSerial:bits property of the setting
122 nm_setting_serial_get_bits (NMSettingSerial *setting)
124 g_return_val_if_fail (NM_IS_SETTING_SERIAL (setting), 0);
126 return NM_SETTING_SERIAL_GET_PRIVATE (setting)->bits;
130 * nm_setting_serial_get_parity:
131 * @setting: the #NMSettingSerial
133 * Returns: the #NMSettingSerial:parity property of the setting
136 nm_setting_serial_get_parity (NMSettingSerial *setting)
138 g_return_val_if_fail (NM_IS_SETTING_SERIAL (setting), 0);
140 return NM_SETTING_SERIAL_GET_PRIVATE (setting)->parity;
144 * nm_setting_serial_get_stopbits:
145 * @setting: the #NMSettingSerial
147 * Returns: the #NMSettingSerial:stopbits property of the setting
150 nm_setting_serial_get_stopbits (NMSettingSerial *setting)
152 g_return_val_if_fail (NM_IS_SETTING_SERIAL (setting), 0);
154 return NM_SETTING_SERIAL_GET_PRIVATE (setting)->stopbits;
158 * nm_setting_serial_get_send_delay:
159 * @setting: the #NMSettingSerial
161 * Returns: the #NMSettingSerial:send-delay property of the setting
164 nm_setting_serial_get_send_delay (NMSettingSerial *setting)
166 g_return_val_if_fail (NM_IS_SETTING_SERIAL (setting), 0);
168 return NM_SETTING_SERIAL_GET_PRIVATE (setting)->send_delay;
172 verify (NMSetting *setting, GSList *all_settings, GError **error)
178 nm_setting_serial_init (NMSettingSerial *setting)
183 set_property (GObject *object, guint prop_id,
184 const GValue *value, GParamSpec *pspec)
186 NMSettingSerialPrivate *priv = NM_SETTING_SERIAL_GET_PRIVATE (object);
190 priv->baud = g_value_get_uint (value);
193 priv->bits = g_value_get_uint (value);
196 priv->parity = g_value_get_schar (value);
199 priv->stopbits = g_value_get_uint (value);
201 case PROP_SEND_DELAY:
202 priv->send_delay = g_value_get_uint64 (value);
205 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
211 get_property (GObject *object, guint prop_id,
212 GValue *value, GParamSpec *pspec)
214 NMSettingSerial *setting = NM_SETTING_SERIAL (object);
218 g_value_set_uint (value, nm_setting_serial_get_baud (setting));
221 g_value_set_uint (value, nm_setting_serial_get_bits (setting));
224 g_value_set_schar (value, nm_setting_serial_get_parity (setting));
227 g_value_set_uint (value, nm_setting_serial_get_stopbits (setting));
229 case PROP_SEND_DELAY:
230 g_value_set_uint64 (value, nm_setting_serial_get_send_delay (setting));
233 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
239 nm_setting_serial_class_init (NMSettingSerialClass *setting_class)
241 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
242 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
244 g_type_class_add_private (setting_class, sizeof (NMSettingSerialPrivate));
246 /* virtual methods */
247 object_class->set_property = set_property;
248 object_class->get_property = get_property;
249 parent_class->verify = verify;
254 * NMSettingSerial:baud:
256 * Speed to use for communication over the serial port. Note that this
257 * value usually has no effect for mobile broadband modems as they generally
258 * ignore speed settings and use the highest available speed.
260 g_object_class_install_property
261 (object_class, PROP_BAUD,
262 g_param_spec_uint (NM_SETTING_SERIAL_BAUD, "", "",
266 G_PARAM_STATIC_STRINGS));
269 * NMSettingSerial:bits:
271 * Byte-width of the serial communication. The 8 in "8n1" for example.
273 g_object_class_install_property
274 (object_class, PROP_BITS,
275 g_param_spec_uint (NM_SETTING_SERIAL_BITS, "", "",
279 G_PARAM_STATIC_STRINGS));
282 * NMSettingSerial:parity:
284 * Parity setting of the serial port. Either 'E' for even parity, 'o' for
285 * odd parity, or 'n' for no parity.
287 g_object_class_install_property
288 (object_class, PROP_PARITY,
289 g_param_spec_char (NM_SETTING_SERIAL_PARITY, "", "",
293 G_PARAM_STATIC_STRINGS));
296 * NMSettingSerial:stopbits:
298 * Number of stop bits for communication on the serial port. Either 1 or 2.
299 * The 1 in "8n1" for example.
301 g_object_class_install_property
302 (object_class, PROP_STOPBITS,
303 g_param_spec_uint (NM_SETTING_SERIAL_STOPBITS, "", "",
307 G_PARAM_STATIC_STRINGS));
310 * NMSettingSerial:send-delay:
312 * Time to delay between each byte sent to the modem, in microseconds.
314 g_object_class_install_property
315 (object_class, PROP_SEND_DELAY,
316 g_param_spec_uint64 (NM_SETTING_SERIAL_SEND_DELAY, "", "",
320 G_PARAM_STATIC_STRINGS));