ua_plugin_history_data_backend.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. *
  5. * Copyright 2018 (c) basysKom GmbH <opensource@basyskom.com> (Author: Peter Rustler)
  6. */
  7. #ifndef UA_PLUGIN_HISTORY_DATA_BACKEND_H_
  8. #define UA_PLUGIN_HISTORY_DATA_BACKEND_H_
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. #include "ua_types.h"
  13. #include "ua_server.h"
  14. typedef enum {
  15. MATCH_EQUAL,
  16. MATCH_AFTER,
  17. MATCH_EQUAL_OR_AFTER,
  18. MATCH_BEFORE,
  19. MATCH_EQUAL_OR_BEFORE
  20. } MatchStrategy;
  21. typedef struct UA_HistoryDataBackend UA_HistoryDataBackend;
  22. struct UA_HistoryDataBackend {
  23. void *context;
  24. void
  25. (*deleteMembers)(UA_HistoryDataBackend *backend);
  26. /* This function sets a DataValue for a node in the historical data storage.
  27. *
  28. * server is the server the node lives in.
  29. * hdbContext is the context of the UA_HistoryDataBackend.
  30. * sessionId and sessionContext identify the session that wants to read historical data.
  31. * nodeId is the node for which the value shall be stored.
  32. * value is the value which shall be stored.
  33. * historizing is the historizing flag of the node identified by nodeId.
  34. * If sessionId is NULL, the historizing flag is invalid and must not be used.
  35. */
  36. UA_StatusCode
  37. (*serverSetHistoryData)(UA_Server *server,
  38. void *hdbContext,
  39. const UA_NodeId *sessionId,
  40. void *sessionContext,
  41. const UA_NodeId *nodeId,
  42. UA_Boolean historizing,
  43. const UA_DataValue *value);
  44. /* This function is the high level interface for the ReadRaw operation.
  45. * Set it to NULL if you use the low level API for your plugin.
  46. * It should be used if the low level interface does not suite your database.
  47. * It is more complex to implement the high level interface but it also provide more freedom.
  48. * If you implement this, then set all low level api function pointer to NULL.
  49. *
  50. * server is the server the node lives in.
  51. * hdbContext is the context of the UA_HistoryDataBackend.
  52. * sessionId and sessionContext identify the session that wants to read historical data.
  53. * backend is the HistoryDataBackend whose storage is to be queried.
  54. * start is the start time of the HistoryRead request.
  55. * end is the end time of the HistoryRead request.
  56. * nodeId is the node id of the node for which historical data is requested.
  57. * maxSizePerResponse is the maximum number of items per response the server can provide.
  58. * numValuesPerNode is the maximum number of items per response the client wants to receive.
  59. * returnBounds determines if the client wants to receive bounding values.
  60. * timestampsToReturn contains the time stamps the client is interested in.
  61. * range is the numeric range the client wants to read.
  62. * releaseContinuationPoints determines if the continuation points shall be released.
  63. * continuationPoint is the continuation point the client wants to release or start from.
  64. * outContinuationPoint is the continuation point that gets passed to the client by the HistoryRead service.
  65. * result contains the result histoy data that gets passed to the client.
  66. */
  67. UA_StatusCode
  68. (*getHistoryData)(UA_Server *server,
  69. const UA_NodeId *sessionId,
  70. void *sessionContext,
  71. const UA_HistoryDataBackend *backend,
  72. const UA_DateTime start,
  73. const UA_DateTime end,
  74. const UA_NodeId *nodeId,
  75. size_t maxSizePerResponse,
  76. UA_UInt32 numValuesPerNode,
  77. UA_Boolean returnBounds,
  78. UA_TimestampsToReturn timestampsToReturn,
  79. UA_NumericRange range,
  80. UA_Boolean releaseContinuationPoints,
  81. const UA_ByteString *continuationPoint,
  82. UA_ByteString *outContinuationPoint,
  83. UA_HistoryData *result);
  84. /* This function is part of the low level HistoryRead API.
  85. * It returns the index of a value in the database which matches certain criteria.
  86. *
  87. * server is the server the node lives in.
  88. * hdbContext is the context of the UA_HistoryDataBackend.
  89. * sessionId and sessionContext identify the session that wants to read historical data.
  90. * nodeId is the node id of the node for which the matching value shall be found.
  91. * timestamp is the timestamp of the requested index.
  92. * strategy is the matching strategy which shall be applied in finding the index.
  93. */
  94. size_t
  95. (*getDateTimeMatch)(UA_Server *server,
  96. void *hdbContext,
  97. const UA_NodeId *sessionId,
  98. void *sessionContext,
  99. const UA_NodeId *nodeId,
  100. const UA_DateTime timestamp,
  101. const MatchStrategy strategy);
  102. /* This function is part of the low level HistoryRead API.
  103. * It returns the index of the element after the last valid entry in the database for a node.
  104. *
  105. * server is the server the node lives in.
  106. * hdbContext is the context of the UA_HistoryDataBackend.
  107. * sessionId and sessionContext identify the session that wants to read historical data.
  108. * nodeId is the node id of the node for which the end of storage shall be returned.
  109. */
  110. size_t
  111. (*getEnd)(UA_Server *server,
  112. void *hdbContext,
  113. const UA_NodeId *sessionId,
  114. void *sessionContext,
  115. const UA_NodeId *nodeId);
  116. /* This function is part of the low level HistoryRead API.
  117. * It returns the index of the last element in the database for a node.
  118. *
  119. * server is the server the node lives in.
  120. * hdbContext is the context of the UA_HistoryDataBackend.
  121. * sessionId and sessionContext identify the session that wants to read historical data.
  122. * nodeId is the node id of the node for which the index of the last element shall be returned.
  123. */
  124. size_t
  125. (*lastIndex)(UA_Server *server,
  126. void *hdbContext,
  127. const UA_NodeId *sessionId,
  128. void *sessionContext,
  129. const UA_NodeId *nodeId);
  130. /* This function is part of the low level HistoryRead API.
  131. * It returns the index of the first element in the database for a node.
  132. *
  133. * server is the server the node lives in.
  134. * hdbContext is the context of the UA_HistoryDataBackend.
  135. * sessionId and sessionContext identify the session that wants to read historical data.
  136. * nodeId is the node id of the node for which the index of the first element shall be returned.
  137. */
  138. size_t
  139. (*firstIndex)(UA_Server *server,
  140. void *hdbContext,
  141. const UA_NodeId *sessionId,
  142. void *sessionContext,
  143. const UA_NodeId *nodeId);
  144. /* This function is part of the low level HistoryRead API.
  145. * It returns the number of elements between startIndex and endIndex including both.
  146. *
  147. * server is the server the node lives in.
  148. * hdbContext is the context of the UA_HistoryDataBackend.
  149. * sessionId and sessionContext identify the session that wants to read historical data.
  150. * nodeId is the node id of the node for which the number of elements shall be returned.
  151. * startIndex is the index of the first element in the range.
  152. * endIndex is the index of the last element in the range.
  153. */
  154. size_t
  155. (*resultSize)(UA_Server *server,
  156. void *hdbContext,
  157. const UA_NodeId *sessionId,
  158. void *sessionContext,
  159. const UA_NodeId *nodeId,
  160. size_t startIndex,
  161. size_t endIndex);
  162. /* This function is part of the low level HistoryRead API.
  163. * It copies data values inside a certain range into a buffer.
  164. *
  165. * server is the server the node lives in.
  166. * hdbContext is the context of the UA_HistoryDataBackend.
  167. * sessionId and sessionContext identify the session that wants to read historical data.
  168. * nodeId is the node id of the node for which the data values shall be copied.
  169. * startIndex is the index of the first value in the range.
  170. * endIndex is the index of the last value in the range.
  171. * reverse determines if the values shall be copied in reverse order.
  172. * valueSize is the maximal number of data values to copy.
  173. * range is the numeric range which shall be copied for every data value.
  174. * releaseContinuationPoints determines if the continuation points shall be released.
  175. * continuationPoint is a continuation point the client wants to release or start from.
  176. * outContinuationPoint is a continuation point which will be passed to the client.
  177. * providedValues contains the number of values that were copied.
  178. * values contains the values that have been copied from the database.
  179. */
  180. UA_StatusCode
  181. (*copyDataValues)(UA_Server *server,
  182. void *hdbContext,
  183. const UA_NodeId *sessionId,
  184. void *sessionContext,
  185. const UA_NodeId *nodeId,
  186. size_t startIndex,
  187. size_t endIndex,
  188. UA_Boolean reverse,
  189. size_t valueSize,
  190. UA_NumericRange range,
  191. UA_Boolean releaseContinuationPoints,
  192. const UA_ByteString *continuationPoint,
  193. UA_ByteString *outContinuationPoint,
  194. size_t *providedValues,
  195. UA_DataValue *values);
  196. /* This function is part of the low level HistoryRead API.
  197. * It returns the data value stored at a certain index in the database.
  198. *
  199. * server is the server the node lives in.
  200. * hdbContext is the context of the UA_HistoryDataBackend.
  201. * sessionId and sessionContext identify the session that wants to read historical data.
  202. * nodeId is the node id of the node for which the data value shall be returned.
  203. * index is the index in the database for which the data value is requested.
  204. */
  205. const UA_DataValue*
  206. (*getDataValue)(UA_Server *server,
  207. void *hdbContext,
  208. const UA_NodeId *sessionId,
  209. void *sessionContext,
  210. const UA_NodeId *nodeId,
  211. size_t index);
  212. /* This function returns UA_TRUE if the backend supports returning bounding values for a node.
  213. * This function is mandatory.
  214. *
  215. * server is the server the node lives in.
  216. * hdbContext is the context of the UA_HistoryDataBackend.
  217. * sessionId and sessionContext identify the session that wants to read historical data.
  218. * nodeId is the node id of the node for which the capability to return bounds shall be queried.
  219. */
  220. UA_Boolean
  221. (*boundSupported)(UA_Server *server,
  222. void *hdbContext,
  223. const UA_NodeId *sessionId,
  224. void *sessionContext,
  225. const UA_NodeId *nodeId);
  226. /* This function returns UA_TRUE if the backend supports returning the requested timestamps for a node.
  227. * This function is mandatory.
  228. *
  229. * server is the server the node lives in.
  230. * hdbContext is the context of the UA_HistoryDataBackend.
  231. * sessionId and sessionContext identify the session that wants to read historical data.
  232. * nodeId is the node id of the node for which the capability to return certain timestamps shall be queried.
  233. */
  234. UA_Boolean
  235. (*timestampsToReturnSupported)(UA_Server *server,
  236. void *hdbContext,
  237. const UA_NodeId *sessionId,
  238. void *sessionContext,
  239. const UA_NodeId *nodeId,
  240. const UA_TimestampsToReturn timestampsToReturn);
  241. };
  242. #ifdef __cplusplus
  243. }
  244. #endif
  245. #endif /* UA_PLUGIN_HISTORY_DATA_BACKEND_H_ */