Skip to content

Commit

Permalink
[Tizen] Display human readable error messages instead of numbers (#31552
Browse files Browse the repository at this point in the history
)

* Common utility for Tizen to Matter error conversion

* Use TizenToChipError in preference module

* Show human readable error message in BLE module

* Use TizenToChipError in BLE module

* Get rid of unnecessary data copying

* Use strerror when getting error from POSIX calls

* Make sure INET socket is closed upon returning error

* Clear iwreq before making ioctl call

* Convert ConnectivityUtils class to namespace

* Remove not used connectivity utils

* Show errno message in DiagnosticDataProviderImpl

* Use human readable error message in DnssdImpl

* Do not pre-initialize buffer for storing log message

* Use TizenToChipError in SystemInfo

* Mark more helper functions as constexpr

* Cleanup

* Use CHIP_ERROR_POSIX for returning errors from POSIX API
  • Loading branch information
arkq authored Jan 25, 2024
1 parent ce800c2 commit 1582d8c
Show file tree
Hide file tree
Showing 15 changed files with 610 additions and 644 deletions.
38 changes: 13 additions & 25 deletions src/platform/Tizen/AppPreference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
#include <lib/support/Span.h>
#include <lib/support/logging/CHIPLogging.h>

#include "ErrorUtils.h"

using chip::DeviceLayer::Internal::TizenToChipError;

