1 // Copyright (C) 2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SALOME_NamingService_Abstract.hxx"
21 #include "Utils_SALOME_Exception.hxx"
26 SALOME_NamingService_Abstract *SALOME_NamingService_Abstract::cloneCoVar()
28 std::unique_ptr<SALOME_NamingService_Container_Abstract> ret(this->clone());
29 SALOME_NamingService_Abstract *ret2(dynamic_cast<SALOME_NamingService_Abstract *>(ret.get()));
31 throw SALOME_Exception(std::string("SALOME_NamingService_Abstract::cloneCoVar : clone is expected to return a SALOME_NamingService_Abstract type !"));
36 // ============================================================================
37 /*! \brief provide a default container name if empty.
39 * the given container name is returned unchanged, unless it is empty.
40 * \param containerName
41 * \return container name, where empty input is replaced by "FactoryServer",
43 * \sa BuildContainerNameForNS(const char *containerName, const char *hostname)
45 // ============================================================================
47 std::string SALOME_NamingService_Abstract::ContainerName(const char *containerName)
49 std::string ret,containerNameCpp(containerName);
51 if (containerNameCpp.empty())
52 ret = "FactoryServer";
59 // ============================================================================
60 /*! \brief build a string representing a container in Naming Service.
62 * Build a string representing the absolute pathname of a container in
63 * SALOME_NamingService. This form gives a suffixed containerName in case of
64 * multi processor machine.
65 * \param containerName name of the container in which the component is
67 * \param hostname name of the host of the container, without domain names.
68 * \return the path under the form /Containers/hostname/containerName
69 * \sa ContainerName(const Engines::MachineParameters& params)
71 // ============================================================================
73 std::string SALOME_NamingService_Abstract::BuildContainerNameForNS(const char *containerName, const char *hostname)
75 std::string ret("/Containers/");
78 ret += ContainerName(containerName);
83 // ============================================================================
84 /*! \brief build a container name, given a ContainerParameters struct.
86 * Build a container name with a ContainerParameters struct. In case of multi
87 * processor machine, container name is suffixed with number of processors.
88 * \param params struct from which we get container name (may be empty) and
89 * number of processors.
90 * \return a container name without the path.
91 * \sa BuildContainerNameForNS(const Engines::ContainerParameters& params,
92 * const char *hostname)
94 // ============================================================================
96 std::string SALOME_NamingService_Abstract::ContainerName(const Engines::ContainerParameters& params)
102 else if ( params.nb_proc <= 0 )
105 nbproc = params.nb_proc;
107 std::string ret(SALOME_NamingService_Abstract::ContainerName(params.container_name));
111 std::ostringstream suffix;
112 suffix << "_" << nbproc;
119 // ============================================================================
120 /*! \brief build a string representing a container in Naming Service.
122 * Build a string representing the absolute pathname of a container in
123 * SALOME_NamingService.
124 * \param params used as it is, or replaced by FactoryServer if empty.
125 * \param hostname name of the host of the container, without domain names.
126 * \return the path under the form /Containers/hostname/containerName
127 * \sa ContainerName(const char *containerName)
129 // ============================================================================
131 std::string SALOME_NamingService_Abstract::BuildContainerNameForNS(const Engines::ContainerParameters& params, const char *hostname)
133 std::string ret("/Containers/");
136 ret += ContainerName(params);