Skip to content

Commit

Permalink
[Tizen] Report errors using error level logging (#18888)
Browse files Browse the repository at this point in the history
* Run clang-tidy on Tizen: modernize-use-nullptr

* Run clang-tidy on Tizen with all checks

* Report errors using error level logging
  • Loading branch information
arkq authored and pull[bot] committed Jul 12, 2023
1 parent 5328843 commit 3965347
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 92 deletions.
56 changes: 28 additions & 28 deletions src/platform/Tizen/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ gboolean BLEManagerImpl::_BleInitialize(void * userData)
ret = bt_initialize();
VerifyOrExit(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "bt_initialize() failed. ret: %d", ret));

ret = bt_adapter_set_state_changed_cb(__AdapterStateChangedCb, NULL);
ret = bt_adapter_set_state_changed_cb(__AdapterStateChangedCb, nullptr);
VerifyOrExit(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "bt_adapter_set_state_changed_cb() failed. ret: %d", ret));

ret = bt_gatt_server_initialize();
VerifyOrExit(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "bt_gatt_server_initialize() failed. ret: %d", ret));

ret = bt_gatt_set_connection_state_changed_cb(GattConnectionStateChangedCb, NULL);
ret = bt_gatt_set_connection_state_changed_cb(GattConnectionStateChangedCb, nullptr);
VerifyOrExit(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "bt_adapter_set_state_changed_cb() failed. ret: %d", ret));

sInstance.InitConnectionData();
Expand Down Expand Up @@ -143,15 +143,15 @@ static const char * __ConvertAttTypeToStr(int type)
case BT_GATT_TYPE_DESCRIPTOR:
return "Descriptor";
default:
return NULL;
return nullptr;
}
}

static void __ReadValueRequestedCb(const char * remoteAddress, int requestId, bt_gatt_server_h server, bt_gatt_h gattHandle,
int offset, void * userData)
{
int ret, len = 0, type = 0;
char *value = NULL, *uuid = NULL;
char *value = nullptr, *uuid = nullptr;

__GetAttInfo(gattHandle, &uuid, &type);
ChipLogProgress(DeviceLayer, "Read Requested on %s(%s)", __ConvertAttTypeToStr(type), uuid);
Expand All @@ -171,7 +171,7 @@ void BLEManagerImpl::WriteValueRequestedCb(const char * remoteAddress, int reque
bool responseNeeded, int offset, const char * value, int len, void * userData)
{
int ret, type = 0;
char * uuid = NULL;
char * uuid = nullptr;
BLEConnection * conn = nullptr;

conn = static_cast<BLEConnection *>(g_hash_table_lookup(sInstance.mConnectionMap, remoteAddress));
Expand All @@ -187,7 +187,7 @@ void BLEManagerImpl::WriteValueRequestedCb(const char * remoteAddress, int reque
ret = bt_gatt_set_value(gattHandle, value, len);
VerifyOrReturn(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "bt_gatt_set_value() failed. ret: %d", ret));

ret = bt_gatt_server_send_response(requestId, BT_GATT_REQUEST_TYPE_WRITE, offset, 0x00, NULL, 0);
ret = bt_gatt_server_send_response(requestId, BT_GATT_REQUEST_TYPE_WRITE, offset, 0x00, nullptr, 0);
VerifyOrReturn(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "bt_gatt_server_send_response() failed. ret: %d", ret));

sInstance.HandleC1CharWriteEvent(conn, (const uint8_t *) value, len);
Expand All @@ -196,7 +196,7 @@ void BLEManagerImpl::WriteValueRequestedCb(const char * remoteAddress, int reque
void BLEManagerImpl::NotificationStateChangedCb(bool notify, bt_gatt_server_h server, bt_gatt_h gattHandle, void * userData)
{
int type = 0;
char * uuid = NULL;
char * uuid = nullptr;
BLEConnection * conn = nullptr;
GHashTableIter iter;
gpointer key, value;
Expand Down Expand Up @@ -504,10 +504,10 @@ int BLEManagerImpl::RegisterGATTServer()
{
int ret = BT_ERROR_NONE;

bt_gatt_server_h server = NULL;
bt_gatt_h service = NULL;
bt_gatt_h char1 = NULL, char2 = NULL;
bt_gatt_h desc = NULL;
bt_gatt_server_h server = nullptr;
bt_gatt_h service = nullptr;
bt_gatt_h char1 = nullptr, char2 = nullptr;
bt_gatt_h desc = nullptr;
char desc_value[2] = { 0, 0 };

ChipLogProgress(DeviceLayer, "Start GATT Service Registration");
Expand All @@ -529,7 +529,7 @@ int BLEManagerImpl::RegisterGATTServer()
"CHIPoBLE_C1", strlen("CHIPoBLE_C1"), &char1);

VerifyOrExit(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "bt_gatt_characteristic_create() failed. ret: %d", ret));
ret = bt_gatt_server_set_write_value_requested_cb(char1, WriteValueRequestedCb, NULL);
ret = bt_gatt_server_set_write_value_requested_cb(char1, WriteValueRequestedCb, nullptr);
VerifyOrExit(ret == BT_ERROR_NONE,
ChipLogError(DeviceLayer, "bt_gatt_server_set_write_value_requested_cb() failed. ret: %d", ret));
ret = bt_gatt_service_add_characteristic(service, char1);
Expand All @@ -541,10 +541,10 @@ int BLEManagerImpl::RegisterGATTServer()
&char2);

VerifyOrExit(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "bt_gatt_characteristic_create() failed. ret: %d", ret));
ret = bt_gatt_server_set_read_value_requested_cb(char2, __ReadValueRequestedCb, NULL);
ret = bt_gatt_server_set_read_value_requested_cb(char2, __ReadValueRequestedCb, nullptr);
VerifyOrExit(ret == BT_ERROR_NONE,
ChipLogError(DeviceLayer, "bt_gatt_server_set_read_value_requested_cb() failed. ret: %d", ret));
ret = bt_gatt_server_set_characteristic_notification_state_change_cb(char2, NotificationStateChangedCb, NULL);
ret = bt_gatt_server_set_characteristic_notification_state_change_cb(char2, NotificationStateChangedCb, nullptr);
VerifyOrExit(
ret == BT_ERROR_NONE,
ChipLogError(DeviceLayer, "bt_gatt_server_set_characteristic_notification_state_change_cb() failed. ret: %d", ret));
Expand Down Expand Up @@ -600,7 +600,7 @@ int BLEManagerImpl::StartAdvertising()

