NetworkManager r4214 - in trunk: . libnm-util src



Author: dcbw
Date: Sun Oct 26 16:54:17 2008
New Revision: 4214
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=4214&view=rev

Log:
2008-10-26  Dan Williams  <dcbw redhat com>

	Patch from Tambet Ingo <tambet gmail com>

	* libnm-util/libnm-util.ver
	  libnm-util/nm-setting-serial.c
	  libnm-util/nm-setting-serial.h
	  src/nm-serial-device.c
		- Make properties private and use accessors instead



Modified:
   trunk/ChangeLog
   trunk/libnm-util/libnm-util.ver
   trunk/libnm-util/nm-setting-serial.c
   trunk/libnm-util/nm-setting-serial.h
   trunk/src/nm-serial-device.c

Modified: trunk/libnm-util/libnm-util.ver
==============================================================================
--- trunk/libnm-util/libnm-util.ver	(original)
+++ trunk/libnm-util/libnm-util.ver	Sun Oct 26 16:54:17 2008
@@ -77,6 +77,11 @@
 	nm_setting_serial_error_quark;
 	nm_setting_serial_get_type;
 	nm_setting_serial_new;
+	nm_setting_serial_get_baud;
+	nm_setting_serial_get_bits;
+	nm_setting_serial_get_parity;
+	nm_setting_serial_get_stopbits;
+	nm_setting_serial_get_send_delay;
 	nm_setting_to_hash;
 	nm_setting_to_string;
 	nm_setting_unregister;

Modified: trunk/libnm-util/nm-setting-serial.c
==============================================================================
--- trunk/libnm-util/nm-setting-serial.c	(original)
+++ trunk/libnm-util/nm-setting-serial.c	Sun Oct 26 16:54:17 2008
@@ -66,6 +66,17 @@
 
 G_DEFINE_TYPE (NMSettingSerial, nm_setting_serial, NM_TYPE_SETTING)
 
+#define NM_SETTING_SERIAL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_SERIAL, NMSettingSerialPrivate))
+
+typedef struct {
+	guint baud;
+	guint bits;
+	char parity;
+	guint stopbits;
+	guint64 send_delay;
+} NMSettingSerialPrivate;
+
+
 enum {
 	PROP_0,
 	PROP_BAUD,
@@ -83,6 +94,46 @@
 	return (NMSetting *) g_object_new (NM_TYPE_SETTING_SERIAL, NULL);
 }
 
