Skip to main content

std_rs/
lib.rs

1#![allow(
2    clippy::collapsible_if,
3    clippy::derivable_impls,
4    clippy::field_reassign_with_default,
5    clippy::type_complexity
6)]
7
8pub mod device_support;
9pub mod records;
10pub mod snl;
11
12pub use device_support::time_of_day::{SecPastEpochDeviceSupport, TimeOfDayStringDeviceSupport};
13pub use records::epid::EpidRecord;
14pub use records::throttle::ThrottleRecord;
15pub use records::timestamp::TimestampRecord;
16
17/// Path to the bundled database template directory.
18pub const STD_DB_DIR: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/db");
19
20/// Return the epid record type factory for injection into IocBuilder.
21pub fn epid_record_factory() -> (&'static str, epics_base_rs::server::RecordFactory) {
22    ("epid", Box::new(|| Box::new(EpidRecord::default())))
23}
24
25/// Return the throttle record type factory for injection into IocBuilder.
26pub fn throttle_record_factory() -> (&'static str, epics_base_rs::server::RecordFactory) {
27    ("throttle", Box::new(|| Box::new(ThrottleRecord::default())))
28}
29
30/// Return the timestamp record type factory for injection into IocBuilder.
31pub fn timestamp_record_factory() -> (&'static str, epics_base_rs::server::RecordFactory) {
32    (
33        "timestamp",
34        Box::new(|| Box::new(TimestampRecord::default())),
35    )
36}
37
38/// Return all std record type factories for bulk registration.
39pub fn std_record_factories() -> Vec<(&'static str, epics_base_rs::server::RecordFactory)> {
40    vec![
41        epid_record_factory(),
42        throttle_record_factory(),
43        timestamp_record_factory(),
44    ]
45}
46
47/// Register all std record types via the global registry (legacy).
48/// Prefer `std_record_factories()` with `IocBuilder::register_record_type()`.
49pub fn register_std_record_types() {
50    for (name, factory) in std_record_factories() {
51        epics_base_rs::server::db_loader::register_record_type(name, factory);
52    }
53}
54
55/// Return the "Sec Past Epoch" (`ai`) device support factory from
56/// `devTimeOfDay.c` (`devAiTodSeconds`) for injection into a builder.
57pub fn sec_past_epoch_device_factory() -> (&'static str, epics_base_rs::server::DeviceSupportFactory)
58{
59    (
60        "Sec Past Epoch",
61        Box::new(|| Box::new(SecPastEpochDeviceSupport::new())),
62    )
63}
64
65/// Return the "Time of Day" (`stringin`) device support factory from
66/// `devTimeOfDay.c` (`devSiTodString`) for injection into a builder.
67pub fn time_of_day_device_factory() -> (&'static str, epics_base_rs::server::DeviceSupportFactory) {
68    (
69        "Time of Day",
70        Box::new(|| Box::new(TimeOfDayStringDeviceSupport::new())),
71    )
72}
73
74/// Return all std-module device support factories for bulk registration.
75///
76/// These are the `devTimeOfDay.c` DTYPs ("Sec Past Epoch" ai, "Time of Day"
77/// stringin). They need only the framework's `ProcessContext` (PHAS/TSE), no
78/// INP, so a static [`DeviceSupportFactory`](epics_base_rs::server::DeviceSupportFactory)
79/// suffices. Register each onto an `IocBuilder` / `IocApplication` /
80/// `CaServerBuilder` via its `register_device_support(dtyp, factory)` — the
81/// boxed factory satisfies the method's `Fn` bound — mirroring how
82/// [`std_record_factories()`] is injected via `register_record_type()`.
83pub fn std_device_supports() -> Vec<(&'static str, epics_base_rs::server::DeviceSupportFactory)> {
84    vec![
85        sec_past_epoch_device_factory(),
86        time_of_day_device_factory(),
87    ]
88}