void OpcUaProtocolAddon::Initialize(Common::AddonsManager& addons, const Common::AddonParameters& params)
  {
    ApplyAddonParameters(params);
    const std::vector<OpcUa::Server::ApplicationData> applications = OpcUa::ParseEndpointsParameters(params.Groups, Debug);
    for (OpcUa::Server::ApplicationData d: applications) {
      std::cout << "Endpoint is: " << d.Endpoints.front().EndpointURL << std::endl;
    }

    std::vector<OpcUa::ApplicationDescription> applicationDescriptions;
    std::vector<OpcUa::EndpointDescription> endpointDescriptions;
    for (const OpcUa::Server::ApplicationData application : applications)
    {
      applicationDescriptions.push_back(application.Application);
      endpointDescriptions.insert(endpointDescriptions.end(), application.Endpoints.begin(), application.Endpoints.end());
    }
    OpcUa::Server::EndpointsRegistry::SharedPtr endpointsAddon = addons.GetAddon<OpcUa::Server::EndpointsRegistry>(OpcUa::Server::EndpointsRegistryAddonID);
    if (!endpointsAddon)
    {
      std::cerr << "Cannot save information about endpoints. Endpoints services addon didn't' registered." << std::endl;
      return;
    }
    endpointsAddon->AddEndpoints(endpointDescriptions);
    endpointsAddon->AddApplications(applicationDescriptions);

    InternalServer = addons.GetAddon<OpcUa::Server::ServicesRegistry>(OpcUa::Server::ServicesRegistryAddonID);

    TcpServer = OpcUa::Server::CreateTcpServer();
    Protocol.reset(new OpcUaProtocol(*TcpServer, Debug));
    Protocol->StartEndpoints(endpointDescriptions, InternalServer->GetServer());
  }
예제 #2
0
  virtual void SetUp()
  {
    const bool debug = false;
    Addons = Common::CreateAddonsManager();

    OpcUa::Test::RegisterServicesRegistry(*Addons);
    OpcUa::Test::RegisterAddressSpace(*Addons);
    OpcUa::Test::RegisterStandardNamespace(*Addons);
    Addons->Start();

    OpcUa::Server::ServicesRegistry::SharedPtr addon = Addons->GetAddon<OpcUa::Server::ServicesRegistry>(OpcUa::Server::ServicesRegistryAddonId);
    Services = addon->GetServer();
  }
TEST_F(EndpointsRegistry, RegisterEndpoints)
{
  OpcUa::EndpointDescription desc;
  desc.EndpointUrl = "url";

  OpcUa::Server::EndpointsRegistry::SharedPtr endpoints = Addons->GetAddon<OpcUa::Server::EndpointsRegistry>(OpcUa::Server::EndpointsRegistryAddonId);
  endpoints->AddEndpoints(std::vector<OpcUa::EndpointDescription>(1, desc));

  OpcUa::Server::ServicesRegistry::SharedPtr services = Addons->GetAddon<OpcUa::Server::ServicesRegistry>(OpcUa::Server::ServicesRegistryAddonId);
  OpcUa::Services::SharedPtr computer = services->GetServer();
  std::vector<OpcUa::EndpointDescription> descriptions;
  ASSERT_NO_THROW(descriptions = computer->Endpoints()->GetEndpoints(OpcUa::GetEndpointsParameters()));
  ASSERT_EQ(descriptions.size(), 1);
  ASSERT_EQ(descriptions[0].EndpointUrl, "url");
}
void BuiltinServerAddon::Initialize(Common::AddonsManager& addons, const Common::AddonParameters& params)
{
  for (const Common::Parameter parameter : params.Parameters)
  {
    if (parameter.Name == "debug" && !parameter.Value.empty() && parameter.Value != "0")
    {
      Debug = true;
    }
  }

  const std::vector<OpcUa::Server::ApplicationData> applications = OpcUa::ParseEndpointsParameters(params.Groups, Debug);
  for (OpcUa::Server::ApplicationData d: applications) {
    std::cout << "Endpoint is: " << d.Endpoints.front().EndpointUrl << std::endl;
  }

  std::vector<OpcUa::ApplicationDescription> applicationDescriptions;
  std::vector<OpcUa::EndpointDescription> endpointDescriptions;
  for (const OpcUa::Server::ApplicationData application : applications)
  {
    applicationDescriptions.push_back(application.Application);
    endpointDescriptions.insert(endpointDescriptions.end(), application.Endpoints.begin(), application.Endpoints.end());
  }

  OpcUa::Server::EndpointsRegistry::SharedPtr endpointsAddon = addons.GetAddon<OpcUa::Server::EndpointsRegistry>(OpcUa::Server::EndpointsRegistryAddonId);
  if (!endpointsAddon)
  {
    std::cerr << "Cannot save information about endpoints. Endpoints services addon didn't' registered." << std::endl;
    return;
  }
  endpointsAddon->AddEndpoints(endpointDescriptions);
  endpointsAddon->AddApplications(applicationDescriptions);

  OpcUa::Server::ServicesRegistry::SharedPtr internalServer = addons.GetAddon<OpcUa::Server::ServicesRegistry>(OpcUa::Server::ServicesRegistryAddonId);

  Protocol = OpcUa::Server::CreateOpcUaProtocol(*this, Debug);
  Protocol->StartEndpoints(endpointDescriptions, internalServer->GetServer());
}