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