Selaa lähdekoodia

Adding/Deleting of subscriptions. Fixed Segfault on LIST_INIT.

ichrispa 10 vuotta sitten
vanhempi
commit
21c0651751
2 muutettua tiedostoa jossa 50 lisäystä ja 23 poistoa
  1. 32 10
      src/server/ua_subscription_manager.c
  2. 18 13
      src/server/ua_subscription_manager.h

+ 32 - 10
src/server/ua_subscription_manager.c

@@ -3,39 +3,61 @@
 #include "ua_server_internal.h"
 #include "ua_subscription_manager.h"
 
+#include <stdio.h> // Remove later, debugging only
+
 void SubscriptionManager_init(UA_Server *server) {
     UA_SubscriptionManager *manager = &(server->subscriptionManager);
 
-    manager->LastSessionID = (UA_UInt32) (server->random_seed + (UA_UInt32)UA_DateTime_now());
     /* FIXME: These init values are empirical. Maybe they should be part
      *        of the server config? */
-    manager->GlobalPublishingInterval = (UA_Int32_BoundedValue) { .maxValue = 100, .minValue = 0, .currentValue=0 };
-    manager->GlobalLifeTimeCount      = (UA_UInt32_BoundedValue) { .maxValue = 15000, .minValue = 0, .currentValue=0 };
-    manager->GlobalKeepAliveCount     = (UA_UInt32_BoundedValue) { .maxValue = 100, .minValue = 0, .currentValue=0 };
-    manager->GlobalNotificationsPerPublish = (UA_Int32_BoundedValue) { .maxValue = 1000, .minValue = 1, .currentValue=0 };
+    manager->GlobalPublishingInterval      = (UA_Int32_BoundedValue)  { .maxValue = 100,   .minValue = 0, .currentValue=0 };
+    manager->GlobalLifeTimeCount           = (UA_UInt32_BoundedValue) { .maxValue = 15000, .minValue = 0, .currentValue=0 };
+    manager->GlobalKeepAliveCount          = (UA_UInt32_BoundedValue) { .maxValue = 100,   .minValue = 0, .currentValue=0 };
+    manager->GlobalNotificationsPerPublish = (UA_Int32_BoundedValue)  { .maxValue = 1000,  .minValue = 1, .currentValue=0 };
     
+    manager->ServerSubscriptions = (UA_ListOfUASubscriptions *) malloc (sizeof(UA_ListOfUASubscriptions));
     LIST_INIT(manager->ServerSubscriptions);
+    
+    // Do this after the malloc to provide some basic degree of entropy
+    manager->LastSessionID = (UA_UInt32) (server->random_seed + (UA_UInt32)UA_DateTime_now());
     return;
 }
 
 UA_Subscription *UA_Subscription_new(UA_Int32 SubscriptionID) {
     UA_Subscription *new = (UA_Subscription *) malloc(sizeof(UA_Subscription));
     
+    new->SubscriptionID = SubscriptionID;
+    new->MonitoredItems = (UA_ListOfUAMonitoredItems *) malloc (sizeof(UA_ListOfUAMonitoredItems));
     LIST_INIT(new->MonitoredItems);
+    
     return new;
 }
 
