common_addons.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2013-2014 by Alexander Rykovanov *
3  * rykovanov.as@gmail.com *
4  * *
5  * This library is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU Lesser General Public License as *
7  * published by the Free Software Foundation; version 3 of the License. *
8  * *
9  * This library is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU Lesser General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU Lesser General Public License *
15  * along with this library; if not, write to the *
16  * Free Software Foundation, Inc., *
17  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18  ******************************************************************************/
19 
21 #include "endpoints_parameters.h"
22 #include "server_object_addon.h"
23 
33 
34 #include <algorithm>
35 
36 namespace
37 {
38 
39 using namespace OpcUa;
40 
41 void AddParameters(Common::AddonInformation & info, const Common::ParametersGroup & params)
42 {
43  info.Parameters.Groups = params.Groups;
44  info.Parameters.Parameters = params.Parameters;
45 }
46 
47 void CreateCommonAddonsConfiguration(const Common::AddonParameters & params, std::vector<Common::AddonInformation> & addons)
48 {
54 
55  for (const Common::ParametersGroup & group : params.Groups)
56  {
58  {
59  AddParameters(endpointsRegistry, group);
60  }
61 
62  /*
63  else if (group.Name == OpcUa::Server::OpcUaProtocolAddonId)
64  {
65  Common::AddonInformation binaryProtocol = Server::CreateBinaryServerAddon();
66  AddParameters(binaryProtocol, group);
67  addons.push_back(binaryProtocol);
68  }
69  */
71  {
72  AddParameters(addressSpaceRegistry, group);
73  }
74 
75  else if (group.Name == OpcUa::Server::AsyncOpcTcpAddonId)
76  {
78  AddParameters(opcTcpAsync, group);
79  addons.push_back(opcTcpAsync);
80  }
81 
82  else if (group.Name == OpcUa::Server::AsioAddonId)
83  {
84  AddParameters(asioAddon, group);
85  }
86 
88  {
89  AddParameters(subscriptionService, group);
90  }
91 
92  else if (group.Name == OpcUa::Server::ServerObjectAddonId)
93  {
94  AddParameters(serverObject, group);
95  }
96  }
97 
98  addons.push_back(endpointsRegistry);
99  addons.push_back(addressSpaceRegistry);
100  addons.push_back(asioAddon);
101  addons.push_back(subscriptionService);
102  addons.push_back(Server::CreateServicesRegistryAddon());
103  addons.push_back(Server::CreateStandardNamespaceAddon());
104  addons.push_back(serverObject);
105 }
106 
107 inline void RegisterAddons(std::vector<Common::AddonInformation> addons, Common::AddonsManager & manager)
108 {
109  std::for_each(std::begin(addons), std::end(addons), [&manager](const Common::AddonInformation & addonConfig)
110  {
111  manager.Register(addonConfig);
112  });
113 }
114 
115 Common::AddonParameters CreateAddonsParameters(const OpcUa::Server::Parameters & serverParams, const Common::Logger::SharedPtr & logger)
116 {
117  Common::Parameter debugMode("debug", std::to_string(serverParams.Debug));
118 
120 
121  Common::ParametersGroup async("async");
122  async.Parameters.push_back(Common::Parameter("threads", std::to_string(serverParams.ThreadsCount)));
123  async.Parameters.push_back(debugMode);
124  addons.Groups.push_back(async);
125 
127  addressSpace.Parameters.push_back(debugMode);
128  addons.Groups.push_back(addressSpace);
129 
131  endpointServices.Parameters.push_back(debugMode);
132  addons.Groups.push_back(endpointServices);
133 
135  subscriptionServices.Parameters.push_back(debugMode);
136  addons.Groups.push_back(subscriptionServices);
137 
139  opc_tcp.Parameters.push_back(debugMode);
140  OpcUa::Server::ApplicationData applicationData;
141  applicationData.Application = serverParams.Endpoint.Server;
142  applicationData.Endpoints.push_back(serverParams.Endpoint);
143  opc_tcp.Groups = OpcUa::CreateCommonParameters({applicationData}, logger);
144  addons.Groups.push_back(opc_tcp);
145 
146  return addons;
147 }
148 
149 } // namespace
150 
151 namespace OpcUa
152 {
154 {
155  Common::AddonInformation services;
156  services.Factory = std::make_shared<OpcUa::Server::ServicesRegistryFactory>();
158  return services;
159 }
160 
162 {
164  config.Factory = std::make_shared<OpcUa::Server::AddressSpaceAddonFactory>();
167  return config;
168 }
169 
171 {
173  config.Factory = std::make_shared<OpcUa::Server::StandardNamespaceAddonFactory>();
176  return config;
177 }
178 
180 {
181  Common::AddonInformation endpoints;
182  endpoints.Factory = std::make_shared<OpcUa::Server::EndpointsRegistryAddonFactory>();
185  return endpoints;
186 }
187 /*
188  Common::AddonInformation Server::CreateBinaryServerAddon()
189  {
190  Common::AddonInformation opcTcp;
191  opcTcp.Factory = std::make_shared<OpcUa::Server::OpcUaProtocolAddonFactory>();
192  opcTcp.Id = OpcUa::Server::OpcUaProtocolAddonId;
193  opcTcp.Dependencies.push_back(OpcUa::Server::EndpointsRegistryAddonId);
194  opcTcp.Dependencies.push_back(OpcUa::Server::SubscriptionServiceAddonId);
195  return opcTcp;
196  }
197 */
199 {
201  opcTcp.Factory = std::make_shared<OpcUa::Server::AsyncOpcTcpAddonFactory>();
203  opcTcp.Dependencies.push_back(OpcUa::Server::AsioAddonId);
206  return opcTcp;
207 }
208 
210 {
211  Common::AddonInformation serverObjectAddon;
212  serverObjectAddon.Factory = std::make_shared<OpcUa::Server::ServerObjectFactory>();
213  serverObjectAddon.Id = OpcUa::Server::ServerObjectAddonId;
214  serverObjectAddon.Dependencies.push_back(OpcUa::Server::StandardNamespaceAddonId);
215  serverObjectAddon.Dependencies.push_back(OpcUa::Server::ServicesRegistryAddonId);
216  serverObjectAddon.Dependencies.push_back(OpcUa::Server::AsioAddonId);
217  return serverObjectAddon;
218 }
219 
221 {
222  Common::AddonInformation asioAddon;
223  asioAddon.Factory = std::make_shared<OpcUa::Server::AsioAddonFactory>();
224  asioAddon.Id = OpcUa::Server::AsioAddonId;
225  return asioAddon;
226 }
227 
229 {
230  Common::AddonInformation subscriptionAddon;
231  subscriptionAddon.Factory = std::make_shared<OpcUa::Server::SubscriptionServiceAddonFactory>();
232  subscriptionAddon.Id = OpcUa::Server::SubscriptionServiceAddonId;
233  subscriptionAddon.Dependencies.push_back(OpcUa::Server::AsioAddonId);
234  subscriptionAddon.Dependencies.push_back(OpcUa::Server::AddressSpaceRegistryAddonId);
235  subscriptionAddon.Dependencies.push_back(OpcUa::Server::ServicesRegistryAddonId);
236  return subscriptionAddon;
237 }
238 
239 void Server::RegisterCommonAddons(const Parameters & serverParams, Common::AddonsManager & manager)
240 {
241  std::vector<Common::AddonInformation> addons;
242  Common::AddonParameters addonParameters = CreateAddonsParameters(serverParams, manager.GetLogger());
243  CreateCommonAddonsConfiguration(addonParameters, addons);
244  RegisterAddons(addons, manager);
245 }
246 
247 void Server::LoadConfiguration(const std::string & configDirectoryPath, Common::AddonsManager & manager)
248 {
249  const Common::Configuration & configuration = Common::ParseConfigurationFiles(configDirectoryPath);
250  std::vector<Common::AddonInformation> addons(configuration.Modules.size());
251  // modules are dynamic addons.
252  std::transform(configuration.Modules.begin(), configuration.Modules.end(), addons.begin(), [](const Common::ModuleConfiguration & module)
253  {
254  return Common::GetAddonInfomation(module);
255  });
256  CreateCommonAddonsConfiguration(configuration.Parameters, addons);
257  RegisterAddons(addons, manager);
258 }
259 
260 }
Configuration ParseConfigurationFiles(const std::string &directory)
ApplicationDescription Application
virtual const Logger::SharedPtr & GetLogger() const
Definition: addon_manager.h:90
const char AsyncOpcTcpAddonId[]
const char EndpointsRegistryAddonId[]
const char SubscriptionServiceAddonId[]
Common::AddonInformation GetAddonInfomation(const ModuleConfiguration &config)
std::vector< Parameter > Parameters
Common::AddonInformation CreateEndpointsRegistryAddon()
Common::AddonInformation CreateOpcTcpAsyncAddon()
Common::AddonInformation CreateStandardNamespaceAddon()
std::vector< ParametersGroup > Groups
std::vector< EndpointDescription > Endpoints
const char AddressSpaceRegistryAddonId[]
void LoadConfiguration(const std::string &configDirectoryPath, Common::AddonsManager &addons)
Load parameters from configuration files. This function will enumerate &#39;*.config&#39; files in the direct...
Common::AddonInformation CreateAsioAddon()
const char ServicesRegistryAddonId[]
const char AsioAddonId[]
Definition: asio_addon.h:31
EndpointDescription Endpoint
Definition: common_addons.h:39
OpcUa::ApplicationDescription Server
Common::AddonParameters Parameters
Definition: config_file.h:31
std::shared_ptr< AddonFactory > Factory
Definition: addon_manager.h:32
std::vector< AddonId > Dependencies
Definition: addon_manager.h:33
Common::AddonInformation CreateAddressSpaceAddon()
OPC UA Address space part. GNU LGPL.
AddonParameters Parameters
Definition: addon_manager.h:34
void RegisterCommonAddons(const Parameters &params, Common::AddonsManager &addons)
parameters of server. can be used at embedded.
Common::AddonInformation CreateServicesRegistryAddon()
std::vector< ParametersGroup > Groups
Common::AddonInformation CreateSubscriptionServiceAddon()
Common::AddonInformation CreateServerObjectAddon()
const char ServerObjectAddonId[]
virtual void Register(const AddonInformation &caddonConfiguration)=0
register new addon.
std::vector< ModuleConfiguration > Modules
Definition: config_file.h:32
const char StandardNamespaceAddonId[]
std::vector< Parameter > Parameters
std::vector< Common::ParametersGroup > CreateCommonParameters(const std::vector< Server::ApplicationData > &endpoints, const Common::Logger::SharedPtr &logger)


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:06:04