Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure CHIP_ERROR numeric values #8179

Merged
merged 5 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/chip-tool/commands/tests/TestCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void TestCommand::OnDeviceConnectedFn(void * context, chip::Controller::Device *

void TestCommand::OnDeviceConnectionFailureFn(void * context, NodeId deviceId, CHIP_ERROR error)
{
ChipLogError(chipTool, "Failed in connecting to the device %" PRIu64 ". Error %d", deviceId, error);
ChipLogError(chipTool, "Failed in connecting to the device %" PRIu64 ". Error %" CHIP_ERROR_FORMAT, deviceId, error);
auto * command = static_cast<TestCommand *>(context);
VerifyOrReturn(command != nullptr, ChipLogError(chipTool, "Test command context is null"));
command->SetCommandExitStatus(error);
Expand Down
12 changes: 10 additions & 2 deletions examples/lighting-app/efr32/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,19 @@
#include <ble/BLEEndPoint.h>
#include <platform/CHIPDeviceLayer.h>

// Application-defined error codes in the CHIP_ERROR space.
#define APP_ERROR_EVENT_QUEUE_FAILED CHIP_APPLICATION_ERROR(0x01)
#define APP_ERROR_CREATE_TASK_FAILED CHIP_APPLICATION_ERROR(0x02)
#define APP_ERROR_UNHANDLED_EVENT CHIP_APPLICATION_ERROR(0x03)
#define APP_ERROR_CREATE_TIMER_FAILED CHIP_APPLICATION_ERROR(0x04)
#define APP_ERROR_START_TIMER_FAILED CHIP_APPLICATION_ERROR(0x05)
#define APP_ERROR_STOP_TIMER_FAILED CHIP_APPLICATION_ERROR(0x06)

class AppTask
{

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

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

int Init();
CHIP_ERROR Init();

static void ActionInitiated(LightingManager::Action_t aAction, int32_t aActor);
static void ActionCompleted(LightingManager::Action_t aAction);
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/efr32/include/Rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace rpc {

class LightingService;

int Init();
void Init();
void RunRpcService(void *);

} // namespace rpc
Expand Down
22 changes: 8 additions & 14 deletions examples/lighting-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,21 @@ using namespace ::chip::DeviceLayer;

AppTask AppTask::sAppTask;

int AppTask::StartAppTask()
CHIP_ERROR AppTask::StartAppTask()
{
int err = CHIP_CONFIG_CORE_ERROR_MAX;

sAppEventQueue = xQueueCreateStatic(APP_EVENT_QUEUE_SIZE, sizeof(AppEvent), sAppEventQueueBuffer, &sAppEventQueueStruct);
if (sAppEventQueue == NULL)
{
EFR32_LOG("Failed to allocate app event queue");
appError(err);
appError(APP_ERROR_EVENT_QUEUE_FAILED);
}

// Start App task.
sAppTaskHandle = xTaskCreateStatic(AppTaskMain, APP_TASK_NAME, ArraySize(appStack), NULL, 1, appStack, &appTaskStruct);
if (sAppTaskHandle != NULL)
{
err = CHIP_NO_ERROR;
}
return err;
return (sAppTaskHandle == nullptr) ? APP_ERROR_CREATE_TASK_FAILED : CHIP_NO_ERROR;
}

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

Expand Down Expand Up @@ -254,7 +248,7 @@ void AppTask::LightActionEventHandler(AppEvent * aEvent)
bool initiated = false;
LightingManager::Action_t action;
int32_t actor;
int err = CHIP_NO_ERROR;
CHIP_ERROR err = CHIP_NO_ERROR;

if (aEvent->Type == AppEvent::kEventType_Light)
{
Expand All @@ -275,7 +269,7 @@ void AppTask::LightActionEventHandler(AppEvent * aEvent)
}
else
{
err = CHIP_CONFIG_CORE_ERROR_MAX;
err = APP_ERROR_UNHANDLED_EVENT;
}

if (err == CHIP_NO_ERROR)
Expand Down Expand Up @@ -419,7 +413,7 @@ void AppTask::CancelTimer()
if (xTimerStop(sFunctionTimer, 0) == pdFAIL)
{
EFR32_LOG("app timer stop() failed");
appError(CHIP_CONFIG_CORE_ERROR_MAX);
appError(APP_ERROR_STOP_TIMER_FAILED);
}

mFunctionTimerActive = false;
Expand All @@ -439,7 +433,7 @@ void AppTask::StartTimer(uint32_t aTimeoutInMs)
if (xTimerChangePeriod(sFunctionTimer, aTimeoutInMs / portTICK_PERIOD_MS, 100) != pdPASS)
{
EFR32_LOG("app timer start() failed");
appError(CHIP_CONFIG_CORE_ERROR_MAX);
appError(APP_ERROR_START_TIMER_FAILED);
}

mFunctionTimerActive = true;
Expand Down
6 changes: 3 additions & 3 deletions examples/lighting-app/efr32/src/LightingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int LightingManager::Init()
if (sLightTimer == NULL)
{
EFR32_LOG("sLightTimer timer create failed");
appError(CHIP_CONFIG_CORE_ERROR_MAX);
appError(APP_ERROR_CREATE_TIMER_FAILED);
}

mState = kState_OffCompleted;
Expand Down Expand Up @@ -135,7 +135,7 @@ void LightingManager::StartTimer(uint32_t aTimeoutMs)
if (xTimerChangePeriod(sLightTimer, (aTimeoutMs / portTICK_PERIOD_MS), 100) != pdPASS)
{
EFR32_LOG("sLightTimer timer start() failed");
appError(CHIP_CONFIG_CORE_ERROR_MAX);
appError(APP_ERROR_START_TIMER_FAILED);
}
}

Expand All @@ -144,7 +144,7 @@ void LightingManager::CancelTimer(void)
if (xTimerStop(sLightTimer, 0) == pdFAIL)
{
EFR32_LOG("sLightTimer stop() failed");
appError(CHIP_CONFIG_CORE_ERROR_MAX);
appError(APP_ERROR_STOP_TIMER_FAILED);
}
}

Expand Down
4 changes: 1 addition & 3 deletions examples/lighting-app/efr32/src/Rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,13 @@ void RunRpcService(void *)
Start(RegisterServices, &logger_mutex);
}

