STXXL  1.4-dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
request.h
Go to the documentation of this file.
1 /***************************************************************************
2  * include/stxxl/bits/io/request.h
3  *
4  * Part of the STXXL. See http://stxxl.sourceforge.net
5  *
6  * Copyright (C) 2002 Roman Dementiev <[email protected]>
7  * Copyright (C) 2008 Andreas Beckmann <[email protected]>
8  * Copyright (C) 2013-2014 Timo Bingmann <[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 STXXL_IO_REQUEST_HEADER
16 #define STXXL_IO_REQUEST_HEADER
17 
18 #include <cassert>
19 
20 #include <stxxl/bits/namespace.h>
26 #include <stxxl/bits/verbose.h>
27 
29 
30 //! \addtogroup reqlayer
31 //! \{
32 
33 #define STXXL_BLOCK_ALIGN 4096
34 
35 class file;
36 
37 //! Request object encapsulating basic properties like file and offset.
38 class request : virtual public request_interface, public atomic_counted_object
39 {
40  friend class linuxaio_queue;
41 
42 protected:
45 
46 protected:
48  void* m_buffer;
52 
53 public:
54  request(const completion_handler& on_compl,
55  file* file,
56  void* buffer,
57  offset_type offset,
59  request_type type);
60 
61  virtual ~request() noexcept(false);
62 
63  file * get_file() const { return m_file; }
64  void * get_buffer() const { return m_buffer; }
65  offset_type get_offset() const { return m_offset; }
66  size_type get_size() const { return m_bytes; }
67  request_type get_type() const { return m_type; }
68 
69  void check_alignment() const;
70 
71  std::ostream & print(std::ostream& out) const;
72 
73  //! Inform the request object that an error occurred during the I/O
74  //! execution.
75  void error_occured(const char* msg)
76  {
77  m_error.reset(new stxxl::io_error(msg));
78  }
79 
80  //! Inform the request object that an error occurred during the I/O
81  //! execution.
82  void error_occured(const std::string& msg)
83  {
84  m_error.reset(new stxxl::io_error(msg));
85  }
86 
87  //! Rises an exception if there were error with the I/O.
88  void check_errors()
89  {
90  if (m_error.get())
91  throw *(m_error.get());
92  }
93 
94  virtual const char * io_type() const;
95 
96 protected:
97  void check_nref(bool after = false)
98  {
99  if (get_reference_count() < 2)
100  check_nref_failed(after);
101  }
102 
103 private:
104  void check_nref_failed(bool after);
105 };
106 
107 inline std::ostream& operator << (std::ostream& out, const request& req)
108 {
109  return req.print(out);
110 }
111 
112 //! A reference counting pointer for \c request.
114 
115 //! \}
116 
118 
119 #endif // !STXXL_IO_REQUEST_HEADER
120 // vim: et:ts=4:sw=4
friend std::ostream & operator<<(std::ostream &os, const uint_pair &a)
make a uint_pair outputtable via iostreams, using unsigned long long.
Definition: uint_types.h:228
Completion handler class (Loki-style).
void error_occured(const std::string &msg)
Inform the request object that an error occurred during the I/O execution.
Definition: request.h:82
request_type m_type
Definition: request.h:51
completion_handler m_on_complete
Definition: request.h:43
Provides reference counting abilities for use with counting_ptr with mutex locking.
Definition: counting_ptr.h:461
offset_type get_offset() const
Definition: request.h:65
void * m_buffer
Definition: request.h:48
file * m_file
Definition: request.h:47
std::auto_ptr< Type > result
Definition: unique_ptr.h:29
counting_ptr< request > request_ptr
A reference counting pointer for request.
Definition: request.h:113
Defines interface of file.
Definition: file.h:56
void check_nref(bool after=false)
Definition: request.h:97
compat_unique_ptr< stxxl::io_error >::result m_error
Definition: request.h:44
#define STXXL_BEGIN_NAMESPACE
Definition: namespace.h:16
size_type m_bytes
Definition: request.h:50
size_type get_size() const
Definition: request.h:66
void check_errors()
Rises an exception if there were error with the I/O.
Definition: request.h:88
stxxl::internal_size_type size_type
Functional interface of a request.
request_type get_type() const
Definition: request.h:67
std::ostream & print(std::ostream &out) const
Dumps properties of a request.
Definition: request.cpp:80
void * get_buffer() const
Definition: request.h:64
static const size_t bytes
number of bytes in uint_pair
Definition: uint_types.h:96
stxxl::external_size_type offset_type
Request object encapsulating basic properties like file and offset.
Definition: request.h:38
void error_occured(const char *msg)
Inform the request object that an error occurred during the I/O execution.
Definition: request.h:75
Queue for linuxaio_file(s)
offset_type m_offset
Definition: request.h:49
#define STXXL_END_NAMESPACE
Definition: namespace.h:17