Lunchbox  1.11.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
61  template< class T > Request< T > registerRequest( void* data = 0 );
62 
72  uint32_t registerRequest( void* data = 0 ) LB_DEPRECATED
73  { return _register( data ); }
74 
85  LUNCHBOX_API void unregisterRequest( const uint32_t requestID );
86 
101  LUNCHBOX_API bool waitRequest( const uint32_t requestID, void*& result,
102  const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
103 
105  LUNCHBOX_API bool waitRequest( const uint32_t requestID, uint32_t& result,
106  const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
108  LUNCHBOX_API bool waitRequest( const uint32_t requestID, bool& result,
109  const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
111  LUNCHBOX_API bool waitRequest( const uint32_t requestID,
112  servus::uint128_t& result,
113  const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
115  LUNCHBOX_API bool waitRequest( const uint32_t requestID );
116 
123  bool isRequestServed( const uint32_t id ) const LB_DEPRECATED
124  { return isRequestReady( id ); }
125 
133  LUNCHBOX_API void* getRequestData( const uint32_t requestID );
134 
142  LUNCHBOX_API void serveRequest( const uint32_t requestID,
143  void* result = 0 );
145  LUNCHBOX_API void serveRequest( const uint32_t requestID,
146  uint32_t result );
148  LUNCHBOX_API void serveRequest( const uint32_t requestID, bool result );
150  LUNCHBOX_API void serveRequest( const uint32_t requestID,
151  const servus::uint128_t& result );
156  LUNCHBOX_API bool hasPendingRequests() const;
157 
158  LUNCHBOX_API bool isRequestReady( const uint32_t ) const;
159 
160 private:
161  detail::RequestHandler* const _impl;
162  friend LUNCHBOX_API std::ostream& operator << ( std::ostream&,
163  const RequestHandler& );
164  LUNCHBOX_API uint32_t _register( void* data );
165  LB_TS_VAR( _thread );
166 };
167 
168 LUNCHBOX_API std::ostream& operator << ( std::ostream&, const RequestHandler& );
169 }
170 
171 #include <lunchbox/request.h>
172 
173 namespace lunchbox
174 {
175 template< class T > inline
177 {
178  return Request< T >( *this, _register( data ));
179 }
180 }
181 
182 #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 Lunchbox.
Basic type definitions not provided by the operating system.
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:32
uint32_t registerRequest(void *data=0) LB_DEPRECATED
Register a request.
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.