1 // SALOME NamingService : wrapping NamingService services
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SALOME_NamingService.cxx
25 // Author : Estelle Deville
29 #include "SALOME_NamingService.hxx"
30 #include "ServiceUnreachable.hxx"
32 #include "utilities.h"
40 //----------------------------------------------------------------------
41 /*! Function : SALOME_NamingService
42 * Purpose : Constructor and Initialisation of _root_context
44 //----------------------------------------------------------------------
46 SALOME_NamingService::SALOME_NamingService()
48 MESSAGE("SALOME_NamingService default constructor");
49 _orb = CORBA::ORB::_nil();
52 //----------------------------------------------------------------------
53 /*! Function : SALOME_NamingService
54 * \param orb CORBA::ORB_ptr arguments
56 //----------------------------------------------------------------------
58 SALOME_NamingService::SALOME_NamingService(CORBA::ORB_ptr orb)
60 MESSAGE("SALOME_NamingService creation");
62 _initialize_root_context();
65 //----------------------------------------------------------------------
66 /*! Function : ~SALOME_NamingService
67 * Purpose : Destructor
69 //----------------------------------------------------------------------
71 SALOME_NamingService::~SALOME_NamingService()
73 // Problem MESSAGE with singleton: late destruction, after trace system destruction ?
74 //MESSAGE("SALOME_NamingService destruction");
77 //----------------------------------------------------------------------
78 /*! Function : init_orb
79 * initialize ORB reference after default constructor
81 //----------------------------------------------------------------------
83 void SALOME_NamingService::init_orb(CORBA::ORB_ptr orb)
85 MESSAGE("SALOME_NamingService initialisation");
86 Utils_Locker lock(&_myMutex);
88 _initialize_root_context();
92 //----------------------------------------------------------------------
93 /*! Function : Register
94 * Method to create an association in the NamingService between ObjRef
96 * If the NamingService is out, the exception ServiceUnreachable is thrown
97 * \param ObjRef CORBA::Object_ptr arguments
98 * \param Path const char* arguments
100 //----------------------------------------------------------------------
102 void SALOME_NamingService::Register(CORBA::Object_ptr ObjRef,
104 throw(ServiceUnreachable)
106 MESSAGE("BEGIN OF Register: "<< Path);
107 Utils_Locker lock(&_myMutex);
108 int dimension_Path = strlen(Path) + 1;
109 char** resultat_resolve_Path = new char* [dimension_Path];
111 // _current_context is replaced to the _root_context
112 // if the Path begins whith '/'
114 _current_context = _root_context;
115 // MESSAGE("Gone to the _root_context");
118 //the resolution of the directory path has to be done
119 //to place the currect_context to the correct node
120 int dimension_resultat = 0;
121 _result_resolve_Path (Path, dimension_resultat, resultat_resolve_Path);
123 CosNaming::Name _context_name;
124 CORBA::Boolean _not_exist = false ;
125 CosNaming::NamingContext_var _temp_context;
127 if(dimension_resultat>1)
129 // A directory is treated (not only an object name)
130 // We had to test if the directory where ObjRef should be recorded
132 // If not, the new context has to be created
134 // MESSAGE("A complet Path has to be treated, not only an object name");
135 _context_name.length(dimension_resultat-1);
137 _create_context_name_dir(resultat_resolve_Path,dimension_resultat-1,
142 CORBA::Object_var _obj = _current_context->resolve(_context_name);
143 _current_context = CosNaming::NamingContext::_narrow(_obj);
145 catch (CosNaming::NamingContext::NotFound &)
147 // failed to resolve, therefore assume cold start
150 catch (CosNaming::NamingContext::InvalidName &)
152 INFOS("!!!Register() : CosNaming::NamingContext::InvalidName");
154 catch (CosNaming::NamingContext::CannotProceed &)
156 INFOS("!!!Register() : CosNaming::NamingContext::CannotProceed");
158 catch(CORBA::SystemException&)
160 INFOS("!!!Register() : CORBA::SystemException : unable to contact"
161 << " the naming service");
162 throw ServiceUnreachable();
168 _context_name.length(1);
169 // MESSAGE("The Path indicated is not yet created. It will soon be done");
170 for (int i = 0 ; i <dimension_resultat -1 ;i++)
172 _context_name[0].id =
173 CORBA::string_dup(resultat_resolve_Path[i]);
174 _context_name[0].kind = CORBA::string_dup("dir");
175 // SCRUTE(_context_name[0].id);
176 //The Path could be in part already created.
180 // this context is already created.
181 // Nothing to be done
182 CORBA::Object_var _obj =
183 _current_context->resolve(_context_name);
185 CosNaming::NamingContext::_narrow(_obj);
186 //MESSAGE("This context was already created");
188 catch (CosNaming::NamingContext::NotFound &)
190 // This context is not created. It will be done
192 _current_context->bind_new_context(_context_name);
193 _current_context = _temp_context;
194 //INFOS("This context was'nt created, it's now done");
198 catch (CosNaming::NamingContext::AlreadyBound&)
200 INFOS("!!!Register() : CosNaming::NamingContext::AlreadyBound");
202 catch(CosNaming::NamingContext::NotFound& ex)
204 CosNaming::Name n = ex.rest_of_name;
205 if (ex.why == CosNaming::NamingContext::missing_node)
206 INFOS("Register() : " << (char *) n[0].id
207 << " (" << (char *) n[0].kind << ") not found");
208 if (ex.why == CosNaming::NamingContext::not_context)
209 INFOS("Register() : " << (char *) n[0].id
210 << " (" << (char *) n[0].kind
211 << ") is not a context");
212 if (ex.why == CosNaming::NamingContext::not_object)
213 INFOS("Register() : " << (char *) n[0].id
214 << " (" << (char *) n[0].kind
215 << ") is not an object");
217 catch(CosNaming::NamingContext::CannotProceed&)
219 INFOS("!!!Register() : CosNaming::NamingContext::CannotProceed");
221 catch(CosNaming::NamingContext::InvalidName&)
223 INFOS("!!!Register() : CosNaming::NamingContext::InvalidName");
225 catch(CORBA::SystemException&)
227 INFOS("!!!Register() :CORBA::SystemException : unable to contact"
228 << " the naming service");
229 throw ServiceUnreachable();
234 // The current directory is now the directory where the object should
236 _context_name.length(1);
239 // the last element is an object an not a directory
240 _context_name[0].id =
241 CORBA::string_dup(resultat_resolve_Path[dimension_resultat -1]);
242 _context_name[0].kind = CORBA::string_dup("object");
243 //SCRUTE(_context_name[0].id);
245 _current_context->bind(_context_name, ObjRef);
246 // MESSAGE("A new element " << _context_name[0].id
247 // << " is recorded in the _current_context");
249 catch(CosNaming::NamingContext::NotFound& ex)
251 CosNaming::Name n = ex.rest_of_name;
252 if (ex.why == CosNaming::NamingContext::missing_node)
253 INFOS("Register() : " << (char *) n[0].id
254 << " (" << (char *) n[0].kind << ") not found");
255 if (ex.why == CosNaming::NamingContext::not_context)
256 INFOS("Register() : " << (char *) n[0].id
257 << " (" << (char *) n[0].kind
258 << ") is not a context");
259 if (ex.why == CosNaming::NamingContext::not_object)
260 INFOS("Register() : " << (char *) n[0].id
261 << " (" << (char *) n[0].kind
262 << ") is not an object");
264 catch(CosNaming::NamingContext::CannotProceed&)
266 INFOS("!!!Register() : CosNaming::NamingContext::CannotProceed");
268 catch(CosNaming::NamingContext::InvalidName&)
270 INFOS("!!!Register() : CosNaming::NamingContext::InvalidName");
272 catch(CosNaming::NamingContext::AlreadyBound&)
274 INFOS("!!!Register() : CosNaming::NamingContext::AlreadyBound, object will be rebind");
275 _current_context->rebind(_context_name, ObjRef);
277 catch(CORBA::SystemException&)
279 INFOS("!!!Register() :CORBA::SystemException : unable to contact"
280 << " the naming service");
281 throw ServiceUnreachable();
285 // Memory destruction
286 for (int i = 0 ; i <dimension_resultat ;i++)
288 delete [] resultat_resolve_Path[i];
290 delete[] resultat_resolve_Path ;
293 //----------------------------------------------------------------------
294 /*! Function : Resolve
295 * Purpose : method to get the ObjRef of a symbolic name
296 * If the NamingService is out, the exception ServiceUnreachable is thrown
297 * \param Path const char* arguments
298 * \return the object reference
300 //----------------------------------------------------------------------
302 CORBA::Object_ptr SALOME_NamingService::Resolve(const char* Path)
303 throw(ServiceUnreachable)
305 MESSAGE("BEGIN OF Resolve: " << Path);
306 Utils_Locker lock(&_myMutex);
307 int dimension_Path = strlen(Path) + 1;
308 char** resultat_resolve_Path = new char* [dimension_Path];
310 // _current_context is replaced to the _root_context
311 // if the Path begins whith '/'
312 if (Path[0]=='/') _current_context = _root_context;
315 //the resolution of the directory path has to be done
316 //to place the currect_context to the correct node
317 int dimension_resultat = 0;
318 _result_resolve_Path (Path, dimension_resultat, resultat_resolve_Path);
320 CosNaming::Name _context_name;
321 _context_name.length(dimension_resultat);
322 CORBA::Object_ptr _obj = NULL ;
324 _create_context_name_dir(resultat_resolve_Path,dimension_resultat-1,
326 // the last element is an object an not a directory
327 _context_name[dimension_resultat -1].id =
328 CORBA::string_dup(resultat_resolve_Path[dimension_resultat -1]);
329 _context_name[dimension_resultat -1].kind = CORBA::string_dup("object");
330 // SCRUTE(_context_name[dimension_resultat -1].id);
331 ASSERT(!CORBA::is_nil(_current_context));
335 _obj =_current_context->resolve(_context_name);
337 catch(CosNaming::NamingContext::NotFound& ex)
339 CosNaming::Name n = ex.rest_of_name;
340 if (ex.why == CosNaming::NamingContext::missing_node)
341 INFOS("Resolve() : " << (char *) n[0].id
342 << " (" << (char *) n[0].kind << ") not found");
343 if (ex.why == CosNaming::NamingContext::not_context)
345 << (char *) n[0].id << " (" << (char *) n[0].kind
346 << ") is not a context");
347 if (ex.why == CosNaming::NamingContext::not_object)
348 INFOS("Resolve() : " << (char *) n[0].id
349 << " (" << (char *) n[0].kind
350 << ") is not an object");
352 catch(CosNaming::NamingContext::CannotProceed&)
354 INFOS("!!!Resolve() : CosNaming::NamingContext::CannotProceed");
356 catch(CosNaming::NamingContext::InvalidName&)
358 INFOS("!!!Resolve() : CosNaming::NamingContext::InvalidName");
360 catch(CORBA::SystemException&)
362 INFOS("!!!Resolve() :CORBA::SystemException : unable to contact"
363 << "the naming service");
364 throw ServiceUnreachable();
366 // Memory destruction
367 for (int i = 0 ; i <dimension_resultat ;i++)
369 delete [] resultat_resolve_Path[i];
371 delete[] resultat_resolve_Path ;
376 //----------------------------------------------------------------------
377 /*! Function : ResolveFirst
378 * Purpose : method to get an ObjRef with a symbolic name
379 * \param Path const char* argument like "/path/name"
380 * search the fist reference like "/path(.dir)/name*(.kind)"
381 * If the NamingService is out, the exception ServiceUnreachable is thrown
386 * \return the object reference
388 //----------------------------------------------------------------------
390 CORBA::Object_ptr SALOME_NamingService::ResolveFirst(const char* Path)
391 throw(ServiceUnreachable)
393 MESSAGE("ResolveFirst");
394 Utils_Locker lock(&_myMutex);
396 string thePath =Path;
397 string basePath ="/";
398 string name = thePath;
399 string::size_type idx = thePath.rfind('/');
400 if (idx != string::npos) // at least one '/' found
402 basePath = thePath.substr(0,idx);
403 name = thePath.substr(idx+1);
407 CORBA::Object_ptr obj = CORBA::Object::_nil();
408 bool isOk = Change_Directory(basePath.c_str());
411 vector<string> listElem = list_directory();
412 vector<string>::iterator its = listElem.begin();
413 while (its != listElem.end())
416 if ((*its).find(name) == 0)
418 //string instance = basePath + "/" + *its;
419 return Resolve((*its).c_str());
427 //----------------------------------------------------------------------
428 /*! Function : Resolve Component from hostname, containername, componentName and number of prcoessors
429 * Purpose : method to get the ObjRef of a component
430 * If the NamingService is out, the exception ServiceUnreachable is thrown
431 * \param hostname const char* argument
432 * \param containername const char* argument
433 * \param componentname const char* argument
434 * \param nbproc const int argument
435 * \return the object reference
437 //----------------------------------------------------------------------
439 CORBA::Object_ptr SALOME_NamingService::ResolveComponent(const char* hostname, const char* containerName, const char* componentName, const int nbproc)
441 MESSAGE("ResolveComponent");
442 Utils_Locker lock(&_myMutex);
444 string name="/Containers/";
446 if( strlen(containerName) != 0 ){
449 char *newContainerName = new char[strlen(containerName)+8];
450 sprintf(newContainerName,"%s_%d",containerName,nbproc);
451 name += newContainerName;
454 name += containerName;
456 name += componentName;
457 return ResolveFirst(name.c_str());
460 Change_Directory(name.c_str());
461 vector<string> contList = list_directory();
462 for(unsigned int ind = 0; ind < contList.size(); ind++){
463 name = contList[ind].c_str();
465 name += componentName;
466 CORBA::Object_ptr obj = ResolveFirst(name.c_str());
467 if( !CORBA::is_nil(obj) )
470 return CORBA::Object::_nil();
475 string SALOME_NamingService::ContainerName(const char *containerName)
479 if (strlen(containerName)== 0)
480 ret = "FactoryServer";
487 string SALOME_NamingService::ContainerName(const Engines::MachineParameters& params)
492 else if( (params.nb_node <= 0) && (params.nb_proc_per_node <= 0) )
494 else if( params.nb_node == 0 )
495 nbproc = params.nb_proc_per_node;
496 else if( params.nb_proc_per_node == 0 )
497 nbproc = params.nb_node;
499 nbproc = params.nb_node * params.nb_proc_per_node;
501 string ret=ContainerName(params.container_name);
504 char *suffix = new char[8];
505 sprintf(suffix,"_%d",nbproc);
512 string SALOME_NamingService::BuildContainerNameForNS(const char *containerName, const char *hostname)
514 string ret="/Containers/";
517 ret+=ContainerName(containerName);
522 string SALOME_NamingService::BuildContainerNameForNS(const Engines::MachineParameters& params, const char *hostname)
524 string ret="/Containers/";
527 ret+=ContainerName(params);
532 //----------------------------------------------------------------------
534 * Purpose : method to research a name from the current directory
535 * of the naming service.
536 * The naming service changes directory to go to the directory where
537 * the last occurence was found.
538 * If the NamingService is out, the exception ServiceUnreachable is thrown
539 * \param name const char* arguments
540 * \return the number of occurences found
543 //----------------------------------------------------------------------
545 int SALOME_NamingService::Find(const char* name)
546 throw(ServiceUnreachable)
548 MESSAGE("BEGIN OF Find " << name);
549 Utils_Locker lock(&_myMutex);
550 CORBA::Long occurence_number = 0 ;
553 _Find(name,occurence_number);
555 catch(CORBA::SystemException&)
557 INFOS("!!!Find() : CORBA::SystemException : unable to contact"
558 << " the naming service");
559 throw ServiceUnreachable();
561 return occurence_number;
564 //----------------------------------------------------------------------
565 /*! Function : Create_Directory
566 * Purpose : method to create a directory from the current directory.
567 * If the NamingService is out, the exception ServiceUnreachable is thrown
568 * \param Path const char* arguments
569 * \return a boolean to indicate if the creation succeeded
571 //----------------------------------------------------------------------
573 bool SALOME_NamingService::Create_Directory(const char* Path)
574 throw(ServiceUnreachable)
576 MESSAGE("BEGIN OF Create_Directory");
577 Utils_Locker lock(&_myMutex);
578 int dimension_Path = strlen(Path) + 1;
579 char** resultat_resolve_Path= new char* [dimension_Path];;
580 CORBA::Boolean _return_code = true ;
582 // _current_context is replaced to the _root_context
583 // if the Path begins whith '/'
584 if (Path[0]=='/') _current_context = _root_context;
586 int dimension_resultat = 0;
587 _result_resolve_Path (Path, dimension_resultat, resultat_resolve_Path);
590 // We had to test if a part of the directory to treat
592 // If not, the new context has to be created
594 CosNaming::Name _context_name;
595 _context_name.length(1);
596 CosNaming::NamingContext_var _temp_context;
597 ASSERT(!CORBA::is_nil(_current_context));
602 for (int i = 0 ; i <dimension_resultat ;i++)
604 _context_name[0].id =
605 CORBA::string_dup(resultat_resolve_Path[i]);
606 _context_name[0].kind = CORBA::string_dup("dir");
607 // SCRUTE(_context_name[0].id);
608 //The Path could be in part already created.
612 // this context is already created.
613 // Nothing to be done
614 CORBA::Object_var _obj =
615 _current_context->resolve(_context_name);
617 CosNaming::NamingContext::_narrow(_obj);
618 MESSAGE("This context was already created");
620 catch (CosNaming::NamingContext::NotFound &)
622 // This context is not created. It will be done
624 _current_context->bind_new_context(_context_name);
625 _current_context = _temp_context;
626 INFOS("This context was'nt created, it's now done");
630 catch (CosNaming::NamingContext::AlreadyBound&)
632 INFOS("!!! Create_Directory() CosNaming::NamingContext::AlreadyBound");
633 _return_code = false;
635 catch(CosNaming::NamingContext::NotFound& ex)
637 _return_code = false;
638 CosNaming::Name n = ex.rest_of_name;
639 if (ex.why == CosNaming::NamingContext::missing_node)
640 INFOS("Create_Directory() : " << (char *) n[0].id
641 << " (" << (char *) n[0].kind << ") not found");
642 if (ex.why == CosNaming::NamingContext::not_context)
643 INFOS("Create_Directory() : " << (char *) n[0].id
644 << " (" << (char *) n[0].kind
645 << ") is not a context");
646 if (ex.why == CosNaming::NamingContext::not_object)
647 INFOS("Create_Directory() : " << (char *) n[0].id
648 << " (" << (char *) n[0].kind
649 << ") is not an object");
651 catch(CosNaming::NamingContext::CannotProceed&)
653 _return_code = false;
654 INFOS("!!!Create_Directory():CosNaming::NamingContext::CannotProceed");
656 catch(CosNaming::NamingContext::InvalidName&)
658 _return_code = false;
659 INFOS("!!!Create_Directory():CosNaming::NamingContext::InvalidName");
661 catch(CORBA::SystemException&)
663 _return_code = false;
664 INFOS("!!!Register() :CORBA::SystemException : unable to contact"
665 << " the naming service");
666 throw ServiceUnreachable();
668 // Memory destruction
669 for (int i = 0 ; i <dimension_resultat;i++)
671 delete [] resultat_resolve_Path[i];
673 delete[] resultat_resolve_Path ;
677 //----------------------------------------------------------------------
678 /*! Function : Change_Directory
679 * Purpose : method to change the current directory to the
680 * directory Path indicated in "in" Parameter.
681 * If Path ="/", the current directory changes to the root directory.
682 * If the NamingService is out, the exception ServiceUnreachable is thrown.
683 * \param Path const char* arguments
684 * \return a boolean to indicate if the change succeeded
686 //----------------------------------------------------------------------
688 bool SALOME_NamingService::Change_Directory(const char* Path)
689 throw(ServiceUnreachable)
691 MESSAGE("BEGIN OF Change_Directory " << Path);
692 Utils_Locker lock(&_myMutex);
693 int dimension_Path = strlen(Path) + 1;
694 char** resultat_resolve_Path = new char* [dimension_Path];
695 CORBA::Boolean _return_code = true ;
697 // _current_context is replaced to the _root_context
698 // if the Path begins whith '/'
699 if (Path[0]=='/') _current_context = _root_context;
701 if ((Path[0]=='/') && (dimension_Path == 2))
703 MESSAGE("Change_Directory is called to go to the root_context");
705 //nothing to de done, the change_dur is called to go to the root_context
706 // no Path to resolve
708 //the resolution of the directory path has to be done
709 //to place the currect_context to the correct node
711 int dimension_resultat = 0;
712 _result_resolve_Path(Path,dimension_resultat,resultat_resolve_Path);
714 CosNaming::Name _context_name;
715 _context_name.length(dimension_resultat);
716 CORBA::Object_var _obj;
718 _create_context_name_dir(resultat_resolve_Path,dimension_resultat,
721 ASSERT(!CORBA::is_nil(_current_context));
725 _obj =_current_context->resolve(_context_name);
726 _current_context = CosNaming::NamingContext::_narrow(_obj);
727 ASSERT(!CORBA::is_nil(_current_context))
729 catch(CosNaming::NamingContext::NotFound& ex)
731 _return_code = false;
732 CosNaming::Name n = ex.rest_of_name;
733 if (ex.why == CosNaming::NamingContext::missing_node)
734 INFOS( "Change_Directory() : " << (char *) n[0].id
735 << " (" << (char *) n[0].kind << ") not found")
736 if (ex.why == CosNaming::NamingContext::not_context)
737 INFOS("Change_Directory() : " << (char *) n[0].id
738 << " (" << (char *) n[0].kind
739 << ") is not a context" )
740 if (ex.why == CosNaming::NamingContext::not_object)
741 INFOS( "Change_Directory() : " << (char *) n[0].id
742 << " (" << (char *) n[0].kind
743 << ") is not an object" )
745 catch(CosNaming::NamingContext::CannotProceed&)
747 _return_code = false;
748 INFOS( "!!!Change_Directory() : CosNaming::NamingContext::CannotProceed" )
750 catch(CosNaming::NamingContext::InvalidName&)
752 _return_code = false;
753 INFOS( "!!!Change_Directory() : CosNaming::NamingContext::InvalidName" )
755 catch(CORBA::SystemException&)
757 _return_code = false;
758 INFOS( "!!!Change_Directory() :CORBA::SystemException : unable to contact"
759 << "the naming service")
760 throw ServiceUnreachable();
762 // Memory destruction
763 for (int i = 0 ; i <dimension_resultat ;i++)
765 delete [] resultat_resolve_Path[i];
767 delete[] resultat_resolve_Path ;
772 //----------------------------------------------------------------------
773 /*! Function : Current_Directory
774 * Purpose : method to get the current directory.
775 * If the NamingService is out, the exception ServiceUnreachable is thrown
776 * \return the path of the current_context
777 * \sa _current_directory
779 //----------------------------------------------------------------------
781 char* SALOME_NamingService::Current_Directory()
782 throw(ServiceUnreachable)
784 MESSAGE("BEGIN OF Current_Directory");
785 Utils_Locker lock(&_myMutex);
787 CosNaming::NamingContext_var _ref_context = _current_context;
791 char** result_path = new char*[50]; // 50 is it enough?
794 // We go to the root_context to begin the search from the root
795 _current_context = _root_context ;
796 CORBA::Boolean _continue = true ;
799 _current_directory(result_path,i,_ref_context,_continue );
801 catch(CORBA::SystemException&)
803 INFOS("!!!Current_Directory(): CORBA::SystemException : unable to contact"
804 << " the naming service" )
805 throw ServiceUnreachable();
807 for (int k = 0 ; k <i ;k++)
809 // We count the length of the char* + 1 for the '/' to separate
811 length_path = length_path + strlen(result_path[k]) + 1;
813 char* return_Path = new char[length_path +2];
814 return_Path[0] = '/' ;
815 return_Path[1] = '\0' ;
817 for (int k = 0 ; k <i ;k++)
819 for (k = 0 ; k <i ;k++)
822 //SCRUTE(result_path[k])
823 strcat(return_Path,result_path[k]);
824 strcat(return_Path,"/");
826 //SCRUTE(return_Path)
827 _current_context = _ref_context ;
832 //----------------------------------------------------------------------
834 * Purpose : method to list and print all the context contained from
835 * the current context
836 * If the NamingService is out, the exception ServiceUnreachable is thrown
838 //----------------------------------------------------------------------
840 void SALOME_NamingService::list()
841 throw(ServiceUnreachable)
843 MESSAGE("Begin of list");
844 Utils_Locker lock(&_myMutex);
845 CosNaming::BindingList_var _binding_list;
846 CosNaming::BindingIterator_var _binding_iterator;
847 unsigned long nb=0 ; // for using only the BindingIterator to access the bindings
848 CosNaming::Binding_var _binding ;
849 CosNaming::NamingContext_var _ref_context = _current_context;
850 _current_context->list(nb, _binding_list, _binding_iterator) ;
852 while (_binding_iterator->next_one(_binding)) {
853 CosNaming::Name _bindingName = _binding->binding_name;
854 if (_binding->binding_type == CosNaming::ncontext) {
855 MESSAGE( "Context : " << _bindingName[0].id );
858 Change_Directory(_bindingName[0].id);
860 catch (ServiceUnreachable&)
862 INFOS( "!!!list(): ServiceUnreachable" )
863 throw ServiceUnreachable();
867 _current_context = _ref_context ;
869 else if (_binding->binding_type == CosNaming::nobject) {
870 MESSAGE( "Object : " << _bindingName[0].id );
873 _binding_iterator->destroy();
876 //----------------------------------------------------------------------
877 /*! Function : list_directory
878 * Purpose : method to get all the contexts contained in the current
880 * Get only objects, isn't iterative
881 * If the NamingService is out, the exception ServiceUnreachable is thrown
883 //----------------------------------------------------------------------
884 vector<string> SALOME_NamingService::list_directory()
885 throw(ServiceUnreachable)
887 vector<string> _list ;
889 CosNaming::BindingList_var _binding_list;
890 CosNaming::BindingIterator_var _binding_iterator;
891 unsigned long nb=0 ; // for using only the BindingIterator to access the bindings
892 CosNaming::Binding_var _binding ;
893 CosNaming::NamingContext_var _ref_context = _current_context;
894 _current_context->list(nb, _binding_list, _binding_iterator) ;
895 if (_binding_iterator->_is_nil()) return _list;
897 while (_binding_iterator->next_one(_binding)) {
898 CosNaming::Name _bindingName = _binding->binding_name;
899 if (_binding->binding_type == CosNaming::nobject) {
900 _list.push_back(CORBA::string_dup(_bindingName[0].id));
903 //for (unsigned int ind = 0; ind < _list.size(); ind++)
904 // MESSAGE("list_directory : Object : " << _list[ind]);
906 _binding_iterator->destroy();
910 //----------------------------------------------------------------------
911 /*! Function : list_directory_recurs
912 * Purpose : method to get all the contexts contained in the current
914 * Get only objects and is recursive
915 * If the NamingService is out, the exception ServiceUnreachable is thrown
917 //----------------------------------------------------------------------
918 vector<string> SALOME_NamingService::list_directory_recurs()
919 throw(ServiceUnreachable)
921 MESSAGE("list_directory_recurs");
922 Utils_Locker lock(&_myMutex);
923 vector<string> _list ;
924 char *currentDir=Current_Directory();
925 _list_directory_recurs(_list,0,currentDir);
926 delete [] currentDir;
930 //----------------------------------------------------------------------
931 /*! Function : Destroy_Name
932 * Purpose : method to destroy an association Path-Object Reference.
933 * WARNING : The complete Path should be given.
934 * If the NamingService is out, the exception ServiceUnreachable is thrown
935 * \param Path const char* arguments
937 //----------------------------------------------------------------------
939 void SALOME_NamingService::Destroy_Name(const char* Path)
940 throw(ServiceUnreachable)
942 MESSAGE("BEGIN OF Destroy_Name");
943 Utils_Locker lock(&_myMutex);
944 int dimension_Path = strlen(Path) + 1;
945 char** resultat_resolve_Path = new char* [dimension_Path];
947 // _current_context is replaced to the _root_context
948 // if the Path begins whith '/'
949 if (Path[0]=='/') _current_context = _root_context;
952 //the resolution of the directory path has to be done
953 //to place the currect_context to the correct node
954 int dimension_resultat = 0;
955 _result_resolve_Path (Path, dimension_resultat, resultat_resolve_Path);
957 CosNaming::Name _context_name;
958 if (dimension_resultat>1)
960 // We go in the directory where the object to destroy is
961 _context_name.length(dimension_resultat-1);
963 _create_context_name_dir(resultat_resolve_Path,dimension_resultat -1,
967 CORBA::Object_var _obj = _current_context->resolve(_context_name);
968 _current_context = CosNaming::NamingContext::_narrow(_obj);
970 catch (CosNaming::NamingContext::NotFound& ex)
972 CosNaming::Name n = ex.rest_of_name;
973 if (ex.why == CosNaming::NamingContext::missing_node)
974 INFOS( "Destroy_Name() : " << (char *) n[0].id
975 << " (" << (char *) n[0].kind << ") not found" )
976 if (ex.why == CosNaming::NamingContext::not_context)
977 INFOS( "Destroy_Name() : " << (char *) n[0].id
978 << " (" << (char *) n[0].kind
979 << ") is not a context" )
980 if (ex.why == CosNaming::NamingContext::not_object)
981 INFOS( "Destroy_Name() : " << (char *) n[0].id
982 << " (" << (char *) n[0].kind
983 << ") is not an object" )
985 catch (CosNaming::NamingContext::InvalidName &)
987 INFOS( "!!!Destroy_Name() : CosNaming::NamingContext::InvalidName" )
989 catch (CosNaming::NamingContext::CannotProceed &)
991 INFOS( "!!!Destroy_Name(): CosNaming::NamingContext::CannotProceed" )
993 catch(CORBA::SystemException&)
995 INFOS( "!!!Destroy_Name() : CORBA::SystemException : unable to contact"
996 << " the naming service")
997 throw ServiceUnreachable();
1001 // the last element is the object to destroy
1002 _context_name.length(1);
1003 _context_name[0].id =
1004 CORBA::string_dup(resultat_resolve_Path[dimension_resultat -1]);
1005 _context_name[0].kind = CORBA::string_dup("object");
1006 SCRUTE(_context_name[0].id);
1007 ASSERT(!CORBA::is_nil(_current_context));
1008 // Object destruction
1011 _current_context->unbind(_context_name);
1012 MESSAGE( "The object " << _context_name[0].id << " has been deleted" )
1014 catch(CosNaming::NamingContext::NotFound& ex)
1016 CosNaming::Name n = ex.rest_of_name;
1017 if (ex.why == CosNaming::NamingContext::missing_node)
1018 INFOS( "Destroy_Name() : " << (char *) n[0].id
1019 << " (" << (char *) n[0].kind << ") not found" )
1020 if (ex.why == CosNaming::NamingContext::not_context)
1021 INFOS( "Destroy_Name() : " << (char *) n[0].id
1022 << " (" << (char *) n[0].kind
1023 << ") is not a context" )
1024 if (ex.why == CosNaming::NamingContext::not_object)
1025 INFOS( "Destroy_Name() : " << (char *) n[0].id
1026 << " (" << (char *) n[0].kind
1027 << ") is not an object" )
1029 catch(CosNaming::NamingContext::CannotProceed&)
1031 INFOS( "!!!Destroy_Name() : CosNaming::NamingContext::CannotProceed")
1033 catch(CosNaming::NamingContext::InvalidName&)
1035 INFOS( "!!!Destroy_Name() : CosNaming::NamingContext::InvalidName")
1037 catch(CORBA::SystemException&)
1039 INFOS( "!!!Destroy_Name() :CORBA::SystemException : unable to contact"
1040 << " the naming service")
1041 throw ServiceUnreachable();
1043 // Memory destruction
1044 for (int i = 0 ; i <dimension_resultat ;i++)
1046 delete [] resultat_resolve_Path[i];
1048 delete[] resultat_resolve_Path ;
1051 //----------------------------------------------------------------------
1052 /*! Function : Destroy_Directory.
1053 * Purpose : method to destroy a directory if it is empty.
1054 * WARNING : The complete Path to the directory (from the root_context)
1055 * to destroy should be given.
1056 * If the NamingService is out, the exception ServiceUnreachable is thrown.
1057 * \param Path const char* arguments
1059 //----------------------------------------------------------------------
1061 void SALOME_NamingService::Destroy_Directory(const char* Path)
1062 throw(ServiceUnreachable)
1064 MESSAGE("BEGIN OF Destroy_Directory");
1065 Utils_Locker lock(&_myMutex);
1066 int dimension_Path = strlen(Path) + 1;
1067 char** resultat_resolve_Path = new char* [dimension_Path];
1069 // _current_context is replaced to the _root_context
1070 // if the Path begins whith '/'
1071 if (Path[0]=='/') _current_context = _root_context;
1073 CosNaming::NamingContext_var _ref_context = _current_context;
1075 //the resolution of the directory path has to be done
1076 //to place the currect_context to the correct node
1077 int dimension_resultat = 0;
1078 _result_resolve_Path (Path, dimension_resultat, resultat_resolve_Path);
1080 CosNaming::Name _context_name;
1081 if (dimension_resultat>1)
1083 // We go in the directory where the context to destroy is
1084 _context_name.length(dimension_resultat-1);
1086 _create_context_name_dir(resultat_resolve_Path,dimension_resultat -1,
1090 CORBA::Object_var _obj = _current_context->resolve(_context_name);
1091 _current_context = CosNaming::NamingContext::_narrow(_obj);
1092 _ref_context = _current_context ;
1094 catch (CosNaming::NamingContext::NotFound& ex)
1096 CosNaming::Name n = ex.rest_of_name;
1097 if (ex.why == CosNaming::NamingContext::missing_node)
1098 INFOS( "Destroy_Directory() : " << (char *) n[0].id
1099 << " (" << (char *) n[0].kind << ") not found")
1100 if (ex.why == CosNaming::NamingContext::not_context)
1101 INFOS( "Destroy_Directory() : " << (char *) n[0].id
1102 << " (" << (char *) n[0].kind
1103 << ") is not a context" )
1104 if (ex.why == CosNaming::NamingContext::not_object)
1105 INFOS( "Destroy_Directory() : " << (char *) n[0].id
1106 << " (" << (char *) n[0].kind
1107 << ") is not an object" )
1109 catch (CosNaming::NamingContext::InvalidName &)
1111 INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::InvalidName" )
1113 catch (CosNaming::NamingContext::CannotProceed &)
1115 INFOS("!!!Destroy_Directory(): CosNaming::NamingContext::CannotProceed" )
1117 catch(CORBA::SystemException&)
1119 INFOS( "!!!Destroy_Directory() : CORBA::SystemException : unable to contact"
1120 << " the naming service" )
1121 throw ServiceUnreachable();
1125 // the last element is the context to destroy
1126 _context_name.length(1);
1127 _context_name[0].id =
1128 CORBA::string_dup(resultat_resolve_Path[dimension_resultat -1]);
1129 _context_name[0].kind = CORBA::string_dup("dir");
1130 SCRUTE(_context_name[0].id);
1134 // We go in the context to destroy
1135 CORBA::Object_var _obj = _current_context->resolve(_context_name);
1136 _current_context = CosNaming::NamingContext::_narrow(_obj);
1138 catch (CosNaming::NamingContext::NotFound& ex)
1140 CosNaming::Name n = ex.rest_of_name;
1141 if (ex.why == CosNaming::NamingContext::missing_node)
1142 INFOS( "Destroy_Directory() : " << (char *) n[0].id
1143 << " (" << (char *) n[0].kind << ") not found" )
1144 if (ex.why == CosNaming::NamingContext::not_context)
1145 INFOS( "Destroy_Directory() : " << (char *) n[0].id
1146 << " (" << (char *) n[0].kind
1147 << ") is not a context" )
1148 if (ex.why == CosNaming::NamingContext::not_object)
1149 INFOS( "Destroy_Directory() : " << (char *) n[0].id
1150 << " (" << (char *) n[0].kind
1151 << ") is not an object" )
1153 catch (CosNaming::NamingContext::InvalidName &)
1155 INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::InvalidName" )
1157 catch (CosNaming::NamingContext::CannotProceed &)
1159 INFOS( "!!!Destroy_Directory(): CosNaming::NamingContext::CannotProceed" )
1161 catch(CORBA::SystemException&)
1163 INFOS( "!!!Destroy_Directory() : CORBA::SystemException : unable to contact"
1164 << " the naming service" )
1165 throw ServiceUnreachable();
1168 ASSERT(!CORBA::is_nil(_current_context));
1169 // Context Destruction
1172 _current_context->destroy();
1173 MESSAGE( "The context " << _context_name[0].id << " has been deleted" )
1175 catch(CosNaming::NamingContext::NotEmpty&)
1177 INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::NoEmpty "
1178 << Path << " is not empty" )
1180 catch(CORBA::SystemException&)
1182 INFOS( "!!!Destroy_Directory() :CORBA::SystemException : "
1183 << "unable to contact the naming service")
1184 throw ServiceUnreachable();
1186 // We go to the directory just before the context to delete
1187 _current_context = _ref_context ;
1190 _current_context->unbind(_context_name);
1191 MESSAGE( "The bind to the context " << _context_name[0].id << " has been deleted" )
1193 catch(CosNaming::NamingContext::NotFound& ex)
1195 CosNaming::Name n = ex.rest_of_name;
1196 if (ex.why == CosNaming::NamingContext::missing_node)
1197 INFOS( "Destroy_Directory() : " << (char *) n[0].id
1198 << " (" << (char *) n[0].kind << ") not found" )
1199 if (ex.why == CosNaming::NamingContext::not_context)
1200 INFOS( "Destroy_Directory() : " << (char *) n[0].id
1201 << " (" << (char *) n[0].kind
1202 << ") is not a context" )
1203 if (ex.why == CosNaming::NamingContext::not_object)
1204 INFOS( "Destroy_Directory() : " << (char *) n[0].id
1205 << " (" << (char *) n[0].kind
1206 << ") is not an object" )
1208 catch(CosNaming::NamingContext::CannotProceed&)
1210 INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::CannotProceed")
1212 catch(CosNaming::NamingContext::InvalidName&)
1214 INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::InvalidName")
1216 catch(CORBA::SystemException&)
1218 INFOS( "!!!Destroy_Directory() :CORBA::SystemException : unable to contact"
1219 << " the naming service")
1220 throw ServiceUnreachable();
1222 // Memory destruction
1223 for (int i = 0 ; i <dimension_resultat ;i++)
1225 delete [] resultat_resolve_Path[i];
1227 delete[] resultat_resolve_Path ;
1230 //----------------------------------------------------------------------
1231 /*! Function : Destroy_Directory.
1232 * Purpose : method to destroy a directory if it is empty.
1233 * WARNING : The complete Path to the directory (from the root_context)
1234 * to destroy should be given.
1235 * If the NamingService is out, the exception ServiceUnreachable is thrown.
1236 * \param Path const char* arguments
1238 //----------------------------------------------------------------------
1240 void SALOME_NamingService::Destroy_FullDirectory(const char* Path)
1241 throw(ServiceUnreachable)
1243 Change_Directory(Path);
1244 vector<string> contList = list_directory();
1245 for(unsigned int ind = 0; ind < contList.size(); ind++)
1246 Destroy_Name(contList[ind].c_str());
1247 Destroy_Directory(Path);
1251 //----------------------------------------------------------------------
1252 /*! Function : _initialize_root_context
1253 * Purpose : method called by constructor to initialize _root_context
1255 //----------------------------------------------------------------------
1257 void SALOME_NamingService::_initialize_root_context()
1259 //MESSAGE("Get the root context");
1262 CORBA::Object_var obj = _orb->resolve_initial_references("NameService");
1263 _root_context = CosNaming::NamingContext::_narrow(obj);
1264 _current_context = _root_context ;
1265 ASSERT(!CORBA::is_nil(_root_context));
1268 catch(CORBA::SystemException&)
1270 INFOS("CORBA::SystemException: unable to contact the naming service");
1271 throw ServiceUnreachable();
1275 INFOS("Unknown Exception: unable to contact the naming service");
1276 throw ServiceUnreachable();
1280 //----------------------------------------------------------------------
1281 /*! Function : _resolve_Path
1282 * Purpose : method to decompose a Path : /Kernel/Services/Sessions.
1284 * \return a char* containing the first char between '/' (in this case Kernel)
1286 //----------------------------------------------------------------------
1288 char* SALOME_NamingService::_resolve_Path(char* Path)
1291 int length = strlen(Path);
1294 if (length==0) return NULL;
1297 while ((i<length) && (Path[i]!='/'))
1299 resultat = new char[i+1];
1300 strncpy(resultat,Path,i);
1306 //----------------------------------------------------------------------
1307 /*! Function : _result_resolve_Path.
1308 * Purpose : method to decompose a Path : /Kernel/Services/Sessions.
1309 * Gives an array of char* containing Kernel, Services, Sessions.
1310 * \param Path const char* arguments, the Path to decompose
1311 * \param j int& arguments, the size of the array of char*
1312 * \param resultat_resolve_Path char** arguments
1314 //----------------------------------------------------------------------
1317 SALOME_NamingService::_result_resolve_Path(const char* Path,
1319 char ** resultat_resolve_Path)
1321 //MESSAGE("BEGIN OF _result_resolve_Path");
1322 int dimension_Path = strlen(Path) + 1;
1323 char** temp= new char* [dimension_Path];
1324 char** tempslash = new char* [dimension_Path];
1326 temp[j] = new char[dimension_Path];
1327 strcpy(temp[j],Path);
1329 while (strlen(temp[j])>0)
1331 // temp[j] contains the characters to be treated :
1332 // (Path - characters already treted)
1333 // tempslash[j] = temp[j] if the string temp[j] doesn't begin whith '/'
1334 // tempslash[j] = temp[j] without '/' if the string begins whith '/'
1335 int length_temp = strlen(temp[j]);
1336 if (temp[j][0]=='/')
1338 // the characters to be treated begin whith '/'
1339 // we don't have to take the '/'
1340 tempslash[j] = new char [length_temp] ;
1341 for (int k = 0; k < length_temp-1; k++)
1342 tempslash[j][k] = temp[j][k+1];
1343 tempslash[j][length_temp-1]='\0';
1347 //the characters to be trated don't begin with '/'
1348 // Nothing to be done on the char
1349 tempslash[j] = new char [length_temp+1] ;
1350 strcpy(tempslash[j],temp[j]);
1352 // decomposition of the Path
1353 resultat_resolve_Path[j]= _resolve_Path(tempslash[j]);
1354 //SCRUTE(resultat_resolve_Path[j]);
1356 int length_resultat = strlen(resultat_resolve_Path[j]) ;
1357 int dimension_temp = length_temp -length_resultat ;
1359 temp[j] = new char[dimension_temp +1];
1360 for (int i = 0 ; i <dimension_temp ;i++)
1362 temp[j][i] =tempslash[j-1][i+ length_resultat];
1364 temp[j][dimension_temp]= '\0';
1367 // Memory destruction
1368 for (int i = 0 ; i <j;i++)
1371 delete [] tempslash[i];
1374 delete [] tempslash ;
1377 //----------------------------------------------------------------------
1378 /*! Function : _Find.
1379 * Purpose : method to research a name from the current directory
1380 * of the naming service.
1381 * The naming service changes directory to go to the directory where
1382 * the last occurence was found.
1383 * \param name const char* arguments
1384 * \param occurence_number CORBA::LONG (by value)
1386 //----------------------------------------------------------------------
1388 void SALOME_NamingService::_Find(const char* name,
1389 CORBA::Long& occurence_number)
1391 //MESSAGE("BEGIN OF _Find") SCRUTE(name);
1392 CosNaming::BindingList_var _binding_list;
1393 CosNaming::BindingIterator_var _binding_iterator;
1394 unsigned long nb=0 ; //for using only the BindingIterator
1395 // to access the bindings
1396 CosNaming::Binding_var _binding ;
1397 CosNaming::NamingContext_var _ref_context = _current_context;
1398 CosNaming::NamingContext_var _found_context = _current_context;
1400 _current_context->list(nb, _binding_list, _binding_iterator) ;
1402 while (_binding_iterator->next_one(_binding)) {
1403 CosNaming::Name _bindingName = _binding->binding_name;
1404 if (_binding->binding_type == CosNaming::ncontext) {
1405 // We work on a directory, the search should be done in this directory
1406 Change_Directory(_bindingName[0].id);
1407 _Find(name,occurence_number);
1408 // We'll go back to the initial context
1409 _current_context = _ref_context ;
1411 else if (_binding->binding_type == CosNaming::nobject) {
1412 // We work on an object...
1413 if (!strcmp( _bindingName[0].id,name))
1415 //MESSAGE("One occurence was found");
1417 // We keep in memory the directory where one occurence was found
1418 _found_context = _current_context ;
1422 _binding_iterator->destroy();
1423 // We go to the last directory where an occurence was found
1424 _current_context = _found_context ;
1425 //SCRUTE(occurence_number);
1428 //----------------------------------------------------------------------
1429 /*! Function : _create_context_name_dir.
1430 * Purpose : method to create a Context_name from an array of char.
1431 * The number of elements to be copied are indicated
1434 * \param resultat_resolve_Path char** arguments
1435 * \param length_copy int arguments
1436 * \param _context_name CosNaming::Name arguments (by value)
1438 //----------------------------------------------------------------------
1441 SALOME_NamingService::_create_context_name_dir(char** resultat_resolve_Path
1443 CosNaming::Name& _context_name)
1445 //MESSAGE("BEGIN OF _create_context_name_dir");
1446 for (int i = 0 ; i < length_copy;i++)
1448 _context_name[i].id = CORBA::string_dup(resultat_resolve_Path[i]);
1449 _context_name[i].kind = CORBA::string_dup("dir");
1450 //SCRUTE(_context_name[i].id);
1454 //----------------------------------------------------------------------
1455 /*! Function : _current_directory.
1456 * Purpose : method to parse the naming service tree to find a context
1457 * and determine the path to go to this context from the
1459 * \param result_path char** arguments
1460 * \param length_result int arguments by value
1461 * \param context_to_found CosNaming::NamingContext_var arguments
1462 * \param _continue boolean arguments
1464 //----------------------------------------------------------------------
1467 SALOME_NamingService::_current_directory(char** result_path,
1469 CosNaming::NamingContext_var context_to_found,
1470 CORBA::Boolean& _continue)
1472 //MESSAGE("BEGIN OF _current_Directory");
1473 CosNaming::BindingList_var _binding_list;
1474 CosNaming::BindingIterator_var _binding_iterator;
1475 unsigned long nb=0 ; //for using only the BindingIterator
1476 // to access the bindings
1477 CosNaming::Binding_var _binding ;
1478 CosNaming::NamingContext_var _ref_context = _current_context;
1479 CosNaming::NamingContext_var _temp_context = _current_context;
1481 _current_context->list(nb, _binding_list, _binding_iterator) ;
1482 if ( !_binding_iterator->_is_nil() ) {
1483 while ((_binding_iterator->next_one(_binding)) && _continue) {
1484 CosNaming::Name _bindingName = _binding->binding_name;
1485 if (_binding->binding_type == CosNaming::ncontext)
1487 // We work on a directory, the search should be done in this directory
1489 result_path[length_result] = new char(strlen(_bindingName[0].id) + 1);
1490 strcpy(result_path[length_result],_bindingName[0].id);
1491 //SCRUTE(result_path[length_result])
1494 CORBA::Object_var _obj =_current_context->resolve(_bindingName);
1495 _temp_context = CosNaming::NamingContext::_narrow(_obj);
1497 if (_temp_context->_is_equivalent(context_to_found))
1499 //MESSAGE("The context is found, we stop the search");
1501 //SCRUTE(_continue);
1505 //SCRUTE(_bindingName[0].id);
1506 Change_Directory(_bindingName[0].id);
1507 _current_directory(result_path,length_result,
1508 context_to_found, _continue );
1511 // We'll go back to the initial context
1512 _current_context = _ref_context ;
1513 //MESSAGE("Just before the delete of ")
1514 //SCRUTE(result_path[length_result-1]);
1515 delete result_path[length_result-1];
1521 _binding_iterator->destroy();
1523 // We go to the last directory where an occurence was found
1524 _current_context = _ref_context ;
1528 //----------------------------------------------------------------------
1529 /*! Function :_list_directory_recurs.
1530 * Purpose : method to list recursively all the objects contained in the tree of absCurDirectory/relativeSubDir.
1531 * \param myList The list that will be filled.
1532 * \param relativeSubDir The directory from absCurDirectory in which the objects are found.
1533 * \param absCurDirectory The directory in ABSOLUTE form.
1534 * _current_context must refer to absCurDirectory.
1536 //----------------------------------------------------------------------
1537 void SALOME_NamingService::_list_directory_recurs(vector<string>& myList, const char *relativeSubDir,const char *absCurDirectory)
1539 CosNaming::BindingList_var _binding_list;
1540 CosNaming::BindingIterator_var _binding_iterator;
1541 unsigned long nb=0 ; // for using only the BindingIterator to access the bindings
1542 CosNaming::Binding_var _binding ;
1545 CosNaming::NamingContext_var _ref_context = _current_context;
1548 Change_Directory(relativeSubDir);
1549 absDir=new char[strlen(absCurDirectory)+2+strlen(relativeSubDir)];
1550 strcpy(absDir,absCurDirectory);
1551 strcat(absDir,relativeSubDir);
1555 absDir=(char *)absCurDirectory;
1556 _current_context->list(nb, _binding_list, _binding_iterator) ;
1558 while (_binding_iterator->next_one(_binding)) {
1559 CosNaming::Name _bindingName = _binding->binding_name;
1560 if (_binding->binding_type == CosNaming::ncontext) {
1561 _list_directory_recurs(myList,_bindingName[0].id,absDir);
1563 else if (_binding->binding_type == CosNaming::nobject) {
1564 char *elt=new char[strlen(absDir)+2+strlen(_bindingName[0].id)];
1566 strcat(elt,_bindingName[0].id);
1567 myList.push_back(elt);
1573 _current_context = _ref_context ;
1577 _binding_iterator->destroy();
1580 //----------------------------------------------------------------------
1582 char * SALOME_NamingService::getIORaddr()
1584 return _orb->object_to_string(_root_context);