subscription_service_addon.cpp
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 #include <opc/ua/server/addons/subscription_service.h>
00012 
00013 #include <opc/ua/server/addons/address_space.h>
00014 #include <opc/ua/server/addons/asio_addon.h>
00015 #include <opc/ua/server/addons/services_registry.h>
00016 #include <opc/ua/server/address_space.h>
00017 #include <opc/ua/server/subscription_service.h>
00018 
00019 #include <iostream>
00020 
00021 namespace
00022 {
00023 
00024   class SubscriptionAddon:
00025         public Common::Addon,
00026         public OpcUa::Server::SubscriptionService
00027   {
00028   public:
00029     void Initialize(Common::AddonsManager& manager, const Common::AddonParameters& parameters)
00030     {
00031       ApplyAddonParameters(parameters);
00032       Services = manager.GetAddon<OpcUa::Server::ServicesRegistry>(OpcUa::Server::ServicesRegistryAddonId);
00033       OpcUa::Server::AddressSpace::SharedPtr addressSpace = manager.GetAddon<OpcUa::Server::AddressSpace>(OpcUa::Server::AddressSpaceRegistryAddonId);
00034       OpcUa::Server::AsioAddon::SharedPtr asio = manager.GetAddon<OpcUa::Server::AsioAddon>(OpcUa::Server::AsioAddonId);
00035       Subscriptions = OpcUa::Server::CreateSubscriptionService(addressSpace, asio->GetIoService(), Debug);
00036       Services->RegisterSubscriptionServices(Subscriptions);
00037     }
00038 
00039     void Stop()
00040     {
00041       Services->UnregisterSubscriptionServices();
00042       Subscriptions.reset();
00043       Services.reset();
00044     }
00045 
00046   public:
00047     void TriggerEvent(OpcUa::NodeId node, OpcUa::Event event)
00048     {
00049       Subscriptions->TriggerEvent(node, event);
00050     }
00051 
00052   public:
00053     OpcUa::SubscriptionData CreateSubscription(const OpcUa::CreateSubscriptionRequest& request, std::function<void (OpcUa::PublishResult)> callback)
00054     {
00055       return Subscriptions->CreateSubscription(request, callback);
00056     }
00057 
00058     std::vector<OpcUa::StatusCode> DeleteSubscriptions(const std::vector<uint32_t>& subscriptions)
00059     {
00060       return Subscriptions->DeleteSubscriptions(subscriptions);
00061     }
00062 
00063     void Publish(const OpcUa::PublishRequest& request)
00064     {
00065       Subscriptions->Publish(request);
00066     }
00067 
00068     OpcUa::RepublishResponse Republish(const OpcUa::RepublishParameters& request)
00069     {
00070       return Subscriptions->Republish(request);
00071     }
00072 
00073     std::vector<OpcUa::MonitoredItemCreateResult> CreateMonitoredItems(const OpcUa::MonitoredItemsParameters& parameters)
00074     {
00075       return Subscriptions->CreateMonitoredItems(parameters);
00076     }
00077 
00078     std::vector<OpcUa::StatusCode> DeleteMonitoredItems(const OpcUa::DeleteMonitoredItemsParameters& parameters)
00079     {
00080       return Subscriptions->DeleteMonitoredItems(parameters);
00081     }
00082 
00083 
00084   private:
00085     void ApplyAddonParameters(const Common::AddonParameters& addons)
00086     {
00087       for (const Common::Parameter parameter : addons.Parameters)
00088       {
00089         if (parameter.Name == "debug" && !parameter.Value.empty() && parameter.Value != "0")
00090         {
00091           std::cout << "SubscriptionService | Debug mode enabled." << std::endl;
00092           Debug = true;
00093         }
00094       }
00095     }
00096 
00097   private:
00098     SubscriptionService::SharedPtr Subscriptions;
00099     OpcUa::Server::ServicesRegistry::SharedPtr Services;
00100     bool Debug = false;
00101   };
00102 
00103 }
00104 
00105 namespace OpcUa
00106 {
00107   namespace Server
00108   {
00109     Common::Addon::UniquePtr SubscriptionServiceAddonFactory::CreateAddon()
00110     {
00111           return Common::Addon::UniquePtr(new SubscriptionAddon());
00112     }
00113   }
00114 }


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Sat Jun 8 2019 18:24:57