Lunchbox  1.4.0
requestHandler.h
00001 
00002 /* Copyright (c) 2005-2012, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #ifndef LUNCHBOX_REQUESTHANDLER_H
00019 #define LUNCHBOX_REQUESTHANDLER_H
00020 
00021 #include <lunchbox/api.h>       // LUNCHBOX_API definition
00022 #include <lunchbox/thread.h>    // thread-safety macros
00023 #include <lunchbox/types.h>
00024 
00025 #include <list>
00026 
00027 namespace lunchbox
00028 {
00029 namespace detail { class RequestHandler; }
00030 
00044     class RequestHandler : public NonCopyable
00045     {
00046     public:
00048         LUNCHBOX_API RequestHandler();
00049 
00051         LUNCHBOX_API ~RequestHandler();
00052 
00061         LUNCHBOX_API uint32_t registerRequest( void* data = 0 );
00062 
00073         LUNCHBOX_API void unregisterRequest( const uint32_t requestID );
00074 
00089         LUNCHBOX_API bool waitRequest( const uint32_t requestID, void*& result,
00090                                const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
00091 
00093         LUNCHBOX_API bool waitRequest( const uint32_t requestID, uint32_t& result,
00094                                const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
00096         LUNCHBOX_API bool waitRequest( const uint32_t requestID, bool& result,
00097                                const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
00099         LUNCHBOX_API bool waitRequest(const uint32_t requestID, uint128_t& result,
00100                                const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
00102         LUNCHBOX_API bool waitRequest( const uint32_t requestID );
00103 
00113         LUNCHBOX_API bool isRequestServed( const uint32_t requestID ) const;
00114 
00122         LUNCHBOX_API void* getRequestData( const uint32_t requestID );
00123 
00131         LUNCHBOX_API void serveRequest( const uint32_t requestID,
00132                                         void* result = 0 );
00134         LUNCHBOX_API void serveRequest( const uint32_t requestID,
00135                                         uint32_t result );
00137         LUNCHBOX_API void serveRequest( const uint32_t requestID, bool result );
00139         LUNCHBOX_API void serveRequest( const uint32_t requestID,
00140                                         const uint128_t& result );
00145         LUNCHBOX_API bool hasPendingRequests() const;
00146 
00147     private:
00148         detail::RequestHandler* const _impl;
00149         friend LUNCHBOX_API std::ostream& operator << ( std::ostream&,
00150                                                         const RequestHandler& );
00151         LB_TS_VAR( _thread );
00152     };
00153 
00154     LUNCHBOX_API std::ostream& operator << ( std::ostream&,
00155                                              const RequestHandler& );
00156 }
00157 #endif //LUNCHBOX_REQUESTHANDLER_H