STXXL  1.4-dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
request.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * lib/io/request.cpp
3  *
4  * Part of the STXXL. See http://stxxl.sourceforge.net
5  *
6  * Copyright (C) 2008 Andreas Beckmann <[email protected]>
7  * Copyright (C) 2009 Johannes Singler <[email protected]>
8  *
9  * Distributed under the Boost Software License, Version 1.0.
10  * (See accompanying file LICENSE_1_0.txt or copy at
11  * http://www.boost.org/LICENSE_1_0.txt)
12  **************************************************************************/
13 
14 #include <ostream>
15 
16 #include <stxxl/bits/io/request.h>
17 #include <stxxl/bits/io/file.h>
18 
20 
21 request::request(
22  const completion_handler& on_compl,
23  file* file,
24  void* buffer,
25  offset_type offset,
27  request_type type)
28  : m_on_complete(on_compl),
29  m_file(file),
30  m_buffer(buffer),
31  m_offset(offset),
32  m_bytes(bytes),
33  m_type(type)
34 {
35  STXXL_VERBOSE3_THIS("request::(...), ref_cnt=" << get_reference_count());
37 }
38 
40 {
41  STXXL_VERBOSE3_THIS("request::~request(), ref_cnt=" << get_reference_count());
42 }
43 
45 {
46  if (m_offset % STXXL_BLOCK_ALIGN != 0)
47  STXXL_ERRMSG("Offset is not aligned: modulo " <<
49 
50  if (m_bytes % STXXL_BLOCK_ALIGN != 0)
51  STXXL_ERRMSG("Size is not a multiple of " <<
52  STXXL_BLOCK_ALIGN << ", = " << m_bytes % STXXL_BLOCK_ALIGN);
53 
54  if (unsigned_type(m_buffer) % STXXL_BLOCK_ALIGN != 0)
55  STXXL_ERRMSG("Buffer is not aligned: modulo " <<
56  STXXL_BLOCK_ALIGN << " = " << unsigned_type(m_buffer) % STXXL_BLOCK_ALIGN <<
57  " (" << m_buffer << ")");
58 }
59 
61 {
62  STXXL_ERRMSG("WARNING: serious error, reference to the request is lost " <<
63  (after ? "after" : "before") << " serve()" <<
64  " nref=" << get_reference_count() <<
65  " this=" << this <<
66  " offset=" << m_offset <<
67  " buffer=" << m_buffer <<
68  " bytes=" << m_bytes <<
69  " type=" << ((m_type == READ) ? "READ" : "WRITE") <<
70  " file=" << m_file <<
71  " iotype=" << m_file->io_type()
72  );
73 }
74 
75 const char* request::io_type() const
76 {
77  return m_file->io_type();
78 }
79 
80 std::ostream& request::print(std::ostream& out) const
81 {
82  out << "File object address: " << static_cast<void*>(m_file);
83  out << " Buffer address: " << static_cast<void*>(m_buffer);
84  out << " File offset: " << m_offset;
85  out << " Transfer size: " << m_bytes << " bytes";
86  out << " Type of transfer: " << ((m_type == READ) ? "READ" : "WRITE");
87  return out;
88 }
89 
91 // vim: et:ts=4:sw=4
virtual ~request()
Definition: request.cpp:39
Completion handler class (Loki-style).
request_type m_type
Definition: request.h:51
#define STXXL_BLOCK_ALIGN
Definition: request.h:33
void * m_buffer
Definition: request.h:48
file * m_file
Definition: request.h:47
Defines interface of file.
Definition: file.h:56
void check_nref_failed(bool after)
Definition: request.cpp:60
void check_alignment() const
Definition: request.cpp:44
#define STXXL_BEGIN_NAMESPACE
Definition: namespace.h:16
size_type m_bytes
Definition: request.h:50
void add_request_ref()
increment referenced requests
Definition: file.h:186
stxxl::internal_size_type size_type
#define STXXL_ERRMSG(x)
Definition: verbose.h:94
choose_int_types< my_pointer_size >::unsigned_type unsigned_type
Definition: types.h:64
std::ostream & print(std::ostream &out) const
Dumps properties of a request.
Definition: request.cpp:80
virtual const char * io_type() const
Identifies the type of I/O implementation.
Definition: request.cpp:75
static const size_t bytes
number of bytes in uint_pair
Definition: uint_types.h:96
#define STXXL_VERBOSE3_THIS(x)
Definition: verbose.h:142
stxxl::external_size_type offset_type
unsigned_type get_reference_count() const
Return the number of references to this object (for debugging)
Definition: counting_ptr.h:512
offset_type m_offset
Definition: request.h:49
virtual const char * io_type() const =0
Identifies the type of I/O implementation.
#define STXXL_END_NAMESPACE
Definition: namespace.h:17