Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use canardTxPoll; MediaPayload::Ownership #409

Merged
merged 28 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
edded3f
Sshirokov/352 zero copy (#401)
serges147 Nov 22, 2024
5856066
Single copy TX pipeline (#405)
serges147 Nov 29, 2024
ade0d04
Latest canard and udpard (v4 & v2) (#406)
serges147 Nov 29, 2024
215b27c
fix issue 398 #verification #sonar #docs
serges147 Nov 29, 2024
9ab3f9d
introduce libcyphal config #verification #sonar #docs
serges147 Nov 29, 2024
8e58076
build fix #verification #sonar #docs
serges147 Dec 2, 2024
9a3b932
sonar fixes #verification #sonar #docs
serges147 Dec 2, 2024
b333779
build fixes #verification #sonar #docs
serges147 Dec 2, 2024
e146b6a
sending now uses stack for serialization of small messages/request/re…
serges147 Dec 2, 2024
3e967e8
sonar and CI fixes #verification #sonar #docs
serges147 Dec 2, 2024
811d8f2
CI fixes #verification #sonar #docs
serges147 Dec 2, 2024
5732518
reworked config #verification #sonar #docs
serges147 Dec 3, 2024
25be9de
eliminated deprecatd NOSONAR cpp:S4963 #verification #sonar #docs
serges147 Dec 3, 2024
b8d8b55
sonar fixes #verification #sonar #docs
serges147 Dec 3, 2024
423849e
sonar fixes #verification #sonar #docs
serges147 Dec 3, 2024
bed3d2f
pr review fixes #verification #sonar #docs
serges147 Dec 3, 2024
37c076c
Merge branch 'issue/352_zero_copy' into sshirokov/config
serges147 Dec 3, 2024
eef24af
simplified config #verification #sonar #docs
serges147 Dec 5, 2024
118c5c2
fix build #verification #sonar #docs
serges147 Dec 5, 2024
9974086
Merge branch 'main' into sshirokov/config
serges147 Dec 5, 2024
1b7345b
try poll #verification #sonar #docs
serges147 Dec 5, 2024
9a4424d
try poll #verification #sonar #docs
serges147 Dec 9, 2024
bc19292
Added `MediaPayload::Ownership` nested struct #verification #sonar #docs
serges147 Dec 9, 2024
bc4a315
sonar fixes #verification #sonar #docs
serges147 Dec 9, 2024
5aba8c7
#verification #sonar #docs
serges147 Dec 9, 2024
fe4f7c6
rename `cavl` -> `libcyphal::common::cavl` #verification #sonar #docs
serges147 Dec 9, 2024
dc68e7c
build fix #verification #sonar #docs
serges147 Dec 9, 2024
a3039c9
Merge branch 'main' into sshirokov/tx_poll
serges147 Dec 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ class EpollSingleThreadedExecutor final : public libcyphal::platform::SingleThre
using Base = SingleThreadedExecutor;
using Self = EpollSingleThreadedExecutor;

/// No Sonar cpp:S4963 b/c `AwaitableNode` supports move operation.
///
class AwaitableNode final : public CallbackNode // NOSONAR cpp:S4963
class AwaitableNode final : public CallbackNode
{
public:
AwaitableNode(Self& executor, Callback::Function&& function)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,7 @@ class PollSingleThreadedExecutor final : public libcyphal::platform::SingleThrea
DoubleLinkedNode* next_node;
};

/// No Sonar cpp:S4963 b/c `AwaitableNode` supports move operation.
///
class AwaitableNode final : public CallbackNode, public DoubleLinkedNode // NOSONAR cpp:S4963
class AwaitableNode final : public CallbackNode, public DoubleLinkedNode
{
public:
AwaitableNode(Self& executor, Callback::Function&& function, DoubleLinkedNode& origin_node)
Expand Down
7 changes: 4 additions & 3 deletions include/libcyphal/application/node/get_info_provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ namespace node
///
/// Internally, it uses the 'GetInfo' service server to handle incoming requests.
///
/// No Sonar cpp:S4963 'The "Rule-of-Zero" should be followed'
/// b/c we do directly handle resources here (namely capturing of `this` in the request callback).
/// No Sonar cpp:S3624 "Customize this class' destructor to participate in resource management."
/// We need custom move constructor to reset up the request callback,
/// but at the destructor level, we don't need to do anything.
///
class GetInfoProvider final // NOSONAR cpp:S4963
class GetInfoProvider final // NOSONAR cpp:S3624
{
using Service = uavcan::node::GetInfo_1_0;

Expand Down
14 changes: 7 additions & 7 deletions include/libcyphal/application/node/heartbeat_producer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#ifndef LIBCYPHAL_APPLICATION_NODE_HEARTBEAT_PRODUCER_HPP_INCLUDED
#define LIBCYPHAL_APPLICATION_NODE_HEARTBEAT_PRODUCER_HPP_INCLUDED

#include "libcyphal/config.hpp"
#include "libcyphal/executor.hpp"
#include "libcyphal/presentation/presentation.hpp"
#include "libcyphal/presentation/publisher.hpp"
Expand Down Expand Up @@ -33,10 +34,11 @@ namespace node
///
/// Internally, it uses the 'Heartbeat' message publisher to periodically publish heartbeat messages.
///
/// No Sonar cpp:S4963 'The "Rule-of-Zero" should be followed'
/// b/c we do directly handle resources here (namely capturing of `this` in the periodic callback).
/// No Sonar cpp:S3624 "Customize this class' destructor to participate in resource management."
/// We need custom move constructor to reset up the publishing callback,
/// but at the destructor level, we don't need to do anything.
///
class HeartbeatProducer final // NOSONAR cpp:S4963
class HeartbeatProducer final // NOSONAR cpp:S3624
{
public:
/// @brief Defines the message type for the Heartbeat.
Expand Down Expand Up @@ -110,10 +112,8 @@ class HeartbeatProducer final // NOSONAR cpp:S4963

/// @brief Defines signature of the heartbeat update callback function.
///
/// The size of the function is arbitrary (4 pointers), but should be enough for simple lambdas.
///
static constexpr std::size_t FunctionSize = sizeof(void*) * 4;
using Function = cetl::pmr::function<void(const Arg& arg), FunctionSize>;
static constexpr auto FunctionSize = config::Application::Node::HeartbeatProducer_UpdateCallback_FunctionSize();
using Function = cetl::pmr::function<void(const Arg& arg), FunctionSize>;
};

/// @brief Sets the message update callback for the heartbeat.
Expand Down
7 changes: 4 additions & 3 deletions include/libcyphal/application/node/registry_provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ namespace node
///
/// Internally, it uses the registry 'List' and 'Access' service servers to handle incoming requests.
///
/// No Sonar cpp:S4963 'The "Rule-of-Zero" should be followed'
/// b/c we do directly handle resources here (namely capturing of `this` in the request callback).
/// No Sonar cpp:S3624 "Customize this class' destructor to participate in resource management."
/// We need custom move constructor to reset up the request callback,
/// but at the destructor level, we don't need to do anything.
///
class RegistryProvider final // NOSONAR cpp:S4963
class RegistryProvider final // NOSONAR cpp:S3624
{
using ListService = uavcan::_register::List_1_0;
using AccessService = uavcan::_register::Access_1_0;
Expand Down
4 changes: 1 addition & 3 deletions include/libcyphal/application/registry/register.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ enum class SetError : std::uint8_t

/// Defines interface for a register.
///
/// NOSONAR cpp:S4963 for below `class IRegister` - protected destructor is necessary.
///
class IRegister : public cavl::Node<IRegister> // NOSONAR cpp:S4963
class IRegister : public common::cavl::Node<IRegister>
{
// 1AD1885B-954B-48CF-BAC4-FA0A251D3FC0
// clang-format off
Expand Down
4 changes: 2 additions & 2 deletions include/libcyphal/application/registry/registry_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ class Registry final : public IIntrospectableRegistry
[key = IRegister::Key{name}](const IRegister& other) { return other.compareBy(key); });
}

cetl::pmr::memory_resource& memory_;
cavl::Tree<IRegister> registers_tree_;
cetl::pmr::memory_resource& memory_;
common::cavl::Tree<IRegister> registers_tree_;

}; // Registry

Expand Down
16 changes: 10 additions & 6 deletions include/libcyphal/common/cavl/cavl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@

// NOLINTBEGIN(cppcoreguidelines-pro-bounds-constant-array-index)

namespace libcyphal
{
namespace common
{
Copy link
Collaborator Author

@serges147 serges147 Dec 9, 2024

Choose a reason for hiding this comment

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

Renamed for...

  1. to be consistent with libcyphal/common/cavl/... folder structure
  2. to minimize possible conflict if some project already has it's own CAVL copy (and not necessarily the same version)

namespace cavl
{
template <typename Derived>
Expand All @@ -58,10 +62,9 @@ class Tree;
/// The size of this type is 4x pointer size (16 bytes on a 32-bit platform).
///
/// No Sonar cpp:S1448 b/c this is the main node entity without public members - maintainability is not a concern here.
/// No Sonar cpp:S4963 b/c `Node` supports move operation.
///
template <typename Derived>
class Node // NOSONAR cpp:S1448 cpp:S4963
class Node // NOSONAR cpp:S1448
{
// Polyfill for C++17's std::invoke_result_t.
template <typename F, typename... Args>
Expand Down Expand Up @@ -789,7 +792,7 @@ class Tree final // NOSONAR cpp:S3624
{
public:
/// Helper alias of the compatible node type.
using NodeType = ::cavl::Node<Derived>;
using NodeType = Node<Derived>;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

already in upstream

using DerivedType = Derived;

Tree() = default;
Expand Down Expand Up @@ -954,8 +957,7 @@ class Tree final // NOSONAR cpp:S3624
/// the same call stack) we may occasionally fail to detect a bona fide case of a race condition, but this is
/// acceptable because the purpose of this feature is to provide a mere best-effort data race detection.
///
/// No Sonar cpp:S4963 b/c of the RAII pattern.
class TraversalIndicatorUpdater final // NOSONAR cpp:S4963
class TraversalIndicatorUpdater final
{
public:
explicit TraversalIndicatorUpdater(const Tree& sup) noexcept
Expand Down Expand Up @@ -994,11 +996,13 @@ class Tree final // NOSONAR cpp:S3624
// including the root node whos `up` points to this origin node (see `isRoot` method).
Node<Derived> origin_node_{};

// No Sonar cpp:S4963 b/c of implicit modification by the `TraversalIndicatorUpdater` RAII class,
// No Sonar cpp:S3687 b/c of implicit modification by the `TraversalIndicatorUpdater` RAII class,
// even for `const` instance of the `Tree` class (hence the `mutable volatile` keywords).
mutable volatile bool traversal_in_progress_ = false; // NOSONAR cpp:S3687
};

} // namespace cavl
} // namespace common
} // namespace libcyphal
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

upstream stay as before - just ::cavl:: ...


// NOLINTEND(cppcoreguidelines-pro-bounds-constant-array-index)
190 changes: 190 additions & 0 deletions include/libcyphal/config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
/// @copyright
/// Copyright (C) OpenCyphal Development Team <opencyphal.org>
/// Copyright Amazon.com Inc. or its affiliates.
/// SPDX-License-Identifier: MIT

#ifndef LIBCYPHAL_CONFIG_HPP_INCLUDED
#define LIBCYPHAL_CONFIG_HPP_INCLUDED

#include <cstddef>

namespace libcyphal
{

// All below NOSONAR cpp:S799 "Rename this identifier to be shorter or equal to 31 characters."
// are intentional and are used to keep the names consistent with the rest of the codebase.
// F.e. `IExecutor_Callback_FunctionMaxSize` is consistent with `IExecutor::Callback::FunctionMaxSize`.

/// Defines various configuration parameters of libcyphal.
///
/// All methods are `static constexpr` - they are evaluated at compile time.
///
/// Nolint b/c this is the main purpose of this file - define various constants.
/// NOLINTBEGIN(cppcoreguidelines-avoid-magic-numbers, readability-magic-numbers)
///
struct Config
{
/// Defines max footprint of a callback function in use by the executor.
///
static constexpr std::size_t IExecutor_Callback_FunctionMaxSize() // NOSONAR cpp:S799
{
return sizeof(void*) * 8;
}

/// Defines footprint size reserved for a callback implementation.
/// The actual max footprint for the callback implementation is `sizeof(IExecutor::Function)` bigger,
/// and it depends on `Cfg_IExecutor_Callback_FunctionMaxSize`.
///
static constexpr std::size_t IExecutor_Callback_ReserveSize() // NOSONAR cpp:S799
{
/// Size is chosen arbitrary, but it should be enough to store any lambda or function pointer.
return sizeof(void*) * 16;
}

/// Defines various configuration parameters for the application layer.
///
struct Application
{
struct Node
{
/// Defines max footprint of a callback function in use by the heartbeat producer.
///
static constexpr std::size_t HeartbeatProducer_UpdateCallback_FunctionSize() // NOSONAR cpp:S799
{
/// Size is chosen arbitrary, but it should be enough to store any lambda or function pointer.
return sizeof(void*) * 4;
}

}; // Node

}; // Application

/// Defines various configuration parameters for the presentation layer.
///
struct Presentation
{
/// Defines max footprint of a callback function in use by the RPC client response promise.
///
static constexpr std::size_t ResponsePromiseBase_Callback_FunctionSize() // NOSONAR cpp:S799
{
/// Size is chosen arbitrary, but it should be enough to store any lambda or function pointer.
return sizeof(void*) * 4;
}

/// Defines max footprint of a callback function in use by the RPC server response continuation.
///
static constexpr std::size_t ServerBase_ContinuationImpl_FunctionMaxSize() // NOSONAR cpp:S799
{
/// Size is chosen arbitrary, but it should be enough to store any lambda or function pointer.
return sizeof(void*) * 5;
}

/// Defines max footprint of a callback function in use by the RPC server request notification.
///
static constexpr std::size_t ServerBase_OnRequestCallback_FunctionMaxSize() // NOSONAR cpp:S799
{
/// Size is chosen arbitrary, but it should be enough to store any lambda or function pointer.
return sizeof(void*) * 5;
}

/// Defines the size serialization/deserialization payload buffer which is considered as a small one,
/// and therefore could be used with stack buffer. Any payload larger than this size will be PMR allocated.
///
/// Setting it to 0 will force all payload buffers to be PMR allocated (except zero-sized).
///
static constexpr std::size_t SmallPayloadSize()
{
/// Size is chosen arbitrary - as compromise between stack and PMR allocation.
return 256;
}

/// Defines max footprint of a callback function in use by the message subscriber receive notification.
///
static constexpr std::size_t Subscriber_OnReceiveCallback_FunctionMaxSize() // NOSONAR cpp:S799
{
/// Size is chosen arbitrary, but it should be enough to store any lambda or function pointer.
return sizeof(void*) * 4;
}
};

/// Defines various configuration parameters for the transport layer.
///
struct Transport
{
/// Defines max footprint of a callback function in use by the message RX session notification.
/// Size is chosen arbitrary, but it should be enough to store any lambda or function pointer.
///
static constexpr std::size_t IMessageRxSession_OnReceiveCallback_FunctionMaxSize() // NOSONAR cpp:S799
{
/// Size is chosen arbitrary, but it should be enough to store any lambda or function pointer.
return sizeof(void*) * 4;
}

/// Defines max footprint of a callback function in use by the service RX session notification.
/// Size is chosen arbitrary, but it should be enough to store any lambda or function pointer.
///
static constexpr std::size_t ISvcRxSession_OnReceiveCallback_FunctionMaxSize() // NOSONAR cpp:S799
{
/// Size is chosen arbitrary, but it should be enough to store any lambda or function pointer.
return sizeof(void*) * 4;
}

/// Defines max footprint of a platform-specific error implementation.
///
static constexpr std::size_t PlatformErrorMaxSize()
{
/// Size is chosen arbitrary, but it should be enough to store simple implementation.
return sizeof(void*) * 3;
}

/// Defines max footprint of a storage implementation used by the scattered buffer.
///
static constexpr std::size_t ScatteredBuffer_StorageVariantFootprint() // NOSONAR cpp:S799
{
/// Size is chosen arbitrary, but it should be enough to store any implementation.
return sizeof(void*) * 8;
}

/// Defines various configuration parameters for the CAN transport sublayer.
///
struct Can
{
/// Defines max footprint of a callback function in use by the CAN transport transient error handler.
///
static constexpr std::size_t ICanTransport_TransientErrorHandlerMaxSize() // NOSONAR cpp:S799
{
/// Size is chosen arbitrary, but it should be enough to store simple lambda or function pointer.
return sizeof(void*) * 3;
}

}; // Can

/// Defines various configuration parameters for the UDO transport sublayer.
///
struct Udp
{
/// Defines max footprint of a callback function in use by the UDP transport transient error handler.
///
static constexpr std::size_t IUdpTransport_TransientErrorHandlerMaxSize() // NOSONAR cpp:S799
{
/// Size is chosen arbitrary, but it should be enough to store simple lambda or function pointer.
return sizeof(void*) * 3;
}

}; // Udp

}; // Transport

}; // Config

// NOLINTEND(cppcoreguidelines-avoid-magic-numbers, readability-magic-numbers)

#ifdef LIBCYPHAL_CONFIG
using config = LIBCYPHAL_CONFIG;
#else
using config = Config;
#endif

} // namespace libcyphal

#endif // LIBCYPHAL_CONFIG_HPP_INCLUDED
Loading
Loading