ROSCommunicator.h 1.1 KB
Newer Older
1 2
#pragma once

3
#include "ros_bridge/rapidjson/include/rapidjson/document.h"
Valentin Platzgummer's avatar
Valentin Platzgummer committed
4 5
#include "ros_bridge/include/PackageQueue.h"
#include "ros_bridge/include/CasePacker.h"
6

7 8
#include <memory>
#include <tuple>
9

10 11 12 13
#include "boost/lockfree/queue.hpp"

namespace ROSBridge {
namespace lf = ::boost::lockfree;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
14
class Communicator : protected CasePacker
15
{
Valentin Platzgummer's avatar
Valentin Platzgummer committed
16 17 18 19 20
    typedef MessageTag Tag;
    typedef rapidjson::Document JsonDoc;
    typedef std::shared_ptr<JsonDoc> JsonDocShardPtr;
    typedef PackageQueue<JsonDocShardPtr> Buffer;
    //typedef std::tuple<UniqueJsonPtr, std::string> MsgTopicHashPair;
21
public:
Valentin Platzgummer's avatar
Valentin Platzgummer committed
22 23 24 25 26 27 28
  explicit Communicator() : CasePacker() {}

    template<class T>
    void send(T &msg, std::string &topic){
        JsonDocShardPtr docPtr(CasePacker::pack(msg, topic));
        _transmittBuffer.push(docPtr);
    }
29

30 31
    void start();
    void stop();
Valentin Platzgummer's avatar
Valentin Platzgummer committed
32 33 34 35 36 37
    bool messagesAvailable();
    bool showMessageTag(Tag &tag);
    template<class T>
    void receive(T &msg){

    }
38

39
private:
Valentin Platzgummer's avatar
Valentin Platzgummer committed
40 41 42
    Buffer              _transmittBuffer;
    Buffer              _receiveBuffer;
    JsonDocShardPtr     _stagedMessage; // message awaiting delivery
43
};
44
}