Lunchbox  1.9.1
 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 
25 namespace lunchbox
26 {
27 namespace detail { class RequestHandler; }
28 
43 class RequestHandler : public boost::noncopyable
44 {
45 public:
47  LUNCHBOX_API RequestHandler();
48 
50  LUNCHBOX_API ~RequestHandler();
51 
60  template< class T > Request< T > registerRequest( void* data = 0 );
61 
71  uint32_t registerRequest( void* data = 0 ) LB_DEPRECATED
72  { return _register( data ); }
73 
84  LUNCHBOX_API void unregisterRequest( const uint32_t requestID );
85 
100  LUNCHBOX_API bool waitRequest( const uint32_t requestID, void*& result,
101  const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
102 
104  LUNCHBOX_API bool waitRequest( const uint32_t requestID, uint32_t& result,
105  const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
107  LUNCHBOX_API bool waitRequest( const uint32_t requestID, bool& result,
108  const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
110  LUNCHBOX_API bool waitRequest(const uint32_t requestID, uint128_t& result,
111  const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
113  LUNCHBOX_API bool waitRequest( const uint32_t requestID );
114 
121  bool isRequestServed( const uint32_t id ) const LB_DEPRECATED
122  { return isRequestReady( id ); }
123 
131  LUNCHBOX_API void* getRequestData( const uint32_t requestID );
132 
140  LUNCHBOX_API void serveRequest( const uint32_t requestID,
141  void* result = 0 );
143  LUNCHBOX_API void serveRequest( const uint32_t requestID,
144  uint32_t result );
146  LUNCHBOX_API void serveRequest( const uint32_t requestID, bool result );
148  LUNCHBOX_API void serveRequest( const uint32_t requestID,
149  const uint128_t& result );
154  LUNCHBOX_API bool hasPendingRequests() const;
155 
156  LUNCHBOX_API bool isRequestReady( const uint32_t ) const;
157 
158 private:
159  detail::RequestHandler* const _impl;
160  friend LUNCHBOX_API std::ostream& operator << ( std::ostream&,
161  const RequestHandler& );
162  LUNCHBOX_API uint32_t _register( void* data );
163  LB_TS_VAR( _thread );
164 };
165 
166 LUNCHBOX_API std::ostream& operator << ( std::ostream&, const RequestHandler& );
167 }
168 
169 #include <lunchbox/request.h>
170 
171 namespace lunchbox
172 {
173 template< class T > inline
175 {
176  return Request< T >( *this, _register( data ));
177 }
178 }
179 
180 #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:106
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.
A base type for 128 bit unsigned integer values.
Definition: uint128_t.h:46
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.