Skip to content

Commit 92109c8

Browse files
ksperling-applegmarcosb
authored andcommitted
Allow platforms to disable BLE-related device events and add BleLayer state accessors (project-chip#37759)
1 parent 4158f80 commit 92109c8

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/ble/BleConfig.h

+10
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@
129129
#define BLE_READ_REQUEST_CONTEXT void *
130130
#endif // BLE_READ_REQUEST_CONTEXT
131131

132+
/**
133+
* @def BLE_USES_DEVICE_EVENTS
134+
*
135+
* @brief Whether the platform uses / supports BLE-related device events.
136+
* @see chip::DeviceLayer::ChipDeviceEvent
137+
*/
138+
#ifndef BLE_USES_DEVICE_EVENTS
139+
#define BLE_USES_DEVICE_EVENTS 1
140+
#endif
141+
132142
/**
133143
* @def BLE_MAX_RECEIVE_WINDOW_SIZE
134144
*

src/ble/BleLayer.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class DLL_EXPORT BleLayer
223223
kState_NotInitialized = 0,
224224
kState_Initialized = 1,
225225
kState_Disconnecting = 2
226-
} mState; ///< [READ-ONLY] Current state
226+
} mState; ///< [READ-ONLY] external access is deprecated, use IsInitialized() / IsBleClosing()
227227

228228
// This app state is not used by ble transport etc, it will be used by external ble implementation like Android
229229
void * mAppState = nullptr;
@@ -236,7 +236,9 @@ class DLL_EXPORT BleLayer
236236
chip::System::Layer * systemLayer);
237237
CHIP_ERROR Init(BlePlatformDelegate * platformDelegate, BleConnectionDelegate * connDelegate,
238238
BleApplicationDelegate * appDelegate, chip::System::Layer * systemLayer);
239+
bool IsInitialized() { return mState != kState_NotInitialized; }
239240
void IndicateBleClosing();
241+
bool IsBleClosing() { return mState == kState_Disconnecting; }
240242
void Shutdown();
241243

242244
CHIP_ERROR CancelBleIncompleteConnection();

src/include/platform/CHIPDeviceEvent.h

+5
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,10 @@ typedef void (*AsyncWorkFunct)(intptr_t arg);
381381
#include CHIPDEVICEPLATFORMEVENT_HEADER
382382
#endif // defined(CHIP_DEVICE_LAYER_TARGET)
383383

384+
#if CONFIG_NETWORK_LAYER_BLE
384385
#include <ble/Ble.h>
386+
#endif
387+
385388
#include <inet/InetInterface.h>
386389
#include <lib/support/LambdaBridge.h>
387390
#include <system/SystemEvent.h>
@@ -467,6 +470,7 @@ struct ChipDeviceEvent final
467470
uint8_t SessionType;
468471
bool IsCommissioner;
469472
} SessionEstablished;
473+
#if CONFIG_NETWORK_LAYER_BLE && BLE_USES_DEVICE_EVENTS
470474
struct
471475
{
472476
BLE_CONNECTION_OBJECT ConId;
@@ -493,6 +497,7 @@ struct ChipDeviceEvent final
493497
{
494498
BLE_CONNECTION_OBJECT ConId;
495499
} CHIPoBLENotifyConfirm;
500+
#endif // CONFIG_NETWORK_LAYER_BLE && BLE_USES_DEVICE_EVENTS
496501
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
497502
struct
498503
{

0 commit comments

Comments
 (0)