Expand description
Federate side of HLA 4 (IEEE Std 1516.1-2025): the RTI ambassador and the federate ambassador in Rust.
RtiAmbassadoroffers every federate-initiated service of clauses 4 to 10 as a typed, blocking method. The methods are named after theCallRequestalternatives of the Federate Protocol (12.13.3):UpdateAttributeValuesWithTimeRequestisRtiAmbassador::update_attribute_values_with_time.FederateAmbassadoris the trait a federate implements to receive the RTI-initiated services, one method perCallbackRequestalternative, all with empty default bodies. Federates that prefer amatchhandle theCallbackenum instead, throughCallbackFn.RtiLinkis the seam to the RTI: anything that can exchange the service messages, such as a Federate Protocol session or an in-process RTI (local).Connectorsopens 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(())
}Re-exports§
pub use microrti_proto as proto;
Modules§
- fedpro
- The network link: an
RtiLinkover a Federate Protocol session (IEEE 1516.1-2025, 12.13), to this project’s RTI or to any other HLA 4 RTI. - local
- An
RtiLinkto an RTI that lives in the same process.
Structs§
- Attribute
Handle - Handle of a class attribute of the FDD.
- Attribute
SetRegion SetPair - A set of attributes together with the set of regions used for them.
- Bytes
- A cheaply cloneable and sliceable chunk of contiguous memory.
- Callback
Fn - Adapts a closure taking the
Callbackenum into aFederateAmbassador, for federates that prefer onematchover implementing trait methods. - Configuration
Result - What the RTI did with the
RtiConfigurationpassed to Connect (4.2). - Connectors
- A set of
LinkFactoryconnectors selected by the scheme of the RTI address. - Credentials
- Credentials presented to the RTI’s authorization service by Connect (12.5).
- Dimension
Handle - Handle of a dimension of the FDD.
- Federate
Handle - Handle of a joined federate.
- Federate
Handle Save Status Pair - Save status of one federate, from the Federation Save Status Response callback (4.26).
- Federate
Internal Error - The one exception a federate ambassador may raise: something went wrong inside the federate while it handled a callback.
- Federate
Restore Status - Restore status of one federate, from the Federation Restore Status Response callback (4.35).
- Federation
Execution Information - One entry of the Report Federation Executions callback (4.8).
- Federation
Execution Member Information - One entry of the Report Federation Execution Members callback (4.10).
- Interaction
Class Handle - Handle of an interaction class of the FDD.
- Join
Result - Result of Join Federation Execution (4.11).
- Link
Callback - A callback request pulled from a link, with the token needed to answer it.
- Message
Retraction Handle - Handle of a sent message that may still be retracted.
- Message
Retraction Return - Result of the timestamped sending services (6.10, 6.12, 6.14, 6.16): the retraction handle, if the message can be retracted.
- Null
Federate Ambassador - A federate ambassador that ignores every callback (the
NullFederateAmbassadorof the standard APIs). - Object
Class Handle - Handle of an object class of the FDD.
- Object
Instance Handle - Handle of an object instance.
- Parameter
Handle - Handle of an interaction parameter of the FDD.
- Range
Bounds - Lower and upper bound of a range on one dimension (9.1).
- Region
Handle - Handle of a region created with Create Region.
- RtiAmbassador
- The federate’s access to the RTI: every federate-initiated service of clauses 4 to 10 as a method.
- RtiConfiguration
- The optional arguments of Connect that select and tune the RTI (4.2). Built with the
with_*methods. - RtiError
- An RTI exception: a standard
ExceptionKindplus a human readable detail message. - Supplemental
Receive Info - The producing federate and the conveyed regions of a Receive Interaction callback (6.13), grouped.
- Supplemental
Reflect Info - The producing federate and the conveyed regions of a Reflect Attribute Values callback (6.11), grouped.
- Time
Query Return - Result of Query GALT and Query LITS (8.17, 8.19): a logical time, if one is defined.
- Transportation
Type Handle - Handle of a transportation type.
- Weak
RtiAmbassador - A reference to an
RtiAmbassadorthat does not keep its connection alive.
Enums§
- Additional
Settings Result Code - Outcome of the additional settings passed to Connect (4.2).
- Callback
- One RTI-initiated service invocation with its arguments.
- Callback
Model - How callbacks reach the federate ambassador (4.2, 10.57 to 10.60).
- Exception
Kind - Every exception an HLA 4 RTI can raise, identified by its standard name.
- FomModule
- Designator of a FOM module or MIM for Create and Join Federation Execution (12.13.3.3 a).
- Link
Error - Failure of an
RtiLinkor of aLinkFactory. - Link
State - Condition of an
RtiLink. - Logical
Time - A point on the federation time axis, in one of the standardized representations.
- Logical
Time Interval - A (possibly zero) distance on the federation time axis; also used for lookahead.
- Order
Type - Message ordering (8.1).
- Resign
Action - What the RTI does with a federate’s objects and attributes when it resigns (4.12).
- Restore
Failure Reason - Why a federation restore did not complete (4.32).
- Restore
Status - Progress of a federate in a federation restore (4.35).
- Save
Failure Reason - Why a federation save did not complete (4.23).
- Save
Status - Progress of a federate in a federation save (4.26).
- Service
Group - The service groups of clauses 4 to 10, as used by Normalize Service Group (10.29).
- Synchronization
Point Failure Reason - Why a synchronization point could not be registered (4.15).
- Time
Kind - One of the standardized time representations.
Constants§
- HLA_
VERSION - HLA version string reported by this implementation (
getHLAversionof the standard APIs).
Traits§
- Federate
Ambassador - The federate’s side of the interface: the RTI-initiated services of clauses 4 to 8.
- Link
Factory - Opens links: the connector abstraction used by the Connect service (4.2).
- RtiLink
- Transport of service messages between one federate and its RTI.
Functions§
- decode_
hla_ unicode_ string - Decodes an
HLAunicodeString. Fails withCouldNotDecodewhen the bytes are truncated, too long or not valid UTF-16. - encode_
hla_ unicode_ string - Encodes text as an
HLAunicodeString: a 32-bit big-endian count of UTF-16 code units followed by the code units, big endian. - global_
connectors - A snapshot of the process-wide connector set.
- register_
connector - Registers a connector for an address scheme in the process-wide set used by
RtiAmbassador::new. - register_
default_ connector - Registers the process-wide connector for addresses without a registered scheme.
- request_
name - Name of the Federate Protocol message of a request, for example
"QueryGALTRequest".
Type Aliases§
- Attribute
Handle Set - Set of attribute handles.
- Attribute
Handle Value Map - Attribute values keyed by attribute handle. A value is the encoded bytes of the attribute’s datatype.
- Attribute
SetRegion SetPair List - Collection of attribute set / region set pairs used by the DDM services of clause 9.
- Callback
Result - Result of every
FederateAmbassadormethod. - Conveyed
Region - The ranges of one region as conveyed with a reflected update or a received interaction (9.1.7).
- Conveyed
Region Set - The regions conveyed with a reflected update or a received interaction.
- Dimension
Handle Set - Set of dimension handles.
- Federate
Handle Set - Set of federate handles.
- Interaction
Class Handle Set - Set of interaction class handles.
- Parameter
Handle Value Map - Parameter values keyed by parameter handle. A value is the encoded bytes of the parameter’s datatype.
- Region
Handle Set - Set of region handles.
- RtiResult
- Result type of every RTI service.