Module messaging_domain

Source
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_domains Module: A collection of i32 constants 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.

  • MessagingDomain Enum: A type-safe Rust representation of the domains. The main Messaging thread 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_domains constants 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 MessagingDomain enum 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_executed method 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

  1. An external tool sends a message with the domain field set to 1.
  2. The Messaging thread receives the message and reads the integer 1.
  3. It matches 1 to messaging_domains::REFILL.
  4. It converts this into the MessagingDomain::Refill enum variant.
  5. It then uses this enum variant to route the command to the correct channel.

Enums§

MessagingDomain
Identifies the addressee of the message