Skip to content

Commit

Permalink
move ReadHandler in its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
jadamcrain committed May 20, 2024
1 parent 237916a commit b1b4cf4
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 131 deletions.
2 changes: 1 addition & 1 deletion dnp3/src/master/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
131 changes: 1 addition & 130 deletions dnp3/src/master/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<Item = (BinaryInput, u16)>,
) {
}

/// Process an object header of `DoubleBitBinaryInput` values
fn handle_double_bit_binary_input(
&mut self,
info: HeaderInfo,
iter: &mut dyn Iterator<Item = (DoubleBitBinaryInput, u16)>,
) {
}

/// Process an object header of `BinaryOutputStatus` values
fn handle_binary_output_status(
&mut self,
info: HeaderInfo,
iter: &mut dyn Iterator<Item = (BinaryOutputStatus, u16)>,
) {
}

/// Process an object header of `Counter` values
fn handle_counter(&mut self, info: HeaderInfo, iter: &mut dyn Iterator<Item = (Counter, u16)>) {
}

/// Process an object header of `FrozenCounter` values
fn handle_frozen_counter(
&mut self,
info: HeaderInfo,
iter: &mut dyn Iterator<Item = (FrozenCounter, u16)>,
) {
}

/// Process an object header of `AnalogInput` values
fn handle_analog_input(
&mut self,
info: HeaderInfo,
iter: &mut dyn Iterator<Item = (AnalogInput, u16)>,
) {
}

/// Process an object header of `FrozenAnalogInput` values
fn handle_frozen_analog_input(
&mut self,
info: HeaderInfo,
iter: &mut dyn Iterator<Item = (FrozenAnalogInput, u16)>,
) {
}

/// Process an object header of `AnalogInputDeadBand` values
fn handle_analog_input_dead_band(
&mut self,
info: HeaderInfo,
iter: &mut dyn Iterator<Item = (AnalogInputDeadBand, u16)>,
) {
}

/// Process an object header of `AnalogOutputStatus` values
fn handle_analog_output_status(
&mut self,
info: HeaderInfo,
iter: &mut dyn Iterator<Item = (AnalogOutputStatus, u16)>,
) {
}

/// Process an object header of `AnalogOutputCommandEvent` values
fn handle_analog_output_command_event(
&mut self,
info: HeaderInfo,
iter: &mut dyn Iterator<Item = (AnalogOutputCommandEvent, u16)>,
) {
}

/// Process an object header of `BinaryOutputCommandEvent` values
fn handle_binary_output_command_event(
&mut self,
info: HeaderInfo,
iter: &mut dyn Iterator<Item = (BinaryOutputCommandEvent, u16)>,
) {
}

/// Process an object header of `UnsignedInteger` values
fn handle_unsigned_integer(
&mut self,
info: HeaderInfo,
iter: &mut dyn Iterator<Item = (UnsignedInteger, u16)>,
) {
}

/// Process an object header of octet string values
fn handle_octet_string<'a>(
&mut self,
info: HeaderInfo,
iter: &'a mut dyn Iterator<Item = (&'a [u8], u16)>,
) {
}

/// Process a device attribute
fn handle_device_attribute(&mut self, info: HeaderInfo, attr: AnyAttribute) {}
}

pub(crate) fn handle_attribute(
var: Variation,
qualifier: QualifierCode,
Expand Down
2 changes: 2 additions & 0 deletions dnp3/src/master/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
132 changes: 132 additions & 0 deletions dnp3/src/master/read_handler.rs
Original file line number Diff line number Diff line change
@@ -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<Item = (BinaryInput, u16)>,
) {
}

/// Process an object header of `DoubleBitBinaryInput` values
fn handle_double_bit_binary_input(
&mut self,
info: HeaderInfo,
iter: &mut dyn Iterator<Item = (DoubleBitBinaryInput, u16)>,
) {
}

/// Process an object header of `BinaryOutputStatus` values
fn handle_binary_output_status(
&mut self,
info: HeaderInfo,
iter: &mut dyn Iterator<Item = (BinaryOutputStatus, u16)>,
) {
}

/// Process an object header of `Counter` values
fn handle_counter(&mut self, info: HeaderInfo, iter: &mut dyn Iterator<Item = (Counter, u16)>) {
}

/// Process an object header of `FrozenCounter` values
fn handle_frozen_counter(
&mut self,
info: HeaderInfo,
iter: &mut dyn Iterator<Item = (FrozenCounter, u16)>,
) {
}

/// Process an object header of `AnalogInput` values
fn handle_analog_input(
&mut self,
info: HeaderInfo,
iter: &mut dyn Iterator<Item = (AnalogInput, u16)>,
) {
}

/// Process an object header of `FrozenAnalogInput` values
fn handle_frozen_analog_input(
&mut self,
info: HeaderInfo,
iter: &mut dyn Iterator<Item = (FrozenAnalogInput, u16)>,
) {
}

/// Process an object header of `AnalogInputDeadBand` values
fn handle_analog_input_dead_band(
&mut self,
info: HeaderInfo,
iter: &mut dyn Iterator<Item = (AnalogInputDeadBand, u16)>,
) {
}

/// Process an object header of `AnalogOutputStatus` values
fn handle_analog_output_status(
&mut self,
info: HeaderInfo,
iter: &mut dyn Iterator<Item = (AnalogOutputStatus, u16)>,
) {
}

/// Process an object header of `AnalogOutputCommandEvent` values
fn handle_analog_output_command_event(
&mut self,
info: HeaderInfo,
iter: &mut dyn Iterator<Item = (AnalogOutputCommandEvent, u16)>,
) {
}

/// Process an object header of `BinaryOutputCommandEvent` values
fn handle_binary_output_command_event(
&mut self,
info: HeaderInfo,
iter: &mut dyn Iterator<Item = (BinaryOutputCommandEvent, u16)>,
) {
}

/// Process an object header of `UnsignedInteger` values
fn handle_unsigned_integer(
&mut self,
info: HeaderInfo,
iter: &mut dyn Iterator<Item = (UnsignedInteger, u16)>,
) {
}

/// Process an object header of octet string values
fn handle_octet_string<'a>(
&mut self,
info: HeaderInfo,
iter: &'a mut dyn Iterator<Item = (&'a [u8], u16)>,
) {
}

/// Process a device attribute
fn handle_device_attribute(&mut self, info: HeaderInfo, attr: AnyAttribute) {}
}

0 comments on commit b1b4cf4

Please sign in to comment.