|
@@ -47,6 +47,19 @@ namespace robotics {
|
|
|
auto func = v3::to_function(std::forward<_Fn>(f));
|
|
|
return add(str_topic, observer, std::move(func));
|
|
|
}
|
|
|
+ /**
|
|
|
+ * @brief 注册消息
|
|
|
+ * @tparam _Fn
|
|
|
+ * @param str_app
|
|
|
+ * @param str_topic
|
|
|
+ * @param observer
|
|
|
+ * @param f
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ template<typename _Fn>
|
|
|
+ bool bind(std::string const& str_app, std::string const& str_topic, bool observer, _Fn&& f) {
|
|
|
+ return bind<_Fn>(str_app + "_" + str_topic, observer, std::forward<_Fn>(f));
|
|
|
+ }
|
|
|
/**
|
|
|
* @brief 注册消息
|
|
|
* @tparam _Fn
|
|
@@ -58,13 +71,31 @@ namespace robotics {
|
|
|
* @return
|
|
|
*/
|
|
|
template<typename _Fn, typename _Obj>
|
|
|
- bool bind(const std::string& str_topic, bool observer, _Fn&& f, _Obj&& obj) {
|
|
|
+ bool bind(std::string const& str_topic, bool observer, _Fn&& f, _Obj&& obj) {
|
|
|
auto func = v3::to_function((v3::function_traits<_Fn>::stl_function_type)(std::bind_front(std::forward<_Fn>(f), std::forward<_Obj>(obj))));
|
|
|
return add(str_topic, observer, std::move(func));
|
|
|
}
|
|
|
+ /**
|
|
|
+ * @brief 注册消息
|
|
|
+ * @tparam _Fn
|
|
|
+ * @tparam _Obj
|
|
|
+ * @param str_app
|
|
|
+ * @param str_topic
|
|
|
+ * @param observer
|
|
|
+ * @param f
|
|
|
+ * @param obj
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ template<typename _Fn, typename _Obj>
|
|
|
+ bool bind(std::string const& str_app, std::string const& str_topic, bool observer, _Fn&& f, _Obj&& obj) {
|
|
|
+ return bind<_Fn, _Obj>(str_app + "_" + str_topic, observer, std::forward<_Fn>(f), std::forward<_Obj>(obj));
|
|
|
+ }
|
|
|
/**
|
|
|
* @brief 发送消息
|
|
|
- * @param str_topic
|
|
|
+ * @tparam _Ret
|
|
|
+ * @tparam _BCast
|
|
|
+ * @param str_topic
|
|
|
+ * @return
|
|
|
*/
|
|
|
template<typename _Ret,bool _BCast = false>
|
|
|
_Ret invoke(const std::string& str_topic) {
|
|
@@ -96,9 +127,24 @@ namespace robotics {
|
|
|
}
|
|
|
/**
|
|
|
* @brief 发送消息
|
|
|
- * @tparam ..._Args
|
|
|
- * @param str_topic
|
|
|
- * @param ...args
|
|
|
+ * @tparam _Ret
|
|
|
+ * @tparam _BCast
|
|
|
+ * @param str_app
|
|
|
+ * @param str_topic
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ template<typename _Ret, bool _BCast = false>
|
|
|
+ _Ret call(std::string const& str_app, std::string const& str_topic) {
|
|
|
+ return invoke<_Ret, _BCast>(str_app + "_" + str_topic);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @brief 发送消息
|
|
|
+ * @tparam ..._Args
|
|
|
+ * @tparam _Ret
|
|
|
+ * @tparam _BCast
|
|
|
+ * @param str_topic
|
|
|
+ * @param ...args
|
|
|
+ * @return
|
|
|
*/
|
|
|
template<typename _Ret, bool _BCast = false,typename... _Args>
|
|
|
_Ret invoke(const std::string& str_topic, _Args ...args) {
|
|
@@ -128,17 +174,42 @@ namespace robotics {
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * @brief 发送消息
|
|
|
+ * @tparam _Ret
|
|
|
+ * @tparam ..._Args
|
|
|
+ * @tparam _BCast
|
|
|
+ * @param str_app
|
|
|
+ * @param str_topic
|
|
|
+ * @param ...args
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ template<typename _Ret, bool _BCast = false, typename... _Args>
|
|
|
+ _Ret call(std::string const& str_app, std::string const& str_topic, _Args ...args) {
|
|
|
+ return invoke<_Ret, _BCast, _Args...>(str_app + "_" + str_topic, std::forward<_Args>(args)...);
|
|
|
+ }
|
|
|
/**
|
|
|
* @brief 移除某个主题,需要主题和消息类型
|
|
|
* @tparam ...Args
|
|
|
* @param strTopic
|
|
|
*/
|
|
|
- template<typename..._Args>
|
|
|
- void remove(const std::string& str_topic) {
|
|
|
- using function_type = std::function<void(_Args...)>;
|
|
|
+ template<typename _Ret,typename..._Args>
|
|
|
+ void remove(std::string const& str_topic) {
|
|
|
+ using function_type = std::function<_Ret(_Args...)>;
|
|
|
std::string str_msg_type = str_topic + typeid(function_type).name();
|
|
|
message_bus_impl_->remove(str_msg_type);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * @brief 移除某个主题,需要主题和消息类型
|
|
|
+ * @tparam _Ret
|
|
|
+ * @tparam ..._Args
|
|
|
+ * @param str_app
|
|
|
+ * @param str_topic
|
|
|
+ */
|
|
|
+ template<typename _Ret, typename..._Args>
|
|
|
+ void remove(std::string const& str_app, std::string const& str_topic) {
|
|
|
+ remove<_Ret, _Args...>(str_app + "_" + str_topic);
|
|
|
+ }
|
|
|
private:
|
|
|
/**
|
|
|
* @brief 单个添加
|