microrti-client 0.1.2

Federate side of HLA 4 (IEEE 1516.1-2025): RtiAmbassador and FederateAmbassador over an abstract RTI link.
Documentation
//! Federate side of HLA 4 (IEEE Std 1516.1-2025): the RTI ambassador and the federate ambassador in Rust.
//!
//! * [`RtiAmbassador`] offers every federate-initiated service of clauses 4 to 10 as a typed, blocking
//!   method. The methods are named after the `CallRequest` alternatives of the Federate Protocol
//!   (12.13.3): `UpdateAttributeValuesWithTimeRequest` is [`RtiAmbassador::update_attribute_values_with_time`].
//! * [`FederateAmbassador`] is the trait a federate implements to receive the RTI-initiated services, one
//!   method per `CallbackRequest` alternative, all with empty default bodies. Federates that prefer a
//!   `match` handle the [`Callback`] enum instead, through [`CallbackFn`].
//! * [`RtiLink`] is the seam to the RTI: anything that can exchange the service messages, such as a
//!   Federate Protocol session or an in-process RTI ([`local`]). [`Connectors`] opens links by RTI address.
//!
//! # Links
//!
//! | Cargo feature | Module | Link |
//! | --- | --- | --- |
//! | `fedpro` (default) | `fedpro` | a Federate Protocol session (12.13) to any HLA 4 RTI; [`RtiAmbassador::new`] uses it for the RTI addresses `tcp://host:port`, `tls://`, `ws://host:port/path`, `wss://` and bare `host[:port]` |
//! | `embedded` | `embedded` | an RTI inside the federate's process, shared by any number of ambassadors |
//! | `test-util` | `testing` | a scripted in-memory link for tests |
//!
//! Handles are opaque byte strings ([`ObjectClassHandle`] and friends), sets and maps are standard
//! collections, logical times are [`LogicalTime`] / [`LogicalTimeInterval`] values in the representation
//! of the joined federation execution ([`RtiAmbassador::time_kind`]). Every service returns
//! [`RtiResult`]; the error names the standard exception ([`ExceptionKind`]).
//!
//! Both callback models are implemented here, as 12.13.3.2 requires of a Federate Protocol client:
//! with [`CallbackModel::Evoked`] callbacks wait for [`RtiAmbassador::evoke_callback`] or
//! [`RtiAmbassador::evoke_multiple_callbacks`], with [`CallbackModel::Immediate`] a thread of the
//! ambassador delivers them as they arrive. Callbacks of one federate never run concurrently, and they may
//! invoke any service except the six listed in 12.8.
//!
//! # Generated code
//!
//! `src/services.rs`, `src/callback.rs`, `src/testing/replies.rs` and the two `tests/generated_*.rs` files
//! are written by `tools/gen_client.py` from the protobuf files in `proto/`. Everything with behaviour of
//! its own (connection handling, callback delivery, conversions) is written by hand.
//!
//! # Example
//!
//! The example runs against the scripted link of the `test-util` feature, which answers every call with
//! an empty success response; with a real link the same code talks to an RTI.
//!
//! ```
//! use std::time::Duration;
//!
//! use microrti_client::testing::MockLink;
//! use microrti_client::{
//!     AttributeHandleSet, AttributeHandleValueMap, Bytes, Callback, CallbackFn, CallbackModel, FomModule,
//!     ResignAction, RtiAmbassador, RtiResult,
//! };
//!
//! fn main() -> RtiResult<()> {
//!     let link = MockLink::new();
//!     let rti = RtiAmbassador::with_link(link.clone());
//!
//!     // The federate ambassador: here a closure matching on the callbacks it cares about.
//!     let federate = CallbackFn::new(|callback: Callback| {
//!         if let Callback::DiscoverObjectInstance { object_instance_name, .. } = callback {
//!             println!("discovered {object_instance_name}");
//!         }
//!         Ok(())
//!     });
//!     rti.connect(federate, CallbackModel::Evoked)?;
//!
//!     let fom = FomModule::content("Restaurant.xml", "<objectModel/>");
//!     rti.create_federation_execution("Lunch", &fom)?;
//!     let joined = rti.join_federation_execution("Chef", "Lunch")?;
//!     println!("joined as {} using {}", joined.federate_handle, rti.time_kind()?);
//!
//!     let food = rti.get_object_class_handle("HLAobjectRoot.Food")?;
//!     let name = rti.get_attribute_handle(&food, "Name")?;
//!     let attributes = AttributeHandleSet::from([name.clone()]);
//!     rti.publish_object_class_attributes(&food, &attributes)?;
//!     rti.subscribe_object_class_attributes(&food, &attributes)?;
//!
//!     let soup = rti.register_object_instance(&food)?;
//!     let values = AttributeHandleValueMap::from([(name, Bytes::from_static(b"soup"))]);
//!     rti.update_attribute_values(&soup, &values, b"lunch time")?;
//!
//!     // EVOKED model: callbacks are delivered here, on this thread.
//!     rti.evoke_multiple_callbacks(Duration::ZERO, Duration::from_millis(10))?;
//!
//!     rti.resign_federation_execution(ResignAction::DeleteObjectsThenDivest)?;
//!     rti.destroy_federation_execution("Lunch")?;
//!     rti.disconnect()?;
//!     assert!(link.is_closed());
//!     Ok(())
//! }
//! ```
#![warn(missing_docs)]

