Skip to content

Commit af4f72a

Browse files
committed
Fix #56, Refactor CDS to use generic pool implementation
Rather than having a second pool implementation only for CDS, use the generic pool implementation. This also uses the abstract resource identifiers to identify CDS blocks, rather than a direct reference.
1 parent 7f6fdfb commit af4f72a

15 files changed

+1619
-1502
lines changed

fsw/cfe-core/src/es/cfe_es_api.c

+13-21
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ uint32 CFE_ES_CalculateCRC(const void *DataPtr, uint32 DataLength, uint32 InputC
13971397
** Purpose: Allocate a data block for a Critical Data Store.
13981398
**
13991399
*/
1400-
int32 CFE_ES_RegisterCDS(CFE_ES_CDSHandle_t *CDSHandlePtr, int32 BlockSize, const char *Name)
1400+
int32 CFE_ES_RegisterCDS(CFE_ES_CDSHandle_t *CDSHandlePtr, CFE_ES_CDS_Offset_t BlockSize, const char *Name)
14011401
{
14021402
int32 Status;
14031403
size_t NameLen = 0;
@@ -1406,14 +1406,17 @@ int32 CFE_ES_RegisterCDS(CFE_ES_CDSHandle_t *CDSHandlePtr, int32 BlockSize, cons
14061406
char AppName[OS_MAX_API_NAME] = {"UNKNOWN"};
14071407
char CDSName[CFE_ES_CDS_MAX_FULL_NAME_LEN] = {""};
14081408

1409+
/* Initialize output to safe value, in case this fails */
1410+
*CDSHandlePtr = CFE_ES_RESOURCEID_UNDEFINED;
1411+
14091412
/* Check to make sure calling application is legit */
14101413
Status = CFE_ES_GetAppID(&ThisAppId);
14111414

14121415
if ( Status != CFE_SUCCESS ) /* Application ID was invalid */
14131416
{
14141417
CFE_ES_WriteToSysLog("CFE_CDS:Register-Bad AppId context\n");
14151418
}
1416-
else if (CFE_ES_Global.CDSVars.MemPoolSize == 0)
1419+
else if (!CFE_ES_Global.CDSIsAvailable)
14171420
{
14181421
CFE_ES_WriteToSysLog("CFE_CDS:Register-CDS not available\n");
14191422
Status = CFE_ES_NOT_IMPLEMENTED;
@@ -1441,16 +1444,13 @@ int32 CFE_ES_RegisterCDS(CFE_ES_CDSHandle_t *CDSHandlePtr, int32 BlockSize, cons
14411444
/* of the form "AppName.Name" */
14421445
CFE_ES_FormCDSName(CDSName, Name, ThisAppId);
14431446

1444-
/* Make sure the specified size is acceptable */
1445-
if (BlockSize == 0)
1446-
{
1447-
Status = CFE_ES_CDS_INVALID_SIZE;
1448-
CFE_ES_WriteToSysLog("CFE_CDS:Register-CDS %s has size of zero\n", Name);
1449-
}
1450-
else
1447+
/* Create CDS and designate it as NOT being a Critical Table */
1448+
Status = CFE_ES_RegisterCDSEx(CDSHandlePtr, BlockSize, CDSName, false);
1449+
1450+
/* If size is unacceptable, log it */
1451+
if (Status == CFE_ES_CDS_INVALID_SIZE)
14511452
{
1452-
/* Create CDS and designate it as NOT being a Critical Table */
1453-
Status = CFE_ES_RegisterCDSEx(CDSHandlePtr, BlockSize, CDSName, false);
1453+
CFE_ES_WriteToSysLog("CFE_CDS:Register-CDS %s has invalid size (%lu)\n", Name, (unsigned long)BlockSize);
14541454
}
14551455
}
14561456
}
@@ -1479,11 +1479,7 @@ int32 CFE_ES_RegisterCDS(CFE_ES_CDSHandle_t *CDSHandlePtr, int32 BlockSize, cons
14791479
*/
14801480
int32 CFE_ES_CopyToCDS(CFE_ES_CDSHandle_t Handle, void *DataToCopy)
14811481
{
1482-
int32 Status;
1483-
1484-
Status = CFE_ES_CDSBlockWrite(CFE_ES_Global.CDSVars.Registry[Handle].MemHandle, DataToCopy);
1485-
1486-
return Status;
1482+
return CFE_ES_CDSBlockWrite(Handle, DataToCopy);
14871483
} /* End of CFE_ES_CopyToCDS() */
14881484

14891485
/*
@@ -1494,11 +1490,7 @@ int32 CFE_ES_CopyToCDS(CFE_ES_CDSHandle_t Handle, void *DataToCopy)
14941490
*/
14951491
int32 CFE_ES_RestoreFromCDS(void *RestoreToMemory, CFE_ES_CDSHandle_t Handle)
14961492
{
1497-
int32 Status;
1498-
1499-
Status = CFE_ES_CDSBlockRead(RestoreToMemory, CFE_ES_Global.CDSVars.Registry[Handle].MemHandle);
1500-
1501-
return Status;
1493+
return CFE_ES_CDSBlockRead(RestoreToMemory, Handle);
15021494
} /* End of CFE_ES_RestoreFromCDS() */
15031495

15041496
/* end of file */

0 commit comments

Comments
 (0)