Skip to content

Commit

Permalink
rule of 5 #verification #docs #sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
serges147 committed May 15, 2024
1 parent c709371 commit c3a4ede
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 8 deletions.
7 changes: 7 additions & 0 deletions include/libcyphal/transport/can/transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ namespace can

class ICanTransport : public ITransport
{
public:
ICanTransport(const ICanTransport&) = delete;
ICanTransport(ICanTransport&&) noexcept = delete;
ICanTransport& operator=(const ICanTransport&) = delete;
ICanTransport& operator=(ICanTransport&&) noexcept = delete;

protected:
ICanTransport() = default;
~ICanTransport() = default;
};

Expand Down
12 changes: 12 additions & 0 deletions include/libcyphal/transport/msg_sessions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ struct MessageTxParams final
class IMessageRxSession : public IRxSession
{
public:
IMessageRxSession(const IMessageRxSession&) = delete;
IMessageRxSession(IMessageRxSession&&) noexcept = delete;
IMessageRxSession& operator=(const IMessageRxSession&) = delete;
IMessageRxSession& operator=(IMessageRxSession&&) noexcept = delete;

virtual MessageRxParams getParams() const noexcept = 0;

/// @brief Receives a message from the transport layer.
Expand All @@ -44,13 +49,19 @@ class IMessageRxSession : public IRxSession
virtual cetl::optional<MessageRxTransfer> receive() = 0;

protected:
IMessageRxSession() = default;
~IMessageRxSession() = default;

}; // IMessageRxSession

class IMessageTxSession : public ITxSession
{
public:
IMessageTxSession(const IMessageTxSession&) = delete;
IMessageTxSession(IMessageTxSession&&) noexcept = delete;
IMessageTxSession& operator=(const IMessageTxSession&) = delete;
IMessageTxSession& operator=(IMessageTxSession&&) noexcept = delete;

virtual MessageTxParams getParams() const noexcept = 0;

/// @brief Sends a message to the transport layer.
Expand All @@ -63,6 +74,7 @@ class IMessageTxSession : public ITxSession
const PayloadFragments payload_fragments) = 0;

protected:
IMessageTxSession() = default;
~IMessageTxSession() = default;

}; // IMessageTxSession
Expand Down
19 changes: 19 additions & 0 deletions include/libcyphal/transport/session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,40 @@ namespace transport

class ISession : public IRunnable
{
public:
ISession(const ISession&) = delete;
ISession(ISession&&) noexcept = delete;
ISession& operator=(const ISession&) = delete;
ISession& operator=(ISession&&) noexcept = delete;

protected:
ISession() = default;
~ISession() = default;
};

class IRxSession : public ISession
{
public:
IRxSession(const IRxSession&) = delete;
IRxSession(IRxSession&&) noexcept = delete;
IRxSession& operator=(const IRxSession&) = delete;
IRxSession& operator=(IRxSession&&) noexcept = delete;

virtual void setTransferIdTimeout(const Duration timeout) = 0;

protected:
IRxSession() = default;
~IRxSession() = default;
};

class ITxSession : public ISession
{
public:
ITxSession(const ITxSession&) = delete;
ITxSession(ITxSession&&) noexcept = delete;
ITxSession& operator=(const ITxSession&) = delete;
ITxSession& operator=(ITxSession&&) noexcept = delete;

/// @brief Sets the timeout for a transmission.
///
/// The value is added to the original transfer timestamp to determine its deadline.
Expand All @@ -42,6 +60,7 @@ class ITxSession : public ISession
virtual void setSendTimeout(const Duration timeout) = 0;

protected:
ITxSession() = default;
~ITxSession() = default;
};

Expand Down
30 changes: 30 additions & 0 deletions include/libcyphal/transport/svc_sessions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ struct ResponseTxParams final
class ISvcRxSession : public IRxSession
{
public:
ISvcRxSession(const ISvcRxSession&) = delete;
ISvcRxSession(ISvcRxSession&&) noexcept = delete;
ISvcRxSession& operator=(const ISvcRxSession&) = delete;
ISvcRxSession& operator=(ISvcRxSession&&) noexcept = delete;

/// @brief Receives a service transfer (request or response) from the transport layer.
///
/// Method is not blocking, and will return immediately if no transfer is available.
Expand All @@ -54,21 +59,33 @@ class ISvcRxSession : public IRxSession
virtual cetl::optional<ServiceRxTransfer> receive() = 0;

protected:
ISvcRxSession() = default;
~ISvcRxSession() = default;
};

class IRequestRxSession : public ISvcRxSession
{
public:
IRequestRxSession(const IRequestRxSession&) = delete;
IRequestRxSession(IRequestRxSession&&) noexcept = delete;
IRequestRxSession& operator=(const IRequestRxSession&) = delete;
IRequestRxSession& operator=(IRequestRxSession&&) noexcept = delete;

virtual RequestRxParams getParams() const noexcept = 0;

protected:
IRequestRxSession() = default;
~IRequestRxSession() = default;
};

class IRequestTxSession : public ITxSession
{
public:
IRequestTxSession(const IRequestTxSession&) = delete;
IRequestTxSession(IRequestTxSession&&) noexcept = delete;
IRequestTxSession& operator=(const IRequestTxSession&) = delete;
IRequestTxSession& operator=(IRequestTxSession&&) noexcept = delete;

virtual RequestTxParams getParams() const noexcept = 0;

/// @brief Sends a service request to the transport layer.
Expand All @@ -81,21 +98,33 @@ class IRequestTxSession : public ITxSession
const PayloadFragments payload_fragments) = 0;

protected:
IRequestTxSession() = default;
~IRequestTxSession() = default;
};

