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

#include "ros_bridge/include/ComPrivateInclude.h"
#include "ros_bridge/include/RosBridgeClient.h"
#include "ros_bridge/include/TypeFactory.h"
#include "ros_bridge/include/CasePacker.h"

8 9
#include <unordered_map>

Valentin Platzgummer's avatar
Valentin Platzgummer committed
10 11 12
namespace ROSBridge {
namespace ComPrivate {

13 14 15

typedef std::function<void(JsonDocUPtr)> CallbackType;

Valentin Platzgummer's avatar
Valentin Platzgummer committed
16 17
class TopicSubscriber
{
18
    typedef std::unordered_map<std::string, std::string> TopicMap;
19
public:
Valentin Platzgummer's avatar
Valentin Platzgummer committed
20 21

    TopicSubscriber() = delete;
22
    TopicSubscriber(CasePacker &casePacker, RosbridgeWsClient &rbc);
23
    ~TopicSubscriber();
Valentin Platzgummer's avatar
Valentin Platzgummer committed
24

25
    //! @brief Starts the subscriber.
Valentin Platzgummer's avatar
Valentin Platzgummer committed
26
    void start();
27 28 29

    //! @brief Resets the subscriber.
    void reset();
Valentin Platzgummer's avatar
Valentin Platzgummer committed
30 31 32 33

    //! @return Returns false if a subscription to this topic allready exists.
    //!
    //! @note Only one callback can be registered.
34
    void subscribe(const char* topic, const CallbackType &callback);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
35 36

private:
37 38 39



40 41
    CasePacker         &_casePacker;
    RosbridgeWsClient  &_rbc;
42 43
    TopicMap            _topicMap;
    std::shared_ptr<std::atomic_bool>   _stopped;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
44 45
};

46 47
} // namespace ComPrivate
} // namespace ROSBridge