locka99 / opcua

A client and server implementation of the OPC UA specification written in Rust
Mozilla Public License 2.0
499 stars 131 forks source link

How to read the value in the AttrFnGetter closure #293

Closed firewave-remo closed 11 months ago

firewave-remo commented 12 months ago

Thanks for this awesome library! Way easier to use than others I have tried!

But currently, I hit a wall and I am not able to figure out how I get the underlying value inside the closure of AttrFnGetter (The getter to retrieve a value)

let getter = AttrFnGetter::new(
        move |node_id, timestamps_to_return, attribute_id, index_range, data_encoding, max_age| -> std::result::Result<Option<DataValue>, StatusCode> {

          println!("In Getter");
          dbg!(address_space_clone.is_locked()); // address space is already locked here. So i am not able to retrieve the value
          let mut address_space = address_space.write();
          if let Some(node) = address_space.find_variable(node_id) {
            let data_value = node.value(timestamps_to_return, index_range, data_encoding, max_age);
            // apply some transformations to the value and return it
          }
        },

I would like to apply some transformations to the value and then return it. Is there a possibility i am missing? Unfortunately the simple_server example does not show how to get the value. It does only show how to create a new value and return this value.

firewave-remo commented 11 months ago

Closing this, as i thought the Getter and Setter act more like an interceptor. But as i was digging through the code of this and other repos, it turns out that these are mostly used for when you have to get a value from other systems.

I would still be cool to have interceptors for getting and setting the value.