Skip to content

Commit

Permalink
Make CHIP_ERROR a class type on cc13x2_26x2, EFR32, QPG. (#8446)
Browse files Browse the repository at this point in the history
#### Problem

Having CHIP_ERROR be a class type would provide (a) type safety,
and (b) the ability to trace the source of errors (issue #8340).

#### Change overview

- Enable `CHIP_CONFIG_ERROR_CLASS` on cc13x2_26x2, EFR32, QPG.

- Remove `operator bool()` (requested in #8383 review).

#### Testing

Existing tests should confirm no change to functionality.
  • Loading branch information
kpschoedel authored and pull[bot] committed Aug 26, 2021
1 parent fae5b07 commit da8f6c2
Show file tree
Hide file tree
Showing 38 changed files with 94 additions and 61 deletions.
3 changes: 3 additions & 0 deletions examples/lighting-app/efr32/include/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,7 @@ void appError(int err);

#ifdef __cplusplus
}

#include <core/CHIPError.h>
void appError(CHIP_ERROR error);
#endif
4 changes: 3 additions & 1 deletion examples/lighting-app/efr32/include/LightingManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "FreeRTOS.h"
#include "timers.h" // provides FreeRTOS timer support

#include <core/CHIPError.h>

class LightingManager
{
public:
Expand All @@ -45,7 +47,7 @@ class LightingManager
kState_OnCompleted,
} State;

int Init();
CHIP_ERROR Init();
bool IsLightOn();
void EnableAutoTurnOff(bool aOn);
void SetAutoTurnOffDuration(uint32_t aDurationInSecs);
Expand Down
3 changes: 1 addition & 2 deletions examples/lighting-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,9 @@ CHIP_ERROR AppTask::Init()

void AppTask::AppTaskMain(void * pvParameter)
{
int err;
AppEvent event;

err = sAppTask.Init();
CHIP_ERROR err = sAppTask.Init();
if (err != CHIP_NO_ERROR)
{
EFR32_LOG("AppTask.Init() failed");
Expand Down
4 changes: 2 additions & 2 deletions examples/lighting-app/efr32/src/LightingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ LightingManager LightingManager::sLight;

TimerHandle_t sLightTimer;

int LightingManager::Init()
CHIP_ERROR LightingManager::Init()
{
// Create FreeRTOS sw timer for light timer.
sLightTimer = xTimerCreate("lightTmr", // Just a text name, not used by the RTOS kernel
Expand All @@ -40,7 +40,7 @@ int LightingManager::Init()
if (sLightTimer == NULL)
{
EFR32_LOG("sLightTimer timer create failed");
appError(APP_ERROR_CREATE_TIMER_FAILED);
return APP_ERROR_CREATE_TIMER_FAILED;
}

mState = kState_OffCompleted;
Expand Down
5 changes: 5 additions & 0 deletions examples/lighting-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ void appError(int err)
;
}

void appError(CHIP_ERROR error)
{
appError(static_cast<int>(chip::ChipError::AsInteger(error)));
}

// ================================================================================
// FreeRTOS Callbacks
// ================================================================================
Expand Down
4 changes: 2 additions & 2 deletions examples/lighting-app/qpg/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class AppTask
{

public:
int StartAppTask();
CHIP_ERROR StartAppTask();
static void AppTaskMain(void * pvParameter);

void PostLightActionRequest(int32_t aActor, LightingManager::Action_t aAction);
Expand All @@ -48,7 +48,7 @@ class AppTask
private:
friend AppTask & GetAppTask(void);

int Init();
CHIP_ERROR Init();

static void ActionInitiated(LightingManager::Action_t aAction);
static void ActionCompleted(LightingManager::Action_t aAction);
Expand Down
4 changes: 3 additions & 1 deletion examples/lighting-app/qpg/include/LightingManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "FreeRTOS.h"
#include "timers.h" // provides FreeRTOS timer support

#include <core/CHIPError.h>

class LightingManager
{
public:
Expand All @@ -45,7 +47,7 @@ class LightingManager
kState_Off,
} State;

int Init();
CHIP_ERROR Init();
bool IsTurnedOn();
uint8_t GetLevel();
bool InitiateAction(Action_t aAction, int32_t aActor, uint16_t size, uint8_t * value);
Expand Down
9 changes: 4 additions & 5 deletions examples/lighting-app/qpg/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static bool sHaveServiceConnectivity = false;

AppTask AppTask::sAppTask;

int AppTask::StartAppTask()
CHIP_ERROR AppTask::StartAppTask()
{
sAppEventQueue = xQueueCreate(APP_EVENT_QUEUE_SIZE, sizeof(AppEvent));
if (sAppEventQueue == NULL)
Expand All @@ -78,7 +78,7 @@ int AppTask::StartAppTask()
return CHIP_NO_ERROR;
}

int AppTask::Init()
CHIP_ERROR AppTask::Init()
{
CHIP_ERROR err = CHIP_NO_ERROR;

Expand Down Expand Up @@ -111,13 +111,12 @@ int AppTask::Init()

void AppTask::AppTaskMain(void * pvParameter)
{
int err;
AppEvent event;

err = sAppTask.Init();
CHIP_ERROR err = sAppTask.Init();
if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "AppTask.Init() failed");
ChipLogError(NotSpecified, "AppTask.Init() failed: %" CHIP_ERROR_FORMAT, chip::ChipError::FormatError(err));
// appError(err);
}

Expand Down
4 changes: 2 additions & 2 deletions examples/lighting-app/qpg/src/LightingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

LightingManager LightingManager::sLight;

int LightingManager::Init()
CHIP_ERROR LightingManager::Init()
{
mState = kState_Off;
mLevel = 64;
return 0;
return CHIP_NO_ERROR;
}

bool LightingManager::IsTurnedOn()
Expand Down
4 changes: 2 additions & 2 deletions examples/lock-app/cc13x2x7_26x2x7/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ int main(void)

SHA2_init();

CHIP_ERROR ret = GetAppTask().StartAppTask();
if (ret != CHIP_NO_ERROR)
int ret = GetAppTask().StartAppTask();
if (ret != 0)
{
// can't log until the kernel is started
// PLAT_LOG("GetAppTask().StartAppTask() failed");
Expand Down
3 changes: 3 additions & 0 deletions examples/lock-app/efr32/include/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,7 @@ void appError(int err);

#ifdef __cplusplus
}

#include <core/CHIPError.h>
void appError(CHIP_ERROR error);
#endif
4 changes: 3 additions & 1 deletion examples/lock-app/efr32/include/BoltLockManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "FreeRTOS.h"
#include "timers.h" // provides FreeRTOS timer support

#include <core/CHIPError.h>

class BoltLockManager
{
public:
Expand All @@ -45,7 +47,7 @@ class BoltLockManager
kState_UnlockingCompleted,
} State;

int Init();
CHIP_ERROR Init();
bool IsUnlocked();
void EnableAutoRelock(bool aOn);
void SetAutoLockDuration(uint32_t aDurationInSecs);
Expand Down
11 changes: 4 additions & 7 deletions examples/lock-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ CHIP_ERROR AppTask::StartAppTask()

CHIP_ERROR AppTask::Init()
{
CHIP_ERROR err = CHIP_NO_ERROR;

// Init ZCL Data Model
InitServer();

Expand All @@ -108,11 +106,11 @@ CHIP_ERROR AppTask::Init()
if (sFunctionTimer == NULL)
{
EFR32_LOG("funct timer create failed");
appError(err);
appError(APP_ERROR_CREATE_TIMER_FAILED);
}

EFR32_LOG("Current Firmware Version: %s", CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION_STRING);
err = BoltLockMgr().Init();
CHIP_ERROR err = BoltLockMgr().Init();
if (err != CHIP_NO_ERROR)
{
EFR32_LOG("BoltLockMgr().Init() failed");
Expand Down Expand Up @@ -152,10 +150,9 @@ CHIP_ERROR AppTask::Init()

void AppTask::AppTaskMain(void * pvParameter)
{
int err;
AppEvent event;

err = sAppTask.Init();
CHIP_ERROR err = sAppTask.Init();
if (err != CHIP_NO_ERROR)
{
EFR32_LOG("AppTask.Init() failed");
Expand Down Expand Up @@ -231,7 +228,7 @@ void AppTask::LockActionEventHandler(AppEvent * aEvent)
bool initiated = false;
BoltLockManager::Action_t action;
int32_t actor;
int err = CHIP_NO_ERROR;
CHIP_ERROR err = CHIP_NO_ERROR;

if (aEvent->Type == AppEvent::kEventType_Lock)
{
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/efr32/src/BoltLockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ BoltLockManager BoltLockManager::sLock;

TimerHandle_t sLockTimer;

int BoltLockManager::Init()
CHIP_ERROR BoltLockManager::Init()
{
// Create FreeRTOS sw timer for lock timer.
sLockTimer = xTimerCreate("lockTmr", // Just a text name, not used by the RTOS kernel
Expand Down
5 changes: 5 additions & 0 deletions examples/lock-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ void appError(int err)
;
}

void appError(CHIP_ERROR error)
{
appError(static_cast<int>(chip::ChipError::AsInteger(error)));
}

// ================================================================================
// FreeRTOS Callbacks
// ================================================================================
Expand Down
8 changes: 6 additions & 2 deletions examples/lock-app/qpg/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@
#include "FreeRTOS.h"
#include "timers.h" // provides FreeRTOS timer support
#include <ble/BLEEndPoint.h>
#include <core/CHIPError.h>
#include <platform/CHIPDeviceLayer.h>

// Application-defined error codes in the CHIP_ERROR space.
#define APP_ERROR_CREATE_TIMER_FAILED CHIP_APPLICATION_ERROR(0x01)

#define APP_NAME "Lock-app"
class AppTask
{

public:
int StartAppTask();
CHIP_ERROR StartAppTask();
static void AppTaskMain(void * pvParameter);

void PostLockActionRequest(int32_t aActor, BoltLockManager::Action_t aAction);
Expand All @@ -47,7 +51,7 @@ class AppTask
private:
friend AppTask & GetAppTask(void);

int Init();
CHIP_ERROR Init();

static void ActionInitiated(BoltLockManager::Action_t aAction, int32_t aActor);
static void ActionCompleted(BoltLockManager::Action_t aAction);
Expand Down
4 changes: 3 additions & 1 deletion examples/lock-app/qpg/include/BoltLockManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "FreeRTOS.h"
#include "timers.h" // provides FreeRTOS timer support

#include <core/CHIPError.h>

class BoltLockManager
{
public:
Expand All @@ -46,7 +48,7 @@ class BoltLockManager
kState_UnlockingCompleted,
} State;

int Init();
CHIP_ERROR Init();
bool IsUnlocked();
void EnableAutoRelock(bool aOn);
void SetAutoLockDuration(uint32_t aDurationInSecs);
Expand Down
11 changes: 5 additions & 6 deletions examples/lock-app/qpg/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static bool sHaveServiceConnectivity = false;

AppTask AppTask::sAppTask;

int AppTask::StartAppTask()
CHIP_ERROR AppTask::StartAppTask()
{
sAppEventQueue = xQueueCreate(APP_EVENT_QUEUE_SIZE, sizeof(AppEvent));
if (sAppEventQueue == NULL)
Expand All @@ -79,7 +79,7 @@ int AppTask::StartAppTask()
return CHIP_NO_ERROR;
}

int AppTask::Init()
CHIP_ERROR AppTask::Init()
{
CHIP_ERROR err = CHIP_NO_ERROR;

Expand Down Expand Up @@ -110,13 +110,12 @@ int AppTask::Init()

void AppTask::AppTaskMain(void * pvParameter)
{
int err;
AppEvent event;

err = sAppTask.Init();
CHIP_ERROR err = sAppTask.Init();
if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "AppTask.Init() failed");
ChipLogError(NotSpecified, "AppTask.Init() failed: %" CHIP_ERROR_FORMAT, chip::ChipError::FormatError(err));
// appError(err);
}

Expand Down Expand Up @@ -186,7 +185,7 @@ void AppTask::LockActionEventHandler(AppEvent * aEvent)
bool initiated = false;
BoltLockManager::Action_t action;
int32_t actor;
int err = CHIP_NO_ERROR;
CHIP_ERROR err = CHIP_NO_ERROR;

if (aEvent->Type == AppEvent::kEventType_Lock)
{
Expand Down
5 changes: 2 additions & 3 deletions examples/lock-app/qpg/src/BoltLockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ BoltLockManager BoltLockManager::sLock;

TimerHandle_t sLockTimer;

int BoltLockManager::Init()
CHIP_ERROR BoltLockManager::Init()
{
// Create FreeRTOS sw timer for lock timer.
sLockTimer = xTimerCreate("lockTmr", // Just a text name, not used by the RTOS kernel
Expand All @@ -40,8 +40,7 @@ int BoltLockManager::Init()
if (sLockTimer == NULL)
{
ChipLogProgress(NotSpecified, "sLockTimer timer create failed");
// TODO:
// appError(APP_ERROR_CREATE_TIMER_FAILED);
return APP_ERROR_CREATE_TIMER_FAILED;
}

mState = kState_LockingCompleted;
Expand Down
3 changes: 1 addition & 2 deletions examples/persistent-storage/KeyValueStorageTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ using namespace chip::DeviceLayer::PersistedStorage;
{ \
char error_str[255]; \
chip::FormatCHIPError(error_str, sizeof(error_str), temp_test_result); \
ChipLogError(NotSpecified, "%s: FAILED %" PRId32 " [%s]", #test_result, temp_test_result, \
chip::ErrorStr(temp_test_result)); \
ChipLogError(NotSpecified, "%s: FAILED [%s]", #test_result, chip::ErrorStr(temp_test_result)); \
} \
else \
{ \
Expand Down
Loading

0 comments on commit da8f6c2

Please sign in to comment.