11:50, EEST
October 9, 2020
Hello,
In the migration guide : ‘The old enumeration types AccessLevel, EventNotifiedClass and WriteAccess that were used as EnumSets in practice, are removed and replaced by new “OptionSet” types AccessLevelType, EventNotifierType and AttributeWriteMask, respectively.’
Could you please provide update of example code for the MyIoManagerListener class?
For example, in the java SDK server documentation, WriteAccess is still present in GetUserWriteMask method :
@Override
public EnumSet onGetUserWriteMask(ServiceContext serviceContext, NodeId nodeId, UaNode node) {
// Enable writing to everything that is allowed by default
// The WriteMask defines the writable attributes, except for Value,
// which is controlled by UserAccessLevel (above)
// The following would deny write access for anonymous users:
// if
// (serviceContext.getSession().getUserIdentity().getType().equals(
// UserTokenType.Anonymous))
// return EnumSet.noneOf(WriteAccess.class);
return EnumSet.allOf(WriteAccess.class);
}
Thanks in advance.
12:44, EEST
April 3, 2012
Hi,
Sorry, seems we forgot to update that part (at some point in the future I hopefully manage to upgrade manual generation to produce via some comment tags vs. copy-pasting …).
However, in most cases you should have the distribution zip of SDK 4.x if you are reading the migration guide and thus you should be able to look at the updated code directly from the examples (sampleconsoleserver, MyIoManagerListener). But just in case also below (though, note that this forum is not exactly the best displaying these, i.e. indentations will fail, we should do something about that at some point):
public class MyIoManagerListener implements IoManagerListener {
private static Logger logger = LoggerFactory.getLogger(MyIoManagerListener.class);
@Override
public AccessLevelType onGetUserAccessLevel(ServiceContext serviceContext, NodeId nodeId, UaVariable node) {
// The AccessLevel defines the accessibility of the Variable.Value
// attribute
// Define anonymous access
// if (serviceContext.getSession().getUserIdentity().getType()
// .equals(UserTokenType.Anonymous))
// return AccessLevelType.of();
if (node.getHistorizing()) {
return AccessLevelType.of(AccessLevelType.CurrentRead, AccessLevelType.CurrentWrite, AccessLevelType.HistoryRead);
} else {
return AccessLevelType.of(AccessLevelType.CurrentRead, AccessLevelType.CurrentWrite);
}
}
@Override
public Boolean onGetUserExecutable(ServiceContext serviceContext, NodeId nodeId, UaMethod node) {
// Enable execution of all methods that are allowed by default
return true;
}
@Override
public AttributeWriteMask onGetUserWriteMask(ServiceContext serviceContext, NodeId nodeId, UaNode node) {
// Enable writing to everything that is allowed by default
// The WriteMask defines the writable attributes, except for Value,
// which is controlled by UserAccessLevel (above)
// The following would deny write access for anonymous users:
// if
// (serviceContext.getSession().getUserIdentity().getType().equals(
// UserTokenType.Anonymous))
// return AttributeWriteMask.of();
return AttributeWriteMask.of(AttributeWriteMask.Fields.values());
}
@Override
public boolean onReadNonValue(ServiceContext serviceContext, NodeId nodeId, UaNode node, UnsignedInteger attributeId,
DataValue dataValue) throws StatusException {
return false;
}
@Override
public boolean onReadValue(ServiceContext serviceContext, NodeId nodeId, UaValueNode node, NumericRange indexRange,
TimestampsToReturn timestampsToReturn, DateTime minTimestamp, DataValue dataValue) throws StatusException {
if (logger.isDebugEnabled()) {
logger.debug("onReadValue: nodeId=" + nodeId + (node != null ? " node=" + node.getBrowseName() : ""));
}
return false;
}
@Override
public boolean onWriteNonValue(ServiceContext serviceContext, NodeId nodeId, UaNode node, UnsignedInteger attributeId,
DataValue dataValue) throws StatusException {
return false;
}
@Override
public boolean onWriteValue(ServiceContext serviceContext, NodeId nodeId, UaValueNode node, NumericRange indexRange,
DataValue dataValue) throws StatusException {
logger.info("onWriteValue: nodeId=" + nodeId + (node != null ? " node=" + node.getBrowseName() : "")
+ (indexRange != null ? " indexRange=" + indexRange : "") + " value=" + dataValue);
return false;
}
}
Each of those “OptionSet-like” types that are subtype of some unsigned integer type also have a nested Fields enum that are similar to the old enums. You can use toSet() on the type to get a set of the fields enums and you can use the static factory method XXX.of(XXX.Fields…) and equivalents to construct one from a set of Field enum values.
It should be noted that previously those types were the raw unsigned integer types (in the OPC UA Specification, Attribute value types), in 1.04 they are of the subtypes, but the change is binary-compatible, since all subtypes of simple built-in types are encoded as the build-in type. Since it is now a proper type, I preferably wanted to generate a proper scalar type (immutablity vs. Enumset is also a plus), but the XXX.Fields is also included to have nicer bitfield-style API of sorts. Additionally SDK contained those enum types previously as a custom solution, but there was also the generated types (as they are now proper types in the address space), so to avoid confusion it was better (hopefully) this time to just remove the SDK custom solution.
Most Users Ever Online: 1919
Currently Online:
30 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Heikki Tahvanainen: 402
hbrackel: 144
rocket science: 88
pramanj: 86
Francesco Zambon: 83
Ibrahim: 78
Sabari: 62
kapsl: 57
gjevremovic: 49
Xavier: 43
Member Stats:
Guest Posters: 0
Members: 727
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1529
Posts: 6471
Newest Members:
kourtneyquisenbe, ellis87832073466, zkxwilliemae, gabriellabachus, Deakin, KTP25Zof, Wojciech Kubala, efrennowell431, wilfredostuart, caitlynfajardoModerators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1032, Jimmy Ni: 26, Matti Siponen: 349, Lusetti: 0
Administrators: admin: 1