1 // Copyright (C) 2021-2024 CEA, EDF
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SALOME_Fake_NamingService.hxx"
24 #include "SALOME_Embedded_NamingService.hxx"
25 #include "SALOME_KernelORB.hxx"
26 #include "Utils_SALOME_Exception.hxx"
29 %include "std_string.i"
30 %include "std_vector.i"
32 %rename(NamingService) SALOME_Fake_NamingService ;
34 %template(svec) std::vector<std::string>;
36 %exceptionclass SALOME_Exception;
38 class SALOME_Exception
41 SALOME_Exception(const std::string& text);
42 ~SALOME_Exception() noexcept;
43 const char *what() const noexcept;
46 std::string __str__() const
48 return std::string(self->what());
57 catch (SALOME_Exception& _e) {
58 // Reraise with SWIG_Python_Raise
59 SWIG_Python_Raise(SWIG_NewPointerObj((new SALOME_Exception(static_cast< const SALOME_Exception& >(_e))),SWIGTYPE_p_SALOME_Exception,SWIG_POINTER_OWN), "SALOME_Exception", SWIGTYPE_p_SALOME_Exception);
64 class SALOME_Fake_NamingService
67 SALOME_Fake_NamingService();
68 std::vector< std::string > repr();
69 static std::string GetLogContainersFile();
70 static void FlushLogContainersFile();
71 void Destroy_Name(const char* Path);
72 void Destroy_FullDirectory(const char* Path);
74 static void SetLogContainersFileInternal(const std::string& logFileName)
76 SALOME_Fake_NamingService::SetLogContainersFile(logFileName);
78 std::string _ResolveInternal(const char *Path)
80 CORBA::Object_var obj = self->Resolve(Path);
81 CORBA::ORB_ptr orb = KERNEL::getORB();
82 CORBA::String_var ior = orb->object_to_string(obj);
83 return std::string(ior);
85 void _RegisterInternal(const char *ior, const char* Path)
87 CORBA::ORB_ptr orb = KERNEL::getORB();
88 CORBA::Object_var obj = orb->string_to_object(ior);
89 self->Register(obj,Path);
91 std::string _Resolve_DirInternal(const char *Path)
93 CORBA::ORB_ptr orb = KERNEL::getORB();
94 CORBA::Object_var ret = self->Resolve(Path);
95 CORBA::String_var ior = orb->object_to_string(ret);
96 return std::string(ior.in());
98 static std::string IOROfNS()
100 CORBA::ORB_ptr orb = KERNEL::getORB();
101 Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
102 CORBA::String_var ior = orb->object_to_string(ns);
103 return std::string(ior);
109 def NamingService_Resolve(self,Path):
110 ret = self._ResolveInternal(Path)
112 orb=CORBA.ORB_init([''])
113 return orb.string_to_object(ret)
114 def NamingService_Register(self,obj,Path):
116 orb=CORBA.ORB_init([''])
117 self._RegisterInternal( orb.object_to_string(obj) , Path)
118 def NamingService_Resolve_Dir(self,Path):
119 ret = self._Resolve_DirInternal( Path )
121 orb=CORBA.ORB_init([''])
122 return orb.string_to_object(ret)
123 NamingService.Resolve = NamingService_Resolve
124 NamingService.Register = NamingService_Register
125 NamingService.Resolve_Dir = NamingService_Resolve_Dir
126 def NamingService_SetLogContainersFile(cls,logFileName = None):
127 if logFileName is None:
129 with tempfile.NamedTemporaryFile() as f:
131 cls.SetLogContainersFileInternal(logFileName)
132 NamingService.SetLogContainersFile = classmethod(NamingService_SetLogContainersFile)
133 def NamingService_RefOfNS(cls):
137 orb=CORBA.ORB_init([''])
138 return orb.string_to_object(ret)
139 NamingService.RefOfNS = classmethod(NamingService_RefOfNS)
140 def NamingService_DumpIORInFile(cls,iorFileName):
141 with open( iorFileName, "w" ) as f:
142 f.write( cls.IOROfNS() )
143 NamingService.DumpIORInFile = classmethod(NamingService_DumpIORInFile)
144 def NamingService_LoadIORInFile(cls,iorFileName):
147 orb=CORBA.ORB_init([''])
148 with open( iorFileName ) as f:
150 ref = orb.string_to_object(ior)
152 NamingService.LoadIORInFile = classmethod( NamingService_LoadIORInFile )
153 def NamingService_KillContainersInFile(cls,logFileName):
156 orb=CORBA.ORB_init([''])
157 with open(logFileName) as f:
158 cont_to_kill = [elt.split(" : ") for elt in f]
159 for name,ior in cont_to_kill:
161 ref = orb.string_to_object(ior)
163 except Exception as e:
164 print("Failed to kill container remotely \"{}\"".format(name))
165 NamingService.KillContainersInFile = classmethod(NamingService_KillContainersInFile)