1 // Copyright (C) 2021 CEA/DEN, EDF R&D
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();
72 static void SetLogContainersFileInternal(const std::string& logFileName)
74 SALOME_Fake_NamingService::SetLogContainersFile(logFileName);
76 std::string _ResolveInternal(const char *Path)
78 CORBA::Object_var obj = self->Resolve(Path);
79 CORBA::ORB_ptr orb = KERNEL::getORB();
80 CORBA::String_var ior = orb->object_to_string(obj);
81 return std::string(ior);
83 void _RegisterInternal(const char *ior, const char* Path)
85 CORBA::ORB_ptr orb = KERNEL::getORB();
86 CORBA::Object_var obj = orb->string_to_object(ior);
87 self->Register(obj,Path);
89 static std::string IOROfNS()
91 CORBA::ORB_ptr orb = KERNEL::getORB();
92 Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
93 CORBA::String_var ior = orb->object_to_string(ns);
94 return std::string(ior);
100 def NamingService_Resolve(self,Path):
101 ret = self._ResolveInternal(Path)
103 orb=CORBA.ORB_init([''])
104 return orb.string_to_object(ret)
105 def NamingService_Register(self,obj,Path):
107 orb=CORBA.ORB_init([''])
108 self._RegisterInternal( orb.object_to_string(obj) , Path)
109 NamingService.Resolve = NamingService_Resolve
110 NamingService.Register = NamingService_Register
111 def NamingService_SetLogContainersFile(cls,logFileName = None):
112 if logFileName is None:
114 with tempfile.NamedTemporaryFile() as f:
116 cls.SetLogContainersFileInternal(logFileName)
117 NamingService.SetLogContainersFile = classmethod(NamingService_SetLogContainersFile)
118 def NamingService_RefOfNS(cls):
122 orb=CORBA.ORB_init([''])
123 return orb.string_to_object(ret)
124 NamingService.RefOfNS = classmethod(NamingService_RefOfNS)
125 def NamingService_KillContainersInFile(cls,logFileName):
128 orb=CORBA.ORB_init([''])
129 with open(logFileName) as f:
130 cont_to_kill = [elt.split(" : ") for elt in f]
131 for name,ior in cont_to_kill:
133 ref = orb.string_to_object(ior)
135 except Exception as e:
136 print("Failed to kill container remotely \"{}\"".format(name))
137 NamingService.KillContainersInFile = classmethod(NamingService_KillContainersInFile)