evtmgr - CSTBox Event manager service¶
CSTBox Event manager service.
Service taking care of events broadcasting to the rest of the framework and application.
In order to be easily filtered by nature, events are exhanged on several separate “channels”. Each channel is managed by a distinct instance of the event manager, which defines its own connection name (aka bus name), set as ROOT_BUS_NAME suffixed by the channel name.
When started as a script, this module creates a bus for the channel passed on the command line (use -h for detailed usage).
This allows a simple and efficient way for consumers to subscribe to only the events of interest, without any complicated matching, just by using the connection to the right manager.
- The following channels are pre-defined as module properties:
- SENSOR_EVENT_CHANNEL = ‘sensor’
- CONTROL_EVENT_CHANNEL = ‘control’
- SYSMON_EVENT_CHANNEL = ‘sysmon’
- FRAMEWORK_EVENT_CHANNEL = ‘framework’
Public methods and signals published through D-Bus are accessed via a single object which path is defined by the OBJECT_PATH module property. They are grouped in an interface which name is provided by the SERVICE_INTERFACE module property.
For details, refer to the documentation of method EventManager.emitEvent, signal EventManager.onCSTBoxEvent and pycstbox.events module.
-
class
pycstbox.evtmgr.
EventManager
(conn, channels=None)¶ CSTBox Event manager service.
This container will host a service object for each event channel, in order to keep the various communication separated, and this easing the subscription to a given family of event.
Parameters: - conn – the bus connection (Session, System,...)
- channels (str) – a list of strings enumerating the event channels (sensor, system,...). If not provided, all pre-defined channels will be used.
-
class
pycstbox.evtmgr.
EventManagerObject
(channel)¶ The service object for a given event channel.
One instance of this class is created for each event channel to be managed.
Parameters: channel (str) – the event channel -
onCSTBoxEvent
(*args, **keywords)¶ CSTBoxEvent broadcasting DBus signal
Parameters: timestamp (unsigned64) – the event timestamp, in milliseconds since January 1st, 1970 See
emitEvent()
documentation for other parameters.
-
emitEvent
(var_type, var_name, data)¶ Timestamps and posts a CSTBoxEvent on the message bus.
Events are automatically timestamp’ed before being posted on the bus. The timestamp is set to the number of milliseconds elapsed since the origin of time (aka epoch).
Appropriate synchronization is also applied to ensure events integrity in case of multi-threaded calls.
Parameters: - var_type (str) – A string defining the type a the involved variable (ex: ‘temperature’)
- var_name (str) – The name of the variable
- data (str) – A string containing the event payload, formatted as a valid JSON representation. The payload format is defined by the event class. Ex: {“value”:”25.7”,”unit”:”degC”}. See json package documentation for details
Returns: True if all is ok
-
emitTimedEvent
(event)¶ Posts an event provided as a tuple.
This method is intended to be called by Python clients, and uses an objectified event instead of separate parameters.
If the provided event is a TimedEvent instance, its timestamp will be discarded, since it can be outdated and thus introduce a break in the time line.
Parameters: event – the event to be emitted, as a events.BasicEvent or a events.TimedEvent instance
-
-
pycstbox.evtmgr.
get_object
(channel)¶ Returns the service proxy object for a given event channel if available
Parameters: channel (str) – the event channel managed by the requested service instance Returns: the requested service instance, if exists Raises ValueError: if no bus name match the requested channel