Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 415 lines (378 sloc) 16.221 kb
4d4d90b @hzeller o More legalese
authored
1 // Folve - A fuse filesystem that convolves audio files on-the-fly.
2 //
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
3 // Copyright (C) 2012 Henner Zeller <h.zeller@acm.org>
1bce634 @hzeller o Remove some trailing whitespaces
authored
4 //
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 #include <arpa/inet.h>
19 #include <fcntl.h>
036c6e1 @hzeller o not wide cellspacing needed anymore.
authored
20 #include <math.h>
b5c1e96 @hzeller o more useful output on status server.
authored
21 #include <stdio.h>
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
22 #include <stdlib.h>
1bce634 @hzeller o Remove some trailing whitespaces
authored
23 #include <string.h>
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
24 #include <sys/select.h>
25 #include <sys/socket.h>
26 #include <sys/time.h>
27 #include <sys/types.h>
28
1bce634 @hzeller o Remove some trailing whitespaces
authored
29 // Microhttpd's headers (at least v0.4.4) are broken and don't include stdarg.h
30 #include <stdarg.h>
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
31 #include <microhttpd.h>
32
1e9ff21 @hzeller o main: report if parameters are not directories.
authored
33 #include <boost/thread/locks.hpp>
34
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
35 #include "folve-filesystem.h"
c1a03f2 @hzeller o Needed convenient sub-second resolution time. Added CurrentTime()
authored
36 #include "status-server.h"
37 #include "util.h"
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
38
8268c37 @hzeller o Bubble up error messages in status server.
authored
39 using folve::Appendf;
40
f1ef960 @hzeller o a bit HTML polishing.
authored
41 static const size_t kMaxRetired = 20;
b698853 @hzeller o README updates.
authored
42 static const int kProgressWidth = 300;
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
43 static const char kActiveProgress[] = "#7070ff";
44 static const char kRetiredProgress[] = "#d0d0d0";
249865a @hzeller o Make debug mode switchable in UI.
authored
45 static const char kSettingsUrl[] = "/settings";
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
46
78e66dd @hzeller o I need to find my browser-tab :) Add favicon.
authored
47 // Aaah, I need to find the right Browser-Tab :)
48 // Sneak in a favicon without another resource access.
49 // TODO: make a nice icon, recognizable as something that has to do with "
50 // files and music ...
a372a03 @hzeller o Make meta-refresh configurable.
authored
51 static const char kStartHtmlHeader[] = "<html><head>"
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
52 "<title>Folve</title>\n"
e619ff2 @hzeller o Redirect to / after settings. That way, a reload won't change any
authored
53 "<link rel='icon' type='image/png' "
78e66dd @hzeller o I need to find my browser-tab :) Add favicon.
authored
54 "href='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2"
55 "AAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9wJDwUlEA/UBrsA"
56 "AABSSURBVCjPrZIxDgAgDAKh8f9froOTirU1ssKFYqS7Q4mktAxFRQDJcsPORMDYsDCXhn331"
a372a03 @hzeller o Make meta-refresh configurable.
authored
57 "9GPwHJVuaFl3l4D1+h0UjIdbTh9SpP2KQ2AgSfVAdEQGx23tOopAAAAAElFTkSuQmCC'/>\n";
78e66dd @hzeller o I need to find my browser-tab :) Add favicon.
authored
58
adde81e @hzeller o some link prettify.
authored
59 // TODO: someone with a bit more stylesheet-fu can attempt to make this
60 // more pretty and the HTML more compact.
61 // First step: extract all css used below in style='xx' here. here.
62 // Also, maybe move to external file, makes editing much faster, then compile
63 // that into a C-string that we can include it in the binary.
64 #define SELECT_COLOR "#a0a0ff"
65 #define PRE_SELECT_COLOR "#e0e0ff"
537e34b @hzeller o cleanup UI: no radio buttons anymore, just simple links.
authored
66 static const char kCSS[] =
adde81e @hzeller o some link prettify.
authored
67 "<style type='text/css'>"
68 " a:link { text-decoration:none; }\n"
69 " a:visited { text-decoration:none; }\n"
70 " a:hover { text-decoration:underline; }\n"
71 " a:active { text-decoration:underline; }\n"
23dc276 @hzeller o make switch-message ('affects new files') more prominent.
authored
72 " .rounded_box, .filter_sel {\n"
73 " padding: 5px 15px;\n"
74 " border-radius: 5px;\n"
75 " -moz-border-radius: 5px; }\n"
76 " .filter_sel { font-weight:bold; }\n"
adde81e @hzeller o some link prettify.
authored
77 " .active { background-color:" SELECT_COLOR "; }\n"
78 " .inactive { background-color:#e0e0e0; }\n"
79 " .inactive:hover { background-color:" PRE_SELECT_COLOR ";\n"
80 " color: #000000;\n"
81 " text-decoration:none;}\n"
82 " .inactive:link { color: #000000;text-decoration:none;}\n"
83 " .inactive:visited { color: #000000;text-decoration:none;}\n"
537e34b @hzeller o cleanup UI: no radio buttons anymore, just simple links.
authored
84 "</style>";
85
b698853 @hzeller o README updates.
authored
86 // Callback function called by micro http daemon. Gets the StatusServer pointer
87 // in the user_argument.
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
88 int StatusServer::HandleHttp(void* user_argument,
89 struct MHD_Connection *connection,
90 const char *url, const char *method,
91 const char *version,
92 const char *upload_data, size_t *upload_size,
93 void**) {
94 StatusServer* server = (StatusServer*) user_argument;
e619ff2 @hzeller o Redirect to / after settings. That way, a reload won't change any
authored
95 struct MHD_Response *response;
96 int ret;
97
249865a @hzeller o Make debug mode switchable in UI.
authored
98 if (strcmp(url, kSettingsUrl) == 0) {
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
99 server->SetFilter(MHD_lookup_connection_value(connection,
100 MHD_GET_ARGUMENT_KIND, "f"));
249865a @hzeller o Make debug mode switchable in UI.
authored
101 server->SetDebug(MHD_lookup_connection_value(connection,
102 MHD_GET_ARGUMENT_KIND, "d"));
e619ff2 @hzeller o Redirect to / after settings. That way, a reload won't change any
authored
103 // We redirect to slash after this, to remove parameters from the GET-URL
104 response = MHD_create_response_from_data(0, (void*)"", MHD_NO, MHD_NO);
105 MHD_add_response_header(response, "Location", "/");
1bce634 @hzeller o Remove some trailing whitespaces
authored
106 ret = MHD_queue_response(connection, 302, response);
e619ff2 @hzeller o Redirect to / after settings. That way, a reload won't change any
authored
107 } else {
108 const std::string &page = server->CreatePage();
109 response = MHD_create_response_from_data(page.length(), (void*) page.data(),
110 MHD_NO, MHD_NO);
111 MHD_add_response_header(response, "Content-Type",
112 "text/html; charset=utf-8");
113 ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
114 }
e619ff2 @hzeller o Redirect to / after settings. That way, a reload won't change any
authored
115 // Tell aggressive cachers not to do so.
116 MHD_add_response_header(response, "Cache-Control", "no-cache");
117 MHD_add_response_header(response, "Expires", "24 Nov 1972 23:42:42 GMT");
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
118 MHD_destroy_response(response);
119 return ret;
120 }
121
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
122 StatusServer::StatusServer(FolveFilesystem *fs)
1e9ff21 @hzeller o main: report if parameters are not directories.
authored
123 : expunged_retired_(0), total_seconds_filtered_(0),
124 total_seconds_music_seen_(0),
a372a03 @hzeller o Make meta-refresh configurable.
authored
125 meta_refresh_time_(-1),
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
126 filesystem_(fs), daemon_(NULL), filter_switched_(false) {
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
127 fs->handler_cache()->SetObserver(this);
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
128 }
129
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
130 void StatusServer::SetFilter(const char *filter) {
131 if (filter == NULL || *filter == '\0') return;
132 char *end;
133 int index = strtol(filter, &end, 10);
134 if (end == NULL || *end != '\0') return;
135 filter_switched_ = (index != filesystem_->current_cfg_index());
136 filesystem_->SwitchCurrentConfigIndex(index);
137 }
138
249865a @hzeller o Make debug mode switchable in UI.
authored
139 void StatusServer::SetDebug(const char *dbg) {
8c7e5c1 @hzeller o Only if -D is given, the debug toggle is active in the UI.
authored
140 if (!filesystem_->is_debug_ui_enabled()) return;
7689c9a @hzeller o preparation to extract classes from folve-filesystem into their
authored
141 folve::EnableDebugLog(dbg != NULL && *dbg == '1');
249865a @hzeller o Make debug mode switchable in UI.
authored
142 }
143
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
144 bool StatusServer::Start(int port) {
118a454 @hzeller o Show the filter used for a particular format.
authored
145 PrepareConfigDirectoriesForUI();
1bce634 @hzeller o Remove some trailing whitespaces
authored
146 daemon_ = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, port, NULL, NULL,
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
147 &HandleHttp, this,
148 MHD_OPTION_END);
149 return daemon_ != NULL;
150 }
151
152 StatusServer::~StatusServer() {
b698853 @hzeller o README updates.
authored
153 if (daemon_) MHD_stop_daemon(daemon_);
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
154 }
155
20e139c @hzeller o Less cluttered output in UI if -D is not set.
authored
156 bool StatusServer::show_details() {
157 // Right now, we just make this dependent on debug output. Could be a separate
158 // option.
159 return folve::IsDebugLogEnabled();
160 }
161
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
162 // FileHandlerCache::Observer interface.
163 void StatusServer::RetireHandlerEvent(FileHandler *handler) {
164 HandlerStats stats;
165 handler->GetHandlerStatus(&stats); // Get last available stats.
166 if (stats.progress >= 0) {
8268c37 @hzeller o Bubble up error messages in status server.
authored
167 total_seconds_music_seen_ += stats.duration_seconds;
168 total_seconds_filtered_ += stats.duration_seconds * stats.progress;
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
169 }
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
170 stats.last_access = folve::CurrentTime();
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
171 stats.status = HandlerStats::RETIRED;
1e9ff21 @hzeller o main: report if parameters are not directories.
authored
172 boost::lock_guard<boost::mutex> l(retired_mutex_);
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
173 retired_.push_front(stats);
1e9ff21 @hzeller o main: report if parameters are not directories.
authored
174 while (retired_.size() > kMaxRetired) {
175 ++expunged_retired_;
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
176 retired_.pop_back();
1e9ff21 @hzeller o main: report if parameters are not directories.
authored
177 }
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
178 }
1bce634 @hzeller o Remove some trailing whitespaces
authored
179
f1ef960 @hzeller o a bit HTML polishing.
authored
180 // As ugly #defines, so that gcc can warn about printf() format problems.
181 #define sMessageRowHtml \
08bbf28 @hzeller o First shot at gapless. Works pretty well for my test-case.
authored
182 "<td>%s</td><td colspan='3' style='font-size:small;'>%s</td>"
b5c1e96 @hzeller o more useful output on status server.
authored
183
f1ef960 @hzeller o a bit HTML polishing.
authored
184 #define sProgressRowHtml \
185 "<td>%s</td>" \
186 "<td>%s</td>" \
187 "<td><div style='background:white;width:%dpx;border:1px solid black;'>\n" \
b9ae86d @hzeller o Higher than percent resolution progress bar.
authored
188 " <div style='width:%dpx;background:%s;'>&nbsp;</div>\n</div></td>" \
08bbf28 @hzeller o First shot at gapless. Works pretty well for my test-case.
authored
189 "<td>%s</td>"
f1ef960 @hzeller o a bit HTML polishing.
authored
190
191 #define sTimeColumns \
192 "<td align='right'>%2d:%02d</td><td>/</td><td align='right'>%2d:%02d</td>"
193 #define sDecibelColumn \
194 "<td align='right' style='background:%s;'>%.1f dB</td>"
b5c1e96 @hzeller o more useful output on status server.
authored
195
118a454 @hzeller o Show the filter used for a particular format.
authored
196 void StatusServer::AppendFileInfo(const char *progress_style,
197 const HandlerStats &stats) {
198 content_.append("<tr style='text-wrap:none;white-space:nowrap;'>");
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
199 const char *status = "";
200 switch (stats.status) {
201 case HandlerStats::OPEN: status = "open"; break;
202 case HandlerStats::IDLE: status = "idle"; break;
bcb77e7 @hzeller o Ran with Amarok over my files. Looks like it sometimes only 'almost'
authored
203 case HandlerStats::RETIRED: status = "&nbsp;----&nbsp;"; break;
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
204 // no default to let the compiler detect new values.
205 }
f1ef960 @hzeller o a bit HTML polishing.
authored
206
8268c37 @hzeller o Bubble up error messages in status server.
authored
207 if (!stats.message.empty()) {
118a454 @hzeller o Show the filter used for a particular format.
authored
208 Appendf(&content_, sMessageRowHtml, status, stats.message.c_str());
8268c37 @hzeller o Bubble up error messages in status server.
authored
209 } else if (stats.progress == 0) {
118a454 @hzeller o Show the filter used for a particular format.
authored
210 Appendf(&content_, sMessageRowHtml, status, "Only header accessed");
b5c1e96 @hzeller o more useful output on status server.
authored
211 } else {
118a454 @hzeller o Show the filter used for a particular format.
authored
212 Appendf(&content_, sProgressRowHtml, status,
08bbf28 @hzeller o First shot at gapless. Works pretty well for my test-case.
authored
213 stats.in_gapless ? "&rarr;" : "",
b9ae86d @hzeller o Higher than percent resolution progress bar.
authored
214 kProgressWidth, (int) (kProgressWidth * stats.progress),
215 progress_style,
f1ef960 @hzeller o a bit HTML polishing.
authored
216 stats.out_gapless ? "&rarr;" : "");
217 }
218 const int secs = stats.duration_seconds;
219 const int fract_sec = stats.progress * secs;
6d4f28b @hzeller o if there is a time, show it.
authored
220 if (secs >= 0 && fract_sec >= 0) {
1bce634 @hzeller o Remove some trailing whitespaces
authored
221 Appendf(&content_, sTimeColumns,
f1ef960 @hzeller o a bit HTML polishing.
authored
222 fract_sec / 60, fract_sec % 60,
223 secs / 60, secs % 60);
224 } else {
118a454 @hzeller o Show the filter used for a particular format.
authored
225 content_.append("<td colspan='3'>-</td>");
b5c1e96 @hzeller o more useful output on status server.
authored
226 }
f00e6a4 @hzeller o Don't do unprotected read on status information such as
authored
227
036c6e1 @hzeller o not wide cellspacing needed anymore.
authored
228 if (stats.max_output_value > 1e-6) {
118a454 @hzeller o Show the filter used for a particular format.
authored
229 Appendf(&content_, sDecibelColumn,
f1ef960 @hzeller o a bit HTML polishing.
authored
230 stats.max_output_value > 1.0 ? "#FF0505" : "white",
7b499ea @hzeller o Uh, log() is actually ln() and log10f() is log() :)
authored
231 20 * log10f(stats.max_output_value));
f1ef960 @hzeller o a bit HTML polishing.
authored
232 } else {
118a454 @hzeller o Show the filter used for a particular format.
authored
233 content_.append("<td>-</td>");
f1ef960 @hzeller o a bit HTML polishing.
authored
234 }
235
118a454 @hzeller o Show the filter used for a particular format.
authored
236 Appendf(&content_, "<td bgcolor='#c0c0c0'>&nbsp;%s (%s)&nbsp;</td>",
237 stats.format.c_str(), ui_config_directories_[stats.filter_id].c_str());
238 Appendf(&content_,"<td "
bea11d6 @hzeller o Don't use snprintf, but use a new function Appendf() to assemble
authored
239 "style='font-size:small;text-wrap:none;white-space:nowrap'>%s</td>",
240 stats.filename.c_str());
118a454 @hzeller o Show the filter used for a particular format.
authored
241 content_.append("</tr>\n");
b5c1e96 @hzeller o more useful output on status server.
authored
242 }
243
d280fce @hzeller o Reload page with a meta-refresn.
authored
244 void StatusServer::PrepareConfigDirectoriesForUI() {
245 // Essentially only keep the directory name.
246 if (!ui_config_directories_.empty()) return;
118a454 @hzeller o Show the filter used for a particular format.
authored
247 ui_config_directories_.push_back("None : Pass Through");
d280fce @hzeller o Reload page with a meta-refresn.
authored
248 for (size_t i = 1; i < filesystem_->config_dirs().size(); ++i) {
249 std::string d = filesystem_->config_dirs()[i];
250 while (d.length() > 0 && d[d.length() - 1] == '/') {
251 d.resize(d.length() - 1); // trim trailing slashes.
252 }
253 const std::string::size_type slash_pos = d.find_last_of('/');
254 if (slash_pos != std::string::npos) {
255 d = d.substr(slash_pos + 1);
256 }
257 ui_config_directories_.push_back(d);
258 }
259 }
260
261 static void CreateSelection(std::string *result,
3dc037e @hzeller o Provide tooltip to full path of filter.
authored
262 const std::vector<std::string> &option_titles,
d280fce @hzeller o Reload page with a meta-refresn.
authored
263 const std::vector<std::string> &options,
264 int selected) {
265 if (options.size() == 1) {
266 result->append(options[0]); // no reason to make this a form :)
267 return;
268 }
269 for (size_t i = 0; i < options.size(); ++i) {
270 const std::string &c = options[i];
adde81e @hzeller o some link prettify.
authored
271 result->append("&nbsp;");
d280fce @hzeller o Reload page with a meta-refresn.
authored
272 const bool active = (int) i == selected;
537e34b @hzeller o cleanup UI: no radio buttons anymore, just simple links.
authored
273 if (active) {
3dc037e @hzeller o Provide tooltip to full path of filter.
authored
274 Appendf(result, "<span title='%s' class='filter_sel active'>%s</span>\n",
20e139c @hzeller o Less cluttered output in UI if -D is not set.
authored
275 (option_titles.size() > i) ? option_titles[i].c_str() : "",
276 c.c_str());
537e34b @hzeller o cleanup UI: no radio buttons anymore, just simple links.
authored
277 } else {
3dc037e @hzeller o Provide tooltip to full path of filter.
authored
278 Appendf(result, "<a title='%s' class='filter_sel inactive' "
279 "href='%s?f=%zd'>%s</a>\n",
20e139c @hzeller o Less cluttered output in UI if -D is not set.
authored
280 (option_titles.size() > i) ? option_titles[i].c_str() : "",
281 kSettingsUrl, i, c.c_str());
537e34b @hzeller o cleanup UI: no radio buttons anymore, just simple links.
authored
282 }
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
283 }
d280fce @hzeller o Reload page with a meta-refresn.
authored
284 }
285
286 void StatusServer::AppendSettingsForm() {
a390745 @hzeller o rename 'config directory' to 'active filter' in the UI. Easier
authored
287 content_.append("<p>Active filter: ");
20e139c @hzeller o Less cluttered output in UI if -D is not set.
authored
288 CreateSelection(&content_,
289 show_details()
290 ? filesystem_->config_dirs()
291 : std::vector<std::string>(),
292 ui_config_directories_,
d280fce @hzeller o Reload page with a meta-refresn.
authored
293 filesystem_->current_cfg_index());
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
294 if (filesystem_->config_dirs().size() == 1) {
d280fce @hzeller o Reload page with a meta-refresn.
authored
295 content_.append(" (This is a boring configuration, add filter directories "
537e34b @hzeller o cleanup UI: no radio buttons anymore, just simple links.
authored
296 "with -c &lt;dir&gt; [-c &lt;another-dir&gt; ...] :-) )");
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
297 } else if (filter_switched_) {
23dc276 @hzeller o make switch-message ('affects new files') more prominent.
authored
298 content_.append("&nbsp;<span class='rounded_box' "
299 "style='font-size:small;background:#FFFFa0;'>"
d280fce @hzeller o Reload page with a meta-refresn.
authored
300 " (Affects re- or newly opened files.) </span>");
e619ff2 @hzeller o Redirect to / after settings. That way, a reload won't change any
authored
301 filter_switched_ = false; // only show once.
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
302 }
537e34b @hzeller o cleanup UI: no radio buttons anymore, just simple links.
authored
303 // TODO: re-add something for filesystem_->is_debug_ui_enabled()
adde81e @hzeller o some link prettify.
authored
304 content_.append("</p><hr/>");
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
305 }
306
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
307 struct CompareStats {
308 bool operator() (const HandlerStats &a, const HandlerStats &b) {
309 if (a.status < b.status) return true; // open before idle.
310 else if (a.status > b.status) return false;
311 return b.last_access < a.last_access; // reverse time.
312 }
313 };
314
1e9ff21 @hzeller o main: report if parameters are not directories.
authored
315 const std::string &StatusServer::CreatePage() {
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
316 const double start = folve::CurrentTime();
b698853 @hzeller o README updates.
authored
317 // We re-use a string to avoid re-allocing memory every time we generate
318 // a page. Since we run with MHD_USE_SELECT_INTERNALLY, this is only accessed
319 // by one thread.
7d695c6 @hzeller o Rename current_page_ to content_ to be more generic.
authored
320 content_.clear();
a372a03 @hzeller o Make meta-refresh configurable.
authored
321 content_.append(kStartHtmlHeader);
322 if (meta_refresh_time_ > 0) {
323 Appendf(&content_, "<meta http-equiv='refresh' content='%d'>\n",
324 meta_refresh_time_);
325 }
537e34b @hzeller o cleanup UI: no radio buttons anymore, just simple links.
authored
326 content_.append(kCSS);
a372a03 @hzeller o Make meta-refresh configurable.
authored
327 content_.append("</head>\n");
328
7d695c6 @hzeller o Rename current_page_ to content_ to be more generic.
authored
329 content_.append("<body style='font-family:Sans-Serif;'>\n");
330 Appendf(&content_, "<center style='background-color:#A0FFA0;'>"
53130a3 @hzeller o link to github page
authored
331 "Welcome to "
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
332 "<a href='https://github.com/hzeller/folve#readme'>Folve</a> "
20e139c @hzeller o Less cluttered output in UI if -D is not set.
authored
333 FOLVE_VERSION "</center>\n");
334 if (show_details()) {
335 Appendf(&content_, "Convolving audio files from <code>%s</code>\n",
336 filesystem_->underlying_dir().c_str());
337 }
d280fce @hzeller o Reload page with a meta-refresn.
authored
338 AppendSettingsForm();
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored
339
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
340 std::vector<HandlerStats> stat_list;
341 filesystem_->handler_cache()->GetStats(&stat_list);
342
562b493 @hzeller o Print out config file name while spotting a problem
authored
343 // Get statistics of active files to add to the existing ones.
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
344 double active_music_seen = 0.0;
345 double active_filtered = 0.0;
346 for (size_t i = 0; i < stat_list.size(); ++i) {
347 const HandlerStats &stats = stat_list[i];
348 if (stats.progress >= 0) {
8268c37 @hzeller o Bubble up error messages in status server.
authored
349 active_music_seen += stats.duration_seconds;
350 active_filtered += stats.duration_seconds * stats.progress;
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
351 }
352 }
20e139c @hzeller o Less cluttered output in UI if -D is not set.
authored
353 if (show_details()) {
1bce634 @hzeller o Remove some trailing whitespaces
authored
354 const int t_seen = total_seconds_music_seen_ + active_music_seen;
355 const int t_filtered = total_seconds_filtered_ + active_filtered;
356 Appendf(&content_, "Total opening files <b>%d</b> "
357 ".. and re-opened from recency cache <b>%d</b><br/>",
358 filesystem_->total_file_openings(),
359 filesystem_->total_file_reopen());
360 Appendf(&content_, "Total music seen <b>%dd %d:%02d:%02d</b> ",
361 t_seen / 86400, (t_seen % 86400) / 3600,
362 (t_seen % 3600) / 60, t_seen % 60);
363 Appendf(&content_, ".. and convolved <b>%dd %d:%02d:%02d</b> ",
364 t_filtered / 86400, (t_filtered % 86400) / 3600,
365 (t_filtered % 3600) / 60, t_filtered % 60);
366 Appendf(&content_, "(%.1f%%)<br/>",
367 (t_seen == 0) ? 0.0 : (100.0 * t_filtered / t_seen));
368 }
bea11d6 @hzeller o Don't use snprintf, but use a new function Appendf() to assemble
authored
369
7d695c6 @hzeller o Rename current_page_ to content_ to be more generic.
authored
370 Appendf(&content_, "<h3>Accessed Recently</h3>\n%zd in recency cache\n",
bea11d6 @hzeller o Don't use snprintf, but use a new function Appendf() to assemble
authored
371 stat_list.size());
372
08bbf28 @hzeller o First shot at gapless. Works pretty well for my test-case.
authored
373 if (filesystem_->gapless_processing()) {
d93a35b @hzeller o Uh, typo in gapless message.
authored
374 content_.append("<br/>&rarr; : denotes gapless transfers\n");
08bbf28 @hzeller o First shot at gapless. Works pretty well for my test-case.
authored
375 }
036c6e1 @hzeller o not wide cellspacing needed anymore.
authored
376 content_.append("<table>\n");
08bbf28 @hzeller o First shot at gapless. Works pretty well for my test-case.
authored
377 Appendf(&content_, "<tr><th>Stat</th><td><!--gapless in--></td>"
378 "<th width='%dpx'>Progress</th>" // progress bar.
379 "<td><!-- gapless out --></td>"
f1e9f27 @hzeller o Explain filter in table header.
authored
380 "<th>Pos</th><td></td><th>Len</th><th>Max&nbsp;out</th><th>Format&nbsp;(used&nbsp;filter)</th>"
b698853 @hzeller o README updates.
authored
381 "<th align='left'>File</th></tr>\n", kProgressWidth);
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
382 CompareStats comparator;
383 std::sort(stat_list.begin(), stat_list.end(), comparator);
384 for (size_t i = 0; i < stat_list.size(); ++i) {
118a454 @hzeller o Show the filter used for a particular format.
authored
385 AppendFileInfo(kActiveProgress, stat_list[i]);
b5c1e96 @hzeller o more useful output on status server.
authored
386 }
7d695c6 @hzeller o Rename current_page_ to content_ to be more generic.
authored
387 content_.append("</table><hr/>\n");
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
388
389 if (retired_.size() > 0) {
7d695c6 @hzeller o Rename current_page_ to content_ to be more generic.
authored
390 content_.append("<h3>Retired</h3>\n");
391 content_.append("<table>\n");
1e9ff21 @hzeller o main: report if parameters are not directories.
authored
392 boost::lock_guard<boost::mutex> l(retired_mutex_);
1bce634 @hzeller o Remove some trailing whitespaces
authored
393 for (RetiredList::const_iterator it = retired_.begin();
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
394 it != retired_.end(); ++it) {
118a454 @hzeller o Show the filter used for a particular format.
authored
395 AppendFileInfo(kRetiredProgress, *it);
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
396 }
7d695c6 @hzeller o Rename current_page_ to content_ to be more generic.
authored
397 content_.append("</table>\n");
1e9ff21 @hzeller o main: report if parameters are not directories.
authored
398 if (expunged_retired_ > 0) {
7d695c6 @hzeller o Rename current_page_ to content_ to be more generic.
authored
399 Appendf(&content_, "... (%d more)<p></p>", expunged_retired_);
1e9ff21 @hzeller o main: report if parameters are not directories.
authored
400 }
7d695c6 @hzeller o Rename current_page_ to content_ to be more generic.
authored
401 content_.append("<hr/>");
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
402 }
403
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
404 const double duration = folve::CurrentTime() - start;
7d695c6 @hzeller o Rename current_page_ to content_ to be more generic.
authored
405 Appendf(&content_,
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
406 "<span style='float:left;font-size:small;'>page-gen %.2fms</span>"
75867a2 @hzeller o legalese: add COPYING, provide "Appropriate Legal Notices" and
authored
407 "<span style='float:right;font-size:x-small;'>"
408 "&copy; 2012 Henner Zeller"
409 " | Folve is free software and comes with no warranty. "
410 " | Conveyed under the terms of the "
411 "<a href='http://www.gnu.org/licenses/gpl.html'>GPLv3</a>.</span>"
e619ff2 @hzeller o Redirect to / after settings. That way, a reload won't change any
authored
412 "</body></html>\n", duration * 1000.0);
7d695c6 @hzeller o Rename current_page_ to content_ to be more generic.
authored
413 return content_;
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
414 }
Something went wrong with that request. Please try again.