namespace chip {
namespace DeviceLayer {
namespace PersistedStorage {
Expand All @@ -56,18 +60,11 @@ CHIP_ERROR GetData(const char * key, void * data, size_t dataSize, size_t * getD
std::unique_ptr<char, decltype(&::free)> _{ encodedData, &::free };

int err = preference_get_string(key, &encodedData);
if (err == PREFERENCE_ERROR_NO_KEY)
{
return CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND;
}
if (err == PREFERENCE_ERROR_OUT_OF_MEMORY)
{
return CHIP_ERROR_NO_MEMORY;
}
if (err != PREFERENCE_ERROR_NONE)
{
ChipLogError(DeviceLayer, "Failed to get preference [%s]: %s", StringOrNullMarker(key), get_error_message(err));
return CHIP_ERROR_INCORRECT_STATE;
if (err != PREFERENCE_ERROR_NO_KEY)
ChipLogError(DeviceLayer, "Failed to get preference [%s]: %s", StringOrNullMarker(key), get_error_message(err));
return TizenToChipError(err);
}

size_t encodedDataSize = strlen(encodedData);
Expand Down Expand Up @@ -104,15 +101,9 @@ CHIP_ERROR SaveData(const char * key, const void * data, size_t dataSize)
encodedData[encodedDataSize] = '\0';

int err = preference_set_string(key, encodedData.Get());
if (err == PREFERENCE_ERROR_OUT_OF_MEMORY)
{
return CHIP_ERROR_NO_MEMORY;
}
if (err != PREFERENCE_ERROR_NONE)
{
ChipLogError(DeviceLayer, "Failed to set preference [%s]: %s", StringOrNullMarker(key), get_error_message(err));
return CHIP_ERROR_INCORRECT_STATE;
}
VerifyOrReturnError(
err == PREFERENCE_ERROR_NONE, TizenToChipError(err),
ChipLogError(DeviceLayer, "Failed to set preference [%s]: %s", StringOrNullMarker(key), get_error_message(err)));

ChipLogDetail(DeviceLayer, "Save preference data: key=%s len=%u", key, static_cast<unsigned int>(dataSize));
ChipLogByteSpan(DeviceLayer, ByteSpan(reinterpret_cast<const uint8_t *>(data), dataSize));
Expand All @@ -123,14 +114,11 @@ CHIP_ERROR SaveData(const char * key, const void * data, size_t dataSize)
CHIP_ERROR RemoveData(const char * key)
{
int err = preference_remove(key);
if (err == PREFERENCE_ERROR_NO_KEY)
{
return CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND;
}
if (err != PREFERENCE_ERROR_NONE)
{
ChipLogError(DeviceLayer, "Failed to remove preference [%s]: %s", StringOrNullMarker(key), get_error_message(err));
return CHIP_ERROR_INCORRECT_STATE;
if (err != PREFERENCE_ERROR_NO_KEY)
ChipLogError(DeviceLayer, "Failed to remove preference [%s]: %s", StringOrNullMarker(key), get_error_message(err));
return TizenToChipError(err);
}

ChipLogProgress(DeviceLayer, "Remove preference data: key=%s", key);
Expand Down
276 changes: 150 additions & 126 deletions src/platform/Tizen/BLEManagerImpl.cpp

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/platform/Tizen/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ class BLEManagerImpl final : public BLEManager,
void NotifySubscribeOpComplete(BLE_CONNECTION_OBJECT conId, bool isSubscribed);
void NotifyBLENotificationReceived(System::PacketBufferHandle & buf, BLE_CONNECTION_OBJECT conId);

int RegisterGATTServer();
int StartBLEAdvertising();
int StopBLEAdvertising();
CHIP_ERROR RegisterGATTServer();
CHIP_ERROR StartBLEAdvertising();
CHIP_ERROR StopBLEAdvertising();
void CleanScanConfig();

CHIPoBLEServiceMode mServiceMode;
Expand Down
2 changes: 2 additions & 0 deletions src/platform/Tizen/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ static_library("Tizen") {
"DeviceInstanceInfoProviderImpl.h",
"DiagnosticDataProviderImpl.cpp",
"DiagnosticDataProviderImpl.h",
"ErrorUtils.cpp",
"ErrorUtils.h",
"InetPlatformConfig.h",
"KeyValueStoreManagerImpl.cpp",
"KeyValueStoreManagerImpl.h",
Expand Down
22 changes: 10 additions & 12 deletions src/platform/Tizen/ChipDeviceScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,35 +173,33 @@ static bool __IsScanFilterSupported()
return is_supported;
}

void ChipDeviceScanner::CheckScanFilter(ScanFilterType filterType, ScanFilterData & filterData)
int ChipDeviceScanner::SetupScanFilter(ScanFilterType filterType, const ScanFilterData & filterData)
{
int ret = BT_ERROR_NONE;

// Scan Filter check
if (!__IsScanFilterSupported())
return;
VerifyOrReturnValue(__IsScanFilterSupported(), BT_ERROR_NONE, ChipLogError(DeviceLayer, "BLE scan filter not supported"));

ret = CreateLEScanFilter(filterType, filterData);
int ret = CreateLEScanFilter(filterType);
VerifyOrExit(ret == BT_ERROR_NONE,
ChipLogError(DeviceLayer, "BLE scan filter creation failed: %s. Do Normal Scan", get_error_message(ret)));

ret = RegisterScanFilter(filterType, filterData);
VerifyOrExit(ret == BT_ERROR_NONE,
ChipLogError(DeviceLayer, "BLE scan filter registration failed: %s. Do Normal Scan", get_error_message(ret)));

return;
return ret;

exit:
UnRegisterScanFilter();
return ret;
}

CHIP_ERROR ChipDeviceScanner::StartChipScan(System::Clock::Timeout timeout, ScanFilterType filterType, ScanFilterData & filterData)
CHIP_ERROR ChipDeviceScanner::StartChipScan(System::Clock::Timeout timeout, ScanFilterType filterType,
const ScanFilterData & filterData)
{
CHIP_ERROR err = CHIP_NO_ERROR;
ReturnErrorCodeIf(mIsScanning, CHIP_ERROR_INCORRECT_STATE);

// Scan Filter Setup if supported: silently bypass error & do filterless scan in case of error
CheckScanFilter(filterType, filterData);
SetupScanFilter(filterType, filterData);

mScanTimeoutMs = System::Clock::Milliseconds32(timeout).count();

Expand Down Expand Up @@ -251,7 +249,7 @@ void ChipDeviceScanner::UnRegisterScanFilter()
}
}

int ChipDeviceScanner::RegisterScanFilter(ScanFilterType filterType, ScanFilterData & filterData)
int ChipDeviceScanner::RegisterScanFilter(ScanFilterType filterType, const ScanFilterData & filterData)
{
int ret = BT_ERROR_NONE;

Expand Down Expand Up @@ -293,7 +291,7 @@ int ChipDeviceScanner::RegisterScanFilter(ScanFilterType filterType, ScanFilterD
return ret;
}

int ChipDeviceScanner::CreateLEScanFilter(ScanFilterType filterType, ScanFilterData & filterData)
int ChipDeviceScanner::CreateLEScanFilter(ScanFilterType filterType)
{
int ret = bt_adapter_le_scan_filter_create(&mScanFilter);
VerifyOrExit(ret == BT_ERROR_NONE,
Expand Down
11 changes: 6 additions & 5 deletions src/platform/Tizen/ChipDeviceScanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ChipDeviceScanner
~ChipDeviceScanner(void);

/// Initiate a scan for devices, with the given timeout & scan filter data
CHIP_ERROR StartChipScan(System::Clock::Timeout timeout, ScanFilterType filterType, ScanFilterData & filterData);
CHIP_ERROR StartChipScan(System::Clock::Timeout timeout, ScanFilterType filterType, const ScanFilterData & filterData);

/// Stop any currently running scan
CHIP_ERROR StopChipScan(void);
Expand All @@ -99,10 +99,11 @@ class ChipDeviceScanner
static void LeScanResultCb(int result, bt_adapter_le_device_scan_result_info_s * info, void * userData);
static gboolean TimerExpiredCb(gpointer user_data);
static CHIP_ERROR TriggerScan(ChipDeviceScanner * userData);
void CheckScanFilter(ScanFilterType filterType, ScanFilterData & filterData);
int RegisterScanFilter(ScanFilterType filterType, ScanFilterData & filterData);
void UnRegisterScanFilter(void);
int CreateLEScanFilter(ScanFilterType filterType, ScanFilterData & filterData);

int CreateLEScanFilter(ScanFilterType filterType);
int RegisterScanFilter(ScanFilterType filterType, const ScanFilterData & filterData);
int SetupScanFilter(ScanFilterType filterType, const ScanFilterData & filterData);
void UnRegisterScanFilter();

ChipDeviceScannerDelegate * mDelegate = nullptr;
bool mIsScanning = false;
Expand Down
Loading

0 comments on commit 1582d8c

Please sign in to comment.