common_addons.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  *   Copyright (C) 2013-2014 by Alexander Rykovanov                        *
00003  *   rykovanov.as@gmail.com                                                   *
00004  *                                                                            *
00005  *   This library is free software; you can redistribute it and/or modify     *
00006  *   it under the terms of the GNU Lesser General Public License as           *
00007  *   published by the Free Software Foundation; version 3 of the License.     *
00008  *                                                                            *
00009  *   This library is distributed in the hope that it will be useful,          *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00012  *   GNU Lesser General Public License for more details.                      *
00013  *                                                                            *
00014  *   You should have received a copy of the GNU Lesser General Public License *
00015  *   along with this library; if not, write to the                            *
00016  *   Free Software Foundation, Inc.,                                          *
00017  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.                *
00018  ******************************************************************************/
00019 
00020 #include <opc/ua/server/addons/common_addons.h>
00021 #include "endpoints_parameters.h"
00022 #include "server_object_addon.h"
00023 
00024 #include <opc/common/addons_core/config_file.h>
00025 #include <opc/ua/server/addons/asio_addon.h>
00026 #include <opc/ua/server/addons/address_space.h>
00027 #include <opc/ua/server/addons/endpoints_services.h>
00028 #include <opc/ua/server/addons/opcua_protocol.h>
00029 #include <opc/ua/server/addons/opc_tcp_async.h>
00030 #include <opc/ua/server/addons/services_registry.h>
00031 #include <opc/ua/server/addons/standard_address_space.h>
00032 #include <opc/ua/server/addons/subscription_service.h>
00033 
00034 #include <algorithm>
00035 
00036 namespace
00037 {
00038 
00039   using namespace OpcUa;
00040 
00041   void AddParameters(Common::AddonInformation& info, const Common::ParametersGroup& params)
00042   {
00043     info.Parameters.Groups = params.Groups;
00044     info.Parameters.Parameters = params.Parameters;
00045   }
00046 
00047   void CreateCommonAddonsConfiguration(const Common::AddonParameters& params, std::vector<Common::AddonInformation>& addons)
00048   {
00049     Common::AddonInformation endpointsRegistry = Server::CreateEndpointsRegistryAddon();
00050     Common::AddonInformation addressSpaceRegistry = Server::CreateAddressSpaceAddon();
00051     Common::AddonInformation asioAddon = Server::CreateAsioAddon();
00052     Common::AddonInformation subscriptionService = Server::CreateSubscriptionServiceAddon();
00053     Common::AddonInformation serverObject = Server::CreateServerObjectAddon();
00054 
00055     for (const Common::ParametersGroup& group : params.Groups)
00056     {
00057       if (group.Name == OpcUa::Server::EndpointsRegistryAddonId)
00058       {
00059         AddParameters(endpointsRegistry, group);
00060       }
00061 /*
00062       else if (group.Name == OpcUa::Server::OpcUaProtocolAddonId)
00063       {
00064         Common::AddonInformation binaryProtocol = Server::CreateBinaryServerAddon();
00065         AddParameters(binaryProtocol, group);
00066         addons.push_back(binaryProtocol);
00067       }
00068 */
00069       else if (group.Name == OpcUa::Server::AddressSpaceRegistryAddonId)
00070       {
00071         AddParameters(addressSpaceRegistry, group);
00072       }
00073       else if (group.Name == OpcUa::Server::AsyncOpcTcpAddonId)
00074       {
00075         Common::AddonInformation opcTcpAsync = Server::CreateOpcTcpAsyncAddon();
00076         AddParameters(opcTcpAsync, group);
00077         addons.push_back(opcTcpAsync);
00078       }
00079       else if (group.Name == OpcUa::Server::AsioAddonId)
00080       {
00081         AddParameters(asioAddon, group);
00082       }
00083       else if (group.Name == OpcUa::Server::SubscriptionServiceAddonId)
00084       {
00085         AddParameters(subscriptionService, group);
00086       }
00087       else if (group.Name == OpcUa::Server::ServerObjectAddonId)
00088       {
00089         AddParameters(serverObject, group);
00090       }
00091     }
00092 
00093     addons.push_back(endpointsRegistry);
00094     addons.push_back(addressSpaceRegistry);
00095     addons.push_back(asioAddon);
00096     addons.push_back(subscriptionService);
00097     addons.push_back(Server::CreateServicesRegistryAddon());
00098     addons.push_back(Server::CreateStandardNamespaceAddon());
00099     addons.push_back(serverObject);
00100   }
00101 
00102   inline void RegisterAddons(std::vector<Common::AddonInformation> addons, Common::AddonsManager& manager)
00103   {
00104     std::for_each(std::begin(addons), std::end(addons), [&manager](const Common::AddonInformation& addonConfig){
00105       manager.Register(addonConfig);
00106     });
00107   }
00108 
00109   Common::AddonParameters CreateAddonsParameters(const OpcUa::Server::Parameters& serverParams)
00110   {
00111     Common::Parameter debugMode("debug", std::to_string(serverParams.Debug));
00112 
00113     Common::AddonParameters addons;
00114 
00115     Common::ParametersGroup async("async");
00116     async.Parameters.push_back(Common::Parameter("threads", std::to_string(serverParams.ThreadsCount)));
00117     async.Parameters.push_back(debugMode);
00118     addons.Groups.push_back(async);
00119 
00120     Common::ParametersGroup addressSpace(OpcUa::Server::AddressSpaceRegistryAddonId);
00121     addressSpace.Parameters.push_back(debugMode);
00122     addons.Groups.push_back(addressSpace);
00123 
00124     Common::ParametersGroup endpointServices(OpcUa::Server::EndpointsRegistryAddonId);
00125     endpointServices.Parameters.push_back(debugMode);
00126     addons.Groups.push_back(endpointServices);
00127 
00128     Common::ParametersGroup subscriptionServices(OpcUa::Server::SubscriptionServiceAddonId);
00129     subscriptionServices.Parameters.push_back(debugMode);
00130     addons.Groups.push_back(subscriptionServices);
00131 
00132     Common::ParametersGroup opc_tcp(OpcUa::Server::AsyncOpcTcpAddonId);
00133     opc_tcp.Parameters.push_back(debugMode);
00134     OpcUa::Server::ApplicationData applicationData;
00135     applicationData.Application = serverParams.Endpoint.Server;
00136     applicationData.Endpoints.push_back(serverParams.Endpoint);
00137     opc_tcp.Groups = OpcUa::CreateCommonParameters({applicationData}, serverParams.Debug);
00138     addons.Groups.push_back(opc_tcp);
00139 
00140     return addons;
00141   }
00142 
00143 } // namespace
00144 
00145 namespace OpcUa
00146 {
00147   Common::AddonInformation Server::CreateServicesRegistryAddon()
00148   {
00149     Common::AddonInformation services;
00150     services.Factory = std::make_shared<OpcUa::Server::ServicesRegistryFactory>();
00151     services.Id = OpcUa::Server::ServicesRegistryAddonId;
00152     return services;
00153   }
00154 
00155   Common::AddonInformation Server::CreateAddressSpaceAddon()
00156   {
00157     Common::AddonInformation config;
00158     config.Factory = std::make_shared<OpcUa::Server::AddressSpaceAddonFactory>();
00159     config.Id = OpcUa::Server::AddressSpaceRegistryAddonId;
00160     config.Dependencies.push_back(OpcUa::Server::ServicesRegistryAddonId);
00161     return config;
00162   }
00163 
00164   Common::AddonInformation Server::CreateStandardNamespaceAddon()
00165   {
00166     Common::AddonInformation config;
00167     config.Factory = std::make_shared<OpcUa::Server::StandardNamespaceAddonFactory>();
00168     config.Id = OpcUa::Server::StandardNamespaceAddonId;
00169     config.Dependencies.push_back(OpcUa::Server::AddressSpaceRegistryAddonId);
00170     return config;
00171   }
00172 
00173   Common::AddonInformation Server::CreateEndpointsRegistryAddon()
00174   {
00175     Common::AddonInformation endpoints;
00176     endpoints.Factory = std::make_shared<OpcUa::Server::EndpointsRegistryAddonFactory>();
00177     endpoints.Id = OpcUa::Server::EndpointsRegistryAddonId;
00178     endpoints.Dependencies.push_back(OpcUa::Server::ServicesRegistryAddonId);
00179     return endpoints;
00180   }
00181 /*
00182   Common::AddonInformation Server::CreateBinaryServerAddon()
00183   {
00184     Common::AddonInformation opcTcp;
00185     opcTcp.Factory = std::make_shared<OpcUa::Server::OpcUaProtocolAddonFactory>();
00186     opcTcp.Id = OpcUa::Server::OpcUaProtocolAddonId;
00187     opcTcp.Dependencies.push_back(OpcUa::Server::EndpointsRegistryAddonId);
00188     opcTcp.Dependencies.push_back(OpcUa::Server::SubscriptionServiceAddonId);
00189     return opcTcp;
00190   }
00191 */
00192   Common::AddonInformation Server::CreateOpcTcpAsyncAddon()
00193   {
00194     Common::AddonInformation opcTcp;
00195     opcTcp.Factory = std::make_shared<OpcUa::Server::AsyncOpcTcpAddonFactory>();
00196     opcTcp.Id = OpcUa::Server::AsyncOpcTcpAddonId;
00197     opcTcp.Dependencies.push_back(OpcUa::Server::AsioAddonId);
00198     opcTcp.Dependencies.push_back(OpcUa::Server::EndpointsRegistryAddonId);
00199     opcTcp.Dependencies.push_back(OpcUa::Server::SubscriptionServiceAddonId);
00200     return opcTcp;
00201   }
00202 
00203   Common::AddonInformation Server::CreateServerObjectAddon()
00204   {
00205     Common::AddonInformation serverObjectAddon;
00206     serverObjectAddon.Factory = std::make_shared<OpcUa::Server::ServerObjectFactory>();
00207     serverObjectAddon.Id = OpcUa::Server::ServerObjectAddonId;
00208     serverObjectAddon.Dependencies.push_back(OpcUa::Server::StandardNamespaceAddonId);
00209     serverObjectAddon.Dependencies.push_back(OpcUa::Server::ServicesRegistryAddonId);
00210     serverObjectAddon.Dependencies.push_back(OpcUa::Server::AsioAddonId);
00211     return serverObjectAddon;
00212   }
00213 
00214   Common::AddonInformation Server::CreateAsioAddon()
00215   {
00216     Common::AddonInformation asioAddon;
00217     asioAddon.Factory = std::make_shared<OpcUa::Server::AsioAddonFactory>();
00218     asioAddon.Id = OpcUa::Server::AsioAddonId;
00219     return asioAddon;
00220   }
00221 
00222   Common::AddonInformation Server::CreateSubscriptionServiceAddon()
00223   {
00224     Common::AddonInformation subscriptionAddon;
00225     subscriptionAddon.Factory = std::make_shared<OpcUa::Server::SubscriptionServiceAddonFactory>();
00226     subscriptionAddon.Id = OpcUa::Server::SubscriptionServiceAddonId;
00227     subscriptionAddon.Dependencies.push_back(OpcUa::Server::AsioAddonId);
00228     subscriptionAddon.Dependencies.push_back(OpcUa::Server::AddressSpaceRegistryAddonId);
00229     subscriptionAddon.Dependencies.push_back(OpcUa::Server::ServicesRegistryAddonId);
00230     return subscriptionAddon;
00231   }
00232 
00233   void Server::RegisterCommonAddons(const Parameters& serverParams, Common::AddonsManager& manager)
00234   {
00235     std::vector<Common::AddonInformation> addons;
00236     Common::AddonParameters addonParameters = CreateAddonsParameters(serverParams);
00237     CreateCommonAddonsConfiguration(addonParameters, addons);
00238     RegisterAddons(addons, manager);
00239   }
00240 
00241   void Server::LoadConfiguration(const std::string& configDirectoryPath, Common::AddonsManager& manager)
00242   {
00243     const Common::Configuration& configuration = Common::ParseConfigurationFiles(configDirectoryPath);
00244     std::vector<Common::AddonInformation> addons(configuration.Modules.size());
00245     // modules are dynamic addons.
00246     std::transform(configuration.Modules.begin(), configuration.Modules.end(), addons.begin(), [] (const Common::ModuleConfiguration& module){
00247         return Common::GetAddonInfomation(module);
00248     });
00249     CreateCommonAddonsConfiguration(configuration.Parameters, addons);
00250         RegisterAddons(addons, manager);
00251   }
00252 
00253 }


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