Mode inheritance

This module implements mode inherition.

class CallbackManager(**callbacks)

This class implements a CallbackManager for modes.

It implements a cache of mode values from a parent device, and is responsible for calling callbacks whenever there is a change.

Create a CallbackManager object, feed it updates on the modes of a parent, and let it know when it is in ‘active’ mode and should therefore call its callbacks.

Call the update method to tell it that the parent device has changed a mode; for example, callback_manager.update(“adminMode”, AdminMode.ONLINE). The stored cache will remember the mode that has been set, but it will only call the relevant callback if/once its active attribute is set to True.

You can set the active property at any time, by simply writing a boolean value to it; for example callback_manager.active = True.

Consider this scenario:

  1. An MccsStation instance is set to inherit its adminMode from its parent, which is the MccsController. The MccsController has adminMode OFFLINE, so this MccsStation instance also adopts adminMode OFFLINE.

  2. The MccsController has its adminMode changed to ONLINE. This change propagates through the entire MCCS subsystem, including this MccsStation, because its inherit attribute is set to True.

  3. A decision is made to make this station an “engineering station” for a time. That means it needs to be excised from the rest of the array, and its adminMode needs to be set to ENGINEERING. This is achieved by explicitly overriding the device’s adminMode, which also causes it to stop inheriting this mode from its parent device. (That explicit override flows down to the station’s subordinate devices, because these subordinate devices are still set to inherit their adminMode`s from their parent. The only point in the system where the chain of inheritance is broken, is at this one `MccsStation instance.)

  4. The MccsController has its adminMode changed to OFFLINE. This change propagates through the entire MCCS subsystem, except for the “engineering station”, which remains online in ENGINEERING adminMode, because it has been told not to inherit from its parent.

  5. The station is not longer needed for an “engineering station”, and is ready to be included back into the overall array. The MccsStation instance is told to inherit its adminMode from its parent. It immediately changes adminMode to OFFLINE, because that is the adminMode of its parent device; and this change flows down to the MccsStation instance’s subordinate devices.

Note that this class is agnostic to the modes that it manages.

__init__(**callbacks)

Initialise a new instance.

Parameters:

callbacks (Optional[Callable[[Any], None]]) –

keyword arguments specifying modes to be managed, and optionally providing a callback to be called when the mode changes. For example, if you initialise this with CallbackManager(adminMode=self.adminModeChanged), then this CallbackManager instance will support a mode named adminMode, and will call self.adminModeChanged whenever it determines that the adminMode has changed.

It is also possible to initialise this as CallbackManager(adminMode=None), in which case this CallbackManager will support adminMode, but will not call a callback when adminMode changes.

property active: bool

Whether this CallbackManager is currently calling its callbacks.

Returns:

whether this CallbackManager is currently active

update(name, value)

Advise that the mode of a parent has changed.

Parameters:
  • name (str) – name of the mode

  • value (Any) – the new value taken by the parent.

Return type:

None

class ModeInheritor(parent_trl, logger, *, adminmode_callback, connection_callback, event_serialiser=None, connection_timeout=120)

This class manages mode inheritance for a device.

Initialise it with the TRL of its parent tango device, and callbacks for the modes that it is managing.

You can then set the modes explicitly, or set the inheriting attribute to toggle mode inheritance.

__init__(parent_trl, logger, *, adminmode_callback, connection_callback, event_serialiser=None, connection_timeout=120)

Initialise a new instance.

Parameters:
  • parent_trl (Optional[str]) – TRL of the parent Tango device. If None, this device does not have a parent device, and therefore cannot inherit its modes.

  • logger (Logger) – a logger for this object to use.

  • adminmode_callback (Callable[[AdminMode], None]) – callback to be called whenever the adminMode value changes. This must be provided as an explicit keyword argument; i.e. adminmode_callback=my_callback. This is to ensure that support for more modes can be added in future without breaking backwards-compatibility.

  • connection_callback (Callable[[bool], None]) – callback to be called whenever the communication state to the parent changes.

  • event_serialiser (Optional[EventSerialiser]) – an EventSerialiser instance for managing the events.

  • connection_timeout (float) – how long to wait to successfully connect.

cleanup()

Notify the event thread to cleanup.

Return type:

None

property inheriting: bool

Return whether we are inheriting modes from the parent mode.

Returns:

whether we are inheriting modes from the parent mode.

parent_mode_changed(mode_name, mode_value, event_quality)

Tango event handler for change of a parent mode.

Parameters:
  • mode_name (str) – name of the mode that has changed

  • mode_value (Any) – the new mode value

  • event_quality (AttrQuality) – the quality of the change event

Return type:

None