1 // Copyright (C) 2021-2024 CEA, EDF
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
20 #include "KernelBasis.hxx"
22 static bool DEFAULT_SSL_MODE = true;
23 static bool GUI_MODE = false;
25 // IOR of SALOME_Embedded_NamingService servant
26 static std::string IOR_OF_EMBEDDED_NS;
30 return DEFAULT_SSL_MODE;
33 void setSSLMode(bool sslMode)
35 DEFAULT_SSL_MODE = sslMode;
43 void setGUIMode(bool guiMode)
48 std::string getIOROfEmbeddedNS()
50 return IOR_OF_EMBEDDED_NS;
53 void setIOROfEmbeddedNS(const std::string& ior)
55 IOR_OF_EMBEDDED_NS = ior;
61 * Callable from Python in case if sys.stdout is not connected to tty
63 void WriteInStdout(const std::string& msg)
65 std::cout << msg << std::endl << std::flush;
69 * Callable from Python in case if sys.stdout is not connected to tty
71 void WriteInStderr(const std::string& msg)
73 std::cerr << msg << std::endl << std::flush;
78 static constexpr char IN_PROCESS_VALUE = 0;
79 static constexpr char IN_PROCESS_VALUE_STR[] = "InProcess";
80 static constexpr char OUT_OF_PROCESS_NO_REPLAY_VALUE = 1;
81 static constexpr char OUT_OF_PROCESS_NO_REPLAY_VALUE_STR[] = "OutOfProcessNoReplay";
82 static constexpr char OUT_OF_PROCESS_WITH_REPLAY_VALUE = 2;
83 static constexpr char OUT_OF_PROCESS_WITH_REPLAY_VALUE_STR[] = "OutOfProcessWithReplay";
84 static constexpr char OUT_OF_PROCESS_NO_REPLAY_FT_VALUE = 3;
85 static constexpr char OUT_OF_PROCESS_NO_REPLAY_FT_VALUE_STR[] = "OutOfProcessNoReplayFT";
86 static constexpr char OUT_OF_PROCESS_WITH_REPLAY_FT_VALUE = 4;
87 static constexpr char OUT_OF_PROCESS_WITH_REPLAY_FT_VALUE_STR[] = "OutOfProcessWithReplayFT";
89 static PyExecutionMode FromIntToPyExecutionMode(char value)
93 case IN_PROCESS_VALUE:
94 return PyExecutionMode::InProcess;
95 case OUT_OF_PROCESS_NO_REPLAY_VALUE:
96 return PyExecutionMode::OutOfProcessNoReplay;
97 case OUT_OF_PROCESS_WITH_REPLAY_VALUE:
98 return PyExecutionMode::OutOfProcessWithReplay;
99 case OUT_OF_PROCESS_NO_REPLAY_FT_VALUE:
100 return PyExecutionMode::OutOfProcessNoReplayFT;
101 case OUT_OF_PROCESS_WITH_REPLAY_FT_VALUE:
102 return PyExecutionMode::OutOfProcessWithReplayFT;
104 throw std::range_error("FromIntToPyExecutionMode : Invalid value for Py Execution Mode ! Must be in 0 (InProcess), 1 (OutOfProcessNoReplay) or 2 (OutOfProcessWithReplay) !");
107 static PyExecutionMode FromStrToPyExecutionMode(const std::string& value)
109 if(value == IN_PROCESS_VALUE_STR)
110 return PyExecutionMode::InProcess;
111 if(value == OUT_OF_PROCESS_NO_REPLAY_VALUE_STR)
112 return PyExecutionMode::OutOfProcessNoReplay;
113 if(value == OUT_OF_PROCESS_WITH_REPLAY_VALUE_STR)
114 return PyExecutionMode::OutOfProcessWithReplay;
115 if(value == OUT_OF_PROCESS_NO_REPLAY_FT_VALUE_STR)
116 return PyExecutionMode::OutOfProcessNoReplayFT;
117 if(value == OUT_OF_PROCESS_WITH_REPLAY_FT_VALUE_STR)
118 return PyExecutionMode::OutOfProcessWithReplayFT;
119 throw std::range_error("FromStrToPyExecutionMode : Invalid str value for py execution mode !");
122 static std::string FromExecutionModeToStr(PyExecutionMode execMode)
126 case PyExecutionMode::InProcess:
127 return IN_PROCESS_VALUE_STR;
128 case PyExecutionMode::OutOfProcessNoReplay:
129 return OUT_OF_PROCESS_NO_REPLAY_VALUE_STR;
130 case PyExecutionMode::OutOfProcessWithReplay:
131 return OUT_OF_PROCESS_WITH_REPLAY_VALUE_STR;
132 case PyExecutionMode::OutOfProcessNoReplayFT:
133 return OUT_OF_PROCESS_NO_REPLAY_FT_VALUE_STR;
134 case PyExecutionMode::OutOfProcessWithReplayFT:
135 return OUT_OF_PROCESS_WITH_REPLAY_FT_VALUE_STR;
137 throw std::range_error("FromExecutionModeToStr : Invalid str value for py execution mode !");
142 constexpr int SALOME_BIG_OBJ_ON_DISK_THRES_DFT = 50000000;
144 static int SALOME_BIG_OBJ_ON_DISK_THRES = SALOME_BIG_OBJ_ON_DISK_THRES_DFT;
146 int SALOME::GetBigObjOnDiskThreshold()
148 return SALOME_BIG_OBJ_ON_DISK_THRES;
151 void SALOME::SetBigObjOnDiskThreshold(int newThresholdInByte)
153 SALOME_BIG_OBJ_ON_DISK_THRES = newThresholdInByte;
156 static std::string SALOME_FILE_BIG_OBJ_DIR;
158 constexpr int DFT_SALOME_NB_RETRY = 1;
160 static int SALOME_NB_RETRY = DFT_SALOME_NB_RETRY;
162 std::string SALOME::GetBigObjOnDiskDirectory()
164 return SALOME_FILE_BIG_OBJ_DIR;
167 void SALOME::SetBigObjOnDiskDirectory(const std::string& directory)
169 SALOME_FILE_BIG_OBJ_DIR = directory;
172 bool SALOME::BigObjOnDiskDirectoryDefined()
174 return ! SALOME_FILE_BIG_OBJ_DIR.empty();
177 void SALOME::SetNumberOfRetry(int nbRetry)
179 SALOME_NB_RETRY = nbRetry;
182 int SALOME::GetNumberOfRetry()
184 return SALOME_NB_RETRY;
187 static SALOME::PyExecutionMode DefaultPyExecMode = SALOME::PyExecutionMode::NotSet;
189 void SALOME::SetPyExecutionMode(PyExecutionMode mode)
191 DefaultPyExecMode = mode;
194 void SALOME::SetPyExecutionModeStr(const std::string& mode)
196 SALOME::SetPyExecutionMode( SALOME::FromStrToPyExecutionMode(mode) );
199 std::vector<std::string> SALOME::GetAllPyExecutionModes()
201 return {IN_PROCESS_VALUE_STR,OUT_OF_PROCESS_NO_REPLAY_VALUE_STR,OUT_OF_PROCESS_WITH_REPLAY_VALUE_STR};
204 std::string SALOME::GetPyExecutionModeStr()
206 return SALOME::FromExecutionModeToStr( SALOME::GetPyExecutionMode() );
209 SALOME::PyExecutionMode SALOME::GetPyExecutionMode()
211 auto isEnvVarSet = []() -> SALOME::PyExecutionMode
213 const char *envVar = std::getenv("SALOME_PY_EXECUTION_MODE");
214 if (envVar && (envVar[0] != '\0'))
216 const int numValue = std::stoi(envVar);
217 return SALOME::FromIntToPyExecutionMode( static_cast<char>(numValue) );
219 return SALOME::PyExecutionMode::InProcess;
221 if(DefaultPyExecMode == SALOME::PyExecutionMode::NotSet)
222 DefaultPyExecMode = isEnvVarSet();
223 return DefaultPyExecMode;