/
mythmiscutil.h
139 lines (112 loc) · 3.65 KB
/
mythmiscutil.h
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#ifndef MYTHMISCUTIL_H_
#define MYTHMISCUTIL_H_
#include <algorithm>
#include <array>
#include <cstdint>
#include <ctime>
#include <QString>
#include <QDir>
#ifdef _WIN32
#undef mkdir
#endif
#include "mythbaseexp.h"
#include "mythsystem.h"
#if QT_VERSION < QT_VERSION_CHECK(5,10,0)
#include <QtGlobal>
#else
#include <QRandomGenerator>
#endif
MBASE_PUBLIC inline uint32_t MythRandom()
{
#if QT_VERSION < QT_VERSION_CHECK(5,10,0)
return static_cast<uint32_t>(qrand());
#else
return QRandomGenerator::global()->generate();
#endif
}
MBASE_PUBLIC bool getUptime(std::chrono::seconds &uptime);
MBASE_PUBLIC bool getMemStats(
int &totalMB, int &freeMB, int &totalVM, int &freeVM);
using loadArray = std::array<double,3>;
MBASE_PUBLIC loadArray getLoadAvgs(void);
MBASE_PUBLIC bool hasUtf8(const char *str);
#define M_QSTRING_UNICODE(str) hasUtf8(str) ? QString::fromUtf8(str) : str
MBASE_PUBLIC bool ping(const QString &host, std::chrono::milliseconds timeout);
MBASE_PUBLIC bool telnet(const QString &host, int port);
MBASE_PUBLIC long long copy(QFile &dst, QFile &src, uint block_size = 0);
MBASE_PUBLIC QString createTempFile(
QString name_template = "/tmp/mythtv_XXXXXX", bool dir = false);
MBASE_PUBLIC bool makeFileAccessible(const QString& filename);
MBASE_PUBLIC QString getResponse(const QString &query, const QString &def);
MBASE_PUBLIC int intResponse(const QString &query, int def);
MBASE_PUBLIC QString getSymlinkTarget(const QString &start_file,
QStringList *intermediaries = nullptr,
unsigned maxLinks = 255);
MBASE_PUBLIC void wrapList(QStringList &list, int width);
inline float clamp(float val, float minimum, float maximum)
{
return std::min(std::max(val, minimum), maximum);
}
inline int clamp(int val, int minimum, int maximum)
{
return std::min(std::max(val, minimum), maximum);
}
inline float lerp(float r, float a, float b)
{
return ((1.0F - r) * a) + (r * b);
}
inline int lerp(float r, int a, int b)
{
return (int) lerp(r, (float) a, (float) b);
}
inline float sq(float a) { return a*a; }
inline int sq(int a) { return a*a; }
static inline QString xml_bool_to_string(bool val)
{
return (val) ? "true" : "false";
}
MBASE_PUBLIC QString xml_indent(uint level);
MBASE_PUBLIC bool IsMACAddress(const QString& MAC);
MBASE_PUBLIC bool WakeOnLAN(const QString& MAC);
MBASE_PUBLIC bool MythWakeup(const QString &wakeUpCommand,
uint flags = kMSNone, std::chrono::seconds timeout = 0s);
MBASE_PUBLIC QString FileHash(const QString& filename);
/// Is A/V Sync destruction daemon is running on this host?
MBASE_PUBLIC bool IsPulseAudioRunning(void);
MBASE_PUBLIC bool myth_nice(int val);
MBASE_PUBLIC void myth_yield(void);
/// range -1..8, smaller is higher priority
MBASE_PUBLIC bool myth_ioprio(int val);
MBASE_PUBLIC bool MythRemoveDirectory(QDir &aDir);
MBASE_PUBLIC void setHttpProxy(void);
MBASE_PUBLIC int naturalCompare(const QString &_a, const QString &_b,
Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive);
// CPU Tick timing function
#ifdef MMX
#ifdef _WIN32
#include "compat.h"
inline void rdtsc(uint64_t &x)
{
QueryPerformanceCounter((LARGE_INTEGER*)(&x));
}
#else
struct timing_ab_t {
uint a;
uint b;
};
inline void rdtsc(uint64_t &x)
{
auto &y = (timing_ab_t&) x;
asm("rdtsc \n"
"mov %%eax, %0 \n"
"mov %%edx, %1 \n"
:
: "m"(y.a), "m"(y.b)
: "%eax", "%edx");
}
#endif
#else // if !MMX
inline void rdtsc(uint64_t &x) { x = 0ULL; }
#endif // !MMX
MBASE_PUBLIC QStringList MythSplitCommandString(const QString &line);
#endif // MYTHMISCUTIL_H_