Skip to content

Commit

Permalink
Pass CHIP_ERROR to device event
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq committed Jun 5, 2024
1 parent 0087f80 commit 0e6b211
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 38 deletions.
1 change: 1 addition & 0 deletions src/platform/Linux/CHIPDevicePlatformEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#pragma once

#include <lib/core/CHIPError.h>
#include <platform/CHIPDeviceEvent.h>
#include <system/SystemPacketBuffer.h>

Expand Down
46 changes: 21 additions & 25 deletions src/platform/Tizen/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ void BLEManagerImpl::AdvertisingStateChangedCb(int result, bt_advertiser_h adver
if (advState == BT_ADAPTER_LE_ADVERTISING_STARTED)
{
mFlags.Set(Flags::kAdvertising);
NotifyBLEPeripheralAdvStartComplete(true, nullptr);
NotifyBLEPeripheralAdvStartComplete(CHIP_NO_ERROR);
DeviceLayer::SystemLayer().ScheduleLambda([this] {
// Start a timer to make sure that the fast advertising is stopped after specified timeout.
DeviceLayer::SystemLayer().StartTimer(kFastAdvertiseTimeout, HandleAdvertisingTimeout, this);
Expand All @@ -329,7 +329,7 @@ void BLEManagerImpl::AdvertisingStateChangedCb(int result, bt_advertiser_h adver
else
{
mFlags.Clear(Flags::kAdvertising);
NotifyBLEPeripheralAdvStopComplete(true, nullptr);
NotifyBLEPeripheralAdvStopComplete(CHIP_NO_ERROR);
DeviceLayer::SystemLayer().ScheduleLambda(
[this] { DeviceLayer::SystemLayer().CancelTimer(HandleAdvertisingTimeout, this); });
}
Expand All @@ -344,39 +344,36 @@ void BLEManagerImpl::AdvertisingStateChangedCb(int result, bt_advertiser_h adver
}

// ====== Private Functions.
void BLEManagerImpl::NotifyBLEPeripheralGATTServerRegisterComplete(bool aIsSuccess, void * apAppstate)

void BLEManagerImpl::NotifyBLEPeripheralGATTServerRegisterComplete(CHIP_ERROR error)
{
ChipDeviceEvent event;
event.Type = DeviceEventType::kPlatformTizenBLEPeripheralGATTServerRegisterComplete;
event.Platform.BLEPeripheralGATTServerRegisterComplete.mIsSuccess = aIsSuccess;
event.Platform.BLEPeripheralGATTServerRegisterComplete.mpAppstate = apAppstate;
event.Platform.BLEPeripheralGATTServerRegisterComplete.mError = error;
PlatformMgr().PostEventOrDie(&event);
}

void BLEManagerImpl::NotifyBLEPeripheralAdvConfiguredComplete(bool aIsSuccess, void * apAppstate)
void BLEManagerImpl::NotifyBLEPeripheralAdvConfiguredComplete(CHIP_ERROR error)
{
ChipDeviceEvent event;
event.Type = DeviceEventType::kPlatformTizenBLEPeripheralAdvConfiguredComplete;
event.Platform.BLEPeripheralAdvConfiguredComplete.mIsSuccess = aIsSuccess;
event.Platform.BLEPeripheralAdvConfiguredComplete.mpAppstate = apAppstate;
event.Type = DeviceEventType::kPlatformTizenBLEPeripheralAdvConfiguredComplete;
event.Platform.BLEPeripheralAdvConfiguredComplete.mError = error;
PlatformMgr().PostEventOrDie(&event);
}

void BLEManagerImpl::NotifyBLEPeripheralAdvStartComplete(bool aIsSuccess, void * apAppstate)
void BLEManagerImpl::NotifyBLEPeripheralAdvStartComplete(CHIP_ERROR error)
{
ChipDeviceEvent event;
event.Type = DeviceEventType::kPlatformTizenBLEPeripheralAdvStartComplete;
event.Platform.BLEPeripheralAdvStartComplete.mIsSuccess = aIsSuccess;
event.Platform.BLEPeripheralAdvStartComplete.mpAppstate = apAppstate;
event.Type = DeviceEventType::kPlatformTizenBLEPeripheralAdvStartComplete;
event.Platform.BLEPeripheralAdvStartComplete.mError = error;
PlatformMgr().PostEventOrDie(&event);
}

void BLEManagerImpl::NotifyBLEPeripheralAdvStopComplete(bool aIsSuccess, void * apAppstate)
void BLEManagerImpl::NotifyBLEPeripheralAdvStopComplete(CHIP_ERROR error)
{
ChipDeviceEvent event;
event.Type = DeviceEventType::kPlatformTizenBLEPeripheralAdvStopComplete;
event.Platform.BLEPeripheralAdvStopComplete.mIsSuccess = aIsSuccess;
event.Platform.BLEPeripheralAdvStopComplete.mpAppstate = apAppstate;
event.Type = DeviceEventType::kPlatformTizenBLEPeripheralAdvStopComplete;
event.Platform.BLEPeripheralAdvStopComplete.mError = error;
PlatformMgr().PostEventOrDie(&event);
}

Expand Down Expand Up @@ -655,17 +652,15 @@ CHIP_ERROR BLEManagerImpl::RegisterGATTServer()
ret = bt_gatt_server_start();
VerifyOrExit(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "bt_gatt_server_start() failed: %s", get_error_message(ret)));

ChipLogDetail(DeviceLayer, "NotifyBLEPeripheralGATTServerRegisterComplete Success");
BLEManagerImpl::NotifyBLEPeripheralGATTServerRegisterComplete(true, nullptr);
BLEManagerImpl::NotifyBLEPeripheralGATTServerRegisterComplete(CHIP_NO_ERROR);

// Save the Local Peripheral char1 & char2 handles
mGattCharC1Handle = char1;
mGattCharC2Handle = char2;
return CHIP_NO_ERROR;

exit:
ChipLogDetail(DeviceLayer, "NotifyBLEPeripheralGATTServerRegisterComplete Failed");
BLEManagerImpl::NotifyBLEPeripheralGATTServerRegisterComplete(false, nullptr);
BLEManagerImpl::NotifyBLEPeripheralGATTServerRegisterComplete(TizenToChipError(ret));
return TizenToChipError(ret);
}

Expand Down Expand Up @@ -734,7 +729,7 @@ CHIP_ERROR BLEManagerImpl::StartBLEAdvertising()
VerifyOrExit(ret == BT_ERROR_NONE,
ChipLogError(DeviceLayer, "bt_adapter_le_set_advertising_device_name() failed: %s", get_error_message(ret)));

BLEManagerImpl::NotifyBLEPeripheralAdvConfiguredComplete(true, nullptr);
BLEManagerImpl::NotifyBLEPeripheralAdvConfiguredComplete(CHIP_NO_ERROR);

ret = bt_adapter_le_start_advertising_new(
mAdvertiser,
Expand All @@ -749,8 +744,9 @@ CHIP_ERROR BLEManagerImpl::StartBLEAdvertising()
return CHIP_NO_ERROR;

exit:
BLEManagerImpl::NotifyBLEPeripheralAdvStartComplete(false, nullptr);
return ret != BT_ERROR_NONE ? TizenToChipError(ret) : err;
err = ret != BT_ERROR_NONE ? TizenToChipError(ret) : err;
BLEManagerImpl::NotifyBLEPeripheralAdvStartComplete(err);
return err;
}

CHIP_ERROR BLEManagerImpl::StopBLEAdvertising()
Expand All @@ -765,7 +761,7 @@ CHIP_ERROR BLEManagerImpl::StopBLEAdvertising()
return CHIP_NO_ERROR;

exit:
BLEManagerImpl::NotifyBLEPeripheralAdvStopComplete(false, nullptr);
BLEManagerImpl::NotifyBLEPeripheralAdvStopComplete(TizenToChipError(ret));
return TizenToChipError(ret);
}

Expand Down
10 changes: 5 additions & 5 deletions src/platform/Tizen/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class BLEManagerImpl final : public BLEManager,
// ===== Members that implement virtual methods on BleConnectionDelegate.

void NewConnection(BleLayer * bleLayer, void * appState, const SetupDiscriminator & connDiscriminator) override;
void NewConnection(BleLayer * bleLayer, void * appState, BLE_CONNECTION_OBJECT connObj) override{};
void NewConnection(BleLayer * bleLayer, void * appState, BLE_CONNECTION_OBJECT connObj) override {};
CHIP_ERROR CancelConnection() override;

// ===== Members that implement virtual methods on ChipDeviceScannerDelegate
Expand Down Expand Up @@ -196,10 +196,10 @@ class BLEManagerImpl final : public BLEManager,
bool IsDeviceChipPeripheral(BLE_CONNECTION_OBJECT conId);

// ==== BLE Adv & GATT Server.
void NotifyBLEPeripheralGATTServerRegisterComplete(bool aIsSuccess, void * apAppstate);
void NotifyBLEPeripheralAdvConfiguredComplete(bool aIsSuccess, void * apAppstate);
void NotifyBLEPeripheralAdvStartComplete(bool aIsSuccess, void * apAppstate);
void NotifyBLEPeripheralAdvStopComplete(bool aIsSuccess, void * apAppstate);
void NotifyBLEPeripheralGATTServerRegisterComplete(CHIP_ERROR error);
void NotifyBLEPeripheralAdvConfiguredComplete(CHIP_ERROR error);
void NotifyBLEPeripheralAdvStartComplete(CHIP_ERROR error);
void NotifyBLEPeripheralAdvStopComplete(CHIP_ERROR error);
void NotifyBLESubscribed(bool indicationsEnabled, BLE_CONNECTION_OBJECT conId);
void NotifyBLEIndicationConfirmation(BLE_CONNECTION_OBJECT conId);
void NotifyBLEWriteReceived(System::PacketBufferHandle & buf, BLE_CONNECTION_OBJECT conId);
Expand Down
13 changes: 5 additions & 8 deletions src/platform/Tizen/CHIPDevicePlatformEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#pragma once

#include <lib/core/CHIPError.h>
#include <platform/CHIPDeviceEvent.h>
#include <system/SystemPacketBuffer.h>

Expand Down Expand Up @@ -67,23 +68,19 @@ struct ChipDevicePlatformEvent
{
struct
{
bool mIsSuccess;
void * mpAppstate;
CHIP_ERROR mError;
} BLEPeripheralGATTServerRegisterComplete;
struct
{
bool mIsSuccess;
void * mpAppstate;
CHIP_ERROR mError;
} BLEPeripheralAdvConfiguredComplete;
struct
{
bool mIsSuccess;
void * mpAppstate;
CHIP_ERROR mError;
} BLEPeripheralAdvStartComplete;
struct
{
bool mIsSuccess;
void * mpAppstate;
CHIP_ERROR mError;
} BLEPeripheralAdvStopComplete;
struct
{
Expand Down

0 comments on commit 0e6b211

Please sign in to comment.