From 84fdbdd2272dd946dc6d370baab1fe690f0c0034 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Tue, 20 Apr 2021 11:36:16 +0200 Subject: [PATCH] Mecanisme de dump des containers --- src/NamingService/NamingService.i | 2 + .../SALOME_Fake_NamingService.cxx | 64 +++++++++++++++++++ .../SALOME_Fake_NamingService.hxx | 43 +++++++------ 3 files changed, 91 insertions(+), 18 deletions(-) diff --git a/src/NamingService/NamingService.i b/src/NamingService/NamingService.i index a477d6165..9b4eb638d 100644 --- a/src/NamingService/NamingService.i +++ b/src/NamingService/NamingService.i @@ -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) { diff --git a/src/NamingService/SALOME_Fake_NamingService.cxx b/src/NamingService/SALOME_Fake_NamingService.cxx index 9dd24c20f..5ca1bf3c8 100644 --- a/src/NamingService/SALOME_Fake_NamingService.cxx +++ b/src/NamingService/SALOME_Fake_NamingService.cxx @@ -19,11 +19,19 @@ #include "SALOME_Fake_NamingService.hxx" #include "Utils_SALOME_Exception.hxx" +#include "SALOME_KernelORB.hxx" + +#include CORBA_CLIENT_HEADER(SALOME_Component) #include +#include +#include +#include std::mutex SALOME_Fake_NamingService::_mutex; std::map 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 SALOME_Fake_NamingService::ListOfContainersInNS() +{ + std::lock_guard g(_mutex); + std::vector 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 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; +} diff --git a/src/NamingService/SALOME_Fake_NamingService.hxx b/src/NamingService/SALOME_Fake_NamingService.hxx index 1288aed74..4c7f81bc4 100644 --- a/src/NamingService/SALOME_Fake_NamingService.hxx +++ b/src/NamingService/SALOME_Fake_NamingService.hxx @@ -30,23 +30,30 @@ 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 list_subdirs() override; - std::vector list_directory() override; - std::vector 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 list_subdirs() override; + std::vector list_directory() override; + std::vector 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 _map; + static std::vector ListOfContainersInNS(); +private: + static std::mutex _mutex; + static std::map _map; + static bool _log_container_file_thread_launched; + static std::string _log_container_file_name; }; -- 2.39.2