#pragma once

#include "ros_bridge/include/com_private.h"
#include "ros_bridge/include/RosBridgeClient.h"

#include <thread>
#include <atomic>
#include <mutex>
#include <condition_variable>

namespace ros_bridge {
namespace com_private {

struct ThreadData;

class TopicPublisher
{
    typedef std::unique_ptr<std::thread> ThreadPtr;
    using CondVar = std::condition_variable;
public:

    TopicPublisher() = delete;
    TopicPublisher(RosbridgeWsClient &rbc);

    ~TopicPublisher();

    //! @brief Starts the publisher.
    void start();

    //! @brief Resets the publisher.
    void reset();

    void publish(JsonDocUPtr docPtr, const char *topic);

private:
    JsonQueue           _queue;
    std::mutex          _mutex;
    std::shared_ptr<std::atomic_bool>   _stopped;
    RosbridgeWsClient  &_rbc;
    CondVar             _cv;
    ThreadPtr           _pThread;
};


} // namespace CommunicatorDetail
} // namespace ROSBridge
