Skip to content

Commit

Permalink
⚡ (ble): Use CoreGattServer in BLEKit
Browse files Browse the repository at this point in the history
🚧 (ble): Do not use post_init in CoreGap
  • Loading branch information
YannLocatelli committed Feb 9, 2022
1 parent 46e861e commit 933a762
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions libs/BLEKit/include/BLEKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "CoreEventQueue.h"
#include "CoreGap.h"
#include "CoreGattServer.h"

namespace leka {

Expand All @@ -27,6 +28,7 @@ class BLEKit

BLE &_ble = BLE::Instance();
CoreGap _core_gap {_ble.gap()};
CoreGattServer _core_gatt_server {_ble.gattServer()};
};

} // namespace leka
Expand Down
3 changes: 3 additions & 0 deletions libs/BLEKit/include/CoreGap.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CoreGap

void setEventHandler();
void onInitializationComplete(BLE::InitializationCompleteCallbackContext *params);
// void onInit(std::function<void()> cb) { _post_init = cb; }

void setDeviceName(const char *name);

Expand All @@ -36,6 +37,8 @@ class CoreGap

CoreGapEventHandler _gap_event_handler;
ble::Gap &_gap;

// std::function<void()> _post_init;
};

} // namespace leka
Expand Down
8 changes: 6 additions & 2 deletions libs/BLEKit/source/BLEKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ void BLEKit::init()

_ble.onEventsToProcess({this, &BLEKit::processEvents});

_event_queue.dispatch_forever();

_core_gap.setDefaultAdvertising();
_core_gap.setDeviceName("Leka");

_core_gatt_server.setServer();
// _core_gap.onInit(std::bind(&CoreGattServer::updateData, &_core_gatt_server));
// _core_gap.onInit([this] { _core_gatt_server.updateData(); }); // clang suggestion

_ble.init(&_core_gap, &CoreGap::onInitializationComplete);

_event_queue.dispatch_forever();
}

void BLEKit::processEvents(BLE::OnEventsToProcessCallbackContext *context)
Expand Down
4 changes: 4 additions & 0 deletions libs/BLEKit/source/CoreGap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ void CoreGap::setEventHandler()
void CoreGap::onInitializationComplete(BLE::InitializationCompleteCallbackContext *params)
{
_gap_event_handler.onInitializationComplete(params);

// if (_post_init) {
// _post_init();
// }
}

void CoreGap::setDeviceName(const char *name)
Expand Down
8 changes: 7 additions & 1 deletion libs/BLEKit/tests/BLEKit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ using namespace leka;
using namespace ble;

using ::testing::AnyNumber;
using ::testing::AtLeast;
using ::testing::Return;

class BLEKitTest : public testing::Test
Expand All @@ -28,7 +29,8 @@ class BLEKitTest : public testing::Test
void TearDown() override { ble::delete_mocks(); }

BLEKit ble {};
GapMock &mock_gap = gap_mock();
GapMock &mock_gap = gap_mock();
GattServerMock &mock_gatt = gatt_server_mock();

void expectStartAdvertisingCall()
{
Expand All @@ -49,6 +51,8 @@ TEST_F(BLEKitTest, init)
spy_ble_hasInitialized_return_value = false;

EXPECT_CALL(mock_gap, setEventHandler).Times(1);
EXPECT_CALL(mock_gatt, setEventHandler).Times(1);
EXPECT_CALL(mock_gatt, addService).Times(AtLeast(1));
expectStartAdvertisingCall();

ble.init();
Expand Down Expand Up @@ -77,6 +81,8 @@ TEST_F(BLEKitTest, callOnEventsToProcess)
spy_CoreEventQueue_did_call_function = false;

EXPECT_CALL(mock_gap, setEventHandler).Times(AnyNumber());
EXPECT_CALL(mock_gatt, setEventHandler).Times(AnyNumber());
EXPECT_CALL(mock_gatt, addService).Times(AnyNumber());

ble.init();

Expand Down

0 comments on commit 933a762

Please sign in to comment.