ska_oso_scripting.functions.tango

class ska_oso_scripting.functions.devicecontrol.tango_executor.TangoDeviceProxyFactory[source]

A call to create Tango DeviceProxy clients. This class exists to allow unit tests to override the factory with an implementation that returns mock DeviceProxy instances.

class ska_oso_scripting.functions.devicecontrol.tango_executor.SubscriptionManager(proxy_factory=<ska_oso_scripting.functions.devicecontrol.tango_executor.TangoDeviceProxyFactory object>)[source]

SubscriptionManager is a proxy for Tango event subscriptions that prevents duplicate subscriptions and minimises subscribe/unsubscribe calls.

Previously, each time a script listened to an event, it would subscribe to an event, wait for reception of the appropriate event, then unsubscribe. These multiple subscribe/unsubscribe calls were found to create problems. SubscriptionManager was introduced to manage subscriptions, with the aim of having fewer, longer-lived subscriptions. Clients subscribe to the SubscriptionManager, and the SubscriptionManager handles any required subscriptions to Tango devices.

The SubscriptionManager component is responsible for managing events within the execution of an observing script. The SubscriptionManager sits as a proxy between client and Tango event subscriptions, moving the pub/sub layer accessed by clients away from the Tango layer and into the Scripting layer. Clients register with the SubscriptionManager as observers of an attribute. If required, one long-lived Tango subscription per attribute is created on demand by the SubscriptionManager. The SubscriptionManager relays received Tango events to all attribute observers registered at the time of event reception. Unregistering an observer from the SubscriptionManager prevents subsequent notifications but does not affect the underlying Tango event subscription, which continues to operate until the Python interpreter exits.

Legacy calling code expects a maximum of one subscription to be active at any one time. Additionally, the caller always sandwiched read_event calls between subscribe_attribute and unsubscribe_attribute calls. Together, this meant subscriptions were short-lived, existing for the duration of a single attribute monitoring operation, and that one Queue to hold events was sufficient as there would only ever be one Tango event subscription. To maintain this legacy behaviour, subscribe_attribute and unsubscribe_attribute register and unregister the TangoExecutor as an observer of events, with the TangoExecutor.notify method adding received events to the TangoExecutor queue read by the legacy TangoExecutor.read_event method.

../../_images/subscriptionmanager-class.svg

Class diagram for components involved in the Tango device event handling

../../_images/subscriptionmanager-sequence.svg

Sequence diagram from observing script event handling

Members:

class ska_oso_scripting.functions.devicecontrol.tango_executor.Callback[source]

Callback is an observable that distributes Tango events received by the callback instance to all observers registered at the moment of event reception.

register_observer(observer)[source]

Register an EventObserver.

Once registered, the observer will be notified of all Tango events received by this instance.

Parameters:

observer – observer to register

unregister_observer(observer)[source]

Unregister an EventObserver.

Unsubscribed observers will not receive Tango events subsequently received by this instance.

Parameters:

observer – observer to register

notify_observers(evt: tango.EventData)[source]

Distribute an event to all registered observers.

Parameters:

evt – event to distribute