history_data_backend.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. #include <open62541/server.h>
  10. _UA_BEGIN_DECLS
  11. typedef enum {
  12. MATCH_EQUAL, /* Match with the exact timestamp. */
  13. MATCH_AFTER, /* Match the value with the timestamp in the
  14. database that is the first later in time from the provided timestamp. */
  15. MATCH_EQUAL_OR_AFTER, /* Match exactly if possible, or the first timestamp
  16. later in time from the provided timestamp. */
  17. MATCH_BEFORE, /* Match the first timestamp in the database that is earlier
  18. in time from the provided timestamp. */
  19. MATCH_EQUAL_OR_BEFORE /* Match exactly if possible, or the first timestamp
  20. that is earlier in time from the provided timestamp. */
  21. } MatchStrategy;
  22. typedef struct UA_HistoryDataBackend UA_HistoryDataBackend;
  23. struct UA_HistoryDataBackend {
  24. void *context;
  25. void
  26. (*deleteMembers)(UA_HistoryDataBackend *backend);
  27. /* This function sets a DataValue for a node in the historical data storage.
  28. *
  29. * server is the server the node lives in.
  30. * hdbContext is the context of the UA_HistoryDataBackend.
  31. * sessionId and sessionContext identify the session that wants to read historical data.
  32. * nodeId is the node for which the value shall be stored.
  33. * value is the value which shall be stored.
  34. * historizing is the historizing flag of the node identified by nodeId.
  35. * If sessionId is NULL, the historizing flag is invalid and must not be used. */
  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. Set
  45. * it to NULL if you use the low level API for your plugin. It should be
  46. * used if the low level interface does not suite your database. It is more
  47. * complex to implement the high level interface but it also provide more
  48. * freedom. If you implement this, then set all low level api function
  49. * pointer to NULL.
  50. *
  51. * server is the server the node lives in.
  52. * hdbContext is the context of the UA_HistoryDataBackend.
  53. * sessionId and sessionContext identify the session that wants to read historical data.
  54. * backend is the HistoryDataBackend whose storage is to be queried.
  55. * start is the start time of the HistoryRead request.
  56. * end is the end time of the HistoryRead request.
  57. * nodeId is the node id of the node for which historical data is requested.
  58. * maxSizePerResponse is the maximum number of items per response the server can provide.
  59. * numValuesPerNode is the maximum number of items per response the client wants to receive.
  60. * returnBounds determines if the client wants to receive bounding values.
  61. * timestampsToReturn contains the time stamps the client is interested in.
  62. * range is the numeric range the client wants to read.
  63. * releaseContinuationPoints determines if the continuation points shall be released.
  64. * continuationPoint is the continuation point the client wants to release or start from.
  65. * outContinuationPoint is the continuation point that gets passed to the
  66. * client by the HistoryRead service.
  67. * result contains the result histoy data that gets passed to the client. */
  68. UA_StatusCode
  69. (*getHistoryData)(UA_Server *server,
  70. const UA_NodeId *sessionId,
  71. void *sessionContext,
  72. const UA_HistoryDataBackend *backend,
  73. const UA_DateTime start,
  74. const UA_DateTime end,
  75. const UA_NodeId *nodeId,
  76. size_t maxSizePerResponse,
  77. UA_UInt32 numValuesPerNode,
  78. UA_Boolean returnBounds,
  79. UA_TimestampsToReturn timestampsToReturn,
  80. UA_NumericRange range,
  81. UA_Boolean releaseContinuationPoints,
  82. const UA_ByteString *continuationPoint,
  83. UA_ByteString *outContinuationPoint,
  84. UA_HistoryData *result);
  85. /* This function is part of the low level HistoryRead API. It returns the
  86. * index of a value in the database which matches certain criteria.
  87. *
  88. * server is the server the node lives in.
  89. * hdbContext is the context of the UA_HistoryDataBackend.
  90. * sessionId and sessionContext identify the session that wants to read historical data.
  91. * nodeId is the node id of the node for which the matching value shall be found.
  92. * timestamp is the timestamp of the requested index.
  93. * strategy is the matching strategy which shall be applied in finding the index. */
  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. It returns the
  103. * index of the element after the last valid entry in the database for a
  104. * node.
  105. *
  106. * server is the server the node lives in.
  107. * hdbContext is the context of the UA_HistoryDataBackend.
  108. * sessionId and sessionContext identify the session that wants to read historical data.
  109. * nodeId is the node id of the node for which the end of storage shall be returned. */
  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. It returns the
  117. * 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
  123. * shall be returned. */
  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. It returns the
  131. * 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
  137. * element shall be returned. */
  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. It returns the
  145. * 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. size_t
  154. (*resultSize)(UA_Server *server,
  155. void *hdbContext,
  156. const UA_NodeId *sessionId,
  157. void *sessionContext,
  158. const UA_NodeId *nodeId,
  159. size_t startIndex,
  160. size_t endIndex);
  161. /* This function is part of the low level HistoryRead API. It copies data
  162. * values inside a certain range into a buffer.
  163. *
  164. * server is the server the node lives in.
  165. * hdbContext is the context of the UA_HistoryDataBackend.
  166. * sessionId and sessionContext identify the session that wants to read historical data.
  167. * nodeId is the node id of the node for which the data values shall be copied.
  168. * startIndex is the index of the first value in the range.
  169. * endIndex is the index of the last value in the range.
  170. * reverse determines if the values shall be copied in reverse order.
  171. * valueSize is the maximal number of data values to copy.
  172. * range is the numeric range which shall be copied for every data value.
  173. * releaseContinuationPoints determines if the continuation points shall be released.
  174. * continuationPoint is a continuation point the client wants to release or start from.
  175. * outContinuationPoint is a continuation point which will be passed to the client.
  176. * providedValues contains the number of values that were copied.
  177. * values contains the values that have been copied from the database. */
  178. UA_StatusCode
  179. (*copyDataValues)(UA_Server *server,
  180. void *hdbContext,
  181. const UA_NodeId *sessionId,
  182. void *sessionContext,
  183. const UA_NodeId *nodeId,
  184. size_t startIndex,
  185. size_t endIndex,
  186. UA_Boolean reverse,
  187. size_t valueSize,
  188. UA_NumericRange range,
  189. UA_Boolean releaseContinuationPoints,
  190. const UA_ByteString *continuationPoint,
  191. UA_ByteString *outContinuationPoint,
  192. size_t *providedValues,
  193. UA_DataValue *values);
  194. /* This function is part of the low level HistoryRead API. It returns the
  195. * data value stored at a certain index in the database.
  196. *
  197. * server is the server the node lives in.
  198. * hdbContext is the context of the UA_HistoryDataBackend.
  199. * sessionId and sessionContext identify the session that wants to read historical data.
  200. * nodeId is the node id of the node for which the data value shall be returned.
  201. * index is the index in the database for which the data value is requested. */
  202. const UA_DataValue*
  203. (*getDataValue)(UA_Server *server,
  204. void *hdbContext,
  205. const UA_NodeId *sessionId,
  206. void *sessionContext,
  207. const UA_NodeId *nodeId,
  208. size_t index);
  209. /* This function returns UA_TRUE if the backend supports returning bounding
  210. * values for a node. This function is mandatory.
  211. *
  212. * server is the server the node lives in.
  213. * hdbContext is the context of the UA_HistoryDataBackend.
  214. * sessionId and sessionContext identify the session that wants to read
  215. * historical data.
  216. * nodeId is the node id of the node for which the capability to return
  217. * bounds shall be queried. */
  218. UA_Boolean
  219. (*boundSupported)(UA_Server *server,
  220. void *hdbContext,
  221. const UA_NodeId *sessionId,
  222. void *sessionContext,
  223. const UA_NodeId *nodeId);
  224. /* This function returns UA_TRUE if the backend supports returning the
  225. * requested timestamps for a node. This function is mandatory.
  226. *
  227. * server is the server the node lives in.
  228. * hdbContext is the context of the UA_HistoryDataBackend.
  229. * sessionId and sessionContext identify the session that wants to read historical data.
  230. * nodeId is the node id of the node for which the capability to return
  231. * certain timestamps shall be queried. */
  232. UA_Boolean
  233. (*timestampsToReturnSupported)(UA_Server *server,
  234. void *hdbContext,
  235. const UA_NodeId *sessionId,
  236. void *sessionContext,
  237. const UA_NodeId *nodeId,
  238. const UA_TimestampsToReturn timestampsToReturn);
  239. UA_StatusCode
  240. (*insertDataValue)(UA_Server *server,
  241. void *hdbContext,
  242. const UA_NodeId *sessionId,
  243. void *sessionContext,
  244. const UA_NodeId *nodeId,
  245. const UA_DataValue *value);
  246. UA_StatusCode
  247. (*replaceDataValue)(UA_Server *server,
  248. void *hdbContext,
  249. const UA_NodeId *sessionId,
  250. void *sessionContext,
  251. const UA_NodeId *nodeId,
  252. const UA_DataValue *value);
  253. UA_StatusCode
  254. (*updateDataValue)(UA_Server *server,
  255. void *hdbContext,
  256. const UA_NodeId *sessionId,
  257. void *sessionContext,
  258. const UA_NodeId *nodeId,
  259. const UA_DataValue *value);
  260. UA_StatusCode
  261. (*removeDataValue)(UA_Server *server,
  262. void *hdbContext,
  263. const UA_NodeId *sessionId,
  264. void *sessionContext,
  265. const UA_NodeId *nodeId,
  266. UA_DateTime startTimestamp,
  267. UA_DateTime endTimestamp);
  268. };
  269. _UA_END_DECLS
  270. #endif /* UA_PLUGIN_HISTORY_DATA_BACKEND_H_ */