switch_mux.cpp
Go to the documentation of this file.
1 // The mux package provides a generic multiplexer
3 //
4 // Copyright (C) 2008, Morgan Quigley
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Stanford University nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
29 
30 
31 #include <cstdio>
32 #include "ros/console.h"
33 #include "ros/ros.h"
34 #include "topic_tools/MuxSelect.h"
35 #include "topic_tools/parse.h"
36 using namespace std;
37 using namespace ros;
38 using namespace topic_tools;
39 
40 int main(int argc, char **argv)
41 {
42  ROS_WARN("topic_tools/switch_mux is deprecated; please use topic_tools/mux_select instead");
43  if (argc < 3)
44  {
45  printf("usage: switch MUXED_TOPIC SELECT_TOPIC\n");
46  return 1;
47  }
48  std::string topic_name;
49  if(!getBaseName(string(argv[1]), topic_name))
50  return 1;
51  ros::init(argc, argv, topic_name + string("_switcher"));
52  ros::NodeHandle nh;
53  string srv_name = string(argv[1]) + "_select";
54  ROS_INFO("Waiting for service %s...\n", srv_name.c_str());
55  ros::service::waitForService(srv_name, -1);
56  ros::ServiceClient client = nh.serviceClient<MuxSelect>(srv_name);
57  MuxSelect cmd;
58  cmd.request.topic = argv[2];
59  if (client.call(cmd))
60  {
61  ROS_INFO("muxed topic %s successfully switched from %s to %s",
62  argv[1], cmd.response.prev_topic.c_str(),
63  cmd.request.topic.c_str());
64  return 0;
65  }
66  else
67  {
68  ROS_ERROR("failed to switch muxed topic %s to %s",
69  argv[1], cmd.request.topic.c_str());
70  return 1;
71  }
72 }
73 
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros
ros.h
ros::NodeHandle::serviceClient
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
parse.h
console.h
main
int main(int argc, char **argv)
Definition: switch_mux.cpp:40
ros::ServiceClient
ROS_WARN
#define ROS_WARN(...)
topic_tools::getBaseName
TOPIC_TOOLS_DECL bool getBaseName(const std::string &full_name, std::string &base_name)
Definition: parse.cpp:40
std
ROS_ERROR
#define ROS_ERROR(...)
ros::ServiceClient::call
bool call(const MReq &req, MRes &resp, const std::string &service_md5sum)
ros::service::waitForService
ROSCPP_DECL bool waitForService(const std::string &service_name, int32_t timeout)
ROS_INFO
#define ROS_INFO(...)
topic_tools
Definition: parse.h:33
ros::NodeHandle


topic_tools
Author(s): Morgan Quigley, Brian Gerkey, Dirk Thomas , Jacob Perron
autogenerated on Sat Sep 14 2024 03:00:05