Skip to content

Commit

Permalink
Fix #1428, Refactor error handling for EVS_GetApplicationInfo()
Browse files Browse the repository at this point in the history
  • Loading branch information
thnkslprpt committed Mar 23, 2024
1 parent ed1faf4 commit 8679507
Showing 1 changed file with 46 additions and 141 deletions.
187 changes: 46 additions & 141 deletions modules/evs/fsw/src/cfe_evs_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ CFE_EVS_Global_t CFE_EVS_Global;
/* Defines */
#define CFE_EVS_PANIC_DELAY 500 /**< \brief Task delay before PSP panic */

/*
** Local function prototypes.
*/
void CFE_EVS_SendEventForGetAppInfoError(int32 Status, const char *LocalName, uint16 CommandCode);

/* Function Definitions */

/*----------------------------------------------------------------
Expand Down Expand Up @@ -305,6 +310,37 @@ int32 CFE_EVS_TaskInit(void)
return CFE_SUCCESS;
}

/*----------------------------------------------------------------
*
* Internal helper routine only, not part of API.
*
* This function handles error returns from calls to
* EVS_GetApplicationInfo() and generates a customized error
* event from the calling function.
*
*-----------------------------------------------------------------*/
void CFE_EVS_SendEventForGetAppInfoError(int32 Status, const char *LocalName, uint16 CommandCode)

Check notice

Code scanning / CodeQL-coding-standard

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
{
switch (Status)
{
case CFE_EVS_APP_NOT_REGISTERED:
EVS_SendEvent(CFE_EVS_ERR_APPNOREGS_EID, CFE_EVS_EventType_ERROR, "%s not registered with EVS: CC = %lu",
LocalName, (long unsigned int)CommandCode);
break;

case CFE_EVS_APP_ILLEGAL_APP_ID:
EVS_SendEvent(CFE_EVS_ERR_ILLAPPIDRANGE_EID, CFE_EVS_EventType_ERROR,
"Illegal application ID retrieved for %s: CC = %lu", LocalName,
(long unsigned int)CommandCode);
break;

default:
EVS_SendEvent(CFE_EVS_ERR_NOAPPIDFOUND_EID, CFE_EVS_EventType_ERROR,
"Unable to retrieve application ID for %s: CC = %lu", LocalName,
(long unsigned int)CommandCode);
}
}

