]> SALOME platform Git repositories - modules/yacs.git/blob - src/NamingService/SALOME_NamingService.hxx
Salome HOME
PR: merge from branch BR_UnitTests tag mergeto_trunk_17oct05
[modules/yacs.git] / src / NamingService / SALOME_NamingService.hxx
1 //  SALOME NamingService : wrapping NamingService services
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOME_NamingService.hxx
25 //  Author : Estelle Deville
26 //  Module : SALOME
27 //  $Header$
28
29 #ifndef SALOME_NAMINGSERVICE_H
30 #define SALOME_NAMINGSERVICE_H
31
32 #include "utilities.h"
33 #include <CORBA.h>
34 #include <vector>
35 #include <string>
36 #include "Utils_Mutex.hxx"
37
38 #include <SALOMEconfig.h>
39 #include CORBA_CLIENT_HEADER(SALOME_ContainerManager)
40 #include CORBA_CLIENT_HEADER(SALOME_Component)
41 //class ServiceUnreachable;
42 #include "ServiceUnreachable.hxx"
43
44 #if defined NAMINGSERVICE_EXPORTS
45 #if defined WIN32
46 #define NAMINGSERVICE_EXPORT __declspec( dllexport )
47 #else
48 #define NAMINGSERVICE_EXPORT
49 #endif
50 #else
51 #if defined WNT
52 #define NAMINGSERVICE_EXPORT __declspec( dllimport )
53 #else
54 #define NAMINGSERVICE_EXPORT
55 #endif
56 #endif
57
58 class NAMINGSERVICE_EXPORT SALOME_NamingService
59 {
60 public:
61   //! default constructor
62   SALOME_NamingService();
63
64   //! standard constructor
65   SALOME_NamingService(CORBA::ORB_ptr orb);
66
67   //! standard destructor
68   virtual ~SALOME_NamingService();
69
70   //! initialize ORB reference after default constructor
71   void init_orb(CORBA::ORB_ptr orb);
72  
73   //! method to create an association in the NamingService between an object reference and a path
74   void Register(CORBA::Object_ptr ObjRef, const char* Path) 
75     throw(ServiceUnreachable);
76
77   //! method to get the ObjRef of a symbolic name
78   CORBA::Object_ptr Resolve(const char* Path)
79     throw( ServiceUnreachable); 
80
81   //! method to get the ObjRef of a component
82   CORBA::Object_ptr ResolveComponent(const char* hostname, const char* containerName, const char* componentName, const int nbproc=0);
83
84  //! method to get an ObjRef, given a symbolic name without instance suffix "/Path/Name*.kind"
85   CORBA::Object_ptr ResolveFirst(const char* Path)
86     throw( ServiceUnreachable); 
87
88   std::string ContainerName(const char *ContainerName);
89   std::string ContainerName(const Engines::MachineParameters& params);
90
91   std::string BuildContainerNameForNS(const char *ContainerName, const char *hostname);
92   std::string BuildContainerNameForNS(const Engines::MachineParameters& params, const char *hostname);
93
94   //! method to research a name from the naming service's current directory 
95   int Find(const char* name)
96     throw(ServiceUnreachable);
97   
98   //! method to create a directory from the current directory
99   bool Create_Directory(const char* Path)
100     throw(ServiceUnreachable);
101   
102   //! method to change the current directory to the directory Path indicated in "in" Parameter
103   bool Change_Directory(const char* Path)
104     throw(ServiceUnreachable);
105  
106   //!method to get the current directory
107   char* Current_Directory()
108     throw(ServiceUnreachable);
109
110   //!method to print all the contexts contained from the current directory
111   void list()
112     throw(ServiceUnreachable);
113
114   //!method to get all the contexts contained in the current direcotry
115   // Get only objects, isn't iterative
116   std::vector<std::string> list_directory()
117     throw(ServiceUnreachable);
118
119   //!methods that lists all objects RECUSIVELY in the current directory
120   std::vector<std::string> list_directory_recurs()
121     throw(ServiceUnreachable);
122  
123   //! method to destroy an association Path-Object Reference
124   void Destroy_Name(const char* Path)
125     throw(ServiceUnreachable);
126  
127   //! method to destroy a directory if it is empty
128   virtual void Destroy_Directory(const char* Path)
129     throw(ServiceUnreachable);
130
131   //! method to destroy a directory even if it is not empty
132   virtual void Destroy_FullDirectory(const char* Path)
133     throw(ServiceUnreachable);
134
135   //! get IORstring naming service address 
136   char * getIORaddr();
137
138 protected:
139   Utils_Mutex _myMutex;
140   CORBA::ORB_ptr _orb;
141   CosNaming::NamingContext_var _root_context, _current_context;
142
143   //! method called by constructor to initialize _root_context
144   void _initialize_root_context();
145   
146   //! method to decompose a Path : /Kernel/Services/Sessions
147   char* _resolve_Path(char* Path);
148
149   //! method to decompose a Path : /Kernel/Services/Sessions
150   void _result_resolve_Path(const char* Path, int& j,
151                             char ** resultat_resolve_Path);
152
153   //! internal method called by Find to research a name from the naming service's current directory 
154   void _Find(const char* name, CORBA::Long& occurence_number);
155
156   //! internal method to create a context name from a Path
157   void _create_context_name_dir(char** resultat_resolve_Path,
158                                 int length_copy,
159                                 CosNaming::Name& _context_name);
160
161   //! internal method to create a parse the naming service tree 
162   void _current_directory(char** result_path,
163                           int& length_result,
164                           CosNaming::NamingContext_var context_to_found,
165                           CORBA::Boolean& _continue);
166
167   //! internal method to list all (recursively) the objects contains in absCurDirectory/relativeSubDir.
168   void _list_directory_recurs(std::vector<std::string>& myList, const char *relativeSubDir,const char *absCurDirectory);
169
170 };
171
172 #endif // SALOME_NAMINGSERVICE_H
173