// Copy to stack object // ============================================================================================= Status NodeId::toSdk(OpcUa_NodeId *destination) const { Status ret; UaNodeId uaNodeId; ret = toSdk(uaNodeId); if (ret.isGood()) uaNodeId.copyTo(destination); return ret; }
UaNodeId::UaNodeId ( const UaNodeId & other) { UA_NodeId_init( &m_impl ); UA_StatusCode status = UA_NodeId_copy( other.pimpl(), &this->m_impl ); if (status != UA_STATUSCODE_GOOD) throw alloc_error(); }
// 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; }
// Fill out the NodeId with information from an UaNodeId instance // ============================================================================================= Status NodeId::fromSdk(const UaNodeId& uaNodeId) { OpcUa_NodeId sdkNodeId; uaNodeId.copyTo(&sdkNodeId); return fromSdk(sdkNodeId); }
// Fill out the NodeId with information from an UaNodeId instance // ============================================================================================= Status NodeId::fromSdk(const UaNodeId& uaNodeId, const string& nameSpaceUri) { OpcUa_NodeId sdkNodeId; uaNodeId.copyTo(&sdkNodeId); return fromSdk(sdkNodeId, nameSpaceUri); }
// 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; }