egse.listener
cgse-common
This code is part of the cgse-common
package.
egse.listener
¶
This module defines Listeners between control servers and is part of a notification system where changes in one control-server are notified to all listeners of that control-server.
Since we have communication between control servers, a listener registers to a control server with its name/id
and a Proxy class that will be used to send the notification. A listener can also contain an event_id
to restrict
events to handle. (Shall events be filtered on the server (only notify events that match the event_id
or shall they
be filtered on the client (only handle those events that match the event_id
) ?)
Any control server will support notification and listeners are added through the service proxy of the control server.
A control server that wants to be notified by an event needs to implement the EventInterface in the Proxy and in the Controller.
Classes:
Name | Description |
---|---|
EVENT_ID |
An identifier for the type of event. |
Event |
An event that is generated by a control server. |
EventInterface |
A dynamic interface for handling events. |
Listeners |
A class for managing and notifying registered listeners. |
EVENT_ID
¶
EventInterface
¶
A dynamic interface for handling events.
This interface defines a single method, 'handle_event', which is intended to be implemented by classes that want to handle specific types of events.
Use this interface as a mixin for classes (Proxy/Controller) that implement this handle_event
method.
Methods:
Name | Description |
---|---|
handle_event |
Handles the specified event. |
Listeners
¶
Listeners()
A class for managing and notifying registered listeners.
This class provides methods to add, remove, and notify listeners of events.
Methods:
Name | Description |
---|---|
add_listener |
Adds a new listener to the registered listeners. |
get_listener_names |
Returns a list with the names of the registered listeners. |
notify_listener |
Notifies a registered listener fro the given event. |
notify_listeners |
Notifies all registered listeners of a specific event. |
remove_listener |
Removes a listener from the registered listeners. |
add_listener
¶
add_listener(listener)
Adds a new listener to the registered listeners.
The listener argument dictionary is expected to have at least the following key:values pairs:
- 'name': the name or identifier of the listener
- 'proxy': a Proxy object that will be used for notifying the service
Parameters:
Name | Type | Description | Default |
---|---|---|---|
listener
|
dict
|
A dictionary with properties of the listener, including 'name' and 'proxy'. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the listener already exists. |
get_listener_names
¶
get_listener_names()
Returns a list with the names of the registered listeners.
notify_listener
¶
notify_listener(name, listener, event)
Notifies a registered listener fro the given event.
notify_listeners
¶
notify_listeners(event)
Notifies all registered listeners of a specific event.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event
|
Event
|
An instance of the Event class representing the event to be broadcasted. |
required |
Note
The 'handle_event' method is called on each listener's proxy object to process the event.
remove_listener
¶
remove_listener(listener)
Removes a listener from the registered listeners.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
listener
|
dict
|
A dictionary representing the listener to be removed. It should contain a 'name' key. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the 'name' key is not present in the listener argument or if the specified listener is not registered. |