Skip to content

Commit 721ca3f

Browse files
Merge pull request #2852 from Cameron-Sykes/fix-2851-cfe-sb-api-cleanup
Fix #2851, Clean up from cfe_sb_api.c complexity reduction
2 parents ef95018 + c47340b commit 721ca3f

5 files changed

Lines changed: 45 additions & 40 deletions

File tree

‎modules/core_api/fsw/inc/cfe_error.h‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -858,17 +858,6 @@ char *CFE_ES_StatusToString(CFE_Status_t status, CFE_StatusString_t *status_stri
858858
*/
859859
#define CFE_SB_BUFFER_INVALID ((CFE_Status_t)0xca00000e)
860860

861-
/**
862-
* @brief Destination Pipe Already Exists on this Path
863-
*
864-
* This error code will be returned when a destination from the routing
865-
* table has the same pipe ID as the provided pipe ID. It's set to
866-
* CFE_SUCCESS because it's not an error per se, it's a status that
867-
* needs to noted for accounting and event reasons
868-
*
869-
*/
870-
#define CFE_SB_DUP_SUBSCRIP_ERR (CFE_SUCCESS)
871-
872861
/**
873862
* @brief Not Implemented
874863
*

‎modules/sb/fsw/src/cfe_sb_api.c‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,6 @@ int32 CFE_SB_SubscribeFull(CFE_SB_MsgId_t MsgId,
10241024
if (CFE_RESOURCEID_TEST_EQUAL(DestPtr->PipeId, PipeId))
10251025
{
10261026
PendingEventID = CFE_SB_DUP_SUBSCRIP_EID;
1027-
Status = CFE_SB_DUP_SUBSCRIP_ERR;
10281027
break;
10291028
}
10301029

@@ -1073,18 +1072,12 @@ int32 CFE_SB_SubscribeFull(CFE_SB_MsgId_t MsgId,
10731072
}
10741073

10751074
/* Increment counter before unlock */
1076-
if (PendingEventID != 0)
1077-
{
1078-
CFE_SB_IncrementSubscribeCounters(Status);
1079-
}
1075+
CFE_SB_IncrementSubscribeCounters(PendingEventID);
10801076

10811077
CFE_SB_UnlockSharedData(__func__, __LINE__);
10821078

10831079
/* Send events now that the SB resources are unlocked */
1084-
if (PendingEventID != 0)
1085-
{
1086-
CFE_SB_IssueSubscribeEvents(PendingEventID, PipeId, MsgId, Scope);
1087-
}
1080+
CFE_SB_IssueSubscribeEvents(PendingEventID, PipeId, MsgId, Scope);
10881081

10891082
/* If no other event pending, send a debug event indicating success */
10901083
if (Status == CFE_SUCCESS && PendingEventID == 0)

‎modules/sb/fsw/src/cfe_sb_priv.c‎

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,34 +1644,51 @@ CFE_Status_t CFE_SB_GetPipeNamePriv(CFE_SB_PipeId_t PipeId, char *PipeNameBuf, s
16441644
return Status;
16451645
}
16461646

1647-
void CFE_SB_IncrementSubscribeCounters(CFE_Status_t ErrorStatus)
1647+
/*----------------------------------------------------------------
1648+
*
1649+
* Application-scope internal function
1650+
* See description in header file for argument/return detail
1651+
*
1652+
*-----------------------------------------------------------------*/
1653+
void CFE_SB_IncrementSubscribeCounters(uint16 EventID)
16481654
{
1649-
switch (ErrorStatus)
1655+
switch (EventID)
16501656
{
1651-
case CFE_SB_BAD_ARGUMENT:
1652-
case CFE_SB_MAX_MSGS_MET:
1653-
case CFE_SB_BUF_ALOC_ERR:
1654-
case CFE_SB_MAX_DESTS_MET:
1657+
case CFE_SB_SUB_INV_PIPE_EID:
1658+
case CFE_SB_SUB_INV_CALLER_EID:
1659+
case CFE_SB_SUB_ARG_ERR_EID:
1660+
case CFE_SB_MAX_MSGS_MET_EID:
1661+
case CFE_SB_MAX_DESTS_MET_EID:
1662+
case CFE_SB_DEST_BLK_ERR_EID:
16551663
CFE_SB_Global.HKTlmMsg.Payload.SubscribeErrorCounter++;
16561664
break;
1657-
case CFE_SB_DUP_SUBSCRIP_ERR:
1665+
case CFE_SB_DUP_SUBSCRIP_EID:
16581666
CFE_SB_Global.HKTlmMsg.Payload.DuplicateSubscriptionsCounter++;
16591667
break;
1668+
default:
1669+
/* If there isn't an error, don't increment error counters */
1670+
break;
16601671
}
16611672
}
16621673

1674+
/*----------------------------------------------------------------
1675+
*
1676+
* Application-scope internal function
1677+
* See description in header file for argument/return detail
1678+
*
1679+
*-----------------------------------------------------------------*/
16631680
void CFE_SB_IssueSubscribeEvents(uint16 PendingEventID, CFE_SB_PipeId_t PipeId, CFE_SB_MsgId_t MsgId, uint16 Scope)
16641681
{
16651682
CFE_ES_TaskId_t TskId;
16661683
char FullName[(OS_MAX_API_NAME * 2)];
16671684
char PipeName[OS_MAX_API_NAME];
16681685

1669-
CFE_ES_GetTaskID(&TskId);
1670-
CFE_SB_GetPipeName(PipeName, sizeof(PipeName), PipeId);
1671-
16721686
switch (PendingEventID)
16731687
{
16741688
case CFE_SB_DUP_SUBSCRIP_EID:
1689+
CFE_ES_GetTaskID(&TskId);
1690+
CFE_SB_GetPipeName(PipeName, sizeof(PipeName), PipeId);
1691+
16751692
CFE_EVS_SendEventWithAppID(CFE_SB_DUP_SUBSCRIP_EID,
16761693
CFE_EVS_EventType_INFORMATION,
16771694
CFE_SB_Global.AppId,
@@ -1680,8 +1697,8 @@ void CFE_SB_IssueSubscribeEvents(uint16 PendingEventID, CFE_SB_PipeId_t PipeId,
16801697
PipeName,
16811698
CFE_SB_GetAppTskName(TskId, FullName));
16821699
break;
1683-
16841700
case CFE_SB_SUB_INV_CALLER_EID:
1701+
CFE_ES_GetTaskID(&TskId);
16851702
CFE_EVS_SendEventWithAppID(CFE_SB_SUB_INV_CALLER_EID,
16861703
CFE_EVS_EventType_ERROR,
16871704
CFE_SB_Global.AppId,
@@ -1690,8 +1707,8 @@ void CFE_SB_IssueSubscribeEvents(uint16 PendingEventID, CFE_SB_PipeId_t PipeId,
16901707
CFE_RESOURCEID_TO_ULONG(PipeId),
16911708
(unsigned int)CFE_SB_MsgIdToValue(MsgId));
16921709
break;
1693-
16941710
case CFE_SB_SUB_INV_PIPE_EID:
1711+
CFE_ES_GetTaskID(&TskId);
16951712
CFE_EVS_SendEventWithAppID(CFE_SB_SUB_INV_PIPE_EID,
16961713
CFE_EVS_EventType_ERROR,
16971714
CFE_SB_Global.AppId,
@@ -1700,16 +1717,17 @@ void CFE_SB_IssueSubscribeEvents(uint16 PendingEventID, CFE_SB_PipeId_t PipeId,
17001717
CFE_RESOURCEID_TO_ULONG(PipeId),
17011718
CFE_SB_GetAppTskName(TskId, FullName));
17021719
break;
1703-
17041720
case CFE_SB_DEST_BLK_ERR_EID:
17051721
CFE_EVS_SendEventWithAppID(CFE_SB_DEST_BLK_ERR_EID,
17061722
CFE_EVS_EventType_ERROR,
17071723
CFE_SB_Global.AppId,
17081724
"Subscribe Err:Request for Destination Blk failed for Msg 0x%x",
17091725
(unsigned int)CFE_SB_MsgIdToValue(MsgId));
17101726
break;
1711-
17121727
case CFE_SB_MAX_DESTS_MET_EID:
1728+
CFE_ES_GetTaskID(&TskId);
1729+
CFE_SB_GetPipeName(PipeName, sizeof(PipeName), PipeId);
1730+
17131731
CFE_EVS_SendEventWithAppID(CFE_SB_MAX_DESTS_MET_EID,
17141732
CFE_EVS_EventType_ERROR,
17151733
CFE_SB_Global.AppId,
@@ -1719,8 +1737,10 @@ void CFE_SB_IssueSubscribeEvents(uint16 PendingEventID, CFE_SB_PipeId_t PipeId,
17191737
PipeName,
17201738
CFE_SB_GetAppTskName(TskId, FullName));
17211739
break;
1722-
17231740
case CFE_SB_MAX_MSGS_MET_EID:
1741+
CFE_ES_GetTaskID(&TskId);
1742+
CFE_SB_GetPipeName(PipeName, sizeof(PipeName), PipeId);
1743+
17241744
CFE_EVS_SendEventWithAppID(CFE_SB_MAX_MSGS_MET_EID,
17251745
CFE_EVS_EventType_ERROR,
17261746
CFE_SB_Global.AppId,
@@ -1730,8 +1750,8 @@ void CFE_SB_IssueSubscribeEvents(uint16 PendingEventID, CFE_SB_PipeId_t PipeId,
17301750
PipeName,
17311751
CFE_SB_GetAppTskName(TskId, FullName));
17321752
break;
1733-
17341753
case CFE_SB_SUB_ARG_ERR_EID:
1754+
CFE_ES_GetTaskID(&TskId);
17351755
CFE_EVS_SendEventWithAppID(CFE_SB_SUB_ARG_ERR_EID,
17361756
CFE_EVS_EventType_ERROR,
17371757
CFE_SB_Global.AppId,
@@ -1741,5 +1761,8 @@ void CFE_SB_IssueSubscribeEvents(uint16 PendingEventID, CFE_SB_PipeId_t PipeId,
17411761
CFE_SB_GetAppTskName(TskId, FullName),
17421762
Scope);
17431763
break;
1764+
default:
1765+
/* No error means no event issued */
1766+
break;
17441767
}
1745-
}
1768+
}

‎modules/sb/fsw/src/cfe_sb_priv.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,7 @@ void CFE_SB_BackgroundFileEventHandler(void *Meta,
15241524
** \brief Local function that increments the subscription counters based on the Status
15251525
** of the subscribe function to that point
15261526
*/
1527-
void CFE_SB_IncrementSubscribeCounters(CFE_Status_t ErrorStatus);
1527+
void CFE_SB_IncrementSubscribeCounters(uint16 EventID);
15281528

15291529
/*---------------------------------------------------------------------------------------
15301530
**

‎modules/sb/ut-coverage/sb_UT.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,7 +2233,7 @@ void Test_Subscribe_InvalidPipeId(void)
22332233

22342234
UtAssert_INT32_EQ(CFE_SB_Subscribe(MsgId, PipeId), CFE_SB_BAD_ARGUMENT);
22352235

2236-
CFE_UtAssert_EVENTCOUNT(2);
2236+
CFE_UtAssert_EVENTCOUNT(1);
22372237

22382238
CFE_UtAssert_EVENTSENT(CFE_SB_SUB_INV_PIPE_EID);
22392239
}
@@ -2473,7 +2473,7 @@ void Test_Subscribe_PipeNonexistent(void)
24732473

24742474
UtAssert_INT32_EQ(CFE_SB_Subscribe(MsgId, PipeId), CFE_SB_BAD_ARGUMENT);
24752475

2476-
CFE_UtAssert_EVENTCOUNT(2);
2476+
CFE_UtAssert_EVENTCOUNT(1);
24772477

24782478
CFE_UtAssert_EVENTSENT(CFE_SB_SUB_INV_PIPE_EID);
24792479
}

0 commit comments

Comments
 (0)