#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)
{
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;
+}
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;
};