#pragma once #include #include #include #include "navmon.pb.h" #include #include class NMMSender { struct Destination { int fd{-1}; std::string dst; std::string fname; std::deque queue; std::mutex mut; void emitNMM(const std::string& out, bool compress); }; public: void addDestination(int fd) { auto d = std::make_unique(); d->fd = fd; d_dests.push_back(std::move(d)); } void addDestination(const std::string& dest) { auto d = std::make_unique(); d->dst = dest; d_dests.push_back(std::move(d)); } void launch() { for(auto& d : d_dests) { if(!d->dst.empty()) { d_thread.emplace_back(std::move(std::make_unique(&NMMSender::sendTCPThread, this, d.get()))); } } } void sendTCPThread(Destination* d); void emitNMM(const NavMonMessage& nmm); void emitNMM(const std::string& out); bool d_debug{false}; bool d_compress{false}; // set BEFORE launch bool d_pleaseQuit{false}; ~NMMSender() { if(!d_thread.empty()) { d_pleaseQuit = true; for(auto& t : d_thread) t->join(); } } private: std::vector> d_dests; std::vector> d_thread; };