all repos — mgba @ 4c38f769565e8ddd7d3a8eef1a41975206c129a0

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 <QObject>
12#include <QStringList>
13
14extern "C" {
15#include "gba/gba.h"
16}
17
18namespace QGBA {
19
20class LogController : public QObject {
21Q_OBJECT
22
23private:
24	class Stream {
25	public:
26		Stream(LogController* controller, int level, int category);
27		~Stream();
28
29		Stream& operator<<(const QString&);
30
31	private:
32		int m_level;
33		int m_category;
34		LogController* m_log;
35
36		QStringList m_queue;
37	};
38
39public:
40	LogController(int levels, QObject* parent = nullptr);
41
42	int levels() const { return m_logLevel; }
43
44	Stream operator()(int category, int level);
45
46	static LogController* global();
47	static QString toString(int level);
48
49signals:
50	void logPosted(int level, int category, const QString& log);
51	void levelsSet(int levels);
52	void levelsEnabled(int levels);
53	void levelsDisabled(int levels);
54
55public slots:
56	void postLog(int level, int category, const QString& string);
57	void setLevels(int levels);
58	void enableLevels(int levels);
59	void disableLevels(int levels);
60
61private:
62	int m_logLevel;
63
64	static LogController s_global;
65};
66
67#define LOG(C, L) (*LogController::global())(_mLOG_CAT_ ## C (), mLOG_ ## L)
68
69}
70
71#endif