connection_manager.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 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 #include "forwards.h"
29 #include "connection.h"
30 #include "common.h"
31 
32 #include <boost/thread/mutex.hpp>
33 #include <boost/signals2/connection.hpp>
34 
35 namespace ros
36 {
37 
40 
43 
44 class ROSCPP_DECL ConnectionManager
45 {
46 public:
47  static const ConnectionManagerPtr& instance();
48 
51 
54  uint32_t getNewConnectionID();
55 
60  void addConnection(const ConnectionPtr& connection);
61 
62  void clear(Connection::DropReason reason);
63 
64  uint32_t getTCPPort();
65  uint32_t getUDPPort();
66 
67  const TransportTCPPtr& getTCPServerTransport() { return tcpserver_transport_; }
68  const TransportUDPPtr& getUDPServerTransport() { return udpserver_transport_; }
69 
70  void udprosIncomingConnection(const TransportUDPPtr& transport, Header& header);
71 
72  void start();
73  void shutdown();
74 
75 private:
76  void onConnectionDropped(const ConnectionPtr& conn);
77  // Remove any dropped connections from our list, causing them to be destroyed
78  // They can't just be removed immediately when they're dropped because the ros
79  // thread may still be using them (or more likely their transport)
80  void removeDroppedConnections();
81 
82  bool onConnectionHeaderReceived(const ConnectionPtr& conn, const Header& header);
83  void tcprosAcceptConnection(const TransportTCPPtr& transport);
84 
85  PollManagerPtr poll_manager_;
86 
89  boost::mutex connections_mutex_;
91 
92  // The connection ID counter, used to assign unique ID to each inbound or
93  // outbound connection. Access via getNewConnectionID()
96 
97  boost::signals2::connection poll_conn_;
98 
101 
102  const static int MAX_TCPROS_CONN_QUEUE = 100; // magic
103 };
104 
105 }
106 
const TransportUDPPtr & getUDPServerTransport()
ROSCPP_DECL void start()
Actually starts the internals of the node (spins up threads, starts the network polling and xmlrpc lo...
Definition: init.cpp:293
const TransportTCPPtr & getTCPServerTransport()
TransportTCPPtr tcpserver_transport_
boost::shared_ptr< ConnectionManager > ConnectionManagerPtr
boost::mutex connection_id_counter_mutex_
std::set< ConnectionPtr > S_Connection
Definition: forwards.h:64
std::vector< ConnectionPtr > V_Connection
Definition: forwards.h:65
boost::signals2::connection poll_conn_
TransportUDPPtr udpserver_transport_
ROSCPP_DECL void shutdown()
Disconnects everything and unregisters from the master. It is generally not necessary to call this fu...
Definition: init.cpp:594
const std::string header
boost::mutex dropped_connections_mutex_
V_Connection dropped_connections_
PollManagerPtr poll_manager_
boost::shared_ptr< PollManager > PollManagerPtr


roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim, Dirk Thomas
autogenerated on Mon Feb 28 2022 23:33:27