Permalink
Browse files

o a bit HTML polishing.

  • Loading branch information...
1 parent e619ff2 commit f1ef9608c883a0110272661aad3a8cd998c6f256 @hzeller committed Sep 22, 2012
Showing with 51 additions and 20 deletions.
  1. +17 −5 folve-filesystem.cc
  2. +34 −15 status-server.cc
View
22 folve-filesystem.cc
@@ -61,18 +61,22 @@ namespace {
// Very simple filter that just passes the original file through. Used for
// everything that is not a sound-file.
-class PassThroughFilter : public FileHandler {
+class PassThroughHandler : public FileHandler {
public:
- PassThroughFilter(int filedes, int filter_id,
+ PassThroughHandler(int filedes, int filter_id,
const HandlerStats &known_stats)
- : FileHandler(filter_id), filedes_(filedes), info_stats_(known_stats) {
+ : FileHandler(filter_id), filedes_(filedes),
+ file_size_(-1), max_accessed_(0), info_stats_(known_stats) {
info_stats_.message.append("; pass through.");
DebugLogf("Creating PassThrough filter for '%s'",
known_stats.filename.c_str());
+ struct stat st;
+ file_size_ = (Stat(&st) == 0) ? st.st_size : -1;
}
- ~PassThroughFilter() { close(filedes_); }
+ ~PassThroughHandler() { close(filedes_); }
virtual int Read(char *buf, size_t size, off_t offset) {
+ max_accessed_ = std::max(max_accessed_, (long unsigned int) offset + size);
const int result = pread(filedes_, buf, size, offset);
return result == -1 ? -errno : result;
}
@@ -81,10 +85,15 @@ class PassThroughFilter : public FileHandler {
}
virtual void GetHandlerStatus(struct HandlerStats *stats) {
*stats = info_stats_;
+ if (file_size_ > 0) {
+ stats->progress = 1.0 * max_accessed_ / file_size_;
+ }
}
private:
const int filedes_;
+ size_t file_size_;
+ long unsigned int max_accessed_;
HandlerStats info_stats_;
};
@@ -210,6 +219,9 @@ class SndFileHandler :
stats->progress = 0.0;
else
stats->progress = 1.0 * frames_done / in_info_.frames;
+ if (processor_ != NULL) {
+ base_stats_.max_output_value = processor_->max_output_value();
+ }
if (base_stats_.max_output_value > 1.0) {
// TODO: the status server could inspect this value and make better
// rendering.
@@ -583,7 +595,7 @@ FileHandler *FolveFilesystem::CreateFromDescriptor(
}
// Every other file-type is just passed through as is.
- return new PassThroughFilter(filedes, cfg_idx, file_info);
+ return new PassThroughHandler(filedes, cfg_idx, file_info);
}
std::string FolveFilesystem::CacheKey(int config_idx, const char *fs_path) {
View
49 status-server.cc
@@ -35,7 +35,7 @@ using folve::Appendf;
// TODO: someone with a bit more stylesheet-fu can attempt to make this
// more pretty and the HTML more compact.
-static const size_t kMaxRetired = 200;
+static const size_t kMaxRetired = 20;
static const int kProgressWidth = 300;
static const char kActiveProgress[] = "#7070ff";
static const char kRetiredProgress[] = "#d0d0d0";
@@ -140,17 +140,21 @@ void StatusServer::RetireHandlerEvent(FileHandler *handler) {
}
}
-static const char sMessageRowHtml[] =
+// As ugly #defines, so that gcc can warn about printf() format problems.
+#define sMessageRowHtml \
"<td>%s</td><td colspan='3' style='font-size:small;'>%s</td>"
- "<td colspan='3' align='center'>-</td>";
-static const char sProgressRowHtml[] =
+#define sProgressRowHtml \
+ "<td>%s</td>" \
+ "<td>%s</td>" \
+ "<td><div style='background:white;width:%dpx;border:1px solid black;'>\n" \
+ " <div style='width:%d%%;background:%s;'>&nbsp;</div>\n</div></td>" \
"<td>%s</td>"
- "<td>%s</td>" // gapless marker
- "<td><div style='width:%dpx; border:1px solid black;'>\n"
- " <div style='width:%d%%;background:%s;'>&nbsp;</div>\n</div></td>"
- "<td>%s</td>" // gapless
- "<td align='right'>%2d:%02d</td><td>/</td><td align='right'>%2d:%02d</td>";
+
+#define sTimeColumns \
+ "<td align='right'>%2d:%02d</td><td>/</td><td align='right'>%2d:%02d</td>"
+#define sDecibelColumn \
+ "<td align='right' style='background:%s;'>%.1f dB</td>"
static void AppendFileInfo(std::string *result, const char *progress_style,
const HandlerStats &stats) {
@@ -162,19 +166,34 @@ static void AppendFileInfo(std::string *result, const char *progress_style,
case HandlerStats::RETIRED: status = "&nbsp;----&nbsp;"; break;
// no default to let the compiler detect new values.
}
+
if (!stats.message.empty()) {
Appendf(result, sMessageRowHtml, status, stats.message.c_str());
} else if (stats.progress == 0) {
Appendf(result, sMessageRowHtml, status, "Only header accessed");
} else {
- const int secs = stats.duration_seconds;
- const int fract_sec = stats.progress * secs;
Appendf(result, sProgressRowHtml, status,
stats.in_gapless ? "&rarr;" : "",
kProgressWidth, (int) (100 * stats.progress), progress_style,
- stats.out_gapless ? "&rarr;" : "",
- fract_sec / 60, fract_sec % 60, secs / 60, secs % 60);
+ stats.out_gapless ? "&rarr;" : "");
+ }
+ const int secs = stats.duration_seconds;
+ const int fract_sec = stats.progress * secs;
+ if (secs > 0 && fract_sec > 0) {
+ Appendf(result, sTimeColumns,
+ fract_sec / 60, fract_sec % 60,
+ secs / 60, secs % 60);
+ } else {
+ result->append("<td colspan='3'>-</td>");
}
+ if (stats.max_output_value > 0.0) {
+ Appendf(result, sDecibelColumn,
+ stats.max_output_value > 1.0 ? "#FF0505" : "white",
+ 20 * log(stats.max_output_value));
+ } else {
+ result->append("<td>-</td>");
+ }
+
Appendf(result, "<td bgcolor='#c0c0c0'>&nbsp;%s&nbsp;</td>",
stats.format.c_str());
Appendf(result,"<td "
@@ -273,11 +292,11 @@ const std::string &StatusServer::CreatePage() {
if (filesystem_->gapless_processing()) {
content_.append("<br/>&rarr; : denotes gapless transfers\n");
}
- content_.append("<table>\n");
+ content_.append("<table cellspacing='10'>\n");
Appendf(&content_, "<tr><th>Stat</th><td><!--gapless in--></td>"
"<th width='%dpx'>Progress</th>" // progress bar.
"<td><!-- gapless out --></td>"
- "<th>Pos</th><td></td><th>Len</th><th>Format</th>"
+ "<th>Pos</th><td></td><th>Len</th><th>Max out</th><th>Format</th>"
"<th align='left'>File</th></tr>\n", kProgressWidth);
CompareStats comparator;
std::sort(stat_list.begin(), stat_list.end(), comparator);

0 comments on commit f1ef960

Please sign in to comment.