Moved common functionality (independent on CORBA) from Utils package (dependent on CORBA) to Basics package and introduced Kernel_Utils namespace for use it
void HouseKeeping();
std::list<PROTECTED_DELETE*> PROTECTED_DELETE::_objList;
-#ifndef WNT
+#ifndef WIN32
pthread_mutex_t PROTECTED_DELETE::_listMutex;
#else
pthread_mutex_t PROTECTED_DELETE::_listMutex =
#ifndef _BASICGENERICDESTRUCTOR_HXX_
#define _BASICGENERICDESTRUCTOR_HXX_
-#ifdef WNT
- #if defined BASICS_EXPORTS
- #if defined WIN32
- #define BASICS_EXPORT __declspec( dllexport )
- #else
- #define BASICS_EXPORT
- #endif
- #else
- #if defined WIN32
- #define BASICS_EXPORT __declspec( dllimport )
- #else
- #define BASICS_EXPORT
- #endif
- #endif
-#else
- #define BASICS_EXPORT
-#endif
+#include "SALOME_Basics.hxx"
#include <list>
#include <algorithm>
--- /dev/null
+// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+//
+//
+// File : Basics_DirUtils.cxx
+// Autor : Alexander A. BORODIN
+// Module : SALOME
+
+#include "Basics_DirUtils.hxx"
+
+#include <errno.h>
+
+#ifndef WIN32
+# include <sys/stat.h>
+#endif
+
+using namespace std;
+
+#ifdef WIN32
+# define _separator_ '\\'
+#else
+# define _separator_ '/'
+#endif
+
+namespace Kernel_Utils
+{
+ string GetTmpDirByEnv( const std::string& tmp_path_env )
+ {
+ string dir;
+ char* val = getenv( tmp_path_env.c_str() );
+ val ? dir = string( val ) : "";
+ return GetTmpDirByPath( dir );
+ }
+
+ string GetTmpDirByPath( const std::string& tmp_path )
+ {
+ string aTmpDir = tmp_path;
+ if ( aTmpDir == "" )
+ {
+#ifdef WIN32
+ 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] != _separator_)
+ aTmpDir+=_separator_;
+
+ 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] != _separator_) aDir += _separator_;
+
+#ifdef WIN32
+ 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/"
+ //============================================================================
+ string GetTmpDir()
+ {
+ return GetTmpDirByPath( "" );
+ }
+
+ string GetTmpFileName()
+ {
+ string tmpDir = GetTmpDir();
+ string aFilePath = "";
+ if(IsExists(tmpDir)) {
+ 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");
+
+ string aFilePath = tmpDir;
+ for(aRND = 0; IsExists(aFilePath); aRND++) {
+ sprintf(buffer, "%d", aRND);
+ aFilePath = tmpDir+buffer; //Build a unique file name
+ }
+ }
+ return aFilePath;
+ }
+
+
+ bool IsExists(const string& thePath)
+ {
+#ifdef WIN32
+ 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;
+ }
+
+}
--- /dev/null
+// SALOME Utils : general SALOME's definitions and tools
+//
+// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+//
+//
+// File : Basics_DirUtils.hxx
+// Autor : Alexander A. BORODIN
+// Module : SALOME
+
+#ifndef _Basics_DIRUTILS_HXX_
+#define _Basics_DIRUTILS_HXX_
+
+#include "SALOME_Basics.hxx"
+
+#include <string>
+
+namespace Kernel_Utils
+{
+ // 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 WIN32
+ BASICS_EXPORT 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 WIN32
+ BASICS_EXPORT std::string GetTmpDirByPath( const std::string& tmp_path );
+
+ // Returns the unique temporary directory in
+ // /tmp/something/ for Unix or c:\something\ for WIN32
+ BASICS_EXPORT std::string GetTmpDir();
+
+ // Returns the unique temporary file name without any extension
+ // /tmp/something/file for Unix or c:\something\file for WIN32
+ BASICS_EXPORT std::string GetTmpFileName();
+
+ // Returns True(False) if the path (not)exists
+ BASICS_EXPORT bool IsExists( const std::string& path );
+}
+
+#endif
--- /dev/null
+// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+//
+//
+// File : Basics_Utils.cxx
+// Autor : Alexander A. BORODIN
+// Module : SALOME
+
+#include "Basics_Utils.hxx"
+
+#ifndef WIN32
+#include <unistd.h>
+#include <sys/stat.h>
+#else
+#include <winsock2.h>
+#endif
+
+using namespace std;
+
+namespace Kernel_Utils
+{
+ string GetHostname()
+ {
+ int ls = 100, r = 1;
+ char *s;
+
+ while (ls < 10000 && r)
+ {
+ ls *= 2;
+ s = new char[ls];
+ r = gethostname(s, ls-1);
+ switch (r)
+ {
+ case 0:
+ break;
+ default:
+#ifdef EINVAL
+ case EINVAL:
+#endif
+#ifdef ENAMETOOLONG
+ case ENAMETOOLONG:
+#endif
+#ifdef WIN32
+ case WSAEFAULT:
+#endif
+ delete [] s;
+ continue;
+ }
+
+ }
+
+ if (r != 0)
+ {
+ s = new char[50];
+ strcpy(s, "localhost");
+ }
+
+ // remove all after '.'
+ char *aDot = (strchr(s,'.'));
+ if (aDot) aDot[0] = '\0';
+
+ string p = s;
+ delete [] s;
+ return p;
+ }
+
+}
--- /dev/null
+// SALOME Utils : general SALOME's definitions and tools
+//
+// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+//
+//
+// File : Basics_DirUtils.hxx
+// Autor : Alexander A. BORODIN
+// Module : SALOME
+
+#ifndef _Basics_UTILS_HXX_
+#define _Basics_UTILS_HXX_
+
+#include "SALOME_Basics.hxx"
+
+#include <string>
+
+namespace Kernel_Utils
+{
+ BASICS_EXPORT std::string GetHostname();
+}
+
+#endif //_Basics_UTILS_HXX_
include $(top_srcdir)/salome_adm/unix/make_common_starter.am
-salomeinclude_HEADERS = BasicsGenericDestructor.hxx
+salomeinclude_HEADERS = \
+ SALOME_Basics.hxx \
+ BasicsGenericDestructor.hxx \
+ Basics_Utils.hxx \
+ Basics_DirUtils.hxx
lib_LTLIBRARIES = libSALOMEBasics.la
libSALOMEBasics_la_SOURCES = \
BasicsGenericDestructor.cxx \
- BasicsGenericDestructor.hxx
+ Basics_Utils.cxx \
+ Basics_DirUtils.cxx \
+ SALOME_Basics.hxx \
+ BasicsGenericDestructor.hxx \
+ Basics_Utils.hxx \
+ Basics_DirUtils.hxx
libSALOMEBasics_la_LDFLAGS = -no-undefined -version-info=0:0:0
libSALOMEBasics_la_CPPFLAGS = @CPPFLAGS@
--- /dev/null
+// SALOME Basics : general SALOME definitions and tools (C++ part - no CORBA)
+//
+// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+//
+//
+// File : SALOME_Basics.hxx
+// Author : Alexander A. BORODIN
+// Module : SALOME
+// $Header$
+
+#ifndef _SALOME_BASICS_HXX_
+#define _SALOME_BASICS_HXX_
+
+
+#ifdef WIN32
+# ifdef BASICS_EXPORTS
+# define BASICS_EXPORT __declspec( dllexport )
+# else
+# define BASICS_EXPORT __declspec( dllimport )
+# endif
+#else
+# define BASICS_EXPORT
+#endif
+
+#endif //_SALOME_BASICS_HXX_