1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//! 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(())
//! }
//! ```
pub use ;
pub use Bytes;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
/// The Federate Protocol message types (Annex D), as exchanged over an [`RtiLink`].
pub use microrti_proto as proto;
pub use request_name;
pub use ;