diff --git a/dnp3/src/master/extract.rs b/dnp3/src/master/extract.rs index 4d6b8f57..13d7f6e2 100644 --- a/dnp3/src/master/extract.rs +++ b/dnp3/src/master/extract.rs @@ -3,7 +3,7 @@ use crate::app::measurement::*; use crate::app::parse::parser::{HeaderCollection, HeaderDetails, ObjectHeader}; use crate::app::variations::*; use crate::app::ResponseHeader; -use crate::master::handler::ReadHandler; +use crate::master::ReadHandler; use crate::master::ReadType; /// Extract measurements from a HeaderCollection, sinking them into diff --git a/dnp3/src/master/handler.rs b/dnp3/src/master/handler.rs index 6cf00f40..f3b9b6da 100644 --- a/dnp3/src/master/handler.rs +++ b/dnp3/src/master/handler.rs @@ -2,7 +2,6 @@ use std::net::SocketAddr; use std::time::{Duration, SystemTime}; use crate::app::attr::*; -use crate::app::measurement::*; use crate::app::*; use crate::decode::DecodeLevel; @@ -28,7 +27,7 @@ use crate::master::tasks::time::TimeSyncTask; use crate::master::tasks::Task; use crate::master::{ AuthKey, BlockNumber, DeadBandHeader, DirReadConfig, FileCredentials, FileError, FileHandle, - FileInfo, FileMode, FileReadConfig, FileReader, Headers, OpenFile, WriteError, + FileInfo, FileMode, FileReadConfig, FileReader, Headers, OpenFile, ReadHandler, WriteError, }; use crate::transport::FragmentAddr; use crate::util::channel::Sender; @@ -664,134 +663,6 @@ pub enum ReadType { PeriodicPoll, } -/// Trait used to process measurement data received from an outstation -#[allow(unused_variables)] -pub trait ReadHandler: Send + Sync { - /// Called as the first action before any of the type-specific handle methods are invoked - /// - /// `read_type` provides information about what triggered the call, e.g. response vs unsolicited - /// `header` provides the full response header - /// - /// Note: The operation may or may not be async depending - fn begin_fragment(&mut self, read_type: ReadType, header: ResponseHeader) -> MaybeAsync<()> { - MaybeAsync::ready(()) - } - - /// Called as the last action after all of the type-specific handle methods have been invoked - /// - /// `read_type` provides information about what triggered the call, e.g. response vs unsolicited - /// `header` provides the full response header - /// - /// Note: The operation may or may not be async depending. A typical use case for using async - /// here would be to publish a message to an async MPSC. - fn end_fragment(&mut self, read_type: ReadType, header: ResponseHeader) -> MaybeAsync<()> { - MaybeAsync::ready(()) - } - - /// Process an object header of `BinaryInput` values - fn handle_binary_input( - &mut self, - info: HeaderInfo, - iter: &mut dyn Iterator, - ) { - } - - /// Process an object header of `DoubleBitBinaryInput` values - fn handle_double_bit_binary_input( - &mut self, - info: HeaderInfo, - iter: &mut dyn Iterator, - ) { - } - - /// Process an object header of `BinaryOutputStatus` values - fn handle_binary_output_status( - &mut self, - info: HeaderInfo, - iter: &mut dyn Iterator, - ) { - } - - /// Process an object header of `Counter` values - fn handle_counter(&mut self, info: HeaderInfo, iter: &mut dyn Iterator) { - } - - /// Process an object header of `FrozenCounter` values - fn handle_frozen_counter( - &mut self, - info: HeaderInfo, - iter: &mut dyn Iterator, - ) { - } - - /// Process an object header of `AnalogInput` values - fn handle_analog_input( - &mut self, - info: HeaderInfo, - iter: &mut dyn Iterator, - ) { - } - - /// Process an object header of `FrozenAnalogInput` values - fn handle_frozen_analog_input( - &mut self, - info: HeaderInfo, - iter: &mut dyn Iterator, - ) { - } - - /// Process an object header of `AnalogInputDeadBand` values - fn handle_analog_input_dead_band( - &mut self, - info: HeaderInfo, - iter: &mut dyn Iterator, - ) { - } - - /// Process an object header of `AnalogOutputStatus` values - fn handle_analog_output_status( - &mut self, - info: HeaderInfo, - iter: &mut dyn Iterator, - ) { - } - - /// Process an object header of `AnalogOutputCommandEvent` values - fn handle_analog_output_command_event( - &mut self, - info: HeaderInfo, - iter: &mut dyn Iterator, - ) { - } - - /// Process an object header of `BinaryOutputCommandEvent` values - fn handle_binary_output_command_event( - &mut self, - info: HeaderInfo, - iter: &mut dyn Iterator, - ) { - } - - /// Process an object header of `UnsignedInteger` values - fn handle_unsigned_integer( - &mut self, - info: HeaderInfo, - iter: &mut dyn Iterator, - ) { - } - - /// Process an object header of octet string values - fn handle_octet_string<'a>( - &mut self, - info: HeaderInfo, - iter: &'a mut dyn Iterator, - ) { - } - - /// Process a device attribute - fn handle_device_attribute(&mut self, info: HeaderInfo, attr: AnyAttribute) {} -} - pub(crate) fn handle_attribute( var: Variation, qualifier: QualifierCode, diff --git a/dnp3/src/master/mod.rs b/dnp3/src/master/mod.rs index bdefbc4e..23288f4b 100644 --- a/dnp3/src/master/mod.rs +++ b/dnp3/src/master/mod.rs @@ -3,12 +3,14 @@ pub use error::*; pub use file::*; pub use handler::*; pub use poll::PollHandle; +pub use read_handler::*; pub use request::*; mod association; mod error; mod file; mod handler; +mod read_handler; mod request; pub(crate) mod convert; diff --git a/dnp3/src/master/read_handler.rs b/dnp3/src/master/read_handler.rs new file mode 100644 index 00000000..a77a6ed8 --- /dev/null +++ b/dnp3/src/master/read_handler.rs @@ -0,0 +1,132 @@ +use crate::app::attr::AnyAttribute; +use crate::app::measurement::*; +use crate::app::{MaybeAsync, ResponseHeader}; +use crate::master::{HeaderInfo, ReadType}; + +/// Trait used to process measurement data received from an outstation +#[allow(unused_variables)] +pub trait ReadHandler: Send + Sync { + /// Called as the first action before any of the type-specific handle methods are invoked + /// + /// `read_type` provides information about what triggered the call, e.g. response vs unsolicited + /// `header` provides the full response header + /// + /// Note: The operation may or may not be async depending + fn begin_fragment(&mut self, read_type: ReadType, header: ResponseHeader) -> MaybeAsync<()> { + MaybeAsync::ready(()) + } + + /// Called as the last action after all the type-specific handle methods have been invoked + /// + /// `read_type` provides information about what triggered the call, e.g. response vs unsolicited + /// `header` provides the full response header + /// + /// Note: The operation may or may not be async depending. A typical use case for using async + /// here would be to publish a message to an async MPSC. + fn end_fragment(&mut self, read_type: ReadType, header: ResponseHeader) -> MaybeAsync<()> { + MaybeAsync::ready(()) + } + + /// Process an object header of `BinaryInput` values + fn handle_binary_input( + &mut self, + info: HeaderInfo, + iter: &mut dyn Iterator, + ) { + } + + /// Process an object header of `DoubleBitBinaryInput` values + fn handle_double_bit_binary_input( + &mut self, + info: HeaderInfo, + iter: &mut dyn Iterator, + ) { + } + + /// Process an object header of `BinaryOutputStatus` values + fn handle_binary_output_status( + &mut self, + info: HeaderInfo, + iter: &mut dyn Iterator, + ) { + } + + /// Process an object header of `Counter` values + fn handle_counter(&mut self, info: HeaderInfo, iter: &mut dyn Iterator) { + } + + /// Process an object header of `FrozenCounter` values + fn handle_frozen_counter( + &mut self, + info: HeaderInfo, + iter: &mut dyn Iterator, + ) { + } + + /// Process an object header of `AnalogInput` values + fn handle_analog_input( + &mut self, + info: HeaderInfo, + iter: &mut dyn Iterator, + ) { + } + + /// Process an object header of `FrozenAnalogInput` values + fn handle_frozen_analog_input( + &mut self, + info: HeaderInfo, + iter: &mut dyn Iterator, + ) { + } + + /// Process an object header of `AnalogInputDeadBand` values + fn handle_analog_input_dead_band( + &mut self, + info: HeaderInfo, + iter: &mut dyn Iterator, + ) { + } + + /// Process an object header of `AnalogOutputStatus` values + fn handle_analog_output_status( + &mut self, + info: HeaderInfo, + iter: &mut dyn Iterator, + ) { + } + + /// Process an object header of `AnalogOutputCommandEvent` values + fn handle_analog_output_command_event( + &mut self, + info: HeaderInfo, + iter: &mut dyn Iterator, + ) { + } + + /// Process an object header of `BinaryOutputCommandEvent` values + fn handle_binary_output_command_event( + &mut self, + info: HeaderInfo, + iter: &mut dyn Iterator, + ) { + } + + /// Process an object header of `UnsignedInteger` values + fn handle_unsigned_integer( + &mut self, + info: HeaderInfo, + iter: &mut dyn Iterator, + ) { + } + + /// Process an object header of octet string values + fn handle_octet_string<'a>( + &mut self, + info: HeaderInfo, + iter: &'a mut dyn Iterator, + ) { + } + + /// Process a device attribute + fn handle_device_attribute(&mut self, info: HeaderInfo, attr: AnyAttribute) {} +}