/*----------------------------------------------------------------
*
* Application-scope internal function
Expand Down Expand Up @@ -449,22 +485,9 @@ int32 CFE_EVS_SetFilterCmd(const CFE_EVS_SetFilterCmd_t *data)
Status = CFE_EVS_EVT_NOT_REGISTERED;
}
}
else if (Status == CFE_EVS_APP_NOT_REGISTERED)
{
EVS_SendEvent(CFE_EVS_ERR_APPNOREGS_EID, CFE_EVS_EventType_ERROR, "%s not registered with EVS: CC = %lu",
LocalName, (long unsigned int)CFE_EVS_SET_FILTER_CC);
}
else if (Status == CFE_EVS_APP_ILLEGAL_APP_ID)
{
EVS_SendEvent(CFE_EVS_ERR_ILLAPPIDRANGE_EID, CFE_EVS_EventType_ERROR,
"Illegal application ID retrieved for %s: CC = %lu", LocalName,
(long unsigned int)CFE_EVS_SET_FILTER_CC);
}
else
{
EVS_SendEvent(CFE_EVS_ERR_NOAPPIDFOUND_EID, CFE_EVS_EventType_ERROR,
"Unable to retrieve application ID for %s: CC = %lu", LocalName,
(long unsigned int)CFE_EVS_SET_FILTER_CC);
CFE_EVS_SendEventForGetAppInfoError(Status, LocalName, CFE_EVS_SET_FILTER_CC);
}

return Status;
Expand Down Expand Up @@ -688,22 +711,9 @@ int32 CFE_EVS_EnableAppEventTypeCmd(const CFE_EVS_EnableAppEventTypeCmd_t *data)
EVS_EnableTypes(AppDataPtr, CmdPtr->BitMask);
}
}
else if (Status == CFE_EVS_APP_NOT_REGISTERED)
{
EVS_SendEvent(CFE_EVS_ERR_APPNOREGS_EID, CFE_EVS_EventType_ERROR, "%s not registered with EVS: CC = %lu",
LocalName, (long unsigned int)CFE_EVS_ENABLE_APP_EVENT_TYPE_CC);
}
else if (Status == CFE_EVS_APP_ILLEGAL_APP_ID)
{
EVS_SendEvent(CFE_EVS_ERR_ILLAPPIDRANGE_EID, CFE_EVS_EventType_ERROR,
"Illegal application ID retrieved for %s: CC = %lu", LocalName,
(long unsigned int)CFE_EVS_ENABLE_APP_EVENT_TYPE_CC);
}
else
{
EVS_SendEvent(CFE_EVS_ERR_NOAPPIDFOUND_EID, CFE_EVS_EventType_ERROR,
"Unable to retrieve application ID for %s: CC = %lu", LocalName,
(long unsigned int)CFE_EVS_ENABLE_APP_EVENT_TYPE_CC);
CFE_EVS_SendEventForGetAppInfoError(Status, LocalName, CFE_EVS_ENABLE_APP_EVENT_TYPE_CC);
}

if (Status == CFE_SUCCESS)
Expand Down Expand Up @@ -750,22 +760,9 @@ int32 CFE_EVS_DisableAppEventTypeCmd(const CFE_EVS_DisableAppEventTypeCmd_t *dat
EVS_DisableTypes(AppDataPtr, CmdPtr->BitMask);
}
}
else if (Status == CFE_EVS_APP_NOT_REGISTERED)
{
EVS_SendEvent(CFE_EVS_ERR_APPNOREGS_EID, CFE_EVS_EventType_ERROR, "%s not registered with EVS,: CC = %lu",
LocalName, (long unsigned int)CFE_EVS_DISABLE_APP_EVENT_TYPE_CC);
}
else if (Status == CFE_EVS_APP_ILLEGAL_APP_ID)
{
EVS_SendEvent(CFE_EVS_ERR_ILLAPPIDRANGE_EID, CFE_EVS_EventType_ERROR,
"Illegal application ID retrieved for %s: CC = %lu", LocalName,
(long unsigned int)CFE_EVS_DISABLE_APP_EVENT_TYPE_CC);
}
else
{
EVS_SendEvent(CFE_EVS_ERR_NOAPPIDFOUND_EID, CFE_EVS_EventType_ERROR,
"Unable to retrieve application ID for %s: CC = %lu", LocalName,
(long unsigned int)CFE_EVS_DISABLE_APP_EVENT_TYPE_CC);
CFE_EVS_SendEventForGetAppInfoError(Status, LocalName, CFE_EVS_DISABLE_APP_EVENT_TYPE_CC);
}

if (Status == CFE_SUCCESS)
Expand Down Expand Up @@ -804,22 +801,9 @@ int32 CFE_EVS_EnableAppEventsCmd(const CFE_EVS_EnableAppEventsCmd_t *data)
EVS_SendEvent(CFE_EVS_ENAAPPEVT_EID, CFE_EVS_EventType_DEBUG,
"Enable App Events Command Received with AppName = %s", LocalName);
}
else if (Status == CFE_EVS_APP_NOT_REGISTERED)
{
EVS_SendEvent(CFE_EVS_ERR_APPNOREGS_EID, CFE_EVS_EventType_ERROR, "%s not registered with EVS: CC = %lu",
LocalName, (long unsigned int)CFE_EVS_ENABLE_APP_EVENTS_CC);
}
else if (Status == CFE_EVS_APP_ILLEGAL_APP_ID)
{
EVS_SendEvent(CFE_EVS_ERR_ILLAPPIDRANGE_EID, CFE_EVS_EventType_ERROR,
"Illegal application ID retrieved for %s: CC = %lu", LocalName,
(long unsigned int)CFE_EVS_ENABLE_APP_EVENTS_CC);
}
else
{
EVS_SendEvent(CFE_EVS_ERR_NOAPPIDFOUND_EID, CFE_EVS_EventType_ERROR,
"Unable to retrieve application ID for %s: CC = %lu", LocalName,
(long unsigned int)CFE_EVS_ENABLE_APP_EVENTS_CC);
CFE_EVS_SendEventForGetAppInfoError(Status, LocalName, CFE_EVS_ENABLE_APP_EVENTS_CC);
}

return Status;
Expand Down Expand Up @@ -851,22 +835,9 @@ int32 CFE_EVS_DisableAppEventsCmd(const CFE_EVS_DisableAppEventsCmd_t *data)
EVS_SendEvent(CFE_EVS_DISAPPEVT_EID, CFE_EVS_EventType_DEBUG,
"Disable App Events Command Received with AppName = %s", LocalName);
}
else if (Status == CFE_EVS_APP_NOT_REGISTERED)
{
EVS_SendEvent(CFE_EVS_ERR_APPNOREGS_EID, CFE_EVS_EventType_ERROR, "%s not registered with EVS: CC = %lu",
LocalName, (long unsigned int)CFE_EVS_DISABLE_APP_EVENTS_CC);
}
else if (Status == CFE_EVS_APP_ILLEGAL_APP_ID)
{
EVS_SendEvent(CFE_EVS_ERR_ILLAPPIDRANGE_EID, CFE_EVS_EventType_ERROR,
"Illegal application ID retrieved for %s: CC = %lu", LocalName,
(long unsigned int)CFE_EVS_DISABLE_APP_EVENTS_CC);
}
else
{
EVS_SendEvent(CFE_EVS_ERR_NOAPPIDFOUND_EID, CFE_EVS_EventType_ERROR,
"Disable App Events Command: Unable to retrieve application ID for %s: CC = %lu", LocalName,
(long unsigned int)CFE_EVS_DISABLE_APP_EVENTS_CC);
CFE_EVS_SendEventForGetAppInfoError(Status, LocalName, CFE_EVS_DISABLE_APP_EVENTS_CC);
}

return Status;
Expand Down Expand Up @@ -899,22 +870,9 @@ int32 CFE_EVS_ResetAppCounterCmd(const CFE_EVS_ResetAppCounterCmd_t *data)
EVS_SendEvent(CFE_EVS_RSTEVTCNT_EID, CFE_EVS_EventType_DEBUG,
"Reset Event Counter Command Received with AppName = %s", LocalName);
}
else if (Status == CFE_EVS_APP_NOT_REGISTERED)
{
EVS_SendEvent(CFE_EVS_ERR_APPNOREGS_EID, CFE_EVS_EventType_ERROR, "%s not registered with EVS: CC = %lu",
LocalName, (long unsigned int)CFE_EVS_RESET_APP_COUNTER_CC);
}
else if (Status == CFE_EVS_APP_ILLEGAL_APP_ID)
{
EVS_SendEvent(CFE_EVS_ERR_ILLAPPIDRANGE_EID, CFE_EVS_EventType_ERROR,
"Illegal application ID retrieved for %s: CC = %lu", LocalName,
(long unsigned int)CFE_EVS_RESET_APP_COUNTER_CC);
}
else
{
EVS_SendEvent(CFE_EVS_ERR_NOAPPIDFOUND_EID, CFE_EVS_EventType_ERROR,
"Reset Event Counter Command: Unable to retrieve application ID for %s: CC = %lu", LocalName,
(long unsigned int)CFE_EVS_RESET_APP_COUNTER_CC);
CFE_EVS_SendEventForGetAppInfoError(Status, LocalName, CFE_EVS_RESET_APP_COUNTER_CC);
}

return Status;
Expand Down Expand Up @@ -961,22 +919,9 @@ int32 CFE_EVS_ResetFilterCmd(const CFE_EVS_ResetFilterCmd_t *data)
Status = CFE_EVS_EVT_NOT_REGISTERED;
}
}
else if (Status == CFE_EVS_APP_NOT_REGISTERED)
{
EVS_SendEvent(CFE_EVS_ERR_APPNOREGS_EID, CFE_EVS_EventType_ERROR, "%s not registered with EVS: CC = %lu",
LocalName, (long unsigned int)CFE_EVS_RESET_FILTER_CC);
}
else if (Status == CFE_EVS_APP_ILLEGAL_APP_ID)
{
EVS_SendEvent(CFE_EVS_ERR_ILLAPPIDRANGE_EID, CFE_EVS_EventType_ERROR,
"Illegal application ID retrieved for %s: CC = %lu", LocalName,
(long unsigned int)CFE_EVS_RESET_FILTER_CC);
}
else
{
EVS_SendEvent(CFE_EVS_ERR_NOAPPIDFOUND_EID, CFE_EVS_EventType_ERROR,
"Unable to retrieve application ID for %s: CC = %lu", LocalName,
(long unsigned int)CFE_EVS_RESET_FILTER_CC);
CFE_EVS_SendEventForGetAppInfoError(Status, LocalName, CFE_EVS_RESET_FILTER_CC);
}

return Status;
Expand Down Expand Up @@ -1012,22 +957,9 @@ int32 CFE_EVS_ResetAllFiltersCmd(const CFE_EVS_ResetAllFiltersCmd_t *data)
EVS_SendEvent(CFE_EVS_RSTALLFILTER_EID, CFE_EVS_EventType_DEBUG,
"Reset All Filters Command Received with AppName = %s", LocalName);
}
else if (Status == CFE_EVS_APP_NOT_REGISTERED)
{
EVS_SendEvent(CFE_EVS_ERR_APPNOREGS_EID, CFE_EVS_EventType_ERROR, "%s not registered with EVS: CC = %lu",
LocalName, (long unsigned int)CFE_EVS_RESET_ALL_FILTERS_CC);
}
else if (Status == CFE_EVS_APP_ILLEGAL_APP_ID)
{
EVS_SendEvent(CFE_EVS_ERR_ILLAPPIDRANGE_EID, CFE_EVS_EventType_ERROR,
"Illegal application ID retrieved for %s: CC = %lu", LocalName,
(long unsigned int)CFE_EVS_RESET_ALL_FILTERS_CC);
}
else
{
EVS_SendEvent(CFE_EVS_ERR_NOAPPIDFOUND_EID, CFE_EVS_EventType_ERROR,
"Unable to retrieve application ID for %s: CC = %lu", LocalName,
(long unsigned int)CFE_EVS_RESET_ALL_FILTERS_CC);
CFE_EVS_SendEventForGetAppInfoError(Status, LocalName, CFE_EVS_RESET_ALL_FILTERS_CC);
}

return Status;
Expand Down Expand Up @@ -1093,23 +1025,9 @@ int32 CFE_EVS_AddEventFilterCmd(const CFE_EVS_AddEventFilterCmd_t *data)
}
} /* end else*/
} /* end if (Status == CFE_SUCCESS) */

