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#include <memory>
30
31#include "compilerService.h"
32#include "compilerTypes.h"
33#include "drawingService.h"
34#include "drawingWidget.h"
35#include "fileService.h"
36#include "fileTypes.h"
37#include "runtimeService.h"
38#include "runtimeTypes.h"
39#include "runtimeView.h"
40#include "uiError.h"
41
49namespace nsbaci {
50
75class Controller : public QObject {
76 Q_OBJECT
77
78 public:
94 std::unique_ptr<nsbaci::services::DrawingService> d,
95 QObject* parent = nullptr);
96
102 ~Controller() = default;
103
104 signals:
109 void saveFailed(std::vector<UIError> errors);
110
115
120 void loadFailed(std::vector<UIError> errors);
121
126 void loadSucceeded(const QString& contents);
127
132 void compileFailed(std::vector<UIError> errors);
133
141
146 void runStarted(const QString& programName);
147
154 void runtimeStateChanged(bool running, bool halted);
155
161 void threadsUpdated(const std::vector<nsbaci::ui::ThreadInfo>& threads);
162
167 void variablesUpdated(const std::vector<nsbaci::ui::VariableInfo>& variables);
168
173 void outputReceived(const QString& output);
174
179 void inputRequested(const QString& prompt);
180
181 public slots:
188
194
205
214 void onRunRequested();
215
222 void onStepRequested();
223
228 void onStepThreadRequested(nsbaci::types::ThreadID threadId);
229
237
243 void onPauseRequested();
244
251 void onResetRequested();
252
258 void onStopRequested();
259
269 void onInputProvided(const QString& input);
270
271 private:
278 void updateRuntimeDisplay();
279
284 std::vector<nsbaci::ui::ThreadInfo> gatherThreadInfo();
285
290 std::vector<nsbaci::ui::VariableInfo> gatherVariableInfo();
291
299 void runBatch();
300
302 fileService;
304 compilerService;
306 runtimeService;
307 std::unique_ptr<nsbaci::services::DrawingService>
308 drawingService;
309 nsbaci::ui::DrawingWidget* drawingWidget =
310 nullptr;
311
312 QString currentProgramName;
313 bool programLoaded = false;
314 bool isRunning = false;
315 bool wasRunningBeforeInput =
316 false;
317 QTimer* runTimer = nullptr;
318};
319
320} // namespace nsbaci
321
322#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:235
~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:242
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:216
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:161
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:121
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:226
void onStepThreadRequested(nsbaci::types::ThreadID threadId)
Executes a single instruction on a specific thread.
Definition controller.cpp:141
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.