port-serial: fix forced closing after b28230411

b28230411 moved up the self->priv->forced_close = TRUE, which
caused mm_port_serial_close() to just return without actually
closing the port and cleaning up.

Also, cancel the reopen separately from closing the port since
the two operations are actually independent of each other.
This commit is contained in:
Dan Williams
2014-10-07 15:53:53 -05:00
parent 1e5ec7e1b1
commit 41b7e7b048

View File

@@ -1274,25 +1274,23 @@ mm_port_serial_is_open (MMPortSerial *self)
return !!self->priv->open_count; return !!self->priv->open_count;
} }
void static void
mm_port_serial_close (MMPortSerial *self) _close_internal (MMPortSerial *self, gboolean force)
{ {
const char *device; const char *device;
int i; int i;
g_return_if_fail (MM_IS_PORT_SERIAL (self)); g_return_if_fail (MM_IS_PORT_SERIAL (self));
/* If we forced closing the port, open_count will be 0 already. if (force)
* Just return without issuing any warning */ self->priv->open_count = 0;
if (self->priv->forced_close) else {
return; g_return_if_fail (self->priv->open_count > 0);
self->priv->open_count--;
g_return_if_fail (self->priv->open_count > 0); }
device = mm_port_get_device (MM_PORT (self)); device = mm_port_get_device (MM_PORT (self));
self->priv->open_count--;
mm_dbg ("(%s) device open count is %d (close)", device, self->priv->open_count); mm_dbg ("(%s) device open count is %d (close)", device, self->priv->open_count);
if (self->priv->open_count > 0) if (self->priv->open_count > 0)
@@ -1402,10 +1400,18 @@ mm_port_serial_close (MMPortSerial *self)
g_clear_object (&self->priv->cancellable); g_clear_object (&self->priv->cancellable);
} }
void
mm_port_serial_close (MMPortSerial *self)
{
g_return_if_fail (MM_IS_PORT_SERIAL (self));
if (!self->priv->forced_close)
_close_internal (self, FALSE);
}
static void static void
port_serial_close_force (MMPortSerial *self) port_serial_close_force (MMPortSerial *self)
{ {
g_return_if_fail (self != NULL);
g_return_if_fail (MM_IS_PORT_SERIAL (self)); g_return_if_fail (MM_IS_PORT_SERIAL (self));
/* If already forced to close, return */ /* If already forced to close, return */
@@ -1418,19 +1424,16 @@ port_serial_close_force (MMPortSerial *self)
* open counts */ * open counts */
self->priv->forced_close = TRUE; self->priv->forced_close = TRUE;
/* If already closed, done */
if (!self->priv->open_count && !self->priv->reopen_ctx)
return;
/* Cancel port reopening if one is running */ /* Cancel port reopening if one is running */
port_serial_reopen_cancel (self); port_serial_reopen_cancel (self);
/* Force the port to close */ /* If already closed, done */
self->priv->open_count = 1; if (self->priv->open_count > 0) {
mm_port_serial_close (self); _close_internal (self, TRUE);
/* Notify about the forced close status */ /* Notify about the forced close status */
g_signal_emit (self, signals[FORCED_CLOSE], 0); g_signal_emit (self, signals[FORCED_CLOSE], 0);
}
} }
/*****************************************************************************/ /*****************************************************************************/