Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #210, Add SB API to get pipe by name #404

Merged
merged 2 commits into from
Feb 12, 2020

Conversation

CDKnightNASA
Copy link
Contributor

Describe the contribution
Fixes issue #210

Testing performed
make mission-all; run cpu1/cfe_core_default_cpu1/unit-test/cfe_core_default_cpu1_sb_UT

Expected behavior changes
Adds a new function, CFE_SB_GetPipeIdByName, which retrieves the pipe ID given a name of a pipe. As this would conflict with the removal of the PipeName from the PipeTbl, this code uses the OS_QueueGetIdByName and iterates across the PipeTbl to find the matching entry.

System(s) tested on:
Ubuntu 64-bit Linux 19.04.

Contributor Info
Chris Knight, NASA Ames Research Center.

@skliper skliper requested review from a user and jphickey November 13, 2019 17:20
@skliper
Copy link
Contributor

skliper commented Nov 13, 2019

CCB 20191113 - pipe id and queue id are of different sizes/types, could look into collapsing into 1 type, associated with the type safe ticket also, could also optimize by mapping them 1 to 1.

@skliper
Copy link
Contributor

skliper commented Nov 13, 2019

CCB 20191123 - approved for integration candidate, under additional review by jphickey and acudmore

@skliper skliper added the CCB:Approved Indicates code review and approval by community CCB label Nov 13, 2019
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approve.

fsw/cfe-core/src/inc/cfe_sb.h Show resolved Hide resolved
fsw/cfe-core/src/inc/cfe_sb_msg.h Outdated Show resolved Hide resolved
Copy link
Contributor

@jphickey jphickey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CFE_SB_GetPipeIdByName function needs some changes in how it handles the locking. It is holding the lock for too long and calling into other subsystems while holding the lock. We just had to fix a similar issue in EVS where it was sending events while holding a global lock.

The "core" of the function should take the global lock, do the necessary searching, and either copy the pipeid value to the output buffer (success) or increment an appropriate counter (failure). It should then release the SB lock, and then to the actual CFE_EVS_SendEvent associated with it (debug event on success, or appropriate error event on failure).

Also, since CFE_SB_GetPipeIdByName is being added to the public SB API, it needs a stub function implemented in ut_sb_stubs.c too. I'd suggest using CFE_ES_GetAppIdByName stub as a guide but that one is more complex than necessary (I think it had to support some existing oddball test scenarios). It should be just as simple as using the UT_DEFAULT_IMPL macro followed up by a UT_Stub_CopyToLocal() to allow a test case to provide its own outputs.

fsw/cfe-core/src/inc/cfe_sb_msg.h Show resolved Hide resolved
@CDKnightNASA
Copy link
Contributor Author

Also, since CFE_SB_GetPipeIdByName is being added to the public SB API, it needs a stub function implemented in ut_sb_stubs.c too. I'd suggest using CFE_ES_GetAppIdByName stub as a guide but that one is more complex than necessary (I think it had to support some existing oddball test scenarios). It should be just as simple as using the UT_DEFAULT_IMPL macro followed up by a UT_Stub_CopyToLocal() to allow a test case to provide its own outputs.

Looking at the CFE_ES_GetAppIDByName, I realize there is no CFE_SB_GetPipeName(char *buf, PipeId_t id) ...should I add it?

Also while a bit nit-picky, it's good to resolve these things for a style guide. I note two things:

  1. ES uses "AppID" most places, not "AppId" in names of functions. SB uses PipeId. We should decide which is "suggested style" for our style guide.

  2. I'm not fond of GetFoo(char *OutBuf, int inId, size_t BufLen), would prefer the len variable be adjacent to the outbuf variable, so GetFoo(char *OutBuf, size_t BufLen, int inId.)

I've captured both in my draft "style" doc (in the fix-404-contributing branch) as "to be decided." Along with other TBD's.

@skliper
Copy link
Contributor

skliper commented Dec 4, 2019

CCB - 12/4/2019: Consider adding an OSAL API which just retrieves the name of a resource, simplifies this issue and the other's related

@CDKnightNASA
Copy link
Contributor Author

I need to squash

@skliper skliper added this to the 6.8.0 milestone Dec 17, 2019
@skliper skliper changed the title fix for issue 210 Fix #210, Add SB API to get pipe by name Jan 7, 2020
@skliper
Copy link
Contributor

skliper commented Jan 7, 2020

Is this ready for merge to integration branch? I don't see all the requests being closed out. @acudmore @jphickey

@jphickey
Copy link
Contributor

jphickey commented Jan 7, 2020

I would still like to see this squashed and rebased into a single commit. There is lots of back and forth on the branch now (incl. some bogus/mistake commits). This should be cleaned up before merging.

@CDKnightNASA
Copy link
Contributor Author

CDKnightNASA commented Jan 7, 2020 via email

@skliper
Copy link
Contributor

skliper commented Jan 14, 2020

I rebased on current master and squashed for review. @acudmore and @jphickey please re-review.

Copy link
Contributor

@jphickey jphickey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still needs some minor updates. Correct the size in strncpy() call and use the sizeof operator instead of hardcoded size. (Latter is not a huge deal for local variables, but a bigger deal when referring to externally defined telemetry definitions).

}else{
if (OS_QueueGetInfo(CFE_SB.PipeTbl[PipeId].SysQueueId, &queue_prop)
== OS_SUCCESS){
strncpy(PipeNameBuf, queue_prop.name, OS_MAX_API_NAME-1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to use PipeNameSize, not OS_MAX_API_NAME-1. It should also ensure a null-terminated output.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hate to be a pain, but still need to make sure that the output is null terminated. This should also handle the case if the passed in size is 0 (since it is handling a passed-in buffer of NULL, should handle this too).

fsw/cfe-core/src/sb/cfe_sb_api.c Outdated Show resolved Hide resolved
fsw/cfe-core/src/sb/cfe_sb_task.c Outdated Show resolved Hide resolved
@skliper
Copy link
Contributor

skliper commented Jan 14, 2020

Analyzing log I see I should have done the squash differently (new method used successfully on #452) to retain authorship by Chris.

@CDKnightNASA
Copy link
Contributor Author

CDKnightNASA commented Jan 14, 2020 via email

@CDKnightNASA
Copy link
Contributor Author

re-squashed

Copy link
Contributor

@jphickey jphickey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy with the sizeof() operations now, but still a couple issues in the CFE_SB_GetPipeName() API. Should handle a passed in buffer size of 0 (this can be checked at the same time as the NULL buffer, first conditional) and should also ensure that the buffer output is always null terminated.

Moves CFE_SB_GetPipeName to public API
Adds CFE_SB_GetPipeIdByName
Adds 6 related events
Adds to SB HK packet (GetPipeIdByNameErrorCounter)
Updates associated internal name logic
Unit tests and stubs added
@skliper
Copy link
Contributor

skliper commented Jan 22, 2020

CCB 20200122 - Reviewed and approved for CI

@astrogeco astrogeco changed the base branch from master to ic-20200213 February 11, 2020 02:24
@astrogeco astrogeco linked an issue Feb 11, 2020 that may be closed by this pull request
@astrogeco astrogeco merged commit b9269fa into nasa:ic-20200213 Feb 12, 2020
astrogeco added a commit that referenced this pull request Feb 12, 2020
jphickey added a commit that referenced this pull request Feb 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CCB:Approved Indicates code review and approval by community CCB enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

no way to find an existing pipe ID by name
4 participants