Skip to content

Commit

Permalink
o Use fuse option handling to extract our flags and options.
Browse files Browse the repository at this point in the history
  • Loading branch information
hzeller committed Sep 17, 2012
1 parent db66f7d commit 27c44cd
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 28 deletions.
21 changes: 13 additions & 8 deletions README
Expand Up @@ -68,18 +68,19 @@ Microhttpd webserver library http://www.gnu.org/software/libmicrohttpd/
configurations, the second the directory to the original flac files. The configurations, the second the directory to the original flac files. The
third is the mount-point, where the convolved flac files will show up: third is the mount-point, where the convolved flac files will show up:


./folve /directory/with/filters /path/to/original/files /mnt/mountpoint -f ./folve -c /filter/dir -f -p 17322 /path/to/original/files /mnt/mountpoint


Parameters: Parameters:
1) The /directory/with/filters needs to be a directory that has 1) The flag '-c' with parameter /filter/dir needs to be a
directory that has
jconvolver filter-configuration files with the following naming scheme: jconvolver filter-configuration files with the following naming scheme:


filter-<samplerate>-<bits>-<channels>.conf filter-<samplerate>-<bits>-<channels>.conf


So if you have flac files with 44.1khz, 16 bits and 2 channel stero, So if you have flac files with 44.1khz, 16 bits and 2 channel stero,
you need a filter configuration named: you need a filter configuration named:


/directory/with/filters/filter-44100-16-2.conf /filter/dir/filter-44100-16-2.conf


(See README.CONFIG in the jconfolver project how these look like) (See README.CONFIG in the jconfolver project how these look like)


Expand All @@ -89,9 +90,12 @@ Parameters:


3) The mount point. 3) The mount point.


There are couple of options. Available flags:
The '-f' option lets it run in foreground (useful, since right now this -f : Operate in foreground; mostly useful for debugging.
spits out some debugging information). -d : Detailed debug log of fuse accesses
-p <port> : port to run an HTTP status server on
-c <cfg-dir> : Configuration directory.
-o <fuse-mount-option> : other generic parameters passed to fuse.


Now you can access the fileystem under that mount point, e.g. Now you can access the fileystem under that mount point, e.g.
mplayer /mnt/mountpoint/foo.flac mplayer /mnt/mountpoint/foo.flac
Expand All @@ -100,7 +104,8 @@ The fuse-convolve filesystem will determine the samplerate/bits/channels and
attempt to find the right filter in the filter directory. If there is a filter, attempt to find the right filter in the filter directory. If there is a filter,
the output is filtered on-the-fly, otherwise the original file is returned. the output is filtered on-the-fly, otherwise the original file is returned.


To watch what is happening: there is a http status server running on
fixed port 17322 (TODO: port not a flag yet)


