Skip to content

Commit

Permalink
Fix #2546, add handle list operation routines
Browse files Browse the repository at this point in the history
Adds a "HandleLink" structure to encapsulate the linked list
functionality and add generic routines to initialize and test/check
this structure, along with list insert/remove functions for
access descriptors that use this link struct interally.

This also cleans up documentation of the table resource ID functions
defined in cfe_tbl_resource.h
  • Loading branch information
jphickey committed Apr 5, 2024
1 parent 5a1034b commit b13c79f
Show file tree
Hide file tree
Showing 9 changed files with 520 additions and 538 deletions.
52 changes: 23 additions & 29 deletions modules/tbl/fsw/src/cfe_tbl_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,8 @@ CFE_Status_t CFE_TBL_Share(CFE_TBL_Handle_t *TblHandlePtr, const char *TblName)
AccessDescPtr->RegIndex = CFE_TBL_TxnRegId(&Txn);
AccessDescPtr->UsedFlag = true;

AccessDescPtr->PrevLink = CFE_TBL_END_OF_LIST; /* We are the new head of the list */
AccessDescPtr->NextLink = RegRecPtr->HeadOfAccessList;

/* Make sure the old head of the list now sees this as the head */
CFE_TBL_Global.Handles[RegRecPtr->HeadOfAccessList].PrevLink = CFE_TBL_TxnHandle(&Txn);

/* Make sure the Registry Record see this as the head of the list */
RegRecPtr->HeadOfAccessList = CFE_TBL_TxnHandle(&Txn);
CFE_TBL_HandleLinkInit(&AccessDescPtr->Link);
CFE_TBL_HandleListInsertLink(RegRecPtr, AccessDescPtr);
}

CFE_TBL_TxnFinish(&Txn);
Expand Down Expand Up @@ -647,7 +641,7 @@ CFE_Status_t CFE_TBL_Update(CFE_TBL_Handle_t TblHandle)
/*
* Note that (Status < 0) specifically matches ERROR, not WARNING codes. The CFE_TBL_UpdateInternal() function
* currently only produces two possible codes (aside from CFE_SUCCESS) and both of these are defined as
* warnings, not errors. Therefore, its impossible to reach this code with RegRegPtr != NULL.
* warnings, not errors. Therefore, its impossible to reach this code with RegRecPtr != NULL.
*/
CFE_EVS_SendEventWithAppID(CFE_TBL_UPDATE_ERR_EID, CFE_EVS_EventType_ERROR, CFE_TBL_Global.TableTaskAppId,
"%s Failed to update table, Status=0x%08X", AppName, (unsigned int)Status);
Expand Down Expand Up @@ -1088,7 +1082,6 @@ CFE_Status_t CFE_TBL_GetInfo(CFE_TBL_Info_t *TblInfoPtr, const char *TblName)
int32 Status = CFE_SUCCESS;
int32 NumAccessDescriptors = 0;
CFE_TBL_RegistryRec_t *RegRecPtr;
CFE_TBL_Handle_t HandleIterator;

if (TblInfoPtr == NULL || TblName == NULL)
{
Expand Down Expand Up @@ -1117,13 +1110,7 @@ CFE_Status_t CFE_TBL_GetInfo(CFE_TBL_Info_t *TblInfoPtr, const char *TblName)
strncpy(TblInfoPtr->LastFileLoaded, RegRecPtr->LastFileLoaded, sizeof(TblInfoPtr->LastFileLoaded) - 1);
TblInfoPtr->LastFileLoaded[sizeof(TblInfoPtr->LastFileLoaded) - 1] = 0;

/* Count the number of Access Descriptors to determine the number of users */
HandleIterator = RegRecPtr->HeadOfAccessList;
while (HandleIterator != CFE_TBL_END_OF_LIST)
{
NumAccessDescriptors++;
HandleIterator = CFE_TBL_Global.Handles[HandleIterator].NextLink;
}
CFE_TBL_ForeachAccessDescriptor(RegRecPtr, CFE_TBL_CountAccessDescHelper, &NumAccessDescriptors);

TblInfoPtr->NumUsers = NumAccessDescriptors;

Expand Down Expand Up @@ -1190,6 +1177,23 @@ CFE_Status_t CFE_TBL_DumpToBuffer(CFE_TBL_Handle_t TblHandle)
return Status;
}

/*----------------------------------------------------------------
*
* Local helper function, not invoked outside this unit
* Intended to be used with CFE_TBL_ForeachAccessDescriptor()
*
*-----------------------------------------------------------------*/
static void CFE_TBL_NotifyOtherAppHelper(CFE_TBL_AccessDescriptor_t *AccessDescPtr, void *Arg)
{
CFE_TBL_TxnState_t *Txn = Arg;

/* Only notify *OTHER* applications that the contents have changed */
if (!CFE_RESOURCEID_TEST_EQUAL(AccessDescPtr->AppId, CFE_TBL_TxnAppId(Txn)))

Check warning

Code scanning / CodeQL-coding-standard

Side effect in a Boolean expression Warning

This Boolean expression is not side-effect free.
{
AccessDescPtr->Updated = true;
}
}

/*----------------------------------------------------------------
*
* Implemented per public API
Expand All @@ -1201,7 +1205,6 @@ CFE_Status_t CFE_TBL_Modified(CFE_TBL_Handle_t TblHandle)
CFE_TBL_TxnState_t Txn;
int32 Status;
CFE_TBL_RegistryRec_t *RegRecPtr = NULL;
CFE_TBL_Handle_t AccessIterator;
CFE_ES_AppId_t ThisAppId;
size_t FilenameLen;

Expand Down Expand Up @@ -1241,17 +1244,8 @@ CFE_Status_t CFE_TBL_Modified(CFE_TBL_Handle_t TblHandle)
strncpy(&RegRecPtr->LastFileLoaded[sizeof(RegRecPtr->LastFileLoaded) - 4], "(*)", 4);
}

AccessIterator = RegRecPtr->HeadOfAccessList;
while (AccessIterator != CFE_TBL_END_OF_LIST)
{
/* Only notify *OTHER* applications that the contents have changed */
if (!CFE_RESOURCEID_TEST_EQUAL(CFE_TBL_Global.Handles[AccessIterator].AppId, ThisAppId))
{
CFE_TBL_Global.Handles[AccessIterator].Updated = true;
}

AccessIterator = CFE_TBL_Global.Handles[AccessIterator].NextLink;
}
/* Only notify *OTHER* applications that the contents have changed */
CFE_TBL_ForeachAccessDescriptor(RegRecPtr, CFE_TBL_NotifyOtherAppHelper, &Txn);
}
else
{
Expand Down
Loading

0 comments on commit b13c79f

Please sign in to comment.