From 9f73c6a345e0dc43bdef387973dbbb5d9bff2378 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 28 Mar 2023 04:36:50 +0200 Subject: [PATCH] Fix: always create port/List.1.0 publisher. (#221) If Publishers/Subscriptions/etc. are created as global static objects the order of initialisation is not clear. Hence it could happen that Publisher IDs are not probably registered. --- .../host-example-01-opencyphal-basic-node.cpp | 2 -- src/Node.cpp | 8 ++------ src/Node.hpp | 3 --- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/examples/host-example-01-opencyphal-basic-node/host-example-01-opencyphal-basic-node.cpp b/examples/host-example-01-opencyphal-basic-node/host-example-01-opencyphal-basic-node.cpp index 6d4fc84f..68fb2e6c 100644 --- a/examples/host-example-01-opencyphal-basic-node/host-example-01-opencyphal-basic-node.cpp +++ b/examples/host-example-01-opencyphal-basic-node/host-example-01-opencyphal-basic-node.cpp @@ -58,8 +58,6 @@ int main(int argc, char ** argv) Node node_hdl(node_heap.data(), node_heap.size(), micros, [socket_can_fd] (CanardFrame const & frame) { return (socketcanPush(socket_can_fd, &frame, 1000*1000UL) > 0); }); std::mutex node_mtx; - PortListPublisher port_list_pub = node_hdl.create_port_list_publisher(); - Publisher heartbeat_pub = node_hdl.create_publisher (1*1000*1000UL /* = 1 sec in usecs. */); diff --git a/src/Node.cpp b/src/Node.cpp index f45f557c..c4cf1355 100644 --- a/src/Node.cpp +++ b/src/Node.cpp @@ -40,18 +40,14 @@ Node::Node(uint8_t * heap_ptr, { _canard_hdl.node_id = node_id; _canard_hdl.user_reference = static_cast(_o1heap_ins); + + _opt_port_list_pub = std::make_shared(*this, _micros_func); } /************************************************************************************** * PUBLIC MEMBER FUNCTIONS **************************************************************************************/ -PortListPublisher Node::create_port_list_publisher() -{ - _opt_port_list_pub = std::make_shared(*this, _micros_func); - return _opt_port_list_pub.value(); -} - #if __GNUC__ >= 11 Registry Node::create_registry() { diff --git a/src/Node.hpp b/src/Node.hpp index f04e9ca7..95ccaad8 100644 --- a/src/Node.hpp +++ b/src/Node.hpp @@ -76,9 +76,6 @@ class Node inline CanardNodeID getNodeId() const { return _canard_hdl.node_id; } - PortListPublisher create_port_list_publisher(); - - template Publisher create_publisher(CanardMicrosecond const tx_timeout_usec); template