Skip to main content

Crate microrti_client

Crate microrti_client 

Source
Expand description

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.
Cargo featureModuleLink
fedpro (default)fedproa 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]
embeddedembeddedan RTI inside the federate’s process, shared by any number of ambassadors
test-utiltestinga 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 RtiLink over a Federate Protocol session (IEEE 1516.1-2025, 12.13), to this project’s RTI or to any other HLA 4 RTI.
local
An RtiLink to an RTI that lives in the same process.

Structs§

AttributeHandle
Handle of a class attribute of the FDD.
AttributeSetRegionSetPair
A set of attributes together with the set of regions used for them.
Bytes
A cheaply cloneable and sliceable chunk of contiguous memory.
CallbackFn
Adapts a closure taking the Callback enum into a FederateAmbassador, for federates that prefer one match over implementing trait methods.
ConfigurationResult
What the RTI did with the RtiConfiguration passed to Connect (4.2).
Connectors
A set of LinkFactory connectors selected by the scheme of the RTI address.
Credentials
Credentials presented to the RTI’s authorization service by Connect (12.5).
DimensionHandle
Handle of a dimension of the FDD.
FederateHandle
Handle of a joined federate.
FederateHandleSaveStatusPair
Save status of one federate, from the Federation Save Status Response callback (4.26).
FederateInternalError
The one exception a federate ambassador may raise: something went wrong inside the federate while it handled a callback.
FederateRestoreStatus
Restore status of one federate, from the Federation Restore Status Response callback (4.35).
FederationExecutionInformation
One entry of the Report Federation Executions callback (4.8).
FederationExecutionMemberInformation
One entry of the Report Federation Execution Members callback (4.10).
InteractionClassHandle
Handle of an interaction class of the FDD.
JoinResult
Result of Join Federation Execution (4.11).
LinkCallback
A callback request pulled from a link, with the token needed to answer it.
MessageRetractionHandle
Handle of a sent message that may still be retracted.
MessageRetractionReturn
Result of the timestamped sending services (6.10, 6.12, 6.14, 6.16): the retraction handle, if the message can be retracted.
NullFederateAmbassador
A federate ambassador that ignores every callback (the NullFederateAmbassador of the standard APIs).
ObjectClassHandle
Handle of an object class of the FDD.
ObjectInstanceHandle
Handle of an object instance.
ParameterHandle
Handle of an interaction parameter of the FDD.
RangeBounds
Lower and upper bound of a range on one dimension (9.1).
RegionHandle
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 ExceptionKind plus a human readable detail message.
SupplementalReceiveInfo
The producing federate and the conveyed regions of a Receive Interaction callback (6.13), grouped.
SupplementalReflectInfo
The producing federate and the conveyed regions of a Reflect Attribute Values callback (6.11), grouped.
TimeQueryReturn
Result of Query GALT and Query LITS (8.17, 8.19): a logical time, if one is defined.
TransportationTypeHandle
Handle of a transportation type.
WeakRtiAmbassador
A reference to an RtiAmbassador that does not keep its connection alive.

Enums§

AdditionalSettingsResultCode
Outcome of the additional settings passed to Connect (4.2).
Callback
One RTI-initiated service invocation with its arguments.
CallbackModel
How callbacks reach the federate ambassador (4.2, 10.57 to 10.60).
ExceptionKind
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).
LinkError
Failure of an RtiLink or of a LinkFactory.
LinkState
Condition of an RtiLink.
LogicalTime
A point on the federation time axis, in one of the standardized representations.
LogicalTimeInterval
A (possibly zero) distance on the federation time axis; also used for lookahead.
OrderType
Message ordering (8.1).
ResignAction
What the RTI does with a federate’s objects and attributes when it resigns (4.12).
RestoreFailureReason
Why a federation restore did not complete (4.32).
RestoreStatus
Progress of a federate in a federation restore (4.35).
SaveFailureReason
Why a federation save did not complete (4.23).
SaveStatus
Progress of a federate in a federation save (4.26).
ServiceGroup
The service groups of clauses 4 to 10, as used by Normalize Service Group (10.29).
SynchronizationPointFailureReason
Why a synchronization point could not be registered (4.15).
TimeKind
One of the standardized time representations.

Constants§

HLA_VERSION
HLA version string reported by this implementation (getHLAversion of the standard APIs).

Traits§

FederateAmbassador
The federate’s side of the interface: the RTI-initiated services of clauses 4 to 8.
LinkFactory
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 with CouldNotDecode when 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§

AttributeHandleSet
Set of attribute handles.
AttributeHandleValueMap
Attribute values keyed by attribute handle. A value is the encoded bytes of the attribute’s datatype.
AttributeSetRegionSetPairList
Collection of attribute set / region set pairs used by the DDM services of clause 9.
CallbackResult
Result of every FederateAmbassador method.
ConveyedRegion
The ranges of one region as conveyed with a reflected update or a received interaction (9.1.7).
ConveyedRegionSet
The regions conveyed with a reflected update or a received interaction.
DimensionHandleSet
Set of dimension handles.
FederateHandleSet
Set of federate handles.
InteractionClassHandleSet
Set of interaction class handles.
ParameterHandleValueMap
Parameter values keyed by parameter handle. A value is the encoded bytes of the parameter’s datatype.
RegionHandleSet
Set of region handles.
RtiResult
Result type of every RTI service.