#ifndef THREAD_PUBLISHER_H_
#define THREAD_PUBLISHER_H_
#include <string>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <vector>
#include <queue>
#include <functional>

template <typename T>
class ThreadPublisher {
public:
  ThreadPublisher();
  ~ThreadPublisher();

  void Register(std::function<void(const std::shared_ptr<const T>&)> cb);
  void Start();
  void Publish(const std::shared_ptr<const T> msg);
  void Process();
  void ShutDown();

private:
  std::mutex msg_mutex_;
  std::condition_variable msg_cond_;
  std::queue<std::shared_ptr<const T>> msgs_;
  std::thread publish_thread_;
  std::vector<std::function<void(const std::shared_ptr<const T>&)>> callbacks_;
  bool shutdown_requested_;
};

#endif  // THREAD_PUBLISHER_H_
