Skip to content

Commit

Permalink
Fix #943, Consistent Name-ID API
Browse files Browse the repository at this point in the history
Implement consistent conversion/lookup functions to translate
between names and IDs for all resource types.

Also reorganize all internal resource ID functions into a separate
source file for better organization.

Clean up documentation and references.
  • Loading branch information
jphickey committed Oct 13, 2020
1 parent dc3d62b commit 75fc1ea
Show file tree
Hide file tree
Showing 25 changed files with 1,808 additions and 1,025 deletions.
670 changes: 352 additions & 318 deletions fsw/cfe-core/src/es/cfe_es_api.c

Large diffs are not rendered by default.

19 changes: 11 additions & 8 deletions fsw/cfe-core/src/es/cfe_es_apps.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "cfe_es_task.h"
#include "cfe_es_apps.h"
#include "cfe_es_log.h"
#include "cfe_es_resource.h"

#include <stdio.h>
#include <string.h> /* memset() */
Expand Down Expand Up @@ -78,7 +79,7 @@ void CFE_ES_StartApplications(uint32 ResetType, const char *StartFilePath )
char ES_AppLoadBuffer[ES_START_BUFF_SIZE]; /* A buffer of for a line in a file */
const char *TokenList[CFE_ES_STARTSCRIPT_MAX_TOKENS_PER_LINE];
uint32 NumTokens;
uint32 BuffLen = 0; /* Length of the current buffer */
uint32 BuffLen; /* Length of the current buffer */
osal_id_t AppFile;
int32 Status;
char c;
Expand Down Expand Up @@ -1447,7 +1448,7 @@ int32 CFE_ES_GetAppInfoInternal(CFE_ES_AppRecord_t *AppRecPtr, CFE_ES_AppInfo_t

if ( !CFE_ES_AppRecordIsUsed(AppRecPtr) )
{
Status = CFE_ES_ERR_APPID;
Status = CFE_ES_ERR_RESOURCEID_NOT_VALID;
}
else
{
Expand All @@ -1456,8 +1457,8 @@ int32 CFE_ES_GetAppInfoInternal(CFE_ES_AppRecord_t *AppRecPtr, CFE_ES_AppInfo_t
AppId = CFE_ES_AppRecordGetID(AppRecPtr);
AppInfoPtr->AppId = AppId;
AppInfoPtr->Type = AppRecPtr->Type;
strncpy((char *)AppInfoPtr->Name,
AppRecPtr->StartParams.Name,
strncpy(AppInfoPtr->Name,
CFE_ES_AppRecordGetName(AppRecPtr),
sizeof(AppInfoPtr->Name)-1);
AppInfoPtr->Name[sizeof(AppInfoPtr->Name)-1] = '\0';

Expand Down Expand Up @@ -1565,7 +1566,8 @@ int32 CFE_ES_GetTaskInfoInternal(CFE_ES_TaskRecord_t *TaskRecPtr, CFE_ES_TaskInf
** Get the Application ID and Task Name
*/
TaskInfoPtr->AppId = TaskRecPtr->AppId;
strncpy((char*)TaskInfoPtr->TaskName, TaskRecPtr->TaskName,
strncpy(TaskInfoPtr->TaskName,
CFE_ES_TaskRecordGetName(TaskRecPtr),
sizeof(TaskInfoPtr->TaskName)-1);
TaskInfoPtr->TaskName[sizeof(TaskInfoPtr->TaskName)-1] = '\0';

Expand All @@ -1585,21 +1587,22 @@ int32 CFE_ES_GetTaskInfoInternal(CFE_ES_TaskRecord_t *TaskRecPtr, CFE_ES_TaskInf
AppRecPtr = CFE_ES_LocateAppRecordByID(TaskRecPtr->AppId);
if (CFE_ES_AppRecordIsMatch(AppRecPtr, TaskRecPtr->AppId))
{
strncpy((char*)TaskInfoPtr->AppName, AppRecPtr->StartParams.Name,
strncpy(TaskInfoPtr->AppName,
CFE_ES_AppRecordGetName(AppRecPtr),
sizeof(TaskInfoPtr->AppName)-1);
TaskInfoPtr->AppName[sizeof(TaskInfoPtr->AppName)-1] = '\0';
ReturnCode = CFE_SUCCESS;
}
else
{
/* task ID was OK but parent app ID is bad */
ReturnCode = CFE_ES_ERR_APPID;
ReturnCode = CFE_ES_ERR_RESOURCEID_NOT_VALID;
}
}
else
{
/* task ID is bad */
ReturnCode = CFE_ES_ERR_TASKID;
ReturnCode = CFE_ES_ERR_RESOURCEID_NOT_VALID;
}

CFE_ES_UnlockSharedData(__func__,__LINE__);
Expand Down
13 changes: 7 additions & 6 deletions fsw/cfe-core/src/es/cfe_es_cds.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "cfe_es_apps.h"
#include "cfe_es_cds.h"
#include "cfe_es_global.h"
#include "cfe_es_resource.h"
#include "cfe_es_log.h"
#include "cfe_psp.h"
#include "cfe_es_cds_mempool.h"
Expand Down Expand Up @@ -325,7 +326,7 @@ int32 CFE_ES_RegisterCDSEx(CFE_ES_CDSHandle_t *HandlePtr, CFE_ES_CDS_Offset_t Us
CFE_ES_LockCDS();

/* Check for duplicate CDS name */
RegRecPtr = CFE_ES_FindCDSInRegistry(Name);
RegRecPtr = CFE_ES_LocateCDSBlockRecordByName(Name);

/* If not found then make a new entry */
if (RegRecPtr == NULL)
Expand Down Expand Up @@ -732,12 +733,12 @@ int32 CFE_ES_UnlockCDS(void)

/*******************************************************************
**
** CFE_ES_FindCDSInRegistry
** CFE_ES_LocateCDSBlockRecordByName
**
** NOTE: For complete prolog information, see 'cfe_es_cds.h'
********************************************************************/

CFE_ES_CDS_RegRec_t *CFE_ES_FindCDSInRegistry(const char *CDSName)
CFE_ES_CDS_RegRec_t *CFE_ES_LocateCDSBlockRecordByName(const char *CDSName)
{
CFE_ES_CDS_Instance_t *CDS = &CFE_ES_Global.CDSVars;
CFE_ES_CDS_RegRec_t *CDSRegRecPtr;
Expand Down Expand Up @@ -768,7 +769,7 @@ CFE_ES_CDS_RegRec_t *CFE_ES_FindCDSInRegistry(const char *CDSName)
}

return CDSRegRecPtr;
} /* End of CFE_ES_FindCDSInRegistry() */
} /* End of CFE_ES_LocateCDSBlockRecordByName() */


/*******************************************************************
Expand Down Expand Up @@ -889,7 +890,7 @@ int32 CFE_ES_DeleteCDS(const char *CDSName, bool CalledByTblServices)
CFE_ES_LockCDS();

/* Find CDS name in registry */
RegRecPtr = CFE_ES_FindCDSInRegistry(CDSName);
RegRecPtr = CFE_ES_LocateCDSBlockRecordByName(CDSName);

/* Check to see if CDS is already in the registry */
if (RegRecPtr != NULL)
Expand Down Expand Up @@ -952,7 +953,7 @@ int32 CFE_ES_DeleteCDS(const char *CDSName, bool CalledByTblServices)
}
else /* Error - CDS not in registry */
{
Status = CFE_ES_CDS_NOT_FOUND_ERR;
Status = CFE_ES_ERR_NAME_NOT_FOUND;
}

/* Unlock Registry for future updates */
Expand Down
6 changes: 3 additions & 3 deletions fsw/cfe-core/src/es/cfe_es_cds.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ int32 CFE_ES_CDS_CachePreload(CFE_ES_CDS_AccessCache_t *Cache, const void *Sourc
* @param[in] BlockID the ID/handle of the CDS block to retrieve
* @param[out] Idx Output buffer to store the index
* @returns #CFE_SUCCESS if conversion successful. @copydoc CFE_SUCCESS
* #CFE_ES_RESOURCE_ID_INVALID if block ID is outside valid range
* #CFE_ES_ERR_RESOURCEID_NOT_VALID if block ID is outside valid range
*/
int32 CFE_ES_CDSBlockID_ToIndex(CFE_ES_ResourceID_t BlockID, uint32 *Idx);

Expand Down Expand Up @@ -505,7 +505,7 @@ void CFE_ES_FormCDSName(char *FullCDSName, const char *CDSName, CFE_ES_ResourceI

/*****************************************************************************/
/**
** \brief Returns the Registry Index for the specified CDS Name
** \brief Returns the Registry Record for the specified CDS Name
**
** \par Description
** Locates given CDS Name in the CDS Registry and
Expand All @@ -520,7 +520,7 @@ void CFE_ES_FormCDSName(char *FullCDSName, const char *CDSName, CFE_ES_ResourceI
** \retval NULL if not found, Non null entry pointer on success
**
******************************************************************************/
CFE_ES_CDS_RegRec_t *CFE_ES_FindCDSInRegistry(const char *CDSName);
CFE_ES_CDS_RegRec_t *CFE_ES_LocateCDSBlockRecordByName(const char *CDSName);

/*****************************************************************************/
/**
Expand Down
4 changes: 2 additions & 2 deletions fsw/cfe-core/src/es/cfe_es_cds_mempool.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ int32 CFE_ES_CDSBlockWrite(CFE_ES_CDSHandle_t Handle, const void *DataToWrite)
}
else
{
Status = CFE_ES_RESOURCE_ID_INVALID;
Status = CFE_ES_ERR_RESOURCEID_NOT_VALID;
}

CFE_ES_UnlockCDS();
Expand Down Expand Up @@ -379,7 +379,7 @@ int32 CFE_ES_CDSBlockRead(void *DataRead, CFE_ES_CDSHandle_t Handle)
}
else
{
Status = CFE_ES_RESOURCE_ID_INVALID;
Status = CFE_ES_ERR_RESOURCEID_NOT_VALID;
}

CFE_ES_UnlockCDS();
Expand Down
1 change: 1 addition & 0 deletions fsw/cfe-core/src/es/cfe_es_erlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "cfe_es.h"
#include "cfe_es_apps.h"
#include "cfe_es_global.h"
#include "cfe_es_resource.h"
#include "cfe_es_log.h"
#include "cfe_es_task.h"
#include "cfe_psp.h"
Expand Down
Loading

0 comments on commit 75fc1ea

Please sign in to comment.