-// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016 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
SALOME_NamingService::SALOME_NamingService()
{
- MESSAGE("SALOME_NamingService default constructor");
_orb = CORBA::ORB::_nil();
_root_context = CosNaming::NamingContext::_nil();
}
SALOME_NamingService::SALOME_NamingService(CORBA::ORB_ptr orb)
{
- MESSAGE("SALOME_NamingService creation");
_orb = CORBA::ORB::_duplicate(orb);
_initialize_root_context();
}
void SALOME_NamingService::init_orb(CORBA::ORB_ptr orb)
{
- MESSAGE("SALOME_NamingService initialisation");
-
Utils_Locker lock (&_myMutex);
if(orb)
_orb = CORBA::ORB::_duplicate(orb);
const char* Path)
throw(ServiceUnreachable)
{
- MESSAGE("BEGIN OF Register: " << Path);
-
Utils_Locker lock (&_myMutex);
// --- _current_context is replaced to the _root_context
- // if the Path begins whith '/'
+ // if the Path begins with '/'
if (Path[0] == '/'){
_current_context = _root_context;
CORBA::Object_ptr SALOME_NamingService::Resolve(const char* Path)
throw(ServiceUnreachable)
{
-// MESSAGE("BEGIN OF Resolve: " << Path);
-
Utils_Locker lock (&_myMutex);
// --- _current_context is replaced to the _root_context
- // if the Path begins whith '/'
+ // if the Path begins with '/'
if (Path[0] == '/')
{
}
// ============================================================================
-/*! \brief get the CORBA object reference associated to an uncomplete name.
+/*! \brief get the CORBA object reference associated to an incomplete name.
*
- * get the CORBA object reference associated to an uncomplete name with a
- * path. Look for the first occurence of name*.
+ * get the CORBA object reference associated to an incomplete name with a
+ * path. Look for the first occurrence of name*.
* If the NamingService is out, the exception ServiceUnreachable is thrown
* \param Path pathname under the form "/path/name" (Absolute reference !)
* search the fist reference like "/path(.dir)/name*(.kind)"
CORBA::Object_ptr SALOME_NamingService::ResolveFirst(const char* Path)
throw(ServiceUnreachable)
{
-// MESSAGE("ResolveFirst");
-
Utils_Locker lock (&_myMutex);
-// SCRUTE(Path);
std::string thePath = Path;
std::string basePath = "";
while (its != listElem.end())
{
- MESSAGE(*its);
-
if ((*its).find(name) == 0)
{
return Resolve((*its).c_str());
* If the NamingService is out, the exception ServiceUnreachable is thrown.
* \param hostname name of the machine on which the component is searched.
* \param containerName name of the container in which the component is
- instanciated.
+ instantiated.
* \param componentName name of the component we are looking for an existing
instance.
* \param nbproc in case of multi processor machine, container name is
const int nbproc)
throw(ServiceUnreachable)
{
-// MESSAGE("ResolveComponent");
-
Utils_Locker lock (&_myMutex);
std::string name = "/Containers/";
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;
*/
// ============================================================================
-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;
* SALOME_NamingService. This form gives a suffixed containerName in case of
* multi processor machine.
* \param containerName name of the container in which the component is
- instanciated.
+ instantiated.
* \param hostname name of the host of the container, without domain names.
* \return the path under the form /Containers/hostname/containerName
* \sa ContainerName(const Engines::MachineParameters& params)
*/
// ============================================================================
-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::ContainerParameters& params,
- const char *hostname)
+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);
/*! \brief search a name in current directory.
*
* Search a name in the current directory. after call, the current directory
- * is changed to the directory containing the last occurence of name found.
- * If no occurence found (see return value), current directory remains
+ * is changed to the directory containing the last occurrence of name found.
+ * If no occurrence found (see return value), current directory remains
* unchanged.
*
* \param name the name to search.
- * \return number of occurences found.
+ * \return number of occurrences found.
* \sa Change_Directory(const char* Path)
*/
// ============================================================================
int SALOME_NamingService::Find(const char* name)
throw(ServiceUnreachable)
{
- MESSAGE("BEGIN OF Find " << name);
-
Utils_Locker lock (&_myMutex);
CORBA::Long occurence_number = 0 ;
* path, to current context. Prefer absolute pathname, relative
* pathname are not safe, when SALOME_NamingService object is
* shared or use in multithreaded context.
- * \return true if successfull
- * (creation not strictly garanteed if true, because Register may
+ * \return true if successful
+ * (creation not strictly guaranteed if true, because Register may
* catch some specific unlikely exception without throw anything
* --- to be corrected ---)
* \sa RegisterCORBA::Object_ptr ObjRef, const char* Path)
*/
// ============================================================================
-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");
-
Utils_Locker lock (&_myMutex);
std::string path(Path);
if (path == "/")
{
- MESSAGE("Create Directory '/', just change to root_context");
_current_context = _root_context;
return true;
}
*/
// ============================================================================
-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);
std::string path(Path);
if (path == "/")
{
-// MESSAGE("Change_Directory is called to go to the root_context");
_current_context = _root_context;
return true;
}
CosNaming::NamingContext_var current_context = _current_context;
bool changeOK = false;
- // --- replace _current_context with _root_context if Path begins whith '/'
+ // --- replace _current_context with _root_context if Path begins with '/'
if (path[0] == '/')
current_context = _root_context;
*/
// ============================================================================
-char* SALOME_NamingService::Current_Directory()
-throw(ServiceUnreachable)
+char *SALOME_NamingService::Current_Directory() throw(ServiceUnreachable)
{
- MESSAGE("BEGIN OF Current_Directory");
-
Utils_Locker lock (&_myMutex);
CosNaming::NamingContext_var ref_context = _current_context;
*/
// ============================================================================
-void SALOME_NamingService::list()
-throw(ServiceUnreachable)
+void SALOME_NamingService::list() throw(ServiceUnreachable)
{
- MESSAGE("Begin of list");
-
Utils_Locker lock (&_myMutex)
;
if (binding->binding_type == CosNaming::ncontext)
{
- MESSAGE( "Context : " << bindingName[0].id );
-
try
{
Change_Directory(bindingName[0].id);
else if (binding->binding_type == CosNaming::nobject)
{
- MESSAGE( "Object : " << bindingName[0].id );
+ MESSAGE( "list(): no Object : " << bindingName[0].id );
}
}
*/
// ============================================================================
-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);
}
}
- for (unsigned int ind = 0; ind < dirList.size(); ind++)
- MESSAGE("list_directory : Object : " << dirList[ind]);
+ // for (unsigned int ind = 0; ind < dirList.size(); ind++)
+ // MESSAGE("list_directory : Object : " << dirList[ind]);
binding_iterator->destroy();
std::vector<std::string> SALOME_NamingService::list_directory_recurs()
throw(ServiceUnreachable)
{
- MESSAGE("list_directory_recurs");
-
Utils_Locker lock (&_myMutex);
std::vector<std::string> dirList ;
void SALOME_NamingService::Destroy_Name(const char* Path)
throw(ServiceUnreachable)
{
- MESSAGE("BEGIN OF Destroy_Name " << Path);
-
Utils_Locker lock (&_myMutex);
std::string path(Path);
context_name[0].id =
CORBA::string_dup(splitPath[dimension_resultat].c_str());
context_name[0].kind = CORBA::string_dup("object");
- SCRUTE(context_name[0].id);
+ //SCRUTE(context_name[0].id);
_current_context->unbind(context_name);
- MESSAGE("The object " << context_name[0].id << " has been deleted");
+ //MESSAGE("The object " << context_name[0].id << " has been deleted");
}
catch (CosNaming::NamingContext::NotFound& ex)
*/
// ============================================================================
-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);
-
Utils_Locker lock (&_myMutex);
std::string path(Path);
try
{
_current_context->destroy();
- MESSAGE( "The context " << path << " has been deleted" );
isContextDestroyed = true;
}
try
{
_current_context->unbind(context_name);
- MESSAGE( "The bind to the context "
- << context_name[0].id
- << " has been deleted" );
}
catch (CosNaming::NamingContext::NotFound& ex)
*/
// ============================================================================
-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");
* \param context_name CosNaming structure to put the path.
* \param splitPath a vector of string with subdirectories and final
* object, if any.
- * \param onlyDir if true, final object (if any) is ommited
+ * \param onlyDir if true, final object (if any) is omitted
* in context_name.
* if false, final object (if any) is included in
* context_name.
/*! \brief search a name in current directory.
*
* Search a name in the current directory. after call, the current directory
- * is changed to the directory containing the last occurence of name found.
- * If no occurence found (see return value), current directory remains
+ * is changed to the directory containing the last occurrence of name found.
+ * If no occurrence found (see return value), current directory remains
* unchanged. The call is recursive.
*
* \param name the name to search.
- * \param occurence_number number of occurence already found (incremented)
+ * \param occurence_number number of occurrence already found (incremented)
*/
// ============================================================================
void SALOME_NamingService::_Find(const char* name,
CORBA::Long& occurence_number)
{
- MESSAGE("BEGIN OF _Find "<< occurence_number << " " << name);
-
CosNaming::BindingList_var binding_list;
CosNaming::BindingIterator_var binding_iterator;
CosNaming::Binding_var binding;
if (!strcmp( bindingName[0].id, name))
{
- //MESSAGE("One occurence was found");
+ //MESSAGE("One occurrence was found");
occurence_number++;
// --- We keep in memory the directory where
- // one occurence was found
+ // one occurrence was found
found_context = _current_context ;
}
binding_iterator->destroy();
}
- // --- We go to the last directory where an occurence was found
+ // --- We go to the last directory where an occurrence was found
_current_context = found_context;
CosNaming::NamingContext_var contextToFind,
bool& notFound)
{
- MESSAGE("BEGIN OF _current_Directory");
-
CosNaming::BindingList_var binding_list;
CosNaming::BindingIterator_var binding_iterator;
CosNaming::Binding_var binding;
if (temp_context->_is_equivalent(contextToFind))
{
- MESSAGE("The context is found, we stop the search");
+ //MESSAGE("The context is found, we stop the search");
notFound = false;
- SCRUTE(notFound);
+ //SCRUTE(notFound);
}
if (notFound)
{
- SCRUTE(bindingName[0].id);
+ //SCRUTE(bindingName[0].id);
Change_Directory(bindingName[0].id);
_current_directory(splitPath,
lengthResult,
_current_context = ref_context;
- MESSAGE("Just before the delete of "
- << splitPath[lengthResult-1]);
+ // MESSAGE("Just before the delete of "
+ // << splitPath[lengthResult-1]);
splitPath.pop_back();
lengthResult--;
}
binding_iterator->destroy();
}
- // --- return to the last directory where an occurence was found
+ // --- return to the last directory where an occurrence was found
_current_context = ref_context ;
}