nsbaci 1.0
Loading...
Searching...
No Matches
nsbaci::Controller Class Reference

Central coordinator between UI and backend services. More...

#include <controller.h>

Inheritance diagram for nsbaci::Controller:
Collaboration diagram for nsbaci::Controller:

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.

Detailed Description

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:

  • FileService: Handles file system operations
  • CompilerService: Compiles NsBaci source code to p-code
  • RuntimeService: Executes compiled programs with thread scheduling
  • DrawingService: Not yet implemented, but will be used as graphical API in the future

Execution modes supported:

  • Single-step execution: Execute one instruction at a time
  • Continuous execution: Run program with timer-based batching
  • Thread-specific stepping: Execute a single thread's instruction
Note
The controller uses a QTimer for continuous execution to maintain UI responsiveness during long-running programs.

Constructor & Destructor Documentation

◆ Controller()

nsbaci::Controller::Controller ( nsbaci::services::FileService && f,
nsbaci::services::CompilerService && c,
nsbaci::services::RuntimeService && r,
std::unique_ptr< nsbaci::services::DrawingService > d,
QObject * parent = nullptr )
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.

Parameters
fFileService instance for file operations.
cCompilerService instance for compilation.
rRuntimeService instance for program execution.
dDrawingService instance for graphical output (unique_ptr).
parentOptional parent QObject for Qt memory management.

◆ ~Controller()

nsbaci::Controller::~Controller ( )
default

Default destructor.

The QTimer is automatically cleaned up through Qt's parent-child system.

Member Function Documentation

◆ compileFailed

void nsbaci::Controller::compileFailed ( std::vector< UIError > errors)
signal

Emitted when compilation fails.

Parameters
errorsList of compilation errors with line/column information.
Here is the caller graph for this function:

◆ compileSucceeded

void nsbaci::Controller::compileSucceeded ( )
signal

Emitted when compilation succeeds.

After this signal, the compiled program is ready to be loaded into the runtime via onRunRequested().

Here is the caller graph for this function:

◆ inputRequested

void nsbaci::Controller::inputRequested ( const QString & prompt)
signal

Emitted when the runtime needs user input (cin, read, etc.).

Parameters
promptThe prompt message to display to the user.
Here is the caller graph for this function:

◆ loadFailed

void nsbaci::Controller::loadFailed ( std::vector< UIError > errors)
signal

Emitted when a file load operation fails.

Parameters
errorsList of errors describing what went wrong.
Here is the caller graph for this function:

◆ loadSucceeded

void nsbaci::Controller::loadSucceeded ( const QString & contents)
signal

Emitted when a file load operation succeeds.

Parameters
contentsThe loaded file contents as a QString.
Here is the caller graph for this function:

◆ onCompileRequested

void nsbaci::Controller::onCompileRequested ( nsbaci::types::Text contents)
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.

Parameters
contentsThe BACI source code to compile.
Here is the call graph for this function:

◆ onInputProvided

void nsbaci::Controller::onInputProvided ( const QString & input)
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.

Parameters
inputThe user-provided input string.
Here is the call graph for this function:

◆ onOpenRequested

void nsbaci::Controller::onOpenRequested ( nsbaci::types::File file)
slot

Handles a request to open and load a source file.

Parameters
fileThe file path to load.
Here is the call graph for this function:

◆ onPauseRequested

void nsbaci::Controller::onPauseRequested ( )
slot

Pauses continuous execution.

Stops the execution timer but preserves program state for later resumption.

Here is the call graph for this function:

◆ onResetRequested

void nsbaci::Controller::onResetRequested ( )
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.

Here is the call graph for this function:

◆ onRunContinueRequested

void nsbaci::Controller::onRunContinueRequested ( )
slot

Starts or resumes continuous execution mode.

Begins timer-based execution where batches of instructions are executed periodically, allowing the UI to remain responsive.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onRunRequested

void nsbaci::Controller::onRunRequested ( )
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.

Here is the call graph for this function:

◆ onSaveRequested

void nsbaci::Controller::onSaveRequested ( nsbaci::types::File file,
nsbaci::types::Text contents )
slot

Handles a request to save source code to a file.

Parameters
fileThe target file path.
contentsThe source code content to save.
Here is the call graph for this function:

◆ onStepRequested

void nsbaci::Controller::onStepRequested ( )
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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onStepThreadRequested

void nsbaci::Controller::onStepThreadRequested ( nsbaci::types::ThreadID threadId)
slot

Executes a single instruction on a specific thread.

Parameters
threadIdThe ID of the thread to step.
Here is the call graph for this function:

◆ onStopRequested

void nsbaci::Controller::onStopRequested ( )
slot

Stops execution and unloads the program.

Completely stops the runtime and marks no program as loaded.

◆ outputReceived

void nsbaci::Controller::outputReceived ( const QString & output)
signal

Emitted when the runtime produces output (cout, writeln, etc.).

Parameters
outputThe output string to display in the console.
Here is the caller graph for this function:

◆ runStarted

void nsbaci::Controller::runStarted ( const QString & programName)
signal

Emitted when a program is loaded and ready for execution.

Parameters
programNameThe name of the loaded program.
Here is the caller graph for this function:

◆ runtimeStateChanged

void nsbaci::Controller::runtimeStateChanged ( bool running,
bool halted )
signal

Emitted when the runtime execution state changes.

Parameters
runningTrue if the program is currently executing continuously.
haltedTrue if the program has terminated (reached Halt instruction).
Here is the caller graph for this function:

◆ saveFailed

void nsbaci::Controller::saveFailed ( std::vector< UIError > errors)
signal

Emitted when a file save operation fails.

Parameters
errorsList of errors describing what went wrong.
Here is the caller graph for this function:

◆ threadsUpdated

void nsbaci::Controller::threadsUpdated ( const std::vector< nsbaci::ui::ThreadInfo > & threads)
signal

Emitted when thread information needs to be updated in the UI.

Parameters
threadsCurrent state of all threads including PC, state, and current instruction.

◆ variablesUpdated

void nsbaci::Controller::variablesUpdated ( const std::vector< nsbaci::ui::VariableInfo > & variables)
signal

Emitted when variable information needs to be updated in the UI.

Parameters
variablesCurrent values of all program variables.

The documentation for this class was generated from the following files: