Skip to main content

PvaServer

Struct PvaServer 

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

High-level PVAccess server.

Built via PvaServer::builder() with typed record constructors, .db_file() loading, .on_put() / .scan() callbacks, and a simple .run() to start serving.

let server = PvaServer::builder()
    .ai("SIM:TEMP", 22.5)
    .ao("SIM:SP", 25.0)
    .build();

// Read/write PVs from another task:
let store = server.store();
store.set_value("SIM:TEMP", ScalarValue::F64(23.1)).await;

server.run().await?;

Implementations§

Source§

impl PvaServer

Source

pub fn builder() -> PvaServerBuilder

Create a builder for configuring a PvaServer.

Source

pub fn store(&self) -> &Arc<SimplePvStore>

Get a reference to the underlying store for runtime get/put.

Source

pub fn events(&self) -> &Arc<Events>

The server’s event registry — register sinks or post events.

Source

pub async fn post_event(&self, event: &str)

Post a named event.

Async because sinks are awaited inline: when this returns, every sink has finished — records on that event have processed — and handlers are queued, not necessarily run. Making the caller .await is what buys the guarantee; a sync wrapper that spawned and returned would silently drop it.

Source

pub async fn run_start_hooks(&self) -> Result<(), String>

Run every on_start hook to completion, in registration order.

Returns Err naming the hook and carrying the panic message if one panics — including any label the hook panicked with (Python source hooks panic with on_start hook for source '<label>' raised: ...).

Also installs the monitor registry onto the store before any hook runs (idempotently — SimplePvStore::set_registry is safe to call more than once), so a hook that writes to the store notifies subscribed monitors, and a hook that reads the registry off the store never sees None. This must happen here rather than only in serve_after_start_hooks, since run_start_hooks can be — and, via Python’s start_background, is — called on its own ahead of it.

Source

pub async fn pv<T: PvScalar>(&self, name: &str) -> Result<Pv<T>, PvError>

Mint a typed handle to any record in this server’s store — the pre-run() counterpart of RunningServer::pv.

Source

pub async fn array_pv(&self, name: &str) -> Result<PvArray, PvError>

Mint an array handle to any record in this server’s store — the pre-run() counterpart of RunningServer::array_pv.

Source

pub fn add_source( &mut self, label: impl Into<String>, order: i32, source: Arc<dyn Source>, )

Register an additional Source after building the server.

This is useful when the source needs a reference to the store (which is only available after .build()).

let server = PvaServer::builder().ai("X", 0.0).build();
let store = server.store().clone();
server.add_source("agg", 10, Arc::new(MyAggSource::new(store)));
server.run().await?;
Source

pub fn set_monitor_registry(&mut self, registry: Arc<MonitorRegistry>)

Pre-supply the MonitorRegistry that Self::run will use.

This lets external code (for example Python Source adapters) hold onto the registry and publish monitor updates to subscribed PVAccess clients from outside run().

Must be called before the registry has been resolved by any other path (monitor_registry(), run_start_hooks(), or serve_after_start_hooks()) — in normal usage this is always right after build(), before any of those run. If the registry was already resolved, this is a no-op: the earlier instance wins.

Source

pub fn monitor_registry(&mut self) -> Arc<MonitorRegistry>

Get a shared handle to the MonitorRegistry that will be used when Self::run starts. Creates (and stores) a new registry on first call so external code can register before run.

Source

pub async fn run(self) -> Result<(), Box<dyn Error>>

Start the PVA server (UDP search + TCP handler + beacon + scan tasks).

This blocks until the server is shut down or an error occurs.

Source

pub async fn serve_after_start_hooks(self) -> Result<(), Box<dyn Error>>

Continue startup on the assumption that run_start_hooks() has already completed successfully.

Builds the source registry, spawns scan tasks, starts the event dispatcher, and binds/accepts connections — i.e. everything run() does except the hook phase. Exists so a caller that needs to surface an on_start failure synchronously (e.g. Python’s start_background, which must raise before returning rather than only logging from a background thread) can run the hooks itself, check the result, and only then hand the server off to a background task — without running the hooks a second time.

Calling this without having run the start hooks first silently skips them; callers that need the hooks-first guarantee should use run() or call run_start_hooks() first themselves.

Source§

impl PvaServer

Source

pub fn serve(pvs: impl IntoIterator<Item = impl Into<AnyPv>>) -> ServeBuilder

Serve a collection of typed PV handles. Shorthand entry point for the handle-based API; combine with .db_file(), .source(), etc.

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