Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
request_interface.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * foxxll/io/request_interface.hpp
3  *
4  * Part of FOXXLL. See http://foxxll.org
5  *
6  * Copyright (C) 2002 Roman Dementiev <[email protected]>
7  * Copyright (C) 2008, 2009, 2011 Andreas Beckmann <[email protected]>
8  * Copyright (C) 2009 Johannes Singler <[email protected]>
9  *
10  * Distributed under the Boost Software License, Version 1.0.
11  * (See accompanying file LICENSE_1_0.txt or copy at
12  * http://www.boost.org/LICENSE_1_0.txt)
13  **************************************************************************/
14 
15 #ifndef FOXXLL_IO_REQUEST_INTERFACE_HEADER
16 #define FOXXLL_IO_REQUEST_INTERFACE_HEADER
17 
18 #include <ostream>
19 
20 #include <foxxll/common/types.hpp>
21 
22 namespace foxxll {
23 
24 //! \addtogroup foxxll_reqlayer
25 //! \{
26 
27 class onoff_switch;
28 
29 //! Functional interface of a request.
30 //!
31 //! Since all library I/O operations are asynchronous,
32 //! one needs to keep track of their status:
33 //! e.g. whether an I/O operation completed or not.
35 {
36 public:
37  //! type for offsets within a file
38  using offset_type = uint64_t;
39  //! type for block transfer sizes
40  using size_type = size_t;
41 
43 
44 public:
45  virtual bool add_waiter(onoff_switch* sw) = 0;
46  virtual void delete_waiter(onoff_switch* sw) = 0;
47 
48 protected:
49  virtual void notify_waiters() = 0;
50 
51 protected:
52  virtual void completed(bool canceled) = 0;
53 
54 public:
55  request_interface() = default;
56 
57  //! non-copyable: delete copy-constructor
58  request_interface(const request_interface&) = delete;
59  //! non-copyable: delete assignment operator
61 
62  virtual ~request_interface() { }
63 
64  //! Suspends calling thread until completion of the request.
65  virtual void wait(bool measure_time = true) = 0;
66 
67  /*!
68  * Cancel a request.
69  *
70  * The request is canceled unless already being processed. However,
71  * cancelation cannot be guaranteed. Canceled requests must still be waited
72  * for in order to ensure correct operation. If the request was canceled
73  * successfully, the completion handler will not be called.
74  *
75  * \return \c true iff the request was canceled successfully
76  */
77  virtual bool cancel() = 0;
78 
79  //! Polls the status of the request.
80  //! \return \c true if request is completed, otherwise \c false
81  virtual bool poll() = 0;
82 
83  /*!
84  * Identifies the type of I/O implementation.
85  *
86  * \return pointer to null terminated string of characters, containing the
87  * name of I/O implementation
88  */
89  virtual const char * io_type() const = 0;
90 
91  //! Dumps properties of a request.
92  virtual std::ostream & print(std::ostream& out) const = 0;
93 };
94 
95 //! \}
96 
97 } // namespace foxxll
98 
99 #endif // !FOXXLL_IO_REQUEST_INTERFACE_HEADER
100 
101 /**************************************************************************/
request_interface & operator=(const request_interface &)=delete
non-copyable: delete assignment operator
uint64_t offset_type
type for offsets within a file
virtual bool cancel()=0
Cancel a request.
virtual void notify_waiters()=0
size_t size_type
type for block transfer sizes
virtual void wait(bool measure_time=true)=0
Suspends calling thread until completion of the request.
virtual std::ostream & print(std::ostream &out) const =0
Dumps properties of a request.
virtual bool poll()=0
virtual void completed(bool canceled)=0
virtual bool add_waiter(onoff_switch *sw)=0
virtual void delete_waiter(onoff_switch *sw)=0
virtual const char * io_type() const =0
Identifies the type of I/O implementation.