|
| 1 | +/** |
| 2 | + * MIT License |
| 3 | + * |
| 4 | + * Copyright (c) 2025 Axis Communications AB |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice (including the next |
| 14 | + * paragraph) shall be included in all copies or substantial portions of the |
| 15 | + * Software. |
| 16 | + * |
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | + * SOFTWARE. |
| 24 | + */ |
| 25 | + |
| 26 | +#ifndef __UA_UTILS_H__ |
| 27 | +#define __UA_UTILS_H__ |
| 28 | + |
| 29 | +#include <glib.h> |
| 30 | +#include <open62541/types.h> |
| 31 | + |
| 32 | +typedef struct rollback_data { |
| 33 | + /* used to save the existing 'customDataTypes' of the server configuration |
| 34 | + * (struct UA_ServerConfig) */ |
| 35 | + const UA_DataTypeArray *saved_cdt; |
| 36 | + |
| 37 | + /* a list of 'struct UA_NodeId' that have been added to the server */ |
| 38 | + GList *node_ids; |
| 39 | +} rollback_data_t; |
| 40 | + |
| 41 | +/* Performs a 'deep' free() to deallocate the 'rollback_data_t' structure with |
| 42 | + * its associated 'node_ids' list */ |
| 43 | +void |
| 44 | +ua_utils_clear_rbd(rollback_data_t **rbd); |
| 45 | + |
| 46 | +/* Loops over the rbd->node_ids list in reverse order and deletes the nodes |
| 47 | + * from the information model. |
| 48 | + * NOTE: the list is populated by pre-pending, traversing it in forward |
| 49 | + * direction will visit the nodes in the reverse order of their addition. |
| 50 | + * IMPORTANT: This can only be called before the server thread gets started |
| 51 | + * as it can change the server configuration. */ |
| 52 | +gboolean |
| 53 | +ua_utils_do_rollback(UA_Server *server, rollback_data_t *rbd, GError **err); |
| 54 | + |
| 55 | +/* wrapper around the open62541 UA_Server_addObjectNode() |
| 56 | + * If underlying UA_Server_addObjectNode() succeeds it also adds the nodeId to |
| 57 | + * the rbd (rollback data) */ |
| 58 | +UA_StatusCode |
| 59 | +UA_Server_addObjectNode_rb(UA_Server *server, |
| 60 | + const UA_NodeId requestedNewNodeId, |
| 61 | + const UA_NodeId parentNodeId, |
| 62 | + const UA_NodeId referenceTypeId, |
| 63 | + const UA_QualifiedName browseName, |
| 64 | + const UA_NodeId typeDefinition, |
| 65 | + const UA_ObjectAttributes attr, |
| 66 | + void *nodeContext, |
| 67 | + rollback_data_t *rbd, |
| 68 | + UA_NodeId *outNewNodeId); |
| 69 | + |
| 70 | +/* wrapper around the open62541 UA_Server_addDataTypeNode() |
| 71 | + * If underlying UA_Server_addDataTypeNode() succeeds it also adds the nodeId to |
| 72 | + * the rbd (rollback data) */ |
| 73 | +UA_StatusCode |
| 74 | +UA_Server_addDataTypeNode_rb(UA_Server *server, |
| 75 | + const UA_NodeId requestedNewNodeId, |
| 76 | + const UA_NodeId parentNodeId, |
| 77 | + const UA_NodeId referenceTypeId, |
| 78 | + const UA_QualifiedName browseName, |
| 79 | + const UA_DataTypeAttributes attr, |
| 80 | + void *nodeContext, |
| 81 | + rollback_data_t *rbd, |
| 82 | + UA_NodeId *outNewNodeId); |
| 83 | + |
| 84 | +/* wrapper around the open62541 UA_Server_addVariableNode() |
| 85 | + * If underlying UA_Server_addVariableNode() succeeds it also adds the nodeId to |
| 86 | + * the rbd (rollback data) */ |
| 87 | +UA_StatusCode |
| 88 | +UA_Server_addVariableNode_rb(UA_Server *server, |
| 89 | + const UA_NodeId requestedNewNodeId, |
| 90 | + const UA_NodeId parentNodeId, |
| 91 | + const UA_NodeId referenceTypeId, |
| 92 | + const UA_QualifiedName browseName, |
| 93 | + const UA_NodeId typeDefinition, |
| 94 | + const UA_VariableAttributes attr, |
| 95 | + void *nodeContext, |
| 96 | + rollback_data_t *rbd, |
| 97 | + UA_NodeId *outNewNodeId); |
| 98 | + |
| 99 | +/* wrapper around the open62541 UA_Server_addObjectTypeNode() |
| 100 | + * If underlying UA_Server_addObjectTypeNode() succeeds it also adds the nodeId |
| 101 | + * to the rbd (rollback data) */ |
| 102 | +UA_StatusCode |
| 103 | +UA_Server_addObjectTypeNode_rb(UA_Server *server, |
| 104 | + const UA_NodeId requestedNewNodeId, |
| 105 | + const UA_NodeId parentNodeId, |
| 106 | + const UA_NodeId referenceTypeId, |
| 107 | + const UA_QualifiedName browseName, |
| 108 | + const UA_ObjectTypeAttributes attr, |
| 109 | + void *nodeContext, |
| 110 | + rollback_data_t *rbd, |
| 111 | + UA_NodeId *outNewNodeId); |
| 112 | + |
| 113 | +/* wrapper around the open62541 UA_Server_addMethodNode() |
| 114 | + * If underlying UA_Server_addMethodNode() succeeds it also adds the nodeId |
| 115 | + * to the rbd (rollback data) */ |
| 116 | +UA_StatusCode |
| 117 | +UA_Server_addMethodNode_rb(UA_Server *server, |
| 118 | + const UA_NodeId requestedNewNodeId, |
| 119 | + const UA_NodeId parentNodeId, |
| 120 | + const UA_NodeId referenceTypeId, |
| 121 | + const UA_QualifiedName browseName, |
| 122 | + const UA_MethodAttributes attr, |
| 123 | + UA_MethodCallback method, |
| 124 | + size_t inputArgumentsSize, |
| 125 | + const UA_Argument *inputArguments, |
| 126 | + size_t outputArgumentsSize, |
| 127 | + const UA_Argument *outputArguments, |
| 128 | + void *nodeContext, |
| 129 | + rollback_data_t *rbd, |
| 130 | + UA_NodeId *outNewNodeId); |
| 131 | + |
| 132 | +#endif /* __UA_UTILS_H__ */ |
0 commit comments