Skip to content

Commit

Permalink
Add BLE shutdown, make linux free up scanning upon shutdown (#11437)
Browse files Browse the repository at this point in the history
* Add BLE shutdown, make linux free up scanning upon shutdown

* Add shutdown method for ameba as well

* Revert change to copyright date in gn.py
  • Loading branch information
andy31415 authored and pull[bot] committed Dec 11, 2023
1 parent ea68e35 commit 62d6484
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/include/platform/internal/BLEManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class BLEManager
using BLEAdvertisingMode = ConnectivityManager::BLEAdvertisingMode;

CHIP_ERROR Init();
CHIP_ERROR Shutdown();
CHIPoBLEServiceMode GetCHIPoBLEServiceMode();
CHIP_ERROR SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val);
bool IsAdvertisingEnabled();
Expand Down Expand Up @@ -116,6 +117,12 @@ inline CHIP_ERROR BLEManager::Init()
return static_cast<ImplClass *>(this)->_Init();
}

inline CHIP_ERROR BLEManager::Shutdown()
{
ReturnErrorOnFailure(GetBleLayer()->Shutdown());
return static_cast<ImplClass *>(this)->_Shutdown();
}

inline BLEManager::CHIPoBLEServiceMode BLEManager::GetCHIPoBLEServiceMode()
{
return static_cast<ImplClass *>(this)->_GetCHIPoBLEServiceMode();
Expand Down
4 changes: 2 additions & 2 deletions src/include/platform/internal/GenericPlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ CHIP_ERROR GenericPlatformManagerImpl<ImplClass>::_Shutdown()
err = InetLayer().Shutdown();

#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
ChipLogError(DeviceLayer, "BLE layer shutdown");
err = BLEMgr().GetBleLayer()->Shutdown();
ChipLogError(DeviceLayer, "BLE shutdown");
err = BLEMgr().Shutdown();
#endif

ChipLogError(DeviceLayer, "System Layer shutdown");
Expand Down
1 change: 1 addition & 0 deletions src/platform/Ameba/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
// ===== Members that implement the BLEManager internal interface.

CHIP_ERROR _Init(void);
CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; }
CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void);
CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val);
bool _IsAdvertisingEnabled(void);
Expand Down
1 change: 1 addition & 0 deletions src/platform/Darwin/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer
// ===== Members that implement the BLEManager internal interface.

CHIP_ERROR _Init(void);
CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; }
CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void);
CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val);
bool _IsAdvertisingEnabled(void);
Expand Down
1 change: 1 addition & 0 deletions src/platform/EFR32/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
// ===== Members that implement the BLEManager internal interface.

CHIP_ERROR _Init(void);
CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; }
CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void);
CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val);
bool _IsAdvertisingEnabled(void);
Expand Down
1 change: 1 addition & 0 deletions src/platform/ESP32/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class BLEManagerImpl final : public BLEManager,
// ===== Members that implement the BLEManager internal interface.

CHIP_ERROR _Init(void);
CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; }
CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void);
CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val);
bool _IsAdvertisingEnabled(void);
Expand Down
8 changes: 8 additions & 0 deletions src/platform/Linux/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ CHIP_ERROR BLEManagerImpl::_Init()
return err;
}

CHIP_ERROR BLEManagerImpl::_Shutdown()
{
// ensure scan resources are cleared (e.g. timeout timers)
mDeviceScanner.reset();

return CHIP_NO_ERROR;
}

CHIP_ERROR BLEManagerImpl::_SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val)
{
CHIP_ERROR err = CHIP_NO_ERROR;
Expand Down
1 change: 1 addition & 0 deletions src/platform/Linux/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class BLEManagerImpl final : public BLEManager,
// ===== Members that implement the BLEManager internal interface.

CHIP_ERROR _Init();
CHIP_ERROR _Shutdown();
CHIPoBLEServiceMode _GetCHIPoBLEServiceMode();
CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val);
bool _IsAdvertisingEnabled();
Expand Down
1 change: 1 addition & 0 deletions src/platform/P6/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class BLEManagerImpl final : public BLEManager,
// ===== Members that implement the BLEManager internal interface.

CHIP_ERROR _Init(void);
CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; }
CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void);
CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val);
bool _IsAdvertisingEnabled(void);
Expand Down
1 change: 1 addition & 0 deletions src/platform/Tizen/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class BLEManagerImpl final : public BLEManager,
// ===== Members that implement the BLEManager internal interface.

CHIP_ERROR _Init(void);
CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; }
CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void);
CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val);
bool _IsAdvertisingEnabled(void);
Expand Down
1 change: 1 addition & 0 deletions src/platform/Zephyr/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
// ===== Members that implement the BLEManager internal interface.

CHIP_ERROR _Init(void);
CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; }
CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void);
CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val);
bool _IsAdvertisingEnabled(void);
Expand Down
1 change: 1 addition & 0 deletions src/platform/android/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class BLEManagerImpl final : public BLEManager,
// ===== Members that implement the BLEManager internal interface.

CHIP_ERROR _Init();
CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; }
CHIPoBLEServiceMode _GetCHIPoBLEServiceMode();
CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val);
bool _IsAdvertisingEnabled();
Expand Down
1 change: 1 addition & 0 deletions src/platform/cc13x2_26x2/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
// ===== Members that implement the BLEManager internal interface.

CHIP_ERROR _Init(void);
CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; }
CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void);
CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val);
bool _IsAdvertisingEnabled(void);
Expand Down
1 change: 1 addition & 0 deletions src/platform/mbed/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
// ===== Members that implement the BLEManager internal interface.

CHIP_ERROR _Init(void);
CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; }
CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void);
CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val);
bool _IsAdvertisingEnabled(void);
Expand Down
1 change: 1 addition & 0 deletions src/platform/nxp/k32w/k32w0/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
// ===== Members that implement the BLEManager internal interface.

CHIP_ERROR _Init(void);
CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; }
CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void);
CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val);
bool _IsAdvertisingEnabled(void);
Expand Down
1 change: 1 addition & 0 deletions src/platform/qpg/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
// ===== Members that implement the BLEManager internal interface.

CHIP_ERROR _Init(void);
CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; }
CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void);
CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val);
bool _IsAdvertisingEnabled(void);
Expand Down

0 comments on commit 62d6484

Please sign in to comment.