31 static bool first_instance =
true;
34 first_instance =
false;
38 throw LogicError(
"Only one instance of PublisherZMQ shall be created");
51 zmq_->
server.setsockopt(ZMQ_RCVTIMEO, &timeout_ms,
sizeof(
int));
55 thread_ = std::thread([
this]() {
69 catch (zmq::error_t& err)
71 std::cout <<
"[PublisherZMQ] just died. Exeption " << err.what() << std::endl;
97 size_t index = status_buffer_.size();
98 status_buffer_.resize(index + 3);
99 flatbuffers::WriteScalar<uint16_t>(&status_buffer_[index], node->UID());
100 flatbuffers::WriteScalar<int8_t>(&status_buffer_[index + 2],
101 static_cast<int8_t>(convertToFlatbuffers(node->status())));
113 std::unique_lock<std::mutex> lock(
mutex_);
120 send_future_ = std::async(std::launch::async, [
this]() {
129 zmq::message_t message;
131 std::unique_lock<std::mutex> lock(
mutex_);
135 message.rebuild(msg_size);
136 uint8_t* data_ptr =
static_cast<uint8_t*
>(message.data());
139 flatbuffers::WriteScalar<uint32_t>(data_ptr,
status_buffer_.size());
140 data_ptr +=
sizeof(uint32_t);
147 data_ptr +=
sizeof(uint32_t);
151 memcpy(data_ptr, transition.data(), transition.size());
152 data_ptr += transition.size();
154 transition_buffer_.clear();
std::vector< uint8_t > status_buffer_
std::vector< uint8_t > tree_buffer_
std::atomic_bool active_server_
static std::atomic< bool > ref_count
virtual void flush() override
void createStatusBuffer()
void CreateFlatbuffersBehaviorTree(flatbuffers::FlatBufferBuilder &builder, const BT::Tree &tree)
std::array< uint8_t, 12 > SerializedTransition
Helper class to hold data needed in creation of a FlatBuffer. To serialize data, you typically call o...
std::future< void > send_future_
virtual void callback(Duration timestamp, const TreeNode &node, NodeStatus prev_status, NodeStatus status) override
PublisherZMQ(const BT::Tree &tree, int max_msg_per_second=25)
uoffset_t GetSize() const
The current size of the serialized buffer, counting from the end.
Abstract base class for Behavior Tree Nodes.
std::chrono::microseconds min_time_between_msgs_
std::vector< SerializedTransition > transition_buffer_
Struct used to store a tree. If this object goes out of scope, the tree is destroyed.
std::chrono::high_resolution_clock::duration Duration
std::atomic_bool send_pending_
void applyRecursiveVisitor(const TreeNode *root_node, const std::function< void(const TreeNode *)> &visitor)
uint8_t * GetBufferPointer() const
Get the serialized buffer (after you call Finish()).
SerializedTransition SerializeTransition(uint16_t UID, Duration timestamp, NodeStatus prev_status, NodeStatus status)