SALOME documentation central

SALOME_NamingService Class Reference

A class to manage the SALOME naming service. More...

Public Member Functions

 SALOME_NamingService ()
 Default Constructor without ORB reference.
 SALOME_NamingService (CORBA::ORB_ptr orb)
 Standard Constructor, with ORB reference.
virtual ~SALOME_NamingService ()
 Standard destructor.
void init_orb (CORBA::ORB_ptr orb=0)
 initializes ORB reference and naming service root context.
void Register (CORBA::Object_ptr ObjRef, const char *Path) throw (ServiceUnreachable)
 Registers a CORBA object reference under a path.
CORBA::Object_ptr Resolve (const char *Path) throw ( ServiceUnreachable)
 get the CORBA object reference associated to a name.
CORBA::Object_ptr ResolveFirst (const char *Path) throw ( ServiceUnreachable)
 get the CORBA object reference associated to an uncomplete name.
CORBA::Object_ptr ResolveComponent (const char *hostname, const char *containerName, const char *componentName, const int nbproc=0) throw (ServiceUnreachable)
 find a component instance from hostname, containername, componentName and number of processors.
std::string ContainerName (const char *ContainerName)
 provide a default container name if empty.
std::string ContainerName (const Engines::MachineParameters &params)
 build a container name, given a MachineParameters struct.
std::string BuildContainerNameForNS (const char *ContainerName, const char *hostname)
 build a string representing a container in Naming Service.
std::string BuildContainerNameForNS (const Engines::MachineParameters &params, const char *hostname)
 build a string representing a container in Naming Service.
int Find (const char *name) throw (ServiceUnreachable)
 search a name in current directory.
bool Create_Directory (const char *Path) throw (ServiceUnreachable)
 Creates a directory (context_name).
bool Change_Directory (const char *Path) throw (ServiceUnreachable)
 change current directory to the given path
char * Current_Directory () throw (ServiceUnreachable)
 get the current directory path
void list () throw (ServiceUnreachable)
 list recursively all objects in the current context
std::vector< std::string > list_directory () throw (ServiceUnreachable)
 list all the objects in the current directory.
std::vector< std::string > list_subdirs () throw (ServiceUnreachable)
 list all the subdirectories in the current directory.
std::vector< std::string > list_directory_recurs () throw (ServiceUnreachable)
 list all the objects in the current directory and subdirectories.
void Destroy_Name (const char *Path) throw (ServiceUnreachable)
 destroy an entry in naming service.
virtual void Destroy_Directory (const char *Path) throw (ServiceUnreachable)
 Destroy an empty directory.
virtual void Destroy_FullDirectory (const char *Path) throw (ServiceUnreachable)
 Destroy a directory with its contents.
char * getIORaddr ()
 return a stringified reference of root context
CORBA::ORB_ptr orb ()
 get the orb used by the naming service

Protected Member Functions

void _initialize_root_context ()
 initialize root context (root directory)
int _createContextNameDir (std::string path, CosNaming::Name &context_name, std::vector< std::string > &splitPath, bool onlyDir)
void _Find (const char *name, CORBA::Long &occurence_number)
 search a name in current directory.
void _current_directory (std::vector< std::string > &splitPath, int &lengthResult, CosNaming::NamingContext_var contextToFind, bool &notFound)
void _list_directory_recurs (std::vector< std::string > &myList, std::string relativeSubDir, std::string absCurDirectory)

Protected Attributes

Utils_Mutex _myMutex
CORBA::ORB_var _orb
CosNaming::NamingContext_var _root_context
CosNaming::NamingContext_var _current_context

Detailed Description

A class to manage the SALOME naming service.


Constructor & Destructor Documentation

SALOME_NamingService::SALOME_NamingService (  ) 

Default Constructor without ORB reference.

After Default Constructor, one needs to initialize ORB.

See also:
init_orb(CORBA::ORB_ptr orb), SALOME_NamingService(CORBA::ORB_ptr orb)
SALOME_NamingService::SALOME_NamingService ( CORBA::ORB_ptr  orb  ) 

Standard Constructor, with ORB reference.

Initializes the naming service root context

Parameters:
orb CORBA::ORB_ptr arguments
SALOME_NamingService::~SALOME_NamingService (  )  [virtual]

Standard destructor.

The standard destructor does nothing special.


Member Function Documentation

void SALOME_NamingService::init_orb ( CORBA::ORB_ptr  orb = 0  ) 

initializes ORB reference and naming service root context.

Initializes ORB reference and naming service root context. For use after default constructor. If param orb is null, the orb is initialized