ChipLogProgress(DeviceLayer, "Start Advertising");

if (mAdvertiser == NULL)
if (mAdvertiser == nullptr)
{
ret = bt_adapter_le_create_advertiser(&mAdvertiser);
VerifyOrExit(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "bt_adapter_le_create_advertiser() failed. ret: %d", ret));
Expand Down Expand Up @@ -641,7 +641,7 @@ int BLEManagerImpl::StartAdvertising()

BLEManagerImpl::NotifyBLEPeripheralAdvConfiguredComplete(true, nullptr);

ret = bt_adapter_le_start_advertising_new(mAdvertiser, AdvertisingStateChangedCb, NULL);
ret = bt_adapter_le_start_advertising_new(mAdvertiser, AdvertisingStateChangedCb, nullptr);
VerifyOrExit(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "bt_adapter_le_start_advertising_new() failed. ret: %d", ret));
sInstance.mAdvReqInProgress = true;
return ret;
Expand Down Expand Up @@ -679,7 +679,7 @@ void BLEManagerImpl::InitConnectionData(void)
static bool __GattClientForeachCharCb(int total, int index, bt_gatt_h charHandle, void * data)
{
int type;
char * uuid = NULL;
char * uuid = nullptr;
auto conn = static_cast<BLEConnection *>(data);

if (__GetAttInfo(charHandle, &uuid, &type) == BT_ERROR_NONE)
Expand All @@ -703,7 +703,7 @@ static bool __GattClientForeachCharCb(int total, int index, bt_gatt_h charHandle
static bool __GattClientForeachServiceCb(int total, int index, bt_gatt_h svcHandle, void * data)
{
int type;
char * uuid = NULL;
char * uuid = nullptr;
auto conn = static_cast<BLEConnection *>(data);
ChipLogProgress(DeviceLayer, "__GattClientForeachServiceCb");

Expand Down Expand Up @@ -743,7 +743,7 @@ void BLEManagerImpl::AddConnectionData(const char * remoteAddr)

if (!g_hash_table_lookup(mConnectionMap, remoteAddr))
{
ChipLogProgress(DeviceLayer, "Not Found in Map");
ChipLogProgress(DeviceLayer, "Connection not found in map [%s]", remoteAddr);
conn = static_cast<BLEConnection *>(g_malloc0(sizeof(BLEConnection)));
conn->peerAddr = g_strdup(remoteAddr);

Expand Down Expand Up @@ -782,10 +782,10 @@ void BLEManagerImpl::RemoveConnectionData(const char * remoteAddr)
BLEConnection * conn = nullptr;
ChipLogProgress(DeviceLayer, "Connection Remove Request for [%s]", remoteAddr);

VerifyOrReturn(mConnectionMap != nullptr, ChipLogError(DeviceLayer, "connection map does not exist"));
VerifyOrReturn(mConnectionMap != nullptr, ChipLogError(DeviceLayer, "Connection map does not exist"));

conn = static_cast<BLEConnection *>(g_hash_table_lookup(mConnectionMap, remoteAddr));
VerifyOrReturn(conn != nullptr, ChipLogError(DeviceLayer, "connection does not exist for [%s]", remoteAddr));
VerifyOrReturn(conn != nullptr, ChipLogError(DeviceLayer, "Connection does not exist for [%s]", remoteAddr));

g_hash_table_remove(mConnectionMap, conn->peerAddr);

Expand Down Expand Up @@ -889,7 +889,7 @@ void BLEManagerImpl::DriveBLEState()

ret = bt_adapter_le_destroy_advertiser(mAdvertiser);
VerifyOrExit(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "bt_adapter_le_destroy_advertiser() failed. ret: %d", ret));
mAdvertiser = NULL;
mAdvertiser = nullptr;
}

exit:
Expand Down Expand Up @@ -970,9 +970,9 @@ CHIP_ERROR BLEManagerImpl::_GetDeviceName(char * buf, size_t bufSize)
{
CHIP_ERROR err = CHIP_NO_ERROR;
int ret;
char * deviceName = NULL;
char * deviceName = nullptr;

VerifyOrExit(buf != NULL, err = CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrExit(buf != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT);

ret = bt_adapter_get_name(&deviceName);
if (ret != BT_ERROR_NONE)
Expand All @@ -981,7 +981,7 @@ CHIP_ERROR BLEManagerImpl::_GetDeviceName(char * buf, size_t bufSize)
return CHIP_ERROR_INTERNAL;
}

VerifyOrExit(deviceName != NULL, err = CHIP_ERROR_INTERNAL);
VerifyOrExit(deviceName != nullptr, err = CHIP_ERROR_INTERNAL);
VerifyOrExit(strlen(deviceName) >= bufSize, err = CHIP_ERROR_BUFFER_TOO_SMALL);

g_strlcpy(buf, deviceName, bufSize);
Expand All @@ -996,7 +996,7 @@ CHIP_ERROR BLEManagerImpl::_SetDeviceName(const char * deviceName)
CHIP_ERROR err = CHIP_NO_ERROR;
int ret;

VerifyOrExit(deviceName != NULL, err = CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrExit(deviceName != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT);

ret = bt_adapter_set_name(deviceName);
if (ret != BT_ERROR_NONE)
Expand Down Expand Up @@ -1248,7 +1248,7 @@ bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const ChipBleUU
ChipLogProgress(DeviceLayer, "Sending indication for CHIPoBLE RX characteristic (con %s, len %u)", conn->peerAddr,
pBuf->DataLength());

ret = bt_gatt_server_notify_characteristic_changed_value(mGattCharC2Handle, IndicationConfirmationCb, conn->peerAddr, NULL);
ret = bt_gatt_server_notify_characteristic_changed_value(mGattCharC2Handle, IndicationConfirmationCb, conn->peerAddr, nullptr);
VerifyOrExit(ret == BT_ERROR_NONE,
ChipLogError(DeviceLayer, "bt_gatt_server_notify_characteristic_changed_value() failed. ret: %d", ret));
return true;
Expand Down Expand Up @@ -1318,7 +1318,7 @@ void BLEManagerImpl::InitiateScan(BleScanState scanType)
{
CHIP_ERROR err = CHIP_NO_ERROR;
ScanFilterData data = {
0x0,
{ 0x0 },
};

ChipLogProgress(DeviceLayer, "Initiate Scan");
Expand Down
7 changes: 5 additions & 2 deletions src/platform/Tizen/ChipDeviceScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ static bool __IsChipThingDevice(bt_adapter_le_device_scan_result_info_s * info,
if (!info)
return false;

ChipLogError(DeviceLayer, "Is [%s] ChipThingDevice ?: Check now", info->remote_address);
ChipLogProgress(DeviceLayer, "Is [%s] ChipThingDevice ?: Check now", info->remote_address);

if (bt_adapter_le_get_scan_result_service_data_list(info, BT_ADAPTER_LE_PACKET_ADVERTISING, &dataList, &count) == BT_ERROR_NONE)
{
Expand Down Expand Up @@ -239,7 +239,10 @@ CHIP_ERROR ChipDeviceScanner::StopChipScan(void)
ReturnErrorCodeIf(!mIsScanning, CHIP_ERROR_INCORRECT_STATE);

ret = bt_adapter_le_stop_scan();
ChipLogError(DeviceLayer, "bt_adapter_le_stop_scan() ret: %d", ret);
if (ret != BT_ERROR_NONE)
{
ChipLogError(DeviceLayer, "bt_adapter_le_stop_scan() failed. ret: %d", ret);
}

g_main_loop_quit(mAsyncLoop);
ChipLogProgress(DeviceLayer, "CHIP Scanner Async Thread Quit Done..Wait for Thread Windup...!");
Expand Down
4 changes: 2 additions & 2 deletions src/platform/Tizen/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ void ConnectivityManagerImpl::_SetWiFiAPIdleTimeout(System::Clock::Timeout val)

void ConnectivityManagerImpl::StartWiFiManagement(void)
{
SystemLayer().ScheduleWork(ActivateWiFiManager, NULL);
SystemLayer().ScheduleWork(ActivateWiFiManager, nullptr);
}

void ConnectivityManagerImpl::StopWiFiManagement(void)
{
SystemLayer().ScheduleWork(DeactivateWiFiManager, NULL);
SystemLayer().ScheduleWork(DeactivateWiFiManager, nullptr);
}

void ConnectivityManagerImpl::ActivateWiFiManager(::chip::System::Layer * aLayer, void * aAppState)
Expand Down
6 changes: 3 additions & 3 deletions src/platform/Tizen/DnssdImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void OnRegister(dnssd_error_e error, dnssd_service_h service, void * data)

g_main_loop_quit(loop);

VerifyOrReturn(CheckForSuccess(rCtx, (int) error, __func__));
VerifyOrReturn(CheckForSuccess(rCtx, static_cast<int>(error), __func__));
rCtx->isRegistered = true;
ChipLogDetail(DeviceLayer, "Dnssd: %s name: %s, type: %s, port: %u, interfaceId: %u", __func__, rCtx->name, rCtx->type,
rCtx->port, rCtx->interfaceId);
Expand Down Expand Up @@ -319,7 +319,7 @@ gboolean BrowseAsync(GMainLoop * mainLoop, gpointer userData)
dnssd_browser_h browser;
if (interfaceId == 0)
{
ret = dnssd_browse_service(bCtx->type, NULL, &browser, OnBrowse, bCtx);
ret = dnssd_browse_service(bCtx->type, nullptr, &browser, OnBrowse, bCtx);
}
else
{
Expand Down Expand Up @@ -500,7 +500,7 @@ CHIP_ERROR Resolve(uint32_t interfaceId, const char * type, const char * name, D

if (interfaceId == 0)
{
ret = dnssd_create_remote_service(type, name, NULL, &service);
ret = dnssd_create_remote_service(type, name, nullptr, &service);
}
else
{
Expand Down
22 changes: 11 additions & 11 deletions src/platform/Tizen/MainLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ gboolean MainLoop::ThreadTimeout(gpointer userData)
{
LoopData * loopData = reinterpret_cast<LoopData *>(userData);

VerifyOrReturnError(loopData != NULL, G_SOURCE_REMOVE);
VerifyOrReturnError(loopData != nullptr, G_SOURCE_REMOVE);

if (loopData->mTimeoutFn)
{
Expand All @@ -50,10 +50,10 @@ gboolean MainLoop::ThreadTimeout(gpointer userData)

void MainLoop::SetThreadTimeout(LoopData * loopData, guint interval)
{
VerifyOrReturn(loopData != NULL);
VerifyOrReturn(loopData != nullptr);

GSource * source = g_timeout_source_new_seconds(interval);
g_source_set_callback(source, ThreadTimeout, reinterpret_cast<gpointer>(loopData), NULL);
g_source_set_callback(source, ThreadTimeout, reinterpret_cast<gpointer>(loopData), nullptr);
g_source_attach(source, loopData->mMainContext);
g_source_unref(source);
}
Expand All @@ -69,14 +69,14 @@ gpointer MainLoop::ThreadMainHandler(gpointer data)
g_main_loop_run(loopData->mMainLoop);
ChipLogProgress(DeviceLayer, "[QUIT] main loop %p", loopData->mMainLoop);
g_main_loop_unref(loopData->mMainLoop);
loopData->mMainLoop = NULL;
loopData->mMainLoop = nullptr;

g_main_context_pop_thread_default(loopData->mMainContext);
ChipLogProgress(DeviceLayer, "[POP] main context %p", loopData->mMainContext);
g_main_context_unref(loopData->mMainContext);
loopData->mMainContext = NULL;
loopData->mMainContext = nullptr;

return NULL;
return nullptr;
}

gpointer MainLoop::ThreadAsyncHandler(gpointer data)
Expand All @@ -90,24 +90,24 @@ gpointer MainLoop::ThreadAsyncHandler(gpointer data)
g_main_loop_run(loopData->mMainLoop);
ChipLogProgress(DeviceLayer, "[QUIT] async loop %p", loopData->mMainLoop);
g_main_loop_unref(loopData->mMainLoop);
loopData->mMainLoop = NULL;
loopData->mMainLoop = nullptr;

g_main_context_pop_thread_default(loopData->mMainContext);
ChipLogProgress(DeviceLayer, "[POP] async context %p", loopData->mMainContext);
g_main_context_unref(loopData->mMainContext);
loopData->mMainContext = NULL;
loopData->mMainContext = nullptr;

chip::Platform::Delete(loopData);

return NULL;
return nullptr;
}

bool MainLoop::Init(initFn_t initFn, gpointer userData)
{
bool result;
LoopData * loopData = chip::Platform::New<LoopData>();

VerifyOrReturnError(loopData != NULL, false);
VerifyOrReturnError(loopData != nullptr, false);

loopData->mMainContext = g_main_context_new();
loopData->mMainLoop = g_main_loop_new(loopData->mMainContext, FALSE);
Expand Down Expand Up @@ -157,7 +157,7 @@ bool MainLoop::AsyncRequest(asyncFn_t asyncFn, gpointer asyncUserData, guint int
bool result = false;
LoopData * loopData = chip::Platform::New<LoopData>();

VerifyOrReturnError(loopData != NULL, false);
VerifyOrReturnError(loopData != nullptr, false);

loopData->mMainContext = g_main_context_new();
loopData->mMainLoop = g_main_loop_new(loopData->mMainContext, FALSE);
Expand Down
2 changes: 1 addition & 1 deletion src/platform/Tizen/NetworkCommissioningWiFiDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ bool TizenWiFiDriver::NetworkMatch(const WiFiNetwork & network, ByteSpan network
networkId.size());
return false;
}
else if (memcmp(networkId.data(), network.ssid, network.ssidLen) != 0)
if (memcmp(networkId.data(), network.ssid, network.ssidLen) != 0)
{
ChipLogProgress(NetworkProvisioning, "ssid is mismatched. network.ssid: %s, networkId.data(): %s", network.ssid,
networkId.data());
Expand Down
4 changes: 2 additions & 2 deletions src/platform/Tizen/ThreadStackManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ CHIP_ERROR ThreadStackManagerImpl::_InitThreadStack()
ThreadDeviceRoleChangedHandler(deviceRole);

/* Set callback for change of device role */
threadErr = thread_set_device_role_changed_cb(mThreadInstance, _ThreadDeviceRoleChangedCb, NULL);
threadErr = thread_set_device_role_changed_cb(mThreadInstance, _ThreadDeviceRoleChangedCb, nullptr);
VerifyOrExit(threadErr == THREAD_ERROR_NONE, ChipLogError(DeviceLayer, "FAIL: set device role changed cb"));

mIsInitialized = true;
Expand Down Expand Up @@ -564,7 +564,7 @@ CHIP_ERROR ThreadStackManagerImpl::_SetupSrpHost(const char * aHostName)
ChipLogError(DeviceLayer, "FAIL: thread_srp_client_set_host_name");

/* Get external ip address */
threadErr = thread_get_ipaddr(mThreadInstance, _ThreadIpAddressCb, THREAD_IPADDR_TYPE_MLEID, NULL);
threadErr = thread_get_ipaddr(mThreadInstance, _ThreadIpAddressCb, THREAD_IPADDR_TYPE_MLEID, nullptr);
VerifyOrExit(threadErr == THREAD_ERROR_NONE, error = CHIP_ERROR_INTERNAL);

return CHIP_NO_ERROR;
Expand Down
Loading

0 comments on commit 3965347

Please sign in to comment.