Skip to content

Commit

Permalink
Add ensureSingleBuffer in slave class
Browse files Browse the repository at this point in the history
  • Loading branch information
slacrherbst committed Aug 9, 2023
1 parent 761c5c2 commit a40e8dc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
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

0 comments on commit a40e8dc

Please sign in to comment.