Parameters:
orb CORBA::ORB_ptr arguments
void SALOME_NamingService::Register ( CORBA::Object_ptr  ObjRef,
const char *  Path 
) throw (ServiceUnreachable)

Registers a CORBA object reference under a path.

Registers a CORBA object reference under a path. If the path ends with '/', only a directory is created. If the NamingService is out, the exception ServiceUnreachable is thrown.

Parameters:
ObjRef CORBA object reference to associate to the path. To create only a directory, give nil pointer.
Path A relative or absolute pathname to store the object reference. If the pathname begins with a '/', pathname is taken as an absolute pathname. Else, pathname is taken as a relative path, to current context. Prefer absolute pathname, relative pathname are not safe, when SALOME_NamingService object is shared or use in multithreaded context. If the path ends with '/', only a directory is created.
See also:
Change_Directory(const char* Path), Create_Directory(const char* Path) CORBA::Object_ptr Resolve(const char* Path)
CORBA::Object_ptr SALOME_NamingService::Resolve ( const char *  Path  )  throw ( ServiceUnreachable)

get the CORBA object reference associated to a name.

get the CORBA object reference associated to a complete name with a path. If the NamingService is out, the exception ServiceUnreachable is thrown

Parameters:
Path pathname. If the pathname begins with a '/', pathname is taken as an absolute pathname. Else, pathname is taken as a relative path, to current context. Prefer absolute pathname, relative pathname are not safe, when SALOME_NamingService object is shared or use in multithreaded context.
Returns:
the object reference if it exists under the pathname, or nil reference in other cases.
See also:
Register(CORBA::Object_ptr ObjRef, const char* Path), Change_Directory(const char* Path)
CORBA::Object_ptr SALOME_NamingService::ResolveFirst ( const char *  Path  )  throw ( ServiceUnreachable)

get the CORBA object reference associated to an uncomplete name.

get the CORBA object reference associated to an uncomplete name with a path. Look for the first occurence of name*. If the NamingService is out, the exception ServiceUnreachable is thrown

Parameters:
Path pathname under the form "/path/name" (Absolute reference !) search the fist reference like "/path(.dir)/name*(.kind)"
Returns:
the object reference if found, or nil reference.
See also:
Resolve(const char* Path)
CORBA::Object_ptr SALOME_NamingService::ResolveComponent ( const char *  hostname,
const char *  containerName,
const char *  componentName,
const int  nbproc = 0 
) throw (ServiceUnreachable)

find a component instance from hostname, containername, componentName and number of processors.

find a component instance from hostname, containername, componentName and number of processors. If the NamingService is out, the exception ServiceUnreachable is thrown.

Parameters:
hostname name of the machine on which the component is searched.
containerName name of the container in which the component is instanciated.
componentName name of the component we are looking for an existing instance.
nbproc in case of multi processor machine, container name is suffixed with _nbproc.
Returns:
the object reference
string SALOME_NamingService::ContainerName ( const char *  containerName  ) 

provide a default container name if empty.

the given container name is returned unchanged, unless it is empty.

Parameters:
containerName 
Returns:
container name, where empty input is replaced by "FactoryServer", without the path.
See also:
BuildContainerNameForNS(const char *containerName, const char *hostname)
string SALOME_NamingService::ContainerName ( const Engines::MachineParameters params  ) 

build a container name, given a MachineParameters 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).

Parameters:
params struct from which we get container name (may be empty), number of nodes and number of processor per node.
Returns:
a container name without the path.
See also:
BuildContainerNameForNS(const Engines::MachineParameters& params, const char *hostname)
string SALOME_NamingService::BuildContainerNameForNS ( const char *  containerName,
const char *  hostname 
)

build a string representing a container in Naming Service.

Build a string representing the absolute pathname of a container in SALOME_NamingService. This form gives a suffixed containerName in case of multi processor machine.

Parameters:
containerName name of the container in which the component is instanciated.
hostname name of the host of the container, without domain names.
Returns:
the path under the form /Containers/hostname/containerName
See also:
ContainerName(const Engines::MachineParameters& params)
string SALOME_NamingService::BuildContainerNameForNS ( const Engines::MachineParameters params,
const char *  hostname 
)

build a string representing a container in Naming Service.

Build a string representing the absolute pathname of a container in SALOME_NamingService.

Parameters:
params used as it is, or replaced by FactoryServer if empty.
hostname name of the host of the container, without domain names.
Returns:
the path under the form /Containers/hostname/containerName
See also:
ContainerName(const char *containerName)
int SALOME_NamingService::Find ( const char *  name  )  throw (ServiceUnreachable)

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 unchanged.

