Skip to main content

bacnet_objects/
traits.rs

1//! BACnetObject trait — the interface all BACnet objects implement.
2
3#[path = "object_storage.rs"]
4mod object_storage;
5pub(crate) use object_storage::ObjectStorageAccess;
6
7use std::borrow::Cow;
8use std::sync::Arc;
9use std::time::Duration;
10
11use bacnet_types::bitstring::EventTransitionBits;
12use bacnet_types::calendar::SpecificDate;
13use bacnet_types::constructed::{
14    BACnetEventLogRecord, BACnetLogMultipleRecord, BACnetLogRecord, BACnetObjectPropertyReference,
15};
16use bacnet_types::enums::{
17    ErrorClass, ErrorCode, EventState, LifeSafetyOperation, ObjectType, PropertyIdentifier,
18    Reliability,
19};
20use bacnet_types::error::Error;
21use bacnet_types::primitives::{BACnetTimeStamp, ObjectIdentifier, PropertyValue, Time};
22
23use crate::audit::{AuditLogNotificationSink, AuditLogStorage};
24use crate::clock::ClockReader;
25use crate::durable::DurableWrites;
26use crate::event::{
27    EnrollmentSummaryCapability, EventStateChange, EventTransitionCommit,
28    EventTransitionCommitError, TransitionOutcome,
29};
30use crate::event_enrollment::{
31    EventEnrollmentEvalState, EventEnrollmentMonitoredSource, EventEnrollmentReliabilityCommit,
32};
33use crate::file::{FileConfiguration, FileStorage};
34use crate::log_buffer::{LogBufferRecords, LogRecordIdentity};
35use crate::log_reporting::BufferReadyReport;
36use crate::schedule::{ScheduleTargetOutcome, ScheduleWrite};
37
38/// Process-local monotonic time source used by internal object lifecycles.
39#[doc(hidden)]
40pub type MonotonicClock = dyn Fn() -> Duration + Send + Sync;
41
42/// Wakes the server's monotonic task to read object deadlines again (#1384).
43#[doc(hidden)]
44pub type DeadlineWaker = dyn Fn() + Send + Sync;
45
46mod defaults;
47use defaults::{
48    array_property_default, cov_reported_properties_default, historical_writable_default,
49    list_property_default,
50};
51
52/// One property a whole-object (SubscribeCOV) notification reports after
53/// Present_Value and Status_Flags, from the object type's Table 13-1 row.
54#[derive(Debug, Clone, Copy, PartialEq, Eq)]
55pub enum CovReportedProperty {
56    /// Carried in each notification; a change of it alone sends none.
57    Value(PropertyIdentifier),
58    /// Carried in each notification, and any change of it sends one.
59    Trigger(PropertyIdentifier),
60}
61
62impl CovReportedProperty {
63    /// The reported property.
64    pub const fn property(self) -> PropertyIdentifier {
65        match self {
66            Self::Value(property) | Self::Trigger(property) => property,
67        }
68    }
69
70    /// Whether any change of the property triggers a notification.
71    pub const fn triggers(self) -> bool {
72        matches!(self, Self::Trigger(_))
73    }
74}
75
76/// Whether the stack's classification table marks `property` as a BACnetARRAY
77/// on `object_type`: the answer the default [`BACnetObject::is_array_property`]
78/// gives, and every built-in object's. The table holds every property a Clause
79/// 12 object table of the 2020 standard types as an array, served or not. A
80/// client can ask it about a remote object, before or without any value, to
81/// learn the property's shape; a vendor-defined array isn't in it.
82pub fn standard_array_property(object_type: ObjectType, property: PropertyIdentifier) -> bool {
83    array_property_default(object_type, property)
84}
85
86/// Whether the stack's classification table marks `property` as a BACnetLIST
87/// on `object_type`: the answer the default [`BACnetObject::is_list_property`]
88/// gives, and every built-in object's, covering every list of the 2020 object
89/// tables. Usable for a remote object as [`standard_array_property`] is.
90pub fn standard_list_property(object_type: ObjectType, property: PropertyIdentifier) -> bool {
91    list_property_default(object_type, property)
92}
93
94/// Result of applying a LifeSafetyOperation to an object.
95#[derive(Debug, Clone, Copy, PartialEq, Eq)]
96pub enum LifeSafetyOperationEffect {
97    /// The operation changed object state.
98    Applied,
99    /// The requested idempotent state was already present.
100    AlreadyApplied,
101}
102
103/// Result of applying a `LifeSafetyOperation` to object-owned state.
104///
105/// `changed_properties` contains exact committed readback changes in the object's
106/// stable reporting order, with each property at most once. Implementations own
107/// this projection; the server does not infer custom object mutations.
108/// [`LifeSafetyOperationEffect::AlreadyApplied`] means no state changed and must
109/// carry an empty property list.
110#[derive(Debug, Clone, PartialEq, Eq)]
111pub struct LifeSafetyOperationOutcome {
112    /// Whether the operation committed a change or was already applied.
113    pub effect: LifeSafetyOperationEffect,
114    /// Exact properties whose committed readback changed.
115    pub changed_properties: Vec<PropertyIdentifier>,
116}
117
118/// Result of one object-owned reliability evaluation pass.
119#[derive(Debug, Clone, Copy, PartialEq, Eq)]
120pub enum ReliabilityEvaluation {
121    /// The object made no reliability-related mutation.
122    Unchanged,
123    /// The object successfully mutated its `Reliability` value.
124    Changed {
125        /// Reliability before the successful mutation.
126        old_reliability: Reliability,
127        /// Reliability after the successful mutation.
128        new_reliability: Reliability,
129    },
130}
131
132/// The core trait for all BACnet objects.
133///
134/// Stored objects have crate-authorized concrete access; borrowed read views
135/// remain valid implementors. Applications cannot manufacture its access permit:
136/// ```compile_fail
137/// use bacnet_objects::traits::ObjectStorageAccess;
138/// let permit = ObjectStorageAccess(());
139/// ```
140/// Implementors represent a single BACnet object (Device, AnalogInput, etc.)
141/// and provide read/write access to their properties.
142pub trait BACnetObject: Send + Sync + object_storage::StoredObject {
143    /// Typed local Device authority for composition-owned configuration.
144    /// This does not grant network write access to the object database.
145    #[doc(hidden)]
146    fn device_authority_internal(&mut self) -> Option<crate::device::DeviceAuthority<'_>> {
147        None
148    }
149
150    /// Snapshot of object-owned target Audit overrides. Absent fields inherit
151    /// the selected Reporter; source reporting does not inspect remote policies.
152    #[doc(hidden)]
153    fn audit_object_policy_internal(&self) -> crate::audit::ObjectAuditPolicy {
154        crate::audit::ObjectAuditPolicy::default()
155    }
156
157    /// Optional sealed built-in policy assignment authority (AV/BV, Color and
158    /// Color Temperature). Custom objects
159    /// remain on their ordinary writer path; adapters may forward this capability.
160    #[doc(hidden)]
161    fn audit_policy_authority_internal(
162        &mut self,
163    ) -> Option<crate::audit::AuditPolicyAuthority<'_>> {
164        None
165    }
166
167    /// The optional built-in Reporter authority.
168    #[doc(hidden)]
169    fn audit_reporter_internal(&self) -> Option<&crate::audit::AuditReporterObject> {
170        None
171    }
172
173    /// Scoped built-in Reporter mutation authority; absent for other objects.
174    #[doc(hidden)]
175    fn audit_reporter_authority_internal(
176        &mut self,
177    ) -> Option<crate::audit::AuditReporterAuthority<'_>> {
178        None
179    }
180
181    /// Atomically replace all trusted local Reporter settings without a network write.
182    ///
183    /// The default opts out. Supporting implementations must reject invalid
184    /// settings before any mutation. `None` selectors remove Monitored_Objects
185    /// (catch-all); `Some(vec![])` retains the property and selects no ordinary
186    /// targets. An installed target owner prepares required records and lifecycle admission.
187    ///
188    /// Supply every field together, including the optional paired delay capability.
189    /// Active target ownership fixes pair presence; source ownership rejects it.
190    /// `None` omits both delay/control properties; a present zero is immediate.
191    #[doc(hidden)]
192    fn configure_audit_reporter_internal(
193        &mut self,
194        _level: bacnet_types::enums::AuditLevel,
195        _operations: bacnet_types::bitstring::AuditOperationFlags,
196        _confirmed: bool,
197        _selectors: Option<Vec<bacnet_types::constructed::BACnetObjectSelector>>,
198        _priorities: bacnet_types::bitstring::BACnetPriorityFilter,
199        _maximum_send_delay: Option<crate::audit::AuditSendDelay>,
200    ) -> Result<(), Error> {
201        Err(Error::Protocol {
202            class: ErrorClass::OBJECT,
203            code: ErrorCode::OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED,
204        })
205    }
206
207    /// The object's identifier (type + instance).
208    fn object_identifier(&self) -> ObjectIdentifier;
209
210    /// The object's name.
211    fn object_name(&self) -> &str;
212
213    /// Read a property value.
214    fn read_property(
215        &self,
216        property: PropertyIdentifier,
217        array_index: Option<u32>,
218    ) -> Result<PropertyValue, Error>;
219
220    /// Write a property value.
221    ///
222    /// Returning `Err` MUST leave the object unchanged. WritePropertyMultiple
223    /// retains earlier successful writes and cannot undo a mutation made by the
224    /// currently failing write, including for a write-only property.
225    ///
226    /// Refusing one element of a list value, an implementation may name it:
227    /// `Error::Structured` with `ErrorDetail::FirstFailedElementNumber`
228    /// holding the element's position, from 1, in the list `value` carries.
229    /// The server's AddListElement handler then reports the request element
230    /// at that position in its ChangeList-Error (#1048); a plain
231    /// `Error::Protocol` there names the first element the list would gain.
232    ///
233    /// Make the checks that don't depend on the value (the property exists,
234    /// it is writable now, the array index is in range) before judging the
235    /// value's datatype, and refuse a value of the wrong datatype with
236    /// PROPERTY / INVALID_DATA_TYPE. The bundled server reads that refusal of
237    /// a NULL, on a property that isn't commandable and has no NULL in its
238    /// datatype, as a success that leaves the property as it is (Clauses
239    /// 15.9.2 and 19.2.1, #1396), so an access check made after the datatype
240    /// check would never be seen for a NULL.
241    fn write_property(
242        &mut self,
243        property: PropertyIdentifier,
244        array_index: Option<u32>,
245        value: PropertyValue,
246        priority: Option<u8>,
247    ) -> Result<(), Error>;
248
249    /// Write with explicit actual command provenance. Standalone callers assert
250    /// the origin; server boundaries additionally validate ingress or membership.
251    /// Decorators must forward this hook without discarding the origin.
252    /// The default preserves custom/unaffected object behavior. First-party
253    /// source-tracked commands require this hook and deny context-free writing.
254    fn write_property_from(
255        &mut self,
256        property: PropertyIdentifier,
257        array_index: Option<u32>,
258        value: PropertyValue,
259        priority: Option<u8>,
260        _origin: &crate::command_source::CommandOrigin,
261    ) -> Result<(), Error> {
262        self.write_property(property, array_index, value, priority)
263    }
264
265    /// Return canonical metadata for this object's effective property rows.
266    ///
267    /// Migrated implementations return every supported standard row for the
268    /// current instance, including `PROPERTY_LIST`. Borrowed rows cover static
269    /// or object-owned metadata; owned rows support dynamically assembled
270    /// per-instance sets. An empty borrowed default marks an object as unmigrated.
271    fn property_metadata(&self) -> Cow<'_, [crate::property_metadata::PropertyMetadata]> {
272        Cow::Borrowed(&[])
273    }
274
275    /// List all properties this object supports in the legacy projection.
276    ///
277    /// For migrated objects this includes Object_Identifier, Object_Name, and
278    /// Object_Type but omits Property_List. Reading the BACnet Property_List
279    /// property applies the additional wire-level universal-property filter.
280    fn property_list(&self) -> Cow<'static, [PropertyIdentifier]>;
281
282    /// Bind or remove the database's shared wall-clock reader.
283    ///
284    /// Objects that do not expose clock-derived state ignore this internal
285    /// lifecycle hook.
286    #[doc(hidden)]
287    fn bind_clock_internal(&mut self, _clock: Option<Arc<dyn ClockReader>>) {}
288
289    /// Advance object-owned operations that use monotonic elapsed time.
290    ///
291    /// The server calls this internal hook from a dedicated lifecycle task.
292    /// `true` means readable state changed and generic COV processing is
293    /// required. The default is a source-compatible no-op for downstream
294    /// object implementations.
295    #[doc(hidden)]
296    fn advance_time_internal(&mut self, _elapsed: Duration) -> bool {
297        false
298    }
299
300    /// Bind the process-local monotonic source used when operations arm.
301    #[doc(hidden)]
302    fn bind_monotonic_clock_internal(&mut self, _clock: Option<Arc<MonotonicClock>>) {}
303
304    /// Bind the waker an object calls when a write arms a monotonic deadline,
305    /// so the server's task looks again sooner than its next routine pass.
306    #[doc(hidden)]
307    fn bind_deadline_waker_internal(&mut self, _waker: Option<Arc<DeadlineWaker>>) {}
308
309    /// The device is starting: drive the object's output as a start does.
310    ///
311    /// The server calls this once for every object in the database as it
312    /// starts, before the database is shared. The Color and Color
313    /// Temperature objects drive an output nothing has driven yet to its
314    /// default (#1526); other objects ignore it.
315    #[doc(hidden)]
316    fn start_output_internal(&mut self) {}
317
318    /// Advance operations to an absolute process-local monotonic instant.
319    #[doc(hidden)]
320    fn advance_monotonic_time_internal(&mut self, _now: Duration) -> bool {
321        false
322    }
323
324    /// Return the next absolute process-local operation deadline, if any.
325    #[doc(hidden)]
326    fn next_monotonic_deadline_internal(&self) -> Option<Duration> {
327        None
328    }
329
330    /// Take the finest COV increment an active property subscription to
331    /// Tracking_Value asks for, or `None` when no such subscription gives
332    /// one (#1510).
333    ///
334    /// The server's monotonic task passes it before each advance, so an
335    /// object whose fade or ramp samples Tracking_Value for COV samples it
336    /// at least that finely, still no more often than its sample grid
337    /// allows. The value is finite and not negative. Objects without such a
338    /// Tracking_Value ignore it.
339    #[doc(hidden)]
340    fn set_tracking_cov_increment_internal(&mut self, _finest: Option<f64>) {}
341
342    /// Freeze COV-readable state while the object's mutation lock is held.
343    #[doc(hidden)]
344    fn cov_snapshot_internal(&self) -> Option<Box<dyn BACnetObject>> {
345        None
346    }
347
348    /// Return how many blink-warn notifications a lighting object has
349    /// requested, for objects that model them.
350    ///
351    /// This is an internal conformance-test channel, not a BACnet property,
352    /// host callback, or physical-output claim.
353    #[doc(hidden)]
354    fn lighting_blink_count_internal(&self) -> u64 {
355        0
356    }
357
358    /// Whether a property write route can accept `property` for this object.
359    ///
360    /// PICS generation and runtime dispatch MUST consult this (or
361    /// `write_property_from` where source authority is required) rather than a
362    /// separate heuristic, so the PICS
363    /// writable flags cannot drift from the actual write routes. The default
364    /// reproduces the historical PICS heuristic (see
365    /// `historical_writable_default`) so unmigrated object types keep their
366    /// current PICS output. Object implementations override to mirror their
367    /// real write capabilities, including required command origin and ownership.
368    ///
369    /// Universal read-only properties (`OBJECT_IDENTIFIER`, `OBJECT_TYPE`,
370    /// `PROPERTY_LIST`, `STATUS_FLAGS`) are always non-writable and are
371    /// excluded by the default; overrides should preserve that invariant.
372    ///
373    /// Built-in analog, binary, multi-state, Event Enrollment, and Alert
374    /// Enrollment objects also deny network writes to `ACKED_TRANSITIONS`.
375    /// The property descriptions accompanying ASHRAE 135-2020 Tables 12-2/3/4,
376    /// 12-6/8/10, 12-21/22/23, 12-14, and 12-61 explicitly make it read-only;
377    /// the table's `R`/`O` classification alone is not a write prohibition.
378    /// Clause 13.2.3 assigns acknowledgment-bit maintenance to internal
379    /// transition and acknowledgment processing. Those lifecycle hooks and
380    /// supported AcknowledgeAlarm paths do not use `write_property`, so this
381    /// network restriction does not prevent their internal updates.
382    fn is_writable_property(&self, property: PropertyIdentifier) -> bool {
383        let metadata = self.property_metadata();
384        if metadata.is_empty() {
385            historical_writable_default(self.object_identifier().object_type(), property)
386        } else {
387            crate::property_metadata::is_writable_in_metadata(metadata.as_ref(), property)
388        }
389    }
390
391    /// Whether `property` accepts an array index on this object.
392    ///
393    /// Per Clause 12.1.5.1, only BACnetARRAY (and BACnetARRAY of BACnetLIST)
394    /// properties accept an array index; Clause 12.1.5.2 makes ReadRange the
395    /// only positional access to a BACnetLIST. The RP/RPM/WP/WPM service
396    /// handlers gate the request's array index on this query and reject a
397    /// supplied index on a non-array property with PROPERTY /
398    /// PROPERTY_IS_NOT_AN_ARRAY (Clause 15.5.1.3, Clause 15.9.1.3).
399    ///
400    /// The default reproduces the standard's classification (see
401    /// `array_property_default`): identifier-stable arrays are admitted
402    /// without consulting the object type, the identifiers whose datatype
403    /// changes with the object type (ACTION, ALARM_VALUES / FAULT_VALUES,
404    /// LIST_OF_OBJECT_PROPERTY_REFERENCES, LOG_DEVICE_OBJECT_PROPERTY,
405    /// PRESENT_VALUE) classify by `object_identifier().object_type()`, and
406    /// everything else — scalars and BACnetLIST properties — rejects the
407    /// index. The built-in objects keep the default, so clients that classify
408    /// with [`standard_array_property`] agree with them; object
409    /// implementations with vendor array properties override.
410    fn is_array_property(&self, property: PropertyIdentifier) -> bool {
411        array_property_default(self.object_identifier().object_type(), property)
412    }
413
414    /// Whether `property` is a BACnetLIST on this object.
415    ///
416    /// AddListElement and RemoveListElement (Clauses 15.1 and 15.2) edit only
417    /// BACnetLIST properties, and ReadRange (Clause 15.8) reads only them. The
418    /// server's handlers ask this before decoding any element or selecting any
419    /// item, and refuse every other target, including an array element, with
420    /// SERVICES / PROPERTY_IS_NOT_A_LIST. Like
421    /// [`Self::is_array_property`], the answer follows the property's datatype,
422    /// not the shape of a value read: a whole array also reads as a list, and
423    /// constructed single values often read as framed bytes.
424    ///
425    /// The default reproduces the standard's classification (see
426    /// `list_property_default`): identifier-stable lists are admitted on every
427    /// object type, and the identifiers whose datatype changes with the object
428    /// type (ALARM_VALUES / FAULT_VALUES, LIST_OF_OBJECT_PROPERTY_REFERENCES,
429    /// PRESENT_VALUE, MEMBER_OF) classify by `object_identifier().object_type()`.
430    /// The built-in objects keep the default; object implementations with
431    /// vendor list properties override.
432    fn is_list_property(&self, property: PropertyIdentifier) -> bool {
433        list_property_default(self.object_identifier().object_type(), property)
434    }
435
436    /// Whether this object type can be created at runtime via CreateObject.
437    ///
438    /// Default `false`; override `true` only for types the network factory
439    /// (`handle_create_object`) actually constructs, so PICS createability
440    /// matches the runtime factory with no separate list to drift.
441    fn is_createable(&self) -> bool {
442        false
443    }
444
445    /// The properties whose whole value a CreateObject initial value may set
446    /// on this object although WriteProperty can't change it afterwards.
447    ///
448    /// Clause 15.3 doesn't limit initial values to the properties
449    /// WriteProperty can change, so a device may take some of its read-only
450    /// properties at creation. The bundled server hands such an initial value,
451    /// written without an array index, to [`Self::initialize_property`]
452    /// instead of the write route; every other initial value goes the way a
453    /// WriteProperty does. The PICS lists the set for each createable type.
454    /// Default empty: no property is set only at creation.
455    fn creation_only_properties(&self) -> &'static [PropertyIdentifier] {
456        &[]
457    }
458
459    /// Apply a CreateObject initial value to one of
460    /// [`Self::creation_only_properties`], written whole.
461    ///
462    /// The server calls this only on the object it is creating, before any
463    /// other request can see it. Check the value as a write would, and on
464    /// `Err` leave the object unchanged: the server then refuses the request,
465    /// naming the initial value, and drops the object. As on the write
466    /// route, an initial value that is one application NULL and that this
467    /// refuses with PROPERTY / INVALID_DATA_TYPE leaves the property as it
468    /// is and counts as applied, so refuse a NULL that way. The default
469    /// refuses every property with PROPERTY / WRITE_ACCESS_DENIED, the
470    /// answer for a property that can't be initialized at creation (Clause
471    /// 15.3.1.3.1).
472    ///
473    /// The bundled server's CreateObject builds only built-in objects today
474    /// (Analog Input and Output, the binary types and the multi-state
475    /// types), so on a custom object this hook is reached only by a caller
476    /// that builds the object itself.
477    fn initialize_property(
478        &mut self,
479        _property: PropertyIdentifier,
480        _value: PropertyValue,
481    ) -> Result<(), Error> {
482        Err(Error::Protocol {
483            class: ErrorClass::PROPERTY,
484            code: ErrorCode::WRITE_ACCESS_DENIED,
485        })
486    }
487
488    /// Whether this object type can be deleted at runtime via DeleteObject.
489    ///
490    /// Default `true`; override `false` on object types that are not
491    /// deleteable (e.g. `Device`, `NetworkPort`).
492    fn is_deleteable(&self) -> bool {
493        true
494    }
495
496    /// List the REQUIRED properties for this object type.
497    ///
498    /// Migrated objects derive this set from canonical `R` and `W` rows,
499    /// including Property_List. Unmigrated objects retain the historical four
500    /// universal properties. Service-specific consumers may exclude
501    /// Property_List where their protocol contract requires it.
502    fn required_properties(&self) -> Cow<'static, [PropertyIdentifier]> {
503        let metadata = self.property_metadata();
504        if !metadata.is_empty() {
505            return crate::property_metadata::required_properties_from_metadata(metadata.as_ref());
506        }
507        static UNIVERSAL: [PropertyIdentifier; 4] = [
508            PropertyIdentifier::OBJECT_IDENTIFIER,
509            PropertyIdentifier::OBJECT_NAME,
510            PropertyIdentifier::OBJECT_TYPE,
511            PropertyIdentifier::PROPERTY_LIST,
512        ];
513        Cow::Borrowed(&UNIVERSAL)
514    }
515
516    /// Whether this object type supports COV notifications.
517    ///
518    /// Override to return `true` for object types that can generate COV
519    /// notifications (analog, binary, multi-state I/O/V). Default is `false`.
520    /// This answer admits SubscribeCOV, the whole-object form, and is the
521    /// default for
522    /// [`supports_subscribe_cov_property`](Self::supports_subscribe_cov_property).
523    fn supports_cov(&self) -> bool {
524        false
525    }
526
527    /// Whether SubscribeCOVProperty and SubscribeCOVPropertyMultiple may
528    /// monitor this object's properties.
529    ///
530    /// Defaults to [`supports_cov`](Self::supports_cov). An object that has
531    /// no whole-object COV criteria, because Clause 13.1's Table 13-1 doesn't
532    /// list its type, can still return `true` here while `supports_cov`
533    /// stays `false`: its property subscriptions then follow Table 13-1a and
534    /// SubscribeCOV is refused. The built-in Averaging object does this.
535    /// [`supports_cov_property`](Self::supports_cov_property) still decides
536    /// each property.
537    fn supports_subscribe_cov_property(&self) -> bool {
538        self.supports_cov()
539    }
540
541    /// Take pending local target work from a Staging object.
542    ///
543    /// The default keeps every non-Staging object source-compatible. The
544    /// bundled server calls this only while it owns the database mutation
545    /// guard, then performs the returned writes after releasing that guard.
546    #[doc(hidden)]
547    fn take_staging_write_plan_internal(&mut self) -> Option<crate::staging::StagingWritePlan> {
548        None
549    }
550
551    /// Return the current Staging transition generation, if applicable.
552    #[doc(hidden)]
553    fn staging_generation_internal(&self) -> Option<u64> {
554        None
555    }
556
557    /// Commit one guarded Staging plan's success or failure to Reliability.
558    ///
559    /// Returns whether readable source state changed. Implementations ignore a
560    /// stale generation so older work cannot fault a newer transition.
561    #[doc(hidden)]
562    fn complete_staging_write_plan_internal(&mut self, _generation: u64, _success: bool) -> bool {
563        false
564    }
565
566    /// Take the writes a Command or Channel object's Present_Value write
567    /// queued: a Command's selected list, or a Channel's value for its
568    /// members.
569    ///
570    /// The default keeps every other object source-compatible. The bundled
571    /// server takes it under the guard that committed the write, then makes
572    /// the writes after releasing that guard.
573    #[doc(hidden)]
574    fn take_command_run_internal(&mut self) -> Option<crate::command::CommandRun> {
575        None
576    }
577
578    /// Return the current Command or Channel run generation, if applicable.
579    #[doc(hidden)]
580    fn command_generation_internal(&self) -> Option<u64> {
581        None
582    }
583
584    /// Record how command `command` of a Command's running list fared.
585    ///
586    /// Returns whether the run is still the current one. Implementations
587    /// ignore a stale generation, so older work can't mark a newer run.
588    #[doc(hidden)]
589    fn record_command_write_internal(
590        &mut self,
591        _generation: u64,
592        _command: usize,
593        _success: bool,
594    ) -> bool {
595        false
596    }
597
598    /// Keep `datatype`, learned for a Channel's member in another device, for
599    /// the distributions after this one, or forget the one kept with `None`:
600    /// the member at zero-based `slot` of List_Of_Object_Property_References,
601    /// if that slot still holds `reference`. Writing the member, or the whole
602    /// list, forgets it too.
603    #[doc(hidden)]
604    fn remember_member_datatype_internal(
605        &mut self,
606        _slot: usize,
607        _reference: &bacnet_types::constructed::BACnetDeviceObjectPropertyReference,
608        _datatype: Option<crate::channel::MemberDatatype>,
609    ) {
610    }
611
612    /// End the current run, setting a Command's All_Writes_Successful or a
613    /// Channel's Write_Status and Reliability. `outcome` is `Ok` when every
614    /// write was made and succeeded, otherwise the run's first failure.
615    ///
616    /// Returns whether readable state changed; a stale generation is ignored.
617    #[doc(hidden)]
618    fn complete_command_run_internal(
619        &mut self,
620        _generation: u64,
621        _outcome: Result<(), crate::command::WriteFailure>,
622    ) -> bool {
623        false
624    }
625
626    /// Return this object's GetEnrollmentSummary event capability.
627    ///
628    /// The default opts custom and downstream objects out. Implementations opt
629    /// in only when they own an actual configured or implied event algorithm
630    /// and shared committed-transition history.
631    #[doc(hidden)]
632    fn enrollment_summary_capability_internal(&self) -> Option<EnrollmentSummaryCapability> {
633        None
634    }
635
636    /// Whether a readable property supports property-specific COV.
637    ///
638    /// The default preserves the existing behavior of every other COV-capable
639    /// object family while enforcing the bounded standardized Life Safety
640    /// surface for source-compatible custom Point and Zone implementations.
641    /// Other types answer
642    /// [`supports_subscribe_cov_property`](Self::supports_subscribe_cov_property)
643    /// for every property.
644    fn supports_cov_property(&self, property: PropertyIdentifier) -> bool {
645        match self.object_identifier().object_type() {
646            ObjectType::LIFE_SAFETY_POINT | ObjectType::LIFE_SAFETY_ZONE => matches!(
647                property,
648                PropertyIdentifier::PRESENT_VALUE
649                    | PropertyIdentifier::STATUS_FLAGS
650                    | PropertyIdentifier::TRACKING_VALUE
651                    | PropertyIdentifier::SILENCED
652                    | PropertyIdentifier::OPERATION_EXPECTED
653            ),
654            _ => self.supports_subscribe_cov_property(),
655        }
656    }
657
658    /// COV increment for this object (objects with a COV_Increment property).
659    ///
660    /// Returns `Some(increment)` for objects that use COV_Increment filtering
661    /// (e.g., AnalogInput, AnalogOutput, AnalogValue, Loop, Staging, and the
662    /// Integer, Positive Integer and Large Analog Value types). A notification
663    /// fires only when the numeric Present_Value delta reaches the increment.
664    /// Property COV inherits this increment only for numeric Present_Value;
665    /// other selected properties use their own supplied increment or typed
666    /// change reporting.
667    ///
668    /// The increment is an `f64` so every COV_Increment datatype fits without
669    /// rounding: a REAL widens exactly, a Large Analog Value's Double is kept
670    /// as is, and an Unsigned increment is exact up to 2^53.
671    ///
672    /// Returns `None` for objects that notify on any state change (binary, multi-state).
673    fn cov_increment(&self) -> Option<f64> {
674        None
675    }
676
677    /// Properties a whole-object (SubscribeCOV) notification reports after
678    /// its leading value and Status_Flags, in report order.
679    ///
680    /// The leading value is Present_Value, except on Access Point, whose
681    /// Table 13-1 row leads with Access_Event; the server chooses it by object
682    /// type. The default follows the object type's Table 13-1 row:
683    ///
684    /// - Access Door: Door_Alarm_State, a trigger.
685    /// - Access Point: Access_Event_Tag, Access_Event_Time (a trigger),
686    ///   Access_Event_Credential and Access_Event_Authentication_Factor.
687    /// - Credential Data Input: Update_Time, a trigger.
688    /// - Load Control: Requested_Shed_Level, Start_Time, Shed_Duration and
689    ///   Duty_Window, all triggers.
690    /// - Loop: Setpoint and Controlled_Variable_Value.
691    /// - Pulse Converter: Update_Time.
692    /// - Staging: Present_Stage, a trigger.
693    ///
694    /// A trigger's change sends a notification by itself; any other listed
695    /// value only rides along. Every other type reports nothing more. The
696    /// server leaves out a listed property the object's Property_List lacks.
697    /// Property subscriptions (SubscribeCOVProperty and
698    /// SubscribeCOVPropertyMultiple) report their own property instead.
699    fn cov_reported_properties(&self) -> &'static [CovReportedProperty] {
700        cov_reported_properties_default(self.object_identifier().object_type())
701    }
702
703    /// Set the OVERRIDDEN bit in StatusFlags.
704    ///
705    /// For software-only objects this is always FALSE per spec. Hardware
706    /// integrations can override to set TRUE when present_value is overridden
707    /// by physical means (e.g., a manual switch on an output).
708    fn set_overridden(&mut self, _overridden: bool) {}
709
710    /// Evaluate intrinsic reporting after a present_value change.
711    ///
712    /// This is the per-write entry point: it seeds (or cancels) a pending
713    /// delayed transition and fires immediately only when `Time_Delay == 0`.
714    /// It never advances the `Time_Delay` countdown — repeated writes to the
715    /// same value do not shorten the delay (ASHRAE 135-2020 Clause 13.3 counts
716    /// the delay in seconds, so the countdown advances once per elapsed second
717    /// via [`tick_intrinsic_reporting`](Self::tick_intrinsic_reporting)).
718    ///
719    /// Returns `Some(TransitionOutcome)` whenever a transition is ready to be
720    /// committed, or
721    /// `None` when none did (no change, delay seeded, or the object does not
722    /// support intrinsic reporting). A cleared `Event_Enable` bit sets the
723    /// outcome's `distribute` flag to false rather than withholding the
724    /// transition. Implementations must leave `Event_State`,
725    /// `Acked_Transitions`, event history, and fire-ready detector state
726    /// unchanged until [`commit_event_transition_internal`](Self::commit_event_transition_internal)
727    /// succeeds. Clause 13.2.2.1.4's transition actions run either way, and
728    /// `Event_Enable` disables only external distribution, downstream in the
729    /// notification-distribution process (Clause 13.2.5).
730    fn evaluate_intrinsic_reporting(&mut self) -> Option<TransitionOutcome> {
731        None
732    }
733
734    /// Advance the `Time_Delay` countdown for a pending transition.
735    ///
736    /// Called by the server's one-second intrinsic-reporting task. Fires the
737    /// pending transition when its delay elapses this tick, cancels it if the
738    /// triggering condition reverted, and returns `Some(TransitionOutcome)`
739    /// when a transition is ready. A fire-ready proposal must remain
740    /// retryable until the commit hook succeeds. As with
741    /// [`evaluate_intrinsic_reporting`](Self::evaluate_intrinsic_reporting),
742    /// `Event_Enable` is reported via `distribute`, not by returning `None`.
743    /// Objects without a delayed transition return `None`.
744    fn tick_intrinsic_reporting(&mut self) -> Option<TransitionOutcome> {
745        None
746    }
747
748    /// Atomically commit all object-owned state for one event transition.
749    ///
750    /// The caller supplies an exact state change, its transition coordinate,
751    /// the resolved Notification Class `Ack_Required` value, a typed
752    /// timestamp, and an optional message. Implementations must validate the
753    /// coordinate and source state before changing `Event_State`,
754    /// `Acked_Transitions`, `Event_Time_Stamps`, or stored message state, and
755    /// must leave every value unchanged on error. A successful
756    /// implementation also finalizes the detector's pending and fault-edge
757    /// state; a failed commit leaves that state retryable.
758    ///
759    /// This internal channel is deliberately separate from network property
760    /// writes and notification distribution. The default fails closed so an
761    /// object participates only after implementing this contract. Custom objects
762    /// can own and commit their state directly using the public
763    /// [`EventTransitionCommit`] and [`EventTransitionCommitError`] types;
764    /// no built-in commit kernel is required. Both server intrinsic paths
765    /// require success before distributing a notification.
766    #[doc(hidden)]
767    fn commit_event_transition_internal(
768        &mut self,
769        _commit: EventTransitionCommit,
770    ) -> Result<(), EventTransitionCommitError> {
771        Err(EventTransitionCommitError::Unsupported)
772    }
773
774    /// Atomically commit Event Enrollment Reliability and transition state.
775    ///
776    /// This Event Enrollment-specific channel joins `Reliability` to the
777    /// existing atomic `Event_State`, `Acked_Transitions`, and
778    /// `Event_Time_Stamps` commit. Implementations must stage every supplied
779    /// value before assigning object-owned fields and leave them unchanged on
780    /// error. The default fails closed for custom objects that have not adopted
781    /// the stronger contract.
782    #[doc(hidden)]
783    fn commit_event_enrollment_reliability_internal(
784        &mut self,
785        _commit: EventEnrollmentReliabilityCommit,
786    ) -> Result<(), EventTransitionCommitError> {
787        Err(EventTransitionCommitError::Unsupported)
788    }
789
790    /// Evaluate this object's schedule at `time` on `today` (Clause 12.24.4).
791    ///
792    /// `calendar_active` answers for a special event whose period references
793    /// a Calendar: whether that Calendar is TRUE on `today`. Returns the
794    /// writes owed when Present_Value changed, the object has just entered
795    /// its Effective_Period, or its references or priority changed since the
796    /// last write, with the complete local references, target array indices
797    /// included. Otherwise, while some references refused their last write,
798    /// returns a [`retry`](ScheduleWrite::retry) of the current value to
799    /// those references only (#1436). Only meaningful for Schedule objects;
800    /// default returns `None`.
801    fn tick_schedule(
802        &mut self,
803        _today: SpecificDate,
804        _time: Time,
805        _calendar_active: &dyn Fn(ObjectIdentifier) -> bool,
806    ) -> Option<ScheduleWrite> {
807        None
808    }
809
810    /// Take the writes this schedule owes its targets apart from its
811    /// calculation, each once, in order: a NULL to every priority slot a
812    /// change of List_Of_Object_Property_References or Priority_For_Writing
813    /// left behind (#1088), then the Present_Value owed out of service, for a
814    /// client's write (Clause 12.24.14) or a change of those two properties.
815    ///
816    /// A schedule pass collects them before calling
817    /// [`tick_schedule`](Self::tick_schedule), so they reach the targets ahead
818    /// of any calculated value; they need no clock. Only meaningful for
819    /// Schedule objects; default returns none.
820    fn take_owed_schedule_writes(&mut self) -> Vec<ScheduleWrite> {
821        Vec::new()
822    }
823
824    /// Report how each target took `write`, one of this schedule's writes:
825    /// `outcomes` holds one entry per member of `write.references`, in order.
826    ///
827    /// A Schedule judges the reference half of its Reliability from these
828    /// (Clause 12.24.13, #1086). Returns whether a readable property, such as
829    /// Reliability, changed. Only meaningful for Schedule objects; default
830    /// returns `false`.
831    fn complete_schedule_write(
832        &mut self,
833        _write: &ScheduleWrite,
834        _outcomes: &[ScheduleTargetOutcome],
835    ) -> bool {
836        false
837    }
838
839    /// The [`retry`](ScheduleWrite::retry) of the current value to the
840    /// references whose last write was refused and that name `target`, an
841    /// object just added to the database (#1440), so the refusal can clear
842    /// without waiting for the next pass. `None` when no such refusal
843    /// stands, or when the pass itself would retry nothing: out of service,
844    /// outside Effective_Period, or with a NULL Present_Value. Only
845    /// meaningful for Schedule objects; default returns `None`.
846    fn retry_refusals_naming(&self, _target: ObjectIdentifier) -> Option<ScheduleWrite> {
847        None
848    }
849
850    /// Whether this Calendar's Date_List matches `day`: its Present_Value on
851    /// that day. `None` for an object that does not evaluate a date list; the
852    /// schedule tick then reads its Present_Value instead.
853    #[doc(hidden)]
854    fn calendar_state_internal(&self, _day: SpecificDate) -> Option<bool> {
855        None
856    }
857
858    /// Acknowledge an alarm transition. Sets the `transition_bit` flags in acked_transitions.
859    /// Returns Ok(()) if the object supports event detection, Err otherwise.
860    fn acknowledge_alarm(
861        &mut self,
862        _transition_bit: EventTransitionBits,
863    ) -> Result<(), bacnet_types::error::Error> {
864        Err(bacnet_types::error::Error::Protocol {
865            class: bacnet_types::enums::ErrorClass::OBJECT,
866            code: bacnet_types::enums::ErrorCode::OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED,
867        })
868    }
869
870    /// Correlate an acknowledgment with the latest committed transition.
871    #[doc(hidden)]
872    fn acknowledge_alarm_correlated_internal(
873        &mut self,
874        _event_state: EventState,
875        _timestamp: &BACnetTimeStamp,
876    ) -> Result<(), Error> {
877        Err(Error::Protocol {
878            class: ErrorClass::OBJECT,
879            code: ErrorCode::NO_ALARM_CONFIGURED,
880        })
881    }
882
883    /// Correlate an acknowledgment and report exact object-owned history.
884    ///
885    /// The default delegates to the source-compatible coarse hook and returns
886    /// no notification context. Custom objects that implement only the coarse
887    /// hook therefore retain their accepted-acknowledgment behavior without the
888    /// bundled server guessing historical states for an ACK notification.
889    #[doc(hidden)]
890    fn acknowledge_alarm_correlated_detailed_internal(
891        &mut self,
892        event_state: EventState,
893        timestamp: &BACnetTimeStamp,
894    ) -> Result<Option<EventStateChange>, Error> {
895        self.acknowledge_alarm_correlated_internal(event_state, timestamp)
896            .map(|()| None)
897    }
898
899    /// Apply a LifeSafetyOperation atomically to this object.
900    ///
901    /// Implementations must leave the object unchanged when returning `Err`.
902    /// They run synchronously under the object-database write lock and must be
903    /// fast, nonblocking, and panic-free. External or irreversible actuation
904    /// also needs an application-owned idempotency/replay contract. The default
905    /// reports that the object does not support this service. Successful
906    /// implementations return an outcome with exact, ordered, deduplicated
907    /// committed property changes. `AlreadyApplied` leaves all state unchanged
908    /// and reports no deltas. The bundled server uses these changes for COV
909    /// after releasing the database lock and dispatching the service response.
910    fn apply_life_safety_operation(
911        &mut self,
912        _operation: LifeSafetyOperation,
913    ) -> Result<LifeSafetyOperationOutcome, Error> {
914        Err(Error::Protocol {
915            class: ErrorClass::OBJECT,
916            code: ErrorCode::OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED,
917        })
918    }
919
920    /// Set the next LifeSafetyOperation expected by trusted local logic.
921    ///
922    /// This is an application-facing state channel, not a network property
923    /// write. The default reports that the object does not support the state.
924    fn set_life_safety_operation_expected_internal(
925        &mut self,
926        _operation: LifeSafetyOperation,
927    ) -> Result<(), Error> {
928        Err(Error::Protocol {
929            class: ErrorClass::OBJECT,
930            code: ErrorCode::OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED,
931        })
932    }
933
934    /// Apply an internally-detected `Event_State` transition.
935    ///
936    /// This is the **internal** lifecycle path for the algorithmically-derived
937    /// `Event_State` on objects such as Event Enrollment (ASHRAE 135-2020
938    /// Clause 12.12). It is deliberately distinct from the network
939    /// [`write_property`](Self::write_property) route: `Event_State` is
940    /// read-only over the network, so network writes are rejected while the
941    /// server's evaluator reaches the field through this method. Objects
942    /// without an algorithmic `Event_State` return
943    /// `OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED`.
944    ///
945    /// The **default** returns `Err`, so objects without an algorithmic
946    /// `Event_State` opt out. Objects that do model one (e.g.
947    /// `EventEnrollmentObject`) override this to store the value verbatim:
948    /// the only caller is a trusted internal evaluator that passes a modeled
949    /// [`EventState`], mirroring the inherent `set_event_state` builder and
950    /// the existing read arm. Network-facing validation — rejecting all
951    /// `Event_State` writes — lives in [`write_property`](Self::write_property),
952    /// not here. Implementations must leave `Event_State` unchanged when they
953    /// return `Err`.
954    fn set_event_state_internal(&mut self, _state: EventState) -> Result<(), Error> {
955        Err(Error::Protocol {
956            class: ErrorClass::OBJECT,
957            code: ErrorCode::OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED,
958        })
959    }
960
961    /// Snapshot this object's Event Enrollment evaluation state, if it models one.
962    ///
963    /// This is the read half of the internal channel the server's Event
964    /// Enrollment evaluator uses to persist per-enrollment algorithm state
965    /// across evaluation cycles: the pending (delayed) transition countdown,
966    /// the CHANGE_OF_VALUE detection baseline (the monitored sample at the
967    /// latest NORMAL indication, per Clause 13.3.3), and
968    /// the monitored value behind the most recent OFFNORMAL transition (Clause
969    /// 13.3.2 condition (c)). Like [`set_event_state_internal`](Self::set_event_state_internal)
970    /// it deliberately bypasses the network property model: none of the three
971    /// slots is a BACnet property, and 135-2020 assigns their initialization
972    /// to local matters.
973    ///
974    /// The default returns `None` — objects without algorithmic event
975    /// detection carry no such state, and the evaluator treats `None` as an
976    /// empty state it cannot write back (delay honoring and the COV baseline
977    /// then stay unavailable, matching this crate's pre-delay behavior).
978    fn enrollment_eval_state_internal(&self) -> Option<EventEnrollmentEvalState> {
979        None
980    }
981
982    /// Store this object's Event Enrollment evaluation state.
983    ///
984    /// The write half of [`enrollment_eval_state_internal`](Self::enrollment_eval_state_internal).
985    /// The only caller is the trusted server evaluator, passing a state it
986    /// derived from a prior snapshot plus the current cycle's evaluation.
987    /// Implementations enforce the Clause 13.2.2.1 invariant by construction:
988    /// transitions are prohibited while `Event_Detection_Enable` is FALSE,
989    /// so a write arriving then is refused rather than queued (and the
990    /// detection-disable reset has already cleared the fields).
991    ///
992    /// The **default** returns `Err`, so objects without enrollment evaluation
993    /// state opt out and the evaluator's write-back is dropped, never stored
994    /// into an object that does not model it.
995    fn set_enrollment_eval_state_internal(
996        &mut self,
997        _state: EventEnrollmentEvalState,
998    ) -> Result<(), Error> {
999        Err(Error::Protocol {
1000            class: ErrorClass::OBJECT,
1001            code: ErrorCode::OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED,
1002        })
1003    }
1004
1005    /// Snapshot the monitored source that owns Event Enrollment private state.
1006    ///
1007    /// The outer `Option` indicates whether the object supports this channel;
1008    /// the inner `Option` is empty before a source has been established.
1009    /// The server stores source ownership in its object database when an
1010    /// object implements evaluation state but leaves this channel unsupported.
1011    fn enrollment_eval_source_internal(&self) -> Option<Option<EventEnrollmentMonitoredSource>> {
1012        None
1013    }
1014
1015    /// Store or clear the monitored source that owns Event Enrollment state.
1016    fn set_enrollment_eval_source_internal(
1017        &mut self,
1018        _source: Option<EventEnrollmentMonitoredSource>,
1019    ) -> Result<(), Error> {
1020        Err(Error::Protocol {
1021            class: ErrorClass::OBJECT,
1022            code: ErrorCode::OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED,
1023        })
1024    }
1025
1026    /// Set or clear one `Acked_Transitions` bit on a received event-state
1027    /// transition.
1028    ///
1029    /// Implements the alarm-acknowledgment half of Clause 13.2.2.1.4's fourth
1030    /// transition action: pass the transition to alarm-acknowledgment handling.
1031    /// Under Clause 13.2.3, receiving a transition updates its Acked_Transitions
1032    /// bit to the inverse of the corresponding Ack_Required bit. The caller (the
1033    /// server evaluator) resolves `Ack_Required` from the referenced
1034    /// Notification Class object and passes the outcome as `acknowledged`;
1035    /// this method performs only the bit maintenance.
1036    ///
1037    /// `transition_bit` is the transition direction's flag, as returned by
1038    /// [`EventTransition::bit_mask`](crate::event::EventTransition::bit_mask). The set half overlaps the
1039    /// network-reachable [`acknowledge_alarm`](Self::acknowledge_alarm), which
1040    /// also ORs the bit in per Clause 13.2.3's acknowledgment-indication
1041    /// paragraph; the clear half has no network route by design (a property
1042    /// write could fabricate or erase acknowledgments — see the
1043    /// `write_generic_event_properties!` denial comment).
1044    ///
1045    /// The **default** returns `Err`, so objects without an algorithmic
1046    /// `Acked_Transitions` opt out.
1047    fn set_acked_transitions_internal(
1048        &mut self,
1049        _transition_bit: EventTransitionBits,
1050        _acknowledged: bool,
1051    ) -> Result<(), Error> {
1052        Err(Error::Protocol {
1053            class: ErrorClass::OBJECT,
1054            code: ErrorCode::OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED,
1055        })
1056    }
1057
1058    /// Evaluate and, when necessary, mutate this object's `Reliability`.
1059    ///
1060    /// Reliability evaluation is object-owned: an implementation decides
1061    /// whether and how its internal conditions affect `Reliability`, performs
1062    /// the mutation itself, and returns [`ReliabilityEvaluation::Changed`] only
1063    /// after that mutation succeeds. [`ReliabilityEvaluation::Unchanged`] means
1064    /// the object made no mutation. Returning `Err` MUST leave all object state
1065    /// unchanged.
1066    ///
1067    /// The default opts out without changing state, preserving source
1068    /// compatibility for object implementations that do not own a reliability
1069    /// evaluation algorithm.
1070    fn evaluate_reliability_internal(&mut self) -> Result<ReliabilityEvaluation, Error> {
1071        Ok(ReliabilityEvaluation::Unchanged)
1072    }
1073
1074    /// Whether periodic object-owned reliability evaluation is currently
1075    /// inhibited.
1076    ///
1077    /// The default is FALSE so existing and downstream object implementations
1078    /// remain source-compatible. Objects that elect the optional
1079    /// Reliability_Evaluation_Inhibit property override this internal
1080    /// predicate; reporting of an already-applied Reliability transition is
1081    /// intentionally unaffected.
1082    #[doc(hidden)]
1083    fn reliability_evaluation_inhibited_internal(&self) -> bool {
1084        false
1085    }
1086
1087    /// Apply an internally-derived `Reliability` value.
1088    ///
1089    /// This is the **internal** reliability-evaluation path, distinct from the
1090    /// network [`write_property`](Self::write_property) route. Implementations
1091    /// enforce symmetric ownership: clients may write while `Out_Of_Service`
1092    /// is TRUE, and internal evaluation may write while it is FALSE. ASHRAE
1093    /// 135-2020 Clause 3.2 describes reliability evaluation as the object's
1094    /// assessment of its reliability, producing its Reliability property value.
1095    ///
1096    /// The default rejects the operation, so object types without an internal
1097    /// reliability-evaluation process remain unaffected.
1098    fn set_reliability_internal(&mut self, _reliability: Reliability) -> Result<(), Error> {
1099        Err(Error::Protocol {
1100            class: ErrorClass::OBJECT,
1101            code: ErrorCode::OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED,
1102        })
1103    }
1104
1105    /// Apply the logical `Present_Value` supplied by the local application.
1106    ///
1107    /// This narrow internal hook is distinct from the network
1108    /// [`write_property`](Self::write_property) route. Built-in Analog Input,
1109    /// Binary Input, and Multi-state Input objects opt in. Their implementations
1110    /// accept application updates only while in service; rejecting them while
1111    /// `Out_Of_Service` is TRUE is a local ownership policy that protects the
1112    /// client's simulation value, not a requirement imposed by the Standard.
1113    ///
1114    /// Analog, Binary, and Multi-state Value objects opt in unless their
1115    /// [`PresentValueAccess`](crate::present_value_access::PresentValueAccess)
1116    /// is `Commandable`. For them, rejecting updates while `Out_Of_Service` is
1117    /// TRUE is required: their Out_Of_Service clause keeps software local to
1118    /// the device from changing Present_Value.
1119    ///
1120    /// Life Safety Point and Zone opt in with a BACnetLifeSafetyState. Clients
1121    /// never write their Present_Value, so they take the application's value in
1122    /// service and out of service alike, and the hook leaves Tracking_Value,
1123    /// Silenced and Operation_Expected as they are: any latching rule belongs
1124    /// to the application.
1125    ///
1126    /// The default fails closed so commandable and other object families do not
1127    /// acquire privileged `Present_Value` write authority through this hook.
1128    fn set_present_value_internal(&mut self, _value: PropertyValue) -> Result<(), Error> {
1129        Err(Error::Protocol {
1130            class: ErrorClass::OBJECT,
1131            code: ErrorCode::OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED,
1132        })
1133    }
1134
1135    /// [`set_present_value_internal`](Self::set_present_value_internal) on
1136    /// behalf of `origin`, the local Device the application runs in.
1137    ///
1138    /// A noncommandable Analog, Binary or Multi-state Value that tracks its
1139    /// Present_Value's source (#1552) publishes `origin` as Value_Source
1140    /// after the update, as Clause 19.5 asks of a write the local device
1141    /// makes; plain `set_present_value_internal` leaves it NONE. The server's
1142    /// `set_present_value_local` calls this when it knows its Device. The
1143    /// default ignores `origin`, and decorators must forward it.
1144    fn set_present_value_from_internal(
1145        &mut self,
1146        value: PropertyValue,
1147        _origin: &crate::command_source::CommandOrigin,
1148    ) -> Result<(), Error> {
1149        self.set_present_value_internal(value)
1150    }
1151
1152    /// Apply the `Tracking_Value` the local application derived.
1153    ///
1154    /// Only the built-in Life Safety Point and Zone opt in, with a
1155    /// BACnetLifeSafetyState; the property stays read-only over the network in
1156    /// service. While `Out_Of_Service` is TRUE a client's simulated value keeps
1157    /// being served and this one takes over on the return to service. The
1158    /// default fails closed with the same error as
1159    /// [`set_present_value_internal`](Self::set_present_value_internal).
1160    fn set_tracking_value_internal(&mut self, _value: PropertyValue) -> Result<(), Error> {
1161        Err(Error::Protocol {
1162            class: ErrorClass::OBJECT,
1163            code: ErrorCode::OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED,
1164        })
1165    }
1166
1167    /// Apply an input the application reports for an access-control object
1168    /// the server holds (#1132): an Access Point's access event, a
1169    /// Credential Data Input's read or an Access Door's hardware state, each
1170    /// a record whose values change together. See
1171    /// [`AccessControlInput`](crate::access_control::AccessControlInput).
1172    ///
1173    /// Only the built-in Access Point, Credential Data Input and Access Door
1174    /// opt in, each for its own kind of record. While Out_Of_Service is TRUE
1175    /// the point refuses an event with PROPERTY / WRITE_ACCESS_DENIED, since
1176    /// it performs no authentication then, and the door and the reader store
1177    /// the input with their device values put aside, leaving a client's
1178    /// simulated values served. The default, and an object offered another
1179    /// kind of record, fails closed with the same error as
1180    /// [`set_present_value_internal`](Self::set_present_value_internal).
1181    fn report_access_input_internal(
1182        &mut self,
1183        _input: crate::access_control::AccessControlInput,
1184    ) -> Result<(), Error> {
1185        Err(Error::Protocol {
1186            class: ErrorClass::OBJECT,
1187            code: ErrorCode::OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED,
1188        })
1189    }
1190
1191    /// Apply the Controlled_Variable_Value measured by the local application.
1192    ///
1193    /// Only the built-in Loop opts in. Its control algorithm runs in the
1194    /// application, which feeds the measured value here while it does so; the
1195    /// property stays read-only over the network. The default fails closed
1196    /// with the same error as [`set_present_value_internal`](Self::set_present_value_internal).
1197    fn set_controlled_variable_value_internal(
1198        &mut self,
1199        _value: PropertyValue,
1200    ) -> Result<(), Error> {
1201        Err(Error::Protocol {
1202            class: ErrorClass::OBJECT,
1203            code: ErrorCode::OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED,
1204        })
1205    }
1206
1207    /// Record one sample for an Averaging object.
1208    ///
1209    /// Only the built-in Averaging object opts in. The value is the reading
1210    /// of the referenced property, or `None` when the attempt produced no
1211    /// value, and the object updates its sample window, statistics and counts
1212    /// together. The application calls it for the samples it takes, and the
1213    /// database for the ones the object's own schedule asks for (see
1214    /// [`take_due_averaging_sample_internal`](Self::take_due_averaging_sample_internal)).
1215    /// The default fails closed with the same error as
1216    /// [`set_present_value_internal`](Self::set_present_value_internal).
1217    fn add_averaging_sample_internal(
1218        &mut self,
1219        _sample: Option<PropertyValue>,
1220    ) -> Result<(), Error> {
1221        Err(Error::Protocol {
1222            class: ErrorClass::OBJECT,
1223            code: ErrorCode::OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED,
1224        })
1225    }
1226
1227    /// Claim the Averaging sample the object's schedule has due at the
1228    /// process-local monotonic instant `now`.
1229    ///
1230    /// When one is due the object steps its schedule past it and returns the
1231    /// property to read; the caller reads it while it still holds exclusive
1232    /// access and records the outcome with
1233    /// [`add_averaging_sample_internal`](Self::add_averaging_sample_internal).
1234    /// An object that answers here reports the due time through
1235    /// [`next_monotonic_deadline_internal`](Self::next_monotonic_deadline_internal),
1236    /// so the server's monotonic task wakes for it. The built-in Averaging
1237    /// object opts in while it holds an Object_Property_Reference and a
1238    /// monotonic clock is bound; the default has nothing to sample.
1239    #[doc(hidden)]
1240    fn take_due_averaging_sample_internal(
1241        &mut self,
1242        _now: Duration,
1243    ) -> Option<BACnetObjectPropertyReference> {
1244        None
1245    }
1246
1247    /// The local property a Pulse Converter counts its input from, its
1248    /// Input_Reference (Clause 12.23.6): `Some(None)` while it holds none,
1249    /// and `None` for an object that counts no referenced input, which the
1250    /// default is.
1251    ///
1252    /// The database judges the reference against its own objects
1253    /// (`ObjectDatabase::check_input_reference`) and reports the verdict
1254    /// through [`set_input_usable_internal`](Self::set_input_usable_internal).
1255    #[doc(hidden)]
1256    fn input_reference_internal(&self) -> Option<Option<&BACnetObjectPropertyReference>> {
1257        None
1258    }
1259
1260    /// Take the database's verdict on the reference
1261    /// [`input_reference_internal`](Self::input_reference_internal) returned:
1262    /// `false` when it names a property the object can't count from, which
1263    /// Clause 12.23.9 reports as a CONFIGURATION_ERROR Reliability. Returns
1264    /// whether a readable property changed, so a caller owes COV. The
1265    /// default has no input to judge.
1266    #[doc(hidden)]
1267    fn set_input_usable_internal(&mut self, _usable: bool) -> bool {
1268        false
1269    }
1270
1271    /// Take a reading of the property
1272    /// [`input_reference_internal`](Self::input_reference_internal) names,
1273    /// or `None` when there is nothing to read. A Pulse Converter counts each
1274    /// increase over the last reading into Count (Clause 12.23.14), across a
1275    /// wrap when the reading carries its bound. Returns whether a readable
1276    /// property changed, so a caller owes COV. The default counts nothing.
1277    #[doc(hidden)]
1278    fn take_input_reading_internal(
1279        &mut self,
1280        _reading: Option<crate::accumulator::InputReading>,
1281    ) -> bool {
1282        false
1283    }
1284
1285    /// Borrow this object's Audit Log query storage, if it has any.
1286    ///
1287    /// This read-only, type-erased channel lets the bundled server execute an
1288    /// AuditLogQuery against an object's already-loaded retained records. It
1289    /// deliberately does not expose persistence, mutation, or object
1290    /// downcasting. The **default** returns `None`; an Audit Log object that
1291    /// does not opt in is reported as SERVICES /
1292    /// OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED.
1293    fn audit_log_storage_internal(&self) -> Option<&dyn AuditLogStorage> {
1294        None
1295    }
1296
1297    /// Instance-owned optional Audit Log forwarding profile, never durable pending work.
1298    #[doc(hidden)]
1299    fn audit_log_forwarding_internal(&self) -> Option<Arc<crate::audit::AuditLogForwarding>> {
1300        None
1301    }
1302
1303    /// Set a trusted local Audit Log parent without downcasting or a second object store.
1304    ///
1305    /// The default opts out. This is not a network property-write capability;
1306    /// callers own configuration admission, and the server still validates the route.
1307    #[doc(hidden)]
1308    fn set_audit_log_parent_internal(
1309        &mut self,
1310        _parent: bacnet_types::constructed::BACnetDeviceObjectReference,
1311    ) -> Result<(), Error> {
1312        Err(Error::Protocol {
1313            class: ErrorClass::OBJECT,
1314            code: ErrorCode::OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED,
1315        })
1316    }
1317
1318    /// Mutably borrow this object's Audit notification receiver capability.
1319    ///
1320    /// The default opts out. Implementations own their persistence transaction
1321    /// and must leave memory unchanged when the batch cannot be committed.
1322    fn audit_log_notification_sink_internal(
1323        &mut self,
1324    ) -> Option<&mut dyn AuditLogNotificationSink> {
1325        None
1326    }
1327
1328    /// Mutably borrow this object's staged-write capability (#1270).
1329    ///
1330    /// An object that saves a written state before serving it opts in, so the
1331    /// server can stage the write and run the save without the database
1332    /// guard. The default opts out: the object's writes run as they always
1333    /// do. See [`crate::durable`].
1334    #[doc(hidden)]
1335    fn durable_writes_internal(&mut self) -> Option<&mut dyn DurableWrites> {
1336        None
1337    }
1338
1339    /// Borrow this object's trusted local File configuration capability.
1340    ///
1341    /// The default returns `None`. The built-in [`crate::file::FileObject`]
1342    /// opts in so bindings can configure its pending payload, access method,
1343    /// and growth limits without general object downcasting or a parallel
1344    /// state cache.
1345    #[doc(hidden)]
1346    fn file_configuration_internal(&self) -> Option<&dyn FileConfiguration> {
1347        None
1348    }
1349
1350    /// Mutably borrow this object's trusted local File configuration capability.
1351    ///
1352    /// The default returns `None`; payload mutations remain object-owned and
1353    /// must preserve the same accounting and metadata behavior as the built-in
1354    /// File setters.
1355    #[doc(hidden)]
1356    fn file_configuration_internal_mut(&mut self) -> Option<&mut dyn FileConfiguration> {
1357        None
1358    }
1359
1360    /// Borrow this object's File storage, if it has any.
1361    ///
1362    /// This is the read half of the **internal** channel the server's
1363    /// AtomicReadFile handler uses to reach file contents. Like
1364    /// [`set_event_state_internal`](Self::set_event_state_internal) it
1365    /// bypasses the property model on purpose: Table 12-16 (ASHRAE 135-2020
1366    /// Clause 12.13) defines no File Data property, so file contents are
1367    /// reachable only through the Clause 14 File Access Services.
1368    ///
1369    /// The **default** returns `None`, so object types without a file opt
1370    /// out; the server reports `None` on a File-typed object as SERVICES /
1371    /// FILE_ACCESS_DENIED (Clause 18 covers locked or inaccessible files)
1372    /// rather than reading it as empty.
1373    /// Applications backing a File object with their own storage — a disk
1374    /// file, a firmware partition — implement [`FileStorage`] and return
1375    /// `Some`.
1376    fn file_storage_internal(&self) -> Option<&dyn FileStorage> {
1377        None
1378    }
1379
1380    /// Mutably borrow this object's File storage, if it has any.
1381    ///
1382    /// The write half of
1383    /// [`file_storage_internal`](Self::file_storage_internal), used by the
1384    /// AtomicWriteFile handler after the read-only and access-method gates
1385    /// have passed. The **default** returns `None`.
1386    fn file_storage_internal_mut(&mut self) -> Option<&mut dyn FileStorage> {
1387        None
1388    }
1389
1390    /// Return stable identities aligned with this object's resident log records.
1391    ///
1392    /// Implementing log objects return identities oldest-to-newest, in the
1393    /// same order as their public resident-record view and their
1394    /// [`log_buffer_internal`](Self::log_buffer_internal) records. Sequence
1395    /// numbers are object-owned metadata and never part of an encoded BACnet
1396    /// record. Non-log objects return `None`.
1397    fn log_record_identities_internal(&self) -> Option<Vec<LogRecordIdentity>> {
1398        None
1399    }
1400
1401    /// Borrow this object's Log_Buffer records as ReadRange pages them.
1402    ///
1403    /// The built-in Trend Log, Trend Log Multiple and Event Log objects
1404    /// answer a ReadProperty of Log_Buffer with PROPERTY / READ_ACCESS_DENIED,
1405    /// since their clauses (12.25.14, 12.30.19, 12.27.13) open the buffer to
1406    /// ReadRange only; the server's ReadRange handler reads it through this
1407    /// channel instead, one encoded record per item. The **default** returns
1408    /// `None`, which leaves ReadRange reading the property through
1409    /// [`read_property`](Self::read_property).
1410    fn log_buffer_internal(&self) -> Option<&dyn LogBufferRecords> {
1411        None
1412    }
1413
1414    /// Submit a trend record to an object's log lifecycle.
1415    ///
1416    /// `Ok(())` means the operation was accepted, not that an ordinary record
1417    /// became resident: disabled logs ignore it and zero-capacity logs may only
1418    /// increment their count. A required status transition can replace the
1419    /// ordinary record. Timestamp failures return an error without mutation.
1420    /// Objects without trend insertion return OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED.
1421    fn add_trend_record(&mut self, _record: BACnetLogRecord) -> Result<(), Error> {
1422        Err(Error::Protocol {
1423            class: ErrorClass::OBJECT,
1424            code: ErrorCode::OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED,
1425        })
1426    }
1427
1428    /// Submit a Trend Log Multiple record, one value per monitored member, to
1429    /// an object's log lifecycle.
1430    ///
1431    /// The outcomes match [`add_trend_record`](Self::add_trend_record).
1432    /// Objects without Trend Log Multiple insertion return
1433    /// OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED.
1434    fn add_trend_multiple_record(&mut self, _record: BACnetLogMultipleRecord) -> Result<(), Error> {
1435        Err(Error::Protocol {
1436            class: ErrorClass::OBJECT,
1437            code: ErrorCode::OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED,
1438        })
1439    }
1440
1441    /// Submit an Event Log record to an object's log lifecycle.
1442    ///
1443    /// The server hands the event notifications this device builds to its
1444    /// Event Logs through this hook
1445    /// ([`ObjectDatabase::log_event_notification`](crate::database::ObjectDatabase::log_event_notification)).
1446    /// The outcomes match [`add_trend_record`](Self::add_trend_record).
1447    /// Objects without Event Log insertion return
1448    /// OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED.
1449    fn add_event_log_record(&mut self, _record: BACnetEventLogRecord) -> Result<(), Error> {
1450        Err(Error::Protocol {
1451            class: ErrorClass::OBJECT,
1452            code: ErrorCode::OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED,
1453        })
1454    }
1455
1456    /// Look at a log's Start_Time / Stop_Time window against the bound
1457    /// clock, recording the LOG_DISABLED change when it opened or closed
1458    /// since the last look while Enable is TRUE.
1459    ///
1460    /// The trend poller calls this for every Trend Log, Trend Log Multiple
1461    /// and Event Log on each pass, so a window that moves while no record
1462    /// arrives is still logged within one pass. Returns whether a record was
1463    /// added. The default, for objects without a window, does nothing and
1464    /// returns `false`.
1465    #[doc(hidden)]
1466    fn refresh_log_window_internal(&mut self) -> bool {
1467        false
1468    }
1469
1470    /// Whether a log keeps the ordinary records it is given now: Enable is
1471    /// TRUE and its Start_Time / Stop_Time window admitted the local time at
1472    /// the last look. A Trend Log logging by COV starts over from the
1473    /// current value when collection resumes, so the trend poller asks this
1474    /// before each look (#1480). The default, for objects that aren't logs,
1475    /// says yes and leaves the gate to the insertion hook.
1476    #[doc(hidden)]
1477    fn log_collecting_internal(&self) -> bool {
1478        true
1479    }
1480
1481    /// Whether this Event Log takes the event notifications the device
1482    /// receives, through
1483    /// [`ObjectDatabase::log_received_event_notification`](crate::database::ObjectDatabase::log_received_event_notification).
1484    /// The default, and an Event Log that hasn't opted in, says no.
1485    #[doc(hidden)]
1486    fn logs_received_event_notifications_internal(&self) -> bool {
1487        false
1488    }
1489
1490    /// The counts the last committed BUFFER_READY transition reported, for
1491    /// the server to carry as its event values (Clause 13.3.7). `None` for an
1492    /// object that hasn't reported one, or doesn't run that algorithm.
1493    #[doc(hidden)]
1494    fn buffer_ready_report_internal(&self) -> Option<BufferReadyReport> {
1495        None
1496    }
1497
1498    /// The local property this object's Event_Algorithm_Inhibit follows, its
1499    /// Event_Algorithm_Inhibit_Ref (#1329); `None` while it holds none, and
1500    /// for an object without one, which the default is. The database reads
1501    /// the property and hands the value over through
1502    /// [`follow_event_algorithm_inhibit_internal`](Self::follow_event_algorithm_inhibit_internal).
1503    #[doc(hidden)]
1504    fn event_algorithm_inhibit_reference_internal(&self) -> Option<BACnetObjectPropertyReference> {
1505        None
1506    }
1507
1508    /// Take the value the database read from the property
1509    /// [`event_algorithm_inhibit_reference_internal`](Self::event_algorithm_inhibit_reference_internal)
1510    /// names as Event_Algorithm_Inhibit; returns whether it changed. The
1511    /// default follows nothing.
1512    #[doc(hidden)]
1513    fn follow_event_algorithm_inhibit_internal(&mut self, _inhibit: bool) -> bool {
1514        false
1515    }
1516}