aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2013-02-08 13:32:51 +0100
committerAleksander Morgado <aleksander@lanedo.com>2013-02-18 15:41:26 +0100
commit553bebe8255a78e1f9f7b559d7782f9ac87be443 (patch)
treeb63b9cba06f05a01cab195116a8569b389cd6f0e
parentf8e3a8adb9584bf462c8016eea831f3a1f945875 (diff)
serial-port: new method to reopen a port
We will fully close the port and the re-open it again keeping the same open_count that we had before.
-rw-r--r--src/mm-serial-port.c32
-rw-r--r--src/mm-serial-port.h4
2 files changed, 35 insertions, 1 deletions
diff --git a/src/mm-serial-port.c b/src/mm-serial-port.c
index c519ddb8..47107616 100644
--- a/src/mm-serial-port.c
+++ b/src/mm-serial-port.c
@@ -1205,6 +1205,36 @@ mm_serial_port_queue_command_cached (MMSerialPort *self,
internal_queue_command (self, command, take_command, TRUE, timeout_seconds, cancellable, callback, user_data);
}
+gboolean
+mm_serial_port_reopen (MMSerialPort *self,
+ GError **error)
+{
+ MMSerialPortPrivate *priv;
+ guint initial_open_count;
+ guint i;
+
+ g_return_val_if_fail (MM_IS_SERIAL_PORT (self), FALSE);
+
+ priv = MM_SERIAL_PORT_GET_PRIVATE (self);
+ initial_open_count = priv->open_count;
+
+ mm_dbg ("(%s) reopening port (%u)",
+ mm_port_get_device (MM_PORT (self)),
+ initial_open_count);
+
+ for (i = 0; i < initial_open_count; i++)
+ mm_serial_port_close (self);
+
+ for (i = 0; i < initial_open_count; i++) {
+ if (!mm_serial_port_open (self, error)) {
+ g_prefix_error (error, "Couldn't reopen port (%u): ", i);
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
static gboolean
get_speed (MMSerialPort *self, speed_t *speed, GError **error)
{
@@ -1676,7 +1706,7 @@ mm_serial_port_class_init (MMSerialPortClass *klass)
g_object_class_install_property
(object_class, PROP_FLASH_OK,
g_param_spec_boolean (MM_SERIAL_PORT_FLASH_OK,
- "FlaskOk",
+ "FlashOk",
"Flashing the port (0 baud for a short period) "
"is allowed.",
TRUE,
diff --git a/src/mm-serial-port.h b/src/mm-serial-port.h
index 27ebc254..a37d3230 100644
--- a/src/mm-serial-port.h
+++ b/src/mm-serial-port.h
@@ -39,6 +39,7 @@
#define MM_SERIAL_PORT_FD "fd" /* Construct-only */
#define MM_SERIAL_PORT_SPEW_CONTROL "spew-control" /* Construct-only */
#define MM_SERIAL_PORT_FLASH_OK "flash-ok" /* Construct-only */
+#define MM_SERIAL_PORT_FLASH_REOPEN "flash-reopen" /* Construct-only */
typedef struct _MMSerialPort MMSerialPort;
typedef struct _MMSerialPortClass MMSerialPortClass;
@@ -122,6 +123,9 @@ gboolean mm_serial_port_open (MMSerialPort *self,
void mm_serial_port_close (MMSerialPort *self);
+gboolean mm_serial_port_reopen (MMSerialPort *self,
+ GError **error);
+
gboolean mm_serial_port_flash (MMSerialPort *self,
guint32 flash_time,
gboolean ignore_errors,