Skip to content

Commit

Permalink
Adds a progress callback to the memory config client. (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsracz authored Oct 19, 2020
1 parent f6264bc commit 7896fc0
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/openlcb/MemoryConfigClient.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ struct MemoryConfigClientRequest : public CallableFlowRequestBase
/// @param ReadCmd polymorphic matching arg; always set to READ.
/// @param d is the destination node to query
/// @param space is the memory space to read out
void reset(ReadCmd, NodeHandle d, uint8_t space)
/// @param cb if specified, will be called inline multiple times during the
/// processing as more data arrives.
void reset(ReadCmd, NodeHandle d, uint8_t space,
std::function<void(MemoryConfigClientRequest *)> cb = nullptr)
{
reset_base();
cmd = CMD_READ;
Expand All @@ -92,6 +95,7 @@ struct MemoryConfigClientRequest : public CallableFlowRequestBase
address = 0;
size = 0xffffffffu;
payload.clear();
progressCb = std::move(cb);
}

/// Sets up a command to read a part of a memory space.
Expand Down Expand Up @@ -201,13 +205,26 @@ struct MemoryConfigClientRequest : public CallableFlowRequestBase
CMD_WRITE,
CMD_META_REQUEST
};

/// Helper function invoked at every other reset call.
void reset_base()
{
CallableFlowRequestBase::reset_base();
progressCb = nullptr;
payload.clear();
size = 0;
address = 0;
}

Command cmd;
uint8_t memory_space;
unsigned address;
unsigned size;
/// Node to send the request to.
NodeHandle dst;
string payload;
/// Callback to execute as progress is being made.
std::function<void(MemoryConfigClientRequest *)> progressCb;
};

class MemoryConfigClient : public CallableFlow<MemoryConfigClientRequest>
Expand Down Expand Up @@ -364,6 +381,10 @@ private:
unsigned dlen = len - ofs;
request()->payload.append((char *)(bytes + ofs), dlen);
offset_ += dlen;
if (request()->progressCb)
{
request()->progressCb(request());
}
if ((dlen < 64) || (request()->size == 0))
{
return call_immediately(STATE(finish_read));
Expand Down

0 comments on commit 7896fc0

Please sign in to comment.