MythTV  master
mythmiscutil.h
Go to the documentation of this file.
1 #ifndef MYTHMISCUTIL_H_
2 #define MYTHMISCUTIL_H_
3 
4 #include <algorithm>
5 #include <array>
6 #include <cstdint>
7 #include <ctime>
8 
9 #include <QString>
10 #include <QDir>
11 
12 #ifdef _WIN32
13  #undef mkdir
14 #endif
15 
16 #include "mythbaseexp.h"
17 #include "mythsystem.h"
18 
19 MBASE_PUBLIC bool getUptime(std::chrono::seconds &uptime);
21  int &totalMB, int &freeMB, int &totalVM, int &freeVM);
22 using loadArray = std::array<double,3>;
24 
25 MBASE_PUBLIC bool hasUtf8(const char *str);
26 #define M_QSTRING_UNICODE(str) hasUtf8(str) ? QString::fromUtf8(str) : str
27 
28 MBASE_PUBLIC bool ping(const QString &host, std::chrono::milliseconds timeout);
29 MBASE_PUBLIC bool telnet(const QString &host, int port);
30 
31 namespace MythFile
32 {
33 MBASE_PUBLIC long long copy(QFile &dst, QFile &src, uint block_size = 0);
34 } // namespace MythFile
36  QString name_template = "/tmp/mythtv_XXXXXX", bool dir = false);
37 MBASE_PUBLIC bool makeFileAccessible(const QString& filename);
38 
39 MBASE_PUBLIC QString getResponse(const QString &query, const QString &def);
40 MBASE_PUBLIC int intResponse(const QString &query, int def);
41 
42 MBASE_PUBLIC QString getSymlinkTarget(const QString &start_file,
43  QStringList *intermediaries = nullptr,
44  unsigned maxLinks = 255);
45 
46 static inline QString xml_bool_to_string(bool val)
47 {
48  return (val) ? "true" : "false";
49 }
50 
51 MBASE_PUBLIC QString xml_indent(uint level);
52 
53 MBASE_PUBLIC bool IsMACAddress(const QString& MAC);
54 MBASE_PUBLIC bool WakeOnLAN(const QString& MAC);
55 MBASE_PUBLIC bool MythWakeup(const QString &wakeUpCommand,
56  uint flags = kMSNone, std::chrono::seconds timeout = 0s);
57 
58 MBASE_PUBLIC QString FileHash(const QString& filename);
59 
62 
63 MBASE_PUBLIC bool myth_nice(int val);
64 MBASE_PUBLIC void myth_yield(void);
66 MBASE_PUBLIC bool myth_ioprio(int val);
67 
68 MBASE_PUBLIC bool MythRemoveDirectory(QDir &aDir);
69 
70 MBASE_PUBLIC void setHttpProxy(void);
71 
72 MBASE_PUBLIC int naturalCompare(const QString &_a, const QString &_b,
73  Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive);
74 
75 // CPU Tick timing function
76 #ifdef MMX
77 #ifdef _WIN32
78 #include "compat.h"
79 inline void rdtsc(uint64_t &x)
80 {
81  QueryPerformanceCounter((LARGE_INTEGER*)(&x));
82 }
83 #else
84 struct timing_ab_t {
85  uint a;
86  uint b;
87 };
88 inline void rdtsc(uint64_t &x)
89 {
90  auto &y = (timing_ab_t&) x;
91  asm("rdtsc \n"
92  "mov %%eax, %0 \n"
93  "mov %%edx, %1 \n"
94  :
95  : "m"(y.a), "m"(y.b)
96  : "%eax", "%edx");
97 }
98 #endif
99 
100 #else // if !MMX
101 inline void rdtsc(uint64_t &x) { x = 0ULL; }
102 #endif // !MMX
103 
104 #endif // MYTHMISCUTIL_H_
IsMACAddress
MBASE_PUBLIC bool IsMACAddress(const QString &MAC)
Definition: mythmiscutil.cpp:554
hasUtf8
MBASE_PUBLIC bool hasUtf8(const char *str)
Guess whether a string is UTF-8.
Definition: mythmiscutil.cpp:198
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
getLoadAvgs
MBASE_PUBLIC loadArray getLoadAvgs(void)
Returns the system load averages.
Definition: mythmiscutil.cpp:181
xml_indent
MBASE_PUBLIC QString xml_indent(uint level)
Definition: mythmiscutil.cpp:966
mythbaseexp.h
myth_yield
MBASE_PUBLIC void myth_yield(void)
Definition: mythmiscutil.cpp:721
MythFile
Definition: mythmiscutil.h:31
IsPulseAudioRunning
MBASE_PUBLIC bool IsPulseAudioRunning(void)
Is A/V Sync destruction daemon is running on this host?
Definition: mythmiscutil.cpp:689
rdtsc
void rdtsc(uint64_t &x)
Definition: mythmiscutil.h:79
getSymlinkTarget
MBASE_PUBLIC QString getSymlinkTarget(const QString &start_file, QStringList *intermediaries=nullptr, unsigned maxLinks=255)
Definition: mythmiscutil.cpp:502
mythsystem.h
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
telnet
MBASE_PUBLIC bool telnet(const QString &host, int port)
Can we talk to port on host?
Definition: mythmiscutil.cpp:283
getResponse
MBASE_PUBLIC QString getResponse(const QString &query, const QString &def)
In an interactive shell, prompt the user to input a string.
Definition: mythmiscutil.cpp:461
MythFile::copy
MBASE_PUBLIC long long copy(QFile &dst, QFile &src, uint block_size=0)
Copies src file to dst file.
Definition: mythmiscutil.cpp:314
WakeOnLAN
MBASE_PUBLIC bool WakeOnLAN(const QString &MAC)
Definition: mythmiscutil.cpp:640
getMemStats
MBASE_PUBLIC bool getMemStats(int &totalMB, int &freeMB, int &totalVM, int &freeVM)
Returns memory statistics in megabytes.
Definition: mythmiscutil.cpp:114
createTempFile
MBASE_PUBLIC QString createTempFile(QString name_template="/tmp/mythtv_XXXXXX", bool dir=false)
Definition: mythmiscutil.cpp:374
compat.h
MythRemoveDirectory
MBASE_PUBLIC bool MythRemoveDirectory(QDir &aDir)
Definition: mythmiscutil.cpp:813
naturalCompare
MBASE_PUBLIC int naturalCompare(const QString &_a, const QString &_b, Qt::CaseSensitivity caseSensitivity=Qt::CaseSensitive)
Definition: mythmiscutil.cpp:992
loadArray
std::array< double, 3 > loadArray
Definition: mythmiscutil.h:22
MythWakeup
MBASE_PUBLIC bool MythWakeup(const QString &wakeUpCommand, uint flags=kMSNone, std::chrono::seconds timeout=0s)
Definition: mythmiscutil.cpp:681
myth_ioprio
MBASE_PUBLIC bool myth_ioprio(int val)
range -1..8, smaller is higher priority
Definition: mythmiscutil.cpp:809
uint
unsigned int uint
Definition: compat.h:144
ping
MBASE_PUBLIC bool ping(const QString &host, std::chrono::milliseconds timeout)
Can we ping host within timeout seconds?
Definition: mythmiscutil.cpp:250
xml_bool_to_string
static QString xml_bool_to_string(bool val)
Definition: mythmiscutil.h:46
FileHash
MBASE_PUBLIC QString FileHash(const QString &filename)
Definition: mythmiscutil.cpp:599
block_size
unsigned int block_size
Definition: freesurround.cpp:47
intResponse
MBASE_PUBLIC int intResponse(const QString &query, int def)
In an interactive shell, prompt the user to input a number.
Definition: mythmiscutil.cpp:491
kMSNone
@ kMSNone
Definition: mythsystem.h:35
myth_nice
MBASE_PUBLIC bool myth_nice(int val)
Definition: mythmiscutil.cpp:707
getUptime
MBASE_PUBLIC bool getUptime(std::chrono::seconds &uptime)
Definition: mythmiscutil.cpp:71
setHttpProxy
MBASE_PUBLIC void setHttpProxy(void)
Get network proxy settings from OS, and use for [Q]Http[Comms].
Definition: mythmiscutil.cpp:857
build_compdb.filename
filename
Definition: build_compdb.py:21
makeFileAccessible
MBASE_PUBLIC bool makeFileAccessible(const QString &filename)
Definition: mythmiscutil.cpp:446