Skip to content

Commit

Permalink
o Make meta-refresh configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
hzeller committed Sep 22, 2012
1 parent 544bf28 commit a372a03
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -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 can supply this option multiple times:
you'll get a drop-down select on the HTTP status page. you'll get a drop-down select on the HTTP status page.
-p <port> : Port to run the HTTP status server on. -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. -g : Gapless convolving alphabetically adjacent files.
-D : Moderate volume Folve debug messages to syslog. -D : Moderate volume Folve debug messages to syslog.
Can then also be toggled in the UI. Can then also be toggled in the UI.
Expand Down
15 changes: 12 additions & 3 deletions folve-main.cc
Expand Up @@ -35,10 +35,12 @@


// Compilation unit variables to communicate with the fuse callbacks. // Compilation unit variables to communicate with the fuse callbacks.
static struct FolveRuntime { 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; FolveFilesystem *fs;
const char *mount_point; const char *mount_point;
int status_port; int status_port;
int refresh_time;
} folve_rt; } folve_rt;


static char *concat_path(char *buf, const char *a, const char *b) { static char *concat_path(char *buf, const char *a, const char *b) {
Expand Down Expand Up @@ -155,8 +157,9 @@ static void *folve_init(struct fuse_conn_info *conn) {
// Need to start status server after we're daemonized. // Need to start status server after we're daemonized.
StatusServer *status_server = new StatusServer(folve_rt.fs); StatusServer *status_server = new StatusServer(folve_rt.fs);
if (status_server->Start(folve_rt.status_port)) { if (status_server->Start(folve_rt.status_port)) {
syslog(LOG_INFO, "HTTP status server on port %d", syslog(LOG_INFO, "HTTP status server on port %d; refresh=%d",
folve_rt.status_port); folve_rt.status_port, folve_rt.refresh_time);
status_server->set_meta_refresh(folve_rt.refresh_time);
} else { } else {
syslog(LOG_ERR, "Couldn't start HTTP server on port %d\n", syslog(LOG_ERR, "Couldn't start HTTP server on port %d\n",
folve_rt.status_port); folve_rt.status_port);
Expand Down Expand Up @@ -188,6 +191,7 @@ static int usage(const char *prg) {
"\t you'll get a drop-down select on the HTTP " "\t you'll get a drop-down select on the HTTP "
"status page.\n" "status page.\n"
"\t-p <port> : Port to run the HTTP status server on.\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-g : Gapless convolving alphabetically adjacent files.\n"
"\t-D : Moderate volume Folve debug messages to syslog.\n" "\t-D : Moderate volume Folve debug messages to syslog.\n"
"\t Can then also be toggled in the UI.\n" "\t Can then also be toggled in the UI.\n"
Expand All @@ -207,6 +211,7 @@ struct FolveConfig {


enum { enum {
FOLVE_OPT_PORT = 42, FOLVE_OPT_PORT = 42,
FOLVE_OPT_REFRESH_TIME,
FOLVE_OPT_CONFIG, FOLVE_OPT_CONFIG,
FOLVE_OPT_DEBUG, FOLVE_OPT_DEBUG,
FOLVE_OPT_GAPLESS, FOLVE_OPT_GAPLESS,
Expand All @@ -228,6 +233,9 @@ int FolveOptionHandling(void *data, const char *arg, int key,
case FOLVE_OPT_PORT: case FOLVE_OPT_PORT:
rt->status_port = atoi(arg + 2); // strip "-p" rt->status_port = atoi(arg + 2); // strip "-p"
return 0; return 0;
case FOLVE_OPT_REFRESH_TIME:
rt->refresh_time = atoi(arg + 2); // strip "-r"
return 0;
case FOLVE_OPT_CONFIG: case FOLVE_OPT_CONFIG:
rt->fs->add_config_dir(arg + 2); // strip "-c" rt->fs->add_config_dir(arg + 2); // strip "-c"
return 0; return 0;
Expand All @@ -252,6 +260,7 @@ int main(int argc, char *argv[]) {


static struct fuse_opt folve_options[] = { static struct fuse_opt folve_options[] = {
FUSE_OPT_KEY("-p ", FOLVE_OPT_PORT), 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("-c ", FOLVE_OPT_CONFIG),
FUSE_OPT_KEY("-D", FOLVE_OPT_DEBUG), FUSE_OPT_KEY("-D", FOLVE_OPT_DEBUG),
FUSE_OPT_KEY("-g", FOLVE_OPT_GAPLESS), FUSE_OPT_KEY("-g", FOLVE_OPT_GAPLESS),
Expand Down
16 changes: 10 additions & 6 deletions status-server.cc
Expand Up @@ -47,16 +47,13 @@ static const char kSettingsUrl[] = "/settings";
// Sneak in a favicon without another resource access. // Sneak in a favicon without another resource access.
// TODO: make a nice icon, recognizable as something that has to do with " // TODO: make a nice icon, recognizable as something that has to do with "
// files and music ... // files and music ...
static const char kHtmlHeader[] = "<html><head>" static const char kStartHtmlHeader[] = "<html><head>"
"<title>Folve</title>\n" "<title>Folve</title>\n"
"<link rel='icon' type='image/png' " "<link rel='icon' type='image/png' "
"href='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2" "href='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2"
"AAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9wJDwUlEA/UBrsA" "AAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9wJDwUlEA/UBrsA"
"AABSSURBVCjPrZIxDgAgDAKh8f9froOTirU1ssKFYqS7Q4mktAxFRQDJcsPORMDYsDCXhn331" "AABSSURBVCjPrZIxDgAgDAKh8f9froOTirU1ssKFYqS7Q4mktAxFRQDJcsPORMDYsDCXhn331"
"9GPwHJVuaFl3l4D1+h0UjIdbTh9SpP2KQ2AgSfVAdEQGx23tOopAAAAAElFTkSuQmCC'/>\n" "9GPwHJVuaFl3l4D1+h0UjIdbTh9SpP2KQ2AgSfVAdEQGx23tOopAAAAAElFTkSuQmCC'/>\n";
// TODO: make refresh configurable.
"<meta http-equiv='refresh' content='1'>\n"
"</head>\n";


// Callback function called by micro http daemon. Gets the StatusServer pointer // Callback function called by micro http daemon. Gets the StatusServer pointer
// in the user_argument. // in the user_argument.
Expand Down Expand Up @@ -97,6 +94,7 @@ int StatusServer::HandleHttp(void* user_argument,
StatusServer::StatusServer(FolveFilesystem *fs) StatusServer::StatusServer(FolveFilesystem *fs)
: expunged_retired_(0), total_seconds_filtered_(0), : expunged_retired_(0), total_seconds_filtered_(0),
total_seconds_music_seen_(0), total_seconds_music_seen_(0),
meta_refresh_time_(-1),
filesystem_(fs), daemon_(NULL), filter_switched_(false) { filesystem_(fs), daemon_(NULL), filter_switched_(false) {
fs->handler_cache()->SetObserver(this); fs->handler_cache()->SetObserver(this);
} }
Expand Down Expand Up @@ -287,7 +285,13 @@ const std::string &StatusServer::CreatePage() {
// a page. Since we run with MHD_USE_SELECT_INTERNALLY, this is only accessed // a page. Since we run with MHD_USE_SELECT_INTERNALLY, this is only accessed
// by one thread. // by one thread.
content_.clear(); 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"); content_.append("<body style='font-family:Sans-Serif;'>\n");
Appendf(&content_, "<center style='background-color:#A0FFA0;'>" Appendf(&content_, "<center style='background-color:#A0FFA0;'>"
"Welcome to " "Welcome to "
Expand Down
8 changes: 6 additions & 2 deletions status-server.h
Expand Up @@ -37,6 +37,9 @@ class StatusServer : protected FileHandlerCache::Observer {
// Start server, listing on given port. // Start server, listing on given port.
bool Start(int 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. // Shut down daemon.
virtual ~StatusServer(); virtual ~StatusServer();


Expand All @@ -52,8 +55,8 @@ class StatusServer : protected FileHandlerCache::Observer {
void PrepareConfigDirectoriesForUI(); void PrepareConfigDirectoriesForUI();


// Set filter or debug mode from http-request. Gracefully handles garbage. // Set filter or debug mode from http-request. Gracefully handles garbage.
void SetFilter(const char *filter); void SetFilter(const char *value);
void SetDebug(const char *filter); void SetDebug(const char *value);


// -- interface FileHandlerCache::Observer // -- interface FileHandlerCache::Observer
virtual void InsertHandlerEvent(FileHandler *handler) {} virtual void InsertHandlerEvent(FileHandler *handler) {}
Expand All @@ -69,6 +72,7 @@ class StatusServer : protected FileHandlerCache::Observer {


double total_seconds_filtered_; double total_seconds_filtered_;
double total_seconds_music_seen_; double total_seconds_music_seen_;
int meta_refresh_time_;
FolveFilesystem *filesystem_; FolveFilesystem *filesystem_;
struct MHD_Daemon *daemon_; struct MHD_Daemon *daemon_;
std::string content_; std::string content_;
Expand Down

0 comments on commit a372a03

Please sign in to comment.