2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 10:47:38 +00:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2015-10-03 13:16:42 +00:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2016-02-08 10:56:18 +00:00
|
|
|
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
class MTPlong;
|
|
|
|
namespace Logs {
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-02-29 16:53:26 +00:00
|
|
|
void start();
|
2016-01-11 15:43:29 +00:00
|
|
|
bool started();
|
2016-02-29 16:53:26 +00:00
|
|
|
void finish();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-01-17 05:01:14 +00:00
|
|
|
bool instanceChecked();
|
|
|
|
void multipleInstances();
|
|
|
|
|
2016-02-08 10:50:56 +00:00
|
|
|
void closeMain();
|
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
void writeMain(const QString &v);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
void writeDebug(const char *file, int32 line, const QString &v);
|
|
|
|
void writeTcp(const QString &v);
|
|
|
|
void writeMtp(int32 dc, const QString &v);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-01-17 05:01:14 +00:00
|
|
|
QString full();
|
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
inline const char *b(bool v) {
|
|
|
|
return v ? "[TRUE]" : "[FALSE]";
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
struct MemoryBuffer {
|
|
|
|
MemoryBuffer(const void *ptr, uint32 size) : p(ptr), s(size) {
|
|
|
|
}
|
|
|
|
QString str() const {
|
|
|
|
QString result;
|
|
|
|
const uchar *buf((const uchar*)p);
|
|
|
|
const char *hex = "0123456789ABCDEF";
|
|
|
|
result.reserve(s * 3);
|
|
|
|
for (uint32 i = 0; i < s; ++i) {
|
|
|
|
result += hex[(buf[i] >> 4)];
|
|
|
|
result += hex[buf[i] & 0x0F];
|
|
|
|
result += ' ';
|
|
|
|
}
|
|
|
|
result.chop(1);
|
|
|
|
return result;
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
const void *p;
|
|
|
|
uint32 s;
|
|
|
|
};
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
inline MemoryBuffer mb(const void *ptr, uint32 size) {
|
|
|
|
return MemoryBuffer(ptr, size);
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
QString vector(const QVector<MTPlong> &ids);
|
|
|
|
QString vector(const QVector<uint64> &ids);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
#define LOG(msg) (Logs::writeMain(QString msg))
|
2014-05-30 08:53:19 +00:00
|
|
|
//usage LOG(("log: %1 %2").arg(1).arg(2))
|
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
#define DEBUG_LOG(msg) { if (cDebug() || !Logs::started()) Logs::writeDebug(__FILE__, __LINE__, QString msg); }
|
|
|
|
//usage DEBUG_LOG(("log: %1 %2").arg(1).arg(2))
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
#define TCP_LOG(msg) { if (cDebug() || !Logs::started()) Logs::writeTcp(QString msg); }
|
|
|
|
//usage TCP_LOG(("log: %1 %2").arg(1).arg(2))
|
|
|
|
|
|
|
|
#define MTP_LOG(dc, msg) { if (cDebug() || !Logs::started()) Logs::writeMtp(dc, QString msg); }
|
|
|
|
//usage MTP_LOG(dc, ("log: %1 %2").arg(1).arg(2))
|
2016-01-21 06:58:58 +00:00
|
|
|
|
|
|
|
namespace SignalHandlers {
|
|
|
|
|
|
|
|
struct dump {
|
|
|
|
~dump();
|
|
|
|
};
|
|
|
|
const dump &operator<<(const dump &stream, const char *str);
|
2016-02-01 11:50:07 +00:00
|
|
|
const dump &operator<<(const dump &stream, const wchar_t *str);
|
2016-01-21 06:58:58 +00:00
|
|
|
const dump &operator<<(const dump &stream, int num);
|
2016-01-30 18:38:33 +00:00
|
|
|
const dump &operator<<(const dump &stream, unsigned int num);
|
|
|
|
const dump &operator<<(const dump &stream, unsigned long num);
|
|
|
|
const dump &operator<<(const dump &stream, unsigned long long num);
|
2016-01-30 18:24:18 +00:00
|
|
|
const dump &operator<<(const dump &stream, double num);
|
2016-01-21 06:58:58 +00:00
|
|
|
enum Status {
|
|
|
|
CantOpen,
|
|
|
|
LastCrashed,
|
|
|
|
Started
|
|
|
|
};
|
|
|
|
Status start();
|
|
|
|
Status restart(); // can be only CantOpen or Started
|
|
|
|
void finish();
|
|
|
|
|
2016-03-31 11:55:25 +00:00
|
|
|
void setCrashAnnotation(const std::string &key, const QString &value);
|
|
|
|
|
|
|
|
// Remembers value pointer and tries to add the value to the crash report.
|
|
|
|
// Attention! You should call clearCrashAnnotationRef(key) before destroying value.
|
|
|
|
void setCrashAnnotationRef(const std::string &key, const QString *valuePtr);
|
|
|
|
inline void clearCrashAnnotationRef(const std::string &key) {
|
|
|
|
setCrashAnnotationRef(key, nullptr);
|
|
|
|
}
|
2016-03-14 09:25:48 +00:00
|
|
|
|
2016-01-21 06:58:58 +00:00
|
|
|
}
|