|
@@ -4,6 +4,7 @@
|
|
|
#include "ua_subscription_manager.h"
|
|
|
#include "ua_statuscodes.h"
|
|
|
#include "ua_util.h"
|
|
|
+#include "ua_nodestore.h"
|
|
|
|
|
|
|
|
|
#include "ua_log.h" // Remove later, debugging only
|
|
@@ -13,7 +14,7 @@
|
|
|
else if (SRC < BOUNDS.minValue) DST = BOUNDS.minValue; \
|
|
|
else DST = SRC; \
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
UA_Int32 Service_CreateSubscription(UA_Server *server, UA_Session *session,
|
|
|
const UA_CreateSubscriptionRequest *request,
|
|
|
UA_CreateSubscriptionResponse *response) {
|
|
@@ -47,4 +48,84 @@ UA_Int32 Service_CreateSubscription(UA_Server *server, UA_Session *session,
|
|
|
return (UA_Int32) 0;
|
|
|
}
|
|
|
|
|
|
+UA_Int32 Service_CreateMonitoredItems(UA_Server *server, UA_Session *session,
|
|
|
+ const UA_CreateMonitoredItemsRequest *request,
|
|
|
+ UA_CreateMonitoredItemsResponse *response) {
|
|
|
+ UA_MonitoredItem *newMon;
|
|
|
+ UA_Subscription *sub;
|
|
|
+ UA_MonitoredItemCreateResult *createResults, *thisItemsResult;
|
|
|
+ UA_MonitoredItemCreateRequest *thisItemsRequest;
|
|
|
+
|
|
|
+ // Verify Session and Subscription
|
|
|
+ response->responseHeader.serviceResult = UA_STATUSCODE_GOOD;
|
|
|
+ sub=SubscriptionManager_getSubscriptionByID(&(server->subscriptionManager), request->subscriptionId);
|
|
|
+ if (session == NULL ) response->responseHeader.serviceResult = UA_STATUSCODE_BADSESSIONIDINVALID;
|
|
|
+ else if ( session->channel == NULL || session->activated == UA_FALSE) response->responseHeader.serviceResult = UA_STATUSCODE_BADSESSIONNOTACTIVATED;
|
|
|
+ else if ( sub == NULL) response->responseHeader.serviceResult = UA_STATUSCODE_BADSUBSCRIPTIONIDINVALID;
|
|
|
+ if ( response->responseHeader.serviceResult != UA_STATUSCODE_GOOD) return 0;
|
|
|
+
|
|
|
+ // Allocate Result Array
|
|
|
+ if (request->itemsToCreateSize > 0) {
|
|
|
+ createResults = (UA_MonitoredItemCreateResult *) malloc(sizeof(UA_MonitoredItemCreateResult) * (request->itemsToCreateSize));
|
|
|
+ if (createResults == NULL) {
|
|
|
+ response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else return 0;
|
|
|
+
|
|
|
+ response->resultsSize = request->itemsToCreateSize;
|
|
|
+ response->results = createResults;
|
|
|
+
|
|
|
+ for(int i=0;i<request->itemsToCreateSize;i++) {
|
|
|
+ thisItemsRequest = &(request->itemsToCreate[i]);
|
|
|
+ thisItemsResult = &(createResults[i]);
|
|
|
+
|
|
|
+ // FIXME: Completely ignoring filters for now!
|
|
|
+ thisItemsResult->filterResult.typeId = UA_NODEID_NULL;
|
|
|
+ thisItemsResult->filterResult.encoding = UA_EXTENSIONOBJECT_ENCODINGMASK_NOBODYISENCODED;
|
|
|
+ thisItemsResult->filterResult.body = UA_BYTESTRING_NULL;
|
|
|
+
|
|
|
+ if (UA_NodeStore_get(server->nodestore, (const UA_NodeId *) &(thisItemsRequest->itemToMonitor.nodeId)) == UA_NULL) {
|
|
|
+ thisItemsResult->statusCode = UA_STATUSCODE_BADNODEIDINVALID;
|
|
|
+ thisItemsResult->monitoredItemId = 0;
|
|
|
+ thisItemsResult->revisedSamplingInterval = 0;
|
|
|
+ thisItemsResult->revisedQueueSize = 0;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ thisItemsResult->statusCode = UA_STATUSCODE_GOOD;
|
|
|
+
|
|
|
+ newMon = UA_MonitoredItem_new();
|
|
|
+ memcpy(&(newMon->ItemNodeId), &(thisItemsRequest->itemToMonitor.nodeId), sizeof(UA_NodeId));
|
|
|
+ newMon->ItemId = ++(server->subscriptionManager.LastSessionID);
|
|
|
+ thisItemsResult->monitoredItemId = newMon->ItemId;
|
|
|
+
|
|
|
+ newMon->ClientHandle = thisItemsRequest->requestedParameters.clientHandle;
|
|
|
+
|
|
|
+ UA_BOUNDEDVALUE_SETWBOUNDS(server->subscriptionManager.GlobalSamplingInterval , thisItemsRequest->requestedParameters.samplingInterval, thisItemsResult->revisedSamplingInterval);
|
|
|
+ newMon->SamplingInterval = thisItemsResult->revisedSamplingInterval;
|
|
|
+
|
|
|
+ UA_BOUNDEDVALUE_SETWBOUNDS(server->subscriptionManager.GlobalQueueSize, thisItemsRequest->requestedParameters.queueSize, thisItemsResult->revisedQueueSize);
|
|
|
+ newMon->QueueSize = thisItemsResult->revisedQueueSize;
|
|
|
+
|
|
|
+ LIST_INSERT_HEAD(sub->MonitoredItems, newMon, listEntry);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+UA_Int32 Service_Publish(UA_Server *server, UA_Session *session,
|
|
|
+ const UA_PublishRequest *request,
|
|
|
+ UA_PublishResponse *response) {
|
|
|
+ response->responseHeader.serviceResult = UA_STATUSCODE_BADSERVICEUNSUPPORTED;
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+UA_Int32 Service_DeleteSubscriptions(UA_Server *server, UA_Session *session,
|
|
|
+ const UA_DeleteSubscriptionsRequest *request,
|
|
|
+ UA_DeleteSubscriptionsResponse *response) {
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
#endif //#ifdef ENABLESUBSCRIPTIONS
|