Skip to content

Commit

Permalink
Breaking out the base class (and make one, where non exists) into a s…
Browse files Browse the repository at this point in the history
…eparate header file breaks the circular dependency.
  • Loading branch information
aentinger committed Jan 11, 2023
1 parent b1d09cb commit 51823ce
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 79 deletions.
8 changes: 4 additions & 4 deletions src/Node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
#include <memory>
#include <functional>

#include "Publisher.hpp"
#include "Subscription.hpp"
#include "ServiceClient.hpp"
#include "ServiceServer.hpp"
#include "PublisherBase.hpp"
#include "SubscriptionBase.h"
#include "ServiceClientBase.hpp"
#include "ServiceServerBase.hpp"
#include "CircularBuffer.hpp"

#include "libo1heap/o1heap.h"
Expand Down
9 changes: 9 additions & 0 deletions src/Node.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
* Contributors: https://github.com/107-systems/107-Arduino-Cyphal/graphs/contributors.
*/

/**************************************************************************************
* INCLUDE
**************************************************************************************/

#include "Publisher.hpp"
#include "Subscription.hpp"
#include "ServiceClient.hpp"
#include "ServiceServer.hpp"

/**************************************************************************************
* PUBLIC MEMBER FUNCTIONS
**************************************************************************************/
Expand Down
20 changes: 4 additions & 16 deletions src/Publisher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@
* INCLUDE
**************************************************************************************/

#include "libcanard/canard.h"

/**************************************************************************************
* FORWARD DECLARATION
**************************************************************************************/

class Node;
#include "PublisherBase.hpp"

/**************************************************************************************
* NAMESPACE
Expand All @@ -32,7 +26,7 @@ namespace impl
**************************************************************************************/

template <typename T>
class Publisher
class Publisher : public PublisherBase<T>
{
public:
Publisher(Node & node_hdl, CanardPortID const port_id, CanardMicrosecond const tx_timeout_usec)
Expand All @@ -41,8 +35,9 @@ class Publisher
, _tx_timeout_usec{tx_timeout_usec}
, _transfer_id{0}
{ }
virtual ~Publisher() { }

bool publish(T const & msg);
virtual bool publish(T const & msg) override;

private:
Node & _node_hdl;
Expand All @@ -57,13 +52,6 @@ class Publisher

} /* impl */

/**************************************************************************************
* TYPEDEF
**************************************************************************************/

template <typename T>
using Publisher = std::shared_ptr<impl::Publisher<T>>;

/**************************************************************************************
* TEMPLATE IMPLEMENTATION
**************************************************************************************/
Expand Down
55 changes: 55 additions & 0 deletions src/PublisherBase.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* This software is distributed under the terms of the MIT License.
* Copyright (c) 2020-2023 LXRobotics.
* Author: Alexander Entinger <alexander.entinger@lxrobotics.com>
* Contributors: https://github.com/107-systems/107-Arduino-Cyphal/graphs/contributors.
*/

#ifndef INC_107_ARDUINO_CYPHAL_PUBLISHER_BASE_H
#define INC_107_ARDUINO_CYPHAL_PUBLISHER_BASE_H

/**************************************************************************************
* INCLUDE
**************************************************************************************/

#include "Node.hpp"

/**************************************************************************************
* NAMESPACE
**************************************************************************************/

namespace impl
{

/**************************************************************************************
* CLASS DECLARATION
**************************************************************************************/

template <typename T>
class PublisherBase
{
public:
PublisherBase() { }
virtual ~PublisherBase() { }
PublisherBase(PublisherBase const &) = delete;
PublisherBase(PublisherBase &&) = delete;
PublisherBase &operator=(PublisherBase const &) = delete;
PublisherBase &operator=(PublisherBase &&) = delete;

virtual bool publish(T const & msg) = 0;
};

/**************************************************************************************
* NAMESPACE
**************************************************************************************/

} /* impl */

/**************************************************************************************
* TYPEDEF
**************************************************************************************/

template <typename T>
using Publisher = std::shared_ptr<impl::PublisherBase<T>>;

#endif /* INC_107_ARDUINO_CYPHAL_PUBLISHER_BASE_H */
26 changes: 2 additions & 24 deletions src/ServiceClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,9 @@

#include <memory>

#include "SubscriptionBase.h"
#include "ServiceClientBase.hpp"

#include "libcanard/canard.h"

/**************************************************************************************
* FORWARD DECLARATION
**************************************************************************************/

class Node;
#include "Node.hpp"

/**************************************************************************************
* NAMESPACE
Expand All @@ -35,15 +29,6 @@ namespace impl
* CLASS DECLARATION
**************************************************************************************/

template <typename T_REQ>
class ServiceClientBase : public SubscriptionBase
{
public:
ServiceClientBase() : SubscriptionBase{CanardTransferKindResponse} { }
virtual ~ServiceClientBase() { }
virtual bool request(CanardNodeID const remote_node_id, T_REQ const & req) = 0;
};

template<typename T_REQ, typename T_RSP, typename OnResponseCb>
class ServiceClient : public ServiceClientBase<T_REQ>
{
Expand Down Expand Up @@ -76,13 +61,6 @@ class ServiceClient : public ServiceClientBase<T_REQ>

} /* impl */

/**************************************************************************************
* TYPEDEF
**************************************************************************************/

template <typename T_REQ>
using ServiceClient = std::shared_ptr<impl::ServiceClientBase<T_REQ>>;

