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 ping(const QString &host, std::chrono::milliseconds timeout);
26 MBASE_PUBLIC bool telnet(const QString &host, int port);
27 
28 namespace MythFile
29 {
30 MBASE_PUBLIC long long copy(QFile &dst, QFile &src, uint block_size = 0);
31 } // namespace MythFile
33  QString name_template = "/tmp/mythtv_XXXXXX", bool dir = false);
34 MBASE_PUBLIC bool makeFileAccessible(const QString& filename);
35 
36 MBASE_PUBLIC QString getResponse(const QString &query, const QString &def);
37 MBASE_PUBLIC int intResponse(const QString &query, int def);
38 
39 MBASE_PUBLIC QString getSymlinkTarget(const QString &start_file,
40  QStringList *intermediaries = nullptr,
41  unsigned maxLinks = 255);
42 
43 MBASE_PUBLIC bool IsMACAddress(const QString& MAC);
44 MBASE_PUBLIC bool WakeOnLAN(const QString& MAC);
45 MBASE_PUBLIC bool MythWakeup(const QString &wakeUpCommand,
46  uint flags = kMSNone, std::chrono::seconds timeout = 0s);
47 
48 MBASE_PUBLIC QString FileHash(const QString& filename);
49 
52 
53 MBASE_PUBLIC bool myth_nice(int val);
54 MBASE_PUBLIC void myth_yield(void);
56 MBASE_PUBLIC bool myth_ioprio(int val);
57 
58 MBASE_PUBLIC bool MythRemoveDirectory(QDir &aDir);
59 
60 MBASE_PUBLIC void setHttpProxy(void);
61 
62 // CPU Tick timing function
63 #ifdef MMX
64 #ifdef _WIN32
65 #include "compat.h"
66 inline void rdtsc(uint64_t &x)
67 {
68  QueryPerformanceCounter((LARGE_INTEGER*)(&x));
69 }
70 #else
71 struct timing_ab_t {
72  uint a;
73  uint b;
74 };
75 inline void rdtsc(uint64_t &x)
76 {
77  auto &y = (timing_ab_t&) x;
78  asm("rdtsc \n"
79  "mov %%eax, %0 \n"
80  "mov %%edx, %1 \n"
81  :
82  : "m"(y.a), "m"(y.b)
83  : "%eax", "%edx");
84 }
85 #endif
86 
87 #else // if !MMX
88 inline void rdtsc(uint64_t &x) { x = 0ULL; }
89 #endif // !MMX
90 
91 #endif // MYTHMISCUTIL_H_
IsMACAddress
MBASE_PUBLIC bool IsMACAddress(const QString &MAC)
Definition: mythmiscutil.cpp:504
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
getLoadAvgs
MBASE_PUBLIC loadArray getLoadAvgs(void)
Returns the system load averages.
Definition: mythmiscutil.cpp:176
mythbaseexp.h
myth_yield
MBASE_PUBLIC void myth_yield(void)
Definition: mythmiscutil.cpp:671
MythFile
Definition: mythmiscutil.h:28
IsPulseAudioRunning
MBASE_PUBLIC bool IsPulseAudioRunning(void)
Is A/V Sync destruction daemon is running on this host?
Definition: mythmiscutil.cpp:639
rdtsc
void rdtsc(uint64_t &x)
Definition: mythmiscutil.h:66
getSymlinkTarget
MBASE_PUBLIC QString getSymlinkTarget(const QString &start_file, QStringList *intermediaries=nullptr, unsigned maxLinks=255)
Definition: mythmiscutil.cpp:452
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:233
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:411
MythFile::copy
MBASE_PUBLIC long long copy(QFile &dst, QFile &src, uint block_size=0)
Copies src file to dst file.
Definition: mythmiscutil.cpp:264
WakeOnLAN
MBASE_PUBLIC bool WakeOnLAN(const QString &MAC)
Definition: mythmiscutil.cpp:590
getMemStats
MBASE_PUBLIC bool getMemStats(int &totalMB, int &freeMB, int &totalVM, int &freeVM)
Returns memory statistics in megabytes.
Definition: mythmiscutil.cpp:109
createTempFile
MBASE_PUBLIC QString createTempFile(QString name_template="/tmp/mythtv_XXXXXX", bool dir=false)
Definition: mythmiscutil.cpp:324
compat.h
MythRemoveDirectory
MBASE_PUBLIC bool MythRemoveDirectory(QDir &aDir)
Definition: mythmiscutil.cpp:752
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:631
myth_ioprio
MBASE_PUBLIC bool myth_ioprio(int val)
range -1..8, smaller is higher priority
Definition: mythmiscutil.cpp:748
uint
unsigned int uint
Definition: compat.h:79
ping
MBASE_PUBLIC bool ping(const QString &host, std::chrono::milliseconds timeout)
Can we ping host within timeout seconds?
Definition: mythmiscutil.cpp:200
FileHash
MBASE_PUBLIC QString FileHash(const QString &filename)
Definition: mythmiscutil.cpp:549
block_size
unsigned int block_size
Definition: freesurround.cpp:48
intResponse
MBASE_PUBLIC int intResponse(const QString &query, int def)
In an interactive shell, prompt the user to input a number.
Definition: mythmiscutil.cpp:441
kMSNone
@ kMSNone
Definition: mythsystem.h:35
myth_nice
MBASE_PUBLIC bool myth_nice(int val)
Definition: mythmiscutil.cpp:657
getUptime
MBASE_PUBLIC bool getUptime(std::chrono::seconds &uptime)
Definition: mythmiscutil.cpp:66
setHttpProxy
MBASE_PUBLIC void setHttpProxy(void)
Get network proxy settings from OS, and use for [Q]Http[Comms].
Definition: mythmiscutil.cpp:796
build_compdb.filename
filename
Definition: build_compdb.py:21
makeFileAccessible
MBASE_PUBLIC bool makeFileAccessible(const QString &filename)
Definition: mythmiscutil.cpp:396