poll_set.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_POLL_SET_H
37 #define ROSCPP_POLL_SET_H
38 
39 #include <vector>
40 #include "io.h"
41 #include "common.h"
42 #include <memory>
43 //#include <boost/function.hpp>
44 #include <mutex>
45 
46 namespace roswrap
47 {
48 
49 class Transport;
50 typedef std::shared_ptr<Transport> TransportPtr;
51 
59 {
60 public:
61  PollSet();
62  ~PollSet();
63 
64  typedef std::function<void(int)> SocketUpdateFunc;
74  bool addSocket(int sock, const SocketUpdateFunc& update_func, const TransportPtr& transport = TransportPtr());
81  bool delSocket(int sock);
82 
90  bool addEvents(int sock, int events);
98  bool delEvents(int sock, int events);
99 
112  void update(int poll_timeout);
113 
118  void signal();
119 
120 private:
124  void createNativePollset();
125 
129  void onLocalPipeEvents(int events);
130 
131  struct SocketInfo
132  {
135  int fd_;
136  int events_;
137  };
138  typedef std::map<int, SocketInfo> M_SocketInfo;
140  std::mutex socket_info_mutex_;
142 
144  typedef std::vector<int> V_int;
146 
147  std::vector<socket_pollfd> ufds_;
148 
149  std::mutex signal_mutex_;
150  signal_fd_t signal_pipe_[2];
151 };
152 
153 }
154 
155 #endif // ROSCPP_POLL_SET_H
roswrap::PollSet::SocketUpdateFunc
std::function< void(int)> SocketUpdateFunc
Definition: poll_set.h:64
roswrap::PollSet::signal_mutex_
std::mutex signal_mutex_
Definition: poll_set.h:149
roswrap::PollSet::socket_info_
M_SocketInfo socket_info_
Definition: poll_set.h:139
roswrap::PollSet::SocketInfo
Definition: poll_set.h:131
roswrap::TransportPtr
std::shared_ptr< Transport > TransportPtr
Definition: connection.h:56
roswrap::PollSet::sockets_changed_
bool sockets_changed_
Definition: poll_set.h:141
roswrap::PollSet::socket_info_mutex_
std::mutex socket_info_mutex_
Definition: poll_set.h:140
update
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
roswrap::PollSet::SocketInfo::fd_
int fd_
Definition: poll_set.h:135
roswrap
Definition: param_modi.cpp:41
roswrap::PollSet::SocketInfo::func_
SocketUpdateFunc func_
Definition: poll_set.h:134
roswrap::PollSet::ufds_
std::vector< socket_pollfd > ufds_
Definition: poll_set.h:147
roswrap::signal_fd_t
int signal_fd_t
Definition: io.h:140
common.h
roswrap::PollSet::V_int
std::vector< int > V_int
Definition: poll_set.h:144
io.h
sick_scan_base.h
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::PollSet::SocketInfo::events_
int events_
Definition: poll_set.h:136
roswrap::PollSet::M_SocketInfo
std::map< int, SocketInfo > M_SocketInfo
Definition: poll_set.h:138
roswrap::PollSet::just_deleted_
V_int just_deleted_
Definition: poll_set.h:145
roswrap::PollSet::just_deleted_mutex_
std::mutex just_deleted_mutex_
Definition: poll_set.h:143
roswrap::PollSet::SocketInfo::transport_
TransportPtr transport_
Definition: poll_set.h:133


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