Parameters:
name the name to search.
Returns:
number of occurences found.
See also:
Change_Directory(const char* Path)
bool SALOME_NamingService::Create_Directory ( const char *  Path  )  throw (ServiceUnreachable)

Creates a directory (context_name).

Creates a directory (context_name) relative to the current directory (current context) or relative to the root directory (root context), if the path given begins with a '/'. If the NamingService is out, the exception ServiceUnreachable is thrown.

Parameters:
Path A relative or absolute pathname to store the object reference. If the pathname begins with a '/', pathname is taken as an absolute pathname. Else, pathname is taken as a relative path, to current context. Prefer absolute pathname, relative pathname are not safe, when SALOME_NamingService object is shared or use in multithreaded context.
Returns:
true if successfull (creation not strictly garanteed if true, because Register may catch some specific unlikely exception without throw anything --- to be corrected ---)
See also:
RegisterCORBA::Object_ptr ObjRef, const char* Path)
bool SALOME_NamingService::Change_Directory ( const char *  Path  )  throw (ServiceUnreachable)

change current directory to the given path

change the current directory to the given path in parameter. Warning: avoid use when the SALOME_NamingService instance is shared by several threads (current context may be modified by another thread). If the path is empty, nothing done return OK. If Path ="/", the current directory changes to the root directory. If the NamingService is out, the exception ServiceUnreachable is thrown.

Parameters:
Path the new current directory
Returns:
true if the change succeeded
char * SALOME_NamingService::Current_Directory (  )  throw (ServiceUnreachable)

get the current directory path

Get the current directory path. If the NamingService is out, the exception ServiceUnreachable is thrown.

Returns:
the path of the current_context
See also:
_current_directory
void SALOME_NamingService::list (  )  throw (ServiceUnreachable)

list recursively all objects in the current context

List and print via trace all directories and objects in the current context. Trace must be activated: compile option _DEBUG_ If the NamingService is out, the exception ServiceUnreachable is thrown

vector< string > SALOME_NamingService::list_directory (  )  throw (ServiceUnreachable)

list all the objects in the current directory.

get a list of all the objects in the current directory, without recursion on the subdirectories. Only the objects are listed, not the directories. If the NamingService is out, the exception ServiceUnreachable is thrown.

Returns:
list of strings with objects found.
See also:
vector<string> list_directory_recurs()
vector< string > SALOME_NamingService::list_subdirs (  )  throw (ServiceUnreachable)

list all the subdirectories in the current directory.

get a list of all the subdirectories in the current directory, without recursion on the subdirectories. Only the subdirectories are listed, not the objects. If the NamingService is out, the exception ServiceUnreachable is thrown.

Returns:
list of strings with directories found.
See also:
vector<string> list_directory()
vector< string > SALOME_NamingService::list_directory_recurs (  )  throw (ServiceUnreachable)

list all the objects in the current directory and subdirectories.

get a list of all the objects in the current directory, with recursion on the subdirectories. Only the objects are listed, not the directories. If the NamingService is out, the exception ServiceUnreachable is thrown.

Returns:
list of strings with objects found.
See also:
vector<string> list_directory()
void SALOME_NamingService::Destroy_Name ( const char *  Path  )  throw (ServiceUnreachable)

destroy an entry in naming service.

Destroy an association Path - Object Reference. If the NamingService is out, the exception ServiceUnreachable is thrown

Parameters:
Path object path
void SALOME_NamingService::Destroy_Directory ( const char *  Path  )  throw (ServiceUnreachable) [virtual]

Destroy an empty directory.

Destroy an empty directory in Naming Service. If the NamingService is out, the exception ServiceUnreachable is thrown.

Parameters:
Path directory path
void SALOME_NamingService::Destroy_FullDirectory ( const char *  Path  )  throw (ServiceUnreachable) [virtual]

Destroy a directory with its contents.

Destroy the objects associations in a directory, and the directory itself, if there is no subdirectories. If the NamingService is out, the exception ServiceUnreachable is thrown.

Parameters:
Path the directory path.
char * SALOME_NamingService::getIORaddr (  ) 

return a stringified reference of root context

Returns:
a stringified reference of root context
CORBA::ORB_ptr SALOME_NamingService::orb (  ) 

get the orb used by the naming service

Returns:
the orb
void SALOME_NamingService::_initialize_root_context (  )  [protected]

initialize root context (root directory)

the root context initialisation must be done when the SALOME_NamingService instance is created and before any othe call. See constructors.

void SALOME_NamingService::_Find ( const char *  name,
CORBA::Long &  occurence_number 
) [protected]

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 unchanged. The call is recursive.

Parameters:
name the name to search.
occurence_number number of occurence already found (incremented)

Copyright © 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS