static void source_cb(struct btd_service *service, btd_service_state_t old_state, btd_service_state_t new_state) { struct btd_device *dev = btd_service_get_device(service); struct policy_data *data; struct btd_service *target; target = btd_device_get_service(dev, AVRCP_TARGET_UUID); if (target == NULL) return; data = policy_get_data(dev); switch (new_state) { case BTD_SERVICE_STATE_UNAVAILABLE: case BTD_SERVICE_STATE_DISCONNECTED: if (old_state == BTD_SERVICE_STATE_CONNECTING) { int err = btd_service_get_error(service); if (err == -EAGAIN) { if (data->source_retries < SOURCE_RETRIES) policy_set_source_timer(data); else data->source_retries = 0; break; } else if (data->source_timer > 0) { g_source_remove(data->source_timer); data->source_timer = 0; } } if (data->tg_timer > 0) { g_source_remove(data->tg_timer); data->tg_timer = 0; } else if (btd_service_get_state(target) != BTD_SERVICE_STATE_DISCONNECTED) policy_disconnect(data, target); break; case BTD_SERVICE_STATE_CONNECTING: break; case BTD_SERVICE_STATE_CONNECTED: if (data->source_timer > 0) { g_source_remove(data->source_timer); data->source_timer = 0; } /* Check if service initiate the connection then proceed * immediatelly otherwise set timer */ if (old_state == BTD_SERVICE_STATE_CONNECTING) policy_connect(data, target); else if (btd_service_get_state(target) != BTD_SERVICE_STATE_CONNECTED) policy_set_tg_timer(data); break; case BTD_SERVICE_STATE_DISCONNECTING: break; } }
static void sink_cb(struct btd_service *service, btd_service_state_t old_state, btd_service_state_t new_state) { struct btd_device *dev = btd_service_get_device(service); struct policy_data *data; struct btd_service *controller; controller = btd_device_get_service(dev, AVRCP_REMOTE_UUID); if (controller == NULL) return; data = policy_get_data(dev); switch (new_state) { case BTD_SERVICE_STATE_UNAVAILABLE: if (data->sink_timer > 0) { g_source_remove(data->sink_timer); data->sink_timer = 0; } break; case BTD_SERVICE_STATE_DISCONNECTED: if (old_state == BTD_SERVICE_STATE_CONNECTING) { int err = btd_service_get_error(service); if (err == -EAGAIN) { if (data->sink_retries < SINK_RETRIES) policy_set_sink_timer(data); else data->sink_retries = 0; break; } else if (data->sink_timer > 0) { g_source_remove(data->sink_timer); data->sink_timer = 0; } } if (data->ct_timer > 0) { g_source_remove(data->ct_timer); data->ct_timer = 0; } else if (btd_service_get_state(controller) != BTD_SERVICE_STATE_DISCONNECTED) policy_disconnect(data, controller); break; case BTD_SERVICE_STATE_CONNECTING: break; case BTD_SERVICE_STATE_CONNECTED: if (data->sink_timer > 0) { g_source_remove(data->sink_timer); data->sink_timer = 0; } /* Check if service initiate the connection then proceed * immediatelly otherwise set timer */ if (old_state == BTD_SERVICE_STATE_CONNECTING) policy_connect(data, controller); else if (btd_service_get_state(controller) != BTD_SERVICE_STATE_CONNECTED) policy_set_ct_timer(data, CONTROL_CONNECT_TIMEOUT); break; case BTD_SERVICE_STATE_DISCONNECTING: break; } }