ROSBridge.h 1.22 KB
Newer Older
Valentin Platzgummer's avatar
Valentin Platzgummer committed
1 2 3 4 5 6
#pragma once

#include "ros_bridge/rapidjson/include/rapidjson/document.h"
#include "ros_bridge/include/CasePacker.h"
#include "ros_bridge/include/TypeFactory.h"
#include "ros_bridge/include/JsonFactory.h"
Valentin Platzgummer's avatar
Valentin Platzgummer committed
7
#include "ros_bridge/include/TopicPublisher.h"
Valentin Platzgummer's avatar
Valentin Platzgummer committed
8
#include "ros_bridge/include/TopicSubscriber.h"
Valentin Platzgummer's avatar
Valentin Platzgummer committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

#include <memory>
#include <tuple>

#include "boost/lockfree/queue.hpp"

namespace ROSBridge {
class ROSBridge
{
public:    
    typedef MessageTag Tag;
    typedef rapidjson::Document JsonDoc;
    typedef std::unique_ptr<JsonDoc> JsonDocUPtr;

    explicit ROSBridge();

    template<class T>
Valentin Platzgummer's avatar
Valentin Platzgummer committed
26 27
    void publish(T &msg, const std::string &topic){
        _topicPublisher.publish(msg, topic);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
28
    }
Valentin Platzgummer's avatar
Valentin Platzgummer committed
29 30
    void publish(JsonDocUPtr doc);

31
    void subscribe(const char *topic, const std::function<void(JsonDocUPtr)> &callBack);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
32 33

    const CasePacker *casePacker() const;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
34

35
    //! @brief Start ROS bridge.
Valentin Platzgummer's avatar
Valentin Platzgummer committed
36
    void start();
37 38
    //! @brief Reset ROS bridge.
    void reset();
Valentin Platzgummer's avatar
Valentin Platzgummer committed
39 40 41 42 43 44

private:
    TypeFactory             _typeFactory;
    JsonFactory             _jsonFactory;
    CasePacker              _casePacker;
    RosbridgeWsClient       _rbc;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
45 46
    ComPrivate::TopicPublisher     _topicPublisher;
    ComPrivate::TopicSubscriber    _topicSubscriber;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
47 48 49

};
}