use of org.eclipse.milo.opcua.stack.core.types.builtin.DataValue in project milo by eclipse.
the class DataTypeDictionaryManager method registerStructureDescription.
public void registerStructureDescription(StructureDescription description, NodeId binaryEncodingId) {
structureDescriptions.put(description.getDataTypeId(), description);
// Add a DataTypeDescriptionTypeNode with a ComponentOf reference to
// dictionaryNode.
DataTypeDescriptionTypeNode descriptionNode = new DataTypeDescriptionTypeNode(getNodeContext(), newNodeId(String.format("%s.Description", description.getName())), newQualifiedName(description.getName().getName()), LocalizedText.english(description.getName().getName()), LocalizedText.NULL_VALUE, uint(0), uint(0));
descriptionNode.setValue(new DataValue(new Variant(description.getName().getName())));
descriptionNode.setDataType(Identifiers.String);
descriptionNode.addReference(new Reference(descriptionNode.getNodeId(), Identifiers.HasTypeDefinition, Identifiers.DataTypeDescriptionType.expanded(), Direction.FORWARD));
descriptionNode.addReference(new Reference(descriptionNode.getNodeId(), Identifiers.HasComponent, dictionaryNode.getNodeId().expanded(), Direction.INVERSE));
addNode(descriptionNode);
// Add a DataTypeEncodingTypeNode with a HasDescription reference to
// descriptionNode and an EncodingOf reference to the DataTypeNode.
DataTypeEncodingTypeNode dataTypeEncodingNode = new DataTypeEncodingTypeNode(getNodeContext(), binaryEncodingId, new QualifiedName(0, "Default Binary"), LocalizedText.english("Default Binary"), LocalizedText.NULL_VALUE, uint(0), uint(0));
dataTypeEncodingNode.addReference(new Reference(dataTypeEncodingNode.getNodeId(), Identifiers.HasTypeDefinition, Identifiers.DataTypeEncodingType.expanded(), Direction.FORWARD));
dataTypeEncodingNode.addReference(new Reference(dataTypeEncodingNode.getNodeId(), Identifiers.HasDescription, descriptionNode.getNodeId().expanded(), Direction.FORWARD));
dataTypeEncodingNode.addReference(new Reference(dataTypeEncodingNode.getNodeId(), Identifiers.HasEncoding, description.getDataTypeId().expanded(), Direction.INVERSE));
addNode(dataTypeEncodingNode);
dictionaryFile.reset();
}
use of org.eclipse.milo.opcua.stack.core.types.builtin.DataValue in project milo by eclipse.
the class DataTypeDictionaryReader method readDataTypeDescriptionValues.
private CompletableFuture<List<String>> readDataTypeDescriptionValues(List<NodeId> nodeIds) {
CompletableFuture<UInteger> maxNodesPerRead = readNode(new ReadValueId(Identifiers.Server_ServerCapabilities_OperationLimits_MaxNodesPerRead, AttributeId.Value.uid(), null, QualifiedName.NULL_VALUE)).thenApply(dv -> (UInteger) dv.getValue().getValue());
CompletableFuture<Integer> getPartitionSize = maxNodesPerRead.thenApply(m -> Math.max(1, Ints.saturatedCast(m.longValue()))).exceptionally(ex -> PARTITION_SIZE);
return getPartitionSize.thenCompose(partitionSize -> {
List<List<NodeId>> partitions = Lists.partition(nodeIds, partitionSize);
CompletableFuture<List<List<DataValue>>> sequence = FutureUtils.sequence(partitions.stream().map(list -> {
List<ReadValueId> readValueIds = list.stream().map(nodeId -> new ReadValueId(nodeId, AttributeId.Value.uid(), null, QualifiedName.NULL_VALUE)).collect(Collectors.toList());
return readNodes(readValueIds);
}));
return sequence.thenApply(values -> values.stream().flatMap(List::stream).map(v -> (String) v.getValue().getValue()).collect(Collectors.toList()));
});
}
use of org.eclipse.milo.opcua.stack.core.types.builtin.DataValue in project milo by eclipse.
the class ExampleNamespace method addDynamicNodes.
private void addDynamicNodes(UaFolderNode rootNode) {
UaFolderNode dynamicFolder = new UaFolderNode(getNodeContext(), newNodeId("HelloWorld/Dynamic"), newQualifiedName("Dynamic"), LocalizedText.english("Dynamic"));
getNodeManager().addNode(dynamicFolder);
rootNode.addOrganizes(dynamicFolder);
// Dynamic Boolean
{
String name = "Boolean";
NodeId typeId = Identifiers.Boolean;
Variant variant = new Variant(false);
UaVariableNode node = new UaVariableNode.UaVariableNodeBuilder(getNodeContext()).setNodeId(newNodeId("HelloWorld/Dynamic/" + name)).setAccessLevel(AccessLevel.READ_WRITE).setBrowseName(newQualifiedName(name)).setDisplayName(LocalizedText.english(name)).setDataType(typeId).setTypeDefinition(Identifiers.BaseDataVariableType).build();
node.setValue(new DataValue(variant));
node.getFilterChain().addLast(new AttributeLoggingFilter(), AttributeFilters.getValue(ctx -> new DataValue(new Variant(random.nextBoolean()))));
getNodeManager().addNode(node);
dynamicFolder.addOrganizes(node);
}
// Dynamic Int32
{
String name = "Int32";
NodeId typeId = Identifiers.Int32;
Variant variant = new Variant(0);
UaVariableNode node = new UaVariableNode.UaVariableNodeBuilder(getNodeContext()).setNodeId(newNodeId("HelloWorld/Dynamic/" + name)).setAccessLevel(AccessLevel.READ_WRITE).setBrowseName(newQualifiedName(name)).setDisplayName(LocalizedText.english(name)).setDataType(typeId).setTypeDefinition(Identifiers.BaseDataVariableType).build();
node.setValue(new DataValue(variant));
node.getFilterChain().addLast(new AttributeLoggingFilter(), AttributeFilters.getValue(ctx -> new DataValue(new Variant(random.nextInt()))));
getNodeManager().addNode(node);
dynamicFolder.addOrganizes(node);
}
// Dynamic Double
{
String name = "Double";
NodeId typeId = Identifiers.Double;
Variant variant = new Variant(0.0);
UaVariableNode node = new UaVariableNode.UaVariableNodeBuilder(getNodeContext()).setNodeId(newNodeId("HelloWorld/Dynamic/" + name)).setAccessLevel(AccessLevel.READ_WRITE).setBrowseName(newQualifiedName(name)).setDisplayName(LocalizedText.english(name)).setDataType(typeId).setTypeDefinition(Identifiers.BaseDataVariableType).build();
node.setValue(new DataValue(variant));
node.getFilterChain().addLast(new AttributeLoggingFilter(), AttributeFilters.getValue(ctx -> new DataValue(new Variant(random.nextDouble()))));
getNodeManager().addNode(node);
dynamicFolder.addOrganizes(node);
}
}
use of org.eclipse.milo.opcua.stack.core.types.builtin.DataValue in project milo by eclipse.
the class ExampleNamespace method addCustomUnionTypeVariable.
private void addCustomUnionTypeVariable(UaFolderNode rootFolder) throws Exception {
NodeId dataTypeId = CustomUnionType.TYPE_ID.toNodeIdOrThrow(getServer().getNamespaceTable());
NodeId binaryEncodingId = CustomUnionType.BINARY_ENCODING_ID.toNodeIdOrThrow(getServer().getNamespaceTable());
UaVariableNode customUnionTypeVariable = UaVariableNode.builder(getNodeContext()).setNodeId(newNodeId("HelloWorld/CustomUnionTypeVariable")).setAccessLevel(AccessLevel.READ_WRITE).setUserAccessLevel(AccessLevel.READ_WRITE).setBrowseName(newQualifiedName("CustomUnionTypeVariable")).setDisplayName(LocalizedText.english("CustomUnionTypeVariable")).setDataType(dataTypeId).setTypeDefinition(Identifiers.BaseDataVariableType).build();
CustomUnionType value = CustomUnionType.ofBar("hello");
ExtensionObject xo = ExtensionObject.encodeDefaultBinary(getServer().getSerializationContext(), value, binaryEncodingId);
customUnionTypeVariable.setValue(new DataValue(new Variant(xo)));
getNodeManager().addNode(customUnionTypeVariable);
customUnionTypeVariable.addReference(new Reference(customUnionTypeVariable.getNodeId(), Identifiers.Organizes, rootFolder.getNodeId().expanded(), false));
}
use of org.eclipse.milo.opcua.stack.core.types.builtin.DataValue in project milo by eclipse.
the class ExampleNamespace method addAdminWritableNodes.
private void addAdminWritableNodes(UaFolderNode rootNode) {
UaFolderNode adminFolder = new UaFolderNode(getNodeContext(), newNodeId("HelloWorld/OnlyAdminCanWrite"), newQualifiedName("OnlyAdminCanWrite"), LocalizedText.english("OnlyAdminCanWrite"));
getNodeManager().addNode(adminFolder);
rootNode.addOrganizes(adminFolder);
String name = "String";
UaVariableNode node = new UaVariableNode.UaVariableNodeBuilder(getNodeContext()).setNodeId(newNodeId("HelloWorld/OnlyAdminCanWrite/" + name)).setAccessLevel(AccessLevel.READ_WRITE).setBrowseName(newQualifiedName(name)).setDisplayName(LocalizedText.english(name)).setDataType(Identifiers.String).setTypeDefinition(Identifiers.BaseDataVariableType).build();
node.setValue(new DataValue(new Variant("admin was here")));
node.getFilterChain().addLast(new RestrictedAccessFilter(identity -> {
if ("admin".equals(identity)) {
return AccessLevel.READ_WRITE;
} else {
return AccessLevel.READ_ONLY;
}
}));
getNodeManager().addNode(node);
adminFolder.addOrganizes(node);
}
Aggregations