Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 59 lines (49 sloc) 2.064 kb
5282bc2 Henner Zeller o Move PassThrougHandler to its won file.
authored
1 // -*- c++ -*-
2 // Folve - A fuse filesystem that convolves audio files on-the-fly.
3 //
4 // Copyright (C) 2012 Henner Zeller <h.zeller@acm.org>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 #include "pass-through-handler.h"
20
21 #include <sys/stat.h>
22 #include <sys/types.h>
23 #include <unistd.h>
24 #include <errno.h>
25
26 #include "util.h"
27
28 using folve::DLogf;
29
30 PassThroughHandler::PassThroughHandler(int filedes, const std::string &filter_id,
31 const HandlerStats &known_stats)
32 : FileHandler(filter_id), filedes_(filedes),
33 file_size_(-1), max_accessed_(0), info_stats_(known_stats) {
34 DLogf("Creating PassThrough filter for '%s'", known_stats.filename.c_str());
35 struct stat st;
36 file_size_ = (Stat(&st) == 0) ? st.st_size : -1;
37 info_stats_.filter_dir = ""; // pass through.
38 }
39
40 PassThroughHandler::~PassThroughHandler() { close(filedes_); }
41
42 int PassThroughHandler::Read(char *buf, size_t size, off_t offset) {
43 const int result = pread(filedes_, buf, size, offset);
44 max_accessed_ = std::max(max_accessed_, (long unsigned int) offset + result);
45 return result == -1 ? -errno : result;
46 }
47
48 int PassThroughHandler::Stat(struct stat *st) {
49 return fstat(filedes_, st);
50 }
51
52 void PassThroughHandler::GetHandlerStatus(HandlerStats *stats) {
53 *stats = info_stats_;
54 if (file_size_ > 0) {
55 stats->access_progress = 1.0 * max_accessed_ / file_size_;
56 stats->buffer_progress = stats->access_progress;
57 }
58 }
Something went wrong with that request. Please try again.