transport_hints.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009, Willow Garage, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice,
7  * this list of conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution.
11  * * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef ROSCPP_TRANSPORT_HINTS_H
29 #define ROSCPP_TRANSPORT_HINTS_H
30 
31 #include "common.h"
32 #include "ros/forwards.h"
33 
34 #include <boost/lexical_cast.hpp>
35 
36 namespace ros
37 {
38 
54 class ROSCPP_DECL TransportHints
55 {
56 public:
61  {
62  tcp();
63 
64  return *this;
65  }
66 
71  {
72  transports_.push_back("TCP");
73  return *this;
74  }
75 
82  TransportHints& tcpNoDelay(bool nodelay = true)
83  {
84  options_["tcp_nodelay"] = nodelay ? "true" : "false";
85  return *this;
86  }
87 
92  {
93  M_string::iterator it = options_.find("tcp_nodelay");
94  if (it == options_.end())
95  {
96  return false;
97  }
98 
99  const std::string& val = it->second;
100  if (val == "true")
101  {
102  return true;
103  }
104 
105  return false;
106  }
107 
114  {
115  options_["max_datagram_size"] = boost::lexical_cast<std::string>(size);
116  return *this;
117  }
118 
124  {
125  M_string::iterator it = options_.find("max_datagram_size");
126  if (it == options_.end())
127  {
128  return 0;
129  }
130 
131  return boost::lexical_cast<int>(it->second);
132  }
133 
138  {
139  udp();
140 
141  return *this;
142  }
143 
148  {
149  transports_.push_back("UDP");
150  return *this;
151  }
152 
156  const V_string& getTransports() { return transports_; }
160  const M_string& getOptions() { return options_; }
161 
162 private:
165 };
166 
167 }
168 
169 #endif
bool getTCPNoDelay()
Returns whether or not this TransportHints has specified TCP_NODELAY.
TransportHints & reliable()
Specifies a reliable transport. Currently this means TCP.
TransportHints & udp()
Explicitly specifies a UDP transport.
const M_string & getOptions()
Returns the map of options created by other methods inside TransportHints.
Provides a way of specifying network transport hints to ros::NodeHandle::subscribe() and someday ros:...
TransportHints & maxDatagramSize(int size)
If a UDP transport is used, specifies the maximum datagram size.
std::map< std::string, std::string > M_string
TransportHints & tcpNoDelay(bool nodelay=true)
If a TCP transport is used, specifies whether or not to use TCP_NODELAY to provide a potentially lowe...
std::vector< std::string > V_string
TransportHints & unreliable()
Specifies an unreliable transport. Currently this means UDP.
int getMaxDatagramSize()
Returns the maximum datagram size specified on this TransportHints, or 0 if no size was specified...
const V_string & getTransports()
Returns a vector of transports, ordered by preference.
TransportHints & tcp()
Explicitly specifies the TCP transport.


roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim, Dirk Thomas
autogenerated on Mon Nov 2 2020 03:52:26