endpoints_services_addon.cpp
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 #include "endpoints_parameters.h"
00012 
00013 #include <opc/ua/server/addons/endpoints_services.h>
00014 
00015 #include <opc/common/addons_core/addon_manager.h>
00016 #include <opc/ua/server/addons/services_registry.h>
00017 #include <opc/ua/services/endpoints.h>
00018 
00019 using namespace OpcUa;
00020 using namespace OpcUa::Server;
00021 
00022 
00023 namespace
00024 {
00025 
00026   class EndpointsAddon : public Common::Addon, public EndpointsRegistry
00027   {
00028   public:
00029     virtual void Initialize(Common::AddonsManager& addons, const Common::AddonParameters& params) override
00030     {
00031       ApplyAddonParameters(params);
00032 
00033       Endpoints = OpcUa::Server::CreateEndpointsRegistry();
00034       InternalServer = addons.GetAddon<ServicesRegistry>(ServicesRegistryAddonId);
00035       InternalServer->RegisterEndpointsServices(Endpoints);
00036 
00037       const std::vector<OpcUa::Server::ApplicationData>& data = OpcUa::ParseEndpointsParameters(params.Groups, Debug);
00038       for (const OpcUa::Server::ApplicationData& application : data)
00039       {
00040         Endpoints->AddApplications(std::vector<OpcUa::ApplicationDescription>(1, application.Application));
00041         Endpoints->AddEndpoints(application.Endpoints);
00042       }
00043     }
00044 
00045     virtual void Stop() override
00046     {
00047       InternalServer->UnregisterEndpointsServices();
00048       InternalServer.reset();
00049       Endpoints.reset();
00050     }
00051 
00052     virtual void AddEndpoints(const std::vector<EndpointDescription>& endpoints) override
00053     {
00054       Endpoints->AddEndpoints(endpoints);
00055     }
00056 
00057     virtual void AddApplications(const std::vector<OpcUa::ApplicationDescription>& applications) override
00058     {
00059       Endpoints->AddApplications(applications);
00060     }
00061 
00062 
00063     virtual std::vector<ApplicationDescription> FindServers(const FindServersParameters& params) const
00064     {
00065       return Endpoints->FindServers(params);
00066     }
00067 
00068     virtual std::vector<EndpointDescription> GetEndpoints(const GetEndpointsParameters& filter) const
00069     {
00070       return Endpoints->GetEndpoints(filter);
00071     }
00072 
00073     virtual void RegisterServer(const ServerParameters& parameters)
00074     {
00075       Endpoints->RegisterServer(parameters);
00076     }
00077 
00078   private:
00079     void ApplyAddonParameters(const Common::AddonParameters& addons)
00080     {
00081       for (const Common::Parameter parameter : addons.Parameters)
00082       {
00083         if (parameter.Name == "debug" && !parameter.Value.empty() && parameter.Value != "0")
00084         {
00085           Debug = true;
00086         }
00087       }
00088     }
00089 
00090   private:
00091     EndpointsRegistry::SharedPtr Endpoints;
00092     ServicesRegistry::SharedPtr InternalServer;
00093     bool Debug = false;
00094   };
00095 
00096 } // namespace
00097 
00098 
00099 namespace OpcUa
00100 {
00101   namespace Server
00102   {
00103     Common::Addon::UniquePtr EndpointsRegistryAddonFactory::CreateAddon()
00104     {
00105       return Common::Addon::UniquePtr(new ::EndpointsAddon());
00106     }
00107   }
00108 }
00109 


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