Skip to content

Commit

Permalink
Fix #225, refactor goto statements
Browse files Browse the repository at this point in the history
  • Loading branch information
havencarlson committed Jul 14, 2022
1 parent c023d56 commit d628409
Show file tree
Hide file tree
Showing 9 changed files with 566 additions and 533 deletions.
93 changes: 50 additions & 43 deletions fsw/src/cf_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,45 +160,36 @@ int32 CF_TableInit(void)
{
int32 status = CFE_SUCCESS;

status = CFE_TBL_Register(&CF_AppData.config_handle, CF_CONFIG_TABLE_NAME, sizeof(CF_ConfigTable_t),
CFE_TBL_OPT_SNGL_BUFFER | CFE_TBL_OPT_LOAD_DUMP, CF_ValidateConfigTable);
if (status != CFE_SUCCESS)
if ((status = CFE_TBL_Register(&CF_AppData.config_handle, CF_CONFIG_TABLE_NAME, sizeof(CF_ConfigTable_t),
CFE_TBL_OPT_SNGL_BUFFER | CFE_TBL_OPT_LOAD_DUMP, CF_ValidateConfigTable)) !=
CFE_SUCCESS)
{
CFE_EVS_SendEvent(CF_EID_ERR_INIT_TBL_REG, CFE_EVS_EventType_ERROR,
"CF: error registering table, returned 0x%08lx", (unsigned long)status);
goto err_out;
}

status = CFE_TBL_Load(CF_AppData.config_handle, CFE_TBL_SRC_FILE, CF_CONFIG_TABLE_FILENAME);
if (status != CFE_SUCCESS)
else if ((status = CFE_TBL_Load(CF_AppData.config_handle, CFE_TBL_SRC_FILE, CF_CONFIG_TABLE_FILENAME)) !=
CFE_SUCCESS)
{
CFE_EVS_SendEvent(CF_EID_ERR_INIT_TBL_LOAD, CFE_EVS_EventType_ERROR,
"CF: error loading table, returned 0x%08lx", (unsigned long)status);
goto err_out;
}

status = CFE_TBL_Manage(CF_AppData.config_handle);
if (status != CFE_SUCCESS)
else if ((status = CFE_TBL_Manage(CF_AppData.config_handle)) != CFE_SUCCESS)
{
CFE_EVS_SendEvent(CF_EID_ERR_INIT_TBL_MANAGE, CFE_EVS_EventType_ERROR,
"CF: error in CFE_TBL_Manage, returned 0x%08lx", (unsigned long)status);
goto err_out;
}

status = CFE_TBL_GetAddress((void **)&CF_AppData.config_table, CF_AppData.config_handle);
/* status will be CFE_TBL_INFO_UPDATED because it was just loaded, but we can use CFE_SUCCESS too */
if ((status != CFE_TBL_INFO_UPDATED) && (status != CFE_SUCCESS))
else if ((status = CFE_TBL_GetAddress((void **)&CF_AppData.config_table, CF_AppData.config_handle)),
(status != CFE_TBL_INFO_UPDATED) && (status != CFE_SUCCESS))
{
CFE_EVS_SendEvent(CF_EID_ERR_INIT_TBL_GETADDR, CFE_EVS_EventType_ERROR,
"CF: error getting table address, returned 0x%08lx", (unsigned long)status);
goto err_out;
}
else
{
status = CFE_SUCCESS;
}

err_out:
return status;
}

Expand All @@ -213,6 +204,7 @@ int32 CF_TableInit(void)
int32 CF_Init(void)
{
int32 status = CFE_SUCCESS;
bool success = true;
static const CFE_SB_MsgId_Atom_t MID_VALUES[] = {CF_CMD_MID, CF_SEND_HK_MID, CF_WAKE_UP_MID};
uint32 i;

Expand All @@ -224,51 +216,66 @@ int32 CF_Init(void)
if (status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("CF app: error registering with EVS, returned 0x%08lx", (unsigned long)status);
goto err_out;
success = false;
}

status = CFE_SB_CreatePipe(&CF_AppData.cmd_pipe, CF_PIPE_DEPTH, CF_PIPE_NAME);
if (status != CFE_SUCCESS)
if (success)
{
CFE_ES_WriteToSysLog("CF app: error creating pipe %s, returend 0x%08lx", CF_PIPE_NAME, (unsigned long)status);
goto err_out;
status = CFE_SB_CreatePipe(&CF_AppData.cmd_pipe, CF_PIPE_DEPTH, CF_PIPE_NAME);
if (status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("CF app: error creating pipe %s, returend 0x%08lx", CF_PIPE_NAME,
(unsigned long)status);
success = false;
}
}

for (i = 0; i < (sizeof(MID_VALUES) / sizeof(MID_VALUES[0])); ++i)
if (success)
{
status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(MID_VALUES[i]), CF_AppData.cmd_pipe);
if (status != CFE_SUCCESS)
for (i = 0; i < (sizeof(MID_VALUES) / sizeof(MID_VALUES[0])); ++i)
{
CFE_ES_WriteToSysLog("CF app: failed to subscribe to MID 0x%04lx, returned 0x%08lx",
(unsigned long)MID_VALUES[i], (unsigned long)status);
goto err_out;
status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(MID_VALUES[i]), CF_AppData.cmd_pipe);
if (status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("CF app: failed to subscribe to MID 0x%04lx, returned 0x%08lx",
(unsigned long)MID_VALUES[i], (unsigned long)status);
success = false;
break;
}
}
}

status = CF_TableInit();
if (status != CFE_SUCCESS)
if (success)
{
/* function sends event internally */
goto err_out;
status = CF_TableInit();
if (status != CFE_SUCCESS)
{
/* function sends event internally */
success = false;
}
}

status = CF_CFDP_InitEngine();
if (status != CFE_SUCCESS)
if (success)
{
/* function sends event internally */
goto err_out;
status = CF_CFDP_InitEngine();
if (status != CFE_SUCCESS)
{
/* function sends event internally */
success = false;
}
}

status = CFE_EVS_SendEvent(CF_EID_INF_INIT, CFE_EVS_EventType_INFORMATION, "CF Initialized. Version %d.%d.%d.%d",
CF_MAJOR_VERSION, CF_MINOR_VERSION, CF_REVISION, CF_MISSION_REV);

if (status != CFE_SUCCESS)
if (success)
{
CFE_ES_WriteToSysLog("CF: error sending init event, returned 0x%08lx", (unsigned long)status);
goto err_out;
status =
CFE_EVS_SendEvent(CF_EID_INF_INIT, CFE_EVS_EventType_INFORMATION, "CF Initialized. Version %d.%d.%d.%d",
CF_MAJOR_VERSION, CF_MINOR_VERSION, CF_REVISION, CF_MISSION_REV);
if (status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("CF: error sending init event, returned 0x%08lx", (unsigned long)status);
}
}

err_out:
return status;
}

Expand Down
Loading

0 comments on commit d628409

Please sign in to comment.