# Rust MXAccess worker prototype This crate exercises the gateway's existing worker contract with native 32-bit Windows COM. Cargo generates the Rust protobuf types from the gateway's canonical schemas at build time. The worker authenticates the launch nonce, negotiates a frame limit, activates LMXProxy on a dedicated message-pumping STA, and reports readiness and heartbeats. It supports registration, item lifecycle and advice, value snapshots, identity lookup, writes, and the worker diagnostic commands. The worker attaches to both MXAccess COM connection points to deliver OnDataChange, OperationComplete, OnWriteComplete, and OnBufferedDataChange notifications. OnDataChange carries the value, quality, MXAccess status records, source timestamp when available, and worker sequence and timestamp. The bounded queue faults the session on overflow. Shutdown detaches the sink, unadvises remaining items, and unregisters clients before releasing COM. The C# worker is the gateway default. Event conversion supports standard Automation scalar values and homogeneous arrays of those types. Other variant types are reported as unknown with the Automation type in the diagnostic. The worker serializes COM commands, accepts cancellation for commands still waiting, and continues sending events and heartbeats while a command runs. A COM call that exceeds the STA ceiling faults the session. Bulk item operations return one ordered result per requested item. ReadBulk uses a cached value for an existing advice when available and otherwise uses temporary advice with a shared timeout. Duplicate snapshot reads share one subscription. The worker supports Write, Write2, WriteSecured, and WriteSecured2, including their bulk forms. It converts scalar and typed array inputs to Automation VARIANTs. For a timestamped write, a protobuf timestamp becomes local wall-clock time for MXAccess. Single-item replies carry the matching OnWriteComplete status rows when MXAccess responds within the configured wait (default 1,500 ms). This correlation uses the server and item handles supplied by MXAccess. The event also flows through StreamEvents. Bulk results report per-item COM acceptance and clients can observe commit outcomes on the event stream. ## Native alarm provider The Rust worker handles alarm subscription, active snapshots, standby watch-list replacement, and authenticated acknowledgement in the worker process. It uses the installed 32-bit AVEVA WnWrap COM alarm consumer for Alarmmgr and MXAccess advice for the optional subtag fallback. The worker polls WnWrap on its COM thread, emits changes on the existing event queue, and retains previously seen records that a capped snapshot may have omitted. To acknowledge a Galaxy alarm, the worker authenticates the operator with MXAccess, writes the comment to the alarm's `AckMsg` attribute, and waits for `OnWriteComplete` within the configured write-completion window. Deploy the Rust executable on a Windows host with the System Platform COM components registered. The Rust worker has no .NET worker companion. ## Build and test From this directory on Windows, with Rust, the x86 MSVC target and linker, and `protoc` on PATH: ```powershell cargo build --locked --release --target i686-pc-windows-msvc cargo test --locked --target i686-pc-windows-msvc ``` On a development Windows host with 32-bit System Platform MXAccess registered, run the opt-in test against a temporary pipe. Set `MXGATEWAY_RUST_SMOKE_ITEM` to an item available in that host's Galaxy to include AddItem and RemoveItem in the smoke test. ```powershell $env:MXGATEWAY_RUST_SMOKE_ITEM = 'TestChildObject.TestInt' cargo test --locked --target i686-pc-windows-msvc --test live_mxaccess -- --ignored ``` The smoke test starts and terminates its own worker and exercises the pipe handshake, heartbeat, registration, item lifecycle when configured, and graceful shutdown. It runs without a gateway service. Portable framing tests also run with `cargo test --locked` on macOS and Linux. From the repository root on a Windows development host with `TestMachine_001.TestChangingInt` deployed, run the opt-in HTTP/2 test to verify the Rust worker through the gateway: ```powershell $env:MXGATEWAY_RUN_RUST_WORKER_LIVE_TESTS = '1' $env:MXGATEWAY_LIVE_MXACCESS_WORKER_EXE = (Resolve-Path 'src/mxgateway-worker-rust/target/i686-pc-windows-msvc/release/mxgateway-worker-rust.exe').Path dotnet test src/ZB.MOM.WW.MxGateway.IntegrationTests --filter FullyQualifiedName~GatewayGrpc_WithRustWorker_StreamsChangingIntegersAndUnadvises ``` The test starts the gateway gRPC service on an ephemeral loopback port and launches the configured Rust worker. It verifies that the client receives distinct good-quality integer values in sequence and that the worker emits no new data for the item after UnAdvise. Run the write round-trip on a development host with a writable integer test item. The test writes and reads back distinct values, checks OnWriteComplete and unary status rows, exercises partial bulk failure, and restores the original value through Write2. ```powershell $env:MXGATEWAY_LIVE_MXACCESS_ITEM = 'TestChildObject.TestInt' dotnet test src/ZB.MOM.WW.MxGateway.IntegrationTests --filter FullyQualifiedName~GatewayGrpc_WithRustWorker_WritesAndReceivesOnWriteComplete ``` The bulk and subtag tests use the deployed `TestChangingInt` items. The Alarmmgr test raises `Galaxy!TestArea.TestMachine_001.TestAlarm001`, checks that the gateway rejects an unknown operator, and verifies the authenticated acknowledgement and its operator attribution on `StreamAlarms`. It restores the test UDA afterward. The development rig uses `Administrator` with an empty password. The test accepts credentials through `MXGATEWAY_LIVE_MXACCESS_WRITE_SECURED_USER` and `MXGATEWAY_LIVE_MXACCESS_WRITE_SECURED_PASSWORD`. ```powershell dotnet test src/ZB.MOM.WW.MxGateway.IntegrationTests --filter 'FullyQualifiedName~GatewayGrpc_WithRustWorker_' ``` ## COM interface evidence The native adapter uses the dual `ILMXProxyServer` interface from the installed `ArchestrA.MxAccess` 3.2.0.0 assembly. REA inspection confirmed the declaration order and managed signatures for Register, Unregister, AddItem, and RemoveItem. Windows reflection confirmed the interface IID, dual-interface flag, DISPIDs, and BSTR input annotations. REA and Windows reflection also identified the base event dispatch interface and the `MXSTATUS_PROXY` layout. The live tests exercise the corresponding native calls and event callbacks. - Assembly SHA-256 `cba8b607305ee0c70ca38b09eca645ae3b98c35a7b78ec051eb4381f48d9e0b1` - REA managed member evidence `ev_78053da509335e3e3749b8e6bb020f28c45255b54d910546659c6760eb52160b` - REA event member evidence `ev_97162abcd831b2d84b5b43fb72cd9876252bbe3bb0af5c4673a6954911500e54` - REA write member evidence for `ILMXProxyServer` and `ILMXProxyServer4` `ev_1b4fe7ab436437391b76f9fa3a300f45b58a4e1cff6aa84e30854f653c0a20df` - REA extended COM and buffered event member evidence `ev_39de39d626e3a933b259fa2650b42311ba60d6844d7b012284467284e8b82977` - REA member evidence for the WnWrap v1 lifecycle and v2 XML snapshot interfaces `ev_4fd97bf483b1cde2544b93a90f4de97569ea95c24f1eaa8aee49b5a1ed552558`