else if (Status == CFE_EVS_APP_NOT_REGISTERED)
{
EVS_SendEvent(CFE_EVS_ERR_APPNOREGS_EID, CFE_EVS_EventType_ERROR, "%s not registered with EVS: CC = %lu",
LocalName, (long unsigned int)CFE_EVS_ADD_EVENT_FILTER_CC);
}
else if (Status == CFE_EVS_APP_ILLEGAL_APP_ID)
{
EVS_SendEvent(CFE_EVS_ERR_ILLAPPIDRANGE_EID, CFE_EVS_EventType_ERROR,
"Illegal application ID retrieved for %s: CC = %lu", LocalName,
(long unsigned int)CFE_EVS_ADD_EVENT_FILTER_CC);
}
else
{
EVS_SendEvent(CFE_EVS_ERR_NOAPPIDFOUND_EID, CFE_EVS_EventType_ERROR,
"Unable to retrieve application ID for %s: CC = %lu", LocalName,
(long unsigned int)CFE_EVS_ADD_EVENT_FILTER_CC);
CFE_EVS_SendEventForGetAppInfoError(Status, LocalName, CFE_EVS_ADD_EVENT_FILTER_CC);
}

return Status;
Expand Down Expand Up @@ -1158,22 +1076,9 @@ int32 CFE_EVS_DeleteEventFilterCmd(const CFE_EVS_DeleteEventFilterCmd_t *data)
Status = CFE_EVS_EVT_NOT_REGISTERED;
}
}
else if (Status == CFE_EVS_APP_NOT_REGISTERED)
{
EVS_SendEvent(CFE_EVS_ERR_APPNOREGS_EID, CFE_EVS_EventType_ERROR, "%s not registered with EVS: CC = %lu",
LocalName, (long unsigned int)CFE_EVS_DELETE_EVENT_FILTER_CC);
}
else if (Status == CFE_EVS_APP_ILLEGAL_APP_ID)
{
EVS_SendEvent(CFE_EVS_ERR_ILLAPPIDRANGE_EID, CFE_EVS_EventType_ERROR,
"Illegal application ID retrieved for %s: CC = %lu", LocalName,
(long unsigned int)CFE_EVS_DELETE_EVENT_FILTER_CC);
}
else
{
EVS_SendEvent(CFE_EVS_ERR_NOAPPIDFOUND_EID, CFE_EVS_EventType_ERROR,
"Unable to retrieve application ID for %s: CC = %lu", LocalName,
(long unsigned int)CFE_EVS_DELETE_EVENT_FILTER_CC);
CFE_EVS_SendEventForGetAppInfoError(Status, LocalName, CFE_EVS_DELETE_EVENT_FILTER_CC);
}

return Status;
Expand Down

0 comments on commit 8679507

Please sign in to comment.