-// Copyright (C) 2019 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2019-2021 CEA/DEN, EDF R&D, OPEN CASCADE
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#include CORBA_CLIENT_HEADER(SALOME_ExternalServerLauncher)
+#ifndef WIN32
#include <unistd.h>
+#else
+#include <windows.h>
+#include <Basics_Utils.hxx>
+#endif
#include <sstream>
#include <fstream>
#include <algorithm>
#include <memory>
+#include <functional>
-constexpr char NAME_IN_NS[]="/ExternalServers";
+const char SALOME_ExternalServerLauncher::NAME_IN_NS[]="/ExternalServers";
unsigned SALOME_ExternalServerLauncher::CNT = 0;
class ChdirRAII
{
public:
+#ifndef WIN32
ChdirRAII(const std::string& wd):_wd(wd) { if(_wd.empty()) return ; char *pwd(get_current_dir_name()); _od = pwd; free(pwd); chdir(_wd.c_str()); }
~ChdirRAII() { if(_od.empty()) return ; chdir(_od.c_str()); }
+#else
+ ChdirRAII(const std::string& wd) : _wd(wd) {
+ if (_wd.empty())
+ return;
+ TCHAR pwd[MAX_PATH];
+ GetCurrentDirectory(sizeof(pwd), pwd);
+ _od = Kernel_Utils::utf8_encode_s(pwd);
+ SetCurrentDirectory(Kernel_Utils::utf8_decode_s(_wd).c_str());
+ }
+ ~ChdirRAII() {
+ if (_od.empty()) return;
+ SetCurrentDirectory(Kernel_Utils::utf8_decode_s(_od).c_str());
+ }
+#endif
private:
std::string _wd;
std::string _od;
throw SALOME_LauncherException(oss2.str());
}
std::vector<std::string> cmd(command_list.length());
- const char *toto(command_list[0]);
- for(auto i=0;i<command_list.length();i++)
+ for(size_t i=0;i<command_list.length();i++)
cmd[i] = command_list[i];
long pid(0);
try
std::ostringstream oss;
oss << "Custom_"<< server_name << "_" << CNT++;
_pyHelper->registerToSalomePiDict(oss.str(),PID);
+ _list_of_pids_to_kill.push_back(PID);
}
void SALOME_ExternalServerLauncher::cleanServersInNS()
void SALOME_ExternalServerLauncher::shutdownServers()
{
+ for(auto pid : this->_list_of_pids_to_kill)
+ {
+ SALOME_ExternalServerHandler::KillPID(pid);
+ }
+ //
std::vector<std::string> lioes(ListOfExternalServersCpp(_NS));
for(auto servName : lioes)
{
std::vector<std::string> loes(ListOfExternalServersCpp(_NS));
std::size_t sz(loes.size());
ret->length(sz);
- for(auto i = 0; i<sz ; i++)
+ for(size_t i=0; i<sz; i++)
{
(*ret)[i]=CORBA::string_dup(loes[i].c_str());
}
//
std::unique_ptr<SALOME::ByteVec> ret(new SALOME::ByteVec);
ret->length(size);
- for(std::size_t i=0;i<size;++i)
+ for(size_t i=0;i<size;++i)
(*ret)[i] = buffer.get()[i];
//
if( unlink(file_name)!=0 )