Skip to content
Newer
Older
100644 80 lines (64 sloc) 2.53 KB
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
1 // -*- c++ -*-
4d4d90b @hzeller o More legalese
authored
2 // Folve - A fuse filesystem that convolves audio files on-the-fly.
3 //
c1a03f2 @hzeller o Needed convenient sub-second resolution time. Added CurrentTime()
authored
4 // Copyright (C) 2012 Henner Zeller <h.zeller@acm.org>
1bce634 @hzeller o Remove some trailing whitespaces
authored
5 //
c1a03f2 @hzeller o Needed convenient sub-second resolution time. Added CurrentTime()
authored
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
19 #ifndef FOLVE_UTIL_H
20 #define FOLVE_UTIL_H
c1a03f2 @hzeller o Needed convenient sub-second resolution time. Added CurrentTime()
authored
21
8268c37 @hzeller o Bubble up error messages in status server.
authored
22 #include <string>
b4eec5c @hzeller o libboost caused too many troubles in embedded systems with weak
authored
23 #include <pthread.h>
8268c37 @hzeller o Bubble up error messages in status server.
authored
24
7689c9a @hzeller o preparation to extract classes from folve-filesystem into their
authored
25 // Define this with empty, if you're not using gcc.
26 #define PRINTF_FMT_CHECK(fmt_pos, args_pos) \
27 __attribute__ ((format (printf, fmt_pos, args_pos)))
28
29 // Some utility functions needed everywhere.
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
30 namespace folve {
8268c37 @hzeller o Bubble up error messages in status server.
authored
31 // Returns the current time as seconds since the start of the unix epoch,
32 // but in microsecond resolution.
c1a03f2 @hzeller o Needed convenient sub-second resolution time. Added CurrentTime()
authored
33 double CurrentTime();
7689c9a @hzeller o preparation to extract classes from folve-filesystem into their
authored
34
8268c37 @hzeller o Bubble up error messages in status server.
authored
35 // Like snprintf, but print to a std::string instead.
7689c9a @hzeller o preparation to extract classes from folve-filesystem into their
authored
36 void Appendf(std::string *str, const char *format, ...) PRINTF_FMT_CHECK(2,3);
3e883b7 @hzeller o Match filters in sequence
authored
37
38 // Convenience, that returns a string directly. A bit less efficient than
39 // Appendf().
7689c9a @hzeller o preparation to extract classes from folve-filesystem into their
authored
40 std::string StringPrintf(const char *format, ...) PRINTF_FMT_CHECK(1, 2);
ac40d85 @hzeller o Make sure we match the alphabetically next file with
authored
41
42 // Return if "str" has suffix "suffix".
43 bool HasSuffix(const std::string &str, const std::string &suffix);
7689c9a @hzeller o preparation to extract classes from folve-filesystem into their
authored
44
45 // Log formatted string if debugging enabled.
46 void DLogf(const char *format, ...) PRINTF_FMT_CHECK(1, 2);
47 void EnableDebugLog(bool b);
48 bool IsDebugLogEnabled();
b4eec5c @hzeller o libboost caused too many troubles in embedded systems with weak
authored
49
50 // Importing boost::mutex posed too many dependencies on some embedded systems
51 // with insufficient library support.
52 // So we have our own little wrapper around the pthread mutex.
53 // Non-recursive.
54 class Mutex {
55 public:
56 Mutex() { pthread_mutex_init(&mutex_, NULL); }
57 ~Mutex() { pthread_mutex_destroy(&mutex_); }
58 void Lock() { pthread_mutex_lock(&mutex_); }
59 void Unlock() { pthread_mutex_unlock(&mutex_); }
60
61 private:
62 pthread_mutex_t mutex_;
63 };
64
8054dc9 @hzeller o whitespace style.
authored
65 // Useful RAII wrapper around mutex.
b4eec5c @hzeller o libboost caused too many troubles in embedded systems with weak
authored
66 class MutexLock {
67 public:
68 MutexLock(Mutex *m) : mutex_(m) { mutex_->Lock(); }
69 ~MutexLock() { mutex_->Unlock(); }
8054dc9 @hzeller o whitespace style.
authored
70
b4eec5c @hzeller o libboost caused too many troubles in embedded systems with weak
authored
71 private:
72 Mutex *const mutex_;
73 };
74
7689c9a @hzeller o preparation to extract classes from folve-filesystem into their
authored
75 } // namespece folve
76
77 #undef PRINTF_FMT_CHECK
c1a03f2 @hzeller o Needed convenient sub-second resolution time. Added CurrentTime()
authored
78
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
79 #endif // FOLVE_UTIL_H
Something went wrong with that request. Please try again.