connection_manager.h
Go to the documentation of this file.
1 #include "sick_scan/sick_scan_base.h" /* Base definitions included in all header files, added by add_sick_scan_base_header.py. Do not edit this line. */
2 /*
3  * Copyright (C) 2009, Willow Garage, Inc.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the names of Willow Garage, Inc. nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include "forwards.h"
30 #include "connection.h"
31 #include "common.h"
32 
33 #include <mutex>
34 //#include <boost/signals2/connection.hpp>
35 
36 namespace roswrap
37 {
38 
40 typedef std::shared_ptr<PollManager> PollManagerPtr;
41 
43 typedef std::shared_ptr<ConnectionManager> ConnectionManagerPtr;
44 
46 {
47 public:
48  static const ConnectionManagerPtr& instance();
49 
52 
55  uint32_t getNewConnectionID();
56 
61  void addConnection(const ConnectionPtr& connection);
62 
63  void clear(Connection::DropReason reason);
64 
65  uint32_t getTCPPort();
66  uint32_t getUDPPort();
67 
68  const TransportTCPPtr& getTCPServerTransport() { return tcpserver_transport_; }
69  const TransportUDPPtr& getUDPServerTransport() { return udpserver_transport_; }
70 
71  void udprosIncomingConnection(const TransportUDPPtr& transport, Header& header);
72 
73  void start();
74  void shutdown();
75 
76 private:
77  void onConnectionDropped(const ConnectionPtr& conn);
78  // Remove any dropped connections from our list, causing them to be destroyed
79  // They can't just be removed immediately when they're dropped because the ros
80  // thread may still be using them (or more likely their transport)
81  void removeDroppedConnections();
82 
83  bool onConnectionHeaderReceived(const ConnectionPtr& conn, const Header& header);
84  void tcprosAcceptConnection(const TransportTCPPtr& transport);
85 
87 
90  std::mutex connections_mutex_;
92 
93  // The connection ID counter, used to assign unique ID to each inbound or
94  // outbound connection. Access via getNewConnectionID()
97 
98  boost::signals2::connection poll_conn_;
99 
102 
103  const static int MAX_TCPROS_CONN_QUEUE = 100; // magic
104 };
105 
106 }
107 
roswrap::ConnectionPtr
std::shared_ptr< Connection > ConnectionPtr
Definition: connection.h:58
roswrap::ConnectionManager::connection_id_counter_
uint32_t connection_id_counter_
Definition: connection_manager.h:95
roswrap::ConnectionManager::connection_id_counter_mutex_
std::mutex connection_id_counter_mutex_
Definition: connection_manager.h:96
roswrap::ConnectionManagerPtr
std::shared_ptr< ConnectionManager > ConnectionManagerPtr
Definition: connection_manager.h:42
forwards.h
roswrap::ConnectionManager::tcpserver_transport_
TransportTCPPtr tcpserver_transport_
Definition: connection_manager.h:100
roswrap::ConnectionManager::dropped_connections_
V_Connection dropped_connections_
Definition: connection_manager.h:89
roswrap::shutdown
ROSCPP_DECL void shutdown()
Disconnects everything and unregisters from the master. It is generally not necessary to call this fu...
Definition: rossimu.cpp:269
roswrap::ConnectionManager::dropped_connections_mutex_
std::mutex dropped_connections_mutex_
Definition: connection_manager.h:91
roswrap::Connection::DropReason
DropReason
Definition: connection.h:74
roswrap::PollManager
Definition: poll_manager.h:49
roswrap::TransportUDPPtr
std::shared_ptr< TransportUDP > TransportUDPPtr
Definition: forwards.h:62
roswrap::TransportTCPPtr
std::shared_ptr< TransportTCP > TransportTCPPtr
Definition: forwards.h:60
roswrap::ConnectionManager
Definition: connection_manager.h:45
roswrap::ConnectionManager::poll_manager_
PollManagerPtr poll_manager_
Definition: connection_manager.h:86
roswrap::ConnectionManager::connections_
S_Connection connections_
Definition: connection_manager.h:88
roswrap::ConnectionManager::connections_mutex_
std::mutex connections_mutex_
Definition: connection_manager.h:90
roswrap
Definition: param_modi.cpp:41
roswrap::ConnectionManager::udpserver_transport_
TransportUDPPtr udpserver_transport_
Definition: connection_manager.h:101
roswrap::ConnectionManager::poll_conn_
boost::signals2::connection poll_conn_
Definition: connection_manager.h:98
roswrap::PollManagerPtr
std::shared_ptr< PollManager > PollManagerPtr
Definition: connection_manager.h:39
connection.h
common.h
roswrap::ConnectionManager::getUDPServerTransport
const TransportUDPPtr & getUDPServerTransport()
Definition: connection_manager.h:69
roswrap::V_Connection
std::vector< ConnectionPtr > V_Connection
Definition: forwards.h:67
roswrap::Header
Provides functionality to parse a connection header and retrieve values from it.
Definition: header.h:53
sick_scan_base.h
roswrap::ConnectionManager::getTCPServerTransport
const TransportTCPPtr & getTCPServerTransport()
Definition: connection_manager.h:68
roswrap::message_traits::header
std_msgs::Header * header(M &m)
returns Header<M>::pointer(m);
Definition: message_traits.h:281
ROSCPP_DECL
#define ROSCPP_DECL
Definition: roswrap/src/cfgsimu/sick_scan/ros/common.h:63
roswrap::start
ROSCPP_DECL void start()
Actually starts the internals of the node (spins up threads, starts the network polling and xmlrpc lo...
roswrap::S_Connection
std::set< ConnectionPtr > S_Connection
Definition: forwards.h:66


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:08