Class StateModel

Inheritance Relationships

Derived Type

Class Documentation

class StateModel

The state model that regulates the behaviour of the classes that inherit from it. This model expects that commands will be executed on it from different threads.

  • Commands: these will be issued by an LmcService, and commence a state change from a steady state (e.g. Idle) to an intermediate state (e.g. ConfiguringBeam).

Subclassed by ska::pst::common::ApplicationManager

Public Functions

StateModel()

Construct a new StateModel object, initialising the State to Unknown.

virtual ~StateModel() = default

Destroy the StateModel object.

void initialise()

initialise call back responsible for the state transition from Unknown to Idle. Required to be called by the Application that uses this statemodel in the Applications constructor class. Calls the virtual method perform_initialise prior to the state transition.

virtual void configure_beam(const AsciiHeader &config)

Issues the ConfigureBeam command and waits for the BeamConfigured or ConfiguringBeamError state to be reached.

Parameters

config – Beam configuration

virtual void configure_scan(const AsciiHeader &config)

Issues the ConfigureScan command and waits for the ScanConfigured or ConfiguringScanError state to be reached.

Parameters

config – Scan configuration

virtual void start_scan(const AsciiHeader &config)

Issues the StartScan command and waits for the Scanning or ScanningError state to be reached.

Parameters

config – StartScan configuration

virtual void stop_scan()

Issues the StopScan command and waits for the ScanConfigured or ScanningError state to be reached.

virtual void deconfigure_scan()

Issues the DeconfigureScan command and waits for the BeamConfigured or ConfiguringBeamError state to be reached.

virtual void deconfigure_beam()

Issues the DeconfigureBeam command and waits for the Idle state to be reached.

virtual void reset()

Issues the Reset command and waits for the state to transition from RuntimeError to Idle.

inline State get_state() const

Return the current state of the state model.

Returns

State current state of the state model

inline std::exception_ptr get_exception()

Return a pointer to the most recently received exception.

Returns

std::exception_ptr

void raise_exception()

Raise the stored exception from the ApplicationManager’s main thread.

inline Command get_command() const

Return the current command of the state model.

Returns

Command current command of the state model

inline std::string get_name(Command command) const

Return the name of the specified command.

Returns

std::string name of the command

inline std::string get_name(State state) const

Return the name of the specified state.

Parameters

state – state whose name to return

Returns

std::string name of the state

inline virtual ska::pst::common::AsciiHeader &get_beam_configuration()

Get the beam configuration parameters.

Returns

ska::pst::common::AsciiHeader& beam configuration parameters

inline virtual ska::pst::common::AsciiHeader &get_scan_configuration()

Get the scan configuration parameters.

Returns

ska::pst::common::AsciiHeader& scan configuration parameters

inline virtual ska::pst::common::AsciiHeader &get_startscan_configuration()

Get the start scan configuration parameters.

Returns

ska::pst::common::AsciiHeader& start scan configuration parameters

virtual void validate_configure_beam(const AsciiHeader &config, ValidationContext *context) = 0

Validates Beam configuration.

Validation errors should not be raise as exceptions but added to the validation context. The client of the method can decide what to do with the validation errors.

Parameters
  • config – Beam configuration to validate

  • context – A validation context where errors should be added.

virtual void validate_configure_scan(const AsciiHeader &config, ValidationContext *context) = 0

Validates Scan configuration.

Validation errors should not be raise as exceptions but added to the validation context. The client of the method can decide what to do with the validation errors.

Parameters
  • config – Scan configuration to validate

  • context – A validation context where errors should be added.

virtual void validate_start_scan(const AsciiHeader &config) = 0

Validates StartScan configuration. Specific validation errors must be set when throwing exceptions.

Parameters

config – StartScan configuration to validate

Protected Functions

void set_beam_config(const AsciiHeader &config)

Set the beam config object.

Parameters

config

void set_scan_config(const AsciiHeader &config)

Set the scan config object.

Parameters

config

void set_startscan_config(const AsciiHeader &config)

Set the startscan config object.

Parameters

config

void set_command(Command command)

Set the command used as a reference for transitioning between states.

Parameters

command – command to be set.

void wait_for_state(State required)

Wait for the state model to transition to the required state or the RuntimeError state. If the state model transitions to the RuntimeError state, the exception raised by the Application that caused the error will be raised here.

Parameters

required – state to wait for.

void wait_for_state_without_error(State required)

Wait for the state model to transition to the expected state.

Parameters

required – state to wait for.

bool wait_for_state(State expected, unsigned milliseconds)

Wait for the state model to achieve the required state within the timeout.

Parameters
  • expected – target state for the state model to achieve.

  • milliseconds – timeout in milliseconds.

Returns

true if the state model did achieve the required state before the timeout

Returns

false if the state model did not achieve the required state before the timeout

bool wait_for_not_state(State required, unsigned milliseconds)

Wait for the state model to achieve any state other than the required state, within the timeout.

Parameters
  • required – the required state for the state model to

  • milliseconds – timeout in milliseconds

Returns

true if the state model did achieve any state other than the required state within the timeout.

Returns

false if the state model did not achieve any state other than the required state within the timeout

Protected Attributes

Command command = {None}

Command variable.

State state = {Unknown}

Current state of the state model.

AsciiHeader beam_config

Beam configuration.

AsciiHeader scan_config

Scan configuration.

AsciiHeader startscan_config

StartScan configuration.

std::exception_ptr last_exception = {nullptr}

Reference to the most recently experienced exception.

std::mutex state_mutex

Control access to the state attribute.

std::condition_variable state_cond

Coordinates interactions with processes waiting on changes to the state attribute.

std::mutex command_mutex

Control access to the command attribute.

std::condition_variable command_cond

Coordinates interactions with processes waiting on changes to the command attribute.