mod ambassador;
mod callback;
#[cfg(feature = "embedded")]
pub mod embedded;
mod federate;
#[cfg(feature = "fedpro")]
pub mod fedpro;
mod handles;
mod link;
pub mod local;
mod services;
#[cfg(feature = "test-util")]
pub mod testing;
mod types;
mod wire;

pub use ambassador::{RtiAmbassador, WeakRtiAmbassador};
pub use bytes::Bytes;
pub use callback::{Callback, FederateAmbassador};
pub use federate::{CallbackFn, CallbackResult, FederateInternalError, NullFederateAmbassador};
pub use handles::{
    AttributeHandle, DimensionHandle, FederateHandle, InteractionClassHandle, MessageRetractionHandle,
    ObjectClassHandle, ObjectInstanceHandle, ParameterHandle, RegionHandle, TransportationTypeHandle,
};
pub use link::{
    Connectors, LinkCallback, LinkError, LinkFactory, LinkState, RtiLink, global_connectors,
    register_connector, register_default_connector,
};
pub use microrti_core::{
    ExceptionKind, HLA_VERSION, LogicalTime, LogicalTimeInterval, RtiError, RtiResult, TimeKind,
};
/// The Federate Protocol message types (Annex D), as exchanged over an [`RtiLink`].
pub use microrti_proto as proto;
pub use services::request_name;
pub use types::{
    AdditionalSettingsResultCode, AttributeHandleSet, AttributeHandleValueMap, AttributeSetRegionSetPair,
    AttributeSetRegionSetPairList, CallbackModel, ConfigurationResult, ConveyedRegion, ConveyedRegionSet,
    Credentials, DimensionHandleSet, FederateHandleSaveStatusPair, FederateHandleSet, FederateRestoreStatus,
    FederationExecutionInformation, FederationExecutionMemberInformation, FomModule,
    InteractionClassHandleSet, JoinResult, MessageRetractionReturn, OrderType, ParameterHandleValueMap,
    RangeBounds, RegionHandleSet, ResignAction, RestoreFailureReason, RestoreStatus, RtiConfiguration,
    SaveFailureReason, SaveStatus, ServiceGroup, SupplementalReceiveInfo, SupplementalReflectInfo,
    SynchronizationPointFailureReason, TimeQueryReturn, decode_hla_unicode_string, encode_hla_unicode_string,
};