Skip to main content

PvaServerBuilder

Struct PvaServerBuilder 

Source
pub struct PvaServerBuilder { /* private fields */ }
Expand description

Builder for PvaServer.

let server = PvaServer::builder()
    .ai("TEMP:READBACK", 22.5)
    .ao("TEMP:SETPOINT", 25.0)
    .bo("HEATER:ON", false)
    .port(5075)
    .build();

Implementations§

Source§

impl PvaServerBuilder

Source

pub fn ai(self, name: impl Into<String>, initial: f64) -> Self

Add an ai (analog input, read-only) record.

Source

pub fn ao(self, name: impl Into<String>, initial: f64) -> Self

Add an ao (analog output, writable) record.

Source

pub fn bi(self, name: impl Into<String>, initial: bool) -> Self

Add a bi (binary input, read-only) record.

Source

pub fn bo(self, name: impl Into<String>, initial: bool) -> Self

Add a bo (binary output, writable) record.

Source

pub fn string_in( self, name: impl Into<String>, initial: impl Into<String>, ) -> Self

Add a stringin (string input, read-only) record.

Source

pub fn string_out( self, name: impl Into<String>, initial: impl Into<String>, ) -> Self

Add a stringout (string output, writable) record.

Source

pub fn waveform(self, name: impl Into<String>, data: ScalarArrayValue) -> Self

Add a waveform record (array) with the given initial data.

Source

pub fn aai(self, name: impl Into<String>, data: ScalarArrayValue) -> Self

Add an aai (analog array input, read-only) record.

Source

pub fn aao(self, name: impl Into<String>, data: ScalarArrayValue) -> Self

Add an aao (analog array output, writable) record.

Source

pub fn sub_array( self, name: impl Into<String>, data: ScalarArrayValue, indx: usize, nelm: usize, ) -> Self

Add a subarray record — a view into part of an array.

Source

pub fn nt_table( self, name: impl Into<String>, columns: Vec<(String, ScalarArrayValue)>, ) -> Self

Add an NTTable record.

Source

pub fn nt_ndarray( self, name: impl Into<String>, data: ScalarArrayValue, dims: Vec<(i32, i32)>, ) -> Self

Add an NTNDArray record.

Source

pub fn mbbi( self, name: impl Into<String>, choices: Vec<String>, initial: i32, ) -> Self

Add an mbbi (multi-bit binary input, read-only) NTEnum record.

Source

pub fn mbbo( self, name: impl Into<String>, choices: Vec<String>, initial: i32, ) -> Self

Add an mbbo (multi-bit binary output, writable) NTEnum record.

Source

pub fn generic( self, name: impl Into<String>, struct_id: impl Into<String>, fields: Vec<(String, PvValue)>, ) -> Self

Add a generic structure record with a custom struct ID and fields.

Source

pub fn db_file(self, path: impl AsRef<str>) -> Self

Load records from an EPICS .db file.

A malformed .db is a startup configuration error, not a runtime condition to log and shrug off: build() returns PvaServer, not a Result, so there is no channel to report the failure through other than refusing to start. Silently continuing with zero records from this file would leave the server up and answering PVA requests while serving none of the PVs its .db was supposed to define, which is worse than failing loudly at startup. load_db’s error already names the file and the line that failed to parse (see DbParseError’s Display), so that detail reaches the panic message unmodified.

Source

pub fn db_string(self, content: &str) -> Self

Parse records from an EPICS .db string.

See Self::db_file’s doc comment for why a parse failure panics here rather than logging and continuing with zero records.

Source

pub fn on_put<F>(self, name: impl Into<String>, callback: F) -> Self
where F: Fn(&str, &DecodedValue) + Send + Sync + 'static,

Register a callback invoked when a PUT is applied to the named PV.

Source

pub fn scan<F>( self, name: impl Into<String>, period: Duration, callback: F, ) -> Self
where F: Fn(&str) -> ScalarValue + Send + Sync + 'static,

