18 #ifndef LUNCHBOX_REQUEST_H
19 #define LUNCHBOX_REQUEST_H
21 #include <lunchbox/future.h>
22 #include <boost/mpl/if.hpp>
23 #include <boost/type_traits/is_same.hpp>
32 std::runtime_error(
"wait on an unregistered request" ) {}
54 uint32_t
getID()
const;
70 #include <lunchbox/requestHandler.h>
76 boost::mpl::if_< boost::is_same< T, void >,
void*, T >::type value_t;
83 , state_( UNRESOLVED )
87 const uint32_t request;
92 if( state_ == UNRESOLVED )
94 state_ = UNREGISTERED;
95 handler_.unregisterRequest( request );
99 bool isUnresolved()
const {
return state_ == UNRESOLVED; }
102 T
wait(
const uint32_t timeout )
final
109 if ( !handler_.waitRequest( request, result, timeout ))
123 return handler_.isRequestReady( request );
133 enum State { UNRESOLVED, DONE, UNREGISTERED };
144 if ( !handler_.
waitRequest( request, result, timeout ))
153 template<
class T >
inline
160 if( static_cast< const Impl* >( this->impl_.get( ))->isUnresolved( ))
166 return static_cast< const Impl*
>( this->impl_.get( ))->request;
171 static_cast< Impl*
>( this->impl_.get( ))->unregister();
176 #endif //LUNCHBOX_REQUEST_H
virtual ~Request()
Destruct and wait for completion of the request, unless relinquished.
Request(RequestHandler &handler, const uint32_t request)
Construct a new 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.
A Future implementation for a RequestHandler request.
RefPtr< FutureImpl< T > > Impl
The wait implementation.
void unregister()
Unregister this request from the request handler.
Base class to implement the wait method fulfilling the future.
bool isReady() const final
A future represents a asynchronous operation.
Abstraction layer and common utilities for multi-threaded programming.
A thread-safe request handler.
T wait(const uint32_t timeout) final
Wait for the promise to be fullfilled.