.Simulation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
Signals | Public Member Functions | Protected Slots | Protected Attributes | Friends | List of all members
SchedulerGUI::SimulationWorker Class Reference

Worker object for running an instance of the simulation. More...

#include <SimulationWorker.h>

Inheritance diagram for SchedulerGUI::SimulationWorker:

Signals

void Initialized ()
 This signal is emitted when the simulation is initialized.
 
void LogMsgReady (const QString &logMessage)
 This signal is emitted when params and simulation constants have been established in the simulation and written to a string for display.
 
void SavePointCreated (unsigned long long savePointNumber)
 This signal is emitted when a save point is being made.
 
void SavePointCreated ()
 
void ChangedRunState (const bool state)
 This signal is emitted when the state of the simulation is changed. More...
 
void ChangedRunState ()
 
void ChangedLiveState (const bool state)
 This signal is emitted when a new instance of a simulation is started or if an existing simulation is completely terminated. More...
 
void ChangedLiveState ()
 
void ResultReady (const SimulationResult &result)
 This signal is emitted when the event loop terminates on its own.
 
void Finished ()
 This signal is emitted when the worker process ends.
 
void Error (const QString &message)
 This signal is emitted when their is an error in the worker.
 

Public Member Functions

 SimulationWorker (QObject *parent=0)
 Constructor.
 
bool GetRunState ()
 Returns the running state of the simulation. More...
 
bool GetLiveState ()
 Returns whether or not an instance of the simulation exists in memory or not. More...
 
void SetWillWriteLog (bool value)
 
bool GetWillWriteLog ()
 

Protected Slots

void DoWork ()
 Event loop that handles the starting, running, and closing of simulation instances. More...
 
void StopWork ()
 Stops the SimulationWorker's event loop. More...
 
void StartSim (const InfoStruct &parameters, const QString &outDir)
 Requests for a new instance of the simulation to be run. More...
 
void ChangeRunState (bool state)
 Changes the running state of the simulation. More...
 
void ChangeLiveState (bool state)
 Changes the live state of the simulation. More...
 
void HaltSimulation ()
 Breaks out of the simulation loop if it is running. More...
 
void RunSim ()
 Runs a new instance of a simulation. More...
 
void InitLogMsg ()
 Writes parameters and simulation constants to a stream so that they can be written to a log.
 
void WriteLogMsg (const QString &msg)
 Used to write log messages to a signal. More...
 

Protected Attributes

InfoStruct Parameters_
 Local copy of the parameters used to instantiate the simulation.
 
QString OutputDir_
 Local copy of the directory path used to store the simulation output.
 
bool IsWorking_
 Indicates whether the event loop is active or not.
 
bool StartNew_
 Flag that prompts the worker to start a new instance of the simulation.
 
bool LiveState_
 Indicates if parameters are loaded and an instance of the simulation has been created, whether it is running or not.
 
bool RunState_
 The run state of the simulation. 'true' means the simulation is running. 'false' means the simulation has paused.
 
bool HaltSim_
 Halts the simulation when set to true.
 
bool WillWriteLog_
 Indicates if parameters and simulation constants will be written to a string so they can be displayed.
 
QReadWriteLock Mutex_
 Mutex used for safeguarding state reads and writes between threads.
 

Friends

class SimulationController
 Provide SimulationController with exclusive access to the protected members of this class.
 

Detailed Description

Worker object for running an instance of the simulation.

Member Function Documentation

void SchedulerGUI::SimulationWorker::ChangedLiveState ( const bool  state)
signal

This signal is emitted when a new instance of a simulation is started or if an existing simulation is completely terminated.

Parameters
stateis indicates if a new simulation has started, "true", or an existing one is terminated, "false".
void SchedulerGUI::SimulationWorker::ChangedRunState ( const bool  state)
signal

This signal is emitted when the state of the simulation is changed.

Parameters
stateis the state of the simulation. 'true' is running. 'false' is paused.
void SimulationWorker::ChangeLiveState ( bool  state)
protectedslot

Changes the live state of the simulation.

The live state differs from the running state in that it indicates whether or not an instance of the simulation exists or not, and not whether a simulation is currently being updated.

Parameters
stateis the live state that the simulation will be changed to.
See Also
SimulationWorker::LiveState_
void SimulationWorker::ChangeRunState ( bool  state)
protectedslot

Changes the running state of the simulation.

The running state indicates whether a live simulation, a fully initialized simulation, is currently updating or not. SimulationWorker::ChangeRunState() can alter the running state the simulation is in.

Parameters
stateis the run state that the simulation will be changed to.
See Also
SimulationWorker::RunState_
void SimulationWorker::DoWork ( )
protectedslot

Event loop that handles the starting, running, and closing of simulation instances.

In the event that there is already an instance of the simulation running, a halt will be called when a new simulation is requested via SimulationWorker::StartSim. When the simulation is successfully halted, the method will return to the head of the event loop and check if a new simulation was called for.

bool SimulationWorker::GetLiveState ( )

Returns whether or not an instance of the simulation exists in memory or not.

The live state differs from the running state in that it indicates whether or not an instance of the simulation exists or not, and not whether a simulation is currently being updated.

bool SimulationWorker::GetRunState ( )

Returns the running state of the simulation.

The running state indicates whether a live simulation, a fully initialized simulation, is currently updating or not.

void SimulationWorker::HaltSimulation ( )
protectedslot

Breaks out of the simulation loop if it is running.

Changes the state of the simulation in order to break out of a currently running simulation's update loop. This has no effect if there is no simulation instantiated.

void SimulationWorker::RunSim ( )
protectedslot

Runs a new instance of a simulation.

Attempts to instantiate a simulation with the parameters and output directory stored within the worker. If the instantiation is successful, the method continues to update the simulation through its steps, until informed to do otherwise.

void SimulationWorker::StartSim ( const InfoStruct parameters,
const QString &  outDir 
)
protectedslot

Requests for a new instance of the simulation to be run.

Stores the passed parameters and output directory into the worker and changes the state of the worker to alert the event loop to start a new instance of the simulation. If the parameters passed are empty, an error will be emitted and the method will return.

Parameters
parametersis an instance of InfoStruct that contains the information necessary to start a simulation.
outDiris the directory where the output files will be saved to.
void SimulationWorker::StopWork ( )
protectedslot

Stops the SimulationWorker's event loop.

Changes the state of the SimulationWorker, forcing the event loop to break and work to stop.

void SimulationWorker::WriteLogMsg ( const QString &  msg)
protectedslot

Used to write log messages to a signal.

This method is used internally to send messages to objects connected to SimulationWorker::LogMsgReady() signal. Its purpose is to broadcast changes in the simulation. SimulationWorker::SetWillWriteLog() can toggle whether or not these messages will be broadcast.

Parameters
msgis the string that will be communicated to a log.

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