ua_plugin_history_data_backend.h 13 KB

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