|
@@ -2626,36 +2626,10 @@ namespace robotics::v2 {
|
|
nexus_net_manager& manager_;
|
|
nexus_net_manager& manager_;
|
|
};
|
|
};
|
|
public:
|
|
public:
|
|
- //构造
|
|
|
|
- nexus_net_multiple_client(nexus_net_client_xml_config const& config) :
|
|
|
|
- nexus_net_multiple_client(config.name, config.client) {
|
|
|
|
- }
|
|
|
|
- //构造
|
|
|
|
- nexus_net_multiple_client(std::string const& app_name, int client_size = 1) :
|
|
|
|
- subscribe_name_(app_name) {
|
|
|
|
- register_once();
|
|
|
|
- client_.reset(new nexus_net_tcp_client(client_size));
|
|
|
|
- message_invoke_.reset(new message_invoke(manager_));
|
|
|
|
- client_->connect_event.bind(&nexus_net_multiple_client::on_connect, this);
|
|
|
|
- client_->connect_fail_event.bind(&nexus_net_multiple_client::on_connect_fail, this);
|
|
|
|
- client_->disconnect_event.bind(&nexus_net_multiple_client::on_disconnect, this);
|
|
|
|
- client_->recv_event.bind(&nexus_net_multiple_client::on_recv, this);
|
|
|
|
- message_invoke_->response_event.bind(&nexus_net_multiple_client::on_response, this);
|
|
|
|
- timer_.timeout_event.bind(&nexus_net_multiple_client::on_heartbeat, this);
|
|
|
|
- }
|
|
|
|
- //构造
|
|
|
|
- nexus_net_multiple_client(int clientSize = 1) {
|
|
|
|
- auto config = nexus_net_xml_config::find_client();
|
|
|
|
- if (!config.enable)
|
|
|
|
- return;
|
|
|
|
- subscribe_name_ = config.name;
|
|
|
|
- register_once();
|
|
|
|
- client_.reset(new nexus_net_tcp_client(clientSize));
|
|
|
|
- client_->connect_event.bind(&nexus_net_multiple_client::on_connect, this);
|
|
|
|
- client_->connect_fail_event.bind(&nexus_net_multiple_client::on_connect_fail, this);
|
|
|
|
- client_->disconnect_event.bind(&nexus_net_multiple_client::on_disconnect, this);
|
|
|
|
- client_->recv_event.bind(&nexus_net_multiple_client::on_recv, this);
|
|
|
|
- timer_.timeout_event.bind(&nexus_net_multiple_client::on_heartbeat, this);
|
|
|
|
|
|
+ //单例
|
|
|
|
+ static nexus_net_multiple_client* instance() {
|
|
|
|
+ static nexus_net_multiple_client g_nexus_net_multiple_client;
|
|
|
|
+ return &g_nexus_net_multiple_client;
|
|
}
|
|
}
|
|
//析构
|
|
//析构
|
|
~nexus_net_multiple_client() {
|
|
~nexus_net_multiple_client() {
|
|
@@ -2680,7 +2654,7 @@ namespace robotics::v2 {
|
|
auto config = nexus_net_xml_config::find_client();
|
|
auto config = nexus_net_xml_config::find_client();
|
|
if (!config.enable)
|
|
if (!config.enable)
|
|
return false;
|
|
return false;
|
|
- return start(config.ip, config.port);
|
|
|
|
|
|
+ return start(config.name, config.ip, config.port);
|
|
}
|
|
}
|
|
//停止
|
|
//停止
|
|
void stop() {
|
|
void stop() {
|
|
@@ -2765,9 +2739,17 @@ namespace robotics::v2 {
|
|
throw std::runtime_error("key禁用或不存在.");
|
|
throw std::runtime_error("key禁用或不存在.");
|
|
manager_.add(std::pair(subscribe.group, subscribe.name), (typename v3::function_traits<_Fn>::stl_function_type)(std::bind_front(std::forward<_Fn>(fn), std::forward<_Ths>(ths))));
|
|
manager_.add(std::pair(subscribe.group, subscribe.name), (typename v3::function_traits<_Fn>::stl_function_type)(std::bind_front(std::forward<_Fn>(fn), std::forward<_Ths>(ths))));
|
|
}
|
|
}
|
|
|
|
+ //订阅
|
|
|
|
+ template<typename _Fn, typename _This>
|
|
|
|
+ bool subscribe(std::string const& subscribe_key, _Fn&& fn, _This&& ths) {
|
|
|
|
+ auto subscribe = nexus_net_xml_config::find_subscribe(subscribe_key);
|
|
|
|
+ if (!subscribe.enable)
|
|
|
|
+ return false;
|
|
|
|
+ manager_.add(std::pair(subscribe.group, subscribe.name), (typename v3::function_traits<_Fn>::stl_function_type)(std::bind_front(std::forward<_Fn>(fn), std::forward<_Ths>(ths))));
|
|
|
|
+ }
|
|
//调用
|
|
//调用
|
|
template<typename _Ret, typename ..._Args>
|
|
template<typename _Ret, typename ..._Args>
|
|
- _Ret config_call(std::string const& publishers_key, _Args &&...args) {
|
|
|
|
|
|
+ _Ret publisher(std::string const& publishers_key, _Args &&...args) {
|
|
auto publishers = nexus_net_xml_config::find_publisher(publishers_key);
|
|
auto publishers = nexus_net_xml_config::find_publisher(publishers_key);
|
|
//遍历发布
|
|
//遍历发布
|
|
for (auto& it : publishers) {
|
|
for (auto& it : publishers) {
|
|
@@ -3167,6 +3149,39 @@ namespace robotics::v2 {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
private:
|
|
private:
|
|
|
|
+ //构造
|
|
|
|
+ nexus_net_multiple_client(nexus_net_client_xml_config const& config) :
|
|
|
|
+ nexus_net_multiple_client(config.name, config.client) {
|
|
|
|
+ }
|
|
|
|
+ //构造
|
|
|
|
+ nexus_net_multiple_client(std::string const& app_name, int client_size = 1) :
|
|
|
|
+ subscribe_name_(app_name) {
|
|
|
|
+ register_once();
|
|
|
|
+ client_.reset(new nexus_net_tcp_client(client_size));
|
|
|
|
+ message_invoke_.reset(new message_invoke(manager_));
|
|
|
|
+ client_->connect_event.bind(&nexus_net_multiple_client::on_connect, this);
|
|
|
|
+ client_->connect_fail_event.bind(&nexus_net_multiple_client::on_connect_fail, this);
|
|
|
|
+ client_->disconnect_event.bind(&nexus_net_multiple_client::on_disconnect, this);
|
|
|
|
+ client_->recv_event.bind(&nexus_net_multiple_client::on_recv, this);
|
|
|
|
+ message_invoke_->response_event.bind(&nexus_net_multiple_client::on_response, this);
|
|
|
|
+ timer_.timeout_event.bind(&nexus_net_multiple_client::on_heartbeat, this);
|
|
|
|
+ }
|
|
|
|
+ //构造
|
|
|
|
+ nexus_net_multiple_client(int clientSize = 1) {
|
|
|
|
+ auto config = nexus_net_xml_config::find_client();
|
|
|
|
+ if (!config.enable)
|
|
|
|
+ return;
|
|
|
|
+ subscribe_name_ = config.name;
|
|
|
|
+ register_once();
|
|
|
|
+ client_.reset(new nexus_net_tcp_client(clientSize));
|
|
|
|
+ message_invoke_.reset(new message_invoke(manager_));
|
|
|
|
+ client_->connect_event.bind(&nexus_net_multiple_client::on_connect, this);
|
|
|
|
+ client_->connect_fail_event.bind(&nexus_net_multiple_client::on_connect_fail, this);
|
|
|
|
+ client_->disconnect_event.bind(&nexus_net_multiple_client::on_disconnect, this);
|
|
|
|
+ client_->recv_event.bind(&nexus_net_multiple_client::on_recv, this);
|
|
|
|
+ message_invoke_->response_event.bind(&nexus_net_multiple_client::on_response, this);
|
|
|
|
+ timer_.timeout_event.bind(&nexus_net_multiple_client::on_heartbeat, this);
|
|
|
|
+ }
|
|
//注册结构体
|
|
//注册结构体
|
|
void register_class() {
|
|
void register_class() {
|
|
rttr::registration::class_<struct nexus_net_node_app_info>("NexusNetNodeAppInfo").constructor<>()(rttr::detail::as_object{}).
|
|
rttr::registration::class_<struct nexus_net_node_app_info>("NexusNetNodeAppInfo").constructor<>()(rttr::detail::as_object{}).
|