From: Luiz Augusto von Dentz <luiz.von.dentz@xxxxxxxxx> Since BTD_SERVICE_STATE_CONNECTING is being used for both initiator and responder case it is no longer possible to use the state distint when the service connection was initiated locally or not, so to fix this a new flag is introduce to track when btd_service_connect has been called. --- src/service.c | 10 ++++++++++ src/service.h | 1 + 2 files changed, 11 insertions(+) diff --git a/src/service.c b/src/service.c index 84fbb208a..14a4c292b 100644 --- a/src/service.c +++ b/src/service.c @@ -42,6 +42,7 @@ struct btd_service { btd_service_state_t state; int err; bool is_allowed; + bool initiator; }; struct service_state_callback { @@ -96,6 +97,9 @@ static void change_state(struct btd_service *service, btd_service_state_t state, cb->cb(service, old, state, cb->user_data); } + + if (state == BTD_SERVICE_STATE_DISCONNECTED) + service->initiator = false; } struct btd_service *btd_service_ref(struct btd_service *service) @@ -261,6 +265,7 @@ int btd_service_connect(struct btd_service *service) err = profile->connect(service); if (err == 0) { + service->initiator = true; change_state(service, BTD_SERVICE_STATE_CONNECTING, 0); return 0; } @@ -343,6 +348,11 @@ int btd_service_get_error(const struct btd_service *service) return service->err; } +bool btd_service_is_initiator(const struct btd_service *service) +{ + return service->initiator; +} + unsigned int btd_service_add_state_cb(btd_service_state_cb cb, void *user_data) { struct service_state_callback *state_cb; diff --git a/src/service.h b/src/service.h index 5a2a02447..fa930f985 100644 --- a/src/service.h +++ b/src/service.h @@ -47,6 +47,7 @@ struct btd_device *btd_service_get_device(const struct btd_service *service); struct btd_profile *btd_service_get_profile(const struct btd_service *service); btd_service_state_t btd_service_get_state(const struct btd_service *service); int btd_service_get_error(const struct btd_service *service); +bool btd_service_is_initiator(const struct btd_service *service); unsigned int btd_service_add_state_cb(btd_service_state_cb cb, void *user_data); -- 2.31.1