![]() |
nsbaci 1.0
|
Central coordinator between UI and backend services. More...
#include <controller.h>


Public Slots | |
| void | onSaveRequested (nsbaci::types::File file, nsbaci::types::Text contents) |
| Handles a request to save source code to a file. | |
| void | onOpenRequested (nsbaci::types::File file) |
| Handles a request to open and load a source file. | |
| void | onCompileRequested (nsbaci::types::Text contents) |
| Handles a request to compile source code. | |
| void | onRunRequested () |
| Handles a request to load and prepare a compiled program for execution. | |
| void | onStepRequested () |
| Executes a single instruction across any ready thread. | |
| void | onStepThreadRequested (nsbaci::types::ThreadID threadId) |
| Executes a single instruction on a specific thread. | |
| void | onRunContinueRequested () |
| Starts or resumes continuous execution mode. | |
| void | onPauseRequested () |
| Pauses continuous execution. | |
| void | onResetRequested () |
| Resets the runtime to initial state. | |
| void | onStopRequested () |
| Stops execution and unloads the program. | |
| void | onInputProvided (const QString &input) |
| Provides user input to the runtime. | |
Signals | |
| void | saveFailed (std::vector< UIError > errors) |
| Emitted when a file save operation fails. | |
| void | saveSucceeded () |
| Emitted when a file save operation succeeds. | |
| void | loadFailed (std::vector< UIError > errors) |
| Emitted when a file load operation fails. | |
| void | loadSucceeded (const QString &contents) |
| Emitted when a file load operation succeeds. | |
| void | compileFailed (std::vector< UIError > errors) |
| Emitted when compilation fails. | |
| void | compileSucceeded () |
| Emitted when compilation succeeds. | |
| void | runStarted (const QString &programName) |
| Emitted when a program is loaded and ready for execution. | |
| void | runtimeStateChanged (bool running, bool halted) |
| Emitted when the runtime execution state changes. | |
| void | threadsUpdated (const std::vector< nsbaci::ui::ThreadInfo > &threads) |
| Emitted when thread information needs to be updated in the UI. | |
| 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 | inputRequested (const QString &prompt) |
| Emitted when the runtime needs user input (cin, read, etc.). | |
Public Member Functions | |
| 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. | |
| ~Controller ()=default | |
| Default destructor. | |
Central coordinator between UI and backend services.
The Controller class is a QObject that serves as the main application controller, implementing the MVC pattern. It receives user actions through Qt slots, processes them using the specific backend services, and communicates results back to the UI through Qt signals.
The controller owns instances of all required services:
Execution modes supported:
|
explicit |
Constructs the Controller with all required services.
Takes ownership of the provided services via move semantics. Initializes the internal QTimer used for continuous execution mode.
| f | FileService instance for file operations. |
| c | CompilerService instance for compilation. |
| r | RuntimeService instance for program execution. |
| d | DrawingService instance for graphical output (unique_ptr). |
| parent | Optional parent QObject for Qt memory management. |
|
default |
Default destructor.
The QTimer is automatically cleaned up through Qt's parent-child system.
|
signal |
Emitted when compilation fails.
| errors | List of compilation errors with line/column information. |

|
signal |
Emitted when compilation succeeds.
After this signal, the compiled program is ready to be loaded into the runtime via onRunRequested().

|
signal |
Emitted when the runtime needs user input (cin, read, etc.).
| prompt | The prompt message to display to the user. |

|
signal |
Emitted when a file load operation fails.
| errors | List of errors describing what went wrong. |

|
signal |
Emitted when a file load operation succeeds.
| contents | The loaded file contents as a QString. |

|
slot |
Handles a request to compile source code.
Compiles the provided source code into p-code instructions. On success, the instructions are stored in the CompilerService ready to be loaded into the runtime.
| contents | The BACI source code to compile. |

|
slot |
Provides user input to the runtime.
Called when the user enters input in response to an inputRequested signal. If the program was running continuously before the input request, execution is automatically resumed.
| input | The user-provided input string. |

|
slot |
Handles a request to open and load a source file.
| file | The file path to load. |

|
slot |
Pauses continuous execution.
Stops the execution timer but preserves program state for later resumption.

|
slot |
Resets the runtime to initial state.
Clears all thread state and memory but keeps the loaded program. The program can be re-run from the beginning.

|
slot |
Starts or resumes continuous execution mode.
Begins timer-based execution where batches of instructions are executed periodically, allowing the UI to remain responsive.


|
slot |
Handles a request to load and prepare a compiled program for execution.
Takes the compiled instructions and symbol table from the CompilerService and loads them into the RuntimeService. Sets up the output callback for forwarding runtime output to the UI.

|
slot |
Handles a request to save source code to a file.
| file | The target file path. |
| contents | The source code content to save. |

|
slot |
Executes a single instruction across any ready thread.
The scheduler picks the next thread to run and executes one instruction. Updates the UI with new thread and variable states.


|
slot |
Executes a single instruction on a specific thread.
| threadId | The ID of the thread to step. |

|
slot |
Stops execution and unloads the program.
Completely stops the runtime and marks no program as loaded.
|
signal |
Emitted when the runtime produces output (cout, writeln, etc.).
| output | The output string to display in the console. |

|
signal |
Emitted when a program is loaded and ready for execution.
| programName | The name of the loaded program. |

|
signal |
Emitted when the runtime execution state changes.
| running | True if the program is currently executing continuously. |
| halted | True if the program has terminated (reached Halt instruction). |

|
signal |
Emitted when a file save operation fails.
| errors | List of errors describing what went wrong. |

|
signal |
Emitted when thread information needs to be updated in the UI.
| threads | Current state of all threads including PC, state, and current instruction. |
|
signal |
Emitted when variable information needs to be updated in the UI.
| variables | Current values of all program variables. |