ua_client_highlevel.h 16 KB

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