Permalink
Browse files

o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface

  essentially convolver-filesystem.h ad provide class ConvolverFilesystem.
o Start status server. Needs to be filled.
  • Loading branch information...
1 parent 680f590 commit 8d1fbe7c330b5d505e7996d44d2704c4f8735a0a @hzeller committed Sep 14, 2012
Showing with 239 additions and 119 deletions.
  1. +3 −3 Makefile
  2. +1 −1 README
  3. +48 −0 convolver-filesystem.h
  4. +9 −17 convolver.cc
  5. +12 −8 file-handler-cache.cc
  6. +15 −2 file-handler-cache.h
  7. +5 −2 file-handler.h
  8. +0 −55 filter-interface.h
  9. +34 −31 fuse-convolve.c → fuse-convolve.cc
  10. +70 −0 status-server.cc
  11. +42 −0 status-server.h
View
@@ -1,10 +1,10 @@
CC=gcc
CXX=g++
-CFLAGS=-D_FILE_OFFSET_BITS=64 -Wall -g -O2
+CFLAGS=-D_FILE_OFFSET_BITS=64 -Wall -g -O0
CXXFLAGS=$(CFLAGS)
-LDFLAGS=-lfuse -lsndfile -lzita-convolver
+LDFLAGS=-lfuse -lsndfile -lzita-convolver -lmicrohttpd
-fuse-convolve: fuse-convolve.o convolver.o conversion-buffer.o zita-audiofile.o zita-config.o zita-fconfig.o zita-sstring.o file-handler-cache.o
+fuse-convolve: fuse-convolve.o convolver.o conversion-buffer.o zita-audiofile.o zita-config.o zita-fconfig.o zita-sstring.o file-handler-cache.o status-server.o
$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)
clean:
View
2 README
@@ -4,7 +4,7 @@ and provides these files that are convolved on the fly using the zita convolver
=== To compile on Ubuntu ===
- $ sudo aptitude install libsndfile-dev libflac-dev libzita-convolver-dev libfuse-dev fftw3-dev libboost-dev
+ $ sudo aptitude install libsndfile-dev libflac-dev libzita-convolver-dev libfuse-dev fftw3-dev libboost-dev libmicrohttpd-dev
$ make
=== Run ===
View
@@ -0,0 +1,48 @@
+// -*- c++ -*-
+// Copyright (C) 2012 Henner Zeller <h.zeller@acm.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef _FUSE_CONVOLVER_FILESYSTEM_H
+#define _FUSE_CONVOLVER_FILESYSTEM_H
+
+#include <unistd.h>
+
+#include "file-handler.h"
+#include "file-handler-cache.h"
+
+class ConvolverFilesystem {
+public:
+ ConvolverFilesystem(const char *zita_config_dir,
+ int cache_size);
+
+ FileHandlerCache *handler_cache() { return &open_files_; }
+
+ // Create a new filter given the open filedescriptor and the path.
+ // Returns NULL, if it cannot be created.
+ FileHandler *CreateHandler(const char *fs_path,
+ const char *underlying_path);
+
+ // Return dynamic size of file.
+ int StatByFilename(const char *fs_path, struct stat *st);
+
+ // At the end of the operation, close filter. Return 0 on success or negative
+ // errno value on failure.
+ void Close(const char *fs_path);
+
+private:
+ FileHandlerCache open_files_;
+};
+
+#endif // _FUSE_CONVOLVER_FILESYSTEM_H
View
@@ -29,7 +29,7 @@
#include "file-handler.h"
#include "file-handler-cache.h"
-#include "filter-interface.h"
+#include "convolver-filesystem.h"
#include "conversion-buffer.h"
#include "zita-config.h"
@@ -404,7 +404,7 @@ class SndFileHandler :
static FileHandlerCache open_files_(1);
static FileHandler *CreateFilterFromFileType(int filedes,
- const char *underlying_file) {
+ const char *underlying_file) {
FileHandler *filter = SndFileHandler::Create(filedes, underlying_file);
if (filter != NULL) return filter;
@@ -414,8 +414,8 @@ static FileHandler *CreateFilterFromFileType(int filedes,
}
// Implementation of the C functions in filter-interface.h
-struct filter_object_t *create_filter(const char *fs_path,
- const char *underlying_path) {
+FileHandler *ConvolverFilesystem::CreateHandler(const char *fs_path,
+ const char *underlying_path) {
FileHandler *handler = open_files_.FindAndPin(fs_path);
if (handler == NULL) {
int filedes = open(underlying_path, O_RDONLY);
@@ -427,29 +427,21 @@ struct filter_object_t *create_filter(const char *fs_path,
return handler;
}
-int read_from_filter(struct filter_object_t *filter,
- char *buf, size_t size, off_t offset) {
- return reinterpret_cast<FileHandler*>(filter)->Read(buf, size, offset);
-}
-
-int fill_stat_by_filename(const char *fs_path, struct stat *st) {
+int ConvolverFilesystem::StatByFilename(const char *fs_path, struct stat *st) {
FileHandler *handler = open_files_.FindAndPin(fs_path);
if (handler == 0)
return -1;
ssize_t result = handler->Stat(st);
open_files_.Unpin(fs_path);
return result;
}
-int fill_fstat_file(struct filter_object_t *filter, struct stat *st) {
- return reinterpret_cast<FileHandler*>(filter)->Stat(st);
-}
-int close_filter(const char *fs_path, struct filter_object_t *filter) {
+void ConvolverFilesystem::Close(const char *fs_path) {
open_files_.Unpin(fs_path);
- // TODO close file.
- return 0;
}
-void initialize_convolver_filter(const char *zita_config_dir) {
+ConvolverFilesystem::ConvolverFilesystem(const char *zita_config_dir,
+ int cache_size)
+ : open_files_(cache_size) {
global_zita_config_dir = zita_config_dir;
}
View
@@ -23,21 +23,16 @@
#include "file-handler.h"
#include "file-handler-cache.h"
-struct FileHandlerCache::Entry {
- Entry(FileHandler *h) : handler(h), references(0) {}
- ~Entry() { delete handler; }
-
- FileHandler *const handler;
- int references;
-};
+FileHandlerCache::Entry::Entry(const std::string &k, FileHandler *h)
+ : key(k), handler(h) {}
FileHandler *FileHandlerCache::InsertPinned(const std::string &key,
FileHandler *handler) {
boost::lock_guard<boost::mutex> l(mutex_);
CacheMap::iterator ins
= cache_.insert(std::make_pair(key, (Entry*)NULL)).first;
if (ins->second == NULL) { // new entry
- ins->second = new Entry(handler);
+ ins->second = new Entry(key, handler);
} else {
delete handler;
}
@@ -64,10 +59,19 @@ void FileHandlerCache::Unpin(const std::string &key) {
--found->second->references;
}
+void FileHandlerCache::GetStats(std::vector<const Entry *> *entries) {
+ boost::lock_guard<boost::mutex> l(mutex_);
+ for (CacheMap::iterator it = cache_.begin(); it != cache_.end(); ++it) {
+ ++it->second->references;
+ entries->push_back(it->second);
+ }
+}
+
void FileHandlerCache::CleanupUnreferenced() {
for (CacheMap::iterator it = cache_.begin(); it != cache_.end(); ++it) {
if (it->second->references == 0) {
fprintf(stderr, "cleanup %s\n", it->first.c_str());
+ delete it->second->handler;
delete it->second;
cache_.erase(it);
}
View
@@ -18,6 +18,7 @@
#define _FUSE_CONVOLVER_FILE_HANDLER_CACHE_
#include <map>
+#include <vector>
#include <string>
#include <boost/thread/mutex.hpp>
@@ -31,6 +32,14 @@ class FileHandler;
// This container is thread-safe.
class FileHandlerCache {
public:
+ // Cache entry.
+ struct Entry {
+ Entry(const std::string &, FileHandler *);
+ const std::string key;
+ FileHandler *const handler;
+ int references;
+ time_t last_used;
+ };
FileHandlerCache(int max_size) : max_size_(max_size) {}
// Insert a new object under the given key.
@@ -46,9 +55,13 @@ class FileHandlerCache {
// Unpin object. If the last object is unpinned, the PinnedMap may decide
// to delete it later (though typically will keep it around for a while).
void Unpin(const std::string &key);
-
+
+ // Get a vector of the current entries in this cache. All entries are
+ // pinned and need to be Unpin()-ed by the user.
+ typedef std::vector<const Entry *> EntryList;
+ void GetStats(EntryList *entries);
+
private:
- struct Entry;
typedef std::map<std::string, Entry*> CacheMap;
void CleanupUnreferenced();
View
@@ -14,12 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-#include "filter-interface.h"
+#ifndef _FUSE_CONVOLVER_FILE_HANDLER_H
+#define _FUSE_CONVOLVER_FILE_HANDLER_H
-class FileHandler : public filter_object_t {
+class FileHandler {
public:
// Returns bytes read or a negative value indicating a negative errno.
virtual int Read(char *buf, size_t size, off_t offset) = 0;
virtual int Stat(struct stat *st) = 0;
virtual ~FileHandler() {}
};
+
+#endif // _FUSE_CONVOLVER_FILE_HANDLER_H
View
@@ -1,55 +0,0 @@
-// -*- c++ -*-
-// Copyright (C) 2012 Henner Zeller <h.zeller@acm.org>
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-// Simple interface to hook the (pure C) fuse-convolve code into some
-// implementation of the filter (which we choose to do with C++).
-
-#ifndef _FUSE_CONVOLVER_FILTER_INTERFACE_H
-#define _FUSE_CONVOLVER_FILTER_INTERFACE_H
-#include <unistd.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-struct filter_object_t {};
-
-// Initialize convolver filters
-void initialize_convolver_filter(const char *zita_config);
-
-// Create a new filter given the open filedescriptor and the path. Returns
-// that filter in an opaque filter_object_t*
-struct filter_object_t *create_filter(const char *fs_path,
- const char *underlying_path);
-
-// Read from the given filter at the file-offset "offset, up to "size" bytes
-// into "buffer". Returns number of bytes read or a negative errno value.
-int read_from_filter(struct filter_object_t *filter,
- char *buffer, size_t size, off_t offset);
-
-// Return dynamic size of file.
-int fill_fstat_file(struct filter_object_t *filter, struct stat *st);
-int fill_stat_by_filename(const char *fs_path, struct stat *st);
-
-// At the end of the operation, close filter. Return 0 on success or negative
-// errno value on failure.
-int close_filter(const char *path, struct filter_object_t *filter);
-
-#ifdef __cplusplus
-} // extern "C"
-#endif /* __cplusplus */
-
-#endif // _FUSE_CONVOLVER_FILTER_INTERFACE_H
Oops, something went wrong.

0 comments on commit 8d1fbe7

Please sign in to comment.