-void SubscriptionManager_addSubscription(UA_SubscriptionManager *manager, UA_Subscription *newSubscription) {
+void SubscriptionManager_addSubscription(UA_SubscriptionManager *manager, UA_Subscription *newSubscription) {    
     LIST_INSERT_HEAD(manager->ServerSubscriptions, newSubscription, listEntry);
-    
+
     return;
 }
 
-void SubscriptionManager_getSubscriptionByID(UA_SubscriptionManager *manager, UA_Int32 SubscriptionID) {
-    return;
+UA_Subscription *SubscriptionManager_getSubscriptionByID(UA_SubscriptionManager *manager, UA_Int32 SubscriptionID) {
+    UA_Subscription *retsub, *sub;
+    retsub = (UA_Subscription *) NULL;
+    
+    for (sub = (manager->ServerSubscriptions)->lh_first; sub != NULL; sub = sub->listEntry.le_next) {
+        if (sub->SubscriptionID == SubscriptionID) {
+            retsub = sub;
+            break;
+        }
+    }
+    return retsub;
 }
 
-void SubscriptionManager_deleteSubscription(UA_SubscriptionManager *manager, UA_Subscription *subscription) {
+void SubscriptionManager_deleteSubscription(UA_SubscriptionManager *manager, UA_Int32 SubscriptionID) {
+    UA_Subscription *sub;
+    
+    sub = SubscriptionManager_getSubscriptionByID(manager, SubscriptionID);
+    if (sub != NULL) LIST_REMOVE(sub, listEntry);
+    
     return;
 }
 

+ 18 - 13
src/server/ua_subscription_manager.h

@@ -19,38 +19,43 @@ typedef struct {
 } UA_UInt32_BoundedValue;
 
 typedef struct UA_MonitoredItem_s {
-    UA_NodeId node;
+    UA_UInt32 TimestampsToReturn;
+    UA_UInt32 MonitoringMode;
+    UA_NodeId ItemNodeId;
+    UA_UInt32 AttributeID;
+    // FIXME: indexRange is ignored; array values default to element 0
+    // FIXME: dataEncoding is hardcoded to UA binary
     LIST_ENTRY(UA_MonitoredItem_s) listEntry;
 } UA_MonitoredItem;
 
-
+typedef LIST_HEAD(UA_ListOfUAMonitoredItems_s, UA_MonitoredItem_s) UA_ListOfUAMonitoredItems;
 typedef struct UA_Subscription_s {
-    UA_UInt32_BoundedValue LiveTime;
+    UA_UInt32_BoundedValue LifeTime;
     UA_UInt32_BoundedValue KeepAliveCount;
-    UA_Int32  PublishingInterval;
-    UA_Int32  SubscriptionID;
-    UA_Int32  NotificationsPerPublish;
-    UA_Byte   PublishingMode;
-    UA_UInt32 Priority;
+    UA_Int32   PublishingInterval;
+    UA_Int32   SubscriptionID;
+    UA_Int32   NotificationsPerPublish;
+    UA_Boolean PublishingMode;
+    UA_UInt32  Priority;
     LIST_ENTRY(UA_Subscription_s) listEntry;
-    LIST_HEAD(ListOfUAMonitoredItems, UA_MonitoredItem_s) *MonitoredItems;
+    UA_ListOfUAMonitoredItems *MonitoredItems;
 } UA_Subscription;
 
-
+typedef LIST_HEAD(UA_ListOfUASubscriptions_s, UA_Subscription_s) UA_ListOfUASubscriptions;
 typedef struct UA_SubscriptionManager_s {
     UA_Int32_BoundedValue  GlobalPublishingInterval;
     UA_UInt32_BoundedValue GlobalLifeTimeCount;
     UA_UInt32_BoundedValue GlobalKeepAliveCount;
     UA_Int32_BoundedValue  GlobalNotificationsPerPublish;
     UA_Int32 LastSessionID;
-    LIST_HEAD(ListOfUASubscription, UA_Subscription_s) *ServerSubscriptions;
+    UA_ListOfUASubscriptions *ServerSubscriptions;
 } UA_SubscriptionManager;
 
 void SubscriptionManager_init(UA_Server *server);
 UA_Subscription *UA_Subscription_new(UA_Int32 SubscriptionID);
 void SubscriptionManager_addSubscription(UA_SubscriptionManager *manager, UA_Subscription *subscription);
-void SubscriptionManager_getSubscriptionByID(UA_SubscriptionManager *manager, UA_Int32 SubscriptionID);
-void SubscriptionManager_deleteSubscription(UA_SubscriptionManager *manager, UA_Subscription *subscription);
+UA_Subscription *SubscriptionManager_getSubscriptionByID(UA_SubscriptionManager *manager, UA_Int32 SubscriptionID);
+void SubscriptionManager_deleteSubscription(UA_SubscriptionManager *manager, UA_Int32 SubscriptionID);
 
 #endif  // ifndef... define UA_SUBSCRIPTION_MANAGER_H_
 #endif  // ifdef EnableSubscriptions ...