xml_address_space_addon.cpp
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 #include "xml_address_space_loader.h"
00012 
00013 #include <opc/ua/server/addons/address_space.h>
00014 #include <sstream>
00015 #include <iostream>
00016 #include <stdexcept>
00017 
00018 namespace OpcUa
00019 {
00020   namespace Internal
00021   {
00022 
00023     void XmlAddressSpaceAddon::Initialize(Common::AddonsManager& addons, const Common::AddonParameters& params)
00024     {
00025       Registry = addons.GetAddon<NodeManagementServices>(Server::AddressSpaceRegistryAddonId);
00026       if (!Registry)
00027       {
00028         std::stringstream stream;
00029         stream << "Unable to find addon '" << Server::AddressSpaceRegistryAddonId << "'. " << std::endl;
00030         throw std::logic_error(stream.str());
00031       }
00032 
00033       for (const Common::Parameter& param : params.Parameters)
00034       {
00035         if (param.Name == "file_name")
00036         {
00037           try
00038           {
00039             Load(param.Value.c_str(), *Registry);
00040           }
00041           catch (const std::exception& err)
00042           {
00043             std::cerr << "Unable to load address space from the file '" << param.Value << "'. " << err.what() << std::endl;
00044           }
00045         }
00046       }
00047     }
00048 
00049     void XmlAddressSpaceAddon::Stop()
00050     {
00051       Registry.reset();
00052     }
00053 
00054     void XmlAddressSpaceAddon::Load(const char* path)
00055     {
00056       Load(path, *Registry);
00057     }
00058 
00059     void XmlAddressSpaceAddon::Load(const char* file, OpcUa::NodeManagementServices& registry)
00060     {
00061       if (!Registry)
00062       {
00063         std::stringstream stream;
00064         stream << "Unable to find addon '" << Server::AddressSpaceRegistryAddonId << "'. " << std::endl;
00065         throw std::logic_error(stream.str());
00066       }
00067 
00068       XmlAddressSpaceLoader xml(*Registry);
00069       xml.Load(file);
00070     }
00071 
00072   } // namespace Internal
00073 } // namespace OpcUa


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