]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Mecanisme de dump des containers
authorAnthony Geay <anthony.geay@edf.fr>
Tue, 20 Apr 2021 09:36:16 +0000 (11:36 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Tue, 20 Apr 2021 09:36:16 +0000 (11:36 +0200)
src/NamingService/NamingService.i
src/NamingService/SALOME_Fake_NamingService.cxx
src/NamingService/SALOME_Fake_NamingService.hxx

index a477d61656e33508516dffd950c17e5d2297b2cc..9b4eb638d504a0e08acc7bacbccb901aa69851c2 100644 (file)
@@ -36,6 +36,8 @@ class SALOME_Fake_NamingService
 public:
   SALOME_Fake_NamingService();
   std::vector< std::string > repr();
+  static void LaunchLogContainersFile(const std::string& logFileName);
+  static std::string GetLogContainersFile();
   %extend {
     std::string _ResolveInternal(const char *Path)
     {
index 9dd24c20f0071ec3f30d5a39022c01d5c4c04b22..5ca1bf3c8dc9b3d36c6b6b5fc74e8480a85a42b3 100644 (file)
 
 #include "SALOME_Fake_NamingService.hxx"
 #include "Utils_SALOME_Exception.hxx"
+#include "SALOME_KernelORB.hxx"
+
+#include CORBA_CLIENT_HEADER(SALOME_Component)
 
 #include <sstream>
+#include <fstream>
+#include <thread>
+#include <chrono>
 
 std::mutex SALOME_Fake_NamingService::_mutex;
 std::map<std::string,CORBA::Object_var> SALOME_Fake_NamingService::_map;
+bool SALOME_Fake_NamingService::_log_container_file_thread_launched = false;
+std::string SALOME_Fake_NamingService::_log_container_file_name;
 
 SALOME_Fake_NamingService::SALOME_Fake_NamingService(CORBA::ORB_ptr orb)
 {
@@ -110,3 +118,59 @@ CORBA::Object_ptr SALOME_Fake_NamingService::ResolveComponent(const char* hostna
   std::string entryToFind(oss.str());
   return Resolve(entryToFind.c_str());
 }
+
+std::vector<Engines::Container_var> SALOME_Fake_NamingService::ListOfContainersInNS()
+{
+  std::lock_guard<std::mutex> g(_mutex);
+  std::vector<Engines::Container_var> ret;
+  for(auto it : _map)
+  {
+    Engines::Container_var elt = Engines::Container::_narrow(it.second);
+    if(!CORBA::is_nil(elt))
+      ret.push_back(elt);
+  }
+  return ret;
+}
+
+std::string SALOME_Fake_NamingService::DumpInFileIORS()
+{
+  std::vector<Engines::Container_var> conts( ListOfContainersInNS() );
+  std::ostringstream oss;
+  CORBA::ORB_ptr orb = KERNEL::getORB();
+  char SEP[2] = { '\0', '\0'};
+  for(auto it : conts)
+  {
+    CORBA::String_var ior(orb->object_to_string(it));
+    oss << SEP << ior;
+    SEP[0] = '\n';
+  }
+  return oss.str();
+}
+
+void WriteContinuously(const std::string& logFileName)
+{
+  while(true)
+  {
+    std::chrono::milliseconds delta( 2000 );
+    std::this_thread::sleep_for( delta );
+    std::string content(SALOME_Fake_NamingService::DumpInFileIORS());
+    { 
+      std::ofstream ofs(logFileName);
+      ofs.write(content.c_str(),content.length());
+    }
+  }
+}
+
+void SALOME_Fake_NamingService::LaunchLogContainersFile(const std::string& logFileName)
+{
+  if(_log_container_file_thread_launched)
+    THROW_SALOME_EXCEPTION("SALOME_Fake_NamingService::LaunchLogContainersFile : Thread lready launched !");
+  _log_container_file_name = logFileName;
+  std::thread t(WriteContinuously,logFileName);
+  t.detach();
+}
+
+std::string SALOME_Fake_NamingService::GetLogContainersFile()
+{
+  return _log_container_file_name;
+}
index 1288aed749a07fd82a2efecbf8a8acd40deb61f7..4c7f81bc4b9300cfe082930f9c11f0604306b7b5 100644 (file)
 class NAMINGSERVICE_EXPORT SALOME_Fake_NamingService : public SALOME_NamingService_Abstract
 {
 public:
-    SALOME_Fake_NamingService(CORBA::ORB_ptr orb);
-    SALOME_Fake_NamingService() = default;
-    std::vector< std::string > repr() override;
-    void init_orb(CORBA::ORB_ptr orb=0) override;
-    void Register(CORBA::Object_ptr ObjRef, const char* Path) override;
-    CORBA::Object_ptr Resolve(const char* Path) override;
-    CORBA::Object_ptr ResolveFirst(const char* Path) override;
-    void Destroy_Name(const char* Path) override;
-    void Destroy_Directory(const char* Path) override;
-    void Destroy_FullDirectory(const char* Path) override;
-    bool Change_Directory(const char* Path) override;
-    std::vector<std::string> list_subdirs() override;
-    std::vector<std::string> list_directory() override;
-    std::vector<std::string> list_directory_recurs() override;
-    SALOME_NamingService_Abstract *clone() override;
-    CORBA::Object_ptr ResolveComponent(const char* hostname, const char* containerName, const char* componentName, const int nbproc=0) override;
+  SALOME_Fake_NamingService(CORBA::ORB_ptr orb);
+  SALOME_Fake_NamingService() = default;
+  static void LaunchLogContainersFile(const std::string& logFileName);
+  static std::string GetLogContainersFile();
+  std::vector< std::string > repr() override;
+  void init_orb(CORBA::ORB_ptr orb=0) override;
+  void Register(CORBA::Object_ptr ObjRef, const char* Path) override;
+  CORBA::Object_ptr Resolve(const char* Path) override;
+  CORBA::Object_ptr ResolveFirst(const char* Path) override;
+  void Destroy_Name(const char* Path) override;
+  void Destroy_Directory(const char* Path) override;
+  void Destroy_FullDirectory(const char* Path) override;
+  bool Change_Directory(const char* Path) override;
+  std::vector<std::string> list_subdirs() override;
+  std::vector<std::string> list_directory() override;
+  std::vector<std::string> list_directory_recurs() override;
+  SALOME_NamingService_Abstract *clone() override;
+  CORBA::Object_ptr ResolveComponent(const char* hostname, const char* containerName, const char* componentName, const int nbproc=0) override;
+  static std::string DumpInFileIORS();
 private:
-    static std::mutex _mutex;
-    static std::map<std::string,CORBA::Object_var> _map;
+  static std::vector<Engines::Container_var> ListOfContainersInNS();
+private:
+  static std::mutex _mutex;
+  static std::map<std::string,CORBA::Object_var> _map;
+  static bool _log_container_file_thread_launched;
+  static std::string _log_container_file_name;
 };