ua_client_highlevel.h 17 KB

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