From 7b06a5623f94b51d587e1e370d802fcf89fe17a5 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 2 Jul 2021 15:20:34 +0200 Subject: [PATCH] btstack_run_loop_qt: implement poll_data_sources_from_irq --- platform/qt/btstack_run_loop_qt.cpp | 13 +++++++++++-- platform/qt/btstack_run_loop_qt.h | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/platform/qt/btstack_run_loop_qt.cpp b/platform/qt/btstack_run_loop_qt.cpp index 537bd8c9d..12edaa4a8 100644 --- a/platform/qt/btstack_run_loop_qt.cpp +++ b/platform/qt/btstack_run_loop_qt.cpp @@ -238,8 +238,9 @@ static void btstack_run_loop_qt_add_timer(btstack_timer_source_t *ts){ // BTstackRunLoopQt class implementation BTstackRunLoopQt::BTstackRunLoopQt(void) : QObject() { - // allow to trigger processCallbacks both from main thread as well as other threads later + // enforce slot callback on receiver (main thread) via Qt::QueuedConnection connect(this, &BTstackRunLoopQt::callbackAdded, this, &BTstackRunLoopQt::processCallbacks, Qt::QueuedConnection); + connect(this, &BTstackRunLoopQt::dataSourcesPollRequested, this, &BTstackRunLoopQt::pollDataSources, Qt::QueuedConnection); } void BTstackRunLoopQt::processTimers(){ @@ -286,6 +287,10 @@ void BTstackRunLoopQt::processCallbacks(void) { } } +void BTstackRunLoopQt::pollDataSources(void) { + btstack_run_loop_base_poll_data_sources(); +} + static void btstack_run_loop_qt_execute_on_main_thread(btstack_context_callback_registration_t * callback_registration){ // protect list with mutex run_loop_callback_mutex.lock(); @@ -294,6 +299,10 @@ static void btstack_run_loop_qt_execute_on_main_thread(btstack_context_callback_ btstack_run_loop_object->emit callbackAdded(); } +static void btstack_run_loop_qt_poll_data_sources_from_irq(void){ + btstack_run_loop_object->emit dataSourcesPollRequested(); +} + static void btstack_run_loop_qt_process_data_source(int fd, uint16_t callback_types){ // find ds btstack_linked_list_iterator_t it; @@ -363,7 +372,7 @@ static const btstack_run_loop_t btstack_run_loop_qt = { &btstack_run_loop_qt_execute, &btstack_run_loop_qt_dump_timer, &btstack_run_loop_qt_get_time_ms, - NULL, /* poll data sources from irq */ + &btstack_run_loop_qt_poll_data_sources_from_irq, &btstack_run_loop_qt_execute_on_main_thread, NULL }; diff --git a/platform/qt/btstack_run_loop_qt.h b/platform/qt/btstack_run_loop_qt.h index aa52d5b18..cce79debf 100644 --- a/platform/qt/btstack_run_loop_qt.h +++ b/platform/qt/btstack_run_loop_qt.h @@ -62,6 +62,7 @@ public: public slots: void processTimers(void); void processCallbacks(void); + void pollDataSources(void); #ifdef Q_OS_WIN void processDataSource(HANDLE handle); #else @@ -70,6 +71,7 @@ public slots: #endif signals: void callbackAdded(void); + void dataSourcesPollRequested(void); }; #endif