ua_subscription_datachange.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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 =
  192. (const UA_VariableNode*) UA_Nodestore_getNode(server->nsCtx, &bpr.targets->targetId.nodeId);
  193. UA_Range* euRange = (UA_Range*) node->value.data.value.value.data;
  194. if(!updateNeededForFilteredPercentValue(&value->value, &mon->lastValue,
  195. mon->filter.dataChangeFilter.deadbandValue, euRange)) {
  196. if(!updateNeededForStatusCode(value, mon)) //when same value, but different status code is written
  197. return UA_STATUSCODE_GOOD;
  198. }
  199. }
  200. #endif
  201. }
  202. /* Stack-allocate some memory for the value encoding. We might heap-allocate
  203. * more memory if needed. This is just enough for scalars and small
  204. * structures. */
  205. UA_STACKARRAY(UA_Byte, stackValueEncoding, UA_VALUENCODING_MAXSTACK);
  206. UA_ByteString valueEncoding;
  207. valueEncoding.data = stackValueEncoding;
  208. valueEncoding.length = UA_VALUENCODING_MAXSTACK;
  209. /* Encode the value */
  210. UA_Byte *bufPos = valueEncoding.data;
  211. const UA_Byte *bufEnd = &valueEncoding.data[valueEncoding.length];
  212. UA_StatusCode retval = UA_encodeBinary(value, &UA_TYPES[UA_TYPES_DATAVALUE],
  213. &bufPos, &bufEnd, NULL, NULL);
  214. if(retval == UA_STATUSCODE_BADENCODINGERROR) {
  215. size_t binsize = UA_calcSizeBinary(value, &UA_TYPES[UA_TYPES_DATAVALUE]);
  216. if(binsize == 0)
  217. return UA_STATUSCODE_BADENCODINGERROR;
  218. if(binsize > UA_VALUENCODING_MAXSTACK) {
  219. retval = UA_ByteString_allocBuffer(&valueEncoding, binsize);
  220. if(retval == UA_STATUSCODE_GOOD) {
  221. bufPos = valueEncoding.data;
  222. bufEnd = &valueEncoding.data[valueEncoding.length];
  223. retval = UA_encodeBinary(value, &UA_TYPES[UA_TYPES_DATAVALUE],
  224. &bufPos, &bufEnd, NULL, NULL);
  225. }
  226. }
  227. }
  228. if(retval != UA_STATUSCODE_GOOD) {
  229. if(valueEncoding.data != stackValueEncoding)
  230. UA_ByteString_deleteMembers(&valueEncoding);
  231. return retval;
  232. }
  233. /* Has the value changed? */
  234. valueEncoding.length = (uintptr_t)bufPos - (uintptr_t)valueEncoding.data;
  235. *changed = (!mon->lastSampledValue.data ||
  236. !UA_String_equal(&valueEncoding, &mon->lastSampledValue));
  237. /* No change */
  238. if(!(*changed)) {
  239. if(valueEncoding.data != stackValueEncoding)
  240. UA_ByteString_deleteMembers(&valueEncoding);
  241. return UA_STATUSCODE_GOOD;
  242. }
  243. /* Change detected. Copy encoding on the heap if necessary. */
  244. if(valueEncoding.data == stackValueEncoding)
  245. return UA_ByteString_copy(&valueEncoding, encoding);
  246. *encoding = valueEncoding;
  247. return UA_STATUSCODE_GOOD;
  248. }
  249. /* Has this sample changed from the last one? The method may allocate additional
  250. * space for the encoding buffer. Detect the change in encoding->data. */
  251. static UA_StatusCode
  252. detectValueChange(UA_Server *server, UA_MonitoredItem *mon,
  253. UA_DataValue value, UA_ByteString *encoding, UA_Boolean *changed) {
  254. /* Apply Filter */
  255. if(mon->filter.dataChangeFilter.trigger == UA_DATACHANGETRIGGER_STATUS)
  256. value.hasValue = false;
  257. value.hasServerTimestamp = false;
  258. value.hasServerPicoseconds = false;
  259. if(mon->filter.dataChangeFilter.trigger < UA_DATACHANGETRIGGER_STATUSVALUETIMESTAMP) {
  260. value.hasSourceTimestamp = false;
  261. value.hasSourcePicoseconds = false;
  262. }
  263. /* Detect the value change */
  264. return detectValueChangeWithFilter(server, mon, &value, encoding, changed);
  265. }
  266. /* movedValue returns whether the sample was moved to the notification. The
  267. * default is false. */
  268. static UA_StatusCode
  269. sampleCallbackWithValue(UA_Server *server, UA_Session *session,
  270. UA_Subscription *sub, UA_MonitoredItem *mon,
  271. UA_DataValue *value, UA_Boolean *movedValue) {
  272. UA_assert(mon->attributeId != UA_ATTRIBUTEID_EVENTNOTIFIER);
  273. /* Contains heap-allocated binary encoding of the value if a change was detected */
  274. UA_ByteString binValueEncoding = UA_BYTESTRING_NULL;
  275. /* Has the value changed? Allocates memory in binValueEncoding if necessary.
  276. * value is edited internally so we make a shallow copy. */
  277. UA_Boolean changed = false;
  278. UA_StatusCode retval = detectValueChange(server, mon, *value, &binValueEncoding, &changed);
  279. if(retval != UA_STATUSCODE_GOOD) {
  280. UA_LOG_WARNING_SESSION(&server->config.logger, session, "Subscription %u | "
  281. "MonitoredItem %i | Value change detection failed with StatusCode %s",
  282. sub ? sub->subscriptionId : 0, mon->monitoredItemId,
  283. UA_StatusCode_name(retval));
  284. return retval;
  285. }
  286. if(!changed) {
  287. UA_LOG_DEBUG_SESSION(&server->config.logger, session, "Subscription %u | "
  288. "MonitoredItem %i | The value has not changed",
  289. sub ? sub->subscriptionId : 0, mon->monitoredItemId);
  290. return UA_STATUSCODE_GOOD;
  291. }
  292. /* The MonitoredItem is attached to a subscription (not server-local).
  293. * Prepare a notification and enqueue it. */
  294. if(sub) {
  295. /* Allocate a new notification */
  296. UA_Notification *newNotification = (UA_Notification *)UA_malloc(sizeof(UA_Notification));
  297. if(!newNotification) {
  298. UA_ByteString_deleteMembers(&binValueEncoding);
  299. return UA_STATUSCODE_BADOUTOFMEMORY;
  300. }
  301. if(value->value.storageType == UA_VARIANT_DATA) {
  302. newNotification->data.value = *value; /* Move the value to the notification */
  303. *movedValue = true;
  304. } else { /* => (value->value.storageType == UA_VARIANT_DATA_NODELETE) */
  305. retval = UA_DataValue_copy(value, &newNotification->data.value);
  306. if(retval != UA_STATUSCODE_GOOD) {
  307. UA_ByteString_deleteMembers(&binValueEncoding);
  308. UA_free(newNotification);
  309. return retval;
  310. }
  311. }
  312. /* <-- Point of no return --> */
  313. UA_LOG_DEBUG_SESSION(&server->config.logger, session, "Subscription %u | "
  314. "MonitoredItem %i | Enqueue a new notification",
  315. sub ? sub->subscriptionId : 0, mon->monitoredItemId);
  316. newNotification->mon = mon;
  317. UA_Notification_enqueue(server, sub, mon, newNotification);
  318. }
  319. /* Store the encoding for comparison */
  320. UA_ByteString_deleteMembers(&mon->lastSampledValue);
  321. mon->lastSampledValue = binValueEncoding;
  322. /* Store the value for filter comparison (we don't want to decode
  323. * lastSampledValue in every iteration). Don't test the return code here. If
  324. * this fails, lastValue is empty and a notification will be forced for the
  325. * next deadband comparison. */
  326. if((mon->filter.dataChangeFilter.deadbandType == UA_DEADBANDTYPE_NONE ||
  327. mon->filter.dataChangeFilter.deadbandType == UA_DEADBANDTYPE_ABSOLUTE ||
  328. mon->filter.dataChangeFilter.deadbandType == UA_DEADBANDTYPE_PERCENT) &&
  329. (mon->filter.dataChangeFilter.trigger == UA_DATACHANGETRIGGER_STATUS ||
  330. mon->filter.dataChangeFilter.trigger == UA_DATACHANGETRIGGER_STATUSVALUE ||
  331. mon->filter.dataChangeFilter.trigger == UA_DATACHANGETRIGGER_STATUSVALUETIMESTAMP)) {
  332. UA_Variant_deleteMembers(&mon->lastValue);
  333. UA_Variant_copy(&value->value, &mon->lastValue);
  334. #ifdef UA_ENABLE_DA
  335. UA_StatusCode_deleteMembers(&mon->lastStatus);
  336. UA_StatusCode_copy(&value->status, &mon->lastStatus);
  337. #endif
  338. }
  339. /* Call the local callback if the MonitoredItem is not attached to a
  340. * subscription. Do this at the very end. Because the callback might delete
  341. * the subscription. */
  342. if(!sub) {
  343. UA_LocalMonitoredItem *localMon = (UA_LocalMonitoredItem*) mon;
  344. void *nodeContext = NULL;
  345. UA_Server_getNodeContext(server, mon->monitoredNodeId, &nodeContext);
  346. localMon->callback.dataChangeCallback(server, mon->monitoredItemId,
  347. localMon->context,
  348. &mon->monitoredNodeId,
  349. nodeContext, mon->attributeId,
  350. value);
  351. }
  352. return UA_STATUSCODE_GOOD;
  353. }
  354. void
  355. UA_MonitoredItem_sampleCallback(UA_Server *server, UA_MonitoredItem *monitoredItem) {
  356. UA_Subscription *sub = monitoredItem->subscription;
  357. UA_Session *session = &server->adminSession;
  358. if(sub)
  359. session = sub->session;
  360. UA_LOG_DEBUG_SESSION(&server->config.logger, session, "Subscription %u | "
  361. "MonitoredItem %i | Sample callback called",
  362. sub ? sub->subscriptionId : 0, monitoredItem->monitoredItemId);
  363. UA_assert(monitoredItem->attributeId != UA_ATTRIBUTEID_EVENTNOTIFIER);
  364. /* Get the node */
  365. const UA_Node *node = UA_Nodestore_getNode(server->nsCtx, &monitoredItem->monitoredNodeId);
  366. /* Sample the value. The sample can still point into the node. */
  367. UA_DataValue value;
  368. UA_DataValue_init(&value);
  369. if(node) {
  370. UA_ReadValueId rvid;
  371. UA_ReadValueId_init(&rvid);
  372. rvid.nodeId = monitoredItem->monitoredNodeId;
  373. rvid.attributeId = monitoredItem->attributeId;
  374. rvid.indexRange = monitoredItem->indexRange;
  375. ReadWithNode(node, server, session, monitoredItem->timestampsToReturn, &rvid, &value);
  376. } else {
  377. value.hasStatus = true;
  378. value.status = UA_STATUSCODE_BADNODEIDUNKNOWN;
  379. }
  380. /* Operate on the sample */
  381. UA_Boolean movedValue = false;
  382. UA_StatusCode retval = sampleCallbackWithValue(server, session, sub, monitoredItem, &value, &movedValue);
  383. if(retval != UA_STATUSCODE_GOOD) {
  384. UA_LOG_WARNING_SESSION(&server->config.logger, session, "Subscription %u | "
  385. "MonitoredItem %i | Sampling returned the statuscode %s",
  386. sub ? sub->subscriptionId : 0, monitoredItem->monitoredItemId,
  387. UA_StatusCode_name(retval));
  388. }
  389. /* Delete the sample if it was not moved to the notification. */
  390. if(!movedValue)
  391. UA_DataValue_deleteMembers(&value); /* Does nothing for UA_VARIANT_DATA_NODELETE */
  392. if(node)
  393. UA_Nodestore_releaseNode(server->nsCtx, node);
  394. }
  395. #endif /* UA_ENABLE_SUBSCRIPTIONS */