Skip to main content

Engine

Struct Engine 

Source
pub struct Engine<S: MessageStore = MemStore> { /* private fields */ }
Expand description

The sans-I/O OCPP protocol engine.

See the module documentation for the rules it enforces.

Implementations§

Source§

impl Engine<MemStore>

Source

pub fn new(config: EngineConfig) -> Self

An engine with an in-memory queue.

Source§

impl<S: MessageStore> Engine<S>

Source

pub fn with_store(config: EngineConfig, store: S) -> Result<Self, StoreError>

An engine backed by a durable MessageStore.

Anything the store still holds is loaded into the queue, so a Charging Station replays the transaction messages a power cut interrupted.

Source

pub fn require_boot(&mut self, now: Instant)

Re-opens the boot gate, so the station registers again before ordinary traffic.

The engine keeps its boot state across reconnects (Part 4 §5.4). The exception is B10.FR.10 (2.0.1 edition 4, 2.1 edition 2): a station that “successfully connected after having switched to a different NetworkConnectionProfile” SHALL send a BootNotificationRequest “even if it has not rebooted”. This returns the engine to BootState::Idle and reports it as Output::BootState, the same signal a Pending/Rejected retry gives; the application then sends the BootNotification. The Tokio station calls it when it connects on a different configuration slot.

Source

pub fn adopt_pending(&mut self, now: Instant) -> Result<usize, StoreError>

Queues what another process added to the store since this engine was built.

The engine reads its store when it is built (with_store) and otherwise only writes it. With a store shared between processes — a station and a metering daemon on one SQLite file — a message the other process pushes is durable at once but would leave only on the next start. This reads MessageStore::pending again and queues every entry whose Seq the engine does not already hold, queued or in flight, so calling it twice queues nothing twice.

Among messages not yet sent, stored ones are ordered by Seq, so each producer’s messages leave in the order it pushed them — what per-transaction ordering requires (1.6 §3.7, E04.FR.01–03), since one transaction’s messages come from one producer. A message already sent is never reordered. Adoption obeys OfflinePolicy::max_queued: what does not fit stays in the store, still counted by MessageStore::len, and is adopted by a later call. During a shutdown drain nothing is adopted.

Only one engine may drain a store. A second one would adopt — and send — every entry the first holds; other processes push and never drain.

Returns how many entries were queued. The Tokio station calls this on connect and periodically when built with store_poll.

§Errors

The store’s error from pending(). The queue is unchanged.

Source

pub fn set_call_timeout(&mut self, timeout: Duration)

Changes the message timeout.

2.x sources it from the active NetworkConnectionProfile.messageTimeout, falling back to OCPPCommCtrlr.MessageTimeout[Default] — so it changes when the station fails over to a different network configuration slot, and it must be changeable at run time. A call that is already outstanding keeps the deadline it was given.

Source

pub fn set_id_generator(&mut self, ids: Box<dyn IdGenerator + Send>)

Replaces the IdGenerator.

A Local Controller uses this to guarantee that the ids it invents cannot collide with the CSMS’s (Part 4 §6.4).

Source

pub fn config(&self) -> &EngineConfig

The configuration this engine was built with.

Source

pub fn version(&self) -> Version

The negotiated version.

Source

pub fn is_connected(&self) -> bool

Whether the transport is currently up.

Source

pub fn boot_state(&self) -> BootState

The boot state machine’s current state.

Source

pub fn heartbeat_interval(&self) -> Option<Duration>

The heartbeat interval the CSMS asked for, once boot succeeded.

Source

pub fn queued(&self) -> usize

How many messages are waiting to be sent.

This is what GetTransactionStatus.messagesInQueue reports.

Source

pub fn store(&self) -> &S

The durable store.

Source

pub fn has_outstanding_call(&self) -> bool

Whether one of our calls is currently outstanding.

Source

pub fn awaiting_response(&self) -> usize

How many of the peer’s calls are waiting for an answer.

More than one means the peer broke the one-outstanding-CALL rule and InboundConcurrency::Serve let it.

Source

pub fn handle(&mut self, now: Instant, input: Input<'_>)

Feeds one event into the state machine at time now.

now is the driver’s monotonic clock, taken on every input rather than only on Input::Timeout: every input can arm a deadline, and one computed from a stale clock fires the moment it is armed.

Source

pub fn now(&self) -> Instant

The engine’s view of the driver’s clock.

Source

pub fn poll_output(&mut self) -> Option<Output>

Takes the next thing the driver must do.

Source

pub fn drain(&mut self) -> Vec<Output>

Takes everything the driver must do, in order.

Source

pub fn call( &mut self, now: Instant, action: &str, payload: Box<RawValue>, ) -> Result<CallToken, EngineError>

Starts a CALL (or a SEND, if that is what the action is).

The call is accepted immediately and reaches the wire when the one-outstanding rule, the boot gate and the connection allow it. The returned CallToken appears again in the matching CallOutcome.

Source

pub fn call_with( &mut self, now: Instant, action: &str, payload: Box<RawValue>, options: CallOptions, ) -> Result<CallToken, EngineError>

Starts a call with per-call overrides.

Source

pub fn respond( &mut self, now: Instant, id: &MessageId, payload: &RawValue, ) -> Result<(), EngineError>

Answers an outstanding request with a CALLRESULT.

Source

pub fn respond_error( &mut self, now: Instant, id: &MessageId, error: CallError, ) -> Result<(), EngineError>

Answers an outstanding request with a CALLERROR.

Source

pub fn reject_result( &mut self, now: Instant, id: &MessageId, error: CallError, ) -> Result<(), EngineError>

Tells the peer that the CALLRESULT it sent could not be used (OCPP 2.1 CALLRESULTERROR).

Before 2.1 no such message exists, and the failure can only be logged locally.

Source

pub fn cancel(&mut self, token: CallToken) -> bool

Abandons a call that has not been transmitted yet.

Returns true if it was still in the queue. A call that is already outstanding cannot be withdrawn — the peer will answer it.

Source

pub fn shutdown(&mut self, now: Instant, deadline: Instant)

Starts a graceful drain: no new calls are accepted, the outstanding call is allowed to finish and the queue is flushed, then Output::Close is emitted.

If deadline passes first, the connection is closed with CloseReason::DrainTimedOut and the queue is left in the durable store.

Auto Trait Implementations§

§

impl<S = MemStore> !RefUnwindSafe for Engine<S>

§

impl<S = MemStore> !Sync for Engine<S>

§

impl<S = MemStore> !UnwindSafe for Engine<S>

§

impl<S> Forget for Engine<S>

§

impl<S> Freeze for Engine<S>
where S: Freeze,

§

impl<S> Send for Engine<S>
where S: Send,

§

impl<S> Unpin for Engine<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for Engine<S>
where S: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.