Skip to content

Commit

Permalink
Fix #1335, Combine redundant switch case to simplify CFE_ES_CleanupOb…
Browse files Browse the repository at this point in the history
…jectCallback
  • Loading branch information
thnkslprpt committed Oct 13, 2024
1 parent 78b8fd7 commit a257797
Showing 1 changed file with 24 additions and 45 deletions.
69 changes: 24 additions & 45 deletions modules/es/fsw/src/cfe_es_apps.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ void CFE_ES_StartApplications(uint32 ResetType, const char *StartFilePath)
*-----------------------------------------------------------------*/
int32 CFE_ES_ParseFileEntry(const char **TokenList, uint32 NumTokens)
{
const char * ModuleName;
const char * EntryType;
const char *ModuleName;
const char *EntryType;
unsigned long ParsedValue;
union
{
Expand Down Expand Up @@ -495,7 +495,7 @@ int32 CFE_ES_LoadModule(CFE_ResourceId_t ParentResourceId, const char *ModuleNam
*-----------------------------------------------------------------*/
int32 CFE_ES_GetTaskFunction(CFE_ES_TaskEntryFuncPtr_t *FuncPtr)
{
CFE_ES_TaskRecord_t * TaskRecPtr;
CFE_ES_TaskRecord_t *TaskRecPtr;
CFE_ES_TaskEntryFuncPtr_t EntryFunc;
int32 ReturnCode;
int32 Timeout;
Expand Down Expand Up @@ -819,7 +819,7 @@ int32 CFE_ES_AppCreate(CFE_ES_AppId_t *ApplicationIdPtr, const char *AppName, co
int32 CFE_ES_LoadLibrary(CFE_ES_LibId_t *LibraryIdPtr, const char *LibName, const CFE_ES_ModuleLoadParams_t *Params)
{
CFE_ES_LibraryEntryFuncPtr_t FunctionPointer;
CFE_ES_LibRecord_t * LibSlotPtr;
CFE_ES_LibRecord_t *LibSlotPtr;
int32 Status;
CFE_ResourceId_t PendingResourceId;

Expand Down Expand Up @@ -974,7 +974,7 @@ bool CFE_ES_RunAppTableScan(uint32 ElapsedTime, void *Arg)
{
CFE_ES_AppTableScanState_t *State = (CFE_ES_AppTableScanState_t *)Arg;
uint32 i;
CFE_ES_AppRecord_t * AppPtr;
CFE_ES_AppRecord_t *AppPtr;
CFE_ES_AppId_t AppTimeoutList[CFE_PLATFORM_ES_MAX_APPLICATIONS];
uint32 NumAppTimeouts;

Expand Down Expand Up @@ -1092,14 +1092,14 @@ bool CFE_ES_RunAppTableScan(uint32 ElapsedTime, void *Arg)
*-----------------------------------------------------------------*/
void CFE_ES_ProcessControlRequest(CFE_ES_AppId_t AppId)
{
CFE_ES_AppRecord_t * AppRecPtr;
CFE_ES_AppRecord_t *AppRecPtr;
uint32 PendingControlReq;
CFE_ES_AppStartParams_t RestartParams;
char OrigAppName[OS_MAX_API_NAME];
CFE_Status_t CleanupStatus;
CFE_Status_t StartupStatus;
CFE_ES_AppId_t NewAppId;
const char * ReqName;
const char *ReqName;
char MessageDetail[48];
uint16 EventID;
CFE_EVS_EventType_Enum_t EventType;
Expand Down Expand Up @@ -1325,8 +1325,8 @@ int32 CFE_ES_CleanUpApp(CFE_ES_AppId_t AppId)
osal_id_t ModuleId;
uint32 NumTasks;
uint32 NumPools;
CFE_ES_AppRecord_t * AppRecPtr;
CFE_ES_TaskRecord_t * TaskRecPtr;
CFE_ES_AppRecord_t *AppRecPtr;
CFE_ES_TaskRecord_t *TaskRecPtr;
CFE_ES_MemPoolRecord_t *MemPoolRecPtr;

NumTasks = 0;
Expand Down Expand Up @@ -1565,6 +1565,7 @@ void CFE_ES_CleanupObjectCallback(osal_id_t ObjectId, void *arg)
int32 OsStatus;
osal_objtype_t ObjType;
bool ObjIsValid;
CFE_Status_t ErrorStatus = CFE_ES_APP_CLEANUP_ERR; // Set default cFE error status for failure to delete an object

CleanState = (CFE_ES_CleanupState_t *)arg;
ObjIsValid = true;
Expand All @@ -1573,22 +1574,28 @@ void CFE_ES_CleanupObjectCallback(osal_id_t ObjectId, void *arg)
switch (ObjType)
{
case OS_OBJECT_TYPE_OS_TASK:
OsStatus = OS_TaskDelete(ObjectId);
OsStatus = OS_TaskDelete(ObjectId);
ErrorStatus = CFE_ES_ERR_CHILD_TASK_DELETE;
break;
case OS_OBJECT_TYPE_OS_QUEUE:
OsStatus = OS_QueueDelete(ObjectId);
OsStatus = OS_QueueDelete(ObjectId);
ErrorStatus = CFE_ES_QUEUE_DELETE_ERR;
break;
case OS_OBJECT_TYPE_OS_BINSEM:
OsStatus = OS_BinSemDelete(ObjectId);
OsStatus = OS_BinSemDelete(ObjectId);
ErrorStatus = CFE_ES_BIN_SEM_DELETE_ERR;
break;
case OS_OBJECT_TYPE_OS_COUNTSEM:
OsStatus = OS_CountSemDelete(ObjectId);
OsStatus = OS_CountSemDelete(ObjectId);
ErrorStatus = CFE_ES_COUNT_SEM_DELETE_ERR;
break;
case OS_OBJECT_TYPE_OS_MUTEX:
OsStatus = OS_MutSemDelete(ObjectId);
OsStatus = OS_MutSemDelete(ObjectId);
ErrorStatus = CFE_ES_MUT_SEM_DELETE_ERR;
break;
case OS_OBJECT_TYPE_OS_TIMECB:
OsStatus = OS_TimerDelete(ObjectId);
OsStatus = OS_TimerDelete(ObjectId);
ErrorStatus = CFE_ES_TIMER_DELETE_ERR;
break;
case OS_OBJECT_TYPE_OS_STREAM:
OsStatus = OS_close(ObjectId);
Expand All @@ -1615,36 +1622,8 @@ void CFE_ES_CleanupObjectCallback(osal_id_t ObjectId, void *arg)
OS_ObjectIdToInteger(ObjectId), (long)OsStatus);
if (CleanState->OverallStatus == CFE_SUCCESS)
{
/*
* Translate any OS failures into the appropriate CFE_ES return codes
* (Some object types have special return codes, depending on what type
* of object failed to delete)
*/
switch (ObjType)
{
case OS_OBJECT_TYPE_OS_TASK:
CleanState->OverallStatus = CFE_ES_ERR_CHILD_TASK_DELETE;
break;
case OS_OBJECT_TYPE_OS_QUEUE:
CleanState->OverallStatus = CFE_ES_QUEUE_DELETE_ERR;
break;
case OS_OBJECT_TYPE_OS_BINSEM:
CleanState->OverallStatus = CFE_ES_BIN_SEM_DELETE_ERR;
break;
case OS_OBJECT_TYPE_OS_COUNTSEM:
CleanState->OverallStatus = CFE_ES_COUNT_SEM_DELETE_ERR;
break;
case OS_OBJECT_TYPE_OS_MUTEX:
CleanState->OverallStatus = CFE_ES_MUT_SEM_DELETE_ERR;
break;
case OS_OBJECT_TYPE_OS_TIMECB:
CleanState->OverallStatus = CFE_ES_TIMER_DELETE_ERR;
break;
default:
/* generic failure */
CleanState->OverallStatus = CFE_ES_APP_CLEANUP_ERR;
break;
}
// Save the object-type-specific error code that was set earlier in each case in the switch statement
CleanState->OverallStatus = ErrorStatus;
}
}
}
Expand Down

0 comments on commit a257797

Please sign in to comment.