transport_udp.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  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2008, Willow Garage, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of Willow Garage, Inc. nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef ROSCPP_TRANSPORT_UDP_H
37 #define ROSCPP_TRANSPORT_UDP_H
38 
39 #include <ros/types.h>
40 #include <ros/transport/transport.h>
41 
42 #include <mutex>
43 #include "ros/io.h"
44 #include <ros/common.h>
45 
46 namespace roswrap
47 {
48 
49 class TransportUDP;
50 typedef std::shared_ptr<TransportUDP> TransportUDPPtr;
51 
52 class PollSet;
53 
54 #define ROS_UDP_DATA0 0
55 #define ROS_UDP_DATAN 1
56 #define ROS_UDP_PING 2
57 #define ROS_UDP_ERR 3
58 typedef struct TransportUDPHeader {
59  uint32_t connection_id_;
60  uint8_t op_;
61  uint8_t message_id_;
62  uint16_t block_;
64 
69 {
70 public:
71  enum Flags
72  {
73  SYNCHRONOUS = 1<<0,
74  };
75 
76  TransportUDP(PollSet* poll_set, int flags = 0, int max_datagram_size = 0);
77  virtual ~TransportUDP();
78 
85  bool connect(const std::string& host, int port, int conn_id);
86 
90  std::string getClientURI();
91 
96  bool createIncoming(int port, bool is_server);
100  TransportUDPPtr createOutgoing(std::string host, int port, int conn_id, int max_datagram_size);
104  int getServerPort() const {return server_port_;}
105 
106  // overrides from Transport
107  virtual int32_t read(uint8_t* buffer, uint32_t size);
108  virtual int32_t write(uint8_t* buffer, uint32_t size);
109 
110  virtual void enableWrite();
111  virtual void disableWrite();
112  virtual void enableRead();
113  virtual void disableRead();
114 
115  virtual void close();
116 
117  virtual std::string getTransportInfo();
118 
119  virtual bool requiresHeader() {return false;}
120 
121  virtual const char* getType() {return "UDPROS";}
122 
123  int getMaxDatagramSize() const {return max_datagram_size_;}
124 
125 private:
129  bool initializeSocket();
130 
136  bool setSocket(int sock);
137 
138  void socketUpdate(int events);
139 
141  bool closed_;
142  std::mutex close_mutex_;
143 
146 
148  sockaddr_in server_address_;
149  sockaddr_in local_address_;
152 
153  std::string cached_remote_host_;
154 
156  int flags_;
157 
158  uint32_t connection_id_;
160  uint16_t total_blocks_;
161  uint16_t last_block_;
162 
164 
165  uint8_t* data_buffer_;
166  uint8_t* data_start_;
167  uint32_t data_filled_;
168 
169  uint8_t* reorder_buffer_;
170  uint8_t* reorder_start_;
172  uint32_t reorder_bytes_;
173 };
174 
175 }
176 
177 #endif // ROSCPP_TRANSPORT_UDP_H
178 
roswrap::TransportUDP::data_buffer_
uint8_t * data_buffer_
Definition: transport_udp.h:165
roswrap::TransportUDP::data_filled_
uint32_t data_filled_
Definition: transport_udp.h:167
roswrap::TransportUDPHeader::message_id_
uint8_t message_id_
Definition: transport_udp.h:61
roswrap::TransportUDP::getMaxDatagramSize
int getMaxDatagramSize() const
Definition: transport_udp.h:123
roswrap::TransportUDP::reorder_start_
uint8_t * reorder_start_
Definition: transport_udp.h:170
roswrap::TransportUDP::reorder_bytes_
uint32_t reorder_bytes_
Definition: transport_udp.h:172
roswrap::TransportUDP::reorder_header_
TransportUDPHeader reorder_header_
Definition: transport_udp.h:171
roswrap::TransportUDPHeader::connection_id_
uint32_t connection_id_
Definition: transport_udp.h:59
roswrap::TransportUDPHeader
Definition: transport_udp.h:58
roswrap::TransportUDP::total_blocks_
uint16_t total_blocks_
Definition: transport_udp.h:160
roswrap::TransportUDP::reorder_buffer_
uint8_t * reorder_buffer_
Definition: transport_udp.h:169
roswrap::TransportUDP::poll_set_
PollSet * poll_set_
Definition: transport_udp.h:155
roswrap::TransportUDPHeader::op_
uint8_t op_
Definition: transport_udp.h:60
roswrap::TransportUDP::server_port_
int server_port_
Definition: transport_udp.h:150
roswrap::TransportUDPPtr
std::shared_ptr< TransportUDP > TransportUDPPtr
Definition: forwards.h:62
roswrap::TransportUDP::server_address_
sockaddr_in server_address_
Definition: transport_udp.h:148
roswrap::TransportUDP::max_datagram_size_
uint32_t max_datagram_size_
Definition: transport_udp.h:163
roswrap::TransportUDP::expecting_write_
bool expecting_write_
Definition: transport_udp.h:145
roswrap::TransportUDP::expecting_read_
bool expecting_read_
Definition: transport_udp.h:144
roswrap::TransportUDP::last_block_
uint16_t last_block_
Definition: transport_udp.h:161
roswrap::TransportUDP::getType
virtual const char * getType()
Return a string that details the type of transport (Eg. TCPROS)
Definition: transport_udp.h:121
roswrap::TransportUDP::requiresHeader
virtual bool requiresHeader()
Returns a boolean to indicate if the transport mechanism is reliable or not.
Definition: transport_udp.h:119
roswrap::TransportUDP::local_port_
int local_port_
Definition: transport_udp.h:151
roswrap
Definition: param_modi.cpp:41
roswrap::TransportUDP::flags_
int flags_
Definition: transport_udp.h:156
roswrap::TransportUDP::closed_
bool closed_
Definition: transport_udp.h:141
roswrap::TransportUDPHeader
struct roswrap::TransportUDPHeader TransportUDPHeader
roswrap::TransportUDP::local_address_
sockaddr_in local_address_
Definition: transport_udp.h:149
colaa::detail::read
T read(const std::string &str)
General template which is unimplemented; implemented specializations follow below.
Definition: colaa.hpp:72
roswrap::TransportUDP::current_message_id_
uint8_t current_message_id_
Definition: transport_udp.h:159
roswrap::TransportUDP::close_mutex_
std::mutex close_mutex_
Definition: transport_udp.h:142
sick_scan_base.h
roswrap::TransportUDP::is_server_
bool is_server_
Definition: transport_udp.h:147
roswrap::TransportUDP::Flags
Flags
Definition: transport_udp.h:71
roswrap::TransportUDPHeader::block_
uint16_t block_
Definition: transport_udp.h:62
roswrap::TransportUDP::connection_id_
uint32_t connection_id_
Definition: transport_udp.h:158
ROSCPP_DECL
#define ROSCPP_DECL
Definition: roswrap/src/cfgsimu/sick_scan/ros/common.h:63
roswrap::PollSet
Manages a set of sockets being polled through the poll() function call.
Definition: poll_set.h:58
roswrap::Transport
Abstract base class that allows abstraction of the transport type, eg. TCP, shared memory,...
Definition: transport.h:56
roswrap::TransportUDP::sock_
socket_fd_t sock_
Definition: transport_udp.h:140
roswrap::socket_fd_t
int socket_fd_t
Definition: io.h:139
roswrap::TransportUDP::getServerPort
int getServerPort() const
Returns the port this transport is listening on.
Definition: transport_udp.h:104
roswrap::TransportUDP::cached_remote_host_
std::string cached_remote_host_
Definition: transport_udp.h:153
roswrap::TransportUDP::data_start_
uint8_t * data_start_
Definition: transport_udp.h:166
roswrap::TransportUDP
UDPROS transport.
Definition: transport_udp.h:68


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