all repos — mgba @ 74bb02065d232108192b41eb80e2889e000457bf

mGBA Game Boy Advance Emulator

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

 1/* Copyright (c) 2013-2016 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_DEBUGGER_CONSOLE_CONTROLLER
 7#define QGBA_DEBUGGER_CONSOLE_CONTROLLER
 8
 9#include "DebuggerController.h"
10
11#include <QMutex>
12#include <QStringList>
13#include <QWaitCondition>
14
15extern "C" {
16#include "debugger/cli-debugger.h"
17}
18
19namespace QGBA {
20
21class GameController;
22
23class DebuggerConsoleController : public DebuggerController {
24Q_OBJECT
25
26public:
27	DebuggerConsoleController(GameController* controller, QObject* parent = nullptr);
28
29signals:
30	void log(const QString&);
31	void lineAppend(const QString&);
32
33public slots:
34	void enterLine(const QString&);
35
36protected:
37	virtual void attachInternal() override;
38
39private:
40	static void printf(struct CLIDebuggerBackend* be, const char* fmt, ...);
41	static void init(struct CLIDebuggerBackend* be);
42	static void deinit(struct CLIDebuggerBackend* be);
43	static const char* readLine(struct CLIDebuggerBackend* be, size_t* len);
44	static void lineAppend(struct CLIDebuggerBackend* be, const char* line);
45	static const char* historyLast(struct CLIDebuggerBackend* be, size_t* len);
46	static void historyAppend(struct CLIDebuggerBackend* be, const char* line);
47
48	CLIDebugger m_cliDebugger;
49
50	QMutex m_mutex;
51	QWaitCondition m_cond;
52	QStringList m_history;
53	QStringList m_lines;
54	QByteArray m_last;
55
56	struct Backend {
57		CLIDebuggerBackend d;
58		DebuggerConsoleController* self;
59	} m_backend;
60};
61
62}
63
64#endif