C++ Based OPC UA Client/Server/PubSub SDK
1.7.9.586
|
Wrapper class for the UA stack structure OpcUa_NodeId. More...
#include <uanodeid.h>
Public Member Functions | |
UaNodeId () | |
Creates a null NodeId with NS=0, IdentifierType=Numeric, Identifier=0. More... | |
UaNodeId (const UaNodeId &other) | |
Constructs a copy of other. More... | |
UaNodeId (const OpcUa_NodeId &other) | |
Constructs a copy of the native OpcUa_NodeId structure. More... | |
UaNodeId (OpcUa_UInt32 id, OpcUa_UInt16 NsIdx=0) | |
Creates a new NodeId with a numeric identifier. More... | |
UaNodeId (const UaString &sId, OpcUa_UInt16 NsIdx) | |
Creates a new NodeId with a string identifier. More... | |
UaNodeId (const UaGuid &guid, OpcUa_UInt16 NsIdx) | |
Creates a new NodeId with a GUID identifier. More... | |
UaNodeId (const UaByteString &data, OpcUa_UInt16 NsIdx) | |
Creates a new NodeId with a ByteString identifier. More... | |
~UaNodeId () | |
Destroys the UaNodeId object. More... | |
OpcUa_Boolean | isNull () const |
Checks whether the NodeId is Null or not. More... | |
void | clear () |
Clears the content of the UaNodeId object and sets it to a null NodeId. More... | |
void | attach (const OpcUa_NodeId *pOther) |
Attaches to the native NodeId structure. More... | |
OpcUa_NodeId * | detach (OpcUa_NodeId *pDst) |
Detaches the internal NodeId structure from this class. More... | |
void | setNamespaceIndex (OpcUa_UInt16 NsIdx) |
Assigns a new namespace index to the NodeId. More... | |
void | setNodeId (OpcUa_UInt32 id, OpcUa_UInt16 NsIdx=0) |
Sets the NodeId with a numeric identifier and namespace index. More... | |
void | setNodeId (const UaString &sId, OpcUa_UInt16 NsIdx=1) |
Sets the NodeId with a string identifier and namespace index. More... | |
void | setNodeId (const UaGuid &id, OpcUa_UInt16 NsIdx) |
Sets the NodeId with a GUID identifier and namespace index. More... | |
void | setNodeId (const UaByteString &id, OpcUa_UInt16 NsIdx) |
Sets the NodeId with a ByteString identifier and namespace index. More... | |
operator const OpcUa_NodeId * () const | |
Returns the OpcUa_NodeId pointer to the internal data structure. More... | |
OpcUa_NodeId * | copy () const |
Allocates a NodeId structure and copies the internal NodeId. More... | |
void | copyTo (OpcUa_NodeId *pDst) const |
Copies the internal NodeId to an allocated and initialized NodeId structure. More... | |
UaNodeId & | operator= (const UaNodeId &other) |
Assigns another NodeId to the current instance. More... | |
bool | operator< (const UaNodeId &other) const |
Returns true if this NodeId is less than NodeId other; otherwise returns false. More... | |
bool | operator== (const UaNodeId &other) const |
Is equal operator for two NodeIds. More... | |
bool | operator!= (const UaNodeId &other) const |
Is not equal operator for two NodeIds. More... | |
bool | nodeIdCompare (OpcUa_NodeId *pNodeId) const |
Compares this NodeId with a NodeId structure and returns true if they are equal. More... | |
UaString | toString () const |
Converts the identifier of the NodeId to a UaString. More... | |
UaString | toFullString () const |
Converts all elements of a NodeId to a human readable string. More... | |
UaString | toXmlString () const |
Converts all elements of a NodeId to a string where the syntax is defined by the OPC UA XML Schema. More... | |
OpcUa_IdentifierType | identifierType () const |
Gets the identifier type of a NodeId. More... | |
OpcUa_UInt16 | namespaceIndex () const |
Returns the namespace index of the NodeId. More... | |
OpcUa_UInt32 | identifierNumeric () const |
Returns the Numeric identifier of the NodeId. More... | |
const OpcUa_String * | identifierString () const |
Returns the String identifier of the NodeId. More... | |
void | toVariant (UaVariant &variant) const |
Initializes a UaVariant with the NodeId. More... | |
void | toVariant (OpcUa_Variant &variant) const |
Initializes an OpcUa_Variant structure with the NodeId. More... | |
void | toVariant (UaVariant &variant, OpcUa_Boolean bDetach) |
Detach the NodeId to a UaVariant. More... | |
void | toVariant (OpcUa_Variant &variant, OpcUa_Boolean bDetach) |
Detach the NodeId to an OpcUa_Variant structure. More... | |
void | toDataValue (UaDataValue &dataValue, OpcUa_Boolean updateTimeStamps) const |
Initializes a UaDataValue with the NodeId. More... | |
void | toDataValue (OpcUa_DataValue &dataValue, OpcUa_Boolean updateTimeStamps) const |
Initializes an OpcUa_DataValue structure with the NodeId. More... | |
void | toDataValue (UaDataValue &dataValue, OpcUa_Boolean bDetach, OpcUa_Boolean updateTimeStamps) |
Detaches the NodeId to a UaDataValue. More... | |
void | toDataValue (OpcUa_DataValue &dataValue, OpcUa_Boolean bDetach, OpcUa_Boolean updateTimeStamps) |
Detaches the NodeId to an OpcUa_DataValue structure. More... | |
Static Public Member Functions | |
static OpcUa_NodeId * | clone (const OpcUa_NodeId &source) |
Static method that allocates a NodeId structure and copies the source NodeId. More... | |
static void | cloneTo (const OpcUa_NodeId &source, OpcUa_NodeId ©) |
Static method that copies the source NodeId structure to the copy NodeId structure. More... | |
static bool | compare (const OpcUa_NodeId &, const OpcUa_NodeId &) |
Compares two NodeId structures and returns true if they are equal. More... | |
static UaNodeId | fromXmlString (UaString xmlString) |
Creates a NodeId to from a string where the syntax is defined by the OPC UA XML Schema. More... | |
Friends | |
UABASE_EXPORT UaDataStream & | operator<< (UaDataStream &, const UaNodeId &) |
Writes a NodeId to the stream. More... | |
UABASE_EXPORT UaDataStream & | operator>> (UaDataStream &, UaNodeId &) |
Reads a NodeId from the stream. More... | |
Wrapper class for the UA stack structure OpcUa_NodeId.
Helper class for handling the OPC UA built-in data type NodeId. It provides conversion and comparison functions and handles memory allocation and cleanup.
UaNodeId uses implicit sharing to avoid needless copying and to boost the performance. Only if you modify a shared NodeId, it creates a copy for that (copy-on-write). So assigning another UaNodeId or passing it as parameter is as fast as assigning a pointer.
NodeId as defined by OPC UA
A Server shall persist the NodeId of a Node, that is, it is not allowed to generate new NodeIds when rebooting. The server is not allowed to change the namespace index for a namespace URI as long as the server is not restarted but new namespaces can be added. The namespace index for a namespace URI may change after a server restart.
Clients must be prepared for changes of the namespace index in a NodeId and must persist their own namespace table together with the stored NodeIds for a server.
Structure of the NodeId
The NodeId data type is a structure with the following elements
Name | Type | Description |
---|---|---|
namespaceIndex | UInt16 | The index for a namespace URI used in an OPC UA server |
identifierType | enum | The format and data type of the identifier |
identifier | * | The identifier for a node in the address space of an OPC UA server |
NamespaceIndex
The namespace is a URI that identifies the naming authority responsible for assigning the identifier element of the NodeId. Naming authorities include the local server, the underlying system, standards bodies and consortia. It is expected that most nodes will use the URI of the server or of the underlying system.
Using a namespace URI allows multiple OPC UA servers attached to the same underlying system to use the same identifier to identify the same object. This enables clients that connect to those Servers to recognise Objects that they have in common. The namespace URI is case sensitive. Namespace URIs are identified by numeric values in OPC UA services to permit more efficient transfer and processing (e.g. table lookups). The numeric values used to identify namespaces correspond to the index into the NamespaceArray. The NamespaceArray is a variable that is part of the Server object in the address space.
The URI for the OPC UA namespace is “http://opcfoundation.org/UA/”. Its corresponding index in the namespace table is 0.
The Namespace URI is case sensitive.
IdentifierType
The following IdentifierTypes are available:
Value | Description |
---|---|
OpcUa_IdentifierType_Numeric | Numeric value |
OpcUa_IdentifierType_String | String value |
OpcUa_IdentifierType_Guid | Globally Unique Identifier |
OpcUa_IdentifierType_Opaque | Namespace specific format in a ByteString |
Identifier value
The identifier value element is used within the context of the first two elements to identify a node. Its data type and format is defined by the identifierType.
Numeric identifiers are typically used for static namespaces or for NodeIds in generated code. Such identifiers in generated code have typically defines generated which makes them easy to use and read in code.
String identifiers are typically used for nodes that are dynamically generated during system configuration. The string is either a path of nodes with a server specific delimiters or a server specific addressing schema contained in the string.
String identifiers are case sensitive. That is, clients shall consider them case sensitive. Servers are allowed to provide alternative NodeIds and using this mechanism severs can handle NodeIds as case insensitive.
Normally the scope of NodeIds is the server in which they are defined. For certain types of NodeIds, NodeIds can uniquely identify a Node within a system, or across systems (e.g. GUIDs). System-wide and globally-unique identifiers allow clients to track Nodes, such as work orders, as they move between OPC UA servers as they progress through the system.
Opaque identifiers are identifiers that are free-format byte strings that might or might not be human interpretable.
Identifier values of IdentifierType STRING are restricted to 4096 characters. Identifier values of IdentifierType OPAQUE are restricted to 4096 bytes.
A null NodeId has special meaning. For example, many services define special behaviour if a null NodeId is passed as a parameter. A node in the address space cannot have a null NodeId.
UaNodeId::UaNodeId | ( | ) |
Creates a null NodeId with NS=0, IdentifierType=Numeric, Identifier=0.
UaNodeId::UaNodeId | ( | const UaNodeId & | other | ) |
UaNodeId::UaNodeId | ( | const OpcUa_NodeId & | other | ) |
Constructs a copy of the native OpcUa_NodeId structure.
This creates a copy of the native data and doesn't modify other. You can also attach the native structure, so that no copying is needed.
other | the OpcUa_NodeId. |
UaNodeId::UaNodeId | ( | OpcUa_UInt32 | id, |
OpcUa_UInt16 | NsIdx = 0 |
||
) |
Creates a new NodeId with a numeric identifier.
id | The numeric identifier. |
NsIdx | The namespace index. The default value for the namespace index is 0 to allow simple assignment of OPC UA defined numeric NodeIds. |
UaNodeId::UaNodeId | ( | const UaString & | sId, |
OpcUa_UInt16 | NsIdx | ||
) |
Creates a new NodeId with a string identifier.
sId | The string identifier. |
NsIdx | The namespace index. |
UaNodeId::UaNodeId | ( | const UaGuid & | guid, |
OpcUa_UInt16 | NsIdx | ||
) |
Creates a new NodeId with a GUID identifier.
guid | The GUID identifier. |
NsIdx | The namespace index. |
UaNodeId::UaNodeId | ( | const UaByteString & | data, |
OpcUa_UInt16 | NsIdx | ||
) |
Creates a new NodeId with a ByteString identifier.
data | The ByteString identifier. |
NsIdx | The namespace index. |
UaNodeId::~UaNodeId | ( | ) |
Destroys the UaNodeId object.
If you want to prevent deleting the internal OpcUa_NodeId structure, you can also detach it before deleting the UaNodeId instance.
void UaNodeId::attach | ( | const OpcUa_NodeId * | pOther | ) |
Attaches to the native NodeId structure.
This means UaNodeId takes ownership of the NodeId data and automatically clears it in the destructor.
It does not clear the OpcUa_NodeId structure itself. This must be done by the caller.
pOther | Pointer to native OpcUa_NodeId structure. |
void UaNodeId::clear | ( | ) |
Clears the content of the UaNodeId object and sets it to a null NodeId.
|
static |
Static method that allocates a NodeId structure and copies the source NodeId.
This method allocates a new OpcUa_NodeId structure and copies the content of the source NodeId the new structure.
The caller must use OpcUa_NodeId_Clear to clear the allocated data in the structure and must use OpcUa_Memory_Free to free the allocated memory for the structure.
source | Source NodeId to clone. |
|
static |
Static method that copies the source NodeId structure to the copy NodeId structure.
This method copies the NodeId data for source to an existing OpcUa_NodeId structure.
The caller must use OpcUa_NodeId_Clear to clear the allocated data in the structure.
source | Source NodeId to clone. |
copy | New copy of source NodeId. |
|
static |
Compares two NodeId structures and returns true if they are equal.
nodeId1 | The source to compare to. |
nodeId2 | The destination to compare to. |
OpcUa_NodeId * UaNodeId::copy | ( | ) | const |
Allocates a NodeId structure and copies the internal NodeId.
This method allocates a new OpcUa_NodeId structure and copies the content of the UaNodeId object to the new structure.
The caller must use OpcUa_NodeId_Clear to clear the allocated data in the structure and must use OpcUa_Memory_Free to free the allocated memory for the structure.
void UaNodeId::copyTo | ( | OpcUa_NodeId * | pDst | ) | const |
Copies the internal NodeId to an allocated and initialized NodeId structure.
This method copies the UaNodeId data to an existing OpcUa_NodeId structure.
The caller must use OpcUa_NodeId_Clear to clear the allocated data in the structure.
pDst | The destination of this copy operation. |
OpcUa_NodeId * UaNodeId::detach | ( | OpcUa_NodeId * | pDst | ) |
Detaches the internal NodeId structure from this class.
This way the caller takes over the ownership of the structure data and is responsible for clearing the NodeId data.
The caller can only detach the data if not more than one reference exists.
pDst | Pointer to OpcUa_NodeId structure that receives the NodeId data. |
Creates a NodeId to from a string where the syntax is defined by the OPC UA XML Schema.
The format of the string is
ns=<namespaceindex>;<identifier type>=<identifier>
with the fields
Flag | Identifier Type |
---|---|
i | NUMERIC (UInteger) |
s | STRING (String) |
g | GUID (Guid) |
b | OPAQUE (ByteString) |
OpcUa_UInt32 UaNodeId::identifierNumeric | ( | ) | const |
Returns the Numeric identifier of the NodeId.
const OpcUa_String * UaNodeId::identifierString | ( | ) | const |
Returns the String identifier of the NodeId.
OpcUa_IdentifierType UaNodeId::identifierType | ( | ) | const |
Gets the identifier type of a NodeId.
Possible values are
OpcUa_Boolean UaNodeId::isNull | ( | ) | const |
Checks whether the NodeId is Null or not.
OpcUa_UInt16 UaNodeId::namespaceIndex | ( | ) | const |
Returns the namespace index of the NodeId.
bool UaNodeId::nodeIdCompare | ( | OpcUa_NodeId * | pNodeId | ) | const |
Compares this NodeId with a NodeId structure and returns true if they are equal.
pNodeId | The node id of the actual node. |
UaNodeId::operator const OpcUa_NodeId * | ( | ) | const |
Returns the OpcUa_NodeId pointer to the internal data structure.
bool UaNodeId::operator!= | ( | const UaNodeId & | other | ) | const |
Is not equal operator for two NodeIds.
other | The UaString to compare. |
bool UaNodeId::operator< | ( | const UaNodeId & | other | ) | const |
Returns true if this NodeId is less than NodeId other; otherwise returns false.
The comparison is executed step by step for the different NodeId fields. If the IdentifierType is different, true is returned if the IdentifierType of this is lesser than other. If the NamespaceIndex is different, true is returned if the NamespaceIndex of this is lesser than other. The checks are executed in sequence and the identifier comparison is only executed if IdentifierType and NamespaceIndex are equal.
If the numeric identifier of this is lesser than other, true is returned. For string NodeIds a string compare is executed. For GUID and Opaque a memory compare is executed.
This is used to sort NodeIds, e.g. to use it as key in a map.
other | The UaNodeId to compare. |
Assigns another NodeId to the current instance.
other | The UaNodeId to assign. |
bool UaNodeId::operator== | ( | const UaNodeId & | other | ) | const |
Is equal operator for two NodeIds.
other | The UaNodeId to compare. |
void UaNodeId::setNamespaceIndex | ( | OpcUa_UInt16 | NsIdx | ) |
Assigns a new namespace index to the NodeId.
NsIdx | The namespace index. |
void UaNodeId::setNodeId | ( | OpcUa_UInt32 | id, |
OpcUa_UInt16 | NsIdx = 0 |
||
) |
Sets the NodeId with a numeric identifier and namespace index.
id | The numeric identifier. |
NsIdx | The namespace index. |
void UaNodeId::setNodeId | ( | const UaString & | sId, |
OpcUa_UInt16 | NsIdx = 1 |
||
) |
Sets the NodeId with a string identifier and namespace index.
sId | The string identifier. |
NsIdx | The namespace index. |
void UaNodeId::setNodeId | ( | const UaGuid & | id, |
OpcUa_UInt16 | NsIdx | ||
) |
Sets the NodeId with a GUID identifier and namespace index.
id | The GUID identifier. |
NsIdx | The namespace index. |
void UaNodeId::setNodeId | ( | const UaByteString & | id, |
OpcUa_UInt16 | NsIdx | ||
) |
Sets the NodeId with a ByteString identifier and namespace index.
id | The ByteString identifier. |
NsIdx | The namespace index. |
void UaNodeId::toDataValue | ( | UaDataValue & | dataValue, |
OpcUa_Boolean | updateTimeStamps | ||
) | const |
Initializes a UaDataValue with the NodeId.
dataValue | The UaDataValue to initialize with the NodeId. |
updateTimeStamps | Flag indicating if the timestamp of the UaDataValue should be updated. |
void UaNodeId::toDataValue | ( | OpcUa_DataValue & | dataValue, |
OpcUa_Boolean | updateTimeStamps | ||
) | const |
Initializes an OpcUa_DataValue structure with the NodeId.
dataValue | The OpcUa_DataValue structure to initialize with the NodeId. |
updateTimeStamps | Flag indicating if the timestamp of the UaDataValue should be updated. |
void UaNodeId::toDataValue | ( | UaDataValue & | dataValue, |
OpcUa_Boolean | bDetach, | ||
OpcUa_Boolean | updateTimeStamps | ||
) |
Detaches the NodeId to a UaDataValue.
dataValue | The UaDataValue where the NodeId should be detached to. |
bDetach | Detaches the NodeId if true. |
updateTimeStamps | Flag indicating if the timestamp of the UaDataValue should be updated. |
void UaNodeId::toDataValue | ( | OpcUa_DataValue & | dataValue, |
OpcUa_Boolean | bDetach, | ||
OpcUa_Boolean | updateTimeStamps | ||
) |
Detaches the NodeId to an OpcUa_DataValue structure.
dataValue | The OpcUa_DataValue structure where the NodeId should be detached to. |
bDetach | Detaches the NodeId if true. |
updateTimeStamps | Flag indicating if the timestamp of the UaDataValue should be updated. |
UaString UaNodeId::toFullString | ( | ) | const |
Converts all elements of a NodeId to a human readable string.
The format of the string is
NS<namespace index>|<identifier type>|<identifier>s
with the fields
There is no reverse function available for toFullString. If you want to create a string that can be used later to create a UaNodeId from this string, toXmlString() must be used.
Examples are
UaString UaNodeId::toString | ( | ) | const |
Converts the identifier of the NodeId to a UaString.
Only the identifier part of the NodeId is returned as UaString. The namespace index and the identifier type is not contained. Use toFullString() or toXmlString() to get all information contained in the NodeId.
There is no reverse function available for toString. If you want to create a string that can be used later to create a UaNodeId from this string, toXmlString() must be used.
void UaNodeId::toVariant | ( | UaVariant & | variant | ) | const |
void UaNodeId::toVariant | ( | OpcUa_Variant & | variant | ) | const |
Initializes an OpcUa_Variant structure with the NodeId.
variant | The OpcUa_Variant structure to initialize with the NodeId. |
void UaNodeId::toVariant | ( | UaVariant & | variant, |
OpcUa_Boolean | bDetach | ||
) |
void UaNodeId::toVariant | ( | OpcUa_Variant & | variant, |
OpcUa_Boolean | bDetach | ||
) |
Detach the NodeId to an OpcUa_Variant structure.
variant | The OpcUa_Variant structure where the NodeId should be detached to. |
bDetach | Detaches the NodeId if true. |
UaString UaNodeId::toXmlString | ( | ) | const |
Converts all elements of a NodeId to a string where the syntax is defined by the OPC UA XML Schema.
The format of the string is
ns=<namespaceindex>;<identifier type>=<identifier>
with the fields
Flag | Identifier Type |
---|---|
i | NUMERIC (UInteger) |
s | STRING (String) |
g | GUID (Guid) |
b | OPAQUE (ByteString) |
Examples are
|
friend |
Writes a NodeId to the stream.
|
friend |
Reads a NodeId from the stream.