Skip to content

Commit

Permalink
feat(util): Add UA_AttributeOperand_print
Browse files Browse the repository at this point in the history
  • Loading branch information
jpfr committed Oct 25, 2024
1 parent 7e98db5 commit ac418f8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
13 changes: 9 additions & 4 deletions include/open62541/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ UA_RelativePath_print(const UA_RelativePath *rp, UA_String *out);
/**
* .. _parse-sao:
*
* Print and Parse SimpleAttributeOperand Expression
* -------------------------------------------------
* Print and Parse AttributeId and SimpleAttributeOperand Expression
* -----------------------------------------------------------------
* The SimpleAttributeOperand is used to specify the location of up values.
* SimpleAttributeOperands are used for example in EventFilters to select the
* values reported for each event instance.
Expand All @@ -336,6 +336,9 @@ UA_RelativePath_print(const UA_RelativePath *rp, UA_String *out);
* For the index range, see the section on :ref:`numericrange`.
* The BNF definition of the SimpleAttributeOperand is as follows::
*
* AttributeOperand :=
* NodeIdId? RelativePath? ("#" Attribute)? ("[" IndexRange "]")?
*
* SimpleAttributeOperand :=
* TypeDefinitionId? SimpleBrowsePath ("#" Attribute)? ("[" IndexRange "]")?
*
Expand All @@ -352,15 +355,17 @@ UA_RelativePath_print(const UA_RelativePath *rp, UA_String *out);

#ifdef UA_ENABLE_PARSING
UA_EXPORT UA_StatusCode
UA_AttributeOperand_parse(UA_AttributeOperand *ao,
const UA_String str);
UA_AttributeOperand_parse(UA_AttributeOperand *ao, const UA_String str);

UA_EXPORT UA_StatusCode
UA_SimpleAttributeOperand_parse(UA_SimpleAttributeOperand *sao,
const UA_String str);

/* The out-string can be pre-allocated. Then the size is adjusted or an error
* returned. If the out-string is NULL, then memory is allocated for it. */
UA_EXPORT UA_StatusCode
UA_AttributeOperand_print(const UA_AttributeOperand *ao, UA_String *out);

UA_EXPORT UA_StatusCode
UA_SimpleAttributeOperand_print(const UA_SimpleAttributeOperand *sao,
UA_String *out);
Expand Down
44 changes: 44 additions & 0 deletions src/util/ua_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,50 @@ UA_SimpleAttributeOperand_print(const UA_SimpleAttributeOperand *sao,
return moveTmpToOut(&tmp, out);
}

UA_StatusCode
UA_AttributeOperand_print(const UA_AttributeOperand *ao,
UA_String *out) {
UA_String tmp = UA_STRING_NULL;
UA_StatusCode res = UA_STATUSCODE_GOOD;

/* Print the TypeDefinitionId */
if(!UA_NodeId_equal(&hierarchicalRefs, &ao->nodeId)) {
UA_Byte nodeIdBuf[512];
UA_String nodeIdBufStr = {512, nodeIdBuf};
res |= UA_NodeId_print(&ao->nodeId, &nodeIdBufStr);
res |= UA_String_escapeAppend(&tmp, nodeIdBufStr, true);
}

/* Print the BrowsePath */
UA_String rpstr = UA_STRING_NULL;
res |= UA_RelativePath_print(&ao->browsePath, &rpstr);
res |= UA_String_escapeAppend(&tmp, rpstr, true);
UA_String_clear(&rpstr);

/* Print the attribute name */
if(ao->attributeId != UA_ATTRIBUTEID_VALUE) {
const char *attrName= UA_AttributeId_name((UA_AttributeId)ao->attributeId);
res |= UA_String_append(&tmp, UA_STRING("#"));
res |= UA_String_append(&tmp, UA_STRING((char*)(uintptr_t)attrName));
}

/* Print the IndexRange
* TODO: Validate the indexRange string */
if(ao->indexRange.length > 0) {
res |= UA_String_append(&tmp, UA_STRING("["));
res |= UA_String_append(&tmp, ao->indexRange);
res |= UA_String_append(&tmp, UA_STRING("]"));
}

/* Encoding failed, clean up */
if(res != UA_STATUSCODE_GOOD) {
UA_String_clear(&tmp);
return res;
}

return moveTmpToOut(&tmp, out);
}

#endif

/************************/
Expand Down

0 comments on commit ac418f8

Please sign in to comment.