Skip to content

Commit

Permalink
[Tizen] Release BLE when no longer needed (#23032)
Browse files Browse the repository at this point in the history
* [Tizen] Release BLE when no longer needed

clang-tidy: modernize redundant void

* [Linux] Check for error when registering GATT
  • Loading branch information
arkq authored and pull[bot] committed Apr 14, 2023
1 parent 9180488 commit 1597340
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
1 change: 1 addition & 0 deletions src/platform/Linux/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ void BLEManagerImpl::DriveBLEState()
if (!mIsCentral && mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_Enabled && !mFlags.Has(Flags::kAppRegistered))
{
err = BluezGattsAppRegister(mpEndpoint);
SuccessOrExit(err);
mFlags.Set(Flags::kControlOpInProgress);
ExitNow();
}
Expand Down
26 changes: 16 additions & 10 deletions src/platform/Tizen/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ void BLEManagerImpl::OnChipDeviceScanned(void * device, const chip::Ble::ChipBLE
ConnectHandler(deviceInfo->remote_address);
}

void BLEManagerImpl::OnChipScanComplete(void)
void BLEManagerImpl::OnChipScanComplete()
{
if (mBLEScanConfig.mBleScanState != BleScanState::kScanForDiscriminator &&
mBLEScanConfig.mBleScanState != BleScanState::kScanForAddress)
Expand Down Expand Up @@ -579,7 +579,7 @@ int BLEManagerImpl::RegisterGATTServer()
return ret;
}

int BLEManagerImpl::StartAdvertising()
int BLEManagerImpl::StartBLEAdvertising()
{
int ret = BT_ERROR_NONE;
CHIP_ERROR err = CHIP_NO_ERROR;
Expand Down Expand Up @@ -649,7 +649,7 @@ int BLEManagerImpl::StartAdvertising()
return ret;
}

int BLEManagerImpl::StopAdvertising()
int BLEManagerImpl::StopBLEAdvertising()
{
int ret = BT_ERROR_NONE;

Expand All @@ -664,7 +664,7 @@ int BLEManagerImpl::StopAdvertising()
return ret;
}

void BLEManagerImpl::InitConnectionData(void)
void BLEManagerImpl::InitConnectionData()
{
/* Initialize Hashmap */
if (!mConnectionMap)
Expand Down Expand Up @@ -872,21 +872,21 @@ void BLEManagerImpl::DriveBLEState()
{
if (!mFlags.Has(Flags::kAdvertising))
{
ret = StartAdvertising();
ret = StartBLEAdvertising();
VerifyOrExit(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "Start Advertising Failed. ret: %d", ret));
}
else if (mFlags.Has(Flags::kAdvertisingRefreshNeeded))
{
ChipLogProgress(DeviceLayer, "Advertising Refreshed Needed. Stop Advertising");
ret = StopAdvertising();
ret = StopBLEAdvertising();
VerifyOrExit(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "Stop Advertising Failed. ret: %d", ret));
}
}
else if (mFlags.Has(Flags::kAdvertising))
{
ChipLogProgress(DeviceLayer, "Stop Advertising");

ret = StopAdvertising();
ret = StopBLEAdvertising();
VerifyOrExit(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "Stop Advertising Failed. ret: %d", ret));

ret = bt_adapter_le_destroy_advertiser(mAdvertiser);
Expand All @@ -906,7 +906,7 @@ void BLEManagerImpl::DriveBLEState(intptr_t arg)
sInstance.DriveBLEState();
}

CHIP_ERROR BLEManagerImpl::_Init(void)
CHIP_ERROR BLEManagerImpl::_Init()
{
CHIP_ERROR err;
bool ret;
Expand All @@ -926,6 +926,12 @@ CHIP_ERROR BLEManagerImpl::_Init(void)
return err;
}

void BLEManagerImpl::_Shutdown()
{
int ret = bt_deinitialize();
VerifyOrReturn(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "bt_deinitialize() failed. ret: %d", ret));
}

CHIP_ERROR BLEManagerImpl::_SetAdvertisingEnabled(bool val)
{
mFlags.Set(Flags::kAdvertisingEnabled, val);
Expand Down Expand Up @@ -994,7 +1000,7 @@ CHIP_ERROR BLEManagerImpl::_SetDeviceName(const char * deviceName)
return err;
}

