-// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
#include <string>
#include <cstdio>
-#ifdef WNT
+#ifdef WIN32
#define strdup _strdup
#endif
std::string SALOME_NamingService::ContainerName(const char *containerName)
{
- std::string ret;
+ std::string ret,containerNameCpp(containerName);
- if (strlen(containerName) == 0)
+ if (containerNameCpp.empty())
ret = "FactoryServer";
else
ret = containerName;
}
// ============================================================================
-/*! \brief build a container name, given a MachineParameters struct.
+/*! \brief build a container name, given a ContainerParameters struct.
*
- * Build a container name with a MachineParameters struct. In case of multi
- * processor machine, container name is suffixed with _nbproc. nproc equals
- * (number of nodes)*(number of processor per nodes).
- * \param params struct from which we get container name (may be
- * empty), number of nodes and number of processor
- * per node.
+ * Build a container name with a ContainerParameters struct. In case of multi
+ * processor machine, container name is suffixed with number of processors.
+ * \param params struct from which we get container name (may be empty) and
+ * number of processors.
* \return a container name without the path.
- * \sa BuildContainerNameForNS(const Engines::MachineParameters& params,
+ * \sa BuildContainerNameForNS(const Engines::ContainerParameters& params,
* const char *hostname)
*/
// ============================================================================
-std::string
-SALOME_NamingService::ContainerName(const Engines::MachineParameters& params)
-{
- int nbproc;
-
- if ( !params.isMPI )
- nbproc = 0;
- else if ( (params.nb_node <= 0) && (params.nb_proc_per_node <= 0) )
- nbproc = 1;
- else if ( params.nb_node == 0 )
- nbproc = params.nb_proc_per_node;
- else if ( params.nb_proc_per_node == 0 )
- nbproc = params.nb_node;
- else
- nbproc = params.nb_node * params.nb_proc_per_node;
-
- std::string ret = ContainerName(params.container_name);
-
- if ( nbproc >= 1 )
- {
- char *suffix = new char[8];
- sprintf(suffix, "_%d", nbproc);
- ret += suffix;
- }
-
- return ret;
-}
-
-std::string
-SALOME_NamingService::ContainerName(const Engines::ContainerParameters& params)
+std::string SALOME_NamingService::ContainerName(const Engines::ContainerParameters& params)
{
int nbproc;
else
nbproc = params.nb_proc;
- std::string ret = ContainerName(params.container_name);
+ std::string ret(ContainerName(params.container_name));
if ( nbproc >= 1 )
{
- char *suffix = new char[8];
- sprintf(suffix, "_%d", nbproc);
- ret += suffix;
+ std::ostringstream suffix;
+ suffix << "_" << nbproc;
+ ret += suffix.str();
}
return ret;
*/
// ============================================================================
-std::string SALOME_NamingService::BuildContainerNameForNS(const char *containerName,
- const char *hostname)
+std::string SALOME_NamingService::BuildContainerNameForNS(const char *containerName, const char *hostname)
{
- std::string ret = "/Containers/";
+ std::string ret("/Containers/");
ret += hostname;
ret += "/";
ret += ContainerName(containerName);
*/
// ============================================================================
-std::string
-SALOME_NamingService::
-BuildContainerNameForNS(const Engines::MachineParameters& params,
- const char *hostname)
+std::string SALOME_NamingService::BuildContainerNameForNS(const Engines::ContainerParameters& params, const char *hostname)
{
- std::string ret = "/Containers/";
- ret += hostname;
- ret += "/";
- ret += ContainerName(params);
-
- return ret;
-}
-
-std::string
-SALOME_NamingService::
-BuildContainerNameForNS(const Engines::ContainerParameters& params,
- const char *hostname)
-{
- std::string ret = "/Containers/";
+ std::string ret("/Containers/");
ret += hostname;
ret += "/";
ret += ContainerName(params);
*/
// ============================================================================
-bool SALOME_NamingService::Create_Directory(const char* Path)
-throw(ServiceUnreachable)
+bool SALOME_NamingService::Create_Directory(const char* Path) throw(ServiceUnreachable)
{
MESSAGE("BEGIN OF Create_Directory");
*/
// ============================================================================
-bool SALOME_NamingService::Change_Directory(const char* Path)
-throw(ServiceUnreachable)
+bool SALOME_NamingService::Change_Directory(const char* Path) throw(ServiceUnreachable)
{
// MESSAGE("BEGIN OF Change_Directory " << Path);
Utils_Locker lock (&_myMutex);
*/
// ============================================================================
-char* SALOME_NamingService::Current_Directory()
-throw(ServiceUnreachable)
+char *SALOME_NamingService::Current_Directory() throw(ServiceUnreachable)
{
MESSAGE("BEGIN OF Current_Directory");
*/
// ============================================================================
-void SALOME_NamingService::list()
-throw(ServiceUnreachable)
+void SALOME_NamingService::list() throw(ServiceUnreachable)
{
MESSAGE("Begin of list");
*/
// ============================================================================
-std::vector<std::string> SALOME_NamingService::list_directory()
-throw(ServiceUnreachable)
+std::vector<std::string> SALOME_NamingService::list_directory() throw(ServiceUnreachable)
{
// MESSAGE("list_directory");
+ Utils_Locker lock (&_myMutex);
std::vector<std::string> dirList ;
dirList.resize(0);
*/
// ============================================================================
-std::vector<std::string> SALOME_NamingService::list_subdirs()
-throw(ServiceUnreachable)
+std::vector<std::string> SALOME_NamingService::list_subdirs() throw(ServiceUnreachable)
{
MESSAGE("list_subdirs");
+ Utils_Locker lock (&_myMutex);
std::vector<std::string> dirList ;
dirList.resize(0);
*/
// ============================================================================
-void SALOME_NamingService::Destroy_Directory(const char* Path)
-throw(ServiceUnreachable)
+void SALOME_NamingService::Destroy_Directory(const char* Path) throw(ServiceUnreachable)
{
MESSAGE("BEGIN OF Destroy_Directory " << Path);
*/
// ============================================================================
-void SALOME_NamingService::Destroy_FullDirectory(const char* Path)
-throw(ServiceUnreachable)
+void SALOME_NamingService::Destroy_FullDirectory(const char* Path) throw(ServiceUnreachable)
{
MESSAGE("begin of Destroy_FullDirectory " << Path);
+ //no need to lock here because method calls are threadsafe.
if( Change_Directory(Path) )
{
std::vector<std::string> contList = list_directory();
void SALOME_NamingService::_initialize_root_context()
{
//MESSAGE("Get the root context");
-
+ //no lock here because initialization is expected to be done once.
try
{
CORBA::Object_var obj = _orb->resolve_initial_references("NameService");