aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-07-10 08:29:14 +0200
committerAleksander Morgado <aleksander@lanedo.com>2012-08-06 20:06:45 +0200
commitb35d6a65faff87c6cb96bdda4fee5cc270be4f6f (patch)
tree149dca655ea1ba81ce2aa9c172fb0d8105f28db8 /src
parente8339385da87665befd36c7041b2ab334883130e (diff)
plugin-manager: define a minimum probing time of 2s
Effectively, we're now letting the kernel up to 2s to show all the ports of the device, starting from the time where the first port is exposed.
Diffstat (limited to 'src')
-rw-r--r--src/mm-plugin-manager.c50
1 files changed, 41 insertions, 9 deletions
diff --git a/src/mm-plugin-manager.c b/src/mm-plugin-manager.c
index a5e489a2..c15a1d9b 100644
--- a/src/mm-plugin-manager.c
+++ b/src/mm-plugin-manager.c
@@ -31,6 +31,9 @@
/* Default time to defer probing checks */
#define SUPPORTS_DEFER_TIMEOUT_SECS 3
+/* Time to wait for other ports to appear once the first port is exposed */
+#define MIN_PROBING_TIME_SECS 2
+
static void initable_iface_init (GInitableIface *iface);
G_DEFINE_TYPE_EXTENDED (MMPluginManager, mm_plugin_manager, G_TYPE_OBJECT, 0,
@@ -525,6 +528,7 @@ typedef struct {
MMPluginManager *self;
MMDevice *device;
GSimpleAsyncResult *result;
+ guint timeout_id;
gulong grabbed_id;
gulong released_id;
@@ -546,6 +550,18 @@ port_probe_context_free (PortProbeContext *ctx)
static void
find_device_support_context_complete_and_free (FindDeviceSupportContext *ctx)
{
+ g_assert (ctx->timeout_id == 0);
+
+ /* Set async operation result */
+ if (!mm_device_peek_plugin (ctx->device)) {
+ g_simple_async_result_set_error (ctx->result,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_UNSUPPORTED,
+ "not supported by any plugin");
+ } else {
+ g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
+ }
+
g_simple_async_result_complete (ctx->result);
g_signal_handler_disconnect (ctx->device, ctx->grabbed_id);
@@ -619,17 +635,12 @@ find_port_support_ready (MMPluginManager *self,
if (ctx->running_probes != NULL)
return;
+ /* If we didn't use the minimum probing time, wait for it to finish */
+ if (ctx->timeout_id > 0)
+ return;
+
/* If we just finished the last running probe, we can now finish the device
* support check */
- if (!mm_device_peek_plugin (ctx->device)) {
- g_simple_async_result_set_error (ctx->result,
- MM_CORE_ERROR,
- MM_CORE_ERROR_UNSUPPORTED,
- "not supported by any plugin");
- } else {
- g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
- }
-
find_device_support_context_complete_and_free (ctx);
}
@@ -674,6 +685,18 @@ device_port_released_cb (MMDevice *device,
g_udev_device_get_name (port));
}
+static gboolean
+min_probing_timeout_cb (FindDeviceSupportContext *ctx)
+{
+ ctx->timeout_id = 0;
+
+ /* If there are no running probes around, we're free to finish */
+ if (ctx->running_probes == NULL)
+ find_device_support_context_complete_and_free (ctx);
+
+ return FALSE;
+}
+
void
mm_plugin_manager_find_device_support (MMPluginManager *self,
MMDevice *device,
@@ -699,6 +722,15 @@ mm_plugin_manager_find_device_support (MMPluginManager *self,
MM_DEVICE_PORT_RELEASED,
G_CALLBACK (device_port_released_cb),
ctx);
+
+ /* Set the initial timeout of 2s. We force the probing time of the device to
+ * be at least this amount of time, so that the kernel has enough time to
+ * bring up ports. Given that we launch this only when the first port of the
+ * device has been exposed in udev, this timeout effectively means that we
+ * leave up to 2s to the remaining ports to appear. */
+ ctx->timeout_id = g_timeout_add_seconds (MIN_PROBING_TIME_SECS,
+ (GSourceFunc)min_probing_timeout_cb,
+ ctx);
}
/*****************************************************************************/