31 static bool first_instance =
true;
34 first_instance =
false;
38 throw std::logic_error(
"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;
100 flatbuffers::WriteScalar<int8_t>(&status_buffer_[index + 2],
108 using namespace std::chrono;
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::array< uint8_t, 12 > SerializedTransition
PublisherZMQ(TreeNode *root_node, int max_msg_per_second=25)
std::vector< uint8_t > tree_buffer_
std::atomic_bool active_server_
static std::atomic< bool > ref_count
BT_Serialization::Type convertToFlatbuffers(NodeType type)
virtual void flush() override
void createStatusBuffer()
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
uoffset_t GetSize() const
The current size of the serialized buffer, counting from the end.
std::chrono::microseconds min_time_between_msgs_
NodeStatus status() const
void CreateFlatbuffersBehaviorTree(flatbuffers::FlatBufferBuilder &builder, BT::TreeNode *root_node)
std::vector< SerializedTransition > transition_buffer_
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)