25 #include <QStringList> 47 if (!String.contains(
'-') && String.length() == 14)
50 return QDateTime::fromString(String, QStringLiteral(
"yyyyMMddhhmmss"));
53 return QDateTime::fromString(String, Qt::ISODate);
64 LARGE_INTEGER ticksPerSecond;
66 if (QueryPerformanceFrequency(&ticksPerSecond))
68 QueryPerformanceCounter(&ticks);
69 return (quint64)(((qreal)ticks.QuadPart / ticksPerSecond.QuadPart) * 1000000);
71 return GetTickCount() * 1000;
72 #elif defined(Q_OS_MAC) 73 struct timeval timenow;
74 gettimeofday(&timenow,
nullptr);
75 return (timenow.tv_sec * 1000000) + timenow.tv_usec;
78 clock_gettime(CLOCK_MONOTONIC, &timenow);
79 return (timenow.tv_sec * 1000000) + ((timenow.tv_nsec + 500) / 1000);
89 const char *
function = Context.function ? Context.function : __FUNCTION__;
90 const char *file = Context.file ? Context.file : __FILE__;
91 int line = Context.line ? Context.line : __LINE__;
93 int level = LOG_UNKNOWN;
96 case QtFatalMsg: level = LOG_CRIT;
break;
97 case QtDebugMsg: level = LOG_INFO;
break;
98 default: level = LOG_ERR;
104 file, line,
function,
105 Message.toLocal8Bit().constData());
108 if (LOG_CRIT == level)
110 QThread::msleep(100);
139 if (Source.size() < 0)
143 static const int chunksize = 16384;
144 char outputbuffer[chunksize];
147 stream.zalloc =
nullptr;
148 stream.zfree =
nullptr;
149 stream.opaque =
nullptr;
150 stream.avail_in = Source.size();
151 stream.next_in = (Bytef*)Source.data();
153 if (Z_OK != deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 15 + 16, 8, Z_DEFAULT_STRATEGY))
155 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Failed to setup zlip decompression"));
161 stream.avail_out = chunksize;
162 stream.next_out = (Bytef*)outputbuffer;
164 int error = deflate(&stream, Z_FINISH);
166 if (Z_NEED_DICT == error || error < Z_OK)
168 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Failed to compress data"));
173 result.append(outputbuffer, chunksize - stream.avail_out);
174 }
while (stream.avail_out == 0);
195 if (Source.size() < 0)
199 static const int chunksize = 32768;
200 char inputbuffer[chunksize];
201 char outputbuffer[chunksize];
204 stream.zalloc =
nullptr;
205 stream.zfree =
nullptr;
206 stream.opaque =
nullptr;
208 if (Z_OK != deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 15 + 16, 8, Z_DEFAULT_STRATEGY))
210 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Failed to setup zlip decompression"));
215 if (!Source.isOpen())
216 if (!Source.open(QIODevice::ReadOnly))
219 while (Source.bytesAvailable() > 0)
221 stream.avail_out = chunksize;
222 stream.next_out = (Bytef*)outputbuffer;
224 qint64 read = Source.read(inputbuffer, qMin(Source.bytesAvailable(), (qint64)chunksize));
228 stream.avail_in = read;
229 stream.next_in = (Bytef*)inputbuffer;
231 int error = deflate(&stream, Source.bytesAvailable() ? Z_SYNC_FLUSH : Z_FINISH);
233 if (error == Z_OK || error == Z_STREAM_END)
235 result.append(outputbuffer, chunksize - stream.avail_out);
240 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Failed to compress file"));
bool HasZlib(void)
Return true if zlib support is available.
quint64 GetMicrosecondCount(void)
Get the current system clock time in microseconds.
QDateTime DateTimeFromString(const QString &String)
Parse a QDateTime from the given QString.
void PrintLogLine(uint64_t mask, LogLevel level, const char *file, int line, const char *function, const char *format,...)
#define LOG(_MASK_, _LEVEL_, _STRING_)
QByteArray GZipCompressFile(QFile &Source)
Compress the given file using GZip.
QByteArray GZipCompress(QByteArray &Source)
Compress the supplied data using GZip.
void QtMessage(QtMsgType Type, const QMessageLogContext &Context, const QString &Message)
A handler routine for Qt messages.
#define VERBOSE_LEVEL_CHECK(_MASK_, _LEVEL_)