Switching Component Manager

This module implements functionality for switching between component managers.

class DriverSimulatorSwitchingComponentManager(driver_component_manager, simulator_component_manager, initial_simulation_mode)

A component manager that switches between driver and simulator components.

It uses the simulation mode to determine which component to drive.

__init__(driver_component_manager, simulator_component_manager, initial_simulation_mode)

Initialise a new instance.

Parameters:
set_communication_state_callback(communication_state_callback)

Set the callback to be called when communication status changes.

Parameters:

communication_state_callback (Optional[Callable[[CommunicationStatus], None]]) – the callback to be called when status of communication with the component changes. If None, no callback will be called.

Return type:

None

set_component_state_callback(component_state_callback)

Set the callback to be called when component state changes.

Parameters:

component_state_callback (Optional[Callable[..., None]]) – the callback to be called when component state changed. If None, no callback will be called.

Return type:

None

property simulation_mode: SimulationMode

Return the simulation mode.

Returns:

the simulation mode

class Switcher(switcher_options, initial_switcher_mode)

An abstract class for a class shim that allows switching between classes.

The envisaged use case for this is a ComponentManager that switches between an underlying ComponentManager that drives hardware, and an underlying ComponentManager that drives a hardware simulator, depending on the value of the simulation_mode attribute.

This class implements the switching functionality for that, but independently of any use case.

The options are specified by a dictionary that maps from mode to the class that implements that mode:

The mode is given in strings in the example above, but can be any hashable type:

Instead of a class, None may be provided as a option. This is used to signify that a mode is valid but not yet provided for. Attempts to switch to such a mode will cause a NotImplementedError to be raised:

__init__(switcher_options, initial_switcher_mode)

Initialise a new Switcher instance.

Parameters:
  • switcher_options (dict[Hashable, Any]) – a dictionary that maps from modes to underlying component managers

  • initial_switcher_mode (Hashable) – the mode that this Switcher should start in.

property switcher_mode: Hashable

Get the component manager mode.

That is, which underlying component manager is driven by this SwitchingComponentManager.

Returns:

the component manager mode.

class SwitchingComponentManager(component_managers, initial_mode)

A base component manager that switches between underlying base component managers.

This class passes commands down to an underlying component manager. This underlying component manager is selected from multiple available component managers.

An example of its use would be a component manager for a device that monitors and controls either a hardware component, or a simulator of that hardware component, depending on its simulation mode. In such a case we could:

  • Implement a component manager for the hardware driver;

  • Implement a component manager for the simulator;

  • Use this SwitchingBaseComponentManager as a component manager that uses a simulation mode setting to switch between hardware driver and simulator.

The switching functionality is implemented in the Switcher class. This class is syntactic sugar that allows us to get the multiple inheritance right once and for all, and then hide it from other classes.

__init__(component_managers, initial_mode)

Initialise a new ComponentManager instance.

Parameters: