From e24fa5f23658f6bff05cbf4d01674660533968c4 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Mon, 8 Jun 2015 12:37:31 +0300 Subject: [PATCH] SubNode<> --- .../include/uavcan/node/abstract_node.hpp | 1 + libuavcan/include/uavcan/node/node.hpp | 1 - libuavcan/include/uavcan/node/sub_node.hpp | 66 +++++++++++++++++++ libuavcan/test/node/node.cpp | 1 + 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 libuavcan/include/uavcan/node/sub_node.hpp diff --git a/libuavcan/include/uavcan/node/abstract_node.hpp b/libuavcan/include/uavcan/node/abstract_node.hpp index a9c80466d9..1dc458cbb4 100644 --- a/libuavcan/include/uavcan/node/abstract_node.hpp +++ b/libuavcan/include/uavcan/node/abstract_node.hpp @@ -6,6 +6,7 @@ #define UAVCAN_NODE_ABSTRACT_NODE_HPP_INCLUDED #include +#include #include namespace uavcan diff --git a/libuavcan/include/uavcan/node/node.hpp b/libuavcan/include/uavcan/node/node.hpp index d5b9731c8a..37900c0729 100644 --- a/libuavcan/include/uavcan/node/node.hpp +++ b/libuavcan/include/uavcan/node/node.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include // High-level functionality available by default diff --git a/libuavcan/include/uavcan/node/sub_node.hpp b/libuavcan/include/uavcan/node/sub_node.hpp new file mode 100644 index 0000000000..ec5484365d --- /dev/null +++ b/libuavcan/include/uavcan/node/sub_node.hpp @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2015 Pavel Kirienko + */ + +#ifndef UAVCAN_SUB_NODE_NODE_HPP_INCLUDED +#define UAVCAN_SUB_NODE_NODE_HPP_INCLUDED + +#include +#include +#include + +#if UAVCAN_TINY +# error "This functionality is not available in tiny mode" +#endif + +namespace uavcan +{ +/** + * This node object can be used in multiprocess UAVCAN nodes. + * Please refer to the @ref Node<> for documentation concerning the template arguments; refer to the tutorials + * to lean how to use libuavcan in multiprocess applications. + */ +template +class UAVCAN_EXPORT SubNode : public INode +{ + enum + { + MemPoolSize = (MemPoolSize_ < std::size_t(MemPoolBlockSize)) ? std::size_t(MemPoolBlockSize) : MemPoolSize_ + }; + + typedef PoolAllocator Allocator; + + Allocator pool_allocator_; + OutgoingTransferRegistry outgoing_trans_reg_; + Scheduler scheduler_; + + uint64_t internal_failure_cnt_; + +protected: + virtual void registerInternalFailure(const char* msg) + { + internal_failure_cnt_++; + UAVCAN_TRACE("Node", "Internal failure: %s", msg); + (void)msg; + } + +public: + SubNode(ICanDriver& can_driver, ISystemClock& system_clock) : + outgoing_trans_reg_(pool_allocator_), + scheduler_(can_driver, pool_allocator_, system_clock, outgoing_trans_reg_), + internal_failure_cnt_(0) + { } + + virtual Allocator& getAllocator() { return pool_allocator_; } + + virtual Scheduler& getScheduler() { return scheduler_; } + virtual const Scheduler& getScheduler() const { return scheduler_; } + + uint64_t getInternalFailureCount() const { return internal_failure_cnt_; } +}; + +} + +#endif // Include guard diff --git a/libuavcan/test/node/node.cpp b/libuavcan/test/node/node.cpp index 2598907abb..a9ddc6ec03 100644 --- a/libuavcan/test/node/node.cpp +++ b/libuavcan/test/node/node.cpp @@ -4,6 +4,7 @@ #include #include +#include // Compilability test #include #include "test_node.hpp" #include "../protocol/helpers.hpp"