If you gave folve the flag -p with an status port, it will serve current
status information on a http server; e.g. With ./folve ... -p 17322 have a look
on
http://localhost:17322/ http://localhost:17322/
1 change: 1 addition & 0 deletions folve-filesystem.h
Expand Up @@ -44,6 +44,7 @@ class FolveFilesystem {


const char *version() const { return version_info_; } const char *version() const { return version_info_; }
const char *underlying_dir() const { return underlying_dir_; } const char *underlying_dir() const { return underlying_dir_; }
const char *config_dir() const { return zita_config_dir_.c_str(); }
FileHandlerCache *handler_cache() { return &open_file_cache_; } FileHandlerCache *handler_cache() { return &open_file_cache_; }


// Some stats. // Some stats.
Expand Down
81 changes: 61 additions & 20 deletions folve-main.cc
Expand Up @@ -37,9 +37,10 @@
#endif #endif


// Compilation unit variables to communicate with the fuse callbacks. // Compilation unit variables to communicate with the fuse callbacks.
static struct FolveParams { static struct FolveRuntime {
FolveParams() : fs(NULL), status_port(-1) {} FolveRuntime() : fs(NULL), status_port(-1) {}
FolveFilesystem *fs; FolveFilesystem *fs;
const char *mount_point;
int status_port; int status_port;
} folve; } folve;


Expand Down Expand Up @@ -169,9 +170,10 @@ static void *folve_init(struct fuse_conn_info *conn) {
// If we're running in the foreground, we like to be seen on stderr as well. // If we're running in the foreground, we like to be seen on stderr as well.
const int ident_len = 20; const int ident_len = 20;
char *ident = (char*) malloc(ident_len); // openlog() keeps reference. Leaks. char *ident = (char*) malloc(ident_len); // openlog() keeps reference. Leaks.
snprintf(ident, ident_len, "[folve:%d]", getpid()); snprintf(ident, ident_len, "folve[%d]", getpid());
openlog(ident, LOG_CONS|LOG_PERROR, LOG_USER); openlog(ident, LOG_CONS|LOG_PERROR, LOG_USER);
syslog(LOG_INFO, "Started. Serving %s", folve.fs->underlying_dir()); syslog(LOG_INFO, "Started. Serving %s on mount point %s",
folve.fs->underlying_dir(), folve.mount_point);


if (folve.status_port > 0) { if (folve.status_port > 0) {
// Need to start status server after we're daemonized. // Need to start status server after we're daemonized.
Expand All @@ -197,37 +199,77 @@ static int usage(const char *prg) {
} }


static bool IsDirectory(const char *path) { static bool IsDirectory(const char *path) {
if (path == NULL)
return false;
struct stat st; struct stat st;
if (stat(path, &st) != 0) if (stat(path, &st) != 0)
return false; return false;
return (st.st_mode & S_IFMT) == S_IFDIR; return (st.st_mode & S_IFMT) == S_IFDIR;
} }


struct FolveConfig {
FolveConfig() : base_dir(NULL), config_dir(NULL), port(-1) {}
const char *base_dir;
const char *mount_point;
const char *config_dir;
int port;
};

enum {
FOLVE_OPT_PORT = 42,
FOLVE_OPT_CONFIG,
};

int FolveOptionHandling(void *data, const char *arg, int key,
struct fuse_args *outargs) {
FolveConfig *cfg = (FolveConfig*) data;
switch (key) {
case FUSE_OPT_KEY_NONOPT:
// First non-opt: our base mounting dir.
if (cfg->base_dir == NULL) {
cfg->base_dir = strdup(arg);
return 0;
} else {
cfg->mount_point = strdup(arg); // remmber as FYI
return 1; // Leave it to fuse
}
case FOLVE_OPT_PORT:
cfg->port = atoi(arg + 2); // strip "-p"
return 0;
case FOLVE_OPT_CONFIG:
cfg->config_dir = strdup(arg + 2); // strip "-c"
return 0;
}
return 1;
}

int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
const char *progname = argv[0]; const char *progname = argv[0];
if (argc < 4) { if (argc < 4) {
return usage(progname); return usage(progname);
} }


// First, let's extract our own configuration, redact them from argv[] and FolveConfig cfg;
// then pass everything on to fuse-main. static struct fuse_opt folve_options[] = {
const char *config_dir = argv[1]; FUSE_OPT_KEY("-p ", FOLVE_OPT_PORT),
const char *underlying_dir = argv[2]; FUSE_OPT_KEY("-c ", FOLVE_OPT_CONFIG),
argc -=2; FUSE_OPT_END
argv += 2; };
if (!IsDirectory(config_dir)) { struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
fprintf(stderr, "%s <config-dir>: not a directory.\n", config_dir); fuse_opt_parse(&args, &cfg, folve_options, FolveOptionHandling);

if (!IsDirectory(cfg.config_dir)) {
fprintf(stderr, "<config-dir>: %s not a directory.\n", cfg.config_dir);
return usage(progname); return usage(progname);
} }
if (!IsDirectory(underlying_dir)) { if (!IsDirectory(cfg.base_dir)) {
fprintf(stderr, "%s <underlying-dir>: not a directory.\n", underlying_dir); fprintf(stderr, "<underlying-dir>: %s not a directory.\n", cfg.base_dir);
return usage(progname); return usage(progname);
} }


folve.fs = new FolveFilesystem(FOLVE_VERSION, underlying_dir, config_dir); folve.fs = new FolveFilesystem(FOLVE_VERSION, cfg.base_dir, cfg.config_dir);

folve.status_port = cfg.port;
// TODO(hzeller): make this configurable folve.mount_point = cfg.mount_point;
folve.status_port = 17322;


struct fuse_operations folve_operations; struct fuse_operations folve_operations;
memset(&folve_operations, 0, sizeof(folve_operations)); memset(&folve_operations, 0, sizeof(folve_operations));
Expand All @@ -249,6 +291,5 @@ int main(int argc, char *argv[]) {
folve_operations.fgetattr = folve_fgetattr; folve_operations.fgetattr = folve_fgetattr;
folve_operations.getattr = folve_getattr; folve_operations.getattr = folve_getattr;


// Lazy: let the rest handle by fuse provided main. return fuse_main(args.argc, args.argv, &folve_operations, NULL);
return fuse_main(argc, argv, &folve_operations, NULL);
} }
3 changes: 3 additions & 0 deletions status-server.cc
Expand Up @@ -171,6 +171,9 @@ const std::string &StatusServer::CreatePage() {
"Convolving audio files from <code>%s</code><br/>\n", "Convolving audio files from <code>%s</code><br/>\n",
filesystem_->version(), filesystem_->underlying_dir()); filesystem_->version(), filesystem_->underlying_dir());


Appendf(&current_page_, "Config directory <code>%s</code><br/>",
filesystem_->config_dir());

std::vector<HandlerStats> stat_list; std::vector<HandlerStats> stat_list;
filesystem_->handler_cache()->GetStats(&stat_list); filesystem_->handler_cache()->GetStats(&stat_list);


Expand Down

0 comments on commit 27c44cd

Please sign in to comment.