class IResponseRxSession : public ISvcRxSession
{
public:
IResponseRxSession(const IResponseRxSession&) = delete;
IResponseRxSession(IResponseRxSession&&) noexcept = delete;
IResponseRxSession& operator=(const IResponseRxSession&) = delete;
IResponseRxSession& operator=(IResponseRxSession&&) noexcept = delete;

virtual ResponseRxParams getParams() const noexcept = 0;

protected:
IResponseRxSession() = default;
~IResponseRxSession() = default;
};

class IResponseTxSession : public ITxSession
{
public:
IResponseTxSession(const IResponseTxSession&) = delete;
IResponseTxSession(IResponseTxSession&&) noexcept = delete;
IResponseTxSession& operator=(const IResponseTxSession&) = delete;
IResponseTxSession& operator=(IResponseTxSession&&) noexcept = delete;

virtual ResponseTxParams getParams() const noexcept = 0;

/// @brief Sends a service response to the transport layer.
Expand All @@ -108,6 +137,7 @@ class IResponseTxSession : public ITxSession
const PayloadFragments payload_fragments) = 0;

protected:
IResponseTxSession() = default;
~IResponseTxSession() = default;
};

Expand Down
6 changes: 6 additions & 0 deletions include/libcyphal/transport/transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ namespace transport
class ITransport : public IRunnable
{
public:
ITransport(const ITransport&) = delete;
ITransport(ITransport&&) noexcept = delete;
ITransport& operator=(const ITransport&) = delete;
ITransport& operator=(ITransport&&) noexcept = delete;

/// @brief Gets the protocol parameters.
///
/// @return Almost the same parameters as they were passed to the corresponding transport layer factory.
Expand Down Expand Up @@ -99,6 +104,7 @@ class ITransport : public IRunnable
virtual Expected<UniquePtr<IResponseTxSession>, AnyError> makeResponseTxSession(const ResponseTxParams& params) = 0;

protected:
ITransport() = default;
~ITransport() = default;

}; // ITransport
Expand Down
7 changes: 7 additions & 0 deletions include/libcyphal/transport/udp/transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ namespace udp

class IUdpTransport : public ITransport
{
public:
IUdpTransport(const IUdpTransport&) = delete;
IUdpTransport(IUdpTransport&&) noexcept = delete;
IUdpTransport& operator=(const IUdpTransport&) = delete;
IUdpTransport& operator=(IUdpTransport&&) noexcept = delete;

protected:
IUdpTransport() = default;
~IUdpTransport() = default;
};

Expand Down
5 changes: 3 additions & 2 deletions test/unittest/transport/can/test_can_msg_rx_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <gtest/gtest.h>

#include <array>
#include <chrono>
#include <utility>

namespace
Expand All @@ -49,10 +50,10 @@ using testing::ElementsAre;
using testing::VariantWith;

// https://github.com/llvm/llvm-project/issues/53444
// NOLINTBEGIN(misc-unused-using-decls)
// NOLINTBEGIN(misc-unused-using-decls, misc-include-cleaner)
using std::literals::chrono_literals::operator""s;
using std::literals::chrono_literals::operator""ms;
// NOLINTEND(misc-unused-using-decls)
// NOLINTEND(misc-unused-using-decls, misc-include-cleaner)

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

Expand Down
5 changes: 3 additions & 2 deletions test/unittest/transport/can/test_can_msg_tx_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <gtest/gtest.h>

#include <array>
#include <chrono>
#include <utility>

namespace
Expand All @@ -49,11 +50,11 @@ using testing::ElementsAre;
using testing::VariantWith;

// https://github.com/llvm/llvm-project/issues/53444
// NOLINTBEGIN(misc-unused-using-decls)
// NOLINTBEGIN(misc-unused-using-decls, misc-include-cleaner)
using std::literals::chrono_literals::operator""s;
using std::literals::chrono_literals::operator""ms;
using std::literals::chrono_literals::operator""us;
// NOLINTEND(misc-unused-using-decls)
// NOLINTEND(misc-unused-using-decls, misc-include-cleaner)

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

Expand Down
5 changes: 3 additions & 2 deletions test/unittest/transport/can/test_can_svc_rx_sessions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <gtest/gtest.h>

#include <array>
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <utility>
Expand Down Expand Up @@ -50,10 +51,10 @@ using testing::ElementsAre;
using testing::VariantWith;

// https://github.com/llvm/llvm-project/issues/53444
// NOLINTBEGIN(misc-unused-using-decls)
// NOLINTBEGIN(misc-unused-using-decls, misc-include-cleaner)
using std::literals::chrono_literals::operator""s;
using std::literals::chrono_literals::operator""ms;
// NOLINTEND(misc-unused-using-decls)
// NOLINTEND(misc-unused-using-decls, misc-include-cleaner)

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

Expand Down
5 changes: 3 additions & 2 deletions test/unittest/transport/can/test_can_svc_tx_sessions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <gtest/gtest.h>

#include <array>
#include <chrono>
#include <utility>

namespace
Expand All @@ -45,10 +46,10 @@ using testing::ElementsAre;
using testing::VariantWith;

// https://github.com/llvm/llvm-project/issues/53444
// NOLINTBEGIN(misc-unused-using-decls)
// NOLINTBEGIN(misc-unused-using-decls, misc-include-cleaner)
using std::literals::chrono_literals::operator""s;
using std::literals::chrono_literals::operator""ms;
// NOLINTEND(misc-unused-using-decls)
// NOLINTEND(misc-unused-using-decls, misc-include-cleaner)

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

Expand Down
1 change: 1 addition & 0 deletions test/unittest/transport/can/test_can_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <algorithm>
#include <array>
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <limits>
Expand Down

0 comments on commit c3a4ede

Please sign in to comment.