1
// libTorrent - BitTorrent library
2
// Copyright (C) 2005-2006, Jari Sundell
4
// This program is free software; you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation; either version 2 of the License, or
7
// (at your option) any later version.
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License
15
// along with this program; if not, write to the Free Software
16
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
// In addition, as a special exception, the copyright holders give
19
// permission to link the code of portions of this program with the
20
// OpenSSL library under certain conditions as described in each
21
// individual source file, and distribute linked combinations
24
// You must obey the GNU General Public License in all respects for
25
// all of the code used other than OpenSSL. If you modify file(s)
26
// with this exception, you may extend this exception to your version
27
// of the file(s), but you are not obligated to do so. If you do not
28
// wish to do so, delete this exception statement from your version.
29
// If you delete this exception statement from all source files in the
30
// program, then also delete it here.
32
// Contact: Jari Sundell <jaris@ifi.uio.no>
35
// 3185 Skoppum, NORWAY
37
#ifndef LIBTORRENT_FILE_H
38
#define LIBTORRENT_FILE_H
40
#include <torrent/common.h>
41
#include <torrent/path.h>
45
class LIBTORRENT_EXPORT File {
47
friend class FileList;
49
typedef std::pair<uint32_t, uint32_t> range_type;
54
bool is_created() const;
55
bool is_open() const { return m_fd != -1; }
57
bool is_correct_size() const;
58
bool is_valid_position(uint64_t p) const;
60
bool has_permissions(int prot) const { return !(prot & ~m_protection); }
62
uint64_t offset() const { return m_offset; }
64
uint64_t size_bytes() const { return m_size; }
65
uint32_t size_chunks() const { return m_range.second - m_range.first; }
67
uint32_t completed_chunks() const { return m_completed; }
69
const range_type& range() const { return m_range; }
70
uint32_t range_first() const { return m_range.first; }
71
uint32_t range_second() const { return m_range.second; }
73
priority_t priority() const { return m_priority; }
74
void set_priority(priority_t t) { m_priority = t; }
76
Path* path() { return &m_path; }
77
const Path* path() const { return &m_path; }
79
const std::string& frozen_path() const { return m_frozenPath; }
81
uint32_t match_depth_prev() const { return m_matchDepthPrev; }
82
uint32_t match_depth_next() const { return m_matchDepthNext; }
84
// This should only be changed by libtorrent.
85
int file_descriptor() const { return m_fd; }
86
void set_file_descriptor(int fd) { m_fd = fd; }
88
// This might actually be wanted, as it would be nice to allow the
89
// File to decide if it needs to try creating the underlying file or
91
bool prepare(int prot, int flags = 0);
93
int protection() const { return m_protection; }
94
void set_protection(int prot) { m_protection = prot; }
96
uint64_t last_touched() const { return m_lastTouched; }
97
void set_last_touched(uint64_t t) { m_lastTouched = t; }
100
void set_frozen_path(const std::string& path) { m_frozenPath = path; }
102
void set_offset(uint64_t off) { m_offset = off; }
103
void set_size_bytes(uint64_t size) { m_size = size; }
104
void set_range(uint32_t chunkSize);
106
void set_completed(uint32_t v) { m_completed = v; }
107
void inc_completed() { m_completed++; }
109
void set_match_depth_prev(uint32_t l) { m_matchDepthPrev = l; }
110
void set_match_depth_next(uint32_t l) { m_matchDepthNext = l; }
116
void operator = (const File&);
125
uint32_t m_completed;
126
priority_t m_priority;
128
uint32_t m_matchDepthPrev;
129
uint32_t m_matchDepthNext;
131
// Move the below stuff up to the right places next incompatible API
134
std::string m_frozenPath;
138
uint64_t m_lastTouched;
142
File::is_valid_position(uint64_t p) const {
143
return p >= m_offset && p < m_offset + m_size;