From 0e6b21184016698cea2bfd416b6ec04b092fb43d Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Tue, 4 Jun 2024 16:02:21 +0200 Subject: [PATCH] Pass CHIP_ERROR to device event --- src/platform/Linux/CHIPDevicePlatformEvent.h | 1 + src/platform/Tizen/BLEManagerImpl.cpp | 46 +++++++++----------- src/platform/Tizen/BLEManagerImpl.h | 10 ++--- src/platform/Tizen/CHIPDevicePlatformEvent.h | 13 +++--- 4 files changed, 32 insertions(+), 38 deletions(-) diff --git a/src/platform/Linux/CHIPDevicePlatformEvent.h b/src/platform/Linux/CHIPDevicePlatformEvent.h index 18ed55a1ef28d4..a70411888413c1 100644 --- a/src/platform/Linux/CHIPDevicePlatformEvent.h +++ b/src/platform/Linux/CHIPDevicePlatformEvent.h @@ -23,6 +23,7 @@ #pragma once +#include #include #include diff --git a/src/platform/Tizen/BLEManagerImpl.cpp b/src/platform/Tizen/BLEManagerImpl.cpp index 60ffa513ddc310..d8cd2a61ce0f6c 100644 --- a/src/platform/Tizen/BLEManagerImpl.cpp +++ b/src/platform/Tizen/BLEManagerImpl.cpp @@ -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); @@ -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); }); } @@ -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); } @@ -655,8 +652,7 @@ 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; @@ -664,8 +660,7 @@ CHIP_ERROR BLEManagerImpl::RegisterGATTServer() return CHIP_NO_ERROR; exit: - ChipLogDetail(DeviceLayer, "NotifyBLEPeripheralGATTServerRegisterComplete Failed"); - BLEManagerImpl::NotifyBLEPeripheralGATTServerRegisterComplete(false, nullptr); + BLEManagerImpl::NotifyBLEPeripheralGATTServerRegisterComplete(TizenToChipError(ret)); return TizenToChipError(ret); } @@ -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, @@ -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() @@ -765,7 +761,7 @@ CHIP_ERROR BLEManagerImpl::StopBLEAdvertising() return CHIP_NO_ERROR; exit: - BLEManagerImpl::NotifyBLEPeripheralAdvStopComplete(false, nullptr); + BLEManagerImpl::NotifyBLEPeripheralAdvStopComplete(TizenToChipError(ret)); return TizenToChipError(ret); } diff --git a/src/platform/Tizen/BLEManagerImpl.h b/src/platform/Tizen/BLEManagerImpl.h index ed30b92aa958b7..d4da822083a241 100644 --- a/src/platform/Tizen/BLEManagerImpl.h +++ b/src/platform/Tizen/BLEManagerImpl.h @@ -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 @@ -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); diff --git a/src/platform/Tizen/CHIPDevicePlatformEvent.h b/src/platform/Tizen/CHIPDevicePlatformEvent.h index 2145b18b448c8f..ce606fd7f576fd 100644 --- a/src/platform/Tizen/CHIPDevicePlatformEvent.h +++ b/src/platform/Tizen/CHIPDevicePlatformEvent.h @@ -23,6 +23,7 @@ #pragma once +#include #include #include @@ -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 {