/**************************************************************************************
* TEMPLATE IMPLEMENTATION
**************************************************************************************/
Expand Down
52 changes: 52 additions & 0 deletions src/ServiceClientBase.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* This software is distributed under the terms of the MIT License.
* Copyright (c) 2020-2023 LXRobotics.
* Author: Alexander Entinger <alexander.entinger@lxrobotics.com>
* Contributors: https://github.com/107-systems/107-Arduino-Cyphal/graphs/contributors.
*/

#ifndef INC_107_ARDUINO_CYPHAL_SERVICE_CLIENT_BASE_HPP
#define INC_107_ARDUINO_CYPHAL_SERVICE_CLIENT_BASE_HPP

/**************************************************************************************
* INCLUDE
**************************************************************************************/

#include <memory>

#include "SubscriptionBase.h"

/**************************************************************************************
* NAMESPACE
**************************************************************************************/

namespace impl
{

/**************************************************************************************
* CLASS DECLARATION
**************************************************************************************/

template <typename T_REQ>
class ServiceClientBase : public SubscriptionBase
{
public:
ServiceClientBase() : SubscriptionBase{CanardTransferKindResponse} { }
virtual ~ServiceClientBase() { }
virtual bool request(CanardNodeID const remote_node_id, T_REQ const & req) = 0;
};

/**************************************************************************************
* NAMESPACE
**************************************************************************************/

} /* impl */

/**************************************************************************************
* TYPEDEF
**************************************************************************************/

template <typename T_REQ>
using ServiceClient = std::shared_ptr<impl::ServiceClientBase<T_REQ>>;

#endif /* INC_107_ARDUINO_CYPHAL_SERVICE_CLIENT_BASE_HPP */
22 changes: 1 addition & 21 deletions src/ServiceServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,7 @@

#include <memory>

#include "SubscriptionBase.h"

#include "libcanard/canard.h"

/**************************************************************************************
* FORWARD DECLARATION
**************************************************************************************/

class Node;
#include "ServiceServerBase.hpp"

/**************************************************************************************
* NAMESPACE
Expand All @@ -35,12 +27,6 @@ namespace impl
* CLASS DECLARATION
**************************************************************************************/

class ServiceServerBase : public SubscriptionBase
{
public:
ServiceServerBase() : SubscriptionBase{CanardTransferKindRequest} { }
};

template<typename T_REQ, typename T_RSP, typename OnRequestCb>
class ServiceServer : public ServiceServerBase
{
Expand Down Expand Up @@ -70,12 +56,6 @@ class ServiceServer : public ServiceServerBase

} /* impl */

/**************************************************************************************
* TYPEDEF
**************************************************************************************/

using ServiceServer = std::shared_ptr<impl::ServiceServerBase>;

/**************************************************************************************
* TEMPLATE IMPLEMENTATION
**************************************************************************************/
Expand Down
50 changes: 50 additions & 0 deletions src/ServiceServerBase.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* This software is distributed under the terms of the MIT License.
* Copyright (c) 2020-2023 LXRobotics.
* Author: Alexander Entinger <alexander.entinger@lxrobotics.com>
* Contributors: https://github.com/107-systems/107-Arduino-Cyphal/graphs/contributors.
*/

#ifndef INC_107_ARDUINO_CYPHAL_SERVICE_SERVER_BASE_HPP
#define INC_107_ARDUINO_CYPHAL_SERVICE_SERVER_BASE_HPP

/**************************************************************************************
* INCLUDE
**************************************************************************************/

#include <memory>

#include "SubscriptionBase.h"

#include "Node.hpp"

/**************************************************************************************
* NAMESPACE
**************************************************************************************/

namespace impl
{

/**************************************************************************************
* CLASS DECLARATION
**************************************************************************************/

class ServiceServerBase : public SubscriptionBase
{
public:
ServiceServerBase() : SubscriptionBase{CanardTransferKindRequest} { }
};

/**************************************************************************************
* NAMESPACE
**************************************************************************************/

} /* impl */

/**************************************************************************************
* TYPEDEF
**************************************************************************************/

using ServiceServer = std::shared_ptr<impl::ServiceServerBase>;

#endif /* INC_107_ARDUINO_CYPHAL_SERVICE_SERVER_BASE_HPP */
14 changes: 0 additions & 14 deletions src/Subscription.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@

#include "SubscriptionBase.h"

#include "libcanard/canard.h"

/**************************************************************************************
* FORWARD DECLARATION
**************************************************************************************/

class Node;

/**************************************************************************************
* NAMESPACE
**************************************************************************************/
Expand Down Expand Up @@ -63,12 +55,6 @@ class Subscription : public SubscriptionBase

} /* impl */

/**************************************************************************************
* TYPEDEF
**************************************************************************************/

using Subscription = std::shared_ptr<impl::SubscriptionBase>;

/**************************************************************************************
* TEMPLATE IMPLEMENTATION
**************************************************************************************/
Expand Down
11 changes: 11 additions & 0 deletions src/SubscriptionBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
* INCLUDE
**************************************************************************************/

#include <memory>

#include "libcanard/canard.h"

#include "Node.hpp"

/**************************************************************************************
* NAMESPACE
**************************************************************************************/
Expand Down Expand Up @@ -58,4 +62,11 @@ class SubscriptionBase

} /* impl */

/**************************************************************************************
* TYPEDEF
**************************************************************************************/

using Subscription = std::shared_ptr<impl::SubscriptionBase>;


#endif /* INC_107_ARDUINO_CYPHAL_CANARDSUBSCRIPTION_H */

0 comments on commit 51823ce

Please sign in to comment.