class documentation

class ROS2InwardMirrorMixin(ROS2MutationMixin):

Constructor: ROS2InwardMirrorMixin(*args, **kwargs)

View In Hierarchy

Keeps a machinery item's Monitoring variables in sync with the topics it declared.

Creating nodes is the mutation chokepoint's job, which this extends. Writing to them is this mixin's.

Method __init__ Start out mirroring nothing, and pass every argument to opensmi's constructor.
Async Method bind_topic_now Open one Binding while the server runs, and give it its nodes.
Property ros2_monitoring_presence Return, per Binding name, whether its topic has a publisher right now.
Property ros2_qos_provenance Return, per Binding name, what its subscription asks for and where that came from.
Property ros2_subscriptions Return the subscription each bound Binding on this item opened, in the order they bound.
Property ros2_unbound_bindings Return the Bindings still waiting for their topic to appear on the graph.
Async Method _bind_from_the_graph Give one waiting Binding its subscription and its nodes, or report why it has neither.
Async Method _follow_binding Write the messages of one Binding until the subscription closes, throttled by max_rate.
Async Method _follow_binding_limited Write at most one message per window seconds: the newest, never losing the last.
Async Method _follow_graph Bind each waiting Binding as its topic appears, then stop watching.
Async Method _follow_publishers Write the status code every time the topic gains or loses its publishers.
Async Method _follow_qos Raise one BindingEvent for every QoS incompatibility the middleware reports.
Async Method _init_monitoring_mirror Open, shape and start every Binding that declared a type, in declaration order.
Async Method _open_binding Subscribe, shape the plan, and ask the chokepoint for the nodes of one Binding.
Async Method _report_a_capped_payload Say once, as a BindingEvent, that a bulk payload reached this server's ceiling.
Method _report_unknown_name Report, once per Binding, a Projection whose decode names what its shape never created.
Method _require_an_unused_binding_name Refuse a second Binding of one name on this item.
Method _require_runtime Return the Runtime this mirror was initialised with.
Async Method _start_following Put the first status on one Binding's variables, then start its tasks.
Method _start_watching_the_graph Open one watch covering every Binding still waiting for its topic, if there are any.
Async Method _stop_monitoring_mirror Stop following every Binding, close its subscription, and let go of the graph.
Async Method _write_message Decode one message and write it once, to the nodes of its Binding.
Async Method _write_message_safely Write one message, and survive whatever it could not be written as.
Async Method _write_status Re-write every node of one Binding under the status its publishers now imply.
Instance Variable _deferred Undocumented
Instance Variable _graph_task Undocumented
Instance Variable _graph_watch Undocumented
Instance Variable _mirrored Undocumented
Instance Variable _registry Undocumented
Instance Variable _runtime Undocumented
def __init__(self, *args: Any, **kwargs: Any):

Start out mirroring nothing, and pass every argument to opensmi's constructor.

async def bind_topic_now(self, binding: MonitoringBinding, *, message_type: str) -> bool:

Open one Binding while the server runs, and give it its nodes.

This is the client-driven exception. It lives here and not on the introspection Component, so that an ad-hoc Binding is built exactly like a declared one.

Parameters
binding:MonitoringBindingWhat to bind. Its name is what its variables are named for. It lives until the server restarts.
message_type:strThe ROS2 type to subscribe with. It is required, because the caller has just read it off the graph and a run-time Binding has no init at which a declared type could be refused.
Returns
boolWhether it happened. False means a mutation cap refused the nodes and the subscription was closed again.
Raises
DuplicateBindingNameErrorWhen this item already has a Binding of that name.
ROS2RuntimeErrorWhen the type cannot be resolved or the subscription cannot be opened.
DeclarationErrorWhen the Binding cannot be shaped (a selection matching nothing, a field with no rendering).
@property
ros2_monitoring_presence: Mapping[str, bool] =

Return, per Binding name, whether its topic has a publisher right now.

This is Satisfied for a topic read into Monitoring: presence, never first data. It is the count the status code is written from, so a required Binding and its variables agree. A Binding that declared no type and whose topic has not appeared is False, not missing.

@property
ros2_qos_provenance: Mapping[str, BindingQoS] =

Return, per Binding name, what its subscription asks for and where that came from.

A Binding still waiting for its topic is absent, because it has no endpoint yet.

@property
ros2_subscriptions: tuple[Subscription, ...] =

Return the subscription each bound Binding on this item opened, in the order they bound.

@property
ros2_unbound_bindings: tuple[MonitoringBinding, ...] =

Return the Bindings still waiting for their topic to appear on the graph.

Empty on a Machine whose declarations all name their type, which then never reads the graph.

async def _bind_from_the_graph(self, binding: MonitoringBinding, types: tuple[str, ...]):

Give one waiting Binding its subscription and its nodes, or report why it has neither.

async def _follow_binding(self, mirrored: _Mirrored):

Write the messages of one Binding until the subscription closes, throttled by max_rate.

async def _follow_binding_limited(self, mirrored: _Mirrored, window: float):

Write at most one message per window seconds: the newest, never losing the last.

The first message after a quiet spell is written at once. A message arriving inside a window replaces the one waiting, and the waiting one is written when the window ends. The throttle sits in front of the Projection, so a replaced message is never decoded.

async def _follow_graph(self):

Bind each waiting Binding as its topic appears, then stop watching.

async def _follow_publishers(self, mirrored: _Mirrored):

Write the status code every time the topic gains or loses its publishers.

The count arrives on the subscription's DDS match events, without reading the graph. The first one arrives at once, so a Binding nobody publishes starts at BadNoCommunication.

async def _follow_qos(self, mirrored: _Mirrored):

Raise one BindingEvent for every QoS incompatibility the middleware reports.

Any adaptation has already happened beneath the handle. The event tells a client that it happened, on which policy, and whether anything will change.

async def _init_monitoring_mirror(self, bindings: Iterable[MonitoringBinding], *, runtime: RuntimeInterface, registry: ProjectionRegistry = DEFAULT_REGISTRY):

Open, shape and start every Binding that declared a type, in declaration order.

Anything wrong with such a declaration is fatal at init (a missing interface package, a pattern matching nothing, a field with no rendering, a name written twice), and whatever was already opened is closed first. A Binding that declared no type is put aside, and one watch on the graph facet covers all of them.

async def _open_binding(self, binding: MonitoringBinding, *, message_type: str, at_init: bool) -> _Mirrored | None:

Subscribe, shape the plan, and ask the chokepoint for the nodes of one Binding.

Returns
_Mirrored | NoneThe live Binding, or None when a cap refused its nodes (the subscription is closed again).
async def _report_a_capped_payload(self, mirrored: _Mirrored, name: str, value: object):

Say once, as a BindingEvent, that a bulk payload reached this server's ceiling.

The test is the length against the ceiling, because the cap is applied in a pure function that cannot report. A buffer as long as the ceiling is a cut one.

def _report_unknown_name(self, mirrored: _Mirrored, name: str):

Report, once per Binding, a Projection whose decode names what its shape never created.

Unreachable with the shipped Projection. A curated one whose halves disagree is exposed only by a message, so it is reported instead of raised, and the value is not written.

def _require_an_unused_binding_name(self, name: str):

Refuse a second Binding of one name on this item.

Raises
DuplicateBindingNameErrorWhen one is already bound or still waiting for its topic. Without this check the chokepoint would refuse the first colliding variable and name a field path instead of the Binding.
def _require_runtime(self) -> RuntimeInterface:

Return the Runtime this mirror was initialised with.

Raises
DeclarationErrorWhen there is none (a wiring fault).
async def _start_following(self, mirrored: _Mirrored):

Put the first status on one Binding's variables, then start its tasks.

The status is written here and not left to the publisher task, so the variables carry BadNoCommunication from the moment they exist and never the Good that node creation leaves.

def _start_watching_the_graph(self):

Open one watch covering every Binding still waiting for its topic, if there are any.

With none, nothing is opened: the facet reads the graph only while a watch is open.

async def _stop_monitoring_mirror(self):

Stop following every Binding, close its subscription, and let go of the graph.

Idempotent. It runs before the Runtime stops, because a Component torn down on its own still has to stop reading.

async def _write_message(self, mirrored: _Mirrored, message: Message):

Decode one message and write it once, to the nodes of its Binding.

async def _write_message_safely(self, mirrored: _Mirrored, message: Message):

Write one message, and survive whatever it could not be written as.

async def _write_status(self, mirrored: _Mirrored):

Re-write every node of one Binding under the status its publishers now imply.

The value goes with it, because a status written alone leaves the variant null.

_deferred: list[MonitoringBinding] =

Undocumented

_graph_task: asyncio.Task[None] | None =

Undocumented

_graph_watch: GraphWatch | None =

Undocumented

_mirrored: list[_Mirrored] =

Undocumented

_registry: ProjectionRegistry =

Undocumented

_runtime: RuntimeInterface | None =

Undocumented