Control
This module provides classes for a simple remote procedure call (RPC) framework.
ATTRIBUTE | DESCRIPTION |
---|---|
BYTE_SIZE |
size of the byte.
TYPE:
|
CLASS | DESCRIPTION |
---|---|
ClassMethods |
class to store methods of a class. |
TwoTierQueue |
a queue that can handle two types of items: normal and high-priority. |
Proxy |
a proxy class to handle remote method calls. |
Controller |
a class to control the flow of data and commands between models and views. |
Documentation last updated: 2025-06-11
ClassMethods
dataclass
Class to store methods of a class.
ATTRIBUTE | DESCRIPTION |
---|---|
name |
name of the class.
TYPE:
|
methods |
dictionary of methods and their parameters.
TYPE:
|
Controller
Controller(
role: str,
interpreter: Interpreter,
*,
relay_delay: int = 1,
)
A class to control the flow of data and commands between models and views.
ATTRIBUTE | DESCRIPTION |
---|---|
role |
the role of the controller
TYPE:
|
interpreter |
the interpreter to use
TYPE:
|
address |
the address of the controller
TYPE:
|
relay_delay |
delay for relaying data
TYPE:
|
relays |
list of relays
TYPE:
|
callbacks |
dictionary of callbacks
TYPE:
|
events |
dictionary of events
TYPE:
|
command_queue |
command queue
TYPE:
|
data_buffer |
data buffer
TYPE:
|
objects |
dictionary of objects
TYPE:
|
object_methods |
dictionary of object methods
TYPE:
|
object_attributes |
dictionary of object attributes
TYPE:
|
execution_event |
event for execution loop
TYPE:
|
registry |
object registry
TYPE:
|
METHOD | DESCRIPTION |
---|---|
receiveRequest |
receive a request |
transmitData |
transmit data |
broadcastRegistry |
broadcast the registry |
register |
register an object |
unregister |
unregister an object |
extractMetadata |
extract metadata from a command |
extractMethods |
extract methods from an object |
exposeAttributes |
expose attributes of registered objects |
exposeMethods |
expose methods of registered objects |
start |
start the execution loop |
stop |
stop the execution loop |
executeCommand |
execute a command |
transmitRequest |
transmit a request |
receiveData |
receive data |
retrieveData |
retrieve data |
getAttributes |
get attributes of the controller |
getMethods |
get methods of the controller |
relay |
relay a request or data |
relayRequest |
relay a request |
relayData |
relay data |
subscribe |
subscribe to a relay |
unsubscribe |
unsubscribe from a relay |
setAddress |
set the address of the controller |
Initialize the Controller class.
PARAMETER | DESCRIPTION |
---|---|
role
|
the role of the controller
TYPE:
|
interpreter
|
the interpreter to use
TYPE:
|
relay_delay
|
delay for relaying data. Defaults to 1.
TYPE:
|
broadcastRegistry
Broadcast the registry
PARAMETER | DESCRIPTION |
---|---|
target
|
the target addresses. Defaults to None.
TYPE:
|
executeCommand
Execute a command
PARAMETER | DESCRIPTION |
---|---|
command
|
the command to execute
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple[Any, dict[str, Any]]
|
tuple[Any, dict[str, Any]]: the result of the command and the status |
extractMetadata
Extract metadata from a command
PARAMETER | DESCRIPTION |
---|---|
command
|
the command to extract metadata from
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict[str, Any]
|
dict[str, Any]: the extracted metadata |
extractMethods
staticmethod
extractMethods(new_object: Callable) -> ClassMethods
Extract methods from an object
PARAMETER | DESCRIPTION |
---|---|
new_object
|
the object to extract methods from
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ClassMethods
|
the extracted methods
TYPE:
|
getAttributes
Get attributes
PARAMETER | DESCRIPTION |
---|---|
target
|
the target addresses. Defaults to None.
TYPE:
|
private
|
flag to indicate private transmission. Defaults to True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
the attributes
TYPE:
|
getMethods
Get methods
PARAMETER | DESCRIPTION |
---|---|
target
|
the target addresses. Defaults to None.
TYPE:
|
private
|
flag to indicate private transmission. Defaults to True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
the methods
TYPE:
|
receiveData
Receive data
PARAMETER | DESCRIPTION |
---|---|
packet
|
the packet to receive. Defaults to None.
TYPE:
|
sender
|
the sender of the packet. Defaults to None.
TYPE:
|
receiveRequest
Receive a request
PARAMETER | DESCRIPTION |
---|---|
packet
|
the request to receive. Defaults to None.
TYPE:
|
sender
|
the sender of the request. Defaults to None.
TYPE:
|
register
Register an object
PARAMETER | DESCRIPTION |
---|---|
new_object
|
the object to register
TYPE:
|
object_id
|
the ID of the object. Defaults to None.
TYPE:
|
relay
Relay a message
PARAMETER | DESCRIPTION |
---|---|
packet
|
the message to relay
TYPE:
|
callback_type
|
the callback type
TYPE:
|
addresses
|
the target addresses. Defaults to None.
TYPE:
|
relayData
Relay data
PARAMETER | DESCRIPTION |
---|---|
packet
|
the packet to relay. Defaults to None.
TYPE:
|
relayRequest
Relay a request
PARAMETER | DESCRIPTION |
---|---|
packet
|
the request to relay. Defaults to None.
TYPE:
|
retrieveData
retrieveData(
request_id: str,
timeout: int | float = 5,
*,
sender: str | None = None,
min_count: int | None = 1,
max_count: int | None = 1,
default: Any | None = None,
data_only: bool = True,
close_request: bool = True,
) -> Any | dict[tuple[str, str], Any]
Retrieve data
PARAMETER | DESCRIPTION |
---|---|
request_id
|
the request ID
TYPE:
|
timeout
|
the timeout. Defaults to 5.
TYPE:
|
min_count
|
the minimum count. Defaults to 1.
TYPE:
|
max_count
|
the maximum count. Defaults to 1.
TYPE:
|
default
|
the default value. Defaults to None.
TYPE:
|
data_only
|
flag to indicate data only. Defaults to True.
TYPE:
|
close_request
|
flag to indicate close request. Defaults to True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Any | dict[tuple[str, str], Any]
|
Any | dict[tuple[str,str], Any]: the retrieved data |
setAddress
Set the address
PARAMETER | DESCRIPTION |
---|---|
address
|
the address
TYPE:
|
subscribe
subscribe(
callback: Callable,
callback_type: str,
address: int | str | None = None,
*,
relay: bool = False,
)
Subscribe to a callback
PARAMETER | DESCRIPTION |
---|---|
callback
|
the callback to subscribe
TYPE:
|
callback_type
|
the callback type
TYPE:
|
address
|
the address. Defaults to None.
TYPE:
|
relay
|
flag to indicate relay. Defaults to False.
TYPE:
|
transmitData
transmitData(
data: Any,
*,
metadata: Mapping[str, Any] | None = None,
status: Mapping[str, Any] | None = None,
)
Transmit data
PARAMETER | DESCRIPTION |
---|---|
data
|
the data to transmit
TYPE:
|
metadata
|
the metadata to include. Defaults to None.
TYPE:
|
status
|
the status to include. Defaults to None.
TYPE:
|
transmitRequest
transmitRequest(
command: Mapping[str, Any],
target: Iterable[int | str] | None = None,
*,
private: bool = True,
priority: bool = False,
rank: int | None = None,
) -> str
Transmit a request
PARAMETER | DESCRIPTION |
---|---|
command
|
the command to transmit
TYPE:
|
target
|
the target addresses. Defaults to None.
TYPE:
|
private
|
flag to indicate private transmission. Defaults to True.
TYPE:
|
priority
|
flag to indicate high-priority transmission. Defaults to False.
TYPE:
|
rank
|
rank of the high-priority transmission. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
the request ID
TYPE:
|
unregister
Unregister an object
PARAMETER | DESCRIPTION |
---|---|
object_id
|
the ID of the object. Defaults to None.
TYPE:
|
old_object
|
the object to unregister. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
flag indicating success
TYPE:
|
Proxy
A proxy class to handle remote method calls.
ATTRIBUTE | DESCRIPTION |
---|---|
prime |
the object to create a proxy for
TYPE:
|
object_id |
the ID of the object
TYPE:
|
controller |
the controller bound to the proxy
TYPE:
|
remote |
flag to indicate remote method calls
TYPE:
|
METHOD | DESCRIPTION |
---|---|
factory |
factory method to create a new class with methods of the prime object |
createMethodEmitter |
create a method emitter for the proxy class |
createPropertyEmitter |
create a property emitter for the proxy class |
bindController |
bind a controller to the proxy |
releaseController |
release the controller from the proxy |
Initialize the Proxy class.
PARAMETER | DESCRIPTION |
---|---|
prime
|
the object to create a proxy for
TYPE:
|
object_id
|
the ID of the object. Defaults to None.
TYPE:
|
bindController
bindController(controller: Controller)
Bind a controller to the proxy.
PARAMETER | DESCRIPTION |
---|---|
controller
|
the controller to bind to the proxy
TYPE:
|
createMethodEmitter
staticmethod
Create a method emitter for the proxy class.
PARAMETER | DESCRIPTION |
---|---|
method
|
the method to create an emitter for
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Callable
|
the method emitter
TYPE:
|
createPropertyEmitter
staticmethod
Create a property emitter for the proxy class.
PARAMETER | DESCRIPTION |
---|---|
attr_name
|
the name of the property to create an emitter for
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
property
|
the property emitter
TYPE:
|
factory
classmethod
factory(
prime: Callable, object_id: str | None = None
) -> Type[Proxy]
Factory method to create a new class with methods and properties of the prime object.
PARAMETER | DESCRIPTION |
---|---|
prime
|
the object to create a proxy for
TYPE:
|
object_id
|
the ID of the object. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Type[Proxy]
|
Type[Proxy]: the new class with methods and properties of the prime object |
releaseController
releaseController() -> Controller
Release the controller from the proxy.
RETURNS | DESCRIPTION |
---|---|
Controller
|
the controller that was bound to the proxy
TYPE:
|
TwoTierQueue
A queue that can handle two types of items: normal and high-priority.
ATTRIBUTE | DESCRIPTION |
---|---|
normal_queue |
queue for normal items.
TYPE:
|
high_priority_queue |
queue for high-priority items.
TYPE:
|
last_used_queue_normal |
flag to indicate the last used queue.
TYPE:
|
priority_counter |
counter for high-priority items.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
qsize |
return the size of the queue |
empty |
check if the queue is empty |
full |
check if the queue is full |
put |
put an item in the queue |
put_nowait |
put an item in the queue without waiting |
get |
get an item from the queue |
get_nowait |
get an item from the queue without waiting |
task_done |
mark a task as done |
join |
wait for all tasks to be done |
put_first |
put an item at the front of the priority queue |
put_priority |
put a high-priority item in the queue |
put_queue |
put an item in the queue |
reset |
reset the queue |
get
Get an item from the queue.
PARAMETER | DESCRIPTION |
---|---|
block
|
flag to block the queue. Defaults to True.
TYPE:
|
timeout
|
time to wait for the queue. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Any
|
item from the queue.
TYPE:
|
get_nowait
Get an item from the queue without waiting.
RETURNS | DESCRIPTION |
---|---|
Any
|
item from the queue.
TYPE:
|
put
put(
item: Any,
block: bool = True,
timeout: float | None = None,
*,
priority: bool = False,
rank: int | None = None,
)
Put an item in the queue.
PARAMETER | DESCRIPTION |
---|---|
item
|
item to put in the queue.
TYPE:
|
block
|
flag to block the queue. Defaults to True.
TYPE:
|
timeout
|
time to wait for the queue. Defaults to None.
TYPE:
|
priority
|
flag to indicate high-priority item. Defaults to False.
TYPE:
|
rank
|
rank of the high-priority item. Defaults to None.
TYPE:
|
put_first
Put an item at the front of the priority queue.
PARAMETER | DESCRIPTION |
---|---|
item
|
item to put in the queue.
TYPE:
|
put_nowait
Put an item in the queue without waiting.
PARAMETER | DESCRIPTION |
---|---|
item
|
item to put in the queue.
TYPE:
|
priority
|
flag to indicate high-priority item. Defaults to False.
TYPE:
|
rank
|
rank of the high-priority item. Defaults to None.
TYPE:
|
put_priority
Put a high-priority item in the queue.
PARAMETER | DESCRIPTION |
---|---|
item
|
item to put in the queue.
TYPE:
|
rank
|
rank of the high-priority item
TYPE:
|
block
|
flag to block the queue. Defaults to True.
TYPE:
|
timeout
|
time to wait for the queue. Defaults to None.
TYPE:
|
put_queue
Put an item in the queue.
PARAMETER | DESCRIPTION |
---|---|
item
|
item to put in the queue.
TYPE:
|
block
|
flag to block the queue. Defaults to True.
TYPE:
|
timeout
|
time to wait for the queue. Defaults to None.
TYPE:
|