aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2011-09-09 20:45:37 +0200
committerAleksander Morgado <aleksander@lanedo.com>2012-03-15 14:14:20 +0100
commitf7b1d99fa0ac00889a65b22905939e4f86061902 (patch)
tree9395179ec625cdd60fa06c38ea42b8b9c4663d9e /src
parentf227572d8f1f8516e2ea2a38bf7a8a73387165d5 (diff)
port-probe: allow cancelling the probing operation
The new `mm_port_probe_cancel()' will cancel the probing operation currently in progress, if any. Note that we don't need to pass any argument to specify which operation to cancel, as there can only be one.
Diffstat (limited to 'src')
-rw-r--r--src/mm-port-probe.c47
-rw-r--r--src/mm-port-probe.h1
2 files changed, 46 insertions, 2 deletions
diff --git a/src/mm-port-probe.c b/src/mm-port-probe.c
index 0f19972a..7f90c845 100644
--- a/src/mm-port-probe.c
+++ b/src/mm-port-probe.c
@@ -25,6 +25,7 @@ G_DEFINE_TYPE (MMPortProbe, mm_port_probe, G_TYPE_OBJECT)
typedef struct {
/* ---- Generic task context ---- */
GSimpleAsyncResult *result;
+ GCancellable *cancellable;
} PortProbeRunTask;
struct _MMPortProbePrivate {
@@ -42,6 +43,9 @@ struct _MMPortProbePrivate {
static void
port_probe_run_task_free (PortProbeRunTask *task)
{
+ if (task->cancellable)
+ g_object_unref (task->cancellable);
+
g_object_unref (task->result);
g_free (task);
}
@@ -63,6 +67,41 @@ port_probe_run_task_complete (PortProbeRunTask *task,
g_simple_async_result_complete (task->result);
}
+static gboolean
+port_probe_run_is_cancelled (MMPortProbe *self)
+{
+ PortProbeRunTask *task = self->priv->task;
+
+ /* Manually check if cancelled. */
+ if (g_cancellable_is_cancelled (task->cancellable)) {
+ port_probe_run_task_complete (
+ task,
+ TRUE, /* in idle */
+ FALSE,
+ g_error_new (MM_CORE_ERROR,
+ MM_CORE_ERROR_CANCELLED,
+ "(%s) port probing cancelled",
+ self->priv->name));
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+gboolean
+mm_port_probe_run_cancel (MMPortProbe *self)
+{
+ g_return_val_if_fail (MM_IS_PORT_PROBE (self), FALSE);
+
+ if (self->priv->task) {
+ mm_dbg ("(%s) requested to cancel the probing", self->priv->name);
+ g_cancellable_cancel (self->priv->task->cancellable);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
gboolean
mm_port_probe_run_finish (MMPortProbe *self,
GAsyncResult *result,
@@ -106,11 +145,15 @@ mm_port_probe_run (MMPortProbe *self,
user_data,
mm_port_probe_run);
+ /* Setup internal cancellable */
+ task->cancellable = g_cancellable_new ();
+
/* Store as current task */
self->priv->task = task;
- /* For now, just set successful */
- port_probe_run_task_complete (task, TRUE, TRUE, NULL);
+ /* For now, just set successful if not cancelled */
+ if (!port_probe_run_is_cancelled (self))
+ port_probe_run_task_complete (task, TRUE, TRUE, NULL);
}
GUdevDevice *
diff --git a/src/mm-port-probe.h b/src/mm-port-probe.h
index 7db56100..e2eff8a6 100644
--- a/src/mm-port-probe.h
+++ b/src/mm-port-probe.h
@@ -62,6 +62,7 @@ void mm_port_probe_run (MMPortProbe *self,
gboolean mm_port_probe_run_finish (MMPortProbe *self,
GAsyncResult *result,
GError **error);
+gboolean mm_port_probe_run_cancel (MMPortProbe *self);
#endif /* MM_PORT_PROBE_H */