Skip to content

Add support for optional std::memory usage and refactor ChannelRx ini…#53

Merged
vshcryabets merged 3 commits into
masterfrom
fix/rp-2040-uart-rx
Nov 23, 2025
Merged

Add support for optional std::memory usage and refactor ChannelRx ini…#53
vshcryabets merged 3 commits into
masterfrom
fix/rp-2040-uart-rx

Conversation

@vshcryabets
Copy link
Copy Markdown
Owner

…tialization

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ChannelRx to use default constructor + setDeserializer() method instead of constructor parameter validation
  • Added USE_STD_MEMORY CMake option to conditionally enable/disable std::shared_ptr usage, falling back to raw pointers
  • Introduced new Client and ClientBlocking abstract 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_MEMORY compile definition for module_l5. The module uses ChannelTxPtr and ChannelRxPtr types which are conditionally defined based on the USE_STD_MEMORY preprocessor 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");
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread cpp/modules/l5/include/Client.h Outdated
ChannelRxPtr channelRx;
public:
ClientBlocking();
~ClientBlocking();
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Suggested change
~ClientBlocking();
~ClientBlocking() override;

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
#include "messages/base/StyxMessage.h"
#include "messages/base/StyxMessage.h"
#include "Channel.h"

Copilot uses AI. Check for mistakes.
Comment thread cpp/modules/l4/include/data.h Outdated
Comment on lines +54 to +60
using SerializerPtr = std::shared_ptr<SerializerL4>;
#else
using SerializerL4Ptr = SerializerL4*;
using DeserializerL4Ptr = DeserializerL4*;
using ChannelRxPtr = ChannelRx*;
using ChannelTxPtr = ChannelTx*;
using SerializerPtr = SerializerL4*;
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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*;

Copilot uses AI. Check for mistakes.
Comment thread cpp/modules/l4/include/data.h Outdated
Comment on lines +54 to +60
using SerializerPtr = std::shared_ptr<SerializerL4>;
#else
using SerializerL4Ptr = SerializerL4*;
using DeserializerL4Ptr = DeserializerL4*;
using ChannelRxPtr = ChannelRx*;
using ChannelTxPtr = ChannelTx*;
using SerializerPtr = SerializerL4*;
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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*;

Copilot uses AI. Check for mistakes.
Comment on lines 3 to +4
add_library(module_l5 STATIC
src/Client.cpp
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,14 @@
#pragma once
#include "messages/base/StyxMessage.h"
#include "Channel.h"
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
#include "Channel.h"

Copilot uses AI. Check for mistakes.
@vshcryabets vshcryabets marked this pull request as draft November 23, 2025 19:20
@vshcryabets vshcryabets marked this pull request as ready for review November 23, 2025 19:23
@vshcryabets vshcryabets merged commit 1852405 into master Nov 23, 2025
3 checks passed
@vshcryabets vshcryabets deleted the fix/rp-2040-uart-rx branch November 23, 2025 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants