Skip to content

Commit

Permalink
Move events and type trees to the nodes crate (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
einarmo authored Sep 4, 2024
1 parent 632f71c commit 715daf0
Show file tree
Hide file tree
Showing 29 changed files with 88 additions and 102 deletions.
4 changes: 3 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/tests/integration/browse.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::utils::setup;
use opcua::{
nodes::TypeTree,
server::address_space::{ObjectBuilder, ReferenceDirection, VariableBuilder},
server::node_manager::TypeTree,
types::{
BrowseDescription, BrowseDirection, BrowsePath, BrowseResultMask, ByteString, DataTypeId,
NodeClass, NodeClassMask, NodeId, ObjectId, ObjectTypeId, ReferenceTypeId, RelativePath,
Expand Down
7 changes: 4 additions & 3 deletions lib/tests/utils/node_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use opcua::{
InMemoryNodeManager, InMemoryNodeManagerBuilder, InMemoryNodeManagerImpl,
NamespaceMetadata,
},
AddNodeItem, AddReferenceItem, DefaultTypeTree, DeleteNodeItem, DeleteReferenceItem,
HistoryNode, HistoryUpdateNode, MethodCall, MonitoredItemRef, MonitoredItemUpdateRef,
AddNodeItem, AddReferenceItem, DeleteNodeItem, DeleteReferenceItem, HistoryNode,
HistoryUpdateNode, MethodCall, MonitoredItemRef, MonitoredItemUpdateRef,
NodeManagerBuilder, NodeManagersRef, ParsedReadValueId, RequestContext, ServerContext,
TypeTree, TypeTreeNode, WriteNode,
WriteNode,
},
ContinuationPoint, CreateMonitoredItem,
},
Expand All @@ -27,6 +27,7 @@ use opcua::{
},
};
use opcua_core::{trace_read_lock, trace_write_lock};
use opcua_nodes::{DefaultTypeTree, TypeTree, TypeTreeNode};
use opcua_server::address_space::add_namespaces;

#[allow(unused)]
Expand Down
2 changes: 1 addition & 1 deletion opcua-macros/src/events/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn generate_event_field_impls(event: EventFieldStruct) -> syn::Result<TokenS
}

Ok(quote! {
impl opcua::server::EventField for #ident {
impl opcua::nodes::EventField for #ident {
fn get_value(
&self,
attribute_id: opcua::types::AttributeId,
Expand Down
6 changes: 3 additions & 3 deletions opcua-macros/src/events/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ pub fn generate_event_impls(event: EventStruct) -> syn::Result<TokenStream> {
}

Ok(quote! {
impl opcua::server::Event for #ident {
impl opcua::nodes::Event for #ident {
fn get_field(
&self,
type_definition_id: &opcua::types::NodeId,
attribute_id: opcua::types::AttributeId,
index_range: opcua::types::NumericRange,
browse_path: &[opcua::types::QualifiedName],
) -> opcua::types::Variant {
use opcua::server::EventField;
use opcua::nodes::EventField;

if type_definition_id != &opcua::types::ObjectTypeId::BaseEventType && !{
#type_id_body
Expand All @@ -151,7 +151,7 @@ pub fn generate_event_impls(event: EventStruct) -> syn::Result<TokenStream> {
}
}

impl opcua::server::EventField for #ident {
impl opcua::nodes::EventField for #ident {
fn get_value(
&self,
attribute_id: opcua::types::AttributeId,
Expand Down
3 changes: 3 additions & 0 deletions opcua-nodes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ name = "opcua_nodes"

[dependencies]
bitflags = { workspace = true }
hashbrown = { workspace = true }
log = { workspace = true }
regex = { workspace = true }

opcua-types = { path = "../opcua-types" }
opcua-macros = { path = "../opcua-macros" }

Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,11 @@ mod tests {
use regex::Regex;

use crate::{
address_space::{AddressSpace, CoreNamespace, ObjectTypeBuilder, VariableBuilder},
events::evaluate::like_to_regex,
node_manager::DefaultTypeTree,
BaseEventType, Event, ParsedContentFilter,
events::evaluate::like_to_regex, BaseEventType, DefaultTypeTree, Event, ParsedContentFilter,
};
use opcua_types::{
AttributeId, ByteString, ContentFilter, ContentFilterElement, DataTypeId, DateTime,
FilterOperator, LocalizedText, NodeId, ObjectId, ObjectTypeId, Operand, UAString,
VariableTypeId,
AttributeId, ByteString, ContentFilter, ContentFilterElement, DateTime, FilterOperator,
LocalizedText, NodeClass, NodeId, ObjectTypeId, Operand, UAString,
};

fn compare_regex(r1: Regex, r2: Regex) {
Expand Down Expand Up @@ -457,8 +453,7 @@ mod tests {
}

mod opcua {
pub use crate as server;
pub use opcua_nodes as nodes;
pub use crate as nodes;
pub use opcua_types as types;
}

Expand Down Expand Up @@ -487,28 +482,20 @@ mod tests {
}

fn type_tree() -> DefaultTypeTree {
let mut address_space = AddressSpace::new();
let mut type_tree = DefaultTypeTree::new();
address_space.import_node_set::<CoreNamespace>(type_tree.namespaces_mut());
address_space.add_namespace(
"my:namespace:uri",
type_tree.namespaces_mut().add_namespace("my:namespace:uri"),
);

let event_type_id = NodeId::new(1, 123);
ObjectTypeBuilder::new(&event_type_id, "TestEventType", "TestEventType")
.is_abstract(false)
.subtype_of(ObjectTypeId::BaseEventType)
.insert(&mut address_space);

VariableBuilder::new(&NodeId::new(1, "field"), "Field", "Field")
.property_of(&event_type_id)
.data_type(DataTypeId::UInt32)
.has_type_definition(VariableTypeId::PropertyType)
.has_modelling_rule(ObjectId::ModellingRule_Mandatory)
.insert(&mut address_space);

address_space.load_into_type_tree(&mut type_tree);
type_tree.add_type_node(
&event_type_id,
&ObjectTypeId::BaseEventType.into(),
NodeClass::ObjectType,
);
type_tree.add_type_property(
&NodeId::new(1, "field"),
&event_type_id,
&[&"Field".into()],
NodeClass::Variable,
);

type_tree
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use opcua_nodes::NamespaceMap;
use crate::NamespaceMap;
use opcua_types::{
event_field::EventField, AttributeId, ByteString, DateTime, LocalizedText, NodeId,
NumericRange, ObjectTypeId, QualifiedName, TimeZoneDataType, UAString, Variant,
Expand Down Expand Up @@ -186,20 +186,17 @@ impl BaseEventType {

#[cfg(test)]
mod tests {
use opcua_crypto::random;
use opcua_macros::EventField;
use opcua_nodes::NamespaceMap;
use crate::NamespaceMap;

mod opcua {
pub use crate as server;
pub use opcua_nodes as nodes;
pub use crate as nodes;
pub use opcua_types as types;
}

use crate::{BaseEventType, Event};
use crate::{BaseEventType, Event, EventField};
use opcua_types::{
AttributeId, DecodingOptions, EUInformation, KeyValuePair, LocalizedText, NodeId,
NumericRange, ObjectTypeId, QualifiedName, StatusCode, UAString, Variant,
AttributeId, ByteString, DecodingOptions, EUInformation, KeyValuePair, LocalizedText,
NodeId, NumericRange, ObjectTypeId, QualifiedName, StatusCode, UAString, Variant,
};
#[derive(Event)]
#[opcua(identifier = "s=myevent", namespace = "uri:my:namespace")]
Expand Down Expand Up @@ -243,7 +240,7 @@ mod tests {
let namespaces = namespace_map();
let mut evt = BasicValueEvent::new_event_now(
BasicValueEvent::event_type_id(&namespaces),
random::byte_string(128),
ByteString::from_base64("dGVzdA==").unwrap(),
"Some message",
&namespaces,
);
Expand Down Expand Up @@ -381,7 +378,7 @@ mod tests {
let namespaces = namespace_map();
let mut evt = NestedEvent::new_event_now(
NestedEvent::event_type_id(&namespaces),
random::byte_string(128),
ByteString::from_base64("dGVzdA==").unwrap(),
"Some message",
&namespaces,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ mod event;
mod evaluate;
mod validation;

pub use evaluate::AttributeQueryable;
pub use event::{BaseEventType, Event};
pub use opcua_types::event_field::EventField;
pub use validation::{
ParsedAttributeOperand, ParsedContentFilter, ParsedContentFilterElement, ParsedEventFilter,
ParsedOperand, ParsedSimpleAttributeOperand,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use opcua_types::{
StatusCode, UAString,
};

use crate::node_manager::TypeTree;
use crate::TypeTree;

#[derive(Debug, Clone)]
pub struct ParsedAttributeOperand {
Expand Down Expand Up @@ -105,7 +105,7 @@ impl ParsedContentFilter {
}
}

pub(crate) fn parse(
pub fn parse(
filter: ContentFilter,
type_tree: &dyn TypeTree,
allow_attribute_operand: bool,
Expand Down Expand Up @@ -437,7 +437,7 @@ fn has_cycles(

#[cfg(test)]
mod tests {
use crate::{events::validation::validate_where_clause, node_manager::DefaultTypeTree};
use crate::{events::validation::validate_where_clause, DefaultTypeTree};
use opcua_types::{
AttributeId, ContentFilter, ContentFilterElement, ContentFilterResult, FilterOperator,
NodeClass, NodeId, ObjectTypeId, Operand, SimpleAttributeOperand, StatusCode,
Expand Down
8 changes: 8 additions & 0 deletions opcua-nodes/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use bitflags::bitflags;

mod events;
mod generic;
mod import;
mod namespaces;
mod type_tree;

pub use base::Base;
pub use data_type::{DataType, DataTypeBuilder};
pub use events::*;
pub use generic::new_node_from_attributes;
pub use import::{ImportedItem, ImportedReference, NodeSetImport, NodeSetNamespaceMapper};
pub use method::{Method, MethodBuilder};
Expand All @@ -15,10 +18,15 @@ pub use object::{Object, ObjectBuilder};
pub use object_type::{ObjectType, ObjectTypeBuilder};
use opcua_types::NodeId;
pub use reference_type::{ReferenceType, ReferenceTypeBuilder};
pub use type_tree::{
DefaultTypeTree, TypeProperty, TypePropertyInverseRef, TypeTree, TypeTreeNode,
};
pub use variable::{Variable, VariableBuilder};
pub use variable_type::{VariableType, VariableTypeBuilder};
pub use view::{View, ViewBuilder};

pub use opcua_macros::{Event, EventField};

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum ReferenceDirection {
Forward,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
collections::{HashMap, HashSet},
};

use opcua_nodes::NamespaceMap;
use crate::NamespaceMap;
use opcua_types::{
DataTypeId, NodeClass, NodeId, ObjectTypeId, QualifiedName, ReferenceTypeId, VariableTypeId,
};
Expand Down
1 change: 0 additions & 1 deletion opcua-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ opcua-types = { path = "../opcua-types" }
opcua-crypto = { path = "../opcua-crypto" }
opcua-core = { path = "../opcua-core" }
opcua-nodes = { path = "../opcua-nodes" }
opcua-macros = { path = "../opcua-macros" }

opcua-client = { path = "../opcua-client", optional = true }
opcua-core-namespace = { path = "../opcua-core-namespace", optional = true }
Expand Down
17 changes: 6 additions & 11 deletions opcua-server/src/address_space/address_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ use std::collections::VecDeque;

use hashbrown::{Equivalent, HashMap, HashSet};
use log::{debug, error, info, warn};
use opcua_nodes::{NamespaceMap, NodeInsertTarget, ReferenceDirection};
use opcua_nodes::{DefaultTypeTree, NamespaceMap, NodeInsertTarget, ReferenceDirection, TypeTree};

use crate::node_manager::{
DefaultTypeTree, ParsedReadValueId, ParsedWriteValue, RequestContext, TypeTree,
};
use crate::node_manager::{ParsedReadValueId, ParsedWriteValue, RequestContext};
use opcua_types::{
BrowseDirection, DataValue, LocalizedText, NodeClass, NodeId, QualifiedName, ReferenceTypeId,
StatusCode, TimestampsToReturn,
Expand Down Expand Up @@ -852,14 +850,11 @@ impl NodeInsertTarget for AddressSpace {

#[cfg(test)]
mod tests {
use crate::{
address_space::{
CoreNamespace, EventNotifier, MethodBuilder, NodeBase, NodeType, Object, ObjectBuilder,
ObjectTypeBuilder, Variable, VariableBuilder,
},
node_manager::{DefaultTypeTree, TypeTree},
use crate::address_space::{
CoreNamespace, EventNotifier, MethodBuilder, NodeBase, NodeType, Object, ObjectBuilder,
ObjectTypeBuilder, Variable, VariableBuilder,
};
use opcua_nodes::NamespaceMap;
use opcua_nodes::{DefaultTypeTree, NamespaceMap, TypeTree};
use opcua_types::{
argument::Argument, Array, BrowseDirection, DataTypeId, DecodingOptions, LocalizedText,
NodeClass, NodeId, NumericRange, ObjectId, ObjectTypeId, QualifiedName, ReferenceTypeId,
Expand Down
5 changes: 2 additions & 3 deletions opcua-server/src/address_space/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::node_manager::{
ParsedReadValueId, ParsedWriteValue, RequestContext, ServerContext, TypeTree,
};
use crate::node_manager::{ParsedReadValueId, ParsedWriteValue, RequestContext, ServerContext};
use log::debug;
use opcua_nodes::TypeTree;
use opcua_types::{
AttributeId, DataTypeId, DataValue, NumericRange, QualifiedName, StatusCode,
TimestampsToReturn, Variant, WriteMask,
Expand Down
2 changes: 1 addition & 1 deletion opcua-server/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::sync::Arc;

use arc_swap::ArcSwap;
use log::{debug, error, warn};
use opcua_nodes::DefaultTypeTree;

use crate::authenticator::Password;
use crate::node_manager::TypeTreeForUser;
Expand Down Expand Up @@ -37,7 +38,6 @@ use super::identity_token::{
IdentityToken, POLICY_ID_ANONYMOUS, POLICY_ID_USER_PASS_NONE, POLICY_ID_USER_PASS_RSA_15,
POLICY_ID_USER_PASS_RSA_OAEP, POLICY_ID_X509,
};
use super::node_manager::DefaultTypeTree;
use super::{OperationalLimits, ServerCapabilities, ANONYMOUS_USER_TOKEN_ID};

/// Server state is any configuration associated with the server as a whole that individual sessions might
Expand Down
4 changes: 0 additions & 4 deletions opcua-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mod builder;
mod config;
#[cfg(feature = "discovery-server-registration")]
mod discovery;
pub mod events;
mod identity_token;
mod info;
pub mod node_manager;
Expand All @@ -17,7 +16,6 @@ mod transport;

pub use builder::ServerBuilder;
pub use config::*;
pub use events::*;
pub use opcua_types::event_field::EventField;
pub use server::Server;
pub use server_handle::ServerHandle;
Expand All @@ -28,8 +26,6 @@ pub use subscriptions::{
SubscriptionCache, SubscriptionState,
};

pub use opcua_macros::{Event, EventField};

/// Contains constaints for default configuration values.
/// These are for the most part possible to override through server configuration.
pub mod constants {
Expand Down
Loading

0 comments on commit 715daf0

Please sign in to comment.