node_check_switch.cpp
Go to the documentation of this file.
2 
4 {
5  advertised_ = false;
6  nh_.param<std::string>(ros::this_node::getName()+"/check_target_node_name", check_target_node_name_, "target_node");
7  nh_.param<std::string>(ros::this_node::getName()+"/topic_exist", topic_exist_, ros::this_node::getName()+"/topic_exist");
8  nh_.param<std::string>(ros::this_node::getName()+"/topic_not_exist", topic_not_exist_, ros::this_node::getName()+"/topic_not_exist");
9  subscribe_();
10 }
11 
13 {
14 
15 }
16 
18 {
20  boost::shared_ptr<const ros::M_string> const& connection_header = msg_event.getConnectionHeaderPtr();
21  if (!advertised_)
22  {
23  if (connection_header)
24  {
25  exist_pub_ = msg->advertise(nh_, topic_exist_, 10, false);
26  not_exist_pub_ = msg->advertise(nh_, topic_not_exist_, 10, false);
27  }
28  advertised_ = true;
29  }
31  {
32  exist_pub_.publish(msg);
33  }
34  else
35  {
37  }
38  return;
39 }
40 
42 {
43  std::vector<std::string> detected_nodes;
44  ros::master::getNodes(detected_nodes);
45  for(auto itr = detected_nodes.rbegin(); itr != detected_nodes.rend(); ++itr)
46  {
47  if(*itr == check_target_node_name_)
48  {
49  return true;
50  }
51  }
52  return false;
53 }
54 
56 {
58  return;
59 }
60 
62 {
63  if(sub_ptr_)
64  {
65  delete sub_ptr_;
66  sub_ptr_ = NULL;
67  }
68  return;
69 }
volatile bool advertised_
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL const std::string & getName()
const boost::shared_ptr< M_string > & getConnectionHeaderPtr() const
ros::Publisher not_exist_pub_
const boost::shared_ptr< ConstMessage > & getConstMessage() const
ros::Publisher exist_pub_
bool param(const std::string &param_name, T &param_val, const T &default_val) const
std::string topic_exist_
const char * msg
std::string topic_not_exist_
void callback_(const ros::MessageEvent< topic_tools::ShapeShifter > &msg_event)
ros::NodeHandle nh_
ros::Subscriber * sub_ptr_
ROSCPP_DECL bool getNodes(V_string &nodes)
std::string check_target_node_name_


topic_switch
Author(s):
autogenerated on Mon Jun 10 2019 15:27:01