Lunchbox  1.12.0
Multi-threaded C++ toolbox library for all application developers creating high-performance multi-threaded programs.
requestHandler.h
1 
2 /* Copyright (c) 2005-2014, Stefan Eilemann <eile@equalizergraphics.com>
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License version 2.1 as published
6  * by the Free Software Foundation.
7  *
8  * This library is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11  * details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this library; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16  */
17 
18 #ifndef LUNCHBOX_REQUESTHANDLER_H
19 #define LUNCHBOX_REQUESTHANDLER_H
20 
21 #include <lunchbox/api.h> // LUNCHBOX_API definition
22 #include <lunchbox/thread.h> // thread-safety macros
23 #include <lunchbox/types.h>
24 #include <servus/uint128_t.h>
25 
26 namespace lunchbox
27 {
28 namespace detail { class RequestHandler; }
29 
44 class RequestHandler : public boost::noncopyable
45 {
46 public:
48  LUNCHBOX_API RequestHandler();
49 
51  LUNCHBOX_API ~RequestHandler();
52 
60  template< class T > Request< T > registerRequest( void* data = 0 );
61 
70  uint32_t registerRequest( void* data = 0 ) { return _register( data ); }
71 
82  LUNCHBOX_API void unregisterRequest( const uint32_t requestID );
83 
98  LUNCHBOX_API bool waitRequest( const uint32_t requestID, void*& result,
99  const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
100 
102  LUNCHBOX_API bool waitRequest( const uint32_t requestID, uint32_t& result,
103  const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
105  LUNCHBOX_API bool waitRequest( const uint32_t requestID, bool& result,
106  const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
108  LUNCHBOX_API bool waitRequest( const uint32_t requestID,
109  servus::uint128_t& result,
110  const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
112  LUNCHBOX_API bool waitRequest( const uint32_t requestID );
113 
120  bool isRequestServed( const uint32_t id ) const LB_DEPRECATED
121  { return isRequestReady( id ); }
122 
130  LUNCHBOX_API void* getRequestData( const uint32_t requestID );
131 
139  LUNCHBOX_API void serveRequest( const uint32_t requestID,
140  void* result = 0 );
142  LUNCHBOX_API void serveRequest( const uint32_t requestID,
143  uint32_t result );
145  LUNCHBOX_API void serveRequest( const uint32_t requestID, bool result );
147  LUNCHBOX_API void serveRequest( const uint32_t requestID,
148  const servus::uint128_t& result );
153  LUNCHBOX_API bool hasPendingRequests() const;
154 
155  LUNCHBOX_API bool isRequestReady( const uint32_t ) const;
156 
157 private:
158  detail::RequestHandler* const _impl;
159  friend LUNCHBOX_API std::ostream& operator << ( std::ostream&,
160  const RequestHandler& );
161  LUNCHBOX_API uint32_t _register( void* data );
162  LB_TS_VAR( _thread );
163 };
164 
165 LUNCHBOX_API std::ostream& operator << ( std::ostream&, const RequestHandler& );
166 }
167 
168 #include <lunchbox/request.h>
169 
170 namespace lunchbox
171 {
172 template< class T > inline
174 {
175  return Request< T >( *this, _register( data ));
176 }
177 }
178 
179 #endif //LUNCHBOX_REQUESTHANDLER_H
bool isRequestServed(const uint32_t id) const LB_DEPRECATED
Poll for the completion of a request.
Defines export visibility macros for library Lunchbox.
Basic type definitions not provided by the operating system.
uint32_t registerRequest(void *data=0)
Register a request.
LUNCHBOX_API bool waitRequest(const uint32_t requestID, void *&result, const uint32_t timeout=LB_TIMEOUT_INDEFINITE)
Wait a given time for the completion of a request.
#define LB_TIMEOUT_INDEFINITE
Constant defining 'wait forever' in methods with wait parameters.
Definition: types.h:79
LUNCHBOX_API void serveRequest(const uint32_t requestID, void *result=0)
Serve a request with a void* result.
LUNCHBOX_API bool hasPendingRequests() const
A Future implementation for a RequestHandler request.
Definition: request.h:39
Abstraction layer and common utilities for multi-threaded programming.
Definition: algorithm.h:32
LUNCHBOX_API ~RequestHandler()
Destruct the request handler.
std::ostream & operator<<(std::ostream &os, const Array< T > &array)
Pretty-print all members of the array.
Definition: array.h:47
A thread-safe request handler.
Request< T > registerRequest(void *data=0)
Register a request.
LUNCHBOX_API void unregisterRequest(const uint32_t requestID)
Unregister a request.
LUNCHBOX_API RequestHandler()
Construct a new request handler.
LUNCHBOX_API void * getRequestData(const uint32_t requestID)
Retrieve the user-specific data for a request.