1
#ifndef MYTHMISCUTIL_H_
2
#define MYTHMISCUTIL_H_
14
#include "mythbaseexp.h"
15
#include "mythtimer.h"
16
#include "mythsystem.h"
17
#include "mythevent.h"
21
MBASE_PUBLIC QDateTime mythCurrentDateTime();
22
MBASE_PUBLIC int calc_utc_offset(void);
23
MBASE_PUBLIC QString getTimeZoneID(void);
24
MBASE_PUBLIC bool checkTimeZone(void);
25
MBASE_PUBLIC bool checkTimeZone(const QStringList &master_settings);
27
MBASE_PUBLIC QDateTime MythUTCToLocal(const QDateTime &utc);
28
MBASE_PUBLIC int MythSecsTo(const QDateTime &from, const QDateTime &to);
29
MBASE_PUBLIC QDateTime myth_dt_from_string(const QString &dtstr);
31
enum DateTimeFormat { kDateFull = 1,
34
kDateTimeFull = 5, ///< KDateFull | KTime
35
kDateTimeShort = 6, ///< KDateShort | KTime
37
kAddYear = 16, ///< Add year to string if not included
38
kSimplify = 32 ///< Show Today/Yesterday/Tomorrow instead of date
41
MBASE_PUBLIC QString MythDateTimeToString(const QDateTime &datetime,
42
uint format = kDateTimeFull);
43
MBASE_PUBLIC QString MythDateToString(const QDate &date,
44
uint format = kDateFull);
45
MBASE_PUBLIC QString MythTimeToString(const QTime &time,
48
MBASE_PUBLIC bool getUptime(time_t &uptime);
49
MBASE_PUBLIC bool getMemStats(int &totalMB, int &freeMB, int &totalVM, int &freeVM);
51
MBASE_PUBLIC bool hasUtf8(const char *str);
52
#define M_QSTRING_UNICODE(str) hasUtf8(str) ? QString::fromUtf8(str) : str
54
MBASE_PUBLIC bool ping(const QString &host, int timeout);
55
MBASE_PUBLIC bool telnet(const QString &host, int port);
57
MBASE_PUBLIC long long copy(QFile &dst, QFile &src, uint block_size = 0);
58
MBASE_PUBLIC QString createTempFile(QString name_template = "/tmp/mythtv_XXXXXX",
60
MBASE_PUBLIC void makeFileAccessible(QString filename);
62
MBASE_PUBLIC QString getResponse(const QString &query, const QString &def);
63
MBASE_PUBLIC int intResponse(const QString &query, int def);
65
MBASE_PUBLIC QString getSymlinkTarget(const QString &start_file,
66
QStringList *intermediaries = NULL,
67
unsigned maxLinks = 255);
69
MBASE_PUBLIC void sendPlaybackStart();
70
MBASE_PUBLIC void sendPlaybackEnd();
72
MBASE_PUBLIC void wrapList(QStringList &list, int width);
75
inline float clamp(float val, float minimum, float maximum)
77
return min(max(val, minimum), maximum);
79
inline int clamp(int val, int minimum, int maximum)
81
return min(max(val, minimum), maximum);
83
inline float lerp(float r, float a, float b)
85
return ((1.0f - r) * a) + (r * b);
87
inline int lerp(float r, int a, int b)
89
return (int) lerp(r, (float) a, (float) b);
91
inline float sq(float a) { return a*a; }
92
inline int sq(int a) { return a*a; }
94
static inline QString xml_bool_to_string(bool val)
96
return (val) ? "true" : "false";
99
MBASE_PUBLIC QString xml_indent(uint level);
101
MBASE_PUBLIC bool IsMACAddress(QString MAC);
102
MBASE_PUBLIC bool WakeOnLAN(QString MAC);
103
MBASE_PUBLIC QString FileHash(QString filename);
105
/// Is A/V Sync destruction daemon is running on this host?
106
MBASE_PUBLIC bool IsPulseAudioRunning(void);
108
MBASE_PUBLIC bool myth_nice(int val);
109
MBASE_PUBLIC void myth_yield(void);
110
MBASE_PUBLIC bool myth_ioprio(int val); // range -1..8, smaller is higher priority
112
MBASE_PUBLIC bool MythRemoveDirectory(QDir &aDir);
113
MBASE_PUBLIC QString &ShellEscape(QString &string);
115
MBASE_PUBLIC void setHttpProxy(void);
117
// CPU Tick timing function
121
inline void rdtsc(uint64_t &x)
123
QueryPerformanceCounter((LARGE_INTEGER*)(&x));
130
inline void rdtsc(uint64_t &x)
132
timing_ab_t &y = (timing_ab_t&) x;
143
inline void rdtsc(uint64_t &x) { x = 0ULL; }
146
#endif // MYTHMISCUTIL_H_