20 const multimaster_msgs_fkie::ROSMaster& master1,
21 const multimaster_msgs_fkie::ROSMaster& master2) {
22 return master1.uri == master2.uri;
25 const multimaster_msgs_fkie::ROSMaster& master1,
26 const multimaster_msgs_fkie::ROSMaster& master2) {
27 return !(master1 == master2);
31 const mrpt_msgs::GraphSlamAgent& agent1,
32 const mrpt_msgs::GraphSlamAgent& agent2) {
34 agent1.agent_ID == agent2.agent_ID &&
35 agent1.topic_namespace.data == agent2.topic_namespace.data);
40 const mrpt_msgs::GraphSlamAgent& agent1,
41 const mrpt_msgs::GraphSlamAgent& agent2) {
42 return !(agent1 == agent2);
46 const mrpt_msgs::GraphSlamAgent& agent1,
47 const mrpt_msgs::GraphSlamAgent& agent2) {
48 return agent1.agent_ID < agent2.agent_ID;
53 const multimaster_msgs_fkie::ROSMaster& master,
54 const mrpt_msgs::GraphSlamAgent& agent) {
55 return (master.name == agent.name.data);
59 const multimaster_msgs_fkie::ROSMaster& master,
60 const mrpt_msgs::GraphSlamAgent& agent) {
61 return !(master == agent);
65 const mrpt_msgs::GraphSlamAgent& agent,
66 const multimaster_msgs_fkie::ROSMaster& master) {
67 return (master == agent);
70 const mrpt_msgs::GraphSlamAgent& agent,
71 const multimaster_msgs_fkie::ROSMaster& master) {
72 return (master != agent);
78 mrpt::utils::COutputLogger*
logger,
92 own_ns_tmp.begin() + own_ns_tmp.find_first_not_of(
" /"),
108 mrpt_msgs::GraphSlamAgents* agents_vec,
112 ASSERTMSG_(agents_vec,
"Invalid pointer to vector of GraphSlam Agents.");
119 auto search = [
this](
const mrpt_msgs::GraphSlamAgent& agent) {
120 return (agent.topic_namespace.data == this->own_ns);
123 agents_vec->list.begin(),
124 agents_vec->list.end(),
search);
132 if (it != agents_vec->list.end()) {
133 agents_vec->list.erase(it);
140 const mrpt_msgs::GraphSlamAgents&
145 const mrpt_msgs::GraphSlamAgents&
161 std::vector<ROSMaster>* masters = &(srv.response.masters);
164 for (std::vector<ROSMaster>::const_iterator
165 masters_it = masters->begin();
166 masters_it != masters->end();
175 auto search = [masters_it](
const mrpt_msgs::GraphSlamAgent& agent) {
176 return agent == *masters_it;
184 it->last_seen_time.data =
ros::Time(masters_it->timestamp);
187 mrpt_msgs::GraphSlamAgent new_agent;
188 bool is_agent = this->
convert(*masters_it, &new_agent);
215 "/master_discovery/list_masters");
221 const multimaster_msgs_fkie::ROSMaster& ros_master,
222 mrpt_msgs::GraphSlamAgent* slam_agent) {
224 bool agent_namespace_found =
false;
226 slam_agent->name.data = ros_master.name;
227 slam_agent->is_online.data =
static_cast<bool>(ros_master.online);
231 slam_agent->ip_addr.data = ip_addr;
233 ros_master.uri, &slam_agent->port);
234 slam_agent->hostname.data = hostname;
237 vector<string> tokens;
239 slam_agent->agent_ID = atoi(tokens.rbegin()->c_str());
246 slam_agent->topic_namespace.data = slam_agent->name.data;
251 ASSERTMSG_(got_topics,
"Unable to fetch topics. Exiting.");
254 const std::string& topic_ns =
"/" + slam_agent->topic_namespace.data;
256 const std::string& feedback_ns =
257 "/" + slam_agent->topic_namespace.data +
"/" +
"feedback";
259 auto search = [&feedback_ns](
261 return (
strStarts(topic.name, feedback_ns));
263 ros::master::V_TopicInfo::const_iterator cit = find_if(
264 topics.begin(), topics.end(),
search);
265 if (cit != topics.end()) {
266 agent_namespace_found =
true;
271 slam_agent->last_seen_time.data =
ros::Time(ros_master.timestamp);
272 return agent_namespace_found;
277 const mrpt_msgs::GraphSlamAgent& slam_agent,
278 multimaster_msgs_fkie::ROSMaster* ros_master) {
281 ros_master->name = slam_agent.name.data;
284 ss <<
"http://" << slam_agent.ip_addr <<
":" << slam_agent.port;
285 ros_master->uri = ss.str();
287 ros_master->online = slam_agent.is_online.data;
288 ros_master->discoverer_name =
"/master_discovery";
295 unsigned short* agent_port) {
297 std::string
s = std::string(str.begin()+7, str.end());
299 vector<string> tokens;
303 *agent_port =
static_cast<unsigned short>(atoi(tokens[1].c_str()));
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
const mrpt_msgs::GraphSlamAgents & getNearbySlamAgentsCached() const
Read-only method for accessing list of nearby agents. This doesn't update the internal list of GraphS...
void setupComm()
Wrapper method around the private setup* class methods.
const mrpt_msgs::GraphSlamAgents & getNearbySlamAgents()
Read-only method for accessing list of nearby agents.
bool call(MReq &req, MRes &res)
void updateNearbySlamAgents()
Update the internal list of nearby SLAM agents.
ROSCPP_DECL bool getTopics(V_TopicInfo &topics)
std::vector< TopicInfo > V_TopicInfo
mrpt_msgs::GraphSlamAgents::_list_type::iterator agents_it
std::string own_ns
Namespace under which we are running. Corresponds to the agent_ID_str with which the nodes are going ...
ros::NodeHandle * m_nh
Pointer to the Ros NodeHanle instance.
mrpt_msgs::GraphSlamAgents m_nearby_slam_agents
List of slam agents in the current agent's neighborhood.
const std::string & getNamespace() const
bool operator<(const mrpt_msgs::GraphSlamAgent &agent1, const mrpt_msgs::GraphSlamAgent &agent2)
bool operator==(const multimaster_msgs_fkie::ROSMaster &master1, const multimaster_msgs_fkie::ROSMaster &master2)
ROSMaster instances are considered the same if the "uri" field is the same.
const std::string & getTrimmedNs() const
Get the agent ROS namespace.
bool BASE_IMPEXP strStarts(const std::string &str, const std::string &subStr)
CConnectionManager(mrpt::utils::COutputLogger *logger, ros::NodeHandle *nh_in)
Constructor.
mrpt::utils::COutputLogger * m_logger
Pointer to the logging instance.
ros::ServiceClient m_DiscoverMasters_client
static std::string extractHostnameOrIP(const std::string &str, unsigned short *agent_port=NULL)
Remove http:// prefix and port suffix from the string and return result.
ROSCPP_DECL bool search(const std::string &ns, const std::string &key, std::string &result)
#define ASSERTMSG_(f, __ERROR_MSG)
void BASE_IMPEXP tokenize(const std::string &inString, const std::string &inDelimiters, std::deque< std::string > &outTokens, bool skipBlankTokens=true) MRPT_NO_THROWS
static bool convert(const multimaster_msgs_fkie::ROSMaster &ros_master, mrpt_msgs::GraphSlamAgent *slam_agent)
ROSMaster ==> mrpt_msgs::GraphSlamAgent.
bool operator!=(const multimaster_msgs_fkie::ROSMaster &master1, const multimaster_msgs_fkie::ROSMaster &master2)
~CConnectionManager()
Destructor.