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 
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
#define ROS_WARN(...)
int main(int argc, char **argv)
Definition: switch_mux.cpp:40
TOPIC_TOOLS_DECL bool getBaseName(const std::string &full_name, std::string &base_name)
Definition: parse.cpp:40
#define ROS_INFO(...)
#define ROS_ERROR(...)
ROSCPP_DECL bool waitForService(const std::string &service_name, int32_t timeout)


topic_tools
Author(s): Morgan Quigley, Brian Gerkey, Dirk Thomas
autogenerated on Mon Feb 28 2022 23:34:17