static gboolean input_device_auto_reconnect(gpointer user_data) { struct input_device *idev = user_data; DBG("path=%s, attempt=%d", idev->path, idev->reconnect_attempt); /* Stop the recurrent reconnection attempts if the device is reconnected * or is marked for removal. */ if (device_is_temporary(idev->device) || device_is_connected(idev->device)) return FALSE; /* Only attempt an auto-reconnect for at most 3 minutes (6 * 30s). */ if (idev->reconnect_attempt >= 6) return FALSE; /* Check if the profile is already connected. */ if (idev->ctrl_io) return FALSE; if (is_connected(idev)) return FALSE; idev->reconnect_attempt++; dev_connect(idev); return TRUE; }
static void input_device_enter_reconnect_mode(struct input_device *idev) { DBG("path=%s reconnect_mode=%s", idev->path, reconnect_mode_to_string(idev->reconnect_mode)); /* Only attempt an auto-reconnect when the device is required to accept * reconnections from the host. */ if (idev->reconnect_mode != RECONNECT_ANY && idev->reconnect_mode != RECONNECT_HOST) return; /* If the device is temporary we are not required to reconnect with the * device. This is likely the case of a removing device. */ if (device_is_temporary(idev->device) || device_is_connected(idev->device)) return; if (idev->reconnect_timer > 0) g_source_remove(idev->reconnect_timer); DBG("registering auto-reconnect"); idev->reconnect_attempt = 0; idev->reconnect_timer = g_timeout_add_seconds(30, input_device_auto_reconnect, idev); }
static gboolean att_device_connected(struct gatt_service *gatt) { GSList *l, *left; if (gatt != NULL && gatt->dev != NULL && device_is_connected(gatt->dev)) return true; return false; }
static gboolean input_device_auto_reconnect(gpointer user_data) { struct input_device *idev = user_data; struct input_conn *iconn; GError *err = NULL; DBG("idev %p", idev); DBG("path=%s, attempt=%d", idev->path, idev->reconnect_attempt); /* Stop the recurrent reconnection attempts if the device is reconnected * or is marked for removal. */ if (device_is_temporary(idev->device) || device_is_connected(idev->device)) return FALSE; /* Only attempt an auto-reconnect for at most 3 minutes (6 * 30s). */ if (idev->reconnect_attempt >= 6) return FALSE; iconn = find_connection(idev->connections, HID_UUID); if (iconn == NULL) return FALSE; if (iconn->ctrl_io) return FALSE; if (is_connected(iconn)) return FALSE; idev->reconnect_attempt++; dev_connect(idev, iconn, &err); if (err != NULL) { error("%s", err->message); g_error_free(err); return FALSE; } return TRUE; }