|
@@ -137,7 +137,15 @@ namespace robotics {
|
|
|
/**
|
|
|
* @brief 详情响应
|
|
|
*/
|
|
|
- REPDETAILS
|
|
|
+ REPDETAILS,
|
|
|
+ /**
|
|
|
+ * @brief 关注
|
|
|
+ */
|
|
|
+ FOLLOW,
|
|
|
+ /**
|
|
|
+ * @brief 关注响应
|
|
|
+ */
|
|
|
+ REPFOLLOW
|
|
|
};
|
|
|
/**
|
|
|
* @brief 消息
|
|
@@ -487,7 +495,9 @@ namespace robotics {
|
|
|
{(std::uint8_t)nexus_net_msg_type_enum::REPPUBLISHER, "发布响应"},
|
|
|
{(std::uint8_t)nexus_net_msg_type_enum::HEARTBEAT, "心跳"},
|
|
|
{(std::uint8_t)nexus_net_msg_type_enum::DETAILS, "详情"},
|
|
|
- {(std::uint8_t)nexus_net_msg_type_enum::REPDETAILS, "详情响应"}
|
|
|
+ {(std::uint8_t)nexus_net_msg_type_enum::REPDETAILS, "详情响应"},
|
|
|
+ {(std::uint8_t)nexus_net_msg_type_enum::FOLLOW, "关注"},
|
|
|
+ {(std::uint8_t)nexus_net_msg_type_enum::REPFOLLOW, "关注响应"}
|
|
|
};
|
|
|
auto config = read();
|
|
|
auto it = std::find_if(config.loggers.begin(), config.loggers.end(), [=](auto& it) {
|
|
@@ -683,6 +693,13 @@ namespace robotics {
|
|
|
return std::nullopt;
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * @brief 添加关注节点
|
|
|
+ * @param values
|
|
|
+ */
|
|
|
+ void add_follow(std::vector<std::string> const& values) {
|
|
|
+ follow_list_ = values;
|
|
|
+ }
|
|
|
/**
|
|
|
* @brief 添加订阅
|
|
|
* @tparam _Fn
|
|
@@ -823,6 +840,10 @@ namespace robotics {
|
|
|
* @brief 连接状态
|
|
|
*/
|
|
|
v3::delegates<bool> connect_event;
|
|
|
+ /**
|
|
|
+ * @brief 关注事件
|
|
|
+ */
|
|
|
+ v3::delegates<std::vector<std::string>> follow_event;
|
|
|
private:
|
|
|
/**
|
|
|
* @brief 构造
|
|
@@ -883,6 +904,15 @@ namespace robotics {
|
|
|
send(it);
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * @brief 关注节点
|
|
|
+ */
|
|
|
+ void follow() {
|
|
|
+ nexus_net_message msg;
|
|
|
+ msg.msg_type = (std::uint8_t)nexus_net_msg_type_enum::FOLLOW;
|
|
|
+ msg.args << follow_list_;
|
|
|
+ send(msg);
|
|
|
+ }
|
|
|
private:
|
|
|
void on_connect(bool success, std::string const& msg) {
|
|
|
if (success) {
|
|
@@ -906,6 +936,7 @@ namespace robotics {
|
|
|
case nexus_net_msg_type_enum::PUBLISHER: on_publisher(data); break;
|
|
|
case nexus_net_msg_type_enum::REPPUBLISHER: on_reppublisher(data); break;
|
|
|
case nexus_net_msg_type_enum::REPSUBSCRIBE: on_repsubscribe(data); break;
|
|
|
+ case nexus_net_msg_type_enum::REPFOLLOW: on_follow(data); break;
|
|
|
}
|
|
|
}
|
|
|
catch (std::exception const& ec) {
|
|
@@ -937,6 +968,7 @@ namespace robotics {
|
|
|
if (is_heartbeat_) {
|
|
|
authorize_event(true, parent_code_, parent_name_);
|
|
|
subscribe();
|
|
|
+ follow();
|
|
|
}
|
|
|
else {
|
|
|
authorize_event(false, "", "");
|
|
@@ -975,12 +1007,28 @@ namespace robotics {
|
|
|
message_manage_.set_data(data.msg_id, data);
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * @brief 关注节点响应
|
|
|
+ * @param data
|
|
|
+ */
|
|
|
+ void on_follow(nexus_net_message data) {
|
|
|
+ std::vector<std::string> follows;
|
|
|
+ try {
|
|
|
+ data.args >> follows;
|
|
|
+ follow_event(follows);
|
|
|
+ }
|
|
|
+ catch (std::exception const& ec) {
|
|
|
+ LOG_ERROR << "解析关注节点失败:" << ec;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
private:
|
|
|
v3::timer timer_;
|
|
|
std::string parent_code_;
|
|
|
std::string parent_name_;
|
|
|
bool is_heartbeat_ = false;
|
|
|
nexus_net_tcp_client client_;
|
|
|
+ std::vector<std::string> follow_list_;
|
|
|
std::mutex caller_mutex_;
|
|
|
std::map<std::thread::id, nexus_net_message> caller_message_list_;
|
|
|
message_manage message_manage_;
|