36 #include "std_msgs/String.h" 37 #include "topic_tools/MuxSelect.h" 38 #include "topic_tools/MuxAdd.h" 39 #include "topic_tools/MuxList.h" 40 #include "topic_tools/MuxDelete.h" 68 static list<struct sub_info_t>
g_subs;
83 topic_tools::MuxSelect::Response &res )
91 ROS_DEBUG(
"Unsubscribing to %s, lazy", res.prev_topic.c_str());
99 res.prev_topic = string(
"");
104 ROS_INFO(
"mux selected to no input.");
111 ROS_INFO(
"trying to switch mux to %s", req.topic.c_str());
113 for (list<struct sub_info_t>::iterator it =
g_subs.begin();
120 ROS_INFO(
"mux selected input: [%s]", it->topic_name.c_str());
141 topic_tools::MuxSelect::Response &res )
143 ROS_WARN(
"the <topic>_select service is deprecated; use mux/select instead");
159 for (
static list<struct sub_info_t>::iterator it =
g_subs.begin(); it !=
g_subs.end(); ++it) {
161 ROS_INFO(
"Unregistering from %s", it->topic_name.c_str());
176 ROS_INFO(
"lazy mode; unsubscribing");
186 topic_tools::MuxList::Response& res)
189 for (list<struct sub_info_t>::iterator it =
g_subs.begin();
193 res.topics.push_back(it->topic_name);
200 topic_tools::MuxAdd::Response& res)
204 ROS_INFO(
"trying to add %s to mux", req.topic.c_str());
209 ROS_WARN(
"failed to add topic %s to mux, because it's reserved for special use",
215 for (list<struct sub_info_t>::iterator it =
g_subs.begin();
221 ROS_WARN(
"tried to add a topic that mux was already listening to: [%s]",
222 it->topic_name.c_str());
239 ROS_WARN(
"failed to add topic %s to mux, because it's an invalid name: %s",
240 req.topic.c_str(), e.what());
244 g_subs.push_back(sub_info);
246 ROS_INFO(
"added %s to mux", req.topic.c_str());
252 topic_tools::MuxDelete::Response& res)
256 ROS_INFO(
"trying to delete %s from mux", req.topic.c_str());
258 for (list<struct sub_info_t>::iterator it =
g_subs.begin();
267 ROS_WARN(
"tried to delete currently selected topic %s from mux", req.topic.c_str());
275 ROS_INFO(
"deleted topic %s from mux", req.topic.c_str());
280 ROS_WARN(
"tried to delete non-subscribed topic %s from mux", req.topic.c_str());
284 int main(
int argc,
char **argv)
291 printf(
"\nusage: mux OUT_TOPIC IN_TOPIC1 [IN_TOPIC2 [...]]\n\n");
297 ros::init(argc, argv, topic_name +
string(
"_mux"),
299 vector<string> topics;
300 for (
unsigned int i = 2; i < args.size(); i++)
301 topics.push_back(args[i]);
311 g_pub_selected = mux_nh.advertise<std_msgs::String>(string(
"selected"), 1,
true);
313 for (
size_t i = 0; i < topics.size(); i++)
320 g_subs.push_back(sub_info);
324 std::string initial_topic;
325 pnh.
getParam(
"initial_topic", initial_topic);
327 if (initial_topic.empty())
334 ROS_INFO(
"mux selected to no input.");
340 ROS_INFO(
"trying to switch mux to %s", initial_topic.c_str());
342 for (list<struct sub_info_t>::iterator it =
g_subs.begin();
349 t.data = initial_topic;
350 ROS_INFO(
"mux selected input: [%s]", it->topic_name.c_str());
370 for (list<struct sub_info_t>::iterator it =
g_subs.begin();
int main(int argc, char **argv)
bool add_topic_cb(topic_tools::MuxAdd::Request &req, topic_tools::MuxAdd::Response &res)
void in_cb(const boost::shared_ptr< ShapeShifter const > &msg, ShapeShifter *s)
static list< struct sub_info_t > g_subs
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
bool del_topic_cb(topic_tools::MuxDelete::Request &req, topic_tools::MuxDelete::Response &res)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool list_topic_cb(topic_tools::MuxList::Request &req, topic_tools::MuxList::Response &res)
ROSCPP_DECL std::string resolve(const std::string &name, bool remap=true)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
static ros::Publisher g_pub_selected
static ros::NodeHandle * g_node
static list< struct sub_info_t >::iterator g_selected
void publish(const boost::shared_ptr< M > &message) const
bool getParam(const std::string &key, std::string &s) const
bool sel_srv_cb_dep(topic_tools::MuxSelect::Request &req, topic_tools::MuxSelect::Response &res)
static const string g_none_topic
void conn_cb(const ros::SingleSubscriberPublisher &)
ROSCPP_DECL void removeROSArgs(int argc, const char *const *argv, V_string &args_out)
bool sel_srv_cb(topic_tools::MuxSelect::Request &req, topic_tools::MuxSelect::Response &res)
static string g_output_topic
uint32_t getNumSubscribers() const
static ros::Publisher g_pub