From 5a958d30546864ed92e45ac49176b9e875eb416d Mon Sep 17 00:00:00 2001 From: abd Date: Fri, 3 Oct 2008 09:14:37 +0000 Subject: [PATCH] Win32 Porting. Correction of Export/Import defines for Win32 platform. Using WIN32 standard define instead WNT define of OpenCascade library. Using Basics instead Utils library. --- src/Container/Component_i.cxx | 54 +- src/Container/Container_i.cxx | 1306 +++++++++++---------- src/Container/Container_init_python.cxx | 2 +- src/Container/Container_init_python.hxx | 2 +- src/Container/Makefile.am | 4 +- src/Container/SALOME_Component_i.hxx | 4 +- src/Container/SALOME_Container.cxx | 16 +- src/Container/SALOME_Container.hxx | 22 +- src/Container/SALOME_ContainerManager.cxx | 132 ++- src/Container/SALOME_Container_i.hxx | 2 +- src/Container/SALOME_FileRef_i.cxx | 4 +- src/Container/Salome_file_i.cxx | 35 +- src/DF/DF_definitions.hxx | 12 +- src/DF/testDF.cxx | 10 +- src/DSC/DSC_Basic/ConnectionManager_i.cxx | 11 +- src/DSC/DSC_Basic/DSC_Basic.hxx | 22 +- 16 files changed, 863 insertions(+), 775 deletions(-) diff --git a/src/Container/Component_i.cxx b/src/Container/Component_i.cxx index b92cf0708..4ee68ae66 100644 --- a/src/Container/Component_i.cxx +++ b/src/Container/Component_i.cxx @@ -32,13 +32,13 @@ #include "RegistryConnexion.hxx" #include "OpUtil.hxx" #include -#ifndef WNT +#ifndef WIN32 #include #endif #include #include "utilities.h" -#ifndef WNT +#ifndef WIN32 #include #include #include @@ -268,7 +268,7 @@ CORBA::Long Engines_Component_i::getStudyId() void Engines_Component_i::ping() { -#ifndef WNT +#ifndef WIN32 MESSAGE("Engines_Component_i::ping() pid "<< getpid() << " threadid " << pthread_self()); #else @@ -387,12 +387,12 @@ bool Engines_Component_i::Kill_impl() // MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self() // << " pid " << getpid() << " instanceName " // << _instanceName.c_str() << " interface " << _interfaceName.c_str() -// << " machineName " << GetHostname().c_str()<< " _id " << hex << _id +// << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id // << dec << " _ThreadId " << _ThreadId << " this " << hex << this // << dec ) ; bool RetVal = false ; -#ifndef WNT +#ifndef WIN32 if ( _ThreadId > 0 && pthread_self() != _ThreadId ) { RetVal = Killer( _ThreadId , SIGUSR2 ) ; @@ -418,23 +418,23 @@ bool Engines_Component_i::Kill_impl() bool Engines_Component_i::Stop_impl() { -#ifndef WNT +#ifndef WIN32 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self() << " pid " << getpid() << " instanceName " << _instanceName.c_str() << " interface " << _interfaceName.c_str() - << " machineName " << GetHostname().c_str()<< " _id " << hex << _id + << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id << dec << " _ThreadId " << _ThreadId ); #else MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self().p << " pid " << _getpid() << " instanceName " << _instanceName.c_str() << " interface " << _interfaceName.c_str() - << " machineName " << GetHostname().c_str()<< " _id " << hex << _id + << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id << dec << " _ThreadId " << _ThreadId ); #endif bool RetVal = false ; -#ifndef WNT +#ifndef WIN32 if ( _ThreadId > 0 && pthread_self() != _ThreadId ) { RetVal = Killer( _ThreadId , 0 ) ; @@ -458,22 +458,22 @@ bool Engines_Component_i::Stop_impl() bool Engines_Component_i::Suspend_impl() { -#ifndef WNT +#ifndef WIN32 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self() << " pid " << getpid() << " instanceName " << _instanceName.c_str() << " interface " << _interfaceName.c_str() - << " machineName " << GetHostname().c_str()<< " _id " << hex << _id + << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id << dec << " _ThreadId " << _ThreadId ); #else MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self().p << " pid " << _getpid() << " instanceName " << _instanceName.c_str() << " interface " << _interfaceName.c_str() - << " machineName " << GetHostname().c_str()<< " _id " << hex << _id + << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id << dec << " _ThreadId " << _ThreadId ); #endif bool RetVal = false ; -#ifndef WNT +#ifndef WIN32 if ( _ThreadId > 0 && pthread_self() != _ThreadId ) #else if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p ) @@ -485,7 +485,7 @@ bool Engines_Component_i::Suspend_impl() } else { -#ifndef WNT +#ifndef WIN32 RetVal = Killer( _ThreadId ,SIGINT ) ; #else RetVal = Killer( *_ThreadId ,SIGINT ) ; @@ -505,21 +505,21 @@ bool Engines_Component_i::Suspend_impl() bool Engines_Component_i::Resume_impl() { -#ifndef WNT +#ifndef WIN32 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self() << " pid " << getpid() << " instanceName " << _instanceName.c_str() << " interface " << _interfaceName.c_str() - << " machineName " << GetHostname().c_str()<< " _id " << hex << _id + << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id << dec << " _ThreadId " << _ThreadId ); #else MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self().p << " pid " << _getpid() << " instanceName " << _instanceName.c_str() << " interface " << _interfaceName.c_str() - << " machineName " << GetHostname().c_str()<< " _id " << hex << _id + << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id << dec << " _ThreadId " << _ThreadId ); #endif bool RetVal = false ; -#ifndef WNT +#ifndef WIN32 if ( _ThreadId > 0 && pthread_self() != _ThreadId ) #else if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p ) @@ -551,7 +551,7 @@ CORBA::Long Engines_Component_i::CpuUsed_impl() { if ( _ThreadId > 0 ) { -#ifndef WNT +#ifndef WIN32 if ( pthread_self() != _ThreadId ) #else if ( pthread_self().p != _ThreadId->p ) @@ -564,7 +564,7 @@ CORBA::Long Engines_Component_i::CpuUsed_impl() { // Get Cpu in the appropriate thread with that object !... theEngines_Component = this ; -#ifndef WNT +#ifndef WIN32 Killer( _ThreadId ,SIGUSR1 ) ; #else Killer( *_ThreadId ,SIGUSR11 ) ; @@ -653,14 +653,14 @@ PortableServer::ObjectId * Engines_Component_i::getId() void Engines_Component_i::beginService(const char *serviceName) { -#ifndef WNT +#ifndef WIN32 MESSAGE(pthread_self() << "Send BeginService notification for " < #include #include -#ifndef WNT +#ifndef WIN32 #include #include #include #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" @@ -55,7 +52,7 @@ int SIGUSR1 = 1000; #include "SALOME_FileTransfer_i.hxx" #include "Salome_file_i.hxx" #include "SALOME_NamingService.hxx" -#include "OpUtil.hxx" +#include "Basics_Utils.hxx" #include #include "Container_init_python.hxx" @@ -73,10 +70,16 @@ char ** _ArgV ; // Other Containers are started via start_impl of FactoryServer extern "C" {void ActSigIntHandler() ; } -#ifndef WNT - extern "C" {void SigIntHandler(int, siginfo_t *, void *) ; } +#ifndef WIN32 +extern "C" {void SigIntHandler(int, siginfo_t *, void *) ; } #else - extern "C" {void SigIntHandler( int ) ; } +extern "C" {void SigIntHandler( int ) ; } +#endif + +#ifdef WIN32 +# define separator '\\' +#else +# define separator '/' #endif @@ -87,19 +90,19 @@ omni_mutex Engines_Container_i::_numInstanceMutex ; //============================================================================= /*! - * Default constructor, not for use - */ +* Default constructor, not for use +*/ //============================================================================= Engines_Container_i::Engines_Container_i () : - _numInstance(0) +_numInstance(0) { } //============================================================================= /*! - * Construtor to use - */ +* Construtor to use +*/ //============================================================================= Engines_Container_i::Engines_Container_i (CORBA::ORB_ptr orb, @@ -109,7 +112,7 @@ Engines_Container_i::Engines_Container_i (CORBA::ORB_ptr orb, bool activAndRegist, bool isServantAloneInProcess ) : - _numInstance(0),_isServantAloneInProcess(isServantAloneInProcess) +_numInstance(0),_isServantAloneInProcess(isServantAloneInProcess) { _pid = (long)getpid(); @@ -119,107 +122,107 @@ Engines_Container_i::Engines_Container_i (CORBA::ORB_ptr orb, _argc = argc ; _argv = argv ; - string hostname = GetHostname(); -#ifndef WNT + string hostname = Kernel_Utils::GetHostname(); +#ifndef WIN32 MESSAGE(hostname << " " << getpid() << - " Engines_Container_i starting argc " << - _argc << " Thread " << pthread_self() ) ; + " Engines_Container_i starting argc " << + _argc << " Thread " << pthread_self() ) ; #else MESSAGE(hostname << " " << _getpid() << - " Engines_Container_i starting argc " << _argc<< " Thread " << pthread_self().p ) ; + " Engines_Container_i starting argc " << _argc<< " Thread " << pthread_self().p ) ; #endif int i = 0 ; while ( _argv[ i ] ) - { - MESSAGE(" argv" << i << " " << _argv[ i ]) ; - i++ ; - } + { + MESSAGE(" argv" << i << " " << _argv[ i ]) ; + i++ ; + } if ( argc < 2 ) - { - INFOS("SALOME_Container usage : SALOME_Container ServerName"); - ASSERT(0) ; - } + { + INFOS("SALOME_Container usage : SALOME_Container ServerName"); + ASSERT(0) ; + } SCRUTE(argv[1]); _isSupervContainer = false; if (strcmp(argv[1],"SuperVisionContainer") == 0) _isSupervContainer = true; if (_isSupervContainer) - { - _ArgC = argc ; - _ArgV = argv ; - } + { + _ArgC = argc ; + _ArgV = argv ; + } _orb = CORBA::ORB::_duplicate(orb) ; _poa = PortableServer::POA::_duplicate(poa) ; - + // Pour les containers paralleles: il ne faut pas enregistrer et activer // le container generique, mais le container specialise if(activAndRegist) + { + _id = _poa->activate_object(this); + _NS = new SALOME_NamingService(); + _NS->init_orb( _orb ) ; + CORBA::Object_var obj=_poa->id_to_reference(*_id); + Engines::Container_var pCont + = Engines::Container::_narrow(obj); + _remove_ref(); + + _containerName = _NS->BuildContainerNameForNS(containerName, + hostname.c_str()); + SCRUTE(_containerName); + _NS->Register(pCont, _containerName.c_str()); + MESSAGE("Engines_Container_i::Engines_Container_i : Container name " + << _containerName); + + // Python: + // import SALOME_Container + // pycont = SALOME_Container.SALOME_Container_i(containerIORStr) + + CORBA::String_var sior = _orb->object_to_string(pCont); + string myCommand="pyCont = SALOME_Container.SALOME_Container_i('"; + myCommand += _containerName + "','"; + myCommand += sior; + myCommand += "')\n"; + SCRUTE(myCommand); + + if (!_isSupervContainer) { - _id = _poa->activate_object(this); - _NS = new SALOME_NamingService(); - _NS->init_orb( _orb ) ; - CORBA::Object_var obj=_poa->id_to_reference(*_id); - Engines::Container_var pCont - = Engines::Container::_narrow(obj); - _remove_ref(); - - _containerName = _NS->BuildContainerNameForNS(containerName, - hostname.c_str()); - SCRUTE(_containerName); - _NS->Register(pCont, _containerName.c_str()); - MESSAGE("Engines_Container_i::Engines_Container_i : Container name " - << _containerName); - - // Python: - // import SALOME_Container - // pycont = SALOME_Container.SALOME_Container_i(containerIORStr) - - CORBA::String_var sior = _orb->object_to_string(pCont); - string myCommand="pyCont = SALOME_Container.SALOME_Container_i('"; - myCommand += _containerName + "','"; - myCommand += sior; - myCommand += "')\n"; - SCRUTE(myCommand); - - if (!_isSupervContainer) - { -#ifdef WNT +#ifdef WIN32 - PyEval_AcquireLock(); - PyThreadState *myTstate = PyThreadState_New(KERNEL_PYTHON::_interp); - PyThreadState *myoldTstate = PyThreadState_Swap(myTstate); + PyEval_AcquireLock(); + PyThreadState *myTstate = PyThreadState_New(KERNEL_PYTHON::_interp); + PyThreadState *myoldTstate = PyThreadState_Swap(myTstate); #else - Py_ACQUIRE_NEW_THREAD; + Py_ACQUIRE_NEW_THREAD; #endif -#ifdef WNT - // mpv: this is temporary solution: there is a unregular crash if not - //Sleep(2000); - // - // first element is the path to Registry.dll, but it's wrong - PyRun_SimpleString("import sys\n"); - PyRun_SimpleString("sys.path = sys.path[1:]\n"); +#ifdef WIN32 + // mpv: this is temporary solution: there is a unregular crash if not + //Sleep(2000); + // + // first element is the path to Registry.dll, but it's wrong + PyRun_SimpleString("import sys\n"); + PyRun_SimpleString("sys.path = sys.path[1:]\n"); #endif - PyRun_SimpleString("import SALOME_Container\n"); - PyRun_SimpleString((char*)myCommand.c_str()); - Py_RELEASE_NEW_THREAD; - } - - fileTransfer_i* aFileTransfer = new fileTransfer_i(); - CORBA::Object_var obref=aFileTransfer->_this(); - _fileTransfer = Engines::fileTransfer::_narrow(obref); - aFileTransfer->_remove_ref(); + PyRun_SimpleString("import SALOME_Container\n"); + PyRun_SimpleString((char*)myCommand.c_str()); + Py_RELEASE_NEW_THREAD; } + + fileTransfer_i* aFileTransfer = new fileTransfer_i(); + CORBA::Object_var obref=aFileTransfer->_this(); + _fileTransfer = Engines::fileTransfer::_narrow(obref); + aFileTransfer->_remove_ref(); + } } //============================================================================= /*! - * Destructor - */ +* Destructor +*/ //============================================================================= Engines_Container_i::~Engines_Container_i() @@ -232,19 +235,19 @@ Engines_Container_i::~Engines_Container_i() //============================================================================= /*! - * CORBA attribute: Container name (see constructor) - */ +* CORBA attribute: Container name (see constructor) +*/ //============================================================================= char* Engines_Container_i::name() { - return CORBA::string_dup(_containerName.c_str()) ; + return CORBA::string_dup(_containerName.c_str()) ; } //============================================================================= /*! - * CORBA attribute: Container working directory - */ +* CORBA attribute: Container working directory +*/ //============================================================================= char* Engines_Container_i::workingdir() @@ -256,8 +259,8 @@ char* Engines_Container_i::workingdir() //============================================================================= /*! - * CORBA attribute: Container log file name - */ +* CORBA attribute: Container log file name +*/ //============================================================================= char* Engines_Container_i::logfilename() @@ -272,21 +275,21 @@ void Engines_Container_i::logfilename(const char* name) //============================================================================= /*! - * CORBA method: Get the hostName of the Container (without domain extensions) - */ +* CORBA method: Get the hostName of the Container (without domain extensions) +*/ //============================================================================= char* Engines_Container_i::getHostName() { - string s = GetHostname(); + string s = Kernel_Utils::GetHostname(); // MESSAGE("Engines_Container_i::getHostName " << s); return CORBA::string_dup(s.c_str()) ; } //============================================================================= /*! - * CORBA method: Get the PID (process identification) of the Container - */ +* CORBA method: Get the PID (process identification) of the Container +*/ //============================================================================= CORBA::Long Engines_Container_i::getPID() @@ -296,8 +299,8 @@ CORBA::Long Engines_Container_i::getPID() //============================================================================= /*! - * CORBA method: check if servant is still alive - */ +* CORBA method: check if servant is still alive +*/ //============================================================================= void Engines_Container_i::ping() @@ -307,11 +310,11 @@ void Engines_Container_i::ping() //============================================================================= /*! - * CORBA method, oneway: Server shutdown. - * - Container name removed from naming service, - * - servant deactivation, - * - orb shutdown if no other servants in the process - */ +* CORBA method, oneway: Server shutdown. +* - Container name removed from naming service, +* - servant deactivation, +* - orb shutdown if no other servants in the process +*/ //============================================================================= void Engines_Container_i::Shutdown() @@ -319,8 +322,8 @@ void Engines_Container_i::Shutdown() MESSAGE("Engines_Container_i::Shutdown()"); /* For each component contained in this container - * tell it to self-destroy - */ + * tell it to self-destroy + */ std::map::iterator itm; for (itm = _listInstances_map.begin(); itm != _listInstances_map.end(); itm++) itm->second->destroy(); @@ -330,94 +333,141 @@ void Engines_Container_i::Shutdown() //_remove_ref(); //_poa->deactivate_object(*_id); if(_isServantAloneInProcess) - { - MESSAGE("Effective Shutdown of container Begins..."); - if(!CORBA::is_nil(_orb)) - _orb->shutdown(0); - } + { + MESSAGE("Effective Shutdown of container Begins..."); + if(!CORBA::is_nil(_orb)) + _orb->shutdown(0); + } } /* int checkifexecutable(const char *filename) - * - * Return non-zero if the name is an executable file, and - * zero if it is not executable, or if it does not exist. - */ +* +* Return non-zero if the name is an executable file, and +* zero if it is not executable, or if it does not exist. +*/ -int checkifexecutable(const char *filename) +int checkifexecutable(const string& filename) { - int result; - struct stat statinfo; - - result = stat(filename, &statinfo); - if (result < 0) return 0; - if (!S_ISREG(statinfo.st_mode)) return 0; - - if (statinfo.st_uid == geteuid()) return statinfo.st_mode & S_IXUSR; - if (statinfo.st_gid == getegid()) return statinfo.st_mode & S_IXGRP; - return statinfo.st_mode & S_IXOTH; + int result; + struct stat statinfo; + + result = stat(filename.c_str(), &statinfo); + if (result < 0) return 0; + if (!S_ISREG(statinfo.st_mode)) return 0; + +#ifdef WIN32 + return 1; +#else + if (statinfo.st_uid == geteuid()) return statinfo.st_mode & S_IXUSR; + if (statinfo.st_gid == getegid()) return statinfo.st_mode & S_IXGRP; + return statinfo.st_mode & S_IXOTH; +#endif } /* int findpathof(char *pth, const char *exe) - * - * Find executable by searching the PATH environment variable. - * - * const char *exe - executable name to search for. - * char *pth - the path found is stored here, space - * needs to be available. - * - * If a path is found, returns non-zero, and the path is stored - * in pth. If exe is not found returns 0, with pth undefined. - */ - -int findpathof(char *pth, const char *exe) +* +* Find executable by searching the PATH environment variable. +* +* const char *exe - executable name to search for. +* char *pth - the path found is stored here, space +* needs to be available. +* +* If a path is found, returns non-zero, and the path is stored +* in pth. If exe is not found returns 0, with pth undefined. +*/ + +int findpathof(string& pth, const string& exe) { - char *searchpath; - char *beg, *end; - int stop, found; - int len; - - if (strchr(exe, '/') != NULL) { - if (realpath(exe, pth) == NULL) return 0; - return checkifexecutable(pth); - } - - searchpath = getenv("PATH"); - if (searchpath == NULL) return 0; - if (strlen(searchpath) <= 0) return 0; - - beg = searchpath; - stop = 0; found = 0; - do { - end = strchr(beg, ':'); - if (end == NULL) { - stop = 1; - strncpy(pth, beg, PATH_MAX); - len = strlen(pth); - } else { - strncpy(pth, beg, end - beg); - pth[end - beg] = '\0'; - len = end - beg; - } - if (pth[len - 1] != '/') strncat(pth, "/", 1); - strncat(pth, exe, PATH_MAX - len); - found = checkifexecutable(pth); - if (!stop) beg = end + 1; - } while (!stop && !found); - - return found; + string path( getenv("PATH") ); + if ( path.size() == 0 ) + return 0; + + char path_spr = +#ifdef WIN32 + ';'; +#else + ':'; +#endif + + char dir_spr = +#ifdef WIN32 + '\\'; +#else + '/'; +#endif + + int offset = 0; + int stop = 0; + int found = 0; + while(!stop && !found) + { + int pos = path.find( path_spr, offset ); + if (pos == string::npos) + stop = 1; + + pth = path.substr( offset, pos - offset ); + if ( pth.size() > 0 ) + { + if( pth[pth.size()-1] != dir_spr ) + pth += dir_spr; + pth += exe; + found = checkifexecutable(pth.c_str()); + } + offset = pos+1; + } + + +/* char *searchpath; + char *beg, *end; + int stop, found; + int len; + + if (strchr(exe, separator) != NULL) { +#ifndef WIN32 + if (realpath(exe, pth) == NULL) return 0; +#endif + return checkifexecutable(pth); + } + + searchpath = getenv("PATH"); + if (searchpath == NULL) return 0; + if (strlen(searchpath) <= 0) return 0; + + string env_path(searchpath); + + beg = searchpath; + stop = 0; found = 0; + do { + end = strchr(beg, ':'); + if (end == NULL) { + stop = 1; + strncpy(pth, beg, PATH_MAX); + len = strlen(pth); + } else { + strncpy(pth, beg, end - beg); + pth[end - beg] = '\0'; + len = end - beg; + } + if (pth[len - 1] != '/') strncat(pth, "/", 1); + strncat(pth, exe, PATH_MAX - len); + found = checkifexecutable(pth); + if (!stop) beg = end + 1; + } while (!stop && !found); +*/ + return found; } //============================================================================= /*! - * CORBA method: load a new component class (Python or C++ implementation) - * \param componentName like COMPONENT - * try to make a Python import of COMPONENT, - * then a lib open of libCOMPONENTEngine.so - * \return true if dlopen successfull or already done, false otherwise - */ +* CORBA method: load a new component class (Python or C++ implementation) +* \param componentName like COMPONENT +* try to make a Python import of COMPONENT, +* then a lib open of libCOMPONENTEngine.so +* \return true if dlopen successfull or already done, false otherwise +*/ //============================================================================= bool @@ -428,24 +478,24 @@ Engines_Container_i::load_component_Library(const char* componentName) // --- try dlopen C++ component -#ifndef WNT +#ifndef WIN32 string impl_name = string ("lib") + aCompName + string("Engine.so"); #else string impl_name = aCompName + string("Engine.dll"); #endif SCRUTE(impl_name); - + _numInstanceMutex.lock(); // lock to be alone // (see decInstanceCnt, finalize_removal)) if (_toRemove_map.count(impl_name) != 0) _toRemove_map.erase(impl_name); if (_library_map.count(impl_name) != 0) - { - MESSAGE("Library " << impl_name << " already loaded"); - _numInstanceMutex.unlock(); - return true; - } - -#ifndef WNT + { + MESSAGE("Library " << impl_name << " already loaded"); + _numInstanceMutex.unlock(); + return true; + } + +#ifndef WIN32 void* handle; handle = dlopen( impl_name.c_str() , RTLD_LAZY ) ; #else @@ -455,9 +505,9 @@ Engines_Container_i::load_component_Library(const char* componentName) if ( handle ) { - _library_map[impl_name] = handle; - _numInstanceMutex.unlock(); - return true; + _library_map[impl_name] = handle; + _numInstanceMutex.unlock(); + return true; } _numInstanceMutex.unlock(); @@ -465,41 +515,41 @@ Engines_Container_i::load_component_Library(const char* componentName) INFOS("try import Python component "<0) otherwise - * \return a loaded component - */ +* CORBA method: Creates a new servant instance of a component. +* The servant registers itself to naming service and Registry. +* \param genericRegisterName Name of the component instance to register +* in Registry & Name Service (without _inst_n suffix) +* \param studyId 0 for multiStudy instance, +* study Id (>0) otherwise +* \return a loaded component +*/ //============================================================================= Engines::Component_ptr @@ -526,71 +576,71 @@ Engines_Container_i::create_component_instance(const char*genericRegisterName, CORBA::Long studyId) { if (studyId < 0) - { - INFOS("studyId must be > 0 for mono study instance, =0 for multiStudy"); - return Engines::Component::_nil() ; - } + { + INFOS("studyId must be > 0 for mono study instance, =0 for multiStudy"); + return Engines::Component::_nil() ; + } Engines::Component_var iobject = Engines::Component::_nil() ; string aCompName = genericRegisterName; if (_library_map.count(aCompName) != 0) // Python component + { + if (_isSupervContainer) { - if (_isSupervContainer) - { - INFOS("Supervision Container does not support Python Component Engines"); - return Engines::Component::_nil(); - } - _numInstanceMutex.lock() ; // lock on the instance number - _numInstance++ ; - int numInstance = _numInstance ; - _numInstanceMutex.unlock() ; - - char aNumI[12]; - sprintf( aNumI , "%d" , numInstance ) ; - string instanceName = aCompName + "_inst_" + aNumI ; - string component_registerName = - _containerName + "/" + instanceName; - - Py_ACQUIRE_NEW_THREAD; - PyObject *mainmod = PyImport_AddModule("__main__"); - PyObject *globals = PyModule_GetDict(mainmod); - PyObject *pyCont = PyDict_GetItemString(globals, "pyCont"); - PyObject *result = PyObject_CallMethod(pyCont, - (char*)"create_component_instance", - (char*)"ssl", - aCompName.c_str(), - instanceName.c_str(), - studyId); - string iors = PyString_AsString(result); - Py_DECREF(result); - SCRUTE(iors); - Py_RELEASE_NEW_THREAD; - - if( iors!="" ) - { - CORBA::Object_var obj = _orb->string_to_object(iors.c_str()); - iobject = Engines::Component::_narrow( obj ) ; - _listInstances_map[instanceName] = iobject; - } - return iobject._retn(); + INFOS("Supervision Container does not support Python Component Engines"); + return Engines::Component::_nil(); } - + _numInstanceMutex.lock() ; // lock on the instance number + _numInstance++ ; + int numInstance = _numInstance ; + _numInstanceMutex.unlock() ; + + char aNumI[12]; + sprintf( aNumI , "%d" , numInstance ) ; + string instanceName = aCompName + "_inst_" + aNumI ; + string component_registerName = + _containerName + "/" + instanceName; + + Py_ACQUIRE_NEW_THREAD; + PyObject *mainmod = PyImport_AddModule("__main__"); + PyObject *globals = PyModule_GetDict(mainmod); + PyObject *pyCont = PyDict_GetItemString(globals, "pyCont"); + PyObject *result = PyObject_CallMethod(pyCont, + (char*)"create_component_instance", + (char*)"ssl", + aCompName.c_str(), + instanceName.c_str(), + studyId); + string iors = PyString_AsString(result); + Py_DECREF(result); + SCRUTE(iors); + Py_RELEASE_NEW_THREAD; + + if( iors!="" ) + { + CORBA::Object_var obj = _orb->string_to_object(iors.c_str()); + iobject = Engines::Component::_narrow( obj ) ; + _listInstances_map[instanceName] = iobject; + } + return iobject._retn(); + } + //--- try C++ -#ifndef WNT +#ifndef WIN32 string impl_name = string ("lib") + genericRegisterName +string("Engine.so"); #else string impl_name = genericRegisterName +string("Engine.dll"); #endif if (_library_map.count(impl_name) != 0) // C++ component - { - void* handle = _library_map[impl_name]; - iobject = createInstance(genericRegisterName, - handle, - studyId); - return iobject._retn(); - } + { + void* handle = _library_map[impl_name]; + iobject = createInstance(genericRegisterName, + handle, + studyId); + return iobject._retn(); + } // If it's not a Python or a C++ component try to launch a standalone component // in a sub directory @@ -611,11 +661,11 @@ Engines_Container_i::create_component_instance(const char*genericRegisterName, //check if an entry exist in naming service CORBA::Object_var nsobj = _NS->Resolve(component_registerName.c_str()); if ( !CORBA::is_nil(nsobj) ) - { - // unregister the registered component - _NS->Destroy_Name(component_registerName.c_str()); - //kill or shutdown it ??? - } + { + // unregister the registered component + _NS->Destroy_Name(component_registerName.c_str()); + //kill or shutdown it ??? + } // first arg container ior string // second arg container name @@ -644,97 +694,99 @@ Engines_Container_i::create_component_instance(const char*genericRegisterName, int status=system(command.c_str()); if (status == -1) - { - MESSAGE("SALOME_Container::create_component_instance system failed " << "(system command status -1)"); - return Engines::Component::_nil(); - } + { + MESSAGE("SALOME_Container::create_component_instance system failed " << "(system command status -1)"); + return Engines::Component::_nil(); + } +#ifndef WIN32 else if (WEXITSTATUS(status) == 217) - { - MESSAGE("SALOME_Container::create_component_instance system failed " << "(system command status 217)"); - return Engines::Component::_nil(); - } + { + MESSAGE("SALOME_Container::create_component_instance system failed " << "(system command status 217)"); + return Engines::Component::_nil(); + } +#endif else + { + int count=20; + CORBA::Object_var obj = CORBA::Object::_nil() ; + while ( CORBA::is_nil(obj) && count ) { - int count=20; - CORBA::Object_var obj = CORBA::Object::_nil() ; - while ( CORBA::is_nil(obj) && count ) - { -#ifndef WNT - sleep( 1 ) ; +#ifndef WIN32 + sleep( 1 ) ; #else - Sleep(1000); + Sleep(1000); #endif - count-- ; - MESSAGE( count << ". Waiting for component " << genericRegisterName); - obj = _NS->Resolve(component_registerName.c_str()); - } + count-- ; + MESSAGE( count << ". Waiting for component " << genericRegisterName); + obj = _NS->Resolve(component_registerName.c_str()); + } - if(CORBA::is_nil(obj)) - { - MESSAGE("SALOME_Container::create_component_instance failed"); - return Engines::Component::_nil(); - } - else - { - MESSAGE("SALOME_Container::create_component_instance successful"); - iobject=Engines::Component::_narrow(obj); - _listInstances_map[instanceName] = iobject; - return iobject._retn(); - } + if(CORBA::is_nil(obj)) + { + MESSAGE("SALOME_Container::create_component_instance failed"); + return Engines::Component::_nil(); + } + else + { + MESSAGE("SALOME_Container::create_component_instance successful"); + iobject=Engines::Component::_narrow(obj); + _listInstances_map[instanceName] = iobject; + return iobject._retn(); } + } } //============================================================================= /*! - * CORBA method: Finds a servant instance of a component - * \param registeredName Name of the component in Registry or Name Service, - * without instance suffix number - * \param studyId 0 if instance is not associated to a study, - * >0 otherwise (== study id) - * \return the first instance found with same studyId - */ +* CORBA method: Finds a servant instance of a component +* \param registeredName Name of the component in Registry or Name Service, +* without instance suffix number +* \param studyId 0 if instance is not associated to a study, +* >0 otherwise (== study id) +* \return the first instance found with same studyId +*/ //============================================================================= Engines::Component_ptr Engines_Container_i::find_component_instance( const char* registeredName, - CORBA::Long studyId) + CORBA::Long studyId) { Engines::Component_var anEngine = Engines::Component::_nil(); map::iterator itm =_listInstances_map.begin(); while (itm != _listInstances_map.end()) + { + string instance = (*itm).first; + SCRUTE(instance); + if (instance.find(registeredName) == 0) { - string instance = (*itm).first; - SCRUTE(instance); - if (instance.find(registeredName) == 0) - { - anEngine = (*itm).second; - if (studyId == anEngine->getStudyId()) - { - return anEngine._retn(); - } - } - itm++; + anEngine = (*itm).second; + if (studyId == anEngine->getStudyId()) + { + return anEngine._retn(); + } } + itm++; + } return anEngine._retn(); } //============================================================================= /*! - * CORBA method: find or create an instance of the component (servant), - * load a new component class (dynamic library) if required, - * ---- FOR COMPATIBILITY WITH 2.2 ---- - * ---- USE ONLY FOR MULTISTUDY INSTANCES ! -------- - * The servant registers itself to naming service and Registry. - * \param genericRegisterName Name of the component to register - * in Registry & Name Service - * \param componentName Name of the constructed library of the component - * \return a loaded component - */ +* CORBA method: find or create an instance of the component (servant), +* load a new component class (dynamic library) if required, +* ---- FOR COMPATIBILITY WITH 2.2 ---- +* ---- USE ONLY FOR MULTISTUDY INSTANCES ! -------- +* The servant registers itself to naming service and Registry. +* \param genericRegisterName Name of the component to register +* in Registry & Name Service +* \param componentName Name of the constructed library of the component +* \return a loaded component +*/ //============================================================================= Engines::Component_ptr Engines_Container_i::load_impl( const char* genericRegisterName, - const char* componentName ) + const char* componentName ) { string impl_name = string ("lib") + genericRegisterName +string("Engine.so"); Engines::Component_var iobject = Engines::Component::_nil() ; @@ -742,13 +794,13 @@ Engines_Container_i::load_impl( const char* genericRegisterName, iobject = find_or_create_instance(genericRegisterName, impl_name); return iobject._retn(); } - + //============================================================================= /*! - * CORBA method: Stops the component servant, and deletes all related objects - * \param component_i Component to be removed - */ +* CORBA method: Stops the component servant, and deletes all related objects +* \param component_i Component to be removed +*/ //============================================================================= void Engines_Container_i::remove_impl(Engines::Component_ptr component_i) @@ -765,44 +817,44 @@ void Engines_Container_i::remove_impl(Engines::Component_ptr component_i) //============================================================================= /*! - * CORBA method: Discharges unused libraries from the container. - */ +* CORBA method: Discharges unused libraries from the container. +*/ //============================================================================= void Engines_Container_i::finalize_removal() { MESSAGE("finalize unload : dlclose"); _numInstanceMutex.lock(); // lock to be alone - // (see decInstanceCnt, load_component_Library) + // (see decInstanceCnt, load_component_Library) map::iterator ith; for (ith = _toRemove_map.begin(); ith != _toRemove_map.end(); ith++) + { + void *handle = (*ith).second; + string impl_name= (*ith).first; + if (handle) { - void *handle = (*ith).second; - string impl_name= (*ith).first; - if (handle) - { - SCRUTE(handle); - SCRUTE(impl_name); -// dlclose(handle); // SALOME unstable after ... -// _library_map.erase(impl_name); - } + SCRUTE(handle); + SCRUTE(impl_name); + // dlclose(handle); // SALOME unstable after ... + // _library_map.erase(impl_name); } + } _toRemove_map.clear(); _numInstanceMutex.unlock(); } //============================================================================= /*! - * CORBA method: Kill the container process with exit(0). - * To remove : never returns ! - */ +* CORBA method: Kill the container process with exit(0). +* To remove : never returns ! +*/ //============================================================================= bool Engines_Container_i::Kill_impl() { MESSAGE("Engines_Container_i::Kill() pid "<< getpid() << " containerName " - << _containerName.c_str() << " machineName " - << GetHostname().c_str()); + << _containerName.c_str() << " machineName " + << Kernel_Utils::GetHostname().c_str()); INFOS("==============================================================="); INFOS("= REMOVE calls to Kill_impl in C++ container ="); INFOS("==============================================================="); @@ -813,14 +865,14 @@ bool Engines_Container_i::Kill_impl() //============================================================================= /*! - * CORBA method: get or create a fileRef object associated to a local file - * (a file on the computer on which runs the container server), which stores - * a list of (machine, localFileName) corresponding to copies already done. - * - * \param origFileName absolute path for a local file to copy on other - * computers - * \return a fileRef object associated to the file. - */ +* CORBA method: get or create a fileRef object associated to a local file +* (a file on the computer on which runs the container server), which stores +* a list of (machine, localFileName) corresponding to copies already done. +* +* \param origFileName absolute path for a local file to copy on other +* computers +* \return a fileRef object associated to the file. +*/ //============================================================================= Engines::fileRef_ptr @@ -830,22 +882,22 @@ Engines_Container_i::createFileRef(const char* origFileName) Engines::fileRef_var theFileRef = Engines::fileRef::_nil(); if (origName[0] != '/') - { - INFOS("path of file to copy must be an absolute path begining with '/'"); - return Engines::fileRef::_nil(); - } + { + INFOS("path of file to copy must be an absolute path begining with '/'"); + return Engines::fileRef::_nil(); + } if (CORBA::is_nil(_fileRef_map[origName])) - { - CORBA::Object_var obj=_poa->id_to_reference(*_id); - Engines::Container_var pCont = Engines::Container::_narrow(obj); - fileRef_i* aFileRef = new fileRef_i(pCont, origFileName); - theFileRef = Engines::fileRef::_narrow(aFileRef->_this()); - _numInstanceMutex.lock() ; // lock to be alone (stl container write) - _fileRef_map[origName] = theFileRef; - _numInstanceMutex.unlock() ; - } - + { + CORBA::Object_var obj=_poa->id_to_reference(*_id); + Engines::Container_var pCont = Engines::Container::_narrow(obj); + fileRef_i* aFileRef = new fileRef_i(pCont, origFileName); + theFileRef = Engines::fileRef::_narrow(aFileRef->_this()); + _numInstanceMutex.lock() ; // lock to be alone (stl container write) + _fileRef_map[origName] = theFileRef; + _numInstanceMutex.unlock() ; + } + theFileRef = Engines::fileRef::_duplicate(_fileRef_map[origName]); ASSERT(! CORBA::is_nil(theFileRef)); return theFileRef._retn(); @@ -853,9 +905,9 @@ Engines_Container_i::createFileRef(const char* origFileName) //============================================================================= /*! - * CORBA method: - * \return a reference to the fileTransfer object - */ +* CORBA method: +* \return a reference to the fileTransfer object +*/ //============================================================================= Engines::fileTransfer_ptr @@ -872,26 +924,26 @@ Engines_Container_i::createSalome_file(const char* origFileName) { string origName(origFileName); if (CORBA::is_nil(_Salome_file_map[origName])) + { + Salome_file_i* aSalome_file = new Salome_file_i(); + aSalome_file->setContainer(Engines::Container::_duplicate(this->_this())); + try { - Salome_file_i* aSalome_file = new Salome_file_i(); - aSalome_file->setContainer(Engines::Container::_duplicate(this->_this())); - try - { - aSalome_file->setLocalFile(origFileName); - aSalome_file->recvFiles(); - } - catch (const SALOME::SALOME_Exception& e) - { - return Engines::Salome_file::_nil(); - } - - Engines::Salome_file_var theSalome_file = Engines::Salome_file::_nil(); - theSalome_file = Engines::Salome_file::_narrow(aSalome_file->_this()); - _numInstanceMutex.lock() ; // lock to be alone (stl container write) - _Salome_file_map[origName] = theSalome_file; - _numInstanceMutex.unlock() ; + aSalome_file->setLocalFile(origFileName); + aSalome_file->recvFiles(); + } + catch (const SALOME::SALOME_Exception& e) + { + return Engines::Salome_file::_nil(); } - + + Engines::Salome_file_var theSalome_file = Engines::Salome_file::_nil(); + theSalome_file = Engines::Salome_file::_narrow(aSalome_file->_this()); + _numInstanceMutex.lock() ; // lock to be alone (stl container write) + _Salome_file_map[origName] = theSalome_file; + _numInstanceMutex.unlock() ; + } + Engines::Salome_file_ptr theSalome_file = Engines::Salome_file::_duplicate(_Salome_file_map[origName]); ASSERT(!CORBA::is_nil(theSalome_file)); @@ -899,25 +951,25 @@ Engines_Container_i::createSalome_file(const char* origFileName) } //============================================================================= /*! - * C++ method: Finds an already existing servant instance of a component, or - * create an instance. - * ---- USE ONLY FOR MULTISTUDY INSTANCES ! -------- - * \param genericRegisterName Name of the component instance to register - * in Registry & Name Service, - * (without _inst_n suffix, like "COMPONENT") - * \param componentLibraryName like "libCOMPONENTEngine.so" - * \return a loaded component - * - * example with names: - * aGenRegisterName = COMPONENT (= first argument) - * impl_name = libCOMPONENTEngine.so (= second argument) - * _containerName = /Containers/cli76ce/FactoryServer - * factoryName = COMPONENTEngine_factory - * component_registerBase = /Containers/cli76ce/FactoryServer/COMPONENT - * - * instanceName = COMPONENT_inst_1 - * component_registerName = /Containers/cli76ce/FactoryServer/COMPONENT_inst_1 - */ +* C++ method: Finds an already existing servant instance of a component, or +* create an instance. +* ---- USE ONLY FOR MULTISTUDY INSTANCES ! -------- +* \param genericRegisterName Name of the component instance to register +* in Registry & Name Service, +* (without _inst_n suffix, like "COMPONENT") +* \param componentLibraryName like "libCOMPONENTEngine.so" +* \return a loaded component +* +* example with names: +* aGenRegisterName = COMPONENT (= first argument) +* impl_name = libCOMPONENTEngine.so (= second argument) +* _containerName = /Containers/cli76ce/FactoryServer +* factoryName = COMPONENTEngine_factory +* component_registerBase = /Containers/cli76ce/FactoryServer/COMPONENT +* +* instanceName = COMPONENT_inst_1 +* component_registerName = /Containers/cli76ce/FactoryServer/COMPONENT_inst_1 +*/ //============================================================================= Engines::Component_ptr @@ -927,77 +979,77 @@ Engines_Container_i::find_or_create_instance(string genericRegisterName, string aGenRegisterName = genericRegisterName; string impl_name = componentLibraryName; if (_library_map.count(impl_name) == 0) - { - INFOS("shared library " << impl_name <<" must be loaded before creating instance"); - return Engines::Component::_nil() ; - } + { + INFOS("shared library " << impl_name <<" must be loaded before creating instance"); + return Engines::Component::_nil() ; + } else - { - // --- find a registered instance in naming service, or create + { + // --- find a registered instance in naming service, or create - void* handle = _library_map[impl_name]; - string component_registerBase = - _containerName + "/" + aGenRegisterName; - Engines::Component_var iobject = Engines::Component::_nil() ; - try + void* handle = _library_map[impl_name]; + string component_registerBase = + _containerName + "/" + aGenRegisterName; + Engines::Component_var iobject = Engines::Component::_nil() ; + try + { + CORBA::Object_var obj = + _NS->ResolveFirst( component_registerBase.c_str()); + if ( CORBA::is_nil( obj ) ) + { + iobject = createInstance(genericRegisterName, + handle, + 0); // force multiStudy instance here ! + } + else + { + iobject = Engines::Component::_narrow( obj ) ; + Engines_Component_i *servant = + dynamic_cast + (_poa->reference_to_servant(iobject)); + ASSERT(servant) + int studyId = servant->getStudyId(); + ASSERT (studyId >= 0); + if (studyId == 0) // multiStudy instance, OK { - CORBA::Object_var obj = - _NS->ResolveFirst( component_registerBase.c_str()); - if ( CORBA::is_nil( obj ) ) - { - iobject = createInstance(genericRegisterName, - handle, - 0); // force multiStudy instance here ! - } - else - { - iobject = Engines::Component::_narrow( obj ) ; - Engines_Component_i *servant = - dynamic_cast - (_poa->reference_to_servant(iobject)); - ASSERT(servant) - int studyId = servant->getStudyId(); - ASSERT (studyId >= 0); - if (studyId == 0) // multiStudy instance, OK - { - // No ReBind ! - MESSAGE(component_registerBase.c_str()<<" already bound"); - } - else // monoStudy instance: NOK - { - iobject = Engines::Component::_nil(); - INFOS("load_impl & find_component_instance methods " - << "NOT SUITABLE for mono study components"); - } - } + // No ReBind ! + MESSAGE(component_registerBase.c_str()<<" already bound"); } - catch (...) + else // monoStudy instance: NOK { - INFOS( "Container_i::load_impl catched" ) ; + iobject = Engines::Component::_nil(); + INFOS("load_impl & find_component_instance methods " + << "NOT SUITABLE for mono study components"); } - return iobject._retn(); + } + } + catch (...) + { + INFOS( "Container_i::load_impl catched" ) ; } + return iobject._retn(); + } } //============================================================================= /*! - * C++ method: create a servant instance of a component. - * \param genericRegisterName Name of the component instance to register - * in Registry & Name Service, - * (without _inst_n suffix, like "COMPONENT") - * \param handle loaded library handle - * \param studyId 0 for multiStudy instance, - * study Id (>0) otherwise - * \return a loaded component - * - * example with names: - * aGenRegisterName = COMPONENT (= first argument) - * _containerName = /Containers/cli76ce/FactoryServer - * factoryName = COMPONENTEngine_factory - * component_registerBase = /Containers/cli76ce/FactoryServer/COMPONENT - * instanceName = COMPONENT_inst_1 - * component_registerName = /Containers/cli76ce/FactoryServer/COMPONENT_inst_1 - */ +* C++ method: create a servant instance of a component. +* \param genericRegisterName Name of the component instance to register +* in Registry & Name Service, +* (without _inst_n suffix, like "COMPONENT") +* \param handle loaded library handle +* \param studyId 0 for multiStudy instance, +* study Id (>0) otherwise +* \return a loaded component +* +* example with names: +* aGenRegisterName = COMPONENT (= first argument) +* _containerName = /Containers/cli76ce/FactoryServer +* factoryName = COMPONENTEngine_factory +* component_registerBase = /Containers/cli76ce/FactoryServer/COMPONENT +* instanceName = COMPONENT_inst_1 +* component_registerName = /Containers/cli76ce/FactoryServer/COMPONENT_inst_1 +*/ //============================================================================= Engines::Component_ptr @@ -1013,12 +1065,12 @@ Engines_Container_i::createInstance(string genericRegisterName, typedef PortableServer::ObjectId * (*FACTORY_FUNCTION) (CORBA::ORB_ptr, - PortableServer::POA_ptr, - PortableServer::ObjectId *, - const char *, - const char *) ; + PortableServer::POA_ptr, + PortableServer::ObjectId *, + const char *, + const char *) ; -#ifndef WNT +#ifndef WIN32 FACTORY_FUNCTION Component_factory = (FACTORY_FUNCTION)dlsym( handle, factory_name.c_str() ); #else FACTORY_FUNCTION Component_factory = (FACTORY_FUNCTION)GetProcAddress( (HINSTANCE)handle, factory_name.c_str() ); @@ -1026,11 +1078,11 @@ Engines_Container_i::createInstance(string genericRegisterName, if ( !Component_factory ) { - INFOS( "Can't resolve symbol: " + factory_name ); -#ifndef WNT - SCRUTE( dlerror() ); + INFOS( "Can't resolve symbol: " + factory_name ); +#ifndef WIN32 + SCRUTE( dlerror() ); #endif - return Engines::Component::_nil() ; + return Engines::Component::_nil() ; } // --- create instance @@ -1038,68 +1090,68 @@ Engines_Container_i::createInstance(string genericRegisterName, Engines::Component_var iobject = Engines::Component::_nil() ; try - { - _numInstanceMutex.lock() ; // lock on the instance number - _numInstance++ ; - int numInstance = _numInstance ; - _numInstanceMutex.unlock() ; - - char aNumI[12]; - sprintf( aNumI , "%d" , numInstance ) ; - string instanceName = aGenRegisterName + "_inst_" + aNumI ; - string component_registerName = - _containerName + "/" + instanceName; - - // --- Instanciate required CORBA object - - PortableServer::ObjectId *id ; //not owner, do not delete (nore use var) - id = (Component_factory) ( _orb, _poa, _id, instanceName.c_str(), - aGenRegisterName.c_str() ) ; - if (id == NULL) - return iobject._retn(); - - // --- get reference & servant from id - - CORBA::Object_var obj = _poa->id_to_reference(*id); - iobject = Engines::Component::_narrow( obj ) ; + { + _numInstanceMutex.lock() ; // lock on the instance number + _numInstance++ ; + int numInstance = _numInstance ; + _numInstanceMutex.unlock() ; + + char aNumI[12]; + sprintf( aNumI , "%d" , numInstance ) ; + string instanceName = aGenRegisterName + "_inst_" + aNumI ; + string component_registerName = + _containerName + "/" + instanceName; + + // --- Instanciate required CORBA object + + PortableServer::ObjectId *id ; //not owner, do not delete (nore use var) + id = (Component_factory) ( _orb, _poa, _id, instanceName.c_str(), + aGenRegisterName.c_str() ) ; + if (id == NULL) + return iobject._retn(); - Engines_Component_i *servant = - dynamic_cast(_poa->reference_to_servant(iobject)); - ASSERT(servant); - //SCRUTE(servant->pd_refCount); - servant->_remove_ref(); // compensate previous id_to_reference - //SCRUTE(servant->pd_refCount); - _numInstanceMutex.lock() ; // lock to be alone (stl container write) - _listInstances_map[instanceName] = iobject; - _cntInstances_map[aGenRegisterName] += 1; - _numInstanceMutex.unlock() ; - SCRUTE(aGenRegisterName); - SCRUTE(_cntInstances_map[aGenRegisterName]); - //SCRUTE(servant->pd_refCount); + // --- get reference & servant from id + + CORBA::Object_var obj = _poa->id_to_reference(*id); + iobject = Engines::Component::_narrow( obj ) ; + + Engines_Component_i *servant = + dynamic_cast(_poa->reference_to_servant(iobject)); + ASSERT(servant); + //SCRUTE(servant->pd_refCount); + servant->_remove_ref(); // compensate previous id_to_reference + //SCRUTE(servant->pd_refCount); + _numInstanceMutex.lock() ; // lock to be alone (stl container write) + _listInstances_map[instanceName] = iobject; + _cntInstances_map[aGenRegisterName] += 1; + _numInstanceMutex.unlock() ; + SCRUTE(aGenRegisterName); + SCRUTE(_cntInstances_map[aGenRegisterName]); + //SCRUTE(servant->pd_refCount); #if defined(_DEBUG_) || defined(_DEBUG) - bool ret_studyId = servant->setStudyId(studyId); - ASSERT(ret_studyId); + bool ret_studyId = servant->setStudyId(studyId); + ASSERT(ret_studyId); #else - servant->setStudyId(studyId); + servant->setStudyId(studyId); #endif - // --- register the engine under the name - // containerName(.dir)/instanceName(.object) + // --- register the engine under the name + // containerName(.dir)/instanceName(.object) - _NS->Register( iobject , component_registerName.c_str() ) ; - MESSAGE( component_registerName.c_str() << " bound" ) ; - } + _NS->Register( iobject , component_registerName.c_str() ) ; + MESSAGE( component_registerName.c_str() << " bound" ) ; + } catch (...) - { - INFOS( "Container_i::createInstance exception catched" ) ; - } + { + INFOS( "Container_i::createInstance exception catched" ) ; + } return iobject._retn(); } //============================================================================= /*! - * - */ +* +*/ //============================================================================= void Engines_Container_i::decInstanceCnt(string genericRegisterName) @@ -1110,25 +1162,25 @@ void Engines_Container_i::decInstanceCnt(string genericRegisterName) MESSAGE("Engines_Container_i::decInstanceCnt " << aGenRegisterName); ASSERT(_cntInstances_map[aGenRegisterName] > 0); _numInstanceMutex.lock(); // lock to be alone - // (see finalize_removal, load_component_Library) + // (see finalize_removal, load_component_Library) _cntInstances_map[aGenRegisterName] -= 1; SCRUTE(_cntInstances_map[aGenRegisterName]); if (_cntInstances_map[aGenRegisterName] == 0) - { - string impl_name = - Engines_Component_i::GetDynLibraryName(aGenRegisterName.c_str()); - SCRUTE(impl_name); - void* handle = _library_map[impl_name]; - ASSERT(handle); - _toRemove_map[impl_name] = handle; - } + { + string impl_name = + Engines_Component_i::GetDynLibraryName(aGenRegisterName.c_str()); + SCRUTE(impl_name); + void* handle = _library_map[impl_name]; + ASSERT(handle); + _toRemove_map[impl_name] = handle; + } _numInstanceMutex.unlock(); } //============================================================================= /*! - * Retrieves only with container naming convention if it is a python container - */ +* Retrieves only with container naming convention if it is a python container +*/ //============================================================================= bool Engines_Container_i::isPythonContainer(const char* ContainerName) @@ -1143,39 +1195,39 @@ bool Engines_Container_i::isPythonContainer(const char* ContainerName) //============================================================================= /*! - * - */ +* +*/ //============================================================================= void ActSigIntHandler() { -#ifndef WNT +#ifndef WIN32 struct sigaction SigIntAct ; SigIntAct.sa_sigaction = &SigIntHandler ; SigIntAct.sa_flags = SA_SIGINFO ; #endif -// DEBUG 03.02.2005 : the first parameter of sigaction is not a mask of signals -// (SIGINT | SIGUSR1) : -// it must be only one signal ===> one call for SIGINT -// and an other one for SIGUSR1 + // DEBUG 03.02.2005 : the first parameter of sigaction is not a mask of signals + // (SIGINT | SIGUSR1) : + // it must be only one signal ===> one call for SIGINT + // and an other one for SIGUSR1 -#ifndef WNT +#ifndef WIN32 if ( sigaction( SIGINT , &SigIntAct, NULL ) ) - { - perror("SALOME_Container main ") ; - exit(0) ; - } + { + perror("SALOME_Container main ") ; + exit(0) ; + } if ( sigaction( SIGUSR1 , &SigIntAct, NULL ) ) - { - perror("SALOME_Container main ") ; - exit(0) ; - } + { + perror("SALOME_Container main ") ; + exit(0) ; + } if ( sigaction( SIGUSR2 , &SigIntAct, NULL ) ) - { - perror("SALOME_Container main ") ; - exit(0) ; - } + { + perror("SALOME_Container main ") ; + exit(0) ; + } //PAL9042 JR : during the execution of a Signal Handler (and of methods called through Signal Handlers) // use of streams (and so on) should never be used because : @@ -1195,7 +1247,7 @@ void ActSigIntHandler() void SetCpuUsed() ; void CallCancelThread() ; -#ifndef WNT +#ifndef WIN32 void SigIntHandler(int what , siginfo_t * siginfo , void * toto ) @@ -1212,71 +1264,71 @@ void SigIntHandler(int what , // << " si_pid " << siginfo->si_pid) ; if ( _Sleeping ) + { + _Sleeping = false ; + // MESSAGE("SigIntHandler END sleeping.") ; + return ; + } + else + { + ActSigIntHandler() ; + if ( siginfo->si_signo == SIGUSR1 ) { - _Sleeping = false ; - // MESSAGE("SigIntHandler END sleeping.") ; - return ; + SetCpuUsed() ; } - else + else if ( siginfo->si_signo == SIGUSR2 ) { - ActSigIntHandler() ; - if ( siginfo->si_signo == SIGUSR1 ) - { - SetCpuUsed() ; - } - else if ( siginfo->si_signo == SIGUSR2 ) - { - CallCancelThread() ; - } - else - { - _Sleeping = true ; - // MESSAGE("SigIntHandler BEGIN sleeping.") ; - int count = 0 ; - while( _Sleeping ) - { - sleep( 1 ) ; - count += 1 ; - } - // MESSAGE("SigIntHandler LEAVE sleeping after " << count << " s.") ; - } - return ; + CallCancelThread() ; + } + else + { + _Sleeping = true ; + // MESSAGE("SigIntHandler BEGIN sleeping.") ; + int count = 0 ; + while( _Sleeping ) + { + sleep( 1 ) ; + count += 1 ; + } + // MESSAGE("SigIntHandler LEAVE sleeping after " << count << " s.") ; } + return ; + } } -#else // Case WNT +#else // Case WIN32 void SigIntHandler( int what ) { -#ifndef WNT +#ifndef WIN32 MESSAGE( pthread_self() << "SigIntHandler what " << what << endl ); #else MESSAGE( "SigIntHandler what " << what << endl ); #endif if ( _Sleeping ) + { + _Sleeping = false ; + MESSAGE("SigIntHandler END sleeping.") ; + return ; + } + else + { + ActSigIntHandler() ; + if ( what == SIGUSR1 ) { - _Sleeping = false ; - MESSAGE("SigIntHandler END sleeping.") ; - return ; + SetCpuUsed() ; } - else + else { - ActSigIntHandler() ; - if ( what == SIGUSR1 ) - { - SetCpuUsed() ; - } - else - { - _Sleeping = true ; - MESSAGE("SigIntHandler BEGIN sleeping.") ; - int count = 0 ; - while( _Sleeping ) - { - Sleep( 1000 ) ; - count += 1 ; - } - MESSAGE("SigIntHandler LEAVE sleeping after " << count << " s.") ; - } - return ; + _Sleeping = true ; + MESSAGE("SigIntHandler BEGIN sleeping.") ; + int count = 0 ; + while( _Sleeping ) + { + Sleep( 1000 ) ; + count += 1 ; + } + MESSAGE("SigIntHandler LEAVE sleeping after " << count << " s.") ; } + return ; + } } #endif diff --git a/src/Container/Container_init_python.cxx b/src/Container/Container_init_python.cxx index bea28a668..64979635d 100644 --- a/src/Container/Container_init_python.cxx +++ b/src/Container/Container_init_python.cxx @@ -27,7 +27,7 @@ // $Header$ #include -#ifndef WNT +#ifndef WIN32 #include #endif diff --git a/src/Container/Container_init_python.hxx b/src/Container/Container_init_python.hxx index d81ac5760..16bb06213 100644 --- a/src/Container/Container_init_python.hxx +++ b/src/Container/Container_init_python.hxx @@ -59,7 +59,7 @@ struct CONTAINER_EXPORT KERNEL_PYTHON { -#ifdef WNT +#ifdef WIN32 static PyThreadState *get_gtstate() { return KERNEL_PYTHON::_gtstate; } static PyObject *getsalome_shared_modules_module() { return KERNEL_PYTHON::salome_shared_modules_module; } static PyInterpreterState *get_interp() { return KERNEL_PYTHON::_interp; } diff --git a/src/Container/Makefile.am b/src/Container/Makefile.am index 0ad023f7a..16ea20722 100644 --- a/src/Container/Makefile.am +++ b/src/Container/Makefile.am @@ -90,7 +90,7 @@ COMMON_LIBS =\ ../Basics/libSALOMEBasics.la \ ../HDFPersist/libSalomeHDFPersist.la \ ../Batch/libSalomeBatch.la \ - $(top_builddir)/idl/libSalomeIDLKernel.la\ + $(top_builddir)/idl/libSalomeIDLKernel.la \ @MPI_LIBS@ \ @CORBA_LIBS@ \ $(PYTHON_LIBS) @@ -142,6 +142,7 @@ SALOME_Container_CPPFLAGS =\ SALOME_Container_LDADD = \ libSalomeContainer.la \ + ../Basics/libSALOMEBasics.la \ $(HDF5_LIBS) \ $(MPI_LIBS) \ $(CORBA_LIBS) \ @@ -158,6 +159,7 @@ TestSalome_file_CPPFLAGS =\ TestSalome_file_LDADD =\ libSalomeContainer.la \ + ../Basics/libSALOMEBasics.la \ $(HDF5_LIBS) \ $(MPI_LIBS) \ $(CORBA_LIBS) \ diff --git a/src/Container/SALOME_Component_i.hxx b/src/Container/SALOME_Component_i.hxx index 154211695..3a2f62cc0 100644 --- a/src/Container/SALOME_Component_i.hxx +++ b/src/Container/SALOME_Component_i.hxx @@ -36,7 +36,7 @@ #include #include #include -#ifndef WNT +#ifndef WIN32 #include #endif #include @@ -176,7 +176,7 @@ protected: std::string _nodeName ; private: -#ifndef WNT +#ifndef WIN32 pthread_t _ThreadId ; #else pthread_t* _ThreadId ; diff --git a/src/Container/SALOME_Container.cxx b/src/Container/SALOME_Container.cxx index 61401e7f0..3cdd20a6a 100644 --- a/src/Container/SALOME_Container.cxx +++ b/src/Container/SALOME_Container.cxx @@ -35,13 +35,13 @@ #include #include #include -#ifndef WNT +#ifndef WIN32 # include # include #endif -#ifndef WNT +#ifndef WIN32 #include #else #include @@ -65,8 +65,11 @@ extern "C" void HandleServerSideSignals(CORBA::ORB_ptr theORB); #include #include #include -#include +#ifndef WIN32 +# include +#endif +#ifndef WIN32 typedef void (*sighandler_t)(int); sighandler_t setsig(int sig, sighandler_t handler) { @@ -78,9 +81,11 @@ sighandler_t setsig(int sig, sighandler_t handler) return SIG_ERR; return ocontext.sa_handler; } +#endif //WIN32 void AttachDebugger() { +#ifndef WIN32 if(getenv ("DEBUGGER")) { std::stringstream exec; @@ -89,6 +94,7 @@ void AttachDebugger() system(exec.str().c_str()); while(1); } +#endif } void Handler(int theSigId) @@ -117,12 +123,14 @@ int main(int argc, char* argv[]) MPI_Init(&argc,&argv); #endif +#ifndef WIN32 if(getenv ("DEBUGGER")) { setsig(SIGSEGV,&Handler); set_terminate(&terminateHandler); set_unexpected(&unexpectedHandler); } +#endif // Initialise the ORB. //SRN: BugID: IPAL9541, it's necessary to set a size of one message to be at least 100Mb @@ -167,7 +175,7 @@ int main(int argc, char* argv[]) PortableServer::POAManager_var pman = root_poa->the_POAManager(); // add new container to the kill list -#ifndef WNT +#ifndef WIN32 stringstream aCommand ; aCommand << "addToKillList.py " << getpid() << " SALOME_Container" << ends ; system(aCommand.str().c_str()); diff --git a/src/Container/SALOME_Container.hxx b/src/Container/SALOME_Container.hxx index 4d3ff13a0..29f8a9cb8 100755 --- a/src/Container/SALOME_Container.hxx +++ b/src/Container/SALOME_Container.hxx @@ -26,22 +26,14 @@ #ifndef _SALOME_Container_HXX_ #define _SALOME_Container_HXX_ -#ifdef WNT - #if defined CONTAINER_EXPORTS - #if defined WIN32 - #define CONTAINER_EXPORT __declspec( dllexport ) - #else - #define CONTAINER_EXPORT - #endif - #else - #if defined WIN32 - #define CONTAINER_EXPORT __declspec( dllimport ) - #else - #define CONTAINER_EXPORT - #endif - #endif +#ifdef WIN32 +# ifdef CONTAINER_EXPORTS +# define CONTAINER_EXPORT __declspec( dllexport ) +# else +# define CONTAINER_EXPORT __declspec( dllimport ) +# endif #else - #define CONTAINER_EXPORT +# define CONTAINER_EXPORT #endif #endif diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index 1c3d5704d..2bdf12e33 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -20,10 +20,11 @@ #include "SALOME_ContainerManager.hxx" #include "SALOME_NamingService.hxx" #include "SALOME_ModuleCatalog.hh" -#include "OpUtil.hxx" +#include "Basics_Utils.hxx" +#include "Basics_DirUtils.hxx" #include #include -#ifndef WNT +#ifndef WIN32 #include #endif #include @@ -223,7 +224,7 @@ StartContainer(const Engines::MachineParameters& params, possibleComputers.length()); vector lm; - for(int i=0;ilogfilename(logFilename.c_str()); } @@ -375,7 +376,7 @@ StartContainer(const Engines::MachineParameters& params, if (CORBA::is_nil (Catalog)) return Engines::Container::_nil(); // Loop through component list - for(int i=0;iGetComponent(compoi); @@ -453,7 +454,7 @@ FindOrStartParallelContainer(const Engines::MachineParameters& params_const, else { INFOS("[FindOrStartParallelContainer] on machine : " << theMachine); string command; - if(theMachine == GetHostname()) { + if(theMachine == Kernel_Utils::GetHostname()) { // Step 3 : starting parallel container proxy params.hostname = CORBA::string_dup(theMachine.c_str()); Engines::MachineParameters params_proxy(params); @@ -479,7 +480,7 @@ FindOrStartParallelContainer(const Engines::MachineParameters& params_const, for (int i = 0; i < params.nb_component_nodes; i++) { char buffer [5]; -#ifndef WNT +#ifndef WIN32 snprintf(buffer,5,"%d",i); #else _snprintf(buffer,5,"%d",i); @@ -492,7 +493,7 @@ FindOrStartParallelContainer(const Engines::MachineParameters& params_const, obj = _NS->Resolve(containerNameInNS.c_str()); while (CORBA::is_nil(obj) && count) { INFOS("[FindOrStartParallelContainer] CONNECTION FAILED !!!!!!!!!!!!!!!!!!!!!!!!"); -#ifndef WNT +#ifndef WIN32 sleep(1) ; #else Sleep(1000); @@ -667,7 +668,7 @@ SALOME_ContainerManager::LaunchParallelContainer(const std::string& command, INFOS("[LaunchParallelContainer] Waiting for Parallel Container proxy on " << theMachine); while (CORBA::is_nil(obj) && count) { -#ifndef WNT +#ifndef WIN32 sleep(1) ; #else Sleep(1000); @@ -692,7 +693,7 @@ SALOME_ContainerManager::LaunchParallelContainer(const std::string& command, // Name of the node char buffer [5]; -#ifndef WNT +#ifndef WIN32 snprintf(buffer,5,"%d",i); #else _snprintf(buffer,5,"%d",i); @@ -705,7 +706,7 @@ SALOME_ContainerManager::LaunchParallelContainer(const std::string& command, containerNameInNS = _NS->BuildContainerNameForNS((char*) name_cont.c_str(),theMachine.c_str()); cerr << "[LaunchContainer] Waiting for Parllel Container node " << containerNameInNS << " on " << theMachine << endl; while (CORBA::is_nil(obj) && count) { -#ifndef WNT +#ifndef WIN32 sleep(1) ; #else Sleep(1000); @@ -908,14 +909,17 @@ string SALOME_ContainerManager::BuildCommandToLaunchLocalContainer (const Engines::MachineParameters& params, const long id,const std::string& container_exe) { - _TmpFileName = ""; + _TmpFileName = BuildTemporaryFileName(); string command; int nbproc = 0; - char idc[3*sizeof(long)]; + //char idc[3*sizeof(long)]; + + ofstream command_file( _TmpFileName.c_str() ); if (params.isMPI) { - command = "mpirun -np "; + //command = "mpirun -np "; + command_file << "mpirun -np "; if ( (params.nb_node <= 0) && (params.nb_proc_per_node <= 0) ) nbproc = 1; @@ -926,24 +930,28 @@ SALOME_ContainerManager::BuildCommandToLaunchLocalContainer else nbproc = params.nb_node * params.nb_proc_per_node; - std::ostringstream o; + //std::ostringstream o; - o << nbproc << " "; + //o << nbproc << " "; + command_file << nbproc << " "; - command += o.str(); + //command += o.str(); #ifdef WITHLAM - command += "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace "; + //command += "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace "; + command_file << "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace "; #endif if (isPythonContainer(params.container_name)) - command += "pyMPI SALOME_ContainerPy.py "; + //command += "pyMPI SALOME_ContainerPy.py "; + command_file << "pyMPI SALOME_ContainerPy.py "; else - command += "SALOME_MPIContainer "; + //command += "SALOME_MPIContainer "; + command_file << "SALOME_MPIContainer "; } else { - command=""; + //command=""; std::string wdir=params.workingdir.in(); if(wdir != "") { @@ -951,33 +959,57 @@ SALOME_ContainerManager::BuildCommandToLaunchLocalContainer if(wdir == "$TEMPDIR") { // a new temporary directory is requested - 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 = Kernel_Utils::GetTmpDir(); +#ifdef WIN32 + //command += "cd /d "+ dir +";"; + command_file << "cd /d " << dir << endl; +#else + //command = "cd "+ dir +";"; + command_file << "cd " << dir << ";"; +#endif + } else { // a permanent directory is requested use it or create it - command="mkdir -p " + wdir + " && cd " + wdir + ";"; +#ifdef WIN32 + //command="mkdir " + wdir; + command_file << "mkdir " + wdir << endl; + command_file << "cd /D " + wdir << endl; +#else + //command="mkdir -p " + wdir + " && cd " + wdir + ";"; + command_file << "mkdir -p " << wdir << " && cd " << wdir + ";"; +#endif } } if (isPythonContainer(params.container_name)) - command += "SALOME_ContainerPy.py "; + //command += "SALOME_ContainerPy.py "; + command_file << "SALOME_ContainerPy.py "; else - command += container_exe + " "; + //command += container_exe + " "; + command_file << container_exe + " "; + } - command += _NS->ContainerName(params); + + /*command += _NS->ContainerName(params); command += " -id "; sprintf(idc,"%ld",id); command += idc; - command += " -"; - AddOmninamesParams(command); + command += " -"; + AddOmninamesParams(command);*/ + + command_file << _NS->ContainerName(params); + command_file << " -id " << id << " -"; + AddOmninamesParams(command_file); + command_file.close(); + +#ifndef WIN32 + chmod(_TmpFileName.c_str(), 0x1ED); +#endif + command = _TmpFileName; - MESSAGE("Command is ... " << command); + MESSAGE("Command is file ... " << command); return command; } @@ -992,7 +1024,7 @@ void SALOME_ContainerManager::RmTmpFile() { if (_TmpFileName != "") { -#ifndef WNT +#ifndef WIN32 string command = "rm "; #else string command = "del /F "; @@ -1043,23 +1075,13 @@ void SALOME_ContainerManager::AddOmninamesParams(ofstream& fileStream) const string SALOME_ContainerManager::BuildTemporaryFileName() const { //build more complex file name to support multiple salome session - char *temp = new char[19]; - strcpy(temp, "/tmp/command"); - strcat(temp, "XXXXXX"); -#ifndef WNT - - mkstemp(temp); + string aFileName = Kernel_Utils::GetTmpFileName(); +#ifndef WIN32 + aFileName += ".sh"; #else - - char aPID[80]; - itoa(getpid(), aPID, 10); - strcat(temp, aPID); + aFileName += ".bat"; #endif - - string command(temp); - delete [] temp; - command += ".sh"; - return command; + return aFileName; } @@ -1138,7 +1160,9 @@ SALOME_ContainerManager::BuildTempFileToLaunchRemoteContainer tempOutputFile << " &" << endl; tempOutputFile.flush(); tempOutputFile.close(); +#ifndef WIN32 chmod(_TmpFileName.c_str(), 0x1ED); +#endif // --- Build command @@ -1279,7 +1303,7 @@ SALOME_ContainerManager::BuildCommandToLaunchLocalParallelContainer(const std::s command += " > /tmp/"; command += _NS->ContainerName(rtn); command += "_"; - command += GetHostname(); + command += Kernel_Utils::GetHostname(); command += "_"; command += getenv( "USER" ) ; command += ".log 2>&1 &" ; diff --git a/src/Container/SALOME_Container_i.hxx b/src/Container/SALOME_Container_i.hxx index 153b381f8..d9743a75b 100644 --- a/src/Container/SALOME_Container_i.hxx +++ b/src/Container/SALOME_Container_i.hxx @@ -37,7 +37,7 @@ #include #include #include -#ifndef WNT +#ifndef WIN32 #include #endif #include diff --git a/src/Container/SALOME_FileRef_i.cxx b/src/Container/SALOME_FileRef_i.cxx index 3fda8667f..b644795fb 100644 --- a/src/Container/SALOME_FileRef_i.cxx +++ b/src/Container/SALOME_FileRef_i.cxx @@ -25,7 +25,7 @@ #include "SALOME_FileRef_i.hxx" #include "utilities.h" -#include "OpUtil.hxx" +#include "Basics_Utils.hxx" #include using namespace std; @@ -52,7 +52,7 @@ fileRef_i::fileRef_i(Engines::Container_ptr container, MESSAGE("fileRef_i::fileRef_i "<< origFileName); _container = Engines::Container::_duplicate(container); _origFileName = origFileName; - _machine = GetHostname(); + _machine = Kernel_Utils::GetHostname(); #if defined(_DEBUG_) || defined(_DEBUG) int OK = addRef(_machine.c_str(), _origFileName.c_str()); SCRUTE(OK); diff --git a/src/Container/Salome_file_i.cxx b/src/Container/Salome_file_i.cxx index 89aae57db..962a9ad81 100644 --- a/src/Container/Salome_file_i.cxx +++ b/src/Container/Salome_file_i.cxx @@ -26,9 +26,17 @@ #include "Salome_file_i.hxx" #include "utilities.h" #include -#include #include "HDFOI.hxx" -#include +#ifndef WIN32 +# include +# define _getcwd getcwd +# define _open open +#else +# include +# include +# include +#endif + //============================================================================= /*! @@ -39,7 +47,14 @@ Salome_file_i::Salome_file_i() { _fileId = 0; +#ifndef WIN32 _path_max = 1 + pathconf("/", _PC_PATH_MAX); +#else + _path_max = 32768; + //from MSDN: + //Note The C Runtime supports path lengths up to 32768 characters in length, but it is up to the operating system, specifically the file system, to support these longer paths. The sum of the fields should not exceed _MAX_PATH for full backwards compatibility with Windows 98 FAT32 file systems. Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003, and Windows Server 2003 NTFS file system supports paths up to 32768 characters in length, but only when using the Unicode APIs. When using long path names, prefix the path with the characters \\?\ and use the Unicode versions of the C Runtime functions. + //currently #define _MAX_PATH 260 +#endif _state.name = CORBA::string_dup(""); _state.hdf5_file_name = CORBA::string_dup(""); _state.number_of_files = 0; @@ -155,10 +170,8 @@ Salome_file_i::load(const char* hdf5_file) { if (mode == "all") { // Changing path, is now current directory - char CurrentPath[_path_max]; - getcwd(CurrentPath, _path_max); - path = CurrentPath; - + path = getcwd(NULL, _path_max); + std::string group_name("GROUP"); group_name += file_name; hdf_group = new HDFgroup(group_name.c_str(),hdf_file); @@ -491,10 +504,8 @@ Salome_file_i::setLocalFile(const char* comp_file_name) } else { - file_name = comp_file_name; - char CurrentPath[_path_max]; - getcwd(CurrentPath, _path_max); - path = CurrentPath; + file_name = comp_file_name; + path = getcwd(NULL, _path_max);; } // Test if this file is already added @@ -556,9 +567,7 @@ Salome_file_i::setDistributedFile(const char* comp_file_name) else { file_name = comp_file_name; - char CurrentPath[_path_max]; - getcwd(CurrentPath, _path_max); - path = CurrentPath; + path = getcwd(NULL, _path_max);; } // Test if this file is already added diff --git a/src/DF/DF_definitions.hxx b/src/DF/DF_definitions.hxx index 3cfe5585d..a9dd7eaa4 100644 --- a/src/DF/DF_definitions.hxx +++ b/src/DF/DF_definitions.hxx @@ -68,7 +68,7 @@ public: }; -# if defined(WNT) && !defined(HAVE_NO_DLL) +# if defined(WIN32) && !defined(HAVE_NO_DLL) # ifndef Standard_EXPORT # define Standard_EXPORT __declspec( dllexport ) @@ -82,7 +82,7 @@ public: # define Standard_IMPORTC extern "C" __declspec( dllimport ) # endif /* Standard_IMPORT */ -# else /* WNT */ +# else /* WIN32 */ # ifndef Standard_EXPORT # define Standard_EXPORT @@ -96,11 +96,11 @@ public: # define Standard_IMPORTC extern "C" # endif /* Standard_IMPORT */ -# endif /* WNT */ +# endif /* WIN32 */ # ifndef __Standard_API -//# ifdef WNT -# if !defined(WNT) +//# ifdef WIN32 +# if !defined(WIN32) # define __Standard_API Standard_EXPORT # define __Standard_APIEXTERN Standard_EXPORTEXTERN # else @@ -109,7 +109,7 @@ public: # endif // __Standard_DLL //# else //# define __Standard_API -//# endif // WNT +//# endif // WIN32 # endif // __Standard_API #include diff --git a/src/DF/testDF.cxx b/src/DF/testDF.cxx index ee457316f..b6148e4b9 100644 --- a/src/DF/testDF.cxx +++ b/src/DF/testDF.cxx @@ -33,7 +33,7 @@ #include "DF_Container.hxx" #include "DF_ChildIterator.hxx" -#ifndef WNT +#ifndef WIN32 #include #include #include @@ -52,7 +52,7 @@ void printStr(const string& theValue) void GetSystemDate(int& year, int& month, int& day, int& hours, int& minutes, int& seconds) { -#ifdef WNT +#ifdef WIN32 SYSTEMTIME st; GetLocalTime ( &st ); @@ -83,7 +83,7 @@ void GetSystemDate(int& year, int& month, int& day, int& hours, int& minutes, in string GetUserName() { -#ifdef WNT +#ifdef WIN32 char* pBuff = new char[UNLEN + 1]; DWORD dwSize = UNLEN + 1; string retVal; @@ -128,7 +128,7 @@ string GetDirFromPath(const string& thePath) { path = thePath+"/"; } -#ifdef WNT //Check if the only disk letter is given as path +#ifdef WIN32 //Check if the only disk letter is given as path if(path.size() == 2 && path[1] == ":") path +='\\'; #endif @@ -140,7 +140,7 @@ string GetDirFromPath(const string& thePath) { bool Exists(const string thePath) { -#ifdef WNT +#ifdef WIN32 if ( GetFileAttributes ( thePath.c_str() ) == 0xFFFFFFFF ) { if ( GetLastError () != ERROR_FILE_NOT_FOUND ) { return false; diff --git a/src/DSC/DSC_Basic/ConnectionManager_i.cxx b/src/DSC/DSC_Basic/ConnectionManager_i.cxx index 2f7f089c9..d023cf6e3 100644 --- a/src/DSC/DSC_Basic/ConnectionManager_i.cxx +++ b/src/DSC/DSC_Basic/ConnectionManager_i.cxx @@ -26,6 +26,10 @@ #include "ConnectionManager_i.hxx" #include "SALOME_NamingService.hxx" +#ifdef WIN32 +# include +#endif + ConnectionManager_i::ConnectionManager_i(CORBA::ORB_ptr orb) { _orb = CORBA::ORB::_duplicate(orb) ; SALOME_NamingService * ns = new SALOME_NamingService(orb); @@ -126,5 +130,10 @@ ConnectionManager_i::ShutdownWithExit() CORBA::Long ConnectionManager_i::getPID() { - return (CORBA::Long)getpid(); + return +#ifndef WIN32 + (CORBA::Long)getpid(); +#else + (CORBA::Long)_getpid(); +#endif } diff --git a/src/DSC/DSC_Basic/DSC_Basic.hxx b/src/DSC/DSC_Basic/DSC_Basic.hxx index 0efc1a2e2..b06f5d075 100755 --- a/src/DSC/DSC_Basic/DSC_Basic.hxx +++ b/src/DSC/DSC_Basic/DSC_Basic.hxx @@ -26,22 +26,14 @@ #ifndef _DSC_Basic_HXX_ #define _DSC_Basic_HXX_ -#ifdef WNT - #if defined DSC_BASIC_EXPORTS - #if defined WIN32 - #define DSC_BASIC_EXPORT __declspec( dllexport ) - #else - #define DSC_BASIC_EXPORT - #endif - #else - #if defined WIN32 - #define DSC_BASIC_EXPORT __declspec( dllimport ) - #else - #define DSC_BASIC_EXPORT - #endif - #endif +#ifdef WIN32 +# ifdef DSC_BASIC_EXPORTS +# define DSC_BASIC_EXPORT __declspec( dllexport ) +# else +# define DSC_BASIC_EXPORT __declspec( dllimport ) +# endif #else - #define DSC_BASIC_EXPORT +# define DSC_BASIC_EXPORT #endif #endif -- 2.39.2