diff options
Diffstat (limited to 'async/src/debug.h')
-rw-r--r-- | async/src/debug.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/async/src/debug.h b/async/src/debug.h new file mode 100644 index 0000000..c453eb3 --- /dev/null +++ b/async/src/debug.h | |||
@@ -0,0 +1,80 @@ | |||
1 | /* | ||
2 | * Copyright 2015 Daniel Vrátil <dvratil@redhat.com> | ||
3 | * | ||
4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Library General Public License as | ||
6 | * published by the Free Software Foundation; either version 2 of | ||
7 | * the License, or (at your option) any later version. | ||
8 | * | ||
9 | * This library is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU Library General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU Library General Public License | ||
15 | * along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #ifndef ASYNC_DEBUG_H | ||
19 | #define ASYNC_DEBUG_H | ||
20 | |||
21 | #include <QLoggingCategory> | ||
22 | #include <QStringBuilder> | ||
23 | |||
24 | #ifndef QT_NO_DEBUG | ||
25 | #include <typeinfo> | ||
26 | #endif | ||
27 | |||
28 | namespace Async | ||
29 | { | ||
30 | |||
31 | Q_DECLARE_LOGGING_CATEGORY(Debug) | ||
32 | Q_DECLARE_LOGGING_CATEGORY(Trace) | ||
33 | |||
34 | QString demangleName(const char *name); | ||
35 | |||
36 | namespace Private | ||
37 | { | ||
38 | class Execution; | ||
39 | } | ||
40 | |||
41 | class Tracer | ||
42 | { | ||
43 | public: | ||
44 | Tracer(Private::Execution *execution); | ||
45 | ~Tracer(); | ||
46 | |||
47 | private: | ||
48 | enum MsgType { | ||
49 | Start, | ||
50 | End | ||
51 | }; | ||
52 | void msg(MsgType); | ||
53 | |||
54 | int mId; | ||
55 | Private::Execution *mExecution; | ||
56 | |||
57 | static int lastId; | ||
58 | }; | ||
59 | |||
60 | } | ||
61 | |||
62 | #ifndef QT_NO_DEBUG | ||
63 | template<typename T> | ||
64 | QString storeExecutorNameExpanded() { | ||
65 | return Async::demangleName(typeid(T).name()); | ||
66 | } | ||
67 | |||
68 | template<typename T, typename ... Tail> | ||
69 | typename std::enable_if<sizeof ... (Tail) != 0, QString>::type | ||
70 | storeExecutorNameExpanded() { | ||
71 | return storeExecutorNameExpanded<T>() % QStringLiteral(", ") % storeExecutorNameExpanded<Tail ...>(); | ||
72 | } | ||
73 | |||
74 | #define STORE_EXECUTOR_NAME(name, ...) \ | ||
75 | ExecutorBase::mExecutorName = QStringLiteral(name) % QStringLiteral("<") % storeExecutorNameExpanded<__VA_ARGS__>() % QStringLiteral(">") | ||
76 | #else | ||
77 | #define STORE_EXECUTOR_NAME(...) | ||
78 | #endif | ||
79 | |||
80 | #endif // ASYNC_DEBUG_H \ No newline at end of file | ||