+guint
+nm_setting_serial_get_baud (NMSettingSerial *setting)
+{
+	g_return_val_if_fail (NM_IS_SETTING_SERIAL (setting), 0);
+
+	return NM_SETTING_SERIAL_GET_PRIVATE (setting)->baud;
+}
+
+guint
+nm_setting_serial_get_bits (NMSettingSerial *setting)
+{
+	g_return_val_if_fail (NM_IS_SETTING_SERIAL (setting), 0);
+
+	return NM_SETTING_SERIAL_GET_PRIVATE (setting)->bits;
+}
+
+char
+nm_setting_serial_get_parity (NMSettingSerial *setting)
+{
+	g_return_val_if_fail (NM_IS_SETTING_SERIAL (setting), 0);
+
+	return NM_SETTING_SERIAL_GET_PRIVATE (setting)->parity;
+}
+
+guint
+nm_setting_serial_get_stopbits (NMSettingSerial *setting)
+{
+	g_return_val_if_fail (NM_IS_SETTING_SERIAL (setting), 0);
+
+	return NM_SETTING_SERIAL_GET_PRIVATE (setting)->stopbits;
+}
+
+guint64
+nm_setting_serial_get_send_delay (NMSettingSerial *setting)
+{
+	g_return_val_if_fail (NM_IS_SETTING_SERIAL (setting), 0);
+
+	return NM_SETTING_SERIAL_GET_PRIVATE (setting)->send_delay;
+}
+
 static gint
 find_setting_by_name (gconstpointer a, gconstpointer b)
 {
@@ -118,23 +169,23 @@
 set_property (GObject *object, guint prop_id,
 		    const GValue *value, GParamSpec *pspec)
 {
-	NMSettingSerial *setting = NM_SETTING_SERIAL (object);
+	NMSettingSerialPrivate *priv = NM_SETTING_SERIAL_GET_PRIVATE (object);
 
 	switch (prop_id) {
 	case PROP_BAUD:
-		setting->baud = g_value_get_uint (value);
+		priv->baud = g_value_get_uint (value);
 		break;
 	case PROP_BITS:
-		setting->bits = g_value_get_uint (value);
+		priv->bits = g_value_get_uint (value);
 		break;
 	case PROP_PARITY:
-		setting->parity = g_value_get_char (value);
+		priv->parity = g_value_get_char (value);
 		break;
 	case PROP_STOPBITS:
-		setting->stopbits = g_value_get_uint (value);
+		priv->stopbits = g_value_get_uint (value);
 		break;
 	case PROP_SEND_DELAY:
-		setting->send_delay = g_value_get_uint64 (value);
+		priv->send_delay = g_value_get_uint64 (value);
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -150,19 +201,19 @@
 
 	switch (prop_id) {
 	case PROP_BAUD:
-		g_value_set_uint (value, setting->baud);
+		g_value_set_uint (value, nm_setting_serial_get_baud (setting));
 		break;
 	case PROP_BITS:
-		g_value_set_uint (value, setting->bits);
+		g_value_set_uint (value, nm_setting_serial_get_bits (setting));
 		break;
 	case PROP_PARITY:
-		g_value_set_char (value, setting->parity);
+		g_value_set_char (value, nm_setting_serial_get_parity (setting));
 		break;
 	case PROP_STOPBITS:
-		g_value_set_uint (value, setting->stopbits);
+		g_value_set_uint (value, nm_setting_serial_get_stopbits (setting));
 		break;
 	case PROP_SEND_DELAY:
-		g_value_set_uint64 (value, setting->send_delay);
+		g_value_set_uint64 (value, nm_setting_serial_get_send_delay (setting));
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -176,6 +227,8 @@
 	GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
 	NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
 
+	g_type_class_add_private (setting_class, sizeof (NMSettingSerialPrivate));
+
 	/* virtual methods */
 	object_class->set_property = set_property;
 	object_class->get_property = get_property;

Modified: trunk/libnm-util/nm-setting-serial.h
==============================================================================
--- trunk/libnm-util/nm-setting-serial.h	(original)
+++ trunk/libnm-util/nm-setting-serial.h	Sun Oct 26 16:54:17 2008
@@ -61,12 +61,6 @@
 
 typedef struct {
 	NMSetting parent;
-
-	guint baud;
-	guint bits;
-	char parity;
-	guint stopbits;
-	guint64 send_delay;
 } NMSettingSerial;
 
 typedef struct {
@@ -75,7 +69,12 @@
 
 GType nm_setting_serial_get_type (void);
 
-NMSetting *nm_setting_serial_new (void);
+NMSetting *nm_setting_serial_new            (void);
+guint      nm_setting_serial_get_baud       (NMSettingSerial *setting);
+guint      nm_setting_serial_get_bits       (NMSettingSerial *setting);
+char       nm_setting_serial_get_parity     (NMSettingSerial *setting);
+guint      nm_setting_serial_get_stopbits   (NMSettingSerial *setting);
+guint64    nm_setting_serial_get_send_delay (NMSettingSerial *setting);
 
 G_END_DECLS
 

Modified: trunk/src/nm-serial-device.c
==============================================================================
--- trunk/src/nm-serial-device.c	(original)
+++ trunk/src/nm-serial-device.c	Sun Oct 26 16:54:17 2008
@@ -331,10 +331,10 @@
 	int parity;
 	int stopbits;
 
-	speed = parse_baudrate (setting->baud);
-	bits = parse_bits (setting->bits);
-	parity = parse_parity (setting->parity);
-	stopbits = parse_stopbits (setting->stopbits);
+	speed = parse_baudrate (nm_setting_serial_get_baud (setting));
+	bits = parse_bits (nm_setting_serial_get_bits (setting));
+	parity = parse_parity (nm_setting_serial_get_parity (setting));
+	stopbits = parse_stopbits (nm_setting_serial_get_stopbits (setting));
 
 	ioctl (priv->fd, TCGETA, &stbuf);
 
@@ -438,15 +438,17 @@
 	NMSettingSerial *setting;
 	int i, eagain_count = 1000;
 	ssize_t written;
-	guint32 send_delay = G_USEC_PER_SEC / 1000;
+	guint32 send_delay = 0;
 
 	g_return_val_if_fail (NM_IS_SERIAL_DEVICE (device), FALSE);
 	g_return_val_if_fail (command != NULL, FALSE);
 
 	fd = NM_SERIAL_DEVICE_GET_PRIVATE (device)->fd;
 	setting = NM_SETTING_SERIAL (serial_device_get_setting (device, NM_TYPE_SETTING_SERIAL));
-	if (setting && setting->send_delay)
-		send_delay = setting->send_delay;
+	if (setting)
+		send_delay = nm_setting_serial_get_send_delay (setting);
+	if (send_delay == 0)
+		send_delay = G_USEC_PER_SEC / 1000;
 
 	nm_serial_debug ("Sending:", (char *) command->data, command->len);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]