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

Add ensureSingleBuffer in slave class #965

Merged
merged 2 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions include/rogue/interfaces/stream/Slave.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@ class Slave : public rogue::interfaces::stream::Pool,
*/
uint64_t getByteCount();

//! Ensure frame is a single buffer
/** This method makes sure the passed frame is composed of a single buffer.
* If the reqNew flag is true and the passed frame is not a single buffer, a
* new frame will be requested and the frame data will be copied, with the passed
* frame pointer being updated. The return value will indicate if the frame is a
* single buffer at the end of the process. A frame lock must be held when this
* method is called.
*
* Not exposed to Python
* @param frame Reference to frame pointer (FramePtr)
* @param rewEn Flag to determine if a new frame should be requested
*/
bool ensureSingleBuffer(std::shared_ptr<rogue::interfaces::stream::Frame>& frame, bool reqEn);

#ifndef NO_PYTHON

//! Support << operator in python
Expand Down
29 changes: 29 additions & 0 deletions src/rogue/interfaces/stream/Slave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,35 @@ uint64_t ris::Slave::getByteCount() {
return (frameBytes_);
}

// Ensure passed frame is a single buffer
bool ris::Slave::ensureSingleBuffer(ris::FramePtr& frame, bool reqEn) {
// Frame is a single buffer
if (frame->bufferCount() == 1)
return true;

else if (!reqEn)
return false;

else {
uint32_t size = frame->getPayload();
ris::FramePtr nFrame = acceptReq(size, true);

if (nFrame->bufferCount() != 1)
return false;

else {
nFrame->setPayload(size);

ris::FrameIterator srcIter = frame->begin();
ris::FrameIterator dstIter = nFrame->begin();

ris::copyFrame(srcIter, size, dstIter);
frame = nFrame;
return true;
}
}
}

void ris::Slave::setup_python() {
#ifndef NO_PYTHON

Expand Down