Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 434 lines (395 sloc) 16.574 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
b4eec5c @hzeller o libboost caused too many troubles in embedded systems with weak
authored
33 #include <algorithm>
1e9ff21 @hzeller o main: report if parameters are not directories.
authored
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
218e0d1 @hzeller o make HTML a bit more compact and centralize most styles.
authored
41 // To be used in CSS constant.
42 #define PROGRESS_WIDTH "300"
b698853 @hzeller o README updates.
authored
43 static const int kProgressWidth = 300;
218e0d1 @hzeller o make HTML a bit more compact and centralize most styles.
authored
44
45 static const size_t kMaxRetired = 20;
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
46 static const char kActiveProgress[] = "#7070ff";
47 static const char kRetiredProgress[] = "#d0d0d0";
249865a @hzeller o Make debug mode switchable in UI.
authored
48 static const char kSettingsUrl[] = "/settings";
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
49
78e66dd @hzeller o I need to find my browser-tab :) Add favicon.
authored
50 // Aaah, I need to find the right Browser-Tab :)
51 // Sneak in a favicon without another resource access.
52 // TODO: make a nice icon, recognizable as something that has to do with "
53 // files and music ...
a372a03 @hzeller o Make meta-refresh configurable.
authored
54 static const char kStartHtmlHeader[] = "<html><head>"
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
55 "<title>Folve</title>\n"
e619ff2 @hzeller o Redirect to / after settings. That way, a reload won't change any
authored
56 "<link rel='icon' type='image/png' "
78e66dd @hzeller o I need to find my browser-tab :) Add favicon.
authored
57 "href='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2"
58 "AAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9wJDwUlEA/UBrsA"
59 "AABSSURBVCjPrZIxDgAgDAKh8f9froOTirU1ssKFYqS7Q4mktAxFRQDJcsPORMDYsDCXhn331"
a372a03 @hzeller o Make meta-refresh configurable.
authored
60 "9GPwHJVuaFl3l4D1+h0UjIdbTh9SpP2KQ2AgSfVAdEQGx23tOopAAAAAElFTkSuQmCC'/>\n";
78e66dd @hzeller o I need to find my browser-tab :) Add favicon.
authored
61
adde81e @hzeller o some link prettify.
authored
62 // TODO: someone with a bit more stylesheet-fu can attempt to make this
63 // more pretty and the HTML more compact.
64 // Also, maybe move to external file, makes editing much faster, then compile
65 // that into a C-string that we can include it in the binary.
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'>"
60badba @hzeller o HTML escaping for directories with nasty names (<, >, &)
authored
68 " body { font-family:Sans-Serif; }\n"
adde81e @hzeller o some link prettify.
authored
69 " a:link { text-decoration:none; }\n"
70 " a:visited { text-decoration:none; }\n"
71 " a:hover { text-decoration:underline; }\n"
72 " a:active { text-decoration:underline; }\n"
23dc276 @hzeller o make switch-message ('affects new files') more prominent.
authored
73 " .rounded_box, .filter_sel {\n"
60badba @hzeller o HTML escaping for directories with nasty names (<, >, &)
authored
74 " float: left;\n"
75 " margin: 5px;\n"
76 " margin-right: 5px;\n"
77 " margin-bottom: 5px;\n"
23dc276 @hzeller o make switch-message ('affects new files') more prominent.
authored
78 " padding: 5px 15px;\n"
79 " border-radius: 5px;\n"
80 " -moz-border-radius: 5px; }\n"
81 " .filter_sel { font-weight:bold; }\n"
218e0d1 @hzeller o make HTML a bit more compact and centralize most styles.
authored
82 " .active { background-color:#a0a0ff; }\n"
adde81e @hzeller o some link prettify.
authored
83 " .inactive { background-color:#e0e0e0; }\n"
218e0d1 @hzeller o make HTML a bit more compact and centralize most styles.
authored
84 " .inactive:hover { background-color:#e0e0ff;\n"
adde81e @hzeller o some link prettify.
authored
85 " color: #000000;\n"
86 " text-decoration:none;}\n"
87 " .inactive:link { color: #000000;text-decoration:none;}\n"
88 " .inactive:visited { color: #000000;text-decoration:none;}\n"
218e0d1 @hzeller o make HTML a bit more compact and centralize most styles.
authored
89 // CSS classes used in the file-listin. Keep things compact.
90 " td { text-wrap:none; white-space:nowrap; }\n"
91 " .fn { font-size:small; text-wrap:none; white-space:nowrap; }\n" // filename
92 " .pf { width:" PROGRESS_WIDTH "px;\n" // progress-
93 " background: white; border:1px solid black; }\n" // frame
94 " .nf { text-align:right; }\n" // number formatting.
95 " .fb { background-color:#c0c0c0;"
96 " border-radius: 3px;\n"
97 " -moz-border-radius: 3px; }\n" // format box
537e34b @hzeller o cleanup UI: no radio buttons anymore, just simple links.
authored
98 "</style>";
99
b698853 @hzeller o README updates.
authored
100 // Callback function called by micro http daemon. Gets the StatusServer pointer
101 // in the user_argument.
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
102 int StatusServer::HandleHttp(void* user_argument,
103 struct MHD_Connection *connection,
104 const char *url, const char *method,
105 const char *version,
106 const char *upload_data, size_t *upload_size,
107 void**) {
108 StatusServer* server = (StatusServer*) user_argument;
e619ff2 @hzeller o Redirect to / after settings. That way, a reload won't change any
authored
109 struct MHD_Response *response;
110 int ret;
111
249865a @hzeller o Make debug mode switchable in UI.
authored
112 if (strcmp(url, kSettingsUrl) == 0) {
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
113 server->SetFilter(MHD_lookup_connection_value(connection,
114 MHD_GET_ARGUMENT_KIND, "f"));
249865a @hzeller o Make debug mode switchable in UI.
authored
115 server->SetDebug(MHD_lookup_connection_value(connection,
116 MHD_GET_ARGUMENT_KIND, "d"));
e619ff2 @hzeller o Redirect to / after settings. That way, a reload won't change any
authored
117 // We redirect to slash after this, to remove parameters from the GET-URL
118 response = MHD_create_response_from_data(0, (void*)"", MHD_NO, MHD_NO);
119 MHD_add_response_header(response, "Location", "/");
1bce634 @hzeller o Remove some trailing whitespaces
authored
120 ret = MHD_queue_response(connection, 302, response);
e619ff2 @hzeller o Redirect to / after settings. That way, a reload won't change any
authored
121 } else {
122 const std::string &page = server->CreatePage();
123 response = MHD_create_response_from_data(page.length(), (void*) page.data(),
124 MHD_NO, MHD_NO);
125 MHD_add_response_header(response, "Content-Type",
126 "text/html; charset=utf-8");
127 ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
128 }
e619ff2 @hzeller o Redirect to / after settings. That way, a reload won't change any
authored
129 // Tell aggressive cachers not to do so.
130 MHD_add_response_header(response, "Cache-Control", "no-cache");
131 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
132 MHD_destroy_response(response);
133 return ret;
134 }
135
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
136 StatusServer::StatusServer(FolveFilesystem *fs)
1e9ff21 @hzeller o main: report if parameters are not directories.
authored
137 : expunged_retired_(0), total_seconds_filtered_(0),
138 total_seconds_music_seen_(0),
a372a03 @hzeller o Make meta-refresh configurable.
authored
139 meta_refresh_time_(-1),
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
140 filesystem_(fs), daemon_(NULL), filter_switched_(false) {
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
141 fs->handler_cache()->SetObserver(this);
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
142 }
143
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
144 void StatusServer::SetFilter(const char *filter) {
31096bb @hzeller o remove option -c and add -C: give a base directory for all filters.
authored
145 if (filter == NULL) return;
146 filter_switched_ = filesystem_->SwitchCurrentConfigDir(filter);
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
147 }
148
249865a @hzeller o Make debug mode switchable in UI.
authored
149 void StatusServer::SetDebug(const char *dbg) {
8c7e5c1 @hzeller o Only if -D is given, the debug toggle is active in the UI.
authored
150 if (!filesystem_->is_debug_ui_enabled()) return;
7689c9a @hzeller o preparation to extract classes from folve-filesystem into their
authored
151 folve::EnableDebugLog(dbg != NULL && *dbg == '1');
249865a @hzeller o Make debug mode switchable in UI.
authored
152 }
153
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
154 bool StatusServer::Start(int port) {
1bce634 @hzeller o Remove some trailing whitespaces
authored
155 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
156 &HandleHttp, this,
157 MHD_OPTION_END);
158 return daemon_ != NULL;
159 }
160
161 StatusServer::~StatusServer() {
b698853 @hzeller o README updates.
authored
162 if (daemon_) MHD_stop_daemon(daemon_);
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
163 }
164
20e139c @hzeller o Less cluttered output in UI if -D is not set.
authored
165 bool StatusServer::show_details() {
166 // Right now, we just make this dependent on debug output. Could be a separate
167 // option.
168 return folve::IsDebugLogEnabled();
169 }
170
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
171 // FileHandlerCache::Observer interface.
172 void StatusServer::RetireHandlerEvent(FileHandler *handler) {
173 HandlerStats stats;
174 handler->GetHandlerStatus(&stats); // Get last available stats.
175 if (stats.progress >= 0) {
8268c37 @hzeller o Bubble up error messages in status server.
authored
176 total_seconds_music_seen_ += stats.duration_seconds;
177 total_seconds_filtered_ += stats.duration_seconds * stats.progress;
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
178 }
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
179 stats.last_access = folve::CurrentTime();
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
180 stats.status = HandlerStats::RETIRED;
b4eec5c @hzeller o libboost caused too many troubles in embedded systems with weak
authored
181 folve::MutexLock l(&retired_mutex_);
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
182 retired_.push_front(stats);
1e9ff21 @hzeller o main: report if parameters are not directories.
authored
183 while (retired_.size() > kMaxRetired) {
184 ++expunged_retired_;
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
185 retired_.pop_back();
1e9ff21 @hzeller o main: report if parameters are not directories.
authored
186 }
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
187 }
1bce634 @hzeller o Remove some trailing whitespaces
authored
188
f1ef960 @hzeller o a bit HTML polishing.
authored
189 // As ugly #defines, so that gcc can warn about printf() format problems.
190 #define sMessageRowHtml \
08bbf28 @hzeller o First shot at gapless. Works pretty well for my test-case.
authored
191 "<td>%s</td><td colspan='3' style='font-size:small;'>%s</td>"
b5c1e96 @hzeller o more useful output on status server.
authored
192
f1ef960 @hzeller o a bit HTML polishing.
authored
193 #define sProgressRowHtml \
194 "<td>%s</td>" \
195 "<td>%s</td>" \
218e0d1 @hzeller o make HTML a bit more compact and centralize most styles.
authored
196 "<td><div class='pf'>" \
197 "<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
198 "<td>%s</td>"
f1ef960 @hzeller o a bit HTML polishing.
authored
199
200 #define sTimeColumns \
218e0d1 @hzeller o make HTML a bit more compact and centralize most styles.
authored
201 "<td class='nf'>%2d:%02d</td><td>/</td><td class='nf'>%2d:%02d</td>"
f1ef960 @hzeller o a bit HTML polishing.
authored
202 #define sDecibelColumn \
218e0d1 @hzeller o make HTML a bit more compact and centralize most styles.
authored
203 "<td class='nf'%s>%.1f dB</td>"
b5c1e96 @hzeller o more useful output on status server.
authored
204
118a454 @hzeller o Show the filter used for a particular format.
authored
205 void StatusServer::AppendFileInfo(const char *progress_style,
206 const HandlerStats &stats) {
218e0d1 @hzeller o make HTML a bit more compact and centralize most styles.
authored
207 content_.append("<tr>");
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
208 const char *status = "";
209 switch (stats.status) {
210 case HandlerStats::OPEN: status = "open"; break;
211 case HandlerStats::IDLE: status = "idle"; break;
bcb77e7 @hzeller o Ran with Amarok over my files. Looks like it sometimes only 'almost'
authored
212 case HandlerStats::RETIRED: status = "&nbsp;----&nbsp;"; break;
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
213 // no default to let the compiler detect new values.
214 }
f1ef960 @hzeller o a bit HTML polishing.
authored
215
8268c37 @hzeller o Bubble up error messages in status server.
authored
216 if (!stats.message.empty()) {
118a454 @hzeller o Show the filter used for a particular format.
authored
217 Appendf(&content_, sMessageRowHtml, status, stats.message.c_str());
8268c37 @hzeller o Bubble up error messages in status server.
authored
218 } else if (stats.progress == 0) {
118a454 @hzeller o Show the filter used for a particular format.
authored
219 Appendf(&content_, sMessageRowHtml, status, "Only header accessed");
b5c1e96 @hzeller o more useful output on status server.
authored
220 } else {
118a454 @hzeller o Show the filter used for a particular format.
authored
221 Appendf(&content_, sProgressRowHtml, status,
08bbf28 @hzeller o First shot at gapless. Works pretty well for my test-case.
authored
222 stats.in_gapless ? "&rarr;" : "",
218e0d1 @hzeller o make HTML a bit more compact and centralize most styles.
authored
223 (int) (kProgressWidth * stats.progress),
b9ae86d @hzeller o Higher than percent resolution progress bar.
authored
224 progress_style,
f1ef960 @hzeller o a bit HTML polishing.
authored
225 stats.out_gapless ? "&rarr;" : "");
226 }
227 const int secs = stats.duration_seconds;
228 const int fract_sec = stats.progress * secs;
6d4f28b @hzeller o if there is a time, show it.
authored
229 if (secs >= 0 && fract_sec >= 0) {
1bce634 @hzeller o Remove some trailing whitespaces
authored
230 Appendf(&content_, sTimeColumns,
f1ef960 @hzeller o a bit HTML polishing.
authored
231 fract_sec / 60, fract_sec % 60,
232 secs / 60, secs % 60);
233 } else {
118a454 @hzeller o Show the filter used for a particular format.
authored
234 content_.append("<td colspan='3'>-</td>");
b5c1e96 @hzeller o more useful output on status server.
authored
235 }
f00e6a4 @hzeller o Don't do unprotected read on status information such as
authored
236
036c6e1 @hzeller o not wide cellspacing needed anymore.
authored
237 if (stats.max_output_value > 1e-6) {
118a454 @hzeller o Show the filter used for a particular format.
authored
238 Appendf(&content_, sDecibelColumn,
218e0d1 @hzeller o make HTML a bit more compact and centralize most styles.
authored
239 stats.max_output_value > 1.0 ? " style='background:#FF8080;'" : "",
7b499ea @hzeller o Uh, log() is actually ln() and log10f() is log() :)
authored
240 20 * log10f(stats.max_output_value));
f1ef960 @hzeller o a bit HTML polishing.
authored
241 } else {
118a454 @hzeller o Show the filter used for a particular format.
authored
242 content_.append("<td>-</td>");
f1ef960 @hzeller o a bit HTML polishing.
authored
243 }
244
31096bb @hzeller o remove option -c and add -C: give a base directory for all filters.
authored
245 const char *filter_dir = stats.filter_dir.empty()
246 ? "Pass Through" : stats.filter_dir.c_str();
218e0d1 @hzeller o make HTML a bit more compact and centralize most styles.
authored
247 Appendf(&content_, "<td class='fb'>&nbsp;%s (%s)&nbsp;</td>",
31096bb @hzeller o remove option -c and add -C: give a base directory for all filters.
authored
248 stats.format.c_str(), filter_dir);
218e0d1 @hzeller o make HTML a bit more compact and centralize most styles.
authored
249 Appendf(&content_,"<td class='fn'>%s</td>", stats.filename.c_str());
118a454 @hzeller o Show the filter used for a particular format.
authored
250 content_.append("</tr>\n");
b5c1e96 @hzeller o more useful output on status server.
authored
251 }
252
60badba @hzeller o HTML escaping for directories with nasty names (<, >, &)
authored
253 // The directories are user-input, so we need to sanitize stuff.
f439f8d @hzeller o allow for non-ascii or space-containing directory names that
authored
254 static void AppendSanitizedUrlParam(const std::string &in, std::string *out) {
255 for (std::string::const_iterator i = in.begin(); i != in.end(); ++i) {
60badba @hzeller o HTML escaping for directories with nasty names (<, >, &)
authored
256 if (isupper(*i) || islower(*i) || isdigit(*i)) {
f439f8d @hzeller o allow for non-ascii or space-containing directory names that
authored
257 out->append(1, *i);
60badba @hzeller o HTML escaping for directories with nasty names (<, >, &)
authored
258 } else {
259 Appendf(out, "%%%02x", (unsigned char) *i);
260 }
261 }
262 }
263
264 static void AppendSanitizedHTML(const std::string &in, std::string *out) {
265 for (std::string::const_iterator i = in.begin(); i != in.end(); ++i) {
266 switch (*i) {
267 case '<': out->append("&lt;"); break;
268 case '>': out->append("&gt;"); break;
269 case '&': out->append("&amp;"); break;
270 default: out->append(1, *i);
f439f8d @hzeller o allow for non-ascii or space-containing directory names that
authored
271 }
272 }
273 }
274
275 static void CreateSelection(const std::set<std::string> &options,
276 const std::string &selected,
277 std::string *result) {
d280fce @hzeller o Reload page with a meta-refresn.
authored
278 if (options.size() == 1) {
31096bb @hzeller o remove option -c and add -C: give a base directory for all filters.
authored
279 result->append(selected);
d280fce @hzeller o Reload page with a meta-refresn.
authored
280 return;
281 }
31096bb @hzeller o remove option -c and add -C: give a base directory for all filters.
authored
282 typedef std::set<std::string> Set;
283 for (Set::const_iterator it = options.begin(); it != options.end(); ++it) {
284 const bool active = (*it == selected);
285 const char *title = it->empty() ? "None : Pass Through" : it->c_str();
537e34b @hzeller o cleanup UI: no radio buttons anymore, just simple links.
authored
286 if (active) {
60badba @hzeller o HTML escaping for directories with nasty names (<, >, &)
authored
287 result->append("<span class='filter_sel active'>");
288 AppendSanitizedHTML(title, result);
289 result->append("</span>");
537e34b @hzeller o cleanup UI: no radio buttons anymore, just simple links.
authored
290 } else {
f439f8d @hzeller o allow for non-ascii or space-containing directory names that
authored
291 Appendf(result, "<a class='filter_sel inactive' href='%s?f=",
292 kSettingsUrl);
293 AppendSanitizedUrlParam(*it, result);
60badba @hzeller o HTML escaping for directories with nasty names (<, >, &)
authored
294 result->append("'>");
295 AppendSanitizedHTML(title, result);
296 result->append("</a>\n");
537e34b @hzeller o cleanup UI: no radio buttons anymore, just simple links.
authored
297 }
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
298 }
d280fce @hzeller o Reload page with a meta-refresn.
authored
299 }
300
301 void StatusServer::AppendSettingsForm() {
60badba @hzeller o HTML escaping for directories with nasty names (<, >, &)
authored
302 content_.append("<p><span class='filter_sel'>Active filter:</span>");
31096bb @hzeller o remove option -c and add -C: give a base directory for all filters.
authored
303 std::set<std::string> available_dirs = filesystem_->GetAvailableConfigDirs();
f439f8d @hzeller o allow for non-ascii or space-containing directory names that
authored
304 CreateSelection(available_dirs,
305 filesystem_->current_config_subdir(),
306 &content_);
31096bb @hzeller o remove option -c and add -C: give a base directory for all filters.
authored
307 if (available_dirs.empty() == 1) {
308 content_.append(" (This is a boring configuration, add filter directories)");
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
309 } else if (filter_switched_) {
60badba @hzeller o HTML escaping for directories with nasty names (<, >, &)
authored
310 content_.append("<span class='rounded_box' "
23dc276 @hzeller o make switch-message ('affects new files') more prominent.
authored
311 "style='font-size:small;background:#FFFFa0;'>"
4c6565f @hzeller o don't put 'affects...' message in parenthesis.
authored
312 "Affects re- or newly opened files.</span>");
e619ff2 @hzeller o Redirect to / after settings. That way, a reload won't change any
authored
313 filter_switched_ = false; // only show once.
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
314 }
537e34b @hzeller o cleanup UI: no radio buttons anymore, just simple links.
authored
315 // TODO: re-add something for filesystem_->is_debug_ui_enabled()
60badba @hzeller o HTML escaping for directories with nasty names (<, >, &)
authored
316 content_.append("</p><hr style='clear:both;'/>");
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
317 }
318
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
319 struct CompareStats {
b76ff19 @hzeller o ICE in 2.7.1; don't have the machine in front of me, but reported
authored
320 bool operator() (const HandlerStats *a, const HandlerStats *b) {
321 if (a->status < b->status) return true; // open before idle.
322 else if (a->status > b->status) return false;
323 return b->last_access < a->last_access; // reverse time.
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
324 }
325 };
326
1e9ff21 @hzeller o main: report if parameters are not directories.
authored
327 const std::string &StatusServer::CreatePage() {
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
328 const double start = folve::CurrentTime();
b698853 @hzeller o README updates.
authored
329 // We re-use a string to avoid re-allocing memory every time we generate
330 // a page. Since we run with MHD_USE_SELECT_INTERNALLY, this is only accessed
331 // by one thread.
7d695c6 @hzeller o Rename current_page_ to content_ to be more generic.
authored
332 content_.clear();
a372a03 @hzeller o Make meta-refresh configurable.
authored
333 content_.append(kStartHtmlHeader);
334 if (meta_refresh_time_ > 0) {
335 Appendf(&content_, "<meta http-equiv='refresh' content='%d'>\n",
336 meta_refresh_time_);
337 }
537e34b @hzeller o cleanup UI: no radio buttons anymore, just simple links.
authored
338 content_.append(kCSS);
a372a03 @hzeller o Make meta-refresh configurable.
authored
339 content_.append("</head>\n");
340
60badba @hzeller o HTML escaping for directories with nasty names (<, >, &)
authored
341 content_.append("<body>\n");
7d695c6 @hzeller o Rename current_page_ to content_ to be more generic.
authored
342 Appendf(&content_, "<center style='background-color:#A0FFA0;'>"
53130a3 @hzeller o link to github page
authored
343 "Welcome to "
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
344 "<a href='https://github.com/hzeller/folve#readme'>Folve</a> "
20e139c @hzeller o Less cluttered output in UI if -D is not set.
authored
345 FOLVE_VERSION "</center>\n");
346 if (show_details()) {
347 Appendf(&content_, "Convolving audio files from <code>%s</code>\n",
348 filesystem_->underlying_dir().c_str());
349 }
d280fce @hzeller o Reload page with a meta-refresn.
authored
350 AppendSettingsForm();
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored
351
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
352 std::vector<HandlerStats> stat_list;
353 filesystem_->handler_cache()->GetStats(&stat_list);
354
562b493 @hzeller o Print out config file name while spotting a problem
authored
355 // Get statistics of active files to add to the existing ones.
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
356 double active_music_seen = 0.0;
357 double active_filtered = 0.0;
358 for (size_t i = 0; i < stat_list.size(); ++i) {
359 const HandlerStats &stats = stat_list[i];
360 if (stats.progress >= 0) {
8268c37 @hzeller o Bubble up error messages in status server.
authored
361 active_music_seen += stats.duration_seconds;
362 active_filtered += stats.duration_seconds * stats.progress;
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
363 }
364 }
20e139c @hzeller o Less cluttered output in UI if -D is not set.
authored
365 if (show_details()) {
1bce634 @hzeller o Remove some trailing whitespaces
authored
366 const int t_seen = total_seconds_music_seen_ + active_music_seen;
367 const int t_filtered = total_seconds_filtered_ + active_filtered;
368 Appendf(&content_, "Total opening files <b>%d</b> "
369 ".. and re-opened from recency cache <b>%d</b><br/>",
370 filesystem_->total_file_openings(),
371 filesystem_->total_file_reopen());
372 Appendf(&content_, "Total music seen <b>%dd %d:%02d:%02d</b> ",
373 t_seen / 86400, (t_seen % 86400) / 3600,
374 (t_seen % 3600) / 60, t_seen % 60);
375 Appendf(&content_, ".. and convolved <b>%dd %d:%02d:%02d</b> ",
376 t_filtered / 86400, (t_filtered % 86400) / 3600,
377 (t_filtered % 3600) / 60, t_filtered % 60);
378 Appendf(&content_, "(%.1f%%)<br/>",
379 (t_seen == 0) ? 0.0 : (100.0 * t_filtered / t_seen));
380 }
bea11d6 @hzeller o Don't use snprintf, but use a new function Appendf() to assemble
authored
381
43bb82b @hzeller o Make gapless transfer legend a bit more compact (not separate line).
authored
382 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
383 stat_list.size());
384
08bbf28 @hzeller o First shot at gapless. Works pretty well for my test-case.
authored
385 if (filesystem_->gapless_processing()) {
43bb82b @hzeller o Make gapless transfer legend a bit more compact (not separate line).
authored
386 content_.append("Gapless transfers indicated with '&rarr;'.\n");
08bbf28 @hzeller o First shot at gapless. Works pretty well for my test-case.
authored
387 }
036c6e1 @hzeller o not wide cellspacing needed anymore.
authored
388 content_.append("<table>\n");
08bbf28 @hzeller o First shot at gapless. Works pretty well for my test-case.
authored
389 Appendf(&content_, "<tr><th>Stat</th><td><!--gapless in--></td>"
390 "<th width='%dpx'>Progress</th>" // progress bar.
391 "<td><!-- gapless out --></td>"
43bb82b @hzeller o Make gapless transfer legend a bit more compact (not separate line).
authored
392 "<th>Pos</th><td></td><th>Len</th><th>Max&nbsp;out</th>"
393 "<th>Format&nbsp;(used&nbsp;filter)</th>"
b698853 @hzeller o README updates.
authored
394 "<th align='left'>File</th></tr>\n", kProgressWidth);
277930c @hzeller o update comment.
authored
395 // ICE in arm 2.7.1 compiler if we sort values. So sort pointers
396 // to the values instead.
b76ff19 @hzeller o ICE in 2.7.1; don't have the machine in front of me, but reported
authored
397 std::vector<HandlerStats *> stat_ptrs;
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
398 for (size_t i = 0; i < stat_list.size(); ++i) {
b76ff19 @hzeller o ICE in 2.7.1; don't have the machine in front of me, but reported
authored
399 stat_ptrs.push_back(&stat_list[i]);
400 }
401 CompareStats comparator;
402 std::sort(stat_ptrs.begin(), stat_ptrs.end(), comparator);
403 for (size_t i = 0; i < stat_ptrs.size(); ++i) {
404 AppendFileInfo(kActiveProgress, *stat_ptrs[i]);
b5c1e96 @hzeller o more useful output on status server.
authored
405 }
7d695c6 @hzeller o Rename current_page_ to content_ to be more generic.
authored
406 content_.append("</table><hr/>\n");
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
407
408 if (retired_.size() > 0) {
7d695c6 @hzeller o Rename current_page_ to content_ to be more generic.
authored
409 content_.append("<h3>Retired</h3>\n");
410 content_.append("<table>\n");
b4eec5c @hzeller o libboost caused too many troubles in embedded systems with weak
authored
411 folve::MutexLock l(&retired_mutex_);
1bce634 @hzeller o Remove some trailing whitespaces
authored
412 for (RetiredList::const_iterator it = retired_.begin();
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
413 it != retired_.end(); ++it) {
118a454 @hzeller o Show the filter used for a particular format.
authored
414 AppendFileInfo(kRetiredProgress, *it);
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
415 }
7d695c6 @hzeller o Rename current_page_ to content_ to be more generic.
authored
416 content_.append("</table>\n");
1e9ff21 @hzeller o main: report if parameters are not directories.
authored
417 if (expunged_retired_ > 0) {
7d695c6 @hzeller o Rename current_page_ to content_ to be more generic.
authored
418 Appendf(&content_, "... (%d more)<p></p>", expunged_retired_);
1e9ff21 @hzeller o main: report if parameters are not directories.
authored
419 }
7d695c6 @hzeller o Rename current_page_ to content_ to be more generic.
authored
420 content_.append("<hr/>");
223f392 @hzeller o Have a separate HandlerStats object that contains relevant
authored
421 }
422
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
423 const double duration = folve::CurrentTime() - start;
7d695c6 @hzeller o Rename current_page_ to content_ to be more generic.
authored
424 Appendf(&content_,
a451825 @hzeller o make page generation time less obtrusive.
authored
425 "<span style='float:left;font-size:x-small;'>%.2fms</span>"
75867a2 @hzeller o legalese: add COPYING, provide "Appropriate Legal Notices" and
authored
426 "<span style='float:right;font-size:x-small;'>"
427 "&copy; 2012 Henner Zeller"
428 " | Folve is free software and comes with no warranty. "
429 " | Conveyed under the terms of the "
430 "<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
431 "</body></html>\n", duration * 1000.0);
7d695c6 @hzeller o Rename current_page_ to content_ to be more generic.
authored
432 return content_;
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
433 }
Something went wrong with that request. Please try again.