Skip to content

Commit

Permalink
Fix nasa#1335, Combine redundant switch case to simplify CFE_ES_Clean…
Browse files Browse the repository at this point in the history
…upObjectCallback
  • Loading branch information
thnkslprpt committed Oct 12, 2024
1 parent 78b8fd7 commit 97bb81a
Showing 1 changed file with 22 additions and 40 deletions.
62 changes: 22 additions & 40 deletions modules/es/fsw/src/cfe_es_apps.c
Original file line number Diff line number Diff line change
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;

CleanState = (CFE_ES_CleanupState_t *)arg;
ObjIsValid = true;
Expand All @@ -1573,32 +1574,41 @@ 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);
OsStatus = OS_close(ObjectId);
ErrorStatus = CFE_ES_APP_CLEANUP_ERR;
break;
case OS_OBJECT_TYPE_OS_MODULE:
OsStatus = OS_ModuleUnload(ObjectId);
OsStatus = OS_ModuleUnload(ObjectId);
ErrorStatus = CFE_ES_APP_CLEANUP_ERR;
break;
default:
ObjIsValid = false;
OsStatus = OS_ERROR;
ObjIsValid = false;
OsStatus = OS_ERROR;
ErrorStatus = CFE_ES_APP_CLEANUP_ERR;
break;
}

Expand All @@ -1615,36 +1625,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 97bb81a

Please sign in to comment.