Permalink
Browse files

o Make debug mode switchable in UI.

  • Loading branch information...
1 parent 062a435 commit 249865ac8f647cad0b561a78b0887621cbb24bd6 @hzeller committed Sep 18, 2012
Showing with 22 additions and 7 deletions.
  1. +4 −1 folve-filesystem.cc
  2. +16 −5 status-server.cc
  3. +2 −1 status-server.h
View
@@ -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; }
View
@@ -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.
@@ -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;
@@ -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,
@@ -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>");
@@ -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>");
}
View
@@ -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) {}

0 comments on commit 249865a

Please sign in to comment.