// Copy to SDK object // ============================================================================================= Status NodeId::toSdk(UaNodeId& destination) const { Status ret; if (hasNameSpaceIndex() || nameSpaceUri() == uaf::constants::OPCUA_NAMESPACE_URI) { // fill the just created UaNodeId if (identifier_.type == nodeididentifiertypes::Identifier_String) { destination.setNodeId(identifier_.idString.c_str(), nameSpaceIndex_); ret.setGood(); } else if (identifier_.type == nodeididentifiertypes::Identifier_Numeric) { destination.setNodeId(identifier_.idNumeric, nameSpaceIndex_); ret.setGood(); } else if (identifier_.type == nodeididentifiertypes::Identifier_Guid) { UaGuid uaGuid; identifier_.idGuid.toSdk(uaGuid); destination.setNodeId(uaGuid, nameSpaceIndex_); ret.setGood(); } else if (identifier_.type == nodeididentifiertypes::Identifier_Opaque) { UaByteString uaOpaque; identifier_.idOpaque.toSdk(uaOpaque); destination.setNodeId(uaOpaque, nameSpaceIndex_); ret.setGood(); } else { ret.setStatus(uaf::statuscodes::UnexpectedError, "Unknown NodeId identifier!"); } } else { // update the status ret.setStatus(statuscodes::UnexpectedError, "Cannot prepare an OpcUa_NodeId since no namespace index is known"); } return ret; }
// Copy to SDK object // ============================================================================================= Status NodeId::toSdk(UaNodeId& destination) const { Status ret; if (hasNameSpaceIndex() || nameSpaceUri() == uaf::constants::OPCUA_NAMESPACE_URI) { // fill the just created UaNodeId if (identifier_.type == nodeididentifiertypes::Identifier_String) { destination.setNodeId(identifier_.idString.c_str(), nameSpaceIndex_); ret = statuscodes::Good; } else if (identifier_.type == nodeididentifiertypes::Identifier_Numeric) { destination.setNodeId(identifier_.idNumeric, nameSpaceIndex_); ret = statuscodes::Good; } else if (identifier_.type == nodeididentifiertypes::Identifier_Guid) { UaGuid uaGuid; identifier_.idGuid.toSdk(uaGuid); destination.setNodeId(uaGuid, nameSpaceIndex_); ret = statuscodes::Good; } else if (identifier_.type == nodeididentifiertypes::Identifier_Opaque) { UaByteString uaOpaque; identifier_.idOpaque.toSdk(uaOpaque); destination.setNodeId(uaOpaque, nameSpaceIndex_); ret = statuscodes::Good; } else { ret = UnsupportedNodeIdIdentifierTypeError(); } } else { ret = UnknownNamespaceIndexError(); } return ret; }
// Convert a uaf::NodeId to a OpcUa_NodeId // ============================================================================================= Status NamespaceArray::fillOpcUaNodeId( const NodeId& nodeId, OpcUa_NodeId& opcUaNodeId) const { Status ret; // we need to get a valid namespace index NameSpaceIndex nameSpaceIndex; // check if the browse name has a namespace URI for which we can find an index if (nodeId.hasNameSpaceUri()) { if (findNamespaceIndex(nodeId.nameSpaceUri(), nameSpaceIndex)) ret = statuscodes::Good; else ret = UnknownNamespaceUriError( nodeId.nameSpaceUri(), nameSpaceMap_, toString(nameSpaceMap_)); } else if (nodeId.hasNameSpaceIndex()) { // OK we don't have a namespace URI but we do have a namespace index nameSpaceIndex = nodeId.nameSpaceIndex(); ret = statuscodes::Good; } else { // we have no possible means to get the namespace index ret = NoNamespaceIndexOrUriGivenError(); } // if the namespace index was found, update the OpcUa_NodeId if (ret.isGood()) { UaNodeId uaNodeId; // update the NodeId identifier if (nodeId.identifier().type == nodeididentifiertypes::Identifier_Numeric) { uaNodeId.setNodeId(nodeId.identifier().idNumeric, nameSpaceIndex); uaNodeId.copyTo(&opcUaNodeId); } else if (nodeId.identifier().type == nodeididentifiertypes::Identifier_String) { uaNodeId.setNodeId(UaString(nodeId.identifier().idString.c_str()), nameSpaceIndex); uaNodeId.copyTo(&opcUaNodeId); } else if (nodeId.identifier().type == nodeididentifiertypes::Identifier_Guid) { UaGuid uaGuid; nodeId.identifier().idGuid.toSdk(uaGuid); uaNodeId.setNodeId(uaGuid, nameSpaceIndex); uaNodeId.copyTo(&opcUaNodeId); } else if (nodeId.identifier().type == nodeididentifiertypes::Identifier_Opaque) { UaByteString uaByteString; nodeId.identifier().idOpaque.toSdk(uaByteString); uaNodeId.setNodeId(uaByteString, nameSpaceIndex); uaNodeId.copyTo(&opcUaNodeId); } else { ret = UnsupportedNodeIdIdentifierTypeError(); } } return ret; }