-
Notifications
You must be signed in to change notification settings - Fork 14
/
util.hpp
78 lines (63 loc) · 2.16 KB
/
util.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef __UTIL_HPP__
#define __UTIL_HPP__
/**************************************************************************
*
* This file is part of Chiton.
*
* Chiton is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Chiton is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Chiton. If not, see <https://www.gnu.org/licenses/>.
*
* Copyright 2020 Ed Martin <[email protected]>
*
**************************************************************************
*/
#include <iostream>
#include <mutex>
#include <time.h>
enum LOG_LEVEL {
LOG_DEBUG,
LOG_INFO,
LOG_WARN,
LOG_ERROR,
LOG_FATAL,
};
//basic macros
#define LDEBUG(str) Util::log_msg(LOG_DEBUG, str)
#define LINFO(str) Util::log_msg(LOG_INFO, str)
#define LWARN(str) Util::log_msg(LOG_WARN, str)
#define LERROR(str) Util::log_msg(LOG_ERROR, str)
#define LFATAL(str) Util::log_msg(LOG_FATAL, str)
struct VideoDate {
unsigned int year;
unsigned int month;
unsigned int day;
unsigned int hour;
unsigned int min;
unsigned int sec;
unsigned int ms;
};
class Util {
public:
/*
* Log a message
*/
static void log_msg(const LOG_LEVEL lvl, const std::string& msg);
static void get_videotime(struct timeval &time);//write the current time out
static void get_time_parts(struct timeval &time, struct VideoDate &date);//write the time out to date format
//pack and unpack time for database storage, spits out a 64-bit unsigned int
static unsigned long long int pack_time(const struct timeval &time);
static void unpack_time(const unsigned long long int packed_time, struct timeval &time);
private:
static std::mutex lock;//lock for actually printing messages
};
#endif