From e90986ff375800685b3f31a917615b01e7622fe7 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Mon, 17 Jun 2024 09:47:04 +0200 Subject: [PATCH] [30157] Improve steering control methods to pilot protocol of exchange file --- src/Basics/KernelBasis.cxx | 50 ++++++++++++++++++++++++++++++-------- src/Basics/KernelBasis.hxx | 14 ++++++++++- src/Basics/KernelBasis.i | 16 ++++++++++-- 3 files changed, 67 insertions(+), 13 deletions(-) diff --git a/src/Basics/KernelBasis.cxx b/src/Basics/KernelBasis.cxx index c49036e7f..63e692922 100644 --- a/src/Basics/KernelBasis.cxx +++ b/src/Basics/KernelBasis.cxx @@ -20,6 +20,7 @@ #include "KernelBasis.hxx" #include +#include static bool DEFAULT_SSL_MODE = true; static bool GUI_MODE = false; @@ -155,12 +156,6 @@ void SALOME::SetBigObjOnDiskThreshold(int newThresholdInByte) SALOME_BIG_OBJ_ON_DISK_THRES = newThresholdInByte; } -enum class BigObjTransferProtocol : char -{ - SharedFileSystem = 0, - SSDCopyFileSystem = 1 -}; - constexpr char SALOME_FILE_BIG_OBJ_DIR_SEP = '@'; static std::string SALOME_FILE_BIG_OBJ_DIR; @@ -169,27 +164,62 @@ constexpr int DFT_SALOME_NB_RETRY = 1; static int SALOME_NB_RETRY = DFT_SALOME_NB_RETRY; +SALOME::BigObjTransferProtocol SALOME::FromIntToBigObjOnDiskProtocol(char protocol) +{ + switch( protocol ) + { + case SALOME::SHARED_FILE_SYSTEM_PROTOCOL: + return SALOME::BigObjTransferProtocol::SharedFileSystem; + case SALOME::SSD_COPY_FILE_SYSTEM_PROTOCOL: + return SALOME::BigObjTransferProtocol::SSDCopyFileSystem; + default: + throw std::runtime_error("FromIntToBigObjOnDiskProtocol unrecognized protocol ! should be in [0,1] !"); + } +} + +SALOME::BigObjTransferProtocol SALOME::BigObjOnDiskProtocolFromStr(const std::string& protocol) +{ + if( protocol == SALOME::SHARED_FILE_SYSTEM_PROTOCOL_STR ) + return SALOME::BigObjTransferProtocol::SharedFileSystem; + if( protocol == SALOME::SSD_COPY_FILE_SYSTEM_PROTOCOL_STR ) + return SALOME::BigObjTransferProtocol::SSDCopyFileSystem; + throw std::runtime_error("BigObjOnDiskProtocolFromStr unrecognized protocol !"); +} + +std::string SALOME::BigObjOnDiskProtocolToStr(BigObjTransferProtocol protocol) +{ + switch( protocol ) + { + case SALOME::BigObjTransferProtocol::SharedFileSystem: + return SALOME::SHARED_FILE_SYSTEM_PROTOCOL_STR; + case SALOME::BigObjTransferProtocol::SSDCopyFileSystem: + return SALOME::SSD_COPY_FILE_SYSTEM_PROTOCOL_STR; + default: + throw std::runtime_error("FromIntToBigObjOnDiskProtocol unrecognized protocol ! should be in [0,1] !"); + } +} + /*! * This method returns the protocol of proxy transfert and the directory */ -int SALOME::GetBigObjOnDiskProtocolAndDirectory(std::string& directory) +SALOME::BigObjTransferProtocol SALOME::GetBigObjOnDiskProtocolAndDirectory(std::string& directory) { if(SALOME_FILE_BIG_OBJ_DIR.size() < 3) { directory = SALOME_FILE_BIG_OBJ_DIR; - return static_cast( BigObjTransferProtocol::SharedFileSystem ); + return SALOME::BigObjTransferProtocol::SharedFileSystem; } std::string protocol = SALOME_FILE_BIG_OBJ_DIR.substr(0,3); directory = SALOME_FILE_BIG_OBJ_DIR.substr(3); if( protocol[0]!=SALOME_FILE_BIG_OBJ_DIR_SEP || protocol[2]!=SALOME_FILE_BIG_OBJ_DIR_SEP) { directory = SALOME_FILE_BIG_OBJ_DIR; - return static_cast( BigObjTransferProtocol::SharedFileSystem ); + return SALOME::BigObjTransferProtocol::SharedFileSystem; } std::istringstream iss(protocol.substr(1,1)); iss.exceptions(std::istringstream::failbit | std::istringstream::badbit); char iproxyprot = 0; iss >> iproxyprot; - return iproxyprot; + return FromIntToBigObjOnDiskProtocol( iproxyprot ); } std::string SALOME::GetBigObjOnDiskDirectory() diff --git a/src/Basics/KernelBasis.hxx b/src/Basics/KernelBasis.hxx index d40a422b8..2b3547e4b 100644 --- a/src/Basics/KernelBasis.hxx +++ b/src/Basics/KernelBasis.hxx @@ -37,7 +37,16 @@ void BASICS_EXPORT WriteInStderr(const std::string& msg); namespace SALOME { + constexpr char SHARED_FILE_SYSTEM_PROTOCOL = 0; + constexpr char SSD_COPY_FILE_SYSTEM_PROTOCOL = 1; + const char SHARED_FILE_SYSTEM_PROTOCOL_STR[] = "SharedFileSystem"; + const char SSD_COPY_FILE_SYSTEM_PROTOCOL_STR[] = "SSDCopyFileSystem"; + enum class PyExecutionMode { NotSet, InProcess, OutOfProcessNoReplay, OutOfProcessWithReplay, OutOfProcessNoReplayFT, OutOfProcessWithReplayFT }; + + enum class BigObjTransferProtocol : char + { SharedFileSystem = SHARED_FILE_SYSTEM_PROTOCOL, SSDCopyFileSystem = SSD_COPY_FILE_SYSTEM_PROTOCOL }; + void BASICS_EXPORT SetPyExecutionMode(PyExecutionMode mode); void BASICS_EXPORT SetPyExecutionModeStr(const std::string& mode); std::vector BASICS_EXPORT GetAllPyExecutionModes(); @@ -45,7 +54,10 @@ namespace SALOME PyExecutionMode BASICS_EXPORT GetPyExecutionMode(); int BASICS_EXPORT GetBigObjOnDiskThreshold(); void BASICS_EXPORT SetBigObjOnDiskThreshold(int newThresholdInByte); - int BASICS_EXPORT GetBigObjOnDiskProtocolAndDirectory(std::string& directory); + std::string BASICS_EXPORT BigObjOnDiskProtocolToStr(BigObjTransferProtocol protocol); + BigObjTransferProtocol BASICS_EXPORT BigObjOnDiskProtocolFromStr(const std::string& protocol); + BigObjTransferProtocol BASICS_EXPORT FromIntToBigObjOnDiskProtocol(char protocol); + BigObjTransferProtocol BASICS_EXPORT GetBigObjOnDiskProtocolAndDirectory(std::string& directory); std::string BASICS_EXPORT GetBigObjOnDiskDirectory(); void BASICS_EXPORT SetBigObjOnDiskDirectory(const std::string& directory); bool BASICS_EXPORT BigObjOnDiskDirectoryDefined(); diff --git a/src/Basics/KernelBasis.i b/src/Basics/KernelBasis.i index 70920c990..c87b89a5a 100644 --- a/src/Basics/KernelBasis.i +++ b/src/Basics/KernelBasis.i @@ -55,6 +55,8 @@ using namespace SALOME; %rename (SetBigObjOnDiskThreshold) SetBigObjOnDiskThresholdSwig; %rename (GetBigObjOnDiskDirectory) GetBigObjOnDiskDirectorySwig; %rename (GetBigObjOnDiskProtocolAndDirectory) GetBigObjOnDiskProtocolAndDirectorySwig; +%rename (BigObjOnDiskProtocolFromStr) BigObjOnDiskProtocolFromStrSwig; +%rename (BigObjOnDiskProtocolToStr) BigObjOnDiskProtocolToStrSwig; %rename (SetBigObjOnDiskDirectory) SetBigObjOnDiskDirectorySwig; %rename (BigObjOnDiskDirectoryDefined) BigObjOnDiskDirectoryDefinedSwig; %rename (SetNumberOfRetry) SetNumberOfRetrySwig; @@ -155,12 +157,22 @@ int GetNumberOfRetrySwig() return SALOME::GetNumberOfRetry( ); } +std::string BigObjOnDiskProtocolToStrSwig( int protocol ) +{ + return SALOME::BigObjOnDiskProtocolToStr( SALOME::FromIntToBigObjOnDiskProtocol( protocol ) ); +} + +int BigObjOnDiskProtocolFromStrSwig(const std::string& protocol) +{ + return static_cast( SALOME::BigObjOnDiskProtocolFromStr( protocol ) ); +} + PyObject *GetBigObjOnDiskProtocolAndDirectorySwig() { std::string directory; - int ret0 = SALOME::GetBigObjOnDiskProtocolAndDirectory(directory); + SALOME::BigObjTransferProtocol ret0 = SALOME::GetBigObjOnDiskProtocolAndDirectory(directory); PyObject *ret(PyTuple_New(2)); - PyTuple_SetItem(ret,0,PyInt_FromLong(ret0)); + PyTuple_SetItem(ret,0,PyInt_FromLong(static_cast( ret0 ) )); PyTuple_SetItem(ret,1,PyUnicode_FromString(directory.c_str())); return ret; } -- 2.39.2