Engine handler#
handler
module.
- class sunflare.engine.handler.EngineHandler(*args, **kwargs)#
EngineHandler
protocol class.The
EngineHandler
wraps the acquisition engine and provides a common interface for all engines. It communicates with the rest of the application via the virtual buses.Controllers receive a reference to the
EngineHandler
object in their constructor.- Parameters:
config (
RedSunSessionInfo
) – Configuration options for the RedSun instance.virtual_bus (
VirtualBus
) – Module-local virtual bus.module_bus (
VirtualBus
) – Inter-module virtual bus.during_task (
DuringTask
) – DuringTask object. This object manages the blocking event used by the run engine to safely execute the plan.
- abstract load_model(name, model)#
Load a model into the handler and make it available to the rest of the application.
This method can be used to dynamically load a model. The request for adding a model should be initiated by the plugin manager.
- Parameters:
name (
str
) – Model identifier.model (
ModelProtocol
) – Model to be loaded.
- Return type:
None
- property models: dict[str, ModelProtocol]#
Models dictionary.
- property plans: dict[str, dict[str, partial[MsgGenerator[Any]]]]#
Dictionaries of plans.
The key of the main dictionary represents the name of the controller. The values are dictionaries where: - the key is the name of the plan; - the value is the plan itself, built as a partial function.
- abstract register_plan(controller, name, plan)#
Register a new plan dynamically.
This method can be used to register a plan from an external source that is not a controller. If a key of value
name
is already present in the plans dictionary, the plan will be appended to the list of plans associated to the key.- Parameters:
controller (
str
) – Controller name.name (
str
) – Key to be used to assign the plan.plan (
MsgGenerator[Any]
) – Plan to be registered.
- Return type:
None
- abstract shutdown()#
Perform a clean shutdown of the engine.
- Return type:
None
- abstract subscribe(func, name='all')#
Subscribe a callback function to the engine notifications.
The callback has signature
func(name, document)
:name
is the type of document the callback should receive;"all"
: all documents;"start"
: start documents;"descriptor"
: descriptor documents;"event"
: event documents;"stop"
: stop documents.
document
is the document received from the engine (a dictionary).
- Parameters:
func (Callable[[EventName, dict[str, Any]], None]) – Function to be called when the event occurs.
name (Optional[EventName]) – Event type. Defaults to
"all"
.
- Returns:
token – Subscription token. It can be used to unsubscribe the callback.
- Return type:
int
Notes
See also
unsubscribe()
.
- abstract unsubscribe(token)#
Unregister a callback function its integer ID.
- Parameters:
token (int) – Subscription token.
- Return type:
None
Notes
See also
unsubscribe()
.