all repos — mgba @ d7fc09768d0c5771f11ad4cf1b40851e7a11a6aa

mGBA Game Boy Advance Emulator

src/platform/qt/LogController.h (view raw)

 1/* Copyright (c) 2013-2015 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#ifndef QGBA_LOG_CONTROLLER
 7#define QGBA_LOG_CONTROLLER
 8
 9#include "GBAApp.h"
10
11#include <mgba/core/log.h>
12
13#include <QObject>
14#include <QStringList>
15
16namespace QGBA {
17
18class LogController : public QObject {
19Q_OBJECT
20
21private:
22	class Stream {
23	public:
24		Stream(LogController* controller, int level, int category);
25		~Stream();
26
27		Stream& operator<<(const QString&);
28
29	private:
30		int m_level;
31		int m_category;
32		LogController* m_log;
33
34		QStringList m_queue;
35	};
36
37public:
38	LogController(int levels, QObject* parent = nullptr);
39
40	int levels() const { return m_filter.defaultLevels; }
41	mLogFilter* filter() { return &m_filter; }
42
43	Stream operator()(int category, int level);
44
45	static LogController* global();
46	static QString toString(int level);
47
48signals:
49	void logPosted(int level, int category, const QString& log);
50	void levelsSet(int levels);
51	void levelsEnabled(int levels);
52	void levelsDisabled(int levels);
53
54public slots:
55	void postLog(int level, int category, const QString& string);
56	void setLevels(int levels);
57	void enableLevels(int levels);
58	void disableLevels(int levels);
59
60private:
61	mLogFilter m_filter;
62
63	static LogController s_global;
64};
65
66#define LOG(C, L) (*LogController::global())(mLOG_ ## L, _mLOG_CAT_ ## C ())
67
68}
69
70#endif