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 
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 
boost::shared_ptr< PollManager >
forwards.h
ros::ConnectionManager::connection_id_counter_
uint32_t connection_id_counter_
Definition: connection_manager.h:94
ros
ros::Header
ros::shutdown
ROSCPP_DECL void shutdown()
Disconnects everything and unregisters from the master. It is generally not necessary to call this fu...
Definition: init.cpp:608
ros::ConnectionManager::dropped_connections_mutex_
boost::mutex dropped_connections_mutex_
Definition: connection_manager.h:90
ros::ConnectionManager::tcpserver_transport_
TransportTCPPtr tcpserver_transport_
Definition: connection_manager.h:99
ros::S_Connection
std::set< ConnectionPtr > S_Connection
Definition: forwards.h:64
ros::PollManager
Definition: poll_manager.h:48
ros::ConnectionManager::udpserver_transport_
TransportUDPPtr udpserver_transport_
Definition: connection_manager.h:100
ros::V_Connection
std::vector< ConnectionPtr > V_Connection
Definition: forwards.h:65
ros::ConnectionManager
Definition: connection_manager.h:44
ros::ConnectionManager::poll_conn_
boost::signals2::connection poll_conn_
Definition: connection_manager.h:97
ros::Connection::DropReason
DropReason
Definition: connection.h:73
ros::ConnectionManager::connection_id_counter_mutex_
boost::mutex connection_id_counter_mutex_
Definition: connection_manager.h:95
ros::start
ROSCPP_DECL void start()
Actually starts the internals of the node (spins up threads, starts the network polling and xmlrpc lo...
Definition: init.cpp:294
ros::ConnectionManager::dropped_connections_
V_Connection dropped_connections_
Definition: connection_manager.h:88
connection.h
ros::ConnectionManager::poll_manager_
PollManagerPtr poll_manager_
Definition: connection_manager.h:85
ros::ConnectionManager::getUDPServerTransport
const TransportUDPPtr & getUDPServerTransport()
Definition: connection_manager.h:68
ros::ConnectionManagerPtr
boost::shared_ptr< ConnectionManager > ConnectionManagerPtr
Definition: connection_manager.h:41
ros::PollManagerPtr
boost::shared_ptr< PollManager > PollManagerPtr
Definition: connection_manager.h:38
ros::ConnectionManager::connections_
S_Connection connections_
Definition: connection_manager.h:87
ros::ConnectionManager::connections_mutex_
boost::mutex connections_mutex_
Definition: connection_manager.h:89
ros::ConnectionManager::getTCPServerTransport
const TransportTCPPtr & getTCPServerTransport()
Definition: connection_manager.h:67


roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim, Dirk Thomas , Jacob Perron
autogenerated on Sat Sep 14 2024 02:59:35