nsbaci 1.0
Loading...
Searching...
No Matches
controller.h
Go to the documentation of this file.
1
23
24#ifndef NSBACI_CONTROLLER_H
25#define NSBACI_CONTROLLER_H
26
27#include <QObject>
28#include <QTimer>
29
30#include <memory>
31
32#include "compilerService.h"
33#include "compilerTypes.h"
34#include "drawingService.h"
35#include "drawingWidget.h"
36#include "fileService.h"
37#include "fileTypes.h"
38#include "runtimeService.h"
39#include "runtimeTypes.h"
40#include "runtimeView.h"
41#include "uiError.h"
42
50namespace nsbaci {
51
76class Controller : public QObject {
77 Q_OBJECT
78
79 public:
95 std::unique_ptr<nsbaci::services::DrawingService> d,
96 QObject* parent = nullptr);
97
103 ~Controller() = default;
104
105 signals:
110 void saveFailed(std::vector<UIError> errors);
111
116
121 void loadFailed(std::vector<UIError> errors);
122
127 void loadSucceeded(const QString& contents);
128
133 void compileFailed(std::vector<UIError> errors);
134
142
147 void runStarted(const QString& programName);
148
155 void runtimeStateChanged(bool running, bool halted);
156
162 void threadsUpdated(const std::vector<nsbaci::ui::ThreadInfo>& threads);
163
168 void variablesUpdated(const std::vector<nsbaci::ui::VariableInfo>& variables);
169
174 void outputReceived(const QString& output);
175
180 void inputRequested(const QString& prompt);
181
182 public slots:
189
195
206
215 void onRunRequested();
216
223 void onStepRequested();
224
229 void onStepThreadRequested(nsbaci::types::ThreadID threadId);
230
238
244 void onPauseRequested();
245
252 void onResetRequested();
253
259 void onStopRequested();
260
270 void onInputProvided(const QString& input);
271
272 private:
279 void updateRuntimeDisplay();
280
285 std::vector<nsbaci::ui::ThreadInfo> gatherThreadInfo();
286
291 std::vector<nsbaci::ui::VariableInfo> gatherVariableInfo();
292
300 void runBatch();
301
303 fileService;
305 compilerService;
307 runtimeService;
308 std::unique_ptr<nsbaci::services::DrawingService>
309 drawingService;
311 drawingWidget = nullptr;
312
313 QString currentProgramName;
314 bool programLoaded = false;
315 bool isRunning = false;
316 bool wasRunningBeforeInput =
317 false;
318 QTimer* runTimer = nullptr;
319};
320
321} // namespace nsbaci
322
323#endif // NSBACI_CONTROLLER_H
void loadSucceeded(const QString &contents)
Emitted when a file load operation succeeds.
void runStarted(const QString &programName)
Emitted when a program is loaded and ready for execution.
void onStopRequested()
Stops execution and unloads the program.
Definition controller.cpp:236
~Controller()=default
Default destructor.
void saveSucceeded()
Emitted when a file save operation succeeds.
void onInputProvided(const QString &input)
Provides user input to the runtime.
Definition controller.cpp:243
void onRunRequested()
Handles a request to load and prepare a compiled program for execution.
Definition controller.cpp:75
void compileFailed(std::vector< UIError > errors)
Emitted when compilation fails.
void onSaveRequested(nsbaci::types::File file, nsbaci::types::Text contents)
Handles a request to save source code to a file.
Definition controller.cpp:41
void onPauseRequested()
Pauses continuous execution.
Definition controller.cpp:217
void compileSucceeded()
Emitted when compilation succeeds.
Controller(nsbaci::services::FileService &&f, nsbaci::services::CompilerService &&c, nsbaci::services::RuntimeService &&r, std::unique_ptr< nsbaci::services::DrawingService > d, QObject *parent=nullptr)
Constructs the Controller with all required services.
Definition controller.cpp:28
void variablesUpdated(const std::vector< nsbaci::ui::VariableInfo > &variables)
Emitted when variable information needs to be updated in the UI.
void outputReceived(const QString &output)
Emitted when the runtime produces output (cout, writeln, etc.).
void saveFailed(std::vector< UIError > errors)
Emitted when a file save operation fails.
void runtimeStateChanged(bool running, bool halted)
Emitted when the runtime execution state changes.
void loadFailed(std::vector< UIError > errors)
Emitted when a file load operation fails.
void onOpenRequested(nsbaci::types::File file)
Handles a request to open and load a source file.
Definition controller.cpp:52
void onRunContinueRequested()
Starts or resumes continuous execution mode.
Definition controller.cpp:162
void onCompileRequested(nsbaci::types::Text contents)
Handles a request to compile source code.
Definition controller.cpp:63
void threadsUpdated(const std::vector< nsbaci::ui::ThreadInfo > &threads)
Emitted when thread information needs to be updated in the UI.
void onStepRequested()
Executes a single instruction across any ready thread.
Definition controller.cpp:122
void inputRequested(const QString &prompt)
Emitted when the runtime needs user input (cin, read, etc.).
void onResetRequested()
Resets the runtime to initial state.
Definition controller.cpp:227
void onStepThreadRequested(nsbaci::types::ThreadID threadId)
Executes a single instruction on a specific thread.
Definition controller.cpp:142
service for compiling nsbaci (or maybe other stuff in the future) source code.
Definition compilerService.h:61
Service for handling file system operations on BACI source files.
Definition fileService.h:181
Service that manages program execution.
Definition runtimeService.h:104
Qt widget that provides a drawing canvas.
Definition drawingWidget.h:39
CompilerService class declaration for nsbaci.
Type definitions for compiler-related operations.
DrawingService class declaration for nsbaci.
DrawingWidget class declaration for nsbaci.
FileService class declaration for nsbaci.
Type definitions for file-related operations.
fs::path File
Alias for file system paths.
Definition fileTypes.h:35
std::string Text
Alias for text content (file contents, source code, etc.).
Definition fileTypes.h:30
Root namespace for the nsbaci application.
Definition controller.cpp:26
RuntimeService class declaration for nsbaci.
Type definitions for runtime-related operations.
RuntimeView widget declaration for nsbaci.
UI Error type definitions for nsbaci.