Lunchbox  1.8.0
requestHandler.h
1 
2 /* Copyright (c) 2005-2012, 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 #include <list>
26 
27 namespace lunchbox
28 {
29 namespace detail { class RequestHandler; }
30 
44  class RequestHandler : public NonCopyable
45  {
46  public:
48  LUNCHBOX_API RequestHandler();
49 
51  LUNCHBOX_API ~RequestHandler();
52 
61  LUNCHBOX_API uint32_t registerRequest( void* data = 0 );
62 
73  LUNCHBOX_API void unregisterRequest( const uint32_t requestID );
74 
89  LUNCHBOX_API bool waitRequest( const uint32_t requestID, void*& result,
90  const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
91 
93  LUNCHBOX_API bool waitRequest( const uint32_t requestID, uint32_t& result,
94  const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
96  LUNCHBOX_API bool waitRequest( const uint32_t requestID, bool& result,
97  const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
99  LUNCHBOX_API bool waitRequest(const uint32_t requestID, uint128_t& result,
100  const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
102  LUNCHBOX_API bool waitRequest( const uint32_t requestID );
103 
113  LUNCHBOX_API bool isRequestServed( const uint32_t requestID ) const;
114 
122  LUNCHBOX_API void* getRequestData( const uint32_t requestID );
123 
131  LUNCHBOX_API void serveRequest( const uint32_t requestID,
132  void* result = 0 );
134  LUNCHBOX_API void serveRequest( const uint32_t requestID,
135  uint32_t result );
137  LUNCHBOX_API void serveRequest( const uint32_t requestID, bool result );
139  LUNCHBOX_API void serveRequest( const uint32_t requestID,
140  const uint128_t& result );
145  LUNCHBOX_API bool hasPendingRequests() const;
146 
147  private:
148  detail::RequestHandler* const _impl;
149  friend LUNCHBOX_API std::ostream& operator << ( std::ostream&,
150  const RequestHandler& );
151  LB_TS_VAR( _thread );
152  };
153 
154  LUNCHBOX_API std::ostream& operator << ( std::ostream&,
155  const RequestHandler& );
156 }
157 #endif //LUNCHBOX_REQUESTHANDLER_H