Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "opc_tcp_async_parameters.h"
00021
00022 #include "endpoints_parameters.h"
00023
00024 #include <opc/common/uri_facade.h>
00025 #include <opc/ua/server/addons/asio_addon.h>
00026 #include <opc/ua/server/addons/endpoints_services.h>
00027 #include <opc/ua/server/addons/opc_tcp_async.h>
00028 #include <opc/ua/server/addons/services_registry.h>
00029 #include <opc/ua/server/opc_tcp_async.h>
00030
00031 #include <iostream>
00032 #include <vector>
00033
00034 namespace
00035 {
00036 using namespace OpcUa::Server;
00037
00038 class AsyncOpcTcpAddon : public Common::Addon
00039 {
00040 public:
00041 DEFINE_CLASS_POINTERS(AsyncOpcTcpAddon);
00042
00043 public:
00044 virtual void Initialize(Common::AddonsManager& addons, const Common::AddonParameters& params) override;
00045 virtual void Stop() override;
00046
00047 public:
00048 void PublishApplicationsInformation(std::vector<OpcUa::ApplicationDescription> applications, std::vector<OpcUa::EndpointDescription> endpoints, const Common::AddonsManager& addons) const;
00049
00050 private:
00051 AsyncOpcTcp::SharedPtr Endpoint;
00052 };
00053
00054
00055 void AsyncOpcTcpAddon::Initialize(Common::AddonsManager& addons, const Common::AddonParameters& addonParams)
00056 {
00057 AsyncOpcTcp::Parameters params = GetOpcTcpParameters(addonParams);
00058 if (params.DebugMode)
00059 {
00060 std::cout << "opc_tcp_async| Parameters:" << std::endl;
00061 std::cout << "opc_tcp_async| Debug mode: " << params.DebugMode << std::endl;
00062 }
00063 const std::vector<OpcUa::Server::ApplicationData> applications = OpcUa::ParseEndpointsParameters(addonParams.Groups, params.DebugMode);
00064 if (params.DebugMode)
00065 {
00066 for (OpcUa::Server::ApplicationData d: applications)
00067 {
00068 std::cout << "opc_tcp_async| Endpoint is: " << d.Endpoints.front().EndpointUrl << std::endl;
00069 }
00070 }
00071
00072 std::vector<OpcUa::ApplicationDescription> applicationDescriptions;
00073 std::vector<OpcUa::EndpointDescription> endpointDescriptions;
00074 for (const OpcUa::Server::ApplicationData application : applications)
00075 {
00076 applicationDescriptions.push_back(application.Application);
00077 endpointDescriptions.insert(endpointDescriptions.end(), application.Endpoints.begin(), application.Endpoints.end());
00078 }
00079
00080 if (endpointDescriptions.empty())
00081 {
00082 std::cerr << "opc_tcp_async| Endpoints parameters does not present in the configuration file." << std::endl;
00083 return;
00084 }
00085 if (endpointDescriptions.size() > 1)
00086 {
00087 std::cerr << "opc_tcp_async| Too many endpoints specified in the configuration file." << std::endl;
00088 return;
00089 }
00090
00091 PublishApplicationsInformation(applicationDescriptions, endpointDescriptions, addons);
00092 OpcUa::Server::ServicesRegistry::SharedPtr internalServer = addons.GetAddon<OpcUa::Server::ServicesRegistry>(OpcUa::Server::ServicesRegistryAddonId);
00093 OpcUa::Server::AsioAddon::SharedPtr asio = addons.GetAddon<OpcUa::Server::AsioAddon>(OpcUa::Server::AsioAddonId);
00094
00095 params.Port = Common::Uri(endpointDescriptions[0].EndpointUrl).Port();
00096 Endpoint = CreateAsyncOpcTcp(params, internalServer->GetServer(), asio->GetIoService());
00097 Endpoint->Listen();
00098 }
00099
00100 void AsyncOpcTcpAddon::PublishApplicationsInformation(std::vector<OpcUa::ApplicationDescription> applications, std::vector<OpcUa::EndpointDescription> endpoints, const Common::AddonsManager& addons) const
00101 {
00102 OpcUa::Server::EndpointsRegistry::SharedPtr endpointsAddon = addons.GetAddon<OpcUa::Server::EndpointsRegistry>(OpcUa::Server::EndpointsRegistryAddonId);
00103 if (!endpointsAddon)
00104 {
00105 std::cerr << "Cannot publish information about endpoints. Endpoints services addon didn't' registered." << std::endl;
00106 return;
00107 }
00108 endpointsAddon->AddEndpoints(endpoints);
00109 endpointsAddon->AddApplications(applications);
00110 }
00111
00112 void AsyncOpcTcpAddon::Stop()
00113 {
00114 Endpoint->Shutdown();
00115 Endpoint.reset();
00116 }
00117
00118 }
00119
00120 namespace OpcUa
00121 {
00122 namespace Server
00123 {
00124
00125 Common::Addon::UniquePtr AsyncOpcTcpAddonFactory::CreateAddon()
00126 {
00127 return Common::Addon::UniquePtr(new AsyncOpcTcpAddon());
00128 }
00129
00130 }
00131 }