int Init()
void Init()
{
int err = CHIP_CONFIG_CORE_ERROR_MAX;
pw_sys_io_Init();

// Start App task.
sRpcTaskHandle = xTaskCreateStatic(RunRpcService, "RPC_TASK", ArraySize(sRpcTaskStack), nullptr, RPC_TASK_PRIORITY,
sRpcTaskStack, &sRpcTaskBuffer);
return err;
}

} // namespace rpc
Expand Down
4 changes: 1 addition & 3 deletions examples/lighting-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ extern "C" void vApplicationIdleHook(void)
// ================================================================================
int main(void)
{
int ret = CHIP_CONFIG_CORE_ERROR_MAX;

init_efrPlatform();
mbedtls_platform_set_calloc_free(CHIPPlatformMemoryCalloc, CHIPPlatformMemoryFree);

Expand All @@ -125,7 +123,7 @@ int main(void)
chip::Platform::MemoryInit();
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init();

ret = PlatformMgr().InitChipStack();
CHIP_ERROR ret = PlatformMgr().InitChipStack();
if (ret != CHIP_NO_ERROR)
{
EFR32_LOG("PlatformMgr().InitChipStack() failed");
Expand Down
5 changes: 3 additions & 2 deletions examples/lighting-app/k32w/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int AppTask::StartAppTask()
sAppEventQueue = xQueueCreate(APP_EVENT_QUEUE_SIZE, sizeof(AppEvent));
if (sAppEventQueue == NULL)
{
err = CHIP_CONFIG_CORE_ERROR_MAX;
err = APP_ERROR_EVENT_QUEUE_FAILED;
K32W_LOG("Failed to allocate app event queue");
assert(err == CHIP_NO_ERROR);
}
Expand Down Expand Up @@ -113,6 +113,7 @@ int AppTask::Init()
);
if (sFunctionTimer == NULL)
{
err = APP_ERROR_CREATE_TIMER_FAILED;
K32W_LOG("app_timer_create() failed");
assert(err == CHIP_NO_ERROR);
}
Expand Down Expand Up @@ -408,7 +409,7 @@ void AppTask::LightActionEventHandler(AppEvent * aEvent)
}
else
{
err = CHIP_CONFIG_CORE_ERROR_MAX;
err = APP_ERROR_UNHANDLED_EVENT;
}

