ua_services_subscription.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifdef ENABLESUBSCRIPTIONS
  2. #include "ua_services.h"
  3. #include "ua_server_internal.h"
  4. #include "ua_subscription_manager.h"
  5. #include "ua_statuscodes.h"
  6. #include "ua_util.h"
  7. #include "ua_log.h" // Remove later, debugging only
  8. #define UA_BOUNDEDVALUE_SETWBOUNDS(BOUNDS, SRC, DST) { \
  9. if (SRC > BOUNDS.maxValue) DST = BOUNDS.maxValue; \
  10. else if (SRC < BOUNDS.minValue) DST = BOUNDS.minValue; \
  11. else DST = SRC; \
  12. }
  13. UA_Int32 Service_CreateSubscription(UA_Server *server, UA_Session *session,
  14. const UA_CreateSubscriptionRequest *request,
  15. UA_CreateSubscriptionResponse *response) {
  16. UA_Subscription *newSubscription;
  17. // Verify Session
  18. response->responseHeader.serviceResult = UA_STATUSCODE_GOOD;
  19. if (session == NULL ) response->responseHeader.serviceResult = UA_STATUSCODE_BADSESSIONIDINVALID;
  20. else if ( session->channel == NULL || session->activated == UA_FALSE) response->responseHeader.serviceResult = UA_STATUSCODE_BADSESSIONNOTACTIVATED;
  21. if ( response->responseHeader.serviceResult != UA_STATUSCODE_GOOD) return 0;
  22. // Create Subscription and Response
  23. response->subscriptionId = ++(server->subscriptionManager.LastSessionID);
  24. newSubscription = UA_Subscription_new(response->subscriptionId);
  25. UA_BOUNDEDVALUE_SETWBOUNDS(server->subscriptionManager.GlobalPublishingInterval, request->requestedPublishingInterval, response->revisedPublishingInterval);
  26. newSubscription->PublishingInterval = response->revisedPublishingInterval;
  27. UA_BOUNDEDVALUE_SETWBOUNDS(server->subscriptionManager.GlobalLifeTimeCount, request->requestedLifetimeCount, response->revisedLifetimeCount);
  28. newSubscription->LifeTime = (UA_UInt32_BoundedValue) { .minValue=server->subscriptionManager.GlobalLifeTimeCount.minValue, .maxValue=server->subscriptionManager.GlobalLifeTimeCount.maxValue, .currentValue=response->revisedLifetimeCount};
  29. UA_BOUNDEDVALUE_SETWBOUNDS(server->subscriptionManager.GlobalKeepAliveCount, request->requestedMaxKeepAliveCount, response->revisedMaxKeepAliveCount);
  30. newSubscription->KeepAliveCount = (UA_UInt32_BoundedValue) { .minValue=server->subscriptionManager.GlobalKeepAliveCount.minValue, .maxValue=server->subscriptionManager.GlobalKeepAliveCount.maxValue, .currentValue=response->revisedMaxKeepAliveCount};
  31. newSubscription->NotificationsPerPublish = request->maxNotificationsPerPublish;
  32. newSubscription->PublishingMode = request->publishingEnabled;
  33. newSubscription->Priority = request->priority;
  34. SubscriptionManager_addSubscription(&(server->subscriptionManager), newSubscription);
  35. return (UA_Int32) 0;
  36. }
  37. #endif //#ifdef ENABLESUBSCRIPTIONS