From: abd Date: Thu, 8 May 2008 08:42:15 +0000 (+0000) Subject: Correct compilation under Win32 platform X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2FBR_WPdev_For_4_0;p=modules%2Fkernel.git Correct compilation under Win32 platform --- diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index 41e2b5b61..e7f75cf58 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -37,17 +37,14 @@ #else #include #include +#include int SIGUSR1 = 1000; #endif #include "utilities.h" #include -//#ifndef WNT #include CORBA_SERVER_HEADER(SALOME_Component) #include CORBA_SERVER_HEADER(SALOME_Exception) -//#else -//#include -//#endif #include // must be before Python.h ! #include "SALOME_Container_i.hxx" #include "SALOME_Component_i.hxx" diff --git a/src/Launcher/BatchLight_Job.cxx b/src/Launcher/BatchLight_Job.cxx index 1980054a9..bb9cfb3cf 100644 --- a/src/Launcher/BatchLight_Job.cxx +++ b/src/Launcher/BatchLight_Job.cxx @@ -132,7 +132,7 @@ Job::check() { rtn = false; } std::string end_mem_value = mem_value.substr(mem_value.length()-2); - if (end_mem_value != "gb" and end_mem_value != "mb") { + if (end_mem_value != "gb" && end_mem_value != "mb") { mem_info = "Error on definition, type is bad ! " + mem_value; rtn = false; } diff --git a/src/Launcher/SALOME_Launcher.cxx b/src/Launcher/SALOME_Launcher.cxx index 48facc1af..6d13865ea 100644 --- a/src/Launcher/SALOME_Launcher.cxx +++ b/src/Launcher/SALOME_Launcher.cxx @@ -206,7 +206,7 @@ char* SALOME_Launcher::querySalomeJob( /*const */CORBA::Long jobId, * \param params : Constraints for the choice of the batch cluster */ //============================================================================= -void SALOME_Launcher::deleteSalomeJob( const CORBA::Long jobId, +void SALOME_Launcher::deleteSalomeJob( CORBA::Long jobId, const Engines::MachineParameters& params) { try{ @@ -237,7 +237,7 @@ void SALOME_Launcher::deleteSalomeJob( const CORBA::Long jobId, */ //============================================================================= void SALOME_Launcher::getResultSalomeJob( const char *directory, - const CORBA::Long jobId, + CORBA::Long jobId, const Engines::MachineParameters& params) { try{ diff --git a/src/Launcher/SALOME_Launcher.hxx b/src/Launcher/SALOME_Launcher.hxx index fa1228697..8627fae23 100644 --- a/src/Launcher/SALOME_Launcher.hxx +++ b/src/Launcher/SALOME_Launcher.hxx @@ -54,9 +54,9 @@ public: const Engines::BatchParameters& batch_params, const Engines::MachineParameters& params); - char* querySalomeJob( const CORBA::Long jobId, const Engines::MachineParameters& params); - void deleteSalomeJob( const CORBA::Long jobId, const Engines::MachineParameters& params); - void getResultSalomeJob( const char * directory, const CORBA::Long jobId, const Engines::MachineParameters& params ); + char* querySalomeJob( CORBA::Long jobId, const Engines::MachineParameters& params); + void deleteSalomeJob( CORBA::Long jobId, const Engines::MachineParameters& params); + void getResultSalomeJob( const char * directory, CORBA::Long jobId, const Engines::MachineParameters& params ); void Shutdown(); diff --git a/src/ResourcesManager/SALOME_ResourcesManager.cxx b/src/ResourcesManager/SALOME_ResourcesManager.cxx index ea88da8f8..5c7ca50e5 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.cxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.cxx @@ -639,12 +639,22 @@ SALOME_ResourcesManager::BuildCommandToLaunchLocalContainer if(wdir == "$TEMPDIR") { // a new temporary directory is requested - char dir[]="/tmp/salomeXXXXXX"; + /*char dir[]="/tmp/salomeXXXXXX"; char* mdir=mkdtemp(dir); if(mdir==NULL) std::cerr << "Problem in mkdtemp " << dir << " " << mdir << std::endl; else command="cd "+std::string(dir)+";"; + */ + string dir = OpUtil_Dir::GetTmpDir(); +#ifdef WNT + if ( dir.length() > 1 && dir[1] == ':') + command = dir.substr( 0, 2 ) + ";"; + command += "cd "+ dir +";"; +#else + command = "cd "+ dir +";"; +#endif + } else { diff --git a/src/TOOLSDS/SALOMEDS_Tool.cxx b/src/TOOLSDS/SALOMEDS_Tool.cxx index 444f54558..7a18c0923 100644 --- a/src/TOOLSDS/SALOMEDS_Tool.cxx +++ b/src/TOOLSDS/SALOMEDS_Tool.cxx @@ -27,6 +27,7 @@ #include "SALOMEDS_Tool.hxx" #include "utilities.h" +#include "OpUtil.hxx" #ifndef WNT #include @@ -70,9 +71,10 @@ bool Exists(const string thePath) //============================================================================ std::string SALOMEDS_Tool::GetTmpDir() { + return OpUtil_Dir::GetTmpDirByEnv("SALOME_TMP_DIR"); //Find a temporary directory to store a file - string aTmpDir = ""; + /*string aTmpDir = ""; char *Tmp_dir = getenv("SALOME_TMP_DIR"); if(Tmp_dir != NULL) { @@ -122,7 +124,7 @@ std::string SALOMEDS_Tool::GetTmpDir() mkdir(aDir.c_str(), 0x1ff); #endif - return aDir; + return aDir;*/ } //============================================================================ diff --git a/src/TOOLSDS/SALOMEDS_Tool.hxx b/src/TOOLSDS/SALOMEDS_Tool.hxx index 0c57ace2e..5829f3fd4 100644 --- a/src/TOOLSDS/SALOMEDS_Tool.hxx +++ b/src/TOOLSDS/SALOMEDS_Tool.hxx @@ -36,21 +36,13 @@ #include CORBA_SERVER_HEADER(SALOMEDS) #ifdef WNT - #if defined TOOLSDS_EXPORTS - #if defined WIN32 - #define TOOLSDS_EXPORT __declspec( dllexport ) - #else - #define TOOLSDS_EXPORT - #endif - #else - #if defined WIN32 - #define TOOLSDS_EXPORT __declspec( dllimport ) - #else - #define TOOLSDS_EXPORT - #endif - #endif +# if defined TOOLSDS_EXPORTS +# define TOOLSDS_EXPORT __declspec( dllexport ) +# else +# define TOOLSDS_EXPORT __declspec( dllimport ) +# endif #else - #define TOOLSDS_EXPORT +# define TOOLSDS_EXPORT #endif class TOOLSDS_EXPORT SALOMEDS_Tool diff --git a/src/Utils/OpUtil.cxx b/src/Utils/OpUtil.cxx index 43052f731..4ce44c479 100644 --- a/src/Utils/OpUtil.cxx +++ b/src/Utils/OpUtil.cxx @@ -35,6 +35,7 @@ #include #endif using namespace std; + //int gethostname(char *name, size_t len); std::string GetHostname() @@ -76,3 +77,170 @@ std::string GetHostname() return p; } + +std::string OpUtil_Dir::GetTmpDirByEnv( const std::string& tmp_path_env ) +{ + string dir; + char* val = getenv( tmp_path_env.c_str() ); + val ? dir = string( val ) : ""; + return GetTmpDirByPath( dir ); +} + +std::string OpUtil_Dir::GetTmpDirByPath( const std::string& tmp_path ) +{ + string aTmpDir = tmp_path; + char sep = +#ifdef WNT + '\\'; +#else + '/'; +#endif + /*if ( tmp_path.length() > 0 ) + { + char *Tmp_dir = getenv(tmp_path_env.c_str()); + if( Tmp_dir != NULL ) + { + aTmpDir = string(Tmp_dir); + if(aTmpDir[aTmpDir.size()-1] != sep) + aTmpDir+=sep; + } + }*/ + if ( aTmpDir == "" ) + { +#ifdef WNT + char *Tmp_dir = getenv("TEMP"); + if( Tmp_dir == NULL ) + { + Tmp_dir = getenv("TMP"); + if (Tmp_dir == NULL) + aTmpDir = string("C:\\"); + else + aTmpDir = string(Tmp_dir); + } + else + aTmpDir = string(Tmp_dir); +#else + aTmpDir = string("/tmp/"); +#endif + } + + if(aTmpDir[aTmpDir.size()-1] != sep) + aTmpDir+=sep; + + srand((unsigned int)time(NULL)); + int aRND = 999 + (int)(100000.0*rand()/(RAND_MAX+1.0)); //Get a random number to present a name of a sub directory + char buffer[127]; + sprintf(buffer, "%d", aRND); + string aSubDir(buffer); + if(aSubDir.size() <= 1) aSubDir = string("123409876"); + + aTmpDir += aSubDir; //Get RND sub directory + + string aDir = aTmpDir; + + if(IsExists(aDir)) { + for(aRND = 0; IsExists(aDir); aRND++) { + sprintf(buffer, "%d", aRND); + aDir = aTmpDir+buffer; //Build a unique directory name + } + } + + if(aDir[aDir.size()-1] != sep) aDir+=sep; + +#ifdef WNT + CreateDirectory(aDir.c_str(), NULL); +#else + mkdir(aDir.c_str(), 0x1ff); +#endif + + return aDir; +} + +//============================================================================ +// function : GetTempDir +// purpose : Return a temp directory to store created files like "/tmp/sub_dir/" +//============================================================================ +std::string OpUtil_Dir::GetTmpDir() +{ + return GetTmpDirByPath( "" ); + //Find a temporary directory to store a file +/* + string aTmpDir = ""; + char sep = +#ifdef WNT + '\\'; +#else + '/'; +#endif + if ( tmp_path_env.length() > 0 ) + { + char *Tmp_dir = getenv(tmp_path_env.c_str()); + if( Tmp_dir != NULL ) + { + aTmpDir = string(Tmp_dir); + if(aTmpDir[aTmpDir.size()-1] != sep) + aTmpDir+=sep; + } + } + if ( aTmpDir == "" ) + { +#ifdef WNT + char *Tmp_dir = getenv("TEMP"); + if( Tmp_dir == NULL ) + { + Tmp_dir = getenv("TMP"); + if (Tmp_dir == NULL) + aTmpDir = string("C:\\"); + else + aTmpDir = string(Tmp_dir); + } + else + aTmpDir = string(Tmp_dir); +#else + aTmpDir = string("/tmp/"); +#endif + } + + srand((unsigned int)time(NULL)); + int aRND = 999 + (int)(100000.0*rand()/(RAND_MAX+1.0)); //Get a random number to present a name of a sub directory + char buffer[127]; + sprintf(buffer, "%d", aRND); + string aSubDir(buffer); + if(aSubDir.size() <= 1) aSubDir = string("123409876"); + + aTmpDir += aSubDir; //Get RND sub directory + + string aDir = aTmpDir; + + if(Exists(aDir)) { + for(aRND = 0; Exists(aDir); aRND++) { + sprintf(buffer, "%d", aRND); + aDir = aTmpDir+buffer; //Build a unique directory name + } + } + + if(aDir[aDir.size()-1] != sep) aDir+=sep; + +#ifdef WNT + CreateDirectory(aDir.c_str(), NULL); +#else + mkdir(aDir.c_str(), 0x1ff); +#endif + + return aDir;*/ +} + +bool OpUtil_Dir::IsExists(const string& thePath) +{ +#ifdef WNT + if ( GetFileAttributes ( thePath.c_str() ) == 0xFFFFFFFF ) { + if ( GetLastError () == ERROR_FILE_NOT_FOUND ) { + return false; + } + } +#else + int status = access ( thePath.c_str() , F_OK ); + if (status != 0) return false; +#endif + return true; +} \ No newline at end of file diff --git a/src/Utils/OpUtil.hxx b/src/Utils/OpUtil.hxx index ba5d5eb42..f462726a4 100644 --- a/src/Utils/OpUtil.hxx +++ b/src/Utils/OpUtil.hxx @@ -34,4 +34,24 @@ UTILS_EXPORT std::string GetHostname(); UTILS_EXPORT const char *duplicate(const char * const); +class UTILS_EXPORT OpUtil_Dir +{ +public: + // Returns the unique temporary directory, that is defined in tmp_path_env if this variable is set + // otherwise return /tmp/something/ for Unix or c:\something\ for WNT + static std::string GetTmpDirByEnv( const std::string& tmp_path_env ); + + // Returns the unique temporary directory, that is defined in tmp_path if this variable is set + // otherwise return /tmp/something/ for Unix or c:\something\ for WNT + static std::string GetTmpDirByPath( const std::string& tmp_path ); + + // Returns the unique temporary directory in + // /tmp/something/ for Unix or c:\something\ for WNT + static std::string GetTmpDir(); + + // Returns True(False) if the path (not)exists + static bool IsExists( const std::string& path ); + +}; + #endif