123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #pragma once
- #ifdef WINDOWS_BUILD
- #ifdef MESSAGE_BUS_EXPORTS
- #define MESSAGE_BUS_API _declspec(dllexport)
- #else
- #define MESSAGE_BUS_API _declspec(dllimport)
- #endif
- #elif LINUX_BUILD
- #define MESSAGE_BUS_API
- #endif
- //stl
- #include <map>
- #include <any>
- #include <string>
- #include <functional>
- namespace robotics::v3 {
- class MESSAGE_BUS_API message_bus_impl {
- public:
- /**
- * @brief 单例
- * @return
- */
- static message_bus_impl* instance();
- ~message_bus_impl();
- /**
- * @brief 函数绑定到指定主题。
- * @param str_topic 要绑定的主题名称。
- * @param observer 指示是否作为观察者绑定的布尔值。
- * @param fn 要绑定的函数对象。
- * @return 如果绑定成功则返回 true,否则返回 false。
- */
- bool bind(std::string const& str_topic, bool observer, std::any const& fn);
- /**
- * @brief 查找
- * @param str_topic
- * @return
- */
- std::vector<std::pair<bool, std::any>> find(const std::string& str_topic);
- /**
- * @brief 删除
- * @param str_topic
- */
- void remove(const std::string& str_topic);
- private:
- message_bus_impl();
- private:
- std::multimap<std::string, std::pair<bool, std::any>> map_;
- typedef std::multimap<std::string, std::pair<bool, std::any>>::iterator Iterater;
- };
- }
|