12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #pragma once
- #ifdef WINDOWS_BUILD
- #ifdef MESSAGE_BUS_EXPORTS
- #define MESSAGE_BUS_IMPL _declspec(dllexport)
- #else
- #define MESSAGE_BUS_IMPL _declspec(dllimport)
- #endif
- #endif
- //stl
- #include <map>
- #include <any>
- #include <string>
- #include <functional>
- namespace robotics::v3 {
- #ifdef WINDOWS_BUILD
- class MESSAGE_BUS_IMPL message_bus_impl {
- #elif LINUX_BUILD
- class message_bus_impl {
- #endif
- public:
- /**
- * @brief 单例
- * @return
- */
- static message_bus_impl* instance();
- ~message_bus_impl();
- /**
- * @brief 绑定单个函数
- * @param str_topic
- * @param fn
- * @return
- */
- bool bind(std::string const& str_topic, std::any const& fn);
- /**
- * @brief 绑定多个函数
- * @param str_topic
- * @param fn
- */
- void bind_multiple(std::string const& str_topic, std::any const& fn);
- /**
- * @brief 查找
- * @param str_topic
- * @return
- */
- std::vector<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;
- };
- }
|