Register a periodic scan callback that produces a new value for a PV.

Source

pub fn on_start<F>(self, hook: F) -> Self
where F: Fn(Arc<SimplePvStore>) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync + 'static,

Register a hook to run once at startup, before the server serves.

Hooks run in registration order, each to completion, before scan tasks spawn and before the listener accepts. A hook that panics aborts startup.

.on_start(|store| Box::pin(async move {
    store.set_value("SETPOINT", ScalarValue::F64(22.5)).await;
}))
Source

pub fn on_event<F>(self, event: impl Into<String>, handler: F) -> Self
where F: Fn(Arc<SimplePvStore>, String) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync + 'static,

Register a handler for a named event.

Handlers are deferred: post_event queues them and returns. They run one at a time, in registration order, on the dispatcher.

.on_event("SHUTTER", |store, event| Box::pin(async move { /* ... */ }))
Source

pub fn event_sink(self, sink: Arc<dyn EventSink>) -> Self

Register an EventSink — an inline consumer awaited by post_event before any handler is queued.

Sinks were previously reachable only through PvaServer::events on an already-built server, which leaves no seam for callers that only ever hold a builder (or a ServeBuilder/RunningServer). Registration order across builder-registered and post-build sinks is call order.

Link an output PV to one or more input PVs.

Whenever any input PV changes (via set_value, protocol PUT, or another link), the compute callback is invoked with the current values of all inputs (in order) and the result is written to the output PV.

.link("CALC:SUM", &["INPUT:A", "INPUT:B"], |values| {
    let a = values[0].as_f64().unwrap_or(0.0);
    let b = values[1].as_f64().unwrap_or(0.0);
    ScalarValue::F64(a + b)
})
Source

pub fn source( self, label: impl Into<String>, order: i32, source: Arc<dyn Source>, ) -> Self

Register an additional Source at the given priority.

Lower order values are checked first during PV name resolution. The built-in SimplePvStore (records added via .ai(), .ao(), etc.) is always registered at order 0.

.source("hardware", -10, Arc::new(HardwareSource::new()))
Source

pub fn ioc<S: StoreSource + 'static>(self, ioc: Arc<S>) -> Self

Register a processing engine as a second store.

Unlike PvaServerBuilder::source, this asserts the engine owns its record names outright: build panics if any of them collide with a record added to the builtin store (.ai(), .db_file() and friends), or if a .scan, .link or on_put handler names one of them. Those callbacks drive the builtin store’s direct-write semantics and would be silently inert against an engine record.

Generic rather than Arc<dyn StoreSource> so the names can be read before the value is erased to Arc<dyn Source>.

§Panics

If called more than once.

Source

pub fn port(self, port: u16) -> Self

Set the TCP port (default 5075).

Source

pub fn udp_port(self, port: u16) -> Self

Set the UDP search port (default 5076).

Source

pub fn listen_ip(self, ip: IpAddr) -> Self

Set the IP address to listen on.

Source

pub fn advertise_ip(self, ip: IpAddr) -> Self

Set the IP address to advertise in search responses.

Source

pub fn compute_alarms(self, enabled: bool) -> Self

Enable alarm computation from limits.

Source

pub fn beacon_period(self, secs: u64) -> Self

Set the beacon broadcast period in seconds (default 15).

Source

pub fn conn_timeout(self, timeout: Duration) -> Self

Set the idle connection timeout (default ~18 hours).

Source

pub fn pvlist_mode(self, mode: PvListMode) -> Self

Set the PV list mode (default PvListMode::List).

Source

pub fn pvlist_max(self, max: usize) -> Self

Set the maximum number of PV names in pvlist responses (default 1024).

Source

pub fn pvlist_allow_pattern(self, pattern: Regex) -> Self

Set a regex filter for PV names exposed by pvlist.

Source

pub fn build(self) -> PvaServer

Build the PvaServer.

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more