Skip to content

Commit

Permalink
🔀 Merge branch 'yann/feature/fix/ble/eventqueue-called-only-once' int…
Browse files Browse the repository at this point in the history
…o develop
  • Loading branch information
ladislas committed Feb 11, 2022
2 parents dfca888 + 12e0490 commit c2d810a
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 19 deletions.
2 changes: 2 additions & 0 deletions drivers/CoreEventQueue/include/CoreEventQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class CoreEventQueue : public interface::EventQueue

void call(std::function<void()> const &f) final;

void callMbedCallback(mbed::Callback<void()> const &f);

private:
rtos::Thread _event_queue_thread {};
events::EventQueue _event_queue {};
Expand Down
5 changes: 5 additions & 0 deletions drivers/CoreEventQueue/source/CoreEventQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ void CoreEventQueue::call(std::function<void()> const &f)
{
_event_queue.call(f);
}

void CoreEventQueue::callMbedCallback(mbed::Callback<void()> const &f)
{
_event_queue.call(f);
}
2 changes: 1 addition & 1 deletion libs/BLEKit/include/BLEKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BLEKit
CoreEventQueue _event_queue {};

BLE &_ble = BLE::Instance();
CoreGap _core_gap {_event_queue, _ble.gap()};
CoreGap _core_gap {_ble.gap()};
};

} // namespace leka
Expand Down
3 changes: 1 addition & 2 deletions libs/BLEKit/include/CoreGap.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
#include "ble/Gap.h"

#include "CoreGapEventHandler.h"
#include "interface/drivers/EventQueue.h"

namespace leka {

class CoreGap
{
public:
explicit CoreGap(interface::EventQueue &event_queue, ble::Gap &gap) : _gap_event_handler(event_queue), _gap(gap) {};
explicit CoreGap(ble::Gap &gap) : _gap(gap) {};

void setDefaultAdvertising();

Expand Down
5 changes: 1 addition & 4 deletions libs/BLEKit/include/CoreGapEventHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
#include "ble/BLE.h"
#include "ble/Gap.h"

#include "interface/drivers/EventQueue.h"

namespace leka {

class CoreGapEventHandler : public ble::Gap::EventHandler
{
public:
explicit CoreGapEventHandler(interface::EventQueue &event_queue) : _event_queue(event_queue) {};
explicit CoreGapEventHandler() = default;

void registerStartAdvertising(std::function<void()> const &function);

Expand All @@ -26,7 +24,6 @@ class CoreGapEventHandler : public ble::Gap::EventHandler
void onAdvertisingEnd(ble::AdvertisingEndEvent const &event) override;

private:
interface::EventQueue &_event_queue;
std::function<void()> _start_advertising {};
};

Expand Down
2 changes: 1 addition & 1 deletion libs/BLEKit/source/BLEKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ void BLEKit::init()

void BLEKit::processEvents(BLE::OnEventsToProcessCallbackContext *context)
{
_event_queue.call(mbed::callback(&context->ble, &BLE::processEvents));
_event_queue.callMbedCallback(mbed::callback(&context->ble, &BLE::processEvents));
}
8 changes: 4 additions & 4 deletions libs/BLEKit/source/CoreGapEventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ void CoreGapEventHandler::onInitializationComplete(BLE::InitializationCompleteCa
return;
}

_event_queue.call(_start_advertising);
_start_advertising();
}

void CoreGapEventHandler::onConnectionComplete(ConnectionCompleteEvent const &event)
{
if (event.getStatus() != BLE_ERROR_NONE) {
_event_queue.call(_start_advertising);
_start_advertising();
}
}

void CoreGapEventHandler::onDisconnectionComplete(DisconnectionCompleteEvent const &event)
{
_event_queue.call(_start_advertising);
_start_advertising();
}

void CoreGapEventHandler::onAdvertisingEnd(AdvertisingEndEvent const &event)
{
_event_queue.call(_start_advertising);
_start_advertising();
}
4 changes: 1 addition & 3 deletions libs/BLEKit/tests/CoreGapEventHandler_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "stubs/leka/CoreEventQueue.h"

using namespace leka;
using namespace ble;
Expand All @@ -25,8 +24,7 @@ class CoreGapEventHandlerTest : public testing::Test
void TearDown() override { ble::delete_mocks(); }

BLE &ble = BLE::Instance();
CoreEventQueue core_event_queue {};
CoreGapEventHandler core_gap_event_handler {core_event_queue};
CoreGapEventHandler core_gap_event_handler {};

MockFunction<void()> mock_start_advertising_func;
};
Expand Down
4 changes: 1 addition & 3 deletions libs/BLEKit/tests/CoreGap_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "stubs/leka/CoreEventQueue.h"
#include "stubs/mbed/BLE.h"

using namespace leka;
Expand All @@ -31,8 +30,7 @@ class CoreGapTest : public testing::Test

BLE &ble = BLE::Instance();
GapMock &mock_gap = gap_mock();
CoreEventQueue eq {};
CoreGap coregap {eq, ble.gap()};
CoreGap coregap {ble.gap()};

void expectStartAdvertisingCall(bool expected)
{
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/stubs/stubs/leka/source/CoreEventQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ void CoreEventQueue::dispatch_forever()
// do nothing
}

void CoreEventQueue::call(const std::function<void()> &f)
void CoreEventQueue::call(std::function<void()> const &f)
{
f();
spy_CoreEventQueue_did_call_function = true;
}

void CoreEventQueue::callMbedCallback(mbed::Callback<void()> const &f)
{
f();
spy_CoreEventQueue_did_call_function = true;
Expand Down

0 comments on commit c2d810a

Please sign in to comment.