Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

o Found a project name: "Folve". Some renamings because of that.

  • Loading branch information...
commit a9d3e538bf852c72e77521b55c25e4febfc3b479 1 parent 0aee3bb
Henner Zeller authored
4 Makefile
@@ -5,11 +5,11 @@ CFLAGS=-D_FILE_OFFSET_BITS=64 -Wall -O2
5 5 CXXFLAGS=$(CFLAGS)
6 6 LDFLAGS=-lfuse -lsndfile -lzita-convolver -lmicrohttpd
7 7
8   -OBJECTS = fuse-convolve.o convolver.o conversion-buffer.o \
  8 +OBJECTS = folve-main.o folve-filesystem.o conversion-buffer.o \
9 9 file-handler-cache.o status-server.o util.o \
10 10 zita-audiofile.o zita-config.o zita-fconfig.o zita-sstring.o
11 11
12   -fuse-convolve: $(OBJECTS)
  12 +folve: $(OBJECTS)
13 13 $(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)
14 14
15 15 clean:
34 README
... ... @@ -1,15 +1,41 @@
1   -A fuse filesystem that takes an original path to a directory with flac-files
2   -and provides these files that are convolved on the fly using the zita convolver
3   -(usually used in jconvolve).
  1 + Folve - Fuse Convolve
  2 + A fuse filesystem with on-the-fly convolving of sound files
  3 +
  4 +This fuse filesystem takes an original path to a directory with flac-files
  5 +and provides these files at the mount point. Accessing sound files will
  6 +automatically convolve these on-the-fly using the zita convolver by
  7 +Fons Adriaensen (Files in this directory starting with zita-* are imported
  8 +from his jconvolver project to parse the same configuration files).
  9 +
  10 +This solves the problem that many media servers don't provide a convolving
  11 +option and their only interface to the outside world is to access a file
  12 +system.
  13 +Also in general the beauty of simply accessing files to convolve is very
  14 +useful and allows for simple experiments.
  15 +
  16 +This project is based on
  17 +Fuse: Filesystem in Userspace http://fuse.sourceforge.net/
  18 +JConvolver Jack audio convolver http://apps.linuxaudio.org/apps/all/jconvolver
  19 +
  20 +Folve has been tested with various players and music servers (and
  21 +workes around bugs in these). Still, this is the first version made public, so
  22 +you should expect rough edges.
4 23
5 24 === To compile on Ubuntu ===
6 25
  26 + This requires the latest versions of libfuse and libzita convolver to compile.
  27 + .. and a couple of other libs:
  28 +
7 29 $ sudo aptitude install libsndfile-dev libflac-dev libzita-convolver-dev libfuse-dev fftw3-dev libboost-dev libmicrohttpd-dev
8 30 $ make
9 31
10 32 === Run ===
11 33
12   - ./fuse-convolve /directory/with/filters /path/to/original/fileystem /mnt/mountpoint -f
  34 + Fuse convolve requires three parameters: the first is directory to filter
  35 + configurations, the second the directory to the original flac files. The
  36 + third is the mount-point, where the convolved flac files will show up:
  37 +
  38 + ./fuse-convolve /directory/with/filters /path/to/original/files /mnt/mountpoint -f
13 39
14 40 Parameters:
15 41 1) The /directory/with/filters needs to be a directory that has
32 conversion-buffer.cc
@@ -13,6 +13,8 @@
13 13 // You should have received a copy of the GNU General Public License
14 14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
15 15
  16 +#include "conversion-buffer.h"
  17 +
16 18 #include <errno.h>
17 19 #include <fcntl.h>
18 20 #include <stdio.h>
@@ -21,16 +23,14 @@
21 23 #include <sys/types.h>
22 24 #include <unistd.h>
23 25
24   -#include "conversion-buffer.h"
25   -
26 26 ConversionBuffer::ConversionBuffer(SoundSource *source, const SF_INFO &info)
27   - : source_(source), tmpfile_(-1), snd_writing_enabled_(true),
  27 + : source_(source), tmpfile_filedes_(-1), snd_writing_enabled_(true),
