callbacks.CallbackBroker

callbacks.CallbackBroker(mod_connections=dict(), stop_event=threading.Event())

A class to handle callbacks from socket clients.

This class manages connections to various modules and listens for callbacks on these connections. It processes the received messages and forwards them to the appropriate target modules.

Attributes

Name Type Description
mod_connections dict[str, ModuleConnection] A dictionary mapping module names to their connections.
stop_event threading.Event An event to signal the stopping of the callback listening loop.

Methods

Name Description
check_for_callback Check for callbacks on the given socket.
listen_for_callbacks Start listening for callbacks from connected modules.

check_for_callback

callbacks.CallbackBroker.check_for_callback(msocket, mod_name)

Check for callbacks on the given socket.

This method reads messages from the provided socket and processes them. If a valid callback message is received, it is forwarded to the appropriate target module. The method handles message formatting and validation.

Parameters

Name Type Description Default
msocket socket The socket to check for callbacks. required
mod_name str The name of the module associated with the socket. required

Notes

This method ignores fully blank messages and common start bytes.

listen_for_callbacks

callbacks.CallbackBroker.listen_for_callbacks()

Start listening for callbacks from connected modules.

This method runs in a loop, checking each connected module for callbacks. If a callback is received, it is processed and forwarded to the appropriate target module. The loop continues until the stop event is set.

Notes

This loop could be a performance bottleneck if multiple modules need to be checked. Consider creating a whitelist of modules to be checked for callbacks.