Add support for optional std::memory usage and refactor ChannelRx ini…#53
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces optional std::memory usage via conditional compilation and refactors the ChannelRx initialization pattern to support deferred deserializer setup. The changes enable the codebase to optionally build without standard library smart pointers (for embedded environments) while maintaining the same API through type aliases.
Key Changes:
- Refactored
ChannelRxto use default constructor +setDeserializer()method instead of constructor parameter validation - Added
USE_STD_MEMORYCMake option to conditionally enable/disablestd::shared_ptrusage, falling back to raw pointers - Introduced new
ClientandClientBlockingabstract base classes for L5 module client implementations
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| cpp/CMakeLists.txt | Adds USE_STD_MEMORY option to control smart pointer usage across the project |
| cpp/modules/l4/CMakeLists.txt | Conditionally defines USE_STD_MEMORY preprocessor macro for l4 module and tests |
| cpp/modules/l4/include/data.h | Conditionally defines pointer type aliases based on USE_STD_MEMORY; adds NullptrArgument error code |
| cpp/modules/l4/include/Channel.h | Replaces inline constructor with declaration; adds setDeserializer() method; removes <memory> and <expected> includes |
| cpp/modules/l4/src/Channel.cpp | Implements default constructor and setDeserializer() with null-check validation |
| cpp/modules/l4/src/impl/ChannelUnixTcp.cpp | Updates to use default constructor + setDeserializer() pattern with error handling |
| cpp/modules/l4/src/impl/ChannelUnixFile.cpp | Updates to use default constructor + setDeserializer() pattern with error handling |
| cpp/modules/l4/include/styxpico/ChannelUsbUart.h | Adds ChannelRx inheritance for bidirectional communication support |
| cpp/modules/l4/include/cxx_23/ChannelTx.h | Updates return type to use SizeResult type alias for consistency |
| cpp/modules/l5/CMakeLists.txt | Adds Client.cpp to the build sources |
| cpp/modules/l5/include/Client.h | Defines abstract Client and ClientBlocking base classes for client implementations |
| cpp/modules/l5/src/Client.cpp | Implements constructors, destructor, and setChannels() method for client classes |
| cpp/modules/l5/include/serialization/Deserializer.h | Adds L5 Deserializer class inheriting from DeserializerL4 |
Comments suppressed due to low confidence (1)
cpp/modules/l5/CMakeLists.txt:13
- Missing
USE_STD_MEMORYcompile definition for module_l5. The module usesChannelTxPtrandChannelRxPtrtypes which are conditionally defined based on theUSE_STD_MEMORYpreprocessor macro. Add the following after line 18:
if (USE_STD_MEMORY)
target_compile_definitions(module_l5 PUBLIC USE_STD_MEMORY)
target_compile_definitions(module_l5_tests PRIVATE USE_STD_MEMORY)
endif()Note: Use PUBLIC for module_l5 so that consumers of this library also get the correct definition.
add_library(module_l5 STATIC
src/Client.cpp
src/BufferWriterImpl.cpp
src/BufferReaderImpl.cpp
src/messages/base/StyxMessage.cpp
src/StyxSerializerImpl.cpp
src/StyxQID.cpp
src/StyxStat.cpp
src/messages/v9p2000/BaseMessage.cpp
src/messages/v9p2000/MessageFactoryImpl.cpp
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| config(config) | ||
| { | ||
| if (setDeserializer(config.deserializer) != ErrorCode::Success) { | ||
| throw std::invalid_argument("Deserializer cannot be null"); |
There was a problem hiding this comment.
Missing include for <stdexcept>. The code throws std::invalid_argument but the <stdexcept> header is not included in this file or in ChannelUnixFile.h. Add #include <stdexcept> to the includes at the top of this file.
| ChannelRxPtr channelRx; | ||
| public: | ||
| ClientBlocking(); | ||
| ~ClientBlocking(); |
There was a problem hiding this comment.
The destructor should be marked as override or virtual for consistency with the codebase convention. Since this class derives from Client which has a virtual destructor, and ClientBlocking is still abstract (has pure virtual sendBlocking), the destructor should follow the same pattern as other derived classes in the codebase. Change to:
virtual ~ClientBlocking() override = default;Or at minimum mark it as override:
~ClientBlocking() override;| ~ClientBlocking(); | |
| ~ClientBlocking() override; |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,38 @@ | |||
| #pragma once | |||
|
|
|||
| #include "messages/base/StyxMessage.h" | |||
There was a problem hiding this comment.
Missing include for ChannelTxPtr and ChannelRxPtr types. Add #include \"data.h\" or #include \"Channel.h\" to resolve the forward declarations used in lines 17-18.
| #include "messages/base/StyxMessage.h" | |
| #include "messages/base/StyxMessage.h" | |
| #include "Channel.h" |
| using SerializerPtr = std::shared_ptr<SerializerL4>; | ||
| #else | ||
| using SerializerL4Ptr = SerializerL4*; | ||
| using DeserializerL4Ptr = DeserializerL4*; | ||
| using ChannelRxPtr = ChannelRx*; | ||
| using ChannelTxPtr = ChannelTx*; | ||
| using SerializerPtr = SerializerL4*; |
There was a problem hiding this comment.
SerializerPtr is redundant with SerializerL4Ptr (line 50). Both define the same type alias for std::shared_ptr. Consider removing SerializerPtr or clarifying if they serve different purposes.
| using SerializerPtr = std::shared_ptr<SerializerL4>; | |
| #else | |
| using SerializerL4Ptr = SerializerL4*; | |
| using DeserializerL4Ptr = DeserializerL4*; | |
| using ChannelRxPtr = ChannelRx*; | |
| using ChannelTxPtr = ChannelTx*; | |
| using SerializerPtr = SerializerL4*; | |
| #else | |
| using SerializerL4Ptr = SerializerL4*; | |
| using DeserializerL4Ptr = DeserializerL4*; | |
| using ChannelRxPtr = ChannelRx*; | |
| using ChannelTxPtr = ChannelTx*; |
| using SerializerPtr = std::shared_ptr<SerializerL4>; | ||
| #else | ||
| using SerializerL4Ptr = SerializerL4*; | ||
| using DeserializerL4Ptr = DeserializerL4*; | ||
| using ChannelRxPtr = ChannelRx*; | ||
| using ChannelTxPtr = ChannelTx*; | ||
| using SerializerPtr = SerializerL4*; |
There was a problem hiding this comment.
SerializerPtr is redundant with SerializerL4Ptr (line 56). Both define the same type alias for SerializerL4*. Consider removing SerializerPtr or clarifying if they serve different purposes.
| using SerializerPtr = std::shared_ptr<SerializerL4>; | |
| #else | |
| using SerializerL4Ptr = SerializerL4*; | |
| using DeserializerL4Ptr = DeserializerL4*; | |
| using ChannelRxPtr = ChannelRx*; | |
| using ChannelTxPtr = ChannelTx*; | |
| using SerializerPtr = SerializerL4*; | |
| #else | |
| using SerializerL4Ptr = SerializerL4*; | |
| using DeserializerL4Ptr = DeserializerL4*; | |
| using ChannelRxPtr = ChannelRx*; | |
| using ChannelTxPtr = ChannelTx*; |
| add_library(module_l5 STATIC | ||
| src/Client.cpp |
There was a problem hiding this comment.
The USE_STD_MEMORY compile definition is not set for module_l5 or module_l5_tests. Since l4 uses PRIVATE visibility for this definition (cpp/modules/l4/CMakeLists.txt:25), it won't propagate. Add similar conditional compile definitions for module_l5 and module_l5_tests to ensure consistent pointer type usage across modules.
| @@ -0,0 +1,14 @@ | |||
| #pragma once | |||
| #include "messages/base/StyxMessage.h" | |||
| #include "Channel.h" | |||
There was a problem hiding this comment.
Including Channel.h is unnecessary as the Deserializer class only inherits from DeserializerL4, which is already declared in SerializerL4.h (line 4). Remove this include to reduce unnecessary dependencies.
| #include "Channel.h" |
…tialization