Browse Source

Unify deletion of Notifications

With this, we can use a single code-path when events are added and
deletion gets more complicated.
Julius Pfrommer 7 years ago
parent
commit
0258d47d47

+ 1 - 3
src/server/ua_services_subscription.c

@@ -458,9 +458,7 @@ Operation_SetMonitoringMode(UA_Server *server, UA_Session *session,
             TAILQ_REMOVE(&mon->queue, notification, listEntry);
             TAILQ_REMOVE(&smc->sub->notificationQueue, notification, globalEntry);
             --smc->sub->notificationQueueSize;
-
-            UA_DataValue_deleteMembers(&notification->data.value);
-            UA_free(notification);
+            UA_Notification_delete(notification);
         }
         mon->queueSize = 0;
 

+ 10 - 0
src/server/ua_subscription.c

@@ -19,6 +19,16 @@
 
 #ifdef UA_ENABLE_SUBSCRIPTIONS /* conditional compilation */
 
+void UA_Notification_delete(UA_Notification *n) {
+    if(n->mon->monitoredItemType == UA_MONITOREDITEMTYPE_CHANGENOTIFY) {
+        UA_DataValue_deleteMembers(&n->data.value);
+    } else {
+        // TODO: Event-Handling
+    }
+
+    UA_free(n);
+}
+
 UA_Subscription *
 UA_Subscription_new(UA_Session *session, UA_UInt32 subscriptionId) {
     /* Allocate the memory */

+ 3 - 0
src/server/ua_subscription.h

@@ -62,6 +62,9 @@ typedef struct UA_Notification {
     } data;
 } UA_Notification;
 
+/* Clean up the notification. Must be removed from the lists first. */
+void UA_Notification_delete(UA_Notification *n);
+
 typedef TAILQ_HEAD(NotificationQueue, UA_Notification) NotificationQueue;
 
 struct UA_MonitoredItem {

+ 2 - 12
src/server/ua_subscription_datachange.c

@@ -45,8 +45,7 @@ MonitoredItem_delete(UA_Server *server, UA_MonitoredItem *monitoredItem) {
             TAILQ_REMOVE(&sub->notificationQueue, notification, globalEntry);
             --sub->notificationQueueSize;
 
-            UA_DataValue_deleteMembers(&notification->data.value);
-            UA_free(notification);
+            UA_Notification_delete(notification);
         }
         monitoredItem->queueSize = 0;
     } else {
@@ -105,16 +104,7 @@ void MonitoredItem_ensureQueueSpace(UA_MonitoredItem *mon) {
         --sub->notificationQueueSize;
 
         /* Free the notification */
-        if(mon->monitoredItemType == UA_MONITOREDITEMTYPE_CHANGENOTIFY) {
-            UA_DataValue_deleteMembers(&del->data.value);
-        } else {
-            /* TODO: event implemantation */
-        }
-
-        /* Work around a false positive in clang analyzer */
-#ifndef __clang_analyzer__
-        UA_free(del);
-#endif
+        UA_Notification_delete(del);
     }
 
     if(mon->monitoredItemType == UA_MONITOREDITEMTYPE_CHANGENOTIFY) {