IPCPublisherManager.h 1.66 KB
Newer Older
嵇洲's avatar
嵇洲 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
/***
 * @Description: 生产者管理类 内含3个不同主题发布者
 * @Author: jizhou
 * @Date: 2023-07-13 19:13:44
 * @LastEditors: jizhou
 * @LastEditTime: 2023-07-16 23:57:01
 * @FilePath: /EnvironmentAccess/src/manager/IPCPublisherManager.h
 */
#ifndef FAST_DDS_GENERATED__IPCPublisherManager
#define FAST_DDS_GENERATED__IPCPublisherManager

#include <string>

#include "BaseManager.h"
#include "fastdds/IPCPublisher.h"

using namespace std;

class IPCPublisherManager : public BaseManager<IPCPublisherManager> {
private:
    /***
     * @brief: 构造函数
     * @return {*}
     */
    IPCPublisherManager() = default;


    std::map<std::string, std::shared_ptr<IPCPublisherBase>> publishers_;
    
public:
    /***
     * @brief: 析构函数
     * @return {*}
     */
    
    ~IPCPublisherManager() = default;

    friend class BaseManager;

     template<typename MessageT>
    std::shared_ptr<IPCPublisher<MessageT>> createPublisher(const std::string& topic, size_t qos_profile_depth) {
        auto publisher = std::make_shared<IPCPublisher<MessageT>>(0, topic);
        publishers_[topic] = publisher;
        return publisher;
    }

    template<typename MessageT>
    std::shared_ptr<IPCPublisher<MessageT>> getPublisherByTopic(const std::string& topic) {
        auto it = publishers_.find(topic);
        if (it != publishers_.end()) {
            return std::dynamic_pointer_cast<IPCPublisher<MessageT>>(it->second);
        }
        return nullptr;
    }

    //publish("topic",<T>xxxxx)
    
    void stopAll() {
        auto iter = publishers_.begin();
        for(; iter!= publishers_.end(); iter++) {
            iter->second->stop();
        }
    }

};

#endif