From fd61d4719ec19e9e4ea6cfbad613de811c071399 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Fri, 3 Oct 2014 14:32:02 +0300 Subject: [PATCH] emulator/bthost: Add API to wait for bthost readiness --- emulator/bthost.c | 19 +++++++++++++++++++ emulator/bthost.h | 3 +++ 2 files changed, 22 insertions(+) diff --git a/emulator/bthost.c b/emulator/bthost.c index 4390082af..9079dceec 100644 --- a/emulator/bthost.c +++ b/emulator/bthost.c @@ -191,6 +191,8 @@ struct rfcomm_connection_data { }; struct bthost { + bool ready; + bthost_ready_cb ready_cb; uint8_t bdaddr[6]; uint8_t features[8]; bthost_send_func send_handler; @@ -741,6 +743,23 @@ static void read_bd_addr_complete(struct bthost *bthost, const void *data, return; memcpy(bthost->bdaddr, ev->bdaddr, 6); + + bthost->ready = true; + + if (bthost->ready_cb) { + bthost->ready_cb(); + bthost->ready_cb = NULL; + } +} + +void bthost_notify_ready(struct bthost *bthost, bthost_ready_cb cb) +{ + if (bthost->ready) { + cb(); + return; + } + + bthost->ready_cb = cb; } static void read_local_features_complete(struct bthost *bthost, diff --git a/emulator/bthost.h b/emulator/bthost.h index 6295c1380..8193cdf14 100644 --- a/emulator/bthost.h +++ b/emulator/bthost.h @@ -33,6 +33,9 @@ struct bthost; struct bthost *bthost_create(void); void bthost_destroy(struct bthost *bthost); +typedef void (*bthost_ready_cb) (void); +void bthost_notify_ready(struct bthost *bthost, bthost_ready_cb cb); + void bthost_set_send_handler(struct bthost *bthost, bthost_send_func handler, void *user_data); -- 2.47.3