Преглед на файлове

add setpublishingmode service

Julius Pfrommer преди 8 години
родител
ревизия
90145a1a94

+ 5 - 0
src/server/ua_server_binary.c

@@ -241,6 +241,11 @@ getServicePointers(UA_UInt32 requestTypeId, const UA_DataType **requestType,
         *requestType = &UA_TYPES[UA_TYPES_MODIFYSUBSCRIPTIONREQUEST];
         *responseType = &UA_TYPES[UA_TYPES_MODIFYSUBSCRIPTIONRESPONSE];
         break;
+	case UA_NS0ID_SETPUBLISHINGMODEREQUEST:
+		*service = (UA_Service)Service_SetPublishingMode;
+		*requestType = &UA_TYPES[UA_TYPES_SETPUBLISHINGMODEREQUEST];
+		*responseType = &UA_TYPES[UA_TYPES_SETPUBLISHINGMODERESPONSE];
+		break;
     case UA_NS0ID_DELETESUBSCRIPTIONSREQUEST:
         *service = (UA_Service)Service_DeleteSubscriptions;
         *requestType = &UA_TYPES[UA_TYPES_DELETESUBSCRIPTIONSREQUEST];

+ 5 - 1
src/server/ua_services.h

@@ -300,6 +300,11 @@ void Service_ModifySubscription(UA_Server *server, UA_Session *session,
                                 const UA_ModifySubscriptionRequest *request,
                                 UA_ModifySubscriptionResponse *response);
 
+/* Used to enable sending of Notifications on one or more Subscriptions. */
+void Service_SetPublishingMode(UA_Server *server, UA_Session *session,
+	                           const UA_SetPublishingModeRequest *request,
+	                           UA_SetPublishingModeResponse *response);
+
 /* Used for two purposes. First, it is used to acknowledge the receipt of
  * NotificationMessages for one or more Subscriptions. Second, it is used to
  * request the Server to return a NotificationMessage or a keep-alive
@@ -323,7 +328,6 @@ void Service_DeleteSubscriptions(UA_Server *server, UA_Session *session,
                                  const UA_DeleteSubscriptionsRequest *request,
                                  UA_DeleteSubscriptionsResponse *response);
 
-/* Not Implemented: Service_SetPublishingMode */
 /* Not Implemented: Service_TransferSubscription */
 
 #endif

+ 27 - 1
src/server/ua_services_subscription.c

@@ -39,7 +39,7 @@ void Service_CreateSubscription(UA_Server *server, UA_Session *session,
     }
 
     UA_Session_addSubscription(session, newSubscription);    
-    newSubscription->publishingMode = request->publishingEnabled;
+    newSubscription->publishingEnabled = request->publishingEnabled;
     setSubscriptionSettings(server, newSubscription, request->requestedPublishingInterval,
                             request->requestedLifetimeCount, request->requestedMaxKeepAliveCount,
                             request->maxNotificationsPerPublish, request->priority);
@@ -66,6 +66,32 @@ void Service_ModifySubscription(UA_Server *server, UA_Session *session,
     return;
 }
 
+void Service_SetPublishingMode(UA_Server *server, UA_Session *session,
+	const UA_SetPublishingModeRequest *request,	UA_SetPublishingModeResponse *response) {
+
+	if (request->subscriptionIdsSize <= 0) {
+		response->responseHeader.serviceResult = UA_STATUSCODE_BADNOTHINGTODO;
+		return;
+	}
+
+	size_t size = request->subscriptionIdsSize;
+	response->results = UA_Array_new(size, &UA_TYPES[UA_TYPES_STATUSCODE]);
+	if(!response->results) {
+		response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
+		return;
+	}
+
+	response->resultsSize = size;
+	for(size_t i = 0; i < size; i++) {
+		UA_Subscription *sub = UA_Session_getSubscriptionByID(session, request->subscriptionIds[i]);
+		if(!sub) {
+			response->results[i] = UA_STATUSCODE_BADSUBSCRIPTIONIDINVALID;
+			continue;
+		}
+		sub->publishingEnabled = request->publishingEnabled;
+	}
+}
+
 static void
 setMonitoredItemSettings(UA_Server *server, UA_MonitoredItem *mon,
                          UA_MonitoringMode monitoringMode, UA_UInt32 clientHandle,

+ 13 - 9
src/server/ua_subscription.c

@@ -141,6 +141,7 @@ UA_Subscription * UA_Subscription_new(UA_Session *session, UA_UInt32 subscriptio
     new->sequenceNumber = 1;
     new->currentKeepAliveCount = 0;
     new->maxKeepAliveCount = 0;
+	new->publishingEnabled = false;
     memset(&new->publishJobGuid, 0, sizeof(UA_Guid));
     new->publishJobIsRegistered = false;
     LIST_INIT(&new->retransmissionQueue);
@@ -194,15 +195,17 @@ UA_Subscription_deleteMonitoredItem(UA_Server *server, UA_Subscription *sub,
 static void PublishCallback(UA_Server *server, UA_Subscription *sub) {
     /* Count the available notifications */
     size_t notifications = 0;
-    UA_MonitoredItem *mon;
-    LIST_FOREACH(mon, &sub->MonitoredItems, listEntry) {
-        MonitoredItem_queuedValue *qv;
-        TAILQ_FOREACH(qv, &mon->queue, listEntry) {
-            if(notifications >= sub->notificationsPerPublish)
-                break;
-            notifications++;
-        }
-    }
+	if(sub->publishingEnabled) {
+		UA_MonitoredItem *mon;
+		LIST_FOREACH(mon, &sub->MonitoredItems, listEntry) {
+			MonitoredItem_queuedValue *qv;
+			TAILQ_FOREACH(qv, &mon->queue, listEntry) {
+				if(notifications >= sub->notificationsPerPublish)
+					break;
+				notifications++;
+			}
+		}
+	}
 
     /* Continue only if we have data or want to send a keepalive */
     if(notifications == 0) {
@@ -241,6 +244,7 @@ static void PublishCallback(UA_Server *server, UA_Subscription *sub) {
     dcn->monitoredItems = UA_Array_new(notifications, &UA_TYPES[UA_TYPES_MONITOREDITEMNOTIFICATION]);
     dcn->monitoredItemsSize = notifications;
     size_t l = 0;
+	UA_MonitoredItem *mon;
     LIST_FOREACH(mon, &sub->MonitoredItems, listEntry) {
         MonitoredItem_queuedValue *qv, *qv_tmp;
         TAILQ_FOREACH_SAFE(qv, &mon->queue, listEntry, qv_tmp) {

+ 1 - 1
src/server/ua_subscription.h

@@ -75,7 +75,7 @@ struct UA_Subscription {
     UA_Double publishingInterval;     // [ms] 
     UA_UInt32 subscriptionID;
     UA_UInt32 notificationsPerPublish;
-    UA_Boolean publishingMode;
+    UA_Boolean publishingEnabled;
     UA_UInt32 priority;
     UA_UInt32 sequenceNumber;
 

+ 2 - 0
tools/schema/datatypes_minimal.txt

@@ -143,6 +143,8 @@ QueryNextRequest
 QueryNextResponse
 CreateSubscriptionRequest
 CreateSubscriptionResponse
+SetPublishingModeRequest
+SetPublishingModeResponse
 DeleteMonitoredItemsRequest
 DeleteMonitoredItemsResponse
 NotificationMessage