Permalink
Browse files

o Make meta-refresh configurable.

  • Loading branch information...
1 parent 544bf28 commit a372a03dcbb6ecac1b670e950267c16278e618d6 @hzeller committed Sep 22, 2012
Showing with 29 additions and 11 deletions.
  1. +1 −0 README.md
  2. +12 −3 folve-main.cc
  3. +10 −6 status-server.cc
  4. +6 −2 status-server.h
View
1 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> : Port to run the HTTP status server on.
+ -r <refresh> : 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.
View
15 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> : Port to run the HTTP status server on.\n"
+ "\t-r <refresh> : 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),
View
16 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[] = "<html><head>"
+static const char kStartHtmlHeader[] = "<html><head>"
"<title>Folve</title>\n"
"<link rel='icon' type='image/png' "
"href='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2"
"AAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9wJDwUlEA/UBrsA"
"AABSSURBVCjPrZIxDgAgDAKh8f9froOTirU1ssKFYqS7Q4mktAxFRQDJcsPORMDYsDCXhn331"
- "9GPwHJVuaFl3l4D1+h0UjIdbTh9SpP2KQ2AgSfVAdEQGx23tOopAAAAAElFTkSuQmCC'/>\n"
- // TODO: make refresh configurable.
- "<meta http-equiv='refresh' content='1'>\n"
- "</head>\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_, "<meta http-equiv='refresh' content='%d'>\n",
+ meta_refresh_time_);
+ }
+ content_.append("</head>\n");
+
content_.append("<body style='font-family:Sans-Serif;'>\n");
Appendf(&content_, "<center style='background-color:#A0FFA0;'>"
"Welcome to "
View
8 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_;

0 comments on commit a372a03

Please sign in to comment.