28 28 total_written_(0), header_end_(0) {
29 29 // We need to be able to skip backwards but we don't want to fill our
30 30 // memory. So lets create a temporary file.
31   - const char *filename = tempnam(NULL, "fuse-");
32   - tmpfile_ = open(filename, O_RDWR|O_CREAT|O_NOATIME, S_IRUSR|S_IWUSR);
33   - if (tmpfile_ < 0) {
  31 + const char *filename = tempnam(NULL, "folve");
  32 + tmpfile_filedes_ = open(filename, O_RDWR|O_CREAT|O_NOATIME, S_IRUSR|S_IWUSR);
  33 + if (tmpfile_filedes_ < 0) {
34 34 perror("Problem opening buffer file");
35 35 }
36 36 unlink(filename);
@@ -40,7 +40,7 @@ ConversionBuffer::ConversionBuffer(SoundSource *source, const SF_INFO &info)
40 40 }
41 41
42 42 ConversionBuffer::~ConversionBuffer() {
43   - close(tmpfile_);
  43 + close(tmpfile_filedes_);
44 44 }
45 45
46 46 sf_count_t ConversionBuffer::SndTell(void *userdata) {
@@ -81,12 +81,12 @@ SNDFILE *ConversionBuffer::CreateOutputSoundfile(const SF_INFO &out_info) {
81 81 }
82 82
83 83 ssize_t ConversionBuffer::Append(const void *data, size_t count) {
84   - if (tmpfile_ < 0) return -1;
  84 + if (tmpfile_filedes_ < 0) return -1;
85 85 //fprintf(stderr, "Extend horizon by %ld bytes.\n", count);
86 86 int remaining = count;
87 87 const char *buf = (const char*)data;
88 88 while (remaining > 0) {
89   - int w = write(tmpfile_, data, count);
  89 + int w = write(tmpfile_filedes_, data, count);
90 90 if (w < 0) return -errno;
91 91 remaining -= w;
92 92 buf += w;
@@ -96,8 +96,8 @@ ssize_t ConversionBuffer::Append(const void *data, size_t count) {
96 96 }
97 97
98 98 void ConversionBuffer::WriteCharAt(unsigned char c, off_t offset) {
99   - if (tmpfile_ < 0) return;
100   - if (pwrite(tmpfile_, &c, 1, offset) != 1) fprintf(stderr, "mmh");
  99 + if (tmpfile_filedes_ < 0) return;
  100 + if (pwrite(tmpfile_filedes_, &c, 1, offset) != 1) fprintf(stderr, "Oops.");
101 101 }
102 102
103 103 ssize_t ConversionBuffer::SndAppend(const void *data, size_t count) {
@@ -123,14 +123,6 @@ ssize_t ConversionBuffer::Read(char *buf, size_t size, off_t offset) {
123 123 // required_min_written = offset + size; // all requested bytes.
124 124 const off_t required_min_written = offset + (offset >= header_end_ ? size : 1);
125 125
126   - // Skipping the file looks like reading beyond what the user already
127   - // consumed. Print this as diagnostic message.
128   -#if 0
129   - if (total_written_ + 1 < offset) {
130   - fprintf(stderr, "(skip> %ld -> %ld)", total_written_, offset);
131   - }
132   -#endif
133   -
134 126 // As soon as someone tries to read beyond of what we already have, we call
135 127 // our WriteToSoundfile() callback that fills more of it.
136 128 while (total_written_ < required_min_written) {
@@ -138,5 +130,5 @@ ssize_t ConversionBuffer::Read(char *buf, size_t size, off_t offset) {
138 130 break;
139 131 }
140 132
141   - return pread(tmpfile_, buf, size, offset);
  133 + return pread(tmpfile_filedes_, buf, size, offset);
142 134 }
31 conversion-buffer.h
... ... @@ -1,3 +1,4 @@
  1 +// -*- c++ -*-
1 2 // Copyright (C) 2012 Henner Zeller <h.zeller@acm.org>
2 3 //
3 4 // This program is free software; you can redistribute it and/or modify
@@ -13,6 +14,9 @@
13 14 // You should have received a copy of the GNU General Public License
14 15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
15 16
  17 +#ifndef FOLVE_CONVERSION_BUFFER_H
  18 +#define FOLVE_CONVERSION_BUFFER_H
  19 +
16 20 #include <sndfile.h>
17 21
18 22 // A file-backed buffer for a SNDFILE, that is only filled on demand via
@@ -20,7 +24,7 @@
20 24 // If Read() is called beyond the current available data, a callback is
21 25 // called to write more into the SNDFILE.
22 26 class ConversionBuffer {
23   - public:
  27 +public:
24 28 // SoundSource, a instance of which needs to be passed to the
25 29 // ConversionBuffer.
26 30 class SoundSource {
@@ -35,19 +39,20 @@ class ConversionBuffer {
35 39 // sf_close() the file.
36 40 virtual void SetOutputSoundfile(ConversionBuffer *parent,
37 41 SNDFILE *sndfile) = 0;
38   -
  42 +
39 43 // This callback is called by the ConversionBuffer if it needs more data.
40 44 // Rerturns 'true' if there is more, 'false' if that was the last available
41 45 // data.
42 46 virtual bool AddMoreSoundData() = 0;
43 47 };
44 48
45   - // Create a conversion buffer that holds "buffer_size" bytes.
46   - // The "source" will be informed to what SNDFILE to write to and whenever
47   - // this ConversionBuffer lusts for more data (it then calls
48   - // AddMoreSoundData()).
  49 + // Create a conversion buffer providing an sound output described in
  50 + // "out_info".
  51 + // The "source" will be called back whenever this conversion buffer needs
  52 + // more data.
  53 + //
49 54 // Ownership is not taken over for source.
50   - ConversionBuffer(SoundSource *source, const SF_INFO &info);
  55 + ConversionBuffer(SoundSource *source, const SF_INFO &out_info);
51 56 ~ConversionBuffer();
52 57
53 58 // Read data from buffer. Can block and call the SoundSource first to get
@@ -55,7 +60,7 @@ class ConversionBuffer {
55 60 ssize_t Read(char *buf, size_t size, off_t offset);
56 61
57 62 // Append data. Usually called via the SndWrite() virtual-SNFFILE callback,
58   - // but can be used to write raw data as well.
  63 + // but can be used to write raw data as well (e.g. to write headers).
59 64 ssize_t Append(const void *data, size_t count);
60 65
61 66 // Write at a particular position. Writes a single character - this is
@@ -70,17 +75,17 @@ class ConversionBuffer {
70 75 bool sndfile_writes_enabled() const { return snd_writing_enabled_; }
71 76
72 77 // Tell conversion buffer when we're done writing the header. It needs to
73   - // know to do some buffer trickery.
  78 + // know so that it can serve reads in these different regions differently.
  79 + // (Long story, see Read() for details).
74 80 void HeaderFinished();
75 81
76 82 // Current max file position.
77 83 off_t FileSize() const { return total_written_; }
78 84
79   - private:
  85 +private:
80 86 static sf_count_t SndTell(void *userdata);
81 87 static sf_count_t SndWrite(const void *ptr, sf_count_t count, void *userdata);
82 88
83   -
84 89 // Append for the SndWrite callback.
85 90 ssize_t SndAppend(const void *data, size_t count);
86 91
@@ -89,8 +94,10 @@ class ConversionBuffer {
89 94 SNDFILE *CreateOutputSoundfile(const SF_INFO &info);
90 95
91 96 SoundSource *const source_;
92   - int tmpfile_;
  97 + int tmpfile_filedes_;
93 98 bool snd_writing_enabled_;
94 99 off_t total_written_;
95 100 off_t header_end_;
96 101 };
  102 +
  103 +#endif // FOLVE_CONVERSION_BUFFER_H
4 file-handler-cache.cc
@@ -46,7 +46,7 @@ FileHandler *FileHandlerCache::InsertPinned(const std::string &key,
46 46 if (cache_.size() > max_size_) {
47 47 CleanupOldestUnreferenced_Locked();
48 48 }
49   - ins->second->last_access = fuse_convolve::CurrentTime();
  49 + ins->second->last_access = folve::CurrentTime();
50 50 if (observer_) observer_->InsertHandlerEvent(ins->second->handler);
51 51 return ins->second->handler;
52 52 }
@@ -57,7 +57,7 @@ FileHandler *FileHandlerCache::FindAndPin(const std::string &key) {
57 57 if (found == cache_.end())
58 58 return NULL;
59 59 ++found->second->references;
60   - found->second->last_access = fuse_convolve::CurrentTime();
  60 + found->second->last_access = folve::CurrentTime();
61 61 return found->second->handler;
62 62 }
63 63
24 file-handler-cache.h
@@ -14,20 +14,24 @@
14 14 // You should have received a copy of the GNU General Public License
15 15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16
17   -#ifndef _FUSE_CONVOLVER_FILE_HANDLER_CACHE_H
18   -#define _FUSE_CONVOLVER_FILE_HANDLER_CACHE_H
  17 +#ifndef FOLVE_FILE_HANDLER_CACHE_H
  18 +#define FOLVE_FILE_HANDLER_CACHE_H
19 19
20 20 #include <time.h>
21 21
22 22 #include <map>
23   -#include <vector>
24 23 #include <string>
  24 +#include <vector>
  25 +
25 26 #include <boost/thread/mutex.hpp>
26 27
  28 +#include "file-handler.h"
  29 +
27 30 class FileHandler;
28 31
29   -// Cache of in-use file handlers. We sometimes get multiple requests for the
30   -// same file, so we want to map them all to the same FileHandler.
  32 +// Cache of in-use file handlers. We sometimes get multiple open()/close()
  33 +// request for the same file by some programs. Also, some constantly monitor
  34 +// the file-size while the file is open.
31 35 //
32 36 // This Cache manages the lifecycle of a FileHandler object; the user creates
33 37 // it, but this Cache handles deletion.
@@ -48,12 +52,12 @@ class FileHandlerCache {
48 52
49 53 // Insert a new object under the given key.
50 54 // Ownership is handed over to this map.
51   - // If there was already an object stored under that key, that is returned
52   - // instead and the new object discarded.
  55 + // If there was already an object stored under that key, the existing one
  56 + // is returned instead and the passed object discarded.
53 57 FileHandler *InsertPinned(const std::string &key, FileHandler *handler);
54 58
55   - // Find an object in this map and pin it down. You've to Unpin() it after
56   - // use.
  59 + // Find an object in this map and pin it down so that it is not evicted.
  60 + // You've to Unpin() it after use.
57 61 FileHandler *FindAndPin(const std::string &key);
58 62
59 63 // Unpin object. If the last object is unpinned, the PinnedMap may decide
@@ -82,4 +86,4 @@ class FileHandlerCache {
82 86 CacheMap cache_;
83 87 };
84 88
85   -#endif // _FUSE_CONVOLVER_FILE_HANDLER_CACHE_H
  89 +#endif // FOLVE_FILE_HANDLER_CACHE_H
11 file-handler.h
@@ -14,8 +14,8 @@
14 14 // You should have received a copy of the GNU General Public License
15 15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16
17   -#ifndef _FUSE_CONVOLVER_FILE_HANDLER_H
18   -#define _FUSE_CONVOLVER_FILE_HANDLER_H
  17 +#ifndef FOLVE_FILE_HANDLER_H
  18 +#define FOLVE_FILE_HANDLER_H
19 19
20 20 #include <string>
21 21
@@ -32,6 +32,11 @@ struct HandlerStats {
32 32 double last_access;
33 33 };
34 34
  35 +// A handler that deals with operations on files. Since we only provide read
  36 +// access, this is limited to very few operations.
  37 +// Closing in particular is not done by this file handler as it might
  38 +// have a longer life-time than an open()/close() cycle we get from the
  39 +// fuse filesystem (see file-handler-cache.h for rationale)
35 40 class FileHandler {
36 41 public:
37 42 virtual ~FileHandler() {}
@@ -44,4 +49,4 @@ class FileHandler {
44 49 virtual void GetHandlerStatus(struct HandlerStats *s) = 0;
45 50 };
46 51
47   -#endif // _FUSE_CONVOLVER_FILE_HANDLER_H
  52 +#endif // FOLVE_FILE_HANDLER_H
23 convolver.cc → folve-filesystem.cc
@@ -13,6 +13,8 @@
13 13 // You should have received a copy of the GNU General Public License
14 14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
15 15
  16 +#include "folve-filesystem.h"
  17 +
16 18 #include <FLAC/metadata.h>
17 19 #include <errno.h>
18 20 #include <fcntl.h>
@@ -24,13 +26,12 @@
24 26 #include <sys/types.h>
25 27 #include <unistd.h>
26 28
27   -#include <string>
28 29 #include <map>
  30 +#include <string>
29 31
30   -#include "file-handler.h"
31   -#include "file-handler-cache.h"
32   -#include "convolver-filesystem.h"
33 32 #include "conversion-buffer.h"
  33 +#include "file-handler-cache.h"
  34 +#include "file-handler.h"
34 35 #include "zita-config.h"
35 36
36 37 static bool global_debug = false;
@@ -464,8 +465,8 @@ static FileHandler *CreateFilterFromFileType(int filedes,
464 465 }
465 466
466 467 // Implementation of the C functions in filter-interface.h
467   -FileHandler *ConvolverFilesystem::CreateHandler(const char *fs_path,
468   - const char *underlying_path) {
  468 +FileHandler *FolveFilesystem::CreateHandler(const char *fs_path,
  469 + const char *underlying_path) {
469 470 FileHandler *handler = open_file_cache_.FindAndPin(fs_path);
470 471 if (handler == NULL) {
471 472 int filedes = open(underlying_path, O_RDONLY);
@@ -480,7 +481,7 @@ FileHandler *ConvolverFilesystem::CreateHandler(const char *fs_path,
480 481 return handler;
481 482 }
482 483
483   -int ConvolverFilesystem::StatByFilename(const char *fs_path, struct stat *st) {
  484 +int FolveFilesystem::StatByFilename(const char *fs_path, struct stat *st) {
484 485 FileHandler *handler = open_file_cache_.FindAndPin(fs_path);
485 486 if (handler == 0)
486 487 return -1;
@@ -489,13 +490,13 @@ int ConvolverFilesystem::StatByFilename(const char *fs_path, struct stat *st) {
489 490 return result;
490 491 }
491 492
492   -void ConvolverFilesystem::Close(const char *fs_path) {
  493 +void FolveFilesystem::Close(const char *fs_path) {
493 494 open_file_cache_.Unpin(fs_path);
494 495 }
495 496
496   -ConvolverFilesystem::ConvolverFilesystem(const char *version_info,
497   - const char *unerlying_dir,
498   - const char *zita_config_dir)
  497 +FolveFilesystem::FolveFilesystem(const char *version_info,
  498 + const char *unerlying_dir,
  499 + const char *zita_config_dir)
499 500 : version_info_(version_info), underlying_dir_(unerlying_dir),
500 501 open_file_cache_(3),
501 502 total_file_openings_(0), total_file_reopen_(0) {
15 convolver-filesystem.h → folve-filesystem.h
@@ -14,19 +14,18 @@
14 14 // You should have received a copy of the GNU General Public License
15 15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16
17   -#ifndef _FUSE_CONVOLVER_FILESYSTEM_H
18   -#define _FUSE_CONVOLVER_FILESYSTEM_H
  17 +#ifndef FOLVE_FILESYSTEM_H
  18 +#define FOLVE_FILESYSTEM_H
19 19
20 20 #include <unistd.h>
21 21
22   -#include "file-handler.h"
23 22 #include "file-handler-cache.h"
  23 +#include "file-handler.h"
24 24
25   -class ConvolverFilesystem {
  25 +class FolveFilesystem {
26 26 public:
27   - ConvolverFilesystem(const char *version_info,
28   - const char *underlying_dir,
29   - const char *zita_config_dir);
  27 + FolveFilesystem(const char *version_info, const char *underlying_dir,
  28 + const char *zita_config_dir);
30 29
31 30 // Create a new filter given the filesystem path and the underlying
32 31 // path.
@@ -57,4 +56,4 @@ class ConvolverFilesystem {
57 56 int total_file_reopen_;
58 57 };
59 58
60   -#endif // _FUSE_CONVOLVER_FILESYSTEM_H
  59 +#endif // FOLVE_FILESYSTEM_H
34 fuse-convolve.cc → folve-main.cc
@@ -13,18 +13,10 @@
13 13 // You should have received a copy of the GNU General Public License
14 14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
15 15
16   -// This fuse filesystem only provides read access to another filesystem that
17   -// contains *.flac and *.wav files. Accessing these files passes them
18   -// through a zita-filter transparently.
19   -// This is a pure C implementation, providing basic file operations and passing
20   -// actual reading to a filter aquired using the functions in filter-interface.h
21   -
22 16 // Use latest version.
23 17 #define FUSE_USE_VERSION 26
24   -
25   -#define FUSE_CONVOLVE_VERSION_INFO "v. 0.79 &mdash; 2012-09-15"
26   -
27 18 #include <fuse.h>
  19 +
28 20 #include <stdio.h>
29 21 #include <string.h>
30 22 #include <unistd.h>
@@ -36,11 +28,14 @@
36 28 #include <limits.h>
37 29 #include <stdlib.h>
38 30
39   -#include "convolver-filesystem.h"
  31 +#include "folve-filesystem.h"
40 32 #include "status-server.h"
41 33
42   -ConvolverFilesystem *convolver_fs = NULL;
43   -const char *orig_dir;
  34 +#define FOLVE_VERSION "v. 0.79 &mdash; 2012-09-15"
  35 +
  36 +// Compilation unit variables to communicate with the
  37 +static FolveFilesystem *folve_fs = NULL;
  38 +static const char *underlying_dir = NULL;
44 39
45 40 static int has_suffix_string (const char *str, const char *suffix) {
46 41 if (!str || !suffix)
@@ -62,7 +57,7 @@ static char *concat_path(char *buf, const char *a, const char *b) {
62 57 // original file from the source filesystem.
63 58 // TODO(hzeller): move the ogg.fuse.flac logic into convolver-filesystem.
64 59 static const char *assemble_orig_path(char *buf, const char *path) {
65   - char *result = concat_path(buf, orig_dir, path);
  60 + char *result = concat_path(buf, underlying_dir, path);
66 61 static const char magic_ogg_rewrite[] = ".ogg.fuse.flac";
67 62 if (has_suffix_string(result, magic_ogg_rewrite)) {
68 63 *(result + strlen(result) - strlen(".fuse.flac")) = '\0';
@@ -75,7 +70,7 @@ static const char *assemble_orig_path(char *buf, const char *path) {
75 70 static int fuseconv_getattr(const char *path, struct stat *stbuf) {
76 71 // If this is a currently open filename, we might be able to output a better
77 72 // estimate.
78   - int result = convolver_fs->StatByFilename(path, stbuf);
  73 + int result = folve_fs->StatByFilename(path, stbuf);
79 74 if (result == 0) return result;
80 75
81 76 char path_buf[PATH_MAX];
@@ -142,7 +137,7 @@ static int fuseconv_open(const char *path, struct fuse_file_info *fi) {
142 137 // (Yay, someone was thinking while developing that API).
143 138 char path_buf[PATH_MAX];
144 139 const char *orig_path = assemble_orig_path(path_buf, path);
145   - FileHandler * handler = convolver_fs->CreateHandler(path, orig_path);
  140 + FileHandler * handler = folve_fs->CreateHandler(path, orig_path);
146 141 if (handler == NULL)
147 142 return -errno;
148 143 fi->fh = (uint64_t) handler;
@@ -155,7 +150,7 @@ static int fuseconv_read(const char *path, char *buf, size_t size, off_t offset,
155 150 }
156 151
157 152 static int fuseconv_release(const char *path, struct fuse_file_info *fi) {
158   - convolver_fs->Close(path);
  153 + folve_fs->Close(path);
159 154 return 0;
160 155 }
161 156
@@ -178,14 +173,13 @@ int main(int argc, char *argv[]) {
178 173
179 174 // First, let's extract our configuration.
180 175 const char *config_dir = argv[1];
181   - orig_dir = argv[2];
  176 + underlying_dir = argv[2];
182 177 argc -=2;
183 178 argv += 2;
184   - convolver_fs = new ConvolverFilesystem(FUSE_CONVOLVE_VERSION_INFO,
185   - orig_dir, config_dir);
  179 + folve_fs = new FolveFilesystem(FOLVE_VERSION, underlying_dir, config_dir);
186 180
187 181 // TODO(hzeller): make this configurable
188   - StatusServer *statusz = new StatusServer(convolver_fs);
  182 + StatusServer *statusz = new StatusServer(folve_fs);
189 183 statusz->Start(17322);
190 184
191 185 struct fuse_operations fuseconv_operations;
25 status-server.cc
@@ -25,10 +25,13 @@
25 25
26 26 #include <microhttpd.h>
27 27
28   -#include "convolver-filesystem.h"
  28 +#include "folve-filesystem.h"
29 29 #include "status-server.h"
30 30 #include "util.h"
31 31
  32 +// TODO: someone with a bit more stylesheet-fu can attempt to make this
  33 +// more pretty and the HTML more compact.
  34 +
32 35 static const size_t kMaxRetired = 200;
33 36 static const int kProgressWidth = 400;
34 37 static const char kActiveProgress[] = "#7070ff";
@@ -39,7 +42,7 @@ static const char kRetiredProgress[] = "#d0d0d0";
39 42 // TODO: make a nice icon, recognizable as something that has to do with "
40 43 // files and music ...
41 44 static const char kHtmlHeader[] = "<header>"
42   - "<title>Fuse Convolver</title>\n"
  45 + "<title>Folve</title>\n"
43 46 "<link rel='icon' type='image/png'"
44 47 "href='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2"
45 48 "AAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9wJDwUlEA/UBrsA"
@@ -67,7 +70,7 @@ int StatusServer::HandleHttp(void* user_argument,
67 70 return ret;
68 71 }
69 72
70   -StatusServer::StatusServer(ConvolverFilesystem *fs)
  73 +StatusServer::StatusServer(FolveFilesystem *fs)
71 74 : total_seconds_filtered_(0), total_seconds_music_seen_(0),
72 75 filesystem_(fs), daemon_(NULL) {
73 76 fs->handler_cache()->SetObserver(this);
@@ -93,7 +96,7 @@ void StatusServer::RetireHandlerEvent(FileHandler *handler) {
93 96 total_seconds_music_seen_ += stats.total_duration_seconds;
94 97 total_seconds_filtered_ += stats.total_duration_seconds * stats.progress;
95 98 }
96   - stats.last_access = fuse_convolve::CurrentTime();
  99 + stats.last_access = folve::CurrentTime();
97 100 stats.status = HandlerStats::RETIRED;
98 101 retired_.push_front(stats);
99 102 while (retired_.size() > kMaxRetired)
@@ -159,11 +162,11 @@ struct CompareStats {
159 162 };
160 163
161 164 void StatusServer::CreatePage(const char **buffer, size_t *size) {
162   - const double start = fuse_convolve::CurrentTime();
  165 + const double start = folve::CurrentTime();
163 166 current_page_.clear();
164 167 current_page_.append(kHtmlHeader);
165   - current_page_.append("<body style='font-family:Helvetica;'>\n");
166   - Appendf(&current_page_, "<center>Welcome to Fuse Convolve %s</center>"
  168 + current_page_.append("<body style='font-family:Sans-Serif;'>\n");
  169 + Appendf(&current_page_, "<center>Welcome to Folve %s</center>"
167 170 "Convolving files from <code>%s</code><br/>\n",
168 171 filesystem_->version().c_str(), filesystem_->underlying_dir().c_str());
169 172
@@ -220,9 +223,11 @@ void StatusServer::CreatePage(const char **buffer, size_t *size) {
220 223 current_page_.append("</table><hr/>\n");
221 224 }
222 225
223   - const double duration = fuse_convolve::CurrentTime() - start;
224   - Appendf(&current_page_, "page-gen %.2fms <div align='right'>HZ</div></body>",
225   - duration * 1000.0);
  226 + const double duration = folve::CurrentTime() - start;
  227 + Appendf(&current_page_,
  228 + "<span style='float:left;font-size:small;'>page-gen %.2fms</span>"
  229 + "<span style='float:right;font-size:small;'>HZ</span>"
  230 + "</body>", duration * 1000.0);
226 231 *buffer = current_page_.data();
227 232 *size = current_page_.size();
228 233 }
15 status-server.h
@@ -14,8 +14,8 @@
14 14 // You should have received a copy of the GNU General Public License
15 15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16
17   -#ifndef FUSE_CONVOLVER_STATUS_SERVER_H
18   -#define FUSE_CONVOLVER_STATUS_SERVER_H
  17 +#ifndef FOLVE_STATUS_SERVER_H
  18 +#define FOLVE_STATUS_SERVER_H
19 19
20 20 #include <string>
21 21 #include <deque>
@@ -23,16 +23,19 @@
23 23 #include "file-handler-cache.h"
24 24 #include "file-handler.h"
25 25
26   -class ConvolverFilesystem;
  26 +class FolveFilesystem;
27 27 struct MHD_Daemon;
28 28 struct MHD_Connection;
29 29
30 30 class StatusServer : protected FileHandlerCache::Observer {
31 31 public:
32 32 // Does not take over ownership of the filesystem.
33   - StatusServer(ConvolverFilesystem *fs);
  33 + StatusServer(FolveFilesystem *fs);
  34 +
  35 + // Start server, listing on given port.
34 36 bool Start(int port);
35 37
  38 + // Shut down daemon.
36 39 virtual ~StatusServer();
37 40
38 41 private:
@@ -51,9 +54,9 @@ class StatusServer : protected FileHandlerCache::Observer {
51 54 RetiredList retired_;
52 55 double total_seconds_filtered_;
53 56 double total_seconds_music_seen_;
54   - ConvolverFilesystem *filesystem_;
  57 + FolveFilesystem *filesystem_;
55 58 struct MHD_Daemon *daemon_;
56 59 std::string current_page_;
57 60 };
58 61
59   -#endif // FUSE_CONVOLVER_STATUS_SERVER_H
  62 +#endif // FOLVE_STATUS_SERVER_H
6 util.cc
@@ -13,12 +13,12 @@
13 13 // You should have received a copy of the GNU General Public License
14 14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
15 15
  16 +#include "util.h"
  17 +
16 18 #include <sys/time.h>
17 19 #include <stdio.h>
18 20
19   -#include "util.h"
20   -
21   -double fuse_convolve::CurrentTime() {
  21 +double folve::CurrentTime() {
22 22 struct timeval tv;
23 23 gettimeofday(&tv, NULL);
24 24 return tv.tv_sec + tv.tv_usec / 1e6;
9 util.h
... ... @@ -1,3 +1,4 @@
  1 +// -*- c++ -*-
1 2 // Copyright (C) 2012 Henner Zeller <h.zeller@acm.org>
2 3 //
3 4 // This program is free software; you can redistribute it and/or modify
@@ -13,11 +14,11 @@
13 14 // You should have received a copy of the GNU General Public License
14 15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
15 16
16   -#ifndef FUSE_CONVOLVE_UTIL_H
17   -#define FUSE_CONVOLVE_UTIL_H
  17 +#ifndef FOLVE_UTIL_H
  18 +#define FOLVE_UTIL_H
18 19
19   -namespace fuse_convolve {
  20 +namespace folve {
20 21 double CurrentTime();
21 22 } // namespece fuse_convolve
22 23
23   -#endif // FUSE_CONVOLVE_UTIL_H
  24 +#endif // FOLVE_UTIL_H

0 comments on commit a9d3e53

Please sign in to comment.
Something went wrong with that request. Please try again.