uint16_t BLEManagerImpl::_NumConnections(void)
uint16_t BLEManagerImpl::_NumConnections()
{
return 0;
}
Expand All @@ -1006,7 +1012,7 @@ CHIP_ERROR BLEManagerImpl::ConfigureBle(uint32_t aAdapterId, bool aIsCentral)
return CHIP_NO_ERROR;
}

void BLEManagerImpl::CleanScanConfig(void)
void BLEManagerImpl::CleanScanConfig()
{
if (mBLEScanConfig.mBleScanState == BleScanState::kConnecting)
chip::DeviceLayer::SystemLayer().CancelTimer(HandleConnectionTimeout, nullptr);
Expand Down
31 changes: 16 additions & 15 deletions src/platform/Tizen/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,19 @@ class BLEManagerImpl final : public BLEManager,
private:
// ===== Members that implement the BLEManager internal interface.

CHIP_ERROR _Init(void);
void _Shutdown() {}
bool _IsAdvertisingEnabled(void);
CHIP_ERROR _Init();
void _Shutdown();
bool _IsAdvertisingEnabled();
CHIP_ERROR _SetAdvertisingEnabled(bool val);
bool _IsAdvertising(void);
bool _IsAdvertising();
CHIP_ERROR _SetAdvertisingMode(BLEAdvertisingMode mode);
CHIP_ERROR _GetDeviceName(char * buf, size_t bufSize);
CHIP_ERROR _SetDeviceName(const char * deviceName);
uint16_t _NumConnections(void);
uint16_t _NumConnections();

void _OnPlatformEvent(const ChipDeviceEvent * event);
void HandlePlatformSpecificBLEEvent(const ChipDeviceEvent * event);
BleLayer * _GetBleLayer(void);
BleLayer * _GetBleLayer();

// ===== Members that implement virtual methods on BlePlatformDelegate.

Expand Down Expand Up @@ -131,8 +132,8 @@ class BLEManagerImpl final : public BLEManager,

// ===== Members for internal use by the following friends.

friend BLEManager & BLEMgr(void);
friend BLEManagerImpl & BLEMgrImpl(void);
friend BLEManager & BLEMgr();
friend BLEManagerImpl & BLEMgrImpl();

static BLEManagerImpl sInstance;

Expand Down Expand Up @@ -172,7 +173,7 @@ class BLEManagerImpl final : public BLEManager,
static void CharacteristicNotificationCb(bt_gatt_h characteristic, char * value, int len, void * userData);

// ==== Connection.
void InitConnectionData(void);
void InitConnectionData();
void AddConnectionData(const char * remoteAddr);
void RemoveConnectionData(const char * remoteAddr);

Expand Down Expand Up @@ -202,10 +203,10 @@ class BLEManagerImpl final : public BLEManager,
void NotifySubscribeOpComplete(BLE_CONNECTION_OBJECT conId, bool isSubscribed);
void NotifyBLENotificationReceived(System::PacketBufferHandle & buf, BLE_CONNECTION_OBJECT conId);

int RegisterGATTServer(void);
int StartAdvertising(void);
int StopAdvertising(void);
void CleanScanConfig(void);
int RegisterGATTServer();
int StartBLEAdvertising();
int StopBLEAdvertising();
void CleanScanConfig();

CHIPoBLEServiceMode mServiceMode;
BitFlags<Flags> mFlags;
Expand All @@ -230,7 +231,7 @@ class BLEManagerImpl final : public BLEManager,
* Internal components should use this to access features of the BLEManager object
* that are common to all platforms.
*/
inline BLEManager & BLEMgr(void)
inline BLEManager & BLEMgr()
{
return BLEManagerImpl::sInstance;
}
Expand All @@ -241,7 +242,7 @@ inline BLEManager & BLEMgr(void)
* Internal components can use this to gain access to features of the BLEManager
* that are specific to the Tizen platforms.
*/
inline BLEManagerImpl & BLEMgrImpl(void)
inline BLEManagerImpl & BLEMgrImpl()
{
return BLEManagerImpl::sInstance;
}
Expand Down

0 comments on commit 1597340

Please sign in to comment.