UA_StatusCode UA_Server_addObjectNode(UA_Server *server, const UA_QualifiedName browseName, UA_NodeId nodeId, const UA_NodeId parentNodeId, const UA_NodeId referenceTypeId, const UA_NodeId typeDefinition) { UA_ObjectNode *node = UA_ObjectNode_new(); UA_NodeId_copy(&nodeId, &node->nodeId); UA_QualifiedName_copy(&browseName, &node->browseName); UA_String_copy(&browseName.name, &node->displayName.text); UA_ExpandedNodeId parentId; // we need an expandednodeid UA_ExpandedNodeId_init(&parentId); UA_NodeId_copy(&parentNodeId, &parentId.nodeId); UA_AddNodesResult res = UA_Server_addNodeWithSession(server, &adminSession, (UA_Node*)node, parentId, referenceTypeId); if(res.statusCode != UA_STATUSCODE_GOOD) { UA_ObjectNode_delete(node); } UA_AddNodesResult_deleteMembers(&res); if(!(UA_NodeId_isNull(&typeDefinition))){ UA_ExpandedNodeId typeDefid; // we need an expandednodeid UA_ExpandedNodeId_init(&typeDefid); UA_NodeId_copy(&typeDefinition, &typeDefid.nodeId); ADDREFERENCE(res.addedNodeId, UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION), typeDefid); } return res.statusCode; }
void UA_Node_deleteAnyNodeClass(UA_Node *node) { switch(node->nodeClass) { case UA_NODECLASS_OBJECT: UA_ObjectNode_delete((UA_ObjectNode*)node); break; case UA_NODECLASS_VARIABLE: UA_VariableNode_delete((UA_VariableNode*)node); break; case UA_NODECLASS_METHOD: UA_MethodNode_delete((UA_MethodNode*)node); break; case UA_NODECLASS_OBJECTTYPE: UA_ObjectTypeNode_delete((UA_ObjectTypeNode*)node); break; case UA_NODECLASS_VARIABLETYPE: UA_VariableTypeNode_delete((UA_VariableTypeNode*)node); break; case UA_NODECLASS_REFERENCETYPE: UA_ReferenceTypeNode_delete((UA_ReferenceTypeNode*)node); break; case UA_NODECLASS_DATATYPE: UA_DataTypeNode_delete((UA_DataTypeNode*)node); break; case UA_NODECLASS_VIEW: UA_ViewNode_delete((UA_ViewNode*)node); break; default: break; } }
static void addNodeFromAttributes(UA_Server *server, UA_Session *session, UA_AddNodesItem *item, UA_AddNodesResult *result) { // adding nodes to ns0 is not allowed over the wire if(item->requestedNewNodeId.nodeId.namespaceIndex == 0) { result->statusCode = UA_STATUSCODE_BADNODEIDREJECTED; return; } // parse the node UA_Node *node = UA_NULL; switch (item->nodeClass) { case UA_NODECLASS_OBJECT: result->statusCode = parseObjectNode(&item->nodeAttributes, &node); break; case UA_NODECLASS_OBJECTTYPE: result->statusCode = parseObjectTypeNode(&item->nodeAttributes, &node); break; case UA_NODECLASS_REFERENCETYPE: result->statusCode = parseReferenceTypeNode(&item->nodeAttributes, &node); break; case UA_NODECLASS_VARIABLE: result->statusCode = parseVariableNode(&item->nodeAttributes, &node); break; default: result->statusCode = UA_STATUSCODE_BADNOTIMPLEMENTED; } if(result->statusCode != UA_STATUSCODE_GOOD) return; // The BrowseName was not included with the NodeAttribute ExtensionObject UA_QualifiedName_init(&(node->browseName)); UA_QualifiedName_copy(&(item->browseName), &(node->browseName)); UA_NodeId_copy(&item->requestedNewNodeId.nodeId, &node->nodeId); // add the node *result = UA_Server_addNodeWithSession(server, session, node, item->parentNodeId, item->referenceTypeId); if(result->statusCode != UA_STATUSCODE_GOOD) { switch (node->nodeClass) { case UA_NODECLASS_OBJECT: UA_ObjectNode_delete((UA_ObjectNode*)node); break; case UA_NODECLASS_OBJECTTYPE: UA_ObjectTypeNode_delete((UA_ObjectTypeNode*)node); break; case UA_NODECLASS_REFERENCETYPE: UA_ReferenceTypeNode_delete((UA_ReferenceTypeNode*)node); break; case UA_NODECLASS_VARIABLE: UA_VariableNode_delete((UA_VariableNode*)node); break; default: UA_assert(UA_FALSE); } } }