ua_client_highlevel.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. #ifndef UA_CLIENT_HIGHLEVEL_H_
  2. #define UA_CLIENT_HIGHLEVEL_H_
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include "ua_client.h"
  7. /**
  8. * Get the namespace-index of a namespace-URI
  9. *
  10. * @param client The UA_Client struct for this connection
  11. * @param namespaceUri The interested namespace URI
  12. * @param namespaceIndex The namespace index of the URI. The value is unchanged in case of an error
  13. * @return Indicates whether the operation succeeded or returns an error code
  14. */
  15. UA_StatusCode UA_EXPORT UA_Client_NamespaceGetIndex(UA_Client *client, UA_String *namespaceUri, UA_UInt16 *namespaceIndex);
  16. #ifndef HAVE_NODEITER_CALLBACK
  17. #define HAVE_NODEITER_CALLBACK
  18. /* Iterate over all nodes referenced by parentNodeId by calling the callback
  19. f unction for each child node */
  20. typedef UA_StatusCode (*UA_NodeIteratorCallback)(UA_NodeId childId, UA_Boolean isInverse,
  21. UA_NodeId referenceTypeId, void *handle);
  22. #endif
  23. UA_StatusCode UA_EXPORT UA_Client_forEachChildNodeCall(UA_Client *client, UA_NodeId parentNodeId, UA_NodeIteratorCallback callback, void *handle) ;
  24. /*******************/
  25. /* Node Management */
  26. /*******************/
  27. UA_StatusCode UA_EXPORT
  28. UA_Client_addReference(UA_Client *client, const UA_NodeId sourceNodeId, const UA_NodeId referenceTypeId,
  29. UA_Boolean isForward, const UA_String targetServerUri,
  30. const UA_ExpandedNodeId targetNodeId, UA_NodeClass targetNodeClass);
  31. UA_StatusCode UA_EXPORT
  32. UA_Client_deleteReference(UA_Client *client, const UA_NodeId sourceNodeId, const UA_NodeId referenceTypeId,
  33. UA_Boolean isForward, const UA_ExpandedNodeId targetNodeId,
  34. UA_Boolean deleteBidirectional);
  35. UA_StatusCode UA_EXPORT
  36. UA_Client_deleteNode(UA_Client *client, const UA_NodeId nodeId, UA_Boolean deleteTargetReferences);
  37. /* Don't call this function, use the typed versions */
  38. UA_StatusCode UA_EXPORT
  39. __UA_Client_addNode(UA_Client *client, const UA_NodeClass nodeClass,
  40. const UA_NodeId requestedNewNodeId, const UA_NodeId parentNodeId,
  41. const UA_NodeId referenceTypeId, const UA_QualifiedName browseName,
  42. const UA_NodeId typeDefinition, const UA_NodeAttributes *attr,
  43. const UA_DataType *attributeType, UA_NodeId *outNewNodeId);
  44. static UA_INLINE UA_StatusCode
  45. UA_Client_addVariableNode(UA_Client *client, const UA_NodeId requestedNewNodeId,
  46. const UA_NodeId parentNodeId, const UA_NodeId referenceTypeId,
  47. const UA_QualifiedName browseName, const UA_NodeId typeDefinition,
  48. const UA_VariableAttributes attr, UA_NodeId *outNewNodeId) {
  49. return __UA_Client_addNode(client, UA_NODECLASS_VARIABLE, requestedNewNodeId,
  50. parentNodeId, referenceTypeId, browseName, typeDefinition,
  51. (const UA_NodeAttributes*)&attr, &UA_TYPES[UA_TYPES_VARIABLEATTRIBUTES],
  52. outNewNodeId); }
  53. static UA_INLINE UA_StatusCode
  54. UA_Client_addVariableTypeNode(UA_Client *client, const UA_NodeId requestedNewNodeId,
  55. const UA_NodeId parentNodeId, const UA_NodeId referenceTypeId,
  56. const UA_QualifiedName browseName, const UA_VariableTypeAttributes attr,
  57. UA_NodeId *outNewNodeId) {
  58. return __UA_Client_addNode(client, UA_NODECLASS_VARIABLETYPE, requestedNewNodeId,
  59. parentNodeId, referenceTypeId, browseName, UA_NODEID_NULL,
  60. (const UA_NodeAttributes*)&attr, &UA_TYPES[UA_TYPES_VARIABLETYPEATTRIBUTES],
  61. outNewNodeId); }
  62. static UA_INLINE UA_StatusCode
  63. UA_Client_addObjectNode(UA_Client *client, const UA_NodeId requestedNewNodeId,
  64. const UA_NodeId parentNodeId, const UA_NodeId referenceTypeId,
  65. const UA_QualifiedName browseName, const UA_NodeId typeDefinition,
  66. const UA_ObjectAttributes attr, UA_NodeId *outNewNodeId) {
  67. return __UA_Client_addNode(client, UA_NODECLASS_OBJECT, requestedNewNodeId,
  68. parentNodeId, referenceTypeId, browseName, typeDefinition,
  69. (const UA_NodeAttributes*)&attr, &UA_TYPES[UA_TYPES_OBJECTATTRIBUTES],
  70. outNewNodeId); }
  71. static UA_INLINE UA_StatusCode
  72. UA_Client_addObjectTypeNode(UA_Client *client, const UA_NodeId requestedNewNodeId,
  73. const UA_NodeId parentNodeId, const UA_NodeId referenceTypeId,
  74. const UA_QualifiedName browseName, const UA_ObjectTypeAttributes attr,
  75. UA_NodeId *outNewNodeId) {
  76. return __UA_Client_addNode(client, UA_NODECLASS_OBJECTTYPE, requestedNewNodeId,
  77. parentNodeId, referenceTypeId, browseName, UA_NODEID_NULL,
  78. (const UA_NodeAttributes*)&attr, &UA_TYPES[UA_TYPES_OBJECTTYPEATTRIBUTES],
  79. outNewNodeId); }
  80. static UA_INLINE UA_StatusCode
  81. UA_Client_addViewNode(UA_Client *client, const UA_NodeId requestedNewNodeId,
  82. const UA_NodeId parentNodeId, const UA_NodeId referenceTypeId,
  83. const UA_QualifiedName browseName, const UA_ViewAttributes attr,
  84. UA_NodeId *outNewNodeId) {
  85. return __UA_Client_addNode(client, UA_NODECLASS_VIEW, requestedNewNodeId,
  86. parentNodeId, referenceTypeId, browseName, UA_NODEID_NULL,
  87. (const UA_NodeAttributes*)&attr, &UA_TYPES[UA_TYPES_VIEWATTRIBUTES],
  88. outNewNodeId); }
  89. static UA_INLINE UA_StatusCode
  90. UA_Client_addReferenceTypeNode(UA_Client *client, const UA_NodeId requestedNewNodeId,
  91. const UA_NodeId parentNodeId, const UA_NodeId referenceTypeId,
  92. const UA_QualifiedName browseName, const UA_ReferenceTypeAttributes attr,
  93. UA_NodeId *outNewNodeId) {
  94. return __UA_Client_addNode(client, UA_NODECLASS_REFERENCETYPE, requestedNewNodeId,
  95. parentNodeId, referenceTypeId, browseName, UA_NODEID_NULL,
  96. (const UA_NodeAttributes*)&attr, &UA_TYPES[UA_TYPES_REFERENCETYPEATTRIBUTES],
  97. outNewNodeId); }
  98. static UA_INLINE UA_StatusCode
  99. UA_Client_addDataTypeNode(UA_Client *client, const UA_NodeId requestedNewNodeId,
  100. const UA_NodeId parentNodeId, const UA_NodeId referenceTypeId,
  101. const UA_QualifiedName browseName, const UA_DataTypeAttributes attr,
  102. UA_NodeId *outNewNodeId) {
  103. return __UA_Client_addNode(client, UA_NODECLASS_DATATYPE, requestedNewNodeId,
  104. parentNodeId, referenceTypeId, browseName, UA_NODEID_NULL,
  105. (const UA_NodeAttributes*)&attr, &UA_TYPES[UA_TYPES_DATATYPEATTRIBUTES],
  106. outNewNodeId); }
  107. static UA_INLINE UA_StatusCode
  108. UA_Client_addMethodNode(UA_Client *client, const UA_NodeId requestedNewNodeId,
  109. const UA_NodeId parentNodeId, const UA_NodeId referenceTypeId,
  110. const UA_QualifiedName browseName, const UA_MethodAttributes attr,
  111. UA_NodeId *outNewNodeId) {
  112. return __UA_Client_addNode(client, UA_NODECLASS_METHOD, requestedNewNodeId,
  113. parentNodeId, referenceTypeId, browseName, UA_NODEID_NULL,
  114. (const UA_NodeAttributes*)&attr, &UA_TYPES[UA_TYPES_METHODATTRIBUTES],
  115. outNewNodeId); }
  116. /*************************/
  117. /* Attribute Service Set */
  118. /*************************/
  119. /* Don't use this function. There are typed versions for every supported attribute. */
  120. UA_StatusCode UA_EXPORT
  121. __UA_Client_readAttribute(UA_Client *client, UA_NodeId nodeId, UA_AttributeId attributeId,
  122. void *out, const UA_DataType *outDataType);
  123. UA_StatusCode UA_EXPORT
  124. __UA_Client_writeAttribute(UA_Client *client, UA_NodeId nodeId, UA_AttributeId attributeId,
  125. void *in, const UA_DataType *inDataType);
  126. static UA_INLINE UA_StatusCode
  127. UA_Client_readNodeIdAttribute(UA_Client *client, UA_NodeId nodeId, UA_NodeId *outNodeId) {
  128. return __UA_Client_readAttribute(client, nodeId, UA_ATTRIBUTEID_NODEID,
  129. outNodeId, &UA_TYPES[UA_TYPES_NODEID]); }
  130. static UA_INLINE UA_StatusCode
  131. UA_Client_readNodeClassAttribute(UA_Client *client, UA_NodeId nodeId, UA_NodeClass *outNodeClass) {
  132. return __UA_Client_readAttribute(client, nodeId, UA_ATTRIBUTEID_NODECLASS,
  133. outNodeClass, &UA_TYPES[UA_TYPES_NODECLASS]); }
  134. static UA_INLINE UA_StatusCode
  135. UA_Client_readBrowseNameAttribute(UA_Client *client, UA_NodeId nodeId, UA_QualifiedName *outBrowseName) {
  136. return __UA_Client_readAttribute(client, nodeId, UA_ATTRIBUTEID_BROWSENAME,
  137. outBrowseName, &UA_TYPES[UA_TYPES_QUALIFIEDNAME]); }
  138. static UA_INLINE UA_StatusCode
  139. UA_Client_readDisplayNameAttribute(UA_Client *client, UA_NodeId nodeId, UA_LocalizedText *outDisplayName) {
  140. return __UA_Client_readAttribute(client, nodeId, UA_ATTRIBUTEID_DISPLAYNAME,
  141. outDisplayName, &UA_TYPES[UA_TYPES_LOCALIZEDTEXT]); }
  142. static UA_INLINE UA_StatusCode
  143. UA_Client_readDescriptionAttribute(UA_Client *client, UA_NodeId nodeId, UA_LocalizedText *outDescription) {
  144. return __UA_Client_readAttribute(client, nodeId, UA_ATTRIBUTEID_DESCRIPTION,
  145. outDescription, &UA_TYPES[UA_TYPES_LOCALIZEDTEXT]); }
  146. static UA_INLINE UA_StatusCode
  147. UA_Client_readWriteMaskAttribute(UA_Client *client, UA_NodeId nodeId, UA_UInt32 *outWriteMask) {
  148. return __UA_Client_readAttribute(client, nodeId, UA_ATTRIBUTEID_WRITEMASK,
  149. outWriteMask, &UA_TYPES[UA_TYPES_UINT32]); }
  150. static UA_INLINE UA_StatusCode
  151. UA_Client_readUserWriteMaskAttribute(UA_Client *client, UA_NodeId nodeId, UA_UInt32 *outUserWriteMask) {
  152. return __UA_Client_readAttribute(client, nodeId, UA_ATTRIBUTEID_USERWRITEMASK,
  153. outUserWriteMask, &UA_TYPES[UA_TYPES_UINT32]); }
  154. static UA_INLINE UA_StatusCode
  155. UA_Client_readIsAbstractAttribute(UA_Client *client, UA_NodeId nodeId, UA_Boolean *outIsAbstract) {
  156. return __UA_Client_readAttribute(client, nodeId, UA_ATTRIBUTEID_ISABSTRACT,
  157. outIsAbstract, &UA_TYPES[UA_TYPES_BOOLEAN]); }
  158. static UA_INLINE UA_StatusCode
  159. UA_Client_readSymmetricAttribute(UA_Client *client, UA_NodeId nodeId, UA_Boolean *outSymmetric) {
  160. return __UA_Client_readAttribute(client, nodeId, UA_ATTRIBUTEID_SYMMETRIC,
  161. outSymmetric, &UA_TYPES[UA_TYPES_BOOLEAN]); }
  162. static UA_INLINE UA_StatusCode
  163. UA_Client_readInverseNameAttribute(UA_Client *client, UA_NodeId nodeId, UA_LocalizedText *outInverseName) {
  164. return __UA_Client_readAttribute(client, nodeId, UA_ATTRIBUTEID_INVERSENAME,
  165. outInverseName, &UA_TYPES[UA_TYPES_LOCALIZEDTEXT]); }
  166. static UA_INLINE UA_StatusCode
  167. UA_Client_readContainsNoLoopsAttribute(UA_Client *client, UA_NodeId nodeId, UA_Boolean *outContainsNoLoops) {
  168. return __UA_Client_readAttribute(client, nodeId, UA_ATTRIBUTEID_CONTAINSNOLOOPS,
  169. outContainsNoLoops, &UA_TYPES[UA_TYPES_BOOLEAN]); }
  170. static UA_INLINE UA_StatusCode
  171. UA_Client_readEventNotifierAttribute(UA_Client *client, UA_NodeId nodeId, UA_Byte *outEventNotifier) {
  172. return __UA_Client_readAttribute(client, nodeId, UA_ATTRIBUTEID_EVENTNOTIFIER,
  173. outEventNotifier, &UA_TYPES[UA_TYPES_BYTE]); }
  174. static UA_INLINE UA_StatusCode
  175. UA_Client_readValueAttribute(UA_Client *client, UA_NodeId nodeId, UA_Variant *outValue) {
  176. return __UA_Client_readAttribute(client, nodeId, UA_ATTRIBUTEID_VALUE,
  177. outValue, &UA_TYPES[UA_TYPES_VARIANT]); }
  178. static UA_INLINE UA_StatusCode
  179. UA_Client_writeValueAttribute(UA_Client *client, UA_NodeId nodeId, UA_Variant *inValue) {
  180. return __UA_Client_writeAttribute(client, nodeId, UA_ATTRIBUTEID_VALUE,
  181. inValue, &UA_TYPES[UA_TYPES_VARIANT]); }
  182. static UA_INLINE UA_StatusCode
  183. UA_Client_readDataTypeAttribute(UA_Client *client, UA_NodeId nodeId, UA_NodeId *outDataType) {
  184. return __UA_Client_readAttribute(client, nodeId, UA_ATTRIBUTEID_DATATYPE,
  185. outDataType, &UA_TYPES[UA_TYPES_NODEID]); }
  186. static UA_INLINE UA_StatusCode
  187. UA_Client_readValueRankAttribute(UA_Client *client, UA_NodeId nodeId, UA_Int32 *outValueRank) {
  188. return __UA_Client_readAttribute(client, nodeId, UA_ATTRIBUTEID_VALUERANK,
  189. outValueRank, &UA_TYPES[UA_TYPES_INT32]); }
  190. // todo: fetch an array
  191. static UA_INLINE UA_StatusCode
  192. UA_Client_readArrayDimensionsAttribute(UA_Client *client, UA_NodeId nodeId, UA_Int32 *outArrayDimensions) {
  193. return __UA_Client_readAttribute(client, nodeId, UA_ATTRIBUTEID_ARRAYDIMENSIONS,
  194. outArrayDimensions, &UA_TYPES[UA_TYPES_INT32]); }
  195. static UA_INLINE UA_StatusCode
  196. UA_Client_readAccessLevelAttribute(UA_Client *client, UA_NodeId nodeId, UA_UInt32 *outAccessLevel) {
  197. return __UA_Client_readAttribute(client, nodeId, UA_ATTRIBUTEID_ACCESSLEVEL,
  198. outAccessLevel, &UA_TYPES[UA_TYPES_UINT32]); }
  199. static UA_INLINE UA_StatusCode
  200. UA_Client_readUserAccessLevelAttribute(UA_Client *client, UA_NodeId nodeId, UA_UInt32 *outUserAccessLevel) {
  201. return __UA_Client_readAttribute(client, nodeId, UA_ATTRIBUTEID_USERACCESSLEVEL,
  202. outUserAccessLevel, &UA_TYPES[UA_TYPES_UINT32]); }
  203. static UA_INLINE UA_StatusCode
  204. UA_Client_readMinimumSamplingIntervalAttribute(UA_Client *client, UA_NodeId nodeId,
  205. UA_Double *outMinimumSamplingInterval) {
  206. return __UA_Client_readAttribute(client, nodeId, UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL,
  207. outMinimumSamplingInterval, &UA_TYPES[UA_TYPES_DOUBLE]); }
  208. static UA_INLINE UA_StatusCode
  209. UA_Client_readHistorizingAttribute(UA_Client *client, UA_NodeId nodeId, UA_Boolean *outHistorizing) {
  210. return __UA_Client_readAttribute(client, nodeId, UA_ATTRIBUTEID_HISTORIZING,
  211. outHistorizing, &UA_TYPES[UA_TYPES_BOOLEAN]); }
  212. static UA_INLINE UA_StatusCode
  213. UA_Client_readExecutableAttribute(UA_Client *client, UA_NodeId nodeId, UA_Boolean *outExecutable) {
  214. return __UA_Client_readAttribute(client, nodeId, UA_ATTRIBUTEID_EXECUTABLE,
  215. outExecutable, &UA_TYPES[UA_TYPES_BOOLEAN]); }
  216. static UA_INLINE UA_StatusCode
  217. UA_Client_readUserExecutableAttribute(UA_Client *client, UA_NodeId nodeId, UA_Boolean *outUserExecutable) {
  218. return __UA_Client_readAttribute(client, nodeId, UA_ATTRIBUTEID_USEREXECUTABLE,
  219. outUserExecutable, &UA_TYPES[UA_TYPES_BOOLEAN]); }
  220. /**********************/
  221. /* Method Service Set */
  222. /**********************/
  223. UA_StatusCode UA_EXPORT
  224. UA_Client_call(UA_Client *client, const UA_NodeId objectId, const UA_NodeId methodId,
  225. size_t inputSize, const UA_Variant *input, size_t *outputSize, UA_Variant **output);
  226. /**************************/
  227. /* Subscriptions Handling */
  228. /**************************/
  229. #ifdef UA_ENABLE_SUBSCRIPTIONS
  230. typedef struct {
  231. UA_Double requestedPublishingInterval;
  232. UA_UInt32 requestedLifetimeCount;
  233. UA_UInt32 requestedMaxKeepAliveCount;
  234. UA_UInt32 maxNotificationsPerPublish;
  235. UA_Boolean publishingEnabled;
  236. UA_Byte priority;
  237. } UA_SubscriptionSettings;
  238. extern const UA_EXPORT UA_SubscriptionSettings UA_SubscriptionSettings_standard;
  239. UA_StatusCode UA_EXPORT
  240. UA_Client_Subscriptions_new(UA_Client *client, UA_SubscriptionSettings settings,
  241. UA_UInt32 *newSubscriptionId);
  242. UA_StatusCode UA_EXPORT
  243. UA_Client_Subscriptions_remove(UA_Client *client, UA_UInt32 subscriptionId);
  244. UA_StatusCode UA_EXPORT UA_Client_Subscriptions_manuallySendPublishRequest(UA_Client *client);
  245. UA_StatusCode UA_EXPORT
  246. UA_Client_Subscriptions_addMonitoredItem(UA_Client *client, UA_UInt32 subscriptionId,
  247. UA_NodeId nodeId, UA_UInt32 attributeID,
  248. void (*handlingFunction)(UA_UInt32 handle, UA_DataValue *value, void *context),
  249. void *handlingContext,
  250. UA_UInt32 *newMonitoredItemId);
  251. UA_StatusCode UA_EXPORT
  252. UA_Client_Subscriptions_removeMonitoredItem(UA_Client *client, UA_UInt32 subscriptionId,
  253. UA_UInt32 monitoredItemId);
  254. #endif
  255. #ifdef __cplusplus
  256. } // extern "C"
  257. #endif
  258. #endif /* UA_CLIENT_HIGHLEVEL_H_ */