Skip to content

Commit 6041ff8

Browse files
committed
more CETL_NODISCARD
1 parent 418b8fb commit 6041ff8

23 files changed

+316
-200
lines changed

include/ocvsmd/sdk/daemon.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef OCVSMD_SDK_DAEMON_HPP_INCLUDED
77
#define OCVSMD_SDK_DAEMON_HPP_INCLUDED
88

9+
#include <cetl/cetl.hpp>
910
#include <cetl/pf17/cetlpf.hpp>
1011
#include <libcyphal/executor.hpp>
1112

@@ -21,7 +22,9 @@ namespace sdk
2122
class Daemon
2223
{
2324
public:
24-
static std::unique_ptr<Daemon> make(cetl::pmr::memory_resource& memory, libcyphal::IExecutor& executor);
25+
CETL_NODISCARD static std::unique_ptr<Daemon> make( //
26+
cetl::pmr::memory_resource& memory,
27+
libcyphal::IExecutor& executor);
2528

2629
Daemon(Daemon&&) = delete;
2730
Daemon(const Daemon&) = delete;

src/common/dsdl/ocvsmd/common/ipc/Route.1.0.dsdl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
uavcan.primitive.Empty.1.0 empty
44
RouteConnect.1.0 connect
55
RouteChannelMsg.1.0 channel_msg
6+
RouteChannelEnd.1.0 channel_end
67

78
@sealed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
uint64 tag
2+
int32 error_code
3+
4+
# reserve twice as much as we need.
5+
@extent _offset_.max * 2

src/common/dsdl_helpers.hpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef OCVSMD_COMMON_DSDL_HELPERS_HPP_INCLUDED
77
#define OCVSMD_COMMON_DSDL_HELPERS_HPP_INCLUDED
88

9+
#include <cetl/cetl.hpp>
910
#include <cetl/pf20/cetlpf.hpp>
1011

1112
#include <array>
@@ -21,13 +22,13 @@ namespace common
2122
{
2223

2324
template <typename Message>
24-
static auto tryDeserializePayload(const cetl::span<const std::uint8_t> payload, Message& out_message)
25+
CETL_NODISCARD static auto tryDeserializePayload(const cetl::span<const std::uint8_t> payload, Message& out_message)
2526
{
2627
return deserialize(out_message, {payload.data(), payload.size()});
2728
}
2829

2930
template <typename Message, typename Action>
30-
static int tryPerformOnSerialized(const Message& message, Action&& action)
31+
CETL_NODISCARD static int tryPerformOnSerialized(const Message& message, Action&& action)
3132
{
3233
// Try to serialize the message to raw payload buffer.
3334
//
@@ -45,8 +46,9 @@ static int tryPerformOnSerialized(const Message& message, Action&& action)
4546
return std::forward<Action>(action)(bytes);
4647
}
4748

48-
template <typename Message, typename Result, std::size_t BufferSize, bool IsOnStack, typename Action>
49-
static auto tryPerformOnSerialized(const Message& message, Action&& action) -> std::enable_if_t<IsOnStack, Result>
49+
template <typename Message, std::size_t BufferSize, bool IsOnStack, typename Action>
50+
CETL_NODISCARD static auto tryPerformOnSerialized(const Message& message,
51+
Action&& action) -> std::enable_if_t<IsOnStack, int>
5052
{
5153
// Try to serialize the message to raw payload buffer.
5254
//
@@ -57,15 +59,16 @@ static auto tryPerformOnSerialized(const Message& message, Action&& action) -> s
5759
const auto result_size = serialize(message, {buffer.data(), buffer.size()});
5860
if (!result_size)
5961
{
60-
return Result{result_size.error()};
62+
return EINVAL;
6163
}
6264

6365
const cetl::span<const std::uint8_t> bytes{buffer.data(), result_size.value()};
6466
return std::forward<Action>(action)(bytes);
6567
}
6668

67-
template <typename Message, typename Result, std::size_t BufferSize, bool IsOnStack, typename Action>
68-
static auto tryPerformOnSerialized(const Message& message, Action&& action) -> std::enable_if_t<!IsOnStack, Result>
69+
template <typename Message, std::size_t BufferSize, bool IsOnStack, typename Action>
70+
CETL_NODISCARD static auto tryPerformOnSerialized(const Message& message,
71+
Action&& action) -> std::enable_if_t<!IsOnStack, int>
6972
{
7073
// Try to serialize the message to raw payload buffer.
7174
//
@@ -75,7 +78,7 @@ static auto tryPerformOnSerialized(const Message& message, Action&& action) -> s
7578
const auto result_size = serialize(message, {buffer->data(), buffer->size()});
7679
if (!result_size)
7780
{
78-
return Result{result_size.error()};
81+
return EINVAL;
7982
}
8083

8184
const cetl::span<const std::uint8_t> bytes{buffer->data(), result_size.value()};

src/common/ipc/channel.hpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <nunavut/support/serialization.hpp>
1313

14+
#include <cetl/cetl.hpp>
1415
#include <cetl/pf17/cetlpf.hpp>
1516
#include <libcyphal/common/crc.hpp>
1617

@@ -37,7 +38,7 @@ class AnyChannel
3738
/// Builds a service ID from either the service name (if not empty), or message type name.
3839
///
3940
template <typename Message>
40-
static detail::ServiceId getServiceId(const cetl::string_view service_name) noexcept
41+
CETL_NODISCARD static detail::ServiceId getServiceId(const cetl::string_view service_name) noexcept
4142
{
4243
const cetl::string_view srv_or_msg_name = !service_name.empty() //
4344
? service_name
@@ -69,32 +70,28 @@ class Channel final : public AnyChannel
6970
Channel(const Channel&) = delete;
7071
Channel& operator=(const Channel&) = delete;
7172

72-
using SendFailure = nunavut::support::Error;
73-
using SendResult = cetl::optional<SendFailure>;
74-
75-
SendResult send(const Output& output)
73+
CETL_NODISCARD int send(const Output& output)
7674
{
7775
constexpr std::size_t BufferSize = Output::_traits_::SerializationBufferSizeBytes;
7876
constexpr bool IsOnStack = BufferSize <= MsgSmallPayloadSize;
7977

80-
return tryPerformOnSerialized<Output, SendResult, BufferSize, IsOnStack>( //
78+
return tryPerformOnSerialized<Output, BufferSize, IsOnStack>( //
8179
output,
8280
[this](const auto payload) {
8381
//
84-
gateway_->send(service_id_, payload);
85-
return cetl::nullopt;
82+
return gateway_->send(service_id_, payload);
8683
});
8784
}
8885

8986
void subscribe(EventHandler event_handler)
9087
{
9188
if (event_handler)
9289
{
93-
gateway_->subscribe(
94-
[adapter = Adapter{memory_, std::move(event_handler)}](const GatewayEvent::Var& ge_var) {
95-
//
96-
cetl::visit(adapter, ge_var);
97-
});
90+
auto adapter = Adapter{memory_, std::move(event_handler)};
91+
gateway_->subscribe([adapter = std::move(adapter)](const GatewayEvent::Var& ge_var) {
92+
//
93+
cetl::visit(adapter, ge_var);
94+
});
9895
}
9996
else
10097
{

0 commit comments

Comments
 (0)