Stxxl
1.4.0
|
00001 /*************************************************************************** 00002 * include/stxxl/bits/io/request_interface.h 00003 * 00004 * Part of the STXXL. See http://stxxl.sourceforge.net 00005 * 00006 * Copyright (C) 2002 Roman Dementiev <dementiev@mpi-sb.mpg.de> 00007 * Copyright (C) 2008, 2009, 2011 Andreas Beckmann <beckmann@cs.uni-frankfurt.de> 00008 * Copyright (C) 2009 Johannes Singler <singler@ira.uka.de> 00009 * 00010 * Distributed under the Boost Software License, Version 1.0. 00011 * (See accompanying file LICENSE_1_0.txt or copy at 00012 * http://www.boost.org/LICENSE_1_0.txt) 00013 **************************************************************************/ 00014 00015 #ifndef STXXL_IO__REQUEST_INTERFACE_H_ 00016 #define STXXL_IO__REQUEST_INTERFACE_H_ 00017 00018 #include <ostream> 00019 00020 #include <stxxl/bits/namespace.h> 00021 #include <stxxl/bits/noncopyable.h> 00022 #include <stxxl/bits/common/types.h> 00023 00024 00025 __STXXL_BEGIN_NAMESPACE 00026 00027 //! \addtogroup iolayer 00028 //! \{ 00029 00030 class onoff_switch; 00031 00032 //! \brief Functional interface of a request 00033 00034 //! Since all library I/O operations are asynchronous, 00035 //! one needs to keep track of their status: 00036 //! e.g. whether an I/O operation completed or not. 00037 class request_interface : private noncopyable 00038 { 00039 public: 00040 typedef stxxl::external_size_type offset_type; 00041 typedef stxxl::internal_size_type size_type; 00042 enum request_type { READ, WRITE }; 00043 00044 public: 00045 virtual bool add_waiter(onoff_switch * sw) = 0; 00046 virtual void delete_waiter(onoff_switch * sw) = 0; 00047 00048 protected: 00049 virtual void notify_waiters() = 0; 00050 00051 public: 00052 // HACK! 00053 virtual void serve() = 0; 00054 00055 protected: 00056 virtual void completed() = 0; 00057 00058 public: 00059 //! \brief Suspends calling thread until completion of the request 00060 virtual void wait(bool measure_time = true) = 0; 00061 00062 //! \brief Cancel a request. 00063 //! 00064 //! The request is canceled unless already being processed. 00065 //! However, cancelation cannot be guaranteed. 00066 //! Canceled requests must still be waited for in order to ensure correct operation. 00067 //! If the request was canceled successfully, the completion handler will not be called. 00068 //! \return \c true iff the request was canceled successfully 00069 virtual bool cancel() = 0; 00070 00071 //! \brief Polls the status of the request 00072 //! \return \c true if request is completed, otherwise \c false 00073 virtual bool poll() = 0; 00074 00075 //! \brief Identifies the type of I/O implementation 00076 //! \return pointer to null terminated string of characters, containing the name of I/O implementation 00077 virtual const char * io_type() const = 0; 00078 00079 //! \brief Dumps properties of a request 00080 virtual std::ostream & print(std::ostream & out) const = 0; 00081 00082 virtual ~request_interface() 00083 { } 00084 }; 00085 00086 //! \} 00087 00088 __STXXL_END_NAMESPACE 00089 00090 #endif // !STXXL_IO__REQUEST_INTERFACE_H_ 00091 // vim: et:ts=4:sw=4