ROSBridge.h 1.15 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 31 32 33
    void publish(JsonDocUPtr doc);

    void subscribe(const char *topic, const std::function<(JsonDocUPtr)> &callBack);

    const CasePacker *casePacker() const;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
34 35 36 37 38 39 40 41 42

    void start();
    void stop();

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

};
}