ua_subscription_datachange.c 21 KB

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