if (err == CHIP_NO_ERROR)
Expand Down
8 changes: 8 additions & 0 deletions examples/lighting-app/k32w/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
#include "FreeRTOS.h"
#include "timers.h"

// Application-defined error codes in the CHIP_ERROR space.
#define APP_ERROR_EVENT_QUEUE_FAILED CHIP_APPLICATION_ERROR(0x01)
#define APP_ERROR_CREATE_TASK_FAILED CHIP_APPLICATION_ERROR(0x02)
#define APP_ERROR_UNHANDLED_EVENT CHIP_APPLICATION_ERROR(0x03)
#define APP_ERROR_CREATE_TIMER_FAILED CHIP_APPLICATION_ERROR(0x04)
#define APP_ERROR_START_TIMER_FAILED CHIP_APPLICATION_ERROR(0x05)
#define APP_ERROR_STOP_TIMER_FAILED CHIP_APPLICATION_ERROR(0x06)

class AppTask
{
public:
Expand Down
4 changes: 1 addition & 3 deletions examples/lighting-app/k32w/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ uint8_t __attribute__((section(".heap"))) ucHeap[0xF000];

extern "C" void main_task(void const * argument)
{
CHIP_ERROR ret = CHIP_CONFIG_CORE_ERROR_MAX;

/* Call C++ constructors */
InitFunc * pFunc = &__init_array_start;
for (; pFunc < &__init_array_end; ++pFunc)
Expand All @@ -78,7 +76,7 @@ extern "C" void main_task(void const * argument)
// Init Chip memory management before the stack
chip::Platform::MemoryInit();

ret = PlatformMgr().InitChipStack();
CHIP_ERROR ret = PlatformMgr().InitChipStack();
if (ret != CHIP_NO_ERROR)
{
K32W_LOG("Error during PlatformMgr().InitWeaveStack()");
Expand Down
12 changes: 10 additions & 2 deletions examples/lock-app/efr32/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,19 @@
#include <ble/BLEEndPoint.h>
#include <platform/CHIPDeviceLayer.h>

// Application-defined error codes in the CHIP_ERROR space.
#define APP_ERROR_EVENT_QUEUE_FAILED CHIP_APPLICATION_ERROR(0x01)
#define APP_ERROR_CREATE_TASK_FAILED CHIP_APPLICATION_ERROR(0x02)
#define APP_ERROR_UNHANDLED_EVENT CHIP_APPLICATION_ERROR(0x03)
#define APP_ERROR_CREATE_TIMER_FAILED CHIP_APPLICATION_ERROR(0x04)
#define APP_ERROR_START_TIMER_FAILED CHIP_APPLICATION_ERROR(0x05)
#define APP_ERROR_STOP_TIMER_FAILED CHIP_APPLICATION_ERROR(0x06)

class AppTask
{

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

void PostLockActionRequest(int32_t aActor, BoltLockManager::Action_t aAction);
Expand All @@ -45,7 +53,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
21 changes: 7 additions & 14 deletions examples/lock-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,21 @@ using namespace ::chip::DeviceLayer;

AppTask AppTask::sAppTask;

int AppTask::StartAppTask()
CHIP_ERROR AppTask::StartAppTask()
{
int err = CHIP_CONFIG_CORE_ERROR_MAX;

sAppEventQueue = xQueueCreate(APP_EVENT_QUEUE_SIZE, sizeof(AppEvent));
if (sAppEventQueue == NULL)
{
EFR32_LOG("Failed to allocate app event queue");
appError(err);
appError(APP_ERROR_EVENT_QUEUE_FAILED);
}

// Start App task.
sAppTaskHandle = xTaskCreateStatic(AppTaskMain, APP_TASK_NAME, ArraySize(appStack), NULL, 1, appStack, &appTaskStruct);
if (sAppTaskHandle != NULL)
{
err = CHIP_NO_ERROR;
}

return err;
return (sAppTaskHandle == nullptr) ? APP_ERROR_CREATE_TASK_FAILED : CHIP_NO_ERROR;
}

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

Expand Down Expand Up @@ -271,7 +264,7 @@ void AppTask::LockActionEventHandler(AppEvent * aEvent)
}
else
{
err = CHIP_CONFIG_CORE_ERROR_MAX;
err = APP_ERROR_UNHANDLED_EVENT;
}

if (err == CHIP_NO_ERROR)
Expand Down Expand Up @@ -415,7 +408,7 @@ void AppTask::CancelTimer()
if (xTimerStop(sFunctionTimer, 0) == pdFAIL)
{
EFR32_LOG("app timer stop() failed");
appError(CHIP_CONFIG_CORE_ERROR_MAX);
appError(APP_ERROR_STOP_TIMER_FAILED);
}

mFunctionTimerActive = false;
Expand All @@ -435,7 +428,7 @@ void AppTask::StartTimer(uint32_t aTimeoutInMs)
if (xTimerChangePeriod(sFunctionTimer, aTimeoutInMs / portTICK_PERIOD_MS, 100) != pdPASS)
{
EFR32_LOG("app timer start() failed");
appError(CHIP_CONFIG_CORE_ERROR_MAX);
appError(APP_ERROR_START_TIMER_FAILED);
}

mFunctionTimerActive = true;
Expand Down
6 changes: 3 additions & 3 deletions examples/lock-app/efr32/src/BoltLockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int BoltLockManager::Init()
if (sLockTimer == NULL)
{
EFR32_LOG("sLockTimer timer create failed");
appError(CHIP_CONFIG_CORE_ERROR_MAX);
appError(APP_ERROR_CREATE_TIMER_FAILED);
}

mState = kState_LockingCompleted;
Expand Down Expand Up @@ -135,7 +135,7 @@ void BoltLockManager::StartTimer(uint32_t aTimeoutMs)
if (xTimerChangePeriod(sLockTimer, (aTimeoutMs / portTICK_PERIOD_MS), 100) != pdPASS)
{
EFR32_LOG("sLockTimer timer start() failed");
appError(CHIP_CONFIG_CORE_ERROR_MAX);
appError(APP_ERROR_START_TIMER_FAILED);
}
}

Expand All @@ -144,7 +144,7 @@ void BoltLockManager::CancelTimer(void)
if (xTimerStop(sLockTimer, 0) == pdFAIL)
{
EFR32_LOG("Lock timer timer stop() failed");
appError(CHIP_CONFIG_CORE_ERROR_MAX);
appError(APP_ERROR_STOP_TIMER_FAILED);
}
}

Expand Down
4 changes: 1 addition & 3 deletions examples/lock-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ extern "C" void vApplicationIdleHook(void)
// ================================================================================
int main(void)
{
int ret = CHIP_CONFIG_CORE_ERROR_MAX;

init_efrPlatform();
mbedtls_platform_set_calloc_free(CHIPPlatformMemoryCalloc, CHIPPlatformMemoryFree);

Expand All @@ -109,7 +107,7 @@ int main(void)
chip::Platform::MemoryInit();
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init();

ret = PlatformMgr().InitChipStack();
CHIP_ERROR ret = PlatformMgr().InitChipStack();
if (ret != CHIP_NO_ERROR)
{
EFR32_LOG("PlatformMgr().InitChipStack() failed");
Expand Down
Loading