00001 #ifndef BT_ZMQ_PUBLISHER_H 00002 #define BT_ZMQ_PUBLISHER_H 00003 00004 #include <array> 00005 #include <future> 00006 #include "abstract_logger.h" 00007 00008 00009 namespace BT 00010 { 00011 class PublisherZMQ : public StatusChangeLogger 00012 { 00013 static std::atomic<bool> ref_count; 00014 00015 public: 00016 PublisherZMQ(TreeNode* root_node, int max_msg_per_second = 25); 00017 00018 virtual ~PublisherZMQ(); 00019 00020 private: 00021 virtual void callback(Duration timestamp, const TreeNode& node, NodeStatus prev_status, 00022 NodeStatus status) override; 00023 00024 virtual void flush() override; 00025 00026 TreeNode* root_node_; 00027 std::vector<uint8_t> tree_buffer_; 00028 std::vector<uint8_t> status_buffer_; 00029 std::vector<SerializedTransition> transition_buffer_; 00030 std::chrono::microseconds min_time_between_msgs_; 00031 00032 std::atomic_bool active_server_; 00033 std::thread thread_; 00034 00035 void createStatusBuffer(); 00036 00037 TimePoint deadline_; 00038 std::mutex mutex_; 00039 std::atomic_bool send_pending_; 00040 00041 std::future<void> send_future_; 00042 00043 struct Pimpl; 00044 Pimpl* zmq_; 00045 00046 }; 00047 } 00048 00049 #endif // BT_ZMQ_PUBLISHER_H