Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 80 lines (69 sloc) 2.351 kb
4d4d90b3 »
2012-09-23 o More legalese
1 // Folve - A fuse filesystem that convolves audio files on-the-fly.
2 //
c1a03f22 »
2012-09-14 o Needed convenient sub-second resolution time. Added CurrentTime()
3 // Copyright (C) 2012 Henner Zeller <h.zeller@acm.org>
1bce6345 »
2012-09-24 o Remove some trailing whitespaces
4 //
c1a03f22 »
2012-09-14 o Needed convenient sub-second resolution time. Added CurrentTime()
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
a9d3e538 »
2012-09-15 o Found a project name: "Folve". Some renamings because of that.
18 #include "util.h"
19
c1a03f22 »
2012-09-14 o Needed convenient sub-second resolution time. Added CurrentTime()
20 #include <stdio.h>
8268c37e »
2012-09-15 o Bubble up error messages in status server.
21 #include <sys/time.h>
7689c9a8 »
2012-09-22 o preparation to extract classes from folve-filesystem into their
22 #include <syslog.h>
c1a03f22 »
2012-09-14 o Needed convenient sub-second resolution time. Added CurrentTime()
23
75fae33e »
2012-10-01 o use cstdarg instad of stdarg.h
24 #include <cstdarg>
25
a9d3e538 »
2012-09-15 o Found a project name: "Folve". Some renamings because of that.
26 double folve::CurrentTime() {
c1a03f22 »
2012-09-14 o Needed convenient sub-second resolution time. Added CurrentTime()
27 struct timeval tv;
28 gettimeofday(&tv, NULL);
29 return tv.tv_sec + tv.tv_usec / 1e6;
30 }
8268c37e »
2012-09-15 o Bubble up error messages in status server.
31
3e883b73 »
2012-09-18 o Match filters in sequence
32 static void vAppendf(std::string *str, const char *format, va_list ap) {
8268c37e »
2012-09-15 o Bubble up error messages in status server.
33 const size_t orig_len = str->length();
3e883b73 »
2012-09-18 o Match filters in sequence
34 const size_t space = 1024; // there should be better ways to do this...
8268c37e »
2012-09-15 o Bubble up error messages in status server.
35 str->resize(orig_len + space);
36 int written = vsnprintf((char*)str->data() + orig_len, space, format, ap);
37 str->resize(orig_len + written);
38 }
3e883b73 »
2012-09-18 o Match filters in sequence
39
40 void folve::Appendf(std::string *str, const char *format, ...) {
41 va_list ap;
42 va_start(ap, format);
43 vAppendf(str, format, ap);
44 va_end(ap);
45 }
46
47 std::string folve::StringPrintf(const char *format, ...) {
48 va_list ap;
49 va_start(ap, format);
dff22d7b »
2012-10-01 o Move va_list to beginning of function; not sure if that
50 std::string result;
3e883b73 »
2012-09-18 o Match filters in sequence
51 vAppendf(&result, format, ap);
52 va_end(ap);
53 return result;
54 }
ac40d857 »
2012-09-21 o Make sure we match the alphabetically next file with
55
7689c9a8 »
2012-09-22 o preparation to extract classes from folve-filesystem into their
56 static bool global_debug_log = false;
57 void folve::EnableDebugLog(bool b) {
58 if (b != global_debug_log) {
59 syslog(LOG_INFO, "Switch debug mode %s.", b ? "on" : "off");
60 global_debug_log = b;
61 }
62 }
63
64 bool folve::IsDebugLogEnabled() {
65 return global_debug_log;
66 }
67
68 void folve::DLogf(const char *format, ...) {
69 if (!global_debug_log) return;
70 va_list ap;
71 va_start(ap, format);
72 vsyslog(LOG_DEBUG, format, ap);
73 va_end(ap);
74 }
75
ac40d857 »
2012-09-21 o Make sure we match the alphabetically next file with
76 bool folve::HasSuffix(const std::string &str, const std::string &suffix) {
77 if (str.length() < suffix.length()) return false;
78 return str.compare(str.length() - suffix.length(),
79 suffix.length(), suffix) == 0;
80 }
Something went wrong with that request. Please try again.