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