diff --git a/README.md b/README.md index a9fe719..a06dcac 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ The files are searched from the most specific to the least specific type. You can supply this option multiple times: you'll get a drop-down select on the HTTP status page. -p : Port to run the HTTP status server on. + -r : If > 0: seconds between refresh of status page. -g : Gapless convolving alphabetically adjacent files. -D : Moderate volume Folve debug messages to syslog. Can then also be toggled in the UI. diff --git a/folve-main.cc b/folve-main.cc index 1603a98..b565447 100644 --- a/folve-main.cc +++ b/folve-main.cc @@ -35,10 +35,12 @@ // Compilation unit variables to communicate with the fuse callbacks. static struct FolveRuntime { - FolveRuntime() : fs(NULL), mount_point(NULL), status_port(-1) {} + FolveRuntime() : fs(NULL), mount_point(NULL), + status_port(-1), refresh_time(-1) {} FolveFilesystem *fs; const char *mount_point; int status_port; + int refresh_time; } folve_rt; static char *concat_path(char *buf, const char *a, const char *b) { @@ -155,8 +157,9 @@ static void *folve_init(struct fuse_conn_info *conn) { // Need to start status server after we're daemonized. StatusServer *status_server = new StatusServer(folve_rt.fs); if (status_server->Start(folve_rt.status_port)) { - syslog(LOG_INFO, "HTTP status server on port %d", - folve_rt.status_port); + syslog(LOG_INFO, "HTTP status server on port %d; refresh=%d", + folve_rt.status_port, folve_rt.refresh_time); + status_server->set_meta_refresh(folve_rt.refresh_time); } else { syslog(LOG_ERR, "Couldn't start HTTP server on port %d\n", folve_rt.status_port); @@ -188,6 +191,7 @@ static int usage(const char *prg) { "\t you'll get a drop-down select on the HTTP " "status page.\n" "\t-p : Port to run the HTTP status server on.\n" + "\t-r : If > 0: seconds between refresh of status page.\n" "\t-g : Gapless convolving alphabetically adjacent files.\n" "\t-D : Moderate volume Folve debug messages to syslog.\n" "\t Can then also be toggled in the UI.\n" @@ -207,6 +211,7 @@ struct FolveConfig { enum { FOLVE_OPT_PORT = 42, + FOLVE_OPT_REFRESH_TIME, FOLVE_OPT_CONFIG, FOLVE_OPT_DEBUG, FOLVE_OPT_GAPLESS, @@ -228,6 +233,9 @@ int FolveOptionHandling(void *data, const char *arg, int key, case FOLVE_OPT_PORT: rt->status_port = atoi(arg + 2); // strip "-p" return 0; + case FOLVE_OPT_REFRESH_TIME: + rt->refresh_time = atoi(arg + 2); // strip "-r" + return 0; case FOLVE_OPT_CONFIG: rt->fs->add_config_dir(arg + 2); // strip "-c" return 0; @@ -252,6 +260,7 @@ int main(int argc, char *argv[]) { static struct fuse_opt folve_options[] = { FUSE_OPT_KEY("-p ", FOLVE_OPT_PORT), + FUSE_OPT_KEY("-r ", FOLVE_OPT_REFRESH_TIME), FUSE_OPT_KEY("-c ", FOLVE_OPT_CONFIG), FUSE_OPT_KEY("-D", FOLVE_OPT_DEBUG), FUSE_OPT_KEY("-g", FOLVE_OPT_GAPLESS), diff --git a/status-server.cc b/status-server.cc index a33fc33..510e3dd 100644 --- a/status-server.cc +++ b/status-server.cc @@ -47,16 +47,13 @@ static const char kSettingsUrl[] = "/settings"; // Sneak in a favicon without another resource access. // TODO: make a nice icon, recognizable as something that has to do with " // files and music ... -static const char kHtmlHeader[] = "" +static const char kStartHtmlHeader[] = "" "Folve\n" "\n" - // TODO: make refresh configurable. - "\n" - "\n"; + "9GPwHJVuaFl3l4D1+h0UjIdbTh9SpP2KQ2AgSfVAdEQGx23tOopAAAAAElFTkSuQmCC'/>\n"; // Callback function called by micro http daemon. Gets the StatusServer pointer // in the user_argument. @@ -97,6 +94,7 @@ int StatusServer::HandleHttp(void* user_argument, StatusServer::StatusServer(FolveFilesystem *fs) : expunged_retired_(0), total_seconds_filtered_(0), total_seconds_music_seen_(0), + meta_refresh_time_(-1), filesystem_(fs), daemon_(NULL), filter_switched_(false) { fs->handler_cache()->SetObserver(this); } @@ -287,7 +285,13 @@ const std::string &StatusServer::CreatePage() { // a page. Since we run with MHD_USE_SELECT_INTERNALLY, this is only accessed // by one thread. content_.clear(); - content_.append(kHtmlHeader); + content_.append(kStartHtmlHeader); + if (meta_refresh_time_ > 0) { + Appendf(&content_, "\n", + meta_refresh_time_); + } + content_.append("\n"); + content_.append("\n"); Appendf(&content_, "
" "Welcome to " diff --git a/status-server.h b/status-server.h index e83de9a..57f0462 100644 --- a/status-server.h +++ b/status-server.h @@ -37,6 +37,9 @@ class StatusServer : protected FileHandlerCache::Observer { // Start server, listing on given port. bool Start(int port); + // Set browser meta-refresh time. < 0 to disable. + void set_meta_refresh(int seconds) { meta_refresh_time_ = seconds; } + // Shut down daemon. virtual ~StatusServer(); @@ -52,8 +55,8 @@ class StatusServer : protected FileHandlerCache::Observer { void PrepareConfigDirectoriesForUI(); // Set filter or debug mode from http-request. Gracefully handles garbage. - void SetFilter(const char *filter); - void SetDebug(const char *filter); + void SetFilter(const char *value); + void SetDebug(const char *value); // -- interface FileHandlerCache::Observer virtual void InsertHandlerEvent(FileHandler *handler) {} @@ -69,6 +72,7 @@ class StatusServer : protected FileHandlerCache::Observer { double total_seconds_filtered_; double total_seconds_music_seen_; + int meta_refresh_time_; FolveFilesystem *filesystem_; struct MHD_Daemon *daemon_; std::string content_;