Skip to content

Commit

Permalink
Adds stream support to MemoryConfigClient (#688)
Browse files Browse the repository at this point in the history
- Adds new commands to the MemoryConfigClientRequest to initiate stream reads.
- Adds a subclass MemoryConfigClientWithStream that can be instantiated instead of MemoryConfigClient if the application needs to use the new stream feature.

Misc: 
- Adds helper function to generate a memory config stream read payload.
- Adds support in the Stream Receiver to cancel a started stream receive. This is needed when the memory config datagram is rejected. To support this, the StreamReceiver state flow has to keep track of when it sleeps.
- Fixes bugs in the stream sender; the registration was not removed for stream proceed.
- Adds an API to StreamTransport to allocate identifiers for stream DIDs. These are static, i.e., they are expected to be taken once per instantiated object and not change over time.
- Adds API on SimpleStack to instantiate the stream support components. When this API is called, the StreamTransportCan object is created, and the MemoryConfigStreamHandler is added. If the API is not called, this code is not linked into the binary at all (it's about 6k extra flash on a CM4).
- Adds a new bit in the memory config Options Read reply to indicate that stream reads are available. Auto-detects this based on whether the extra objects are instantiated or not.
- Adds a link-time constant for how many stream senders to instantiate.
- Switches dynamic_cast<> to static_cast<> because we build application binaries with -fno-rtti.

===

* Adds API for stream-based clients.
Adds a subclass for stream aware memcfg client.

* Implements stream reads in the memory config stream client.

* Adds an API to allocate a new receive stream ID in a semi-static manner.

* Fix incorrect comment.

* Invokes the client progress callback.

* Adds test case with error in the memory config datagram.

* Fixes bugs in client.
Adds a (working) endtoend test with  memcfg client.

* Adds an e2e test for an error (which crashes).

* Adds a (successful) erroneous read example.

* Adds a non-working error example.

* Adds cancellation support to the stream receiver.
This is needed in the memory config interactions: we have to set up the stream receiver before sending the
read request datagram to the remote, but the read request might fail without ever
opening the stream, so the stream receiver ends up waiting forever.

* Cleans up stream state after a memory config datagram receive error happens.

* Ensures we don't go to sleep when a cancellation is pending.

* Fix whitespace.

* Adds unit tests for the callbacks.

* Adds a definition for stream read command availability.

* Adds stream support features to simplestack.

* Switchesfrom dynamic_cast<> to static_cast<> because we build applications with
-fno-rtti.

* Fixes an incorrect comment.

* Fixes some compilation bugs.

* Adds a helper function for GDB.
  • Loading branch information
balazsracz authored Dec 28, 2022
1 parent c300e8f commit 8905b17
Show file tree
Hide file tree
Showing 14 changed files with 603 additions and 50 deletions.
4 changes: 4 additions & 0 deletions include/nmranet_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ DECLARE_CONST(num_datagram_registry_entries);
* happen concurrently. */
DECLARE_CONST(num_datagram_clients);

/** Number of stream senders. This is how many stream send operations can
* happen concurrently. */
DECLARE_CONST(num_stream_senders);

/** Maximum number of memory spaces that can be registered for the MemoryConfig
* datagram handler. */
DECLARE_CONST(num_memory_spaces);
Expand Down
7 changes: 7 additions & 0 deletions src/openlcb/MemoryConfig.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,8 @@ private:
case MemoryConfigDefs::COMMAND_WRITE_STREAM_FAILED:
case MemoryConfigDefs::COMMAND_READ_REPLY:
case MemoryConfigDefs::COMMAND_READ_FAILED:
case MemoryConfigDefs::COMMAND_READ_STREAM_REPLY:
case MemoryConfigDefs::COMMAND_READ_STREAM_FAILED:
case MemoryConfigDefs::COMMAND_OPTIONS_REPLY:
case MemoryConfigDefs::COMMAND_INFORMATION_REPLY:
case MemoryConfigDefs::COMMAND_LOCK_REPLY:
Expand All @@ -730,6 +732,7 @@ private:
client_->send(transfer_message());
return exit();
}
LOG(VERBOSE, "memcfg handler reply: no client registered");
} // fall through to unsupported.
default:
// Unknown/unsupported command, reject datagram.
Expand Down Expand Up @@ -775,6 +778,10 @@ private:
response_.push_back(MemoryConfigDefs::COMMAND_OPTIONS_REPLY);
uint16_t available_commands =
MemoryConfigDefs::AVAIL_UR | MemoryConfigDefs::AVAIL_UW;
if (streamHandler_)
{
available_commands |= MemoryConfigDefs::AVAIL_SR;
}
// Figure out about ACDI spaces
MemorySpace* memspace = registry_.lookup(message()->data()->dst, 0xFC);
if (memspace) {
Expand Down
Loading

0 comments on commit 8905b17

Please sign in to comment.