Skip to content

Commit

Permalink
o Make debug mode switchable in UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
hzeller committed Sep 18, 2012
1 parent 062a435 commit 249865a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
5 changes: 4 additions & 1 deletion folve-filesystem.cc
Expand Up @@ -562,7 +562,10 @@ static bool IsDirectory(const std::string &path) {
}

void FolveFilesystem::SetDebugMode(bool b) {
global_debug = b;
if (b != global_debug) {
syslog(LOG_INFO, "Switch debug mode %s.", b ? "on" : "off");
global_debug = b;
}
}
bool FolveFilesystem::IsDebugMode() const { return global_debug; }

Expand Down
21 changes: 16 additions & 5 deletions status-server.cc
Expand Up @@ -39,7 +39,7 @@ static const size_t kMaxRetired = 200;
static const int kProgressWidth = 300;
static const char kActiveProgress[] = "#7070ff";
static const char kRetiredProgress[] = "#d0d0d0";
static const char kSetFilterUrl[] = "/set-filter";
static const char kSettingsUrl[] = "/settings";

// Aaah, I need to find the right Browser-Tab :)
// Sneak in a favicon without another resource access.
Expand All @@ -64,9 +64,11 @@ int StatusServer::HandleHttp(void* user_argument,
void**) {
StatusServer* server = (StatusServer*) user_argument;

if (strcmp(url, kSetFilterUrl) == 0) {
if (strcmp(url, kSettingsUrl) == 0) {
server->SetFilter(MHD_lookup_connection_value(connection,
MHD_GET_ARGUMENT_KIND, "f"));
server->SetDebug(MHD_lookup_connection_value(connection,
MHD_GET_ARGUMENT_KIND, "d"));
}

struct MHD_Response *response;
Expand Down Expand Up @@ -96,6 +98,10 @@ void StatusServer::SetFilter(const char *filter) {
filesystem_->SwitchCurrentConfigIndex(index);
}

void StatusServer::SetDebug(const char *dbg) {
filesystem_->SetDebugMode(dbg != NULL && *dbg == '1');
}

bool StatusServer::Start(int port) {
daemon_ = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, port, NULL, NULL,
&HandleHttp, this,
Expand Down Expand Up @@ -166,13 +172,13 @@ static void AppendFileInfo(std::string *result, const char *progress_style,

void StatusServer::AppendFilterOptions(std::string *result) {
Appendf(result, "<form action='%s'>"
"<label for='cfg_sel'>Config directory</label> ", kSetFilterUrl);
"<label for='cfg_sel'>Config directory</label> ", kSettingsUrl);
result->append("<select id='cfg_sel' name='f' "
"onchange='this.form.submit();'>\n");
for (size_t i = 0; i < filesystem_->config_dirs().size(); ++i) {
const std::string &c = filesystem_->config_dirs()[i];
Appendf(result, "<option value='%zd' %s>%s</option>\n",
i, ((int) i == filesystem_->current_cfg_index()) ? "selected" : "",
Appendf(result, "<option value='%zd'%s>%s</option>\n",
i, ((int) i == filesystem_->current_cfg_index()) ? " selected" : "",
(i == 0) ? "[No convolver - just pass through]" : c.c_str());
}
result->append("</select>");
Expand All @@ -183,6 +189,11 @@ void StatusServer::AppendFilterOptions(std::string *result) {
result->append(" <span style='font-size:small;'>Affects re- or newly opened "
"files.</span>");
}
Appendf(result, "<span style='float:right;font-size:small;'>"
"<label for='dbg_sel'>Folve debug to syslog</label>"
"<input id='dbg_sel' onchange='this.form.submit();' "
"type='checkbox' name='d' value='1'%s/></span>",
filesystem_->IsDebugMode() ? " checked" : "");
result->append("</form>");
}

Expand Down
3 changes: 2 additions & 1 deletion status-server.h
Expand Up @@ -50,8 +50,9 @@ class StatusServer : protected FileHandlerCache::Observer {

void AppendFilterOptions(std::string *result);

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

// -- interface FileHandlerCache::Observer
virtual void InsertHandlerEvent(FileHandler *handler) {}
Expand Down

0 comments on commit 249865a

Please sign in to comment.