Skip to content

Commit

Permalink
Add UA_Server_deleteCondition
Browse files Browse the repository at this point in the history
  • Loading branch information
ccvca authored and jpfr committed Jun 7, 2020
1 parent ba5cf14 commit 1e29c33
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 12 deletions.
11 changes: 11 additions & 0 deletions include/open62541/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,17 @@ UA_Server_setConditionTwoStateVariableCallback(UA_Server *server, const UA_NodeI
UA_TwoStateVariableChangeCallback callback,
UA_TwoStateVariableCallbackType callbackType);

/**
* Delete a condition from the address space and the internal lists.
*
* @param server The server object
* @param condition The NodeId of the node representation of the Condition Instance
* @param conditionSource The NodeId of the node representation of the Condition Source
* @return UA_STATUSCODE_GOOD on success
*/
UA_StatusCode UA_EXPORT
UA_Server_deleteCondition(UA_Server *server, const UA_NodeId condition, const UA_NodeId conditionSource);

#endif//UA_ENABLE_SUBSCRIPTIONS_ALARMS_CONDITIONS

UA_StatusCode UA_EXPORT
Expand Down
68 changes: 56 additions & 12 deletions src/server/ua_subscription_alarms_conditions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1746,9 +1746,9 @@ setConditionInConditionList(UA_Server *server, const UA_NodeId *conditionNodeId,
UA_ConditionBranch *conditionBranchListEntry;
conditionBranchListEntry = (UA_ConditionBranch*)UA_malloc(sizeof(UA_ConditionBranch));
if(!conditionBranchListEntry) {
UA_free(conditionListEntry);
UA_free(conditionListEntry);
return UA_STATUSCODE_BADOUTOFMEMORY;
}
}

memset(conditionBranchListEntry, 0, sizeof(UA_ConditionBranch));
LIST_INSERT_HEAD(&conditionSourceEntry->conditionHead, conditionListEntry, listEntry);
Expand Down Expand Up @@ -1785,22 +1785,32 @@ appendConditionEntry(UA_Server *server, const UA_NodeId *conditionNodeId,
return setConditionInConditionList(server, conditionNodeId, conditionSourceListEntry);
}

static void deleteAllBranchesFromCondition(UA_Condition *cond)
{
UA_ConditionBranch *branch, *tmp_branch;
LIST_FOREACH_SAFE(branch, &cond->conditionBranchHead, listEntry, tmp_branch) {
UA_NodeId_clear(&branch->conditionBranchId);
UA_ByteString_clear(&branch->lastEventId);
LIST_REMOVE(branch, listEntry);
UA_free(branch);
}
}

static void deleteCondition(UA_Condition *cond)
{
deleteAllBranchesFromCondition(cond);
UA_NodeId_clear(&cond->conditionId);
LIST_REMOVE(cond, listEntry);
UA_free(cond);
}

void
UA_ConditionList_delete(UA_Server *server) {
UA_ConditionSource *source, *tmp_source;
LIST_FOREACH_SAFE(source, &server->headConditionSource, listEntry, tmp_source) {
UA_Condition *cond, *tmp_cond;
LIST_FOREACH_SAFE(cond, &source->conditionHead, listEntry, tmp_cond) {
UA_ConditionBranch *branch, *tmp_branch;
LIST_FOREACH_SAFE(branch, &cond->conditionBranchHead, listEntry, tmp_branch) {
UA_NodeId_clear(&branch->conditionBranchId);
UA_ByteString_clear(&branch->lastEventId);
LIST_REMOVE(branch, listEntry);
UA_free(branch);
}
UA_NodeId_clear(&cond->conditionId);
LIST_REMOVE(cond, listEntry);
UA_free(cond);
deleteCondition(cond);
}
UA_NodeId_clear(&source->conditionSourceId);
LIST_REMOVE(source, listEntry);
Expand Down Expand Up @@ -2521,4 +2531,38 @@ UA_Server_triggerConditionEvent(UA_Server *server, const UA_NodeId condition,
UA_ByteString_deleteMembers(&eventId);
return retval;
}

UA_StatusCode UA_Server_deleteCondition(UA_Server *server, const UA_NodeId condition, const UA_NodeId conditionSource)
{
// Delete from internal list
UA_Boolean found = UA_FALSE;
/* Get ConditionSource Entry */
UA_ConditionSource *source, *tmp_source;
LIST_FOREACH_SAFE(source, &server->headConditionSource, listEntry, tmp_source) {
if(!UA_NodeId_equal(&source->conditionSourceId, &conditionSource))
continue;
/* Get Condition Entry */
UA_Condition *cond, *tmp_cond;
LIST_FOREACH_SAFE(cond, &source->conditionHead, listEntry, tmp_cond) {
if(!UA_NodeId_equal(&cond->conditionId, &condition))
continue;
deleteCondition(cond);
found = UA_TRUE;
break;
}

if(LIST_EMPTY(&source->conditionHead)){
UA_NodeId_clear(&source->conditionSourceId);
LIST_REMOVE(source, listEntry);
UA_free(source);
}
break;
}
if(!found)
{
return UA_STATUSCODE_BADNOTFOUND;
}
// Delete from address space
return UA_Server_deleteNode(server, condition, true);
}
#endif//UA_ENABLE_SUBSCRIPTIONS_ALARMS_CONDITIONS

0 comments on commit 1e29c33

Please sign in to comment.