Skip to content

Commit

Permalink
Move AttributeGetter and AttributeSetter callbacks into callbacks.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
locka99 committed Apr 13, 2019
1 parent 2838691 commit c8f5308
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 34 deletions.
6 changes: 3 additions & 3 deletions server/src/address_space/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use opcua_types::{
service_types::*,
};

use crate::address_space::{
{AttributeGetter, AttributeSetter},
node::Node,
use crate::{
callbacks::{AttributeGetter, AttributeSetter},
address_space::node::Node,
};

// This should match size of AttributeId
Expand Down
31 changes: 5 additions & 26 deletions server/src/address_space/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,7 @@ use std::result::Result;
use opcua_types::{NodeId, AttributeId, DataValue};
use opcua_types::status_code::StatusCode;

/// An attribute getter trait is used to obtain the data value associated with the particular attribute id
/// This allows server implementations to supply a value on demand, usually in response to a polling action
/// such as a monitored item in a subscription.
///
/// `node_id` is the node to which the node belongs
/// `attribute_id` is the attribute of the node to fetch a value for
///
/// Use `max_age` according to the OPC UA Part 4, Table 52 specification to determine how to return
/// a value:
///
/// * 0 = a new value
/// * time in ms for a value less than the specified age
/// * i32::max() or higher to fetch a cached value.
///
pub trait AttributeGetter {
/// Returns some datavalue or none
fn get(&mut self, node_id: &NodeId, attribute_id: AttributeId, max_age: f64) -> Result<Option<DataValue>, StatusCode>;
}
use crate::callbacks::{AttributeGetter, AttributeSetter};

/// An implementation of attribute getter that can be easily constructed from a mutable function
pub struct AttrFnGetter<F> where F: FnMut(&NodeId, AttributeId, f64) -> Result<Option<DataValue>, StatusCode> + Send {
Expand All @@ -40,12 +23,6 @@ impl<F> AttrFnGetter<F> where F: FnMut(&NodeId, AttributeId, f64) -> Result<Opti
pub fn new(getter: F) -> AttrFnGetter<F> { AttrFnGetter { getter } }
}

// An attribute setter. Sets the value on the specified attribute
pub trait AttributeSetter {
/// Sets the attribute on the specified node
fn set(&mut self, node_id: &NodeId, attribute_id: AttributeId, data_value: DataValue) -> Result<(), StatusCode>;
}

/// An implementation of attribute setter that can be easily constructed using a mutable function
pub struct AttrFnSetter<F> where F: FnMut(&NodeId, AttributeId, DataValue) -> Result<(), StatusCode> + Send {
setter: F
Expand Down Expand Up @@ -133,8 +110,10 @@ pub mod data_type;
pub mod view;
mod references;

#[cfg(feature = "generated-address-space")] mod generated;
#[cfg(feature = "generated-address-space")] mod method_impls;
#[cfg(feature = "generated-address-space")]
mod generated;
#[cfg(feature = "generated-address-space")]
mod method_impls;

bitflags! {
pub struct AccessLevel: u8 {
Expand Down
12 changes: 7 additions & 5 deletions server/src/address_space/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ use std::convert::Into;

use opcua_types::node_ids::DataTypeId;

use crate::address_space::{
AttributeGetter, AttributeSetter,
AccessLevel, UserAccessLevel,
base::Base,
node::Node,
use crate::{
callbacks::{AttributeGetter, AttributeSetter},
address_space::{
AccessLevel, UserAccessLevel,
base::Base,
node::Node,
},
};
use opcua_types::service_types::VariableAttributes;

Expand Down
27 changes: 27 additions & 0 deletions server/src/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,39 @@ use std::sync::{Arc, RwLock};

use opcua_types::{
NodeId,
DataValue,
AttributeId,
status_code::StatusCode,
service_types::{CallMethodRequest, CallMethodResult},
};

use crate::session::Session;

/// An attribute getter trait is used to obtain the data value associated with the particular attribute id
/// This allows server implementations to supply a value on demand, usually in response to a polling action
/// such as a monitored item in a subscription.
///
/// `node_id` is the node to which the node belongs
/// `attribute_id` is the attribute of the node to fetch a value for
///
/// Use `max_age` according to the OPC UA Part 4, Table 52 specification to determine how to return
/// a value:
///
/// * 0 = a new value
/// * time in ms for a value less than the specified age
/// * i32::max() or higher to fetch a cached value.
///
pub trait AttributeGetter {
/// Returns some datavalue or none
fn get(&mut self, node_id: &NodeId, attribute_id: AttributeId, max_age: f64) -> Result<Option<DataValue>, StatusCode>;
}

// An attribute setter. Sets the value on the specified attribute
pub trait AttributeSetter {
/// Sets the attribute on the specified node
fn set(&mut self, node_id: &NodeId, attribute_id: AttributeId, data_value: DataValue) -> Result<(), StatusCode>;
}

/// Called by RegisterNodes service
pub trait RegisterNodes {
/// Called when a client calls the RegisterNodes service. This implementation should return a list
Expand Down

0 comments on commit c8f5308

Please sign in to comment.