diff options
-rw-r--r-- | src/mm-serial-port.c | 26 | ||||
-rw-r--r-- | src/mm-serial-port.h | 1 |
2 files changed, 23 insertions, 4 deletions
diff --git a/src/mm-serial-port.c b/src/mm-serial-port.c index 94903bc8..0f4d888e 100644 --- a/src/mm-serial-port.c +++ b/src/mm-serial-port.c @@ -43,6 +43,7 @@ enum { PROP_PARITY, PROP_STOPBITS, PROP_SEND_DELAY, + PROP_FD, LAST_PROP }; @@ -706,10 +707,13 @@ mm_serial_port_open (MMSerialPort *self, GError **error) } else g_message ("(%s) opening serial port...", device); - devfile = g_strdup_printf ("/dev/%s", device); - errno = 0; - priv->fd = open (devfile, O_RDWR | O_EXCL | O_NONBLOCK | O_NOCTTY); - g_free (devfile); + /* Only open a new file descriptor if we weren't given one already */ + if (priv->fd < 0) { + devfile = g_strdup_printf ("/dev/%s", device); + errno = 0; + priv->fd = open (devfile, O_RDWR | O_EXCL | O_NONBLOCK | O_NOCTTY); + g_free (devfile); + } if (priv->fd < 0) { /* nozomi isn't ready yet when the port appears, and it'll return @@ -1222,6 +1226,9 @@ set_property (GObject *object, guint prop_id, MMSerialPortPrivate *priv = MM_SERIAL_PORT_GET_PRIVATE (object); switch (prop_id) { + case PROP_FD: + priv->fd = g_value_get_int (value); + break; case PROP_BAUD: priv->baud = g_value_get_uint (value); break; @@ -1250,6 +1257,9 @@ get_property (GObject *object, guint prop_id, MMSerialPortPrivate *priv = MM_SERIAL_PORT_GET_PRIVATE (object); switch (prop_id) { + case PROP_FD: + g_value_set_int (value, priv->fd); + break; case PROP_BAUD: g_value_set_uint (value, priv->baud); break; @@ -1313,6 +1323,14 @@ mm_serial_port_class_init (MMSerialPortClass *klass) /* Properties */ g_object_class_install_property + (object_class, PROP_FD, + g_param_spec_int (MM_SERIAL_PORT_FD, + "File descriptor", + "Fiel descriptor", + -1, G_MAXINT, -1, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (object_class, PROP_BAUD, g_param_spec_uint (MM_SERIAL_PORT_BAUD, "Baud", diff --git a/src/mm-serial-port.h b/src/mm-serial-port.h index f78f7931..5fee1b4f 100644 --- a/src/mm-serial-port.h +++ b/src/mm-serial-port.h @@ -35,6 +35,7 @@ #define MM_SERIAL_PORT_PARITY "parity" #define MM_SERIAL_PORT_STOPBITS "stopbits" #define MM_SERIAL_PORT_SEND_DELAY "send-delay" +#define MM_SERIAL_PORT_FD "fd" /* Construct-only */ typedef struct _MMSerialPort MMSerialPort; typedef struct _MMSerialPortClass MMSerialPortClass; |