Expand description
Definition of messaging domains including related functionality Defines the domains (subsystems) that can be controlled via Inter-Process Communication (IPC).
This module serves as a dictionary for the application’s controllable parts, such as
Refill, Heating, and Feed. It provides both the raw integer constants used in the
low-level POSIX message queue protocol and a type-safe Rust enum for use in the
application’s internal logic.
This entire module is conditionally compiled and is only available on target_os = "linux".
§Key Components
-
messaging_domainsModule: A collection ofi32constants that represent the unique identifier for each domain in the raw byte message. These are the “on-the-wire” values that form the external contract with command-line tools. -
MessagingDomainEnum: A type-safe Rust representation of the domains. The mainMessagingthread translates the raw integer from an incoming message into one of these variants before dispatching a command. This prevents logic errors related to “magic numbers.”
§Design and Purpose
The separation between the raw constants and the type-safe enum is a deliberate design choice that enhances robustness.
-
Protocol Stability: The
messaging_domainsconstants define a stable, language-agnostic protocol. External C or Python scripts can use these same integer values to communicate with the application. -
Type Safety: By converting the raw integer to a
MessagingDomainenum at the earliest opportunity, the rest of the application can use pattern matching and benefit from the compiler’s checks, eliminating a whole class of potential bugs. -
Runtime Validation: The
is_domain_thread_executedmethod provides a way to check if a target domain’s thread is actually running before attempting to send a message, preventing unnecessary channel errors for disabled features.
§Example Flow
- An external tool sends a message with the domain field set to
1. - The
Messagingthread receives the message and reads the integer1. - It matches
1tomessaging_domains::REFILL. - It converts this into the
MessagingDomain::Refillenum variant. - It then uses this enum variant to route the command to the correct channel.
Enums§
- Messaging
Domain - Identifies the addressee of the message