ua_subscription_datachange.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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 2017 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
  6. * Copyright 2017 (c) Stefan Profanter, fortiss GmbH
  7. * Copyright 2018 (c) Ari Breitkreuz, fortiss GmbH
  8. * Copyright 2018 (c) Thomas Stalder, Blue Time Concept SA
  9. * Copyright 2018 (c) Fabian Arndt, Root-Core
  10. */
  11. #include "ua_server_internal.h"
  12. #include "ua_subscription.h"
  13. #include "ua_types_encoding_binary.h"
  14. #ifdef UA_ENABLE_DA
  15. #include <math.h> // fabs
  16. #endif
  17. #ifdef UA_ENABLE_SUBSCRIPTIONS /* conditional compilation */
  18. #define UA_VALUENCODING_MAXSTACK 512
  19. #define ABS_SUBTRACT_TYPE_INDEPENDENT(a,b) ((a)>(b)?(a)-(b):(b)-(a))
  20. static UA_Boolean
  21. outOfDeadBand(const void *data1, const void *data2, const size_t arrayPos,
  22. const UA_DataType *type, const UA_Double deadbandValue) {
  23. if(type == &UA_TYPES[UA_TYPES_BOOLEAN]) {
  24. if(ABS_SUBTRACT_TYPE_INDEPENDENT(((const UA_Boolean*)data1)[arrayPos],
  25. ((const UA_Boolean*)data2)[arrayPos]) <= deadbandValue)
  26. return false;
  27. } else if(type == &UA_TYPES[UA_TYPES_SBYTE]) {
  28. if(ABS_SUBTRACT_TYPE_INDEPENDENT(((const UA_SByte*)data1)[arrayPos],
  29. ((const UA_SByte*)data2)[arrayPos]) <= deadbandValue)
  30. return false;
  31. } else if(type == &UA_TYPES[UA_TYPES_BYTE]) {
  32. if(ABS_SUBTRACT_TYPE_INDEPENDENT(((const UA_Byte*)data1)[arrayPos],
  33. ((const UA_Byte*)data2)[arrayPos]) <= deadbandValue)
  34. return false;
  35. } else if(type == &UA_TYPES[UA_TYPES_INT16]) {
  36. if(ABS_SUBTRACT_TYPE_INDEPENDENT(((const UA_Int16*)data1)[arrayPos],
  37. ((const UA_Int16*)data2)[arrayPos]) <= deadbandValue)
  38. return false;
  39. } else if(type == &UA_TYPES[UA_TYPES_UINT16]) {
  40. if(ABS_SUBTRACT_TYPE_INDEPENDENT(((const UA_UInt16*)data1)[arrayPos],
  41. ((const UA_UInt16*)data2)[arrayPos]) <= deadbandValue)
  42. return false;
  43. } else if(type == &UA_TYPES[UA_TYPES_INT32]) {
  44. if(ABS_SUBTRACT_TYPE_INDEPENDENT(((const UA_Int32*)data1)[arrayPos],
  45. ((const UA_Int32*)data2)[arrayPos]) <= deadbandValue)
  46. return false;
  47. } else if(type == &UA_TYPES[UA_TYPES_UINT32]) {
  48. if(ABS_SUBTRACT_TYPE_INDEPENDENT(((const UA_UInt32*)data1)[arrayPos],
  49. ((const UA_UInt32*)data2)[arrayPos]) <= deadbandValue)
  50. return false;
  51. } else if(type == &UA_TYPES[UA_TYPES_INT64]) {
  52. if(ABS_SUBTRACT_TYPE_INDEPENDENT(((const UA_Int64*)data1)[arrayPos],
  53. ((const UA_Int64*)data2)[arrayPos]) <= deadbandValue)
  54. return false;
  55. } else if(type == &UA_TYPES[UA_TYPES_UINT64]) {
  56. if(ABS_SUBTRACT_TYPE_INDEPENDENT(((const UA_UInt64*)data1)[arrayPos],
  57. ((const UA_UInt64*)data2)[arrayPos]) <= deadbandValue)
  58. return false;
  59. } else if(type == &UA_TYPES[UA_TYPES_FLOAT]) {
  60. if(ABS_SUBTRACT_TYPE_INDEPENDENT(((const UA_Float*)data1)[arrayPos],
  61. ((const UA_Float*)data2)[arrayPos]) <= deadbandValue)
  62. return false;
  63. } else if(type == &UA_TYPES[UA_TYPES_DOUBLE]) {
  64. if(ABS_SUBTRACT_TYPE_INDEPENDENT(((const UA_Double*)data1)[arrayPos],
  65. ((const UA_Double*)data2)[arrayPos]) <= deadbandValue)
  66. return false;
  67. }
  68. return true;
  69. }
  70. #ifdef UA_ENABLE_DA
  71. static UA_INLINE UA_Boolean
  72. outOfPercentDeadBand(const void *data1, const void *data2, const size_t index,
  73. const UA_DataType *type, const UA_Double deadbandValue, UA_Range* range) {
  74. if(type == &UA_TYPES[UA_TYPES_SBYTE]) {
  75. if(ABS_SUBTRACT_TYPE_INDEPENDENT(((const UA_SByte*)data1)[index],
  76. ((const UA_SByte*)data2)[index]) <= (deadbandValue/100.0)*(fabs(range->high - range->low)) ||
  77. *(const UA_SByte*)data1 > range->high)
  78. return false;
  79. } else if(type == &UA_TYPES[UA_TYPES_BYTE]) {
  80. if(ABS_SUBTRACT_TYPE_INDEPENDENT(((const UA_Byte*)data1)[index],
  81. ((const UA_Byte*)data2)[index]) <= (deadbandValue/100.0)*(fabs(range->high - range->low)) ||
  82. *(const UA_Byte*)data1 > range->high)
  83. return false;
  84. } else if(type == &UA_TYPES[UA_TYPES_INT16]) {
  85. if(ABS_SUBTRACT_TYPE_INDEPENDENT(((const UA_Int16*)data1)[index],
  86. ((const UA_Int16*)data2)[index]) <= (deadbandValue/100.0)*(fabs(range->high - range->low)) ||
  87. *(const UA_Int16*)data1 > range->high)
  88. return false;
  89. } else if(type == &UA_TYPES[UA_TYPES_UINT16]) {
  90. if(ABS_SUBTRACT_TYPE_INDEPENDENT(((const UA_UInt16*)data1)[index],
  91. ((const UA_UInt16*)data2)[index]) <= (deadbandValue/100.0)*(fabs(range->high - range->low)) ||
  92. *(const UA_UInt16*)data1 > range->high)
  93. return false;
  94. } else if(type == &UA_TYPES[UA_TYPES_INT32]) {
  95. if(ABS_SUBTRACT_TYPE_INDEPENDENT(((const UA_Int32*)data1)[index],
  96. ((const UA_Int32*)data2)[index]) <= (deadbandValue/100.0)*(fabs(range->high - range->low)) ||
  97. *(const UA_Int32*)data1 > range->high)
  98. return false;
  99. } else if(type == &UA_TYPES[UA_TYPES_UINT32]) {
  100. if(ABS_SUBTRACT_TYPE_INDEPENDENT(((const UA_UInt32*)data1)[index],
  101. ((const UA_UInt32*)data2)[index]) <= (deadbandValue/100.0)*(fabs(range->high - range->low)) ||
  102. *(const UA_UInt32*)data1 > range->high)
  103. return false;
  104. } else if(type == &UA_TYPES[UA_TYPES_INT64]) {
  105. if(ABS_SUBTRACT_TYPE_INDEPENDENT(((const UA_Int64*)data1)[index],
  106. ((const UA_Int64*)data2)[index]) <= (deadbandValue/100.0)*(fabs(range->high - range->low)) ||
  107. *(const UA_Int64*)data1 > range->high)
  108. return false;
  109. } else if(type == &UA_TYPES[UA_TYPES_UINT64]) {
  110. if(ABS_SUBTRACT_TYPE_INDEPENDENT(((const UA_UInt64*)data1)[index],
  111. ((const UA_UInt64*)data2)[index]) <= (deadbandValue/100.0)*(fabs(range->high - range->low)) ||
  112. *(const UA_UInt64*)data1 > range->high)
  113. return false;
  114. } else if(type == &UA_TYPES[UA_TYPES_FLOAT]) {
  115. if(ABS_SUBTRACT_TYPE_INDEPENDENT(((const UA_Float*)data1)[index],
  116. ((const UA_Float*)data2)[index]) <= (deadbandValue/100.0)*(fabs(range->high - range->low)) ||
  117. *(const UA_Float*)data1 > range->high)
  118. return false;
  119. } else if(type == &UA_TYPES[UA_TYPES_DOUBLE]) {
  120. if(ABS_SUBTRACT_TYPE_INDEPENDENT(((const UA_Double*)data1)[index],
  121. ((const UA_Double*)data2)[index]) <= (deadbandValue/100.0)*(fabs(range->high - range->low)) ||
  122. *(const UA_Double*)data1 > range->high)
  123. return false;
  124. }
  125. return true;
  126. }
  127. #endif /* UA_ENABLE_DA */
  128. static UA_INLINE UA_Boolean
  129. updateNeededForFilteredValue(const UA_Variant *value, const UA_Variant *oldValue,
  130. const UA_Double deadbandValue) {
  131. if(value->arrayLength != oldValue->arrayLength)
  132. return true;
  133. if(value->type != oldValue->type)
  134. return true;
  135. if (UA_Variant_isScalar(value)) {
  136. return outOfDeadBand(value->data, oldValue->data, 0, value->type, deadbandValue);
  137. }
  138. for (size_t i = 0; i < value->arrayLength; ++i) {
  139. if (outOfDeadBand(value->data, oldValue->data, i, value->type, deadbandValue))
  140. return true;
  141. }
  142. return false;
  143. }
  144. #ifdef UA_ENABLE_DA
  145. static UA_INLINE UA_Boolean
  146. updateNeededForFilteredPercentValue(const UA_Variant *value, const UA_Variant *oldValue,
  147. const UA_Double deadbandValue, UA_Range* euRange) {
  148. if(value->arrayLength != oldValue->arrayLength)
  149. return true;
  150. if(value->type != oldValue->type)
  151. return true;
  152. if (UA_Variant_isScalar(value)) {
  153. return outOfPercentDeadBand(value->data, oldValue->data, 0, value->type, deadbandValue, euRange);
  154. }
  155. for (size_t i = 0; i < value->arrayLength; ++i) {
  156. if (outOfPercentDeadBand(value->data, oldValue->data, i, value->type, deadbandValue, euRange))
  157. return true;
  158. }
  159. return false;
  160. }
  161. static UA_Boolean
  162. updateNeededForStatusCode(const UA_DataValue *value, const UA_MonitoredItem *mon) {
  163. if (UA_Variant_isScalar(&value->value)) {
  164. if(value->status != mon->lastStatus)
  165. return true;
  166. }
  167. return false;
  168. }
  169. #endif
  170. /* When a change is detected, encoding contains the heap-allocated binary
  171. * encoded value. The default for changed is false. */
  172. static UA_StatusCode
  173. detectValueChangeWithFilter(UA_Server *server, UA_MonitoredItem *mon, UA_DataValue *value,
  174. UA_ByteString *encoding, UA_Boolean *changed) {
  175. if(UA_DataType_isNumeric(value->value.type) &&
  176. (mon->filter.dataChangeFilter.trigger == UA_DATACHANGETRIGGER_STATUSVALUE ||
  177. mon->filter.dataChangeFilter.trigger == UA_DATACHANGETRIGGER_STATUSVALUETIMESTAMP)) {
  178. if(mon->filter.dataChangeFilter.deadbandType == UA_DEADBANDTYPE_ABSOLUTE) {
  179. if(!updateNeededForFilteredValue(&value->value, &mon->lastValue,
  180. mon->filter.dataChangeFilter.deadbandValue))
  181. return UA_STATUSCODE_GOOD;
  182. }
  183. #ifdef UA_ENABLE_DA
  184. else if(mon->filter.dataChangeFilter.deadbandType == UA_DEADBANDTYPE_PERCENT) {
  185. UA_QualifiedName qn = UA_QUALIFIEDNAME(0, "EURange");
  186. UA_BrowsePathResult bpr = UA_Server_browseSimplifiedBrowsePath(server, mon->monitoredNodeId, 1, &qn);
  187. if(bpr.statusCode != UA_STATUSCODE_GOOD || bpr.targetsSize < 1) { //if branch is not entried, property has been found
  188. UA_BrowsePathResult_deleteMembers(&bpr);
  189. return UA_STATUSCODE_GOOD;
  190. }
  191. const UA_VariableNode* node = (const UA_VariableNode*) UA_Nodestore_get(server, &bpr.targets->targetId.nodeId);
  192. UA_Range* euRange = (UA_Range*) node->value.data.value.value.data;
  193. if(!updateNeededForFilteredPercentValue(&value->value, &mon->lastValue,
  194. mon->filter.dataChangeFilter.deadbandValue, euRange)) {
  195. if(!updateNeededForStatusCode(value, mon)) //when same value, but different status code is written
  196. return UA_STATUSCODE_GOOD;
  197. }
  198. }
  199. #endif
  200. }
  201. /* Stack-allocate some memory for the value encoding. We might heap-allocate
  202. * more memory if needed. This is just enough for scalars and small
  203. * structures. */
  204. UA_STACKARRAY(UA_Byte, stackValueEncoding, UA_VALUENCODING_MAXSTACK);
  205. UA_ByteString valueEncoding;
  206. valueEncoding.data = stackValueEncoding;
  207. valueEncoding.length = UA_VALUENCODING_MAXSTACK;
  208. /* Encode the value */
  209. UA_Byte *bufPos = valueEncoding.data;
  210. const UA_Byte *bufEnd = &valueEncoding.data[valueEncoding.length];
  211. UA_StatusCode retval = UA_encodeBinary(value, &UA_TYPES[UA_TYPES_DATAVALUE],
  212. &bufPos, &bufEnd, NULL, NULL);
  213. if(retval == UA_STATUSCODE_BADENCODINGERROR) {
  214. size_t binsize = UA_calcSizeBinary(value, &UA_TYPES[UA_TYPES_DATAVALUE]);
  215. if(binsize == 0)
  216. return UA_STATUSCODE_BADENCODINGERROR;
  217. if(binsize > UA_VALUENCODING_MAXSTACK) {
  218. retval = UA_ByteString_allocBuffer(&valueEncoding, binsize);
  219. if(retval == UA_STATUSCODE_GOOD) {
  220. bufPos = valueEncoding.data;
  221. bufEnd = &valueEncoding.data[valueEncoding.length];
  222. retval = UA_encodeBinary(value, &UA_TYPES[UA_TYPES_DATAVALUE],
  223. &bufPos, &bufEnd, NULL, NULL);
  224. }
  225. }
  226. }
  227. if(retval != UA_STATUSCODE_GOOD) {
  228. if(valueEncoding.data != stackValueEncoding)
  229. UA_ByteString_deleteMembers(&valueEncoding);
  230. return retval;
  231. }
  232. /* Has the value changed? */
  233. valueEncoding.length = (uintptr_t)bufPos - (uintptr_t)valueEncoding.data;
  234. *changed = (!mon->lastSampledValue.data ||
  235. !UA_String_equal(&valueEncoding, &mon->lastSampledValue));
  236. /* No change */
  237. if(!(*changed)) {
  238. if(valueEncoding.data != stackValueEncoding)
  239. UA_ByteString_deleteMembers(&valueEncoding);
  240. return UA_STATUSCODE_GOOD;
  241. }
  242. /* Change detected. Copy encoding on the heap if necessary. */
  243. if(valueEncoding.data == stackValueEncoding)
  244. return UA_ByteString_copy(&valueEncoding, encoding);
  245. *encoding = valueEncoding;
  246. return UA_STATUSCODE_GOOD;
  247. }
  248. /* Has this sample changed from the last one? The method may allocate additional
  249. * space for the encoding buffer. Detect the change in encoding->data. */
  250. static UA_StatusCode
  251. detectValueChange(UA_Server *server, UA_MonitoredItem *mon,
  252. UA_DataValue value, UA_ByteString *encoding, UA_Boolean *changed) {
  253. /* Apply Filter */
  254. if(mon->filter.dataChangeFilter.trigger == UA_DATACHANGETRIGGER_STATUS)
  255. value.hasValue = false;
  256. value.hasServerTimestamp = false;
  257. value.hasServerPicoseconds = false;
  258. if(mon->filter.dataChangeFilter.trigger < UA_DATACHANGETRIGGER_STATUSVALUETIMESTAMP) {
  259. value.hasSourceTimestamp = false;
  260. value.hasSourcePicoseconds = false;
  261. }
  262. /* Detect the value change */
  263. return detectValueChangeWithFilter(server, mon, &value, encoding, changed);
  264. }
  265. /* movedValue returns whether the sample was moved to the notification. The
  266. * default is false. */
  267. static UA_StatusCode
  268. sampleCallbackWithValue(UA_Server *server, UA_Session *session,
  269. UA_Subscription *sub, UA_MonitoredItem *mon,
  270. UA_DataValue *value, UA_Boolean *movedValue) {
  271. UA_assert(mon->monitoredItemType == UA_MONITOREDITEMTYPE_CHANGENOTIFY);
  272. /* Contains heap-allocated binary encoding of the value if a change was detected */
  273. UA_ByteString binValueEncoding = UA_BYTESTRING_NULL;
  274. /* Has the value changed? Allocates memory in binValueEncoding if necessary.
  275. * value is edited internally so we make a shallow copy. */
  276. UA_Boolean changed = false;
  277. UA_StatusCode retval = detectValueChange(server, mon, *value, &binValueEncoding, &changed);
  278. if(retval != UA_STATUSCODE_GOOD) {
  279. UA_LOG_WARNING_SESSION(&server->config.logger, session, "Subscription %u | "
  280. "MonitoredItem %i | Value change detection failed with StatusCode %s",
  281. sub ? sub->subscriptionId : 0, mon->monitoredItemId,
  282. UA_StatusCode_name(retval));
  283. return retval;
  284. }
  285. if(!changed) {
  286. UA_LOG_DEBUG_SESSION(&server->config.logger, session, "Subscription %u | "
  287. "MonitoredItem %i | The value has not changed",
  288. sub ? sub->subscriptionId : 0, mon->monitoredItemId);
  289. return UA_STATUSCODE_GOOD;
  290. }
  291. /* The MonitoredItem is attached to a subscription (not server-local).
  292. * Prepare a notification and enqueue it. */
  293. if(sub) {
  294. /* Allocate a new notification */
  295. UA_Notification *newNotification = (UA_Notification *)UA_malloc(sizeof(UA_Notification));
  296. if(!newNotification) {
  297. UA_ByteString_deleteMembers(&binValueEncoding);
  298. return UA_STATUSCODE_BADOUTOFMEMORY;
  299. }
  300. if(value->value.storageType == UA_VARIANT_DATA) {
  301. newNotification->data.value = *value; /* Move the value to the notification */
  302. *movedValue = true;
  303. } else { /* => (value->value.storageType == UA_VARIANT_DATA_NODELETE) */
  304. retval = UA_DataValue_copy(value, &newNotification->data.value);
  305. if(retval != UA_STATUSCODE_GOOD) {
  306. UA_ByteString_deleteMembers(&binValueEncoding);
  307. UA_free(newNotification);
  308. return retval;
  309. }
  310. }
  311. /* <-- Point of no return --> */
  312. UA_LOG_DEBUG_SESSION(&server->config.logger, session, "Subscription %u | "
  313. "MonitoredItem %i | Enqueue a new notification",
  314. sub ? sub->subscriptionId : 0, mon->monitoredItemId);
  315. newNotification->mon = mon;
  316. UA_Notification_enqueue(server, sub, mon, newNotification);
  317. }
  318. /* Store the encoding for comparison */
  319. UA_ByteString_deleteMembers(&mon->lastSampledValue);
  320. mon->lastSampledValue = binValueEncoding;
  321. /* Store the value for filter comparison (we don't want to decode
  322. * lastSampledValue in every iteration). Don't test the return code here. If
  323. * this fails, lastValue is empty and a notification will be forced for the
  324. * next deadband comparison. */
  325. if((mon->filter.dataChangeFilter.deadbandType == UA_DEADBANDTYPE_NONE ||
  326. mon->filter.dataChangeFilter.deadbandType == UA_DEADBANDTYPE_ABSOLUTE ||
  327. mon->filter.dataChangeFilter.deadbandType == UA_DEADBANDTYPE_PERCENT) &&
  328. (mon->filter.dataChangeFilter.trigger == UA_DATACHANGETRIGGER_STATUS ||
  329. mon->filter.dataChangeFilter.trigger == UA_DATACHANGETRIGGER_STATUSVALUE ||
  330. mon->filter.dataChangeFilter.trigger == UA_DATACHANGETRIGGER_STATUSVALUETIMESTAMP)) {
  331. UA_Variant_deleteMembers(&mon->lastValue);
  332. UA_Variant_copy(&value->value, &mon->lastValue);
  333. #ifdef UA_ENABLE_DA
  334. UA_StatusCode_deleteMembers(&mon->lastStatus);
  335. UA_StatusCode_copy(&value->status, &mon->lastStatus);
  336. #endif
  337. }
  338. /* Call the local callback if the MonitoredItem is not attached to a
  339. * subscription. Do this at the very end. Because the callback might delete
  340. * the subscription. */
  341. if(!sub) {
  342. UA_LocalMonitoredItem *localMon = (UA_LocalMonitoredItem*) mon;
  343. void *nodeContext = NULL;
  344. UA_Server_getNodeContext(server, mon->monitoredNodeId, &nodeContext);
  345. localMon->callback.dataChangeCallback(server, mon->monitoredItemId,
  346. localMon->context,
  347. &mon->monitoredNodeId,
  348. nodeContext, mon->attributeId,
  349. value);
  350. }
  351. return UA_STATUSCODE_GOOD;
  352. }
  353. void
  354. UA_MonitoredItem_sampleCallback(UA_Server *server, UA_MonitoredItem *monitoredItem) {
  355. UA_Subscription *sub = monitoredItem->subscription;
  356. UA_Session *session = &server->adminSession;
  357. if(sub)
  358. session = sub->session;
  359. UA_LOG_DEBUG_SESSION(&server->config.logger, session, "Subscription %u | "
  360. "MonitoredItem %i | Sample callback called",
  361. sub ? sub->subscriptionId : 0, monitoredItem->monitoredItemId);
  362. if(monitoredItem->monitoredItemType != UA_MONITOREDITEMTYPE_CHANGENOTIFY) {
  363. UA_LOG_DEBUG_SESSION(&server->config.logger, session, "Subscription %u | "
  364. "MonitoredItem %i | Not a data change notification",
  365. sub ? sub->subscriptionId : 0, monitoredItem->monitoredItemId);
  366. return;
  367. }
  368. /* Get the node */
  369. const UA_Node *node = UA_Nodestore_get(server, &monitoredItem->monitoredNodeId);
  370. /* Sample the value. The sample can still point into the node. */
  371. UA_DataValue value;
  372. UA_DataValue_init(&value);
  373. if(node) {
  374. UA_ReadValueId rvid;
  375. UA_ReadValueId_init(&rvid);
  376. rvid.nodeId = monitoredItem->monitoredNodeId;
  377. rvid.attributeId = monitoredItem->attributeId;
  378. rvid.indexRange = monitoredItem->indexRange;
  379. ReadWithNode(node, server, session, monitoredItem->timestampsToReturn, &rvid, &value);
  380. } else {
  381. value.hasStatus = true;
  382. value.status = UA_STATUSCODE_BADNODEIDUNKNOWN;
  383. }
  384. /* Operate on the sample */
  385. UA_Boolean movedValue = false;
  386. UA_StatusCode retval = sampleCallbackWithValue(server, session, sub, monitoredItem, &value, &movedValue);
  387. if(retval != UA_STATUSCODE_GOOD) {
  388. UA_LOG_WARNING_SESSION(&server->config.logger, session, "Subscription %u | "
  389. "MonitoredItem %i | Sampling returned the statuscode %s",
  390. sub ? sub->subscriptionId : 0, monitoredItem->monitoredItemId,
  391. UA_StatusCode_name(retval));
  392. }
  393. /* Delete the sample if it was not moved to the notification. */
  394. if(!movedValue)
  395. UA_DataValue_deleteMembers(&value); /* Does nothing for UA_VARIANT_DATA_NODELETE */
  396. if(node)
  397. UA_Nodestore_release(server, node);
  398. }
  399. #endif /* UA_ENABLE_SUBSCRIPTIONS */