From ff694e726fa6e6caaae539185539439a1ede2f40 Mon Sep 17 00:00:00 2001 From: ribes Date: Mon, 24 Sep 2007 13:52:40 +0000 Subject: [PATCH] - Fix warning for SALOME_Registry - Parallel_Salome_file ok, needs some more tests --- idl/SALOME_Component.xml | 8 +- .../Parallel_Salome_file_i.cxx | 23 +- .../Parallel_Salome_file_i.hxx | 2 +- .../SALOME_ParallelComponent_i.cxx | 249 ++++++++++++------ .../SALOME_ParallelContainerNodeDummy.cxx | 52 +++- src/Registry/SALOME_Registry.hxx | 3 +- 6 files changed, 241 insertions(+), 96 deletions(-) diff --git a/idl/SALOME_Component.xml b/idl/SALOME_Component.xml index 189f18638..850f18a07 100644 --- a/idl/SALOME_Component.xml +++ b/idl/SALOME_Component.xml @@ -50,6 +50,10 @@ setInputServiceSalome_file distributed + + setOutputServiceSalome_file + distributed + Parallel_Component @@ -60,10 +64,6 @@ Salome_file - - recvFiles - distributed - Parallel_Salome_file diff --git a/src/ParallelContainer/Parallel_Salome_file_i.cxx b/src/ParallelContainer/Parallel_Salome_file_i.cxx index 440a0b455..19cecbb25 100644 --- a/src/ParallelContainer/Parallel_Salome_file_i.cxx +++ b/src/ParallelContainer/Parallel_Salome_file_i.cxx @@ -26,7 +26,7 @@ #include "Parallel_Salome_file_i.hxx" #include "utilities.h" -Parallel_Salome_file_i::Parallel_Salome_file_i(CORBA::ORB_ptr orb, char * ior) : +Parallel_Salome_file_i::Parallel_Salome_file_i(CORBA::ORB_ptr orb, const char * ior) : InterfaceParallel_impl(orb,ior), Engines::Salome_file_serv(orb,ior), Engines::fileTransfer_serv(orb,ior), @@ -120,7 +120,7 @@ Parallel_Salome_file_i::recvFiles() { int total = getTotalNode(); for (int i =0; irecvFiles_node(i); + parallel_file->recvFiles_node(i); } catch (SALOME::SALOME_Exception & ex) { files_not_ok = files_not_ok + std::string(ex.details.text.in()); @@ -200,6 +200,7 @@ Parallel_Salome_file_i::getParallelDistributedFile(std::string file_name) { int fileId; FILE* fp; std::string comp_file_name(_fileManaged[file_name].path.in()); + comp_file_name.append("/"); comp_file_name.append(_fileManaged[file_name].file_name.in()); // Test if the process can write on disk @@ -320,6 +321,24 @@ Parallel_Salome_file_i::getFileNode(const char* file_name) { // Test if this file is managed std::string fname(file_name); + if (fname == "") { + // We enter in the simple case where the user + // has not used setDistributedSourceFile. + // In this case we try to see if the Salome_file + if (_fileManaged.size() == 1) + { + // only one file managed + _t_fileManaged::iterator it = _fileManaged.begin(); + fname = it->first; + } + else + { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "Error : there is more than one file that is managed"; + throw SALOME::SALOME_Exception(es); + } + } _t_fileManaged::iterator it = _fileManaged.find(fname); if (it == _fileManaged.end()) { diff --git a/src/ParallelContainer/Parallel_Salome_file_i.hxx b/src/ParallelContainer/Parallel_Salome_file_i.hxx index f2847b824..c3814a5c4 100644 --- a/src/ParallelContainer/Parallel_Salome_file_i.hxx +++ b/src/ParallelContainer/Parallel_Salome_file_i.hxx @@ -39,7 +39,7 @@ class CONTAINER_EXPORT Parallel_Salome_file_i: public virtual Engines::Parallel_Salome_file_serv { public: - Parallel_Salome_file_i(CORBA::ORB_ptr orb, char * ior); + Parallel_Salome_file_i(CORBA::ORB_ptr orb, const char * ior); virtual ~Parallel_Salome_file_i(); virtual void setFileNode(const char* file_name, CORBA::Long node); diff --git a/src/ParallelContainer/SALOME_ParallelComponent_i.cxx b/src/ParallelContainer/SALOME_ParallelComponent_i.cxx index 3a6002cb7..245a6f791 100644 --- a/src/ParallelContainer/SALOME_ParallelComponent_i.cxx +++ b/src/ParallelContainer/SALOME_ParallelComponent_i.cxx @@ -771,10 +771,10 @@ string Engines_Parallel_Component_i::GetDynLibraryName(const char *componentName //============================================================================= Engines::TMPFile* Engines_Parallel_Component_i::DumpPython(CORBA::Object_ptr theStudy, - CORBA::Boolean isPublished, - CORBA::Boolean& isValidScript) + CORBA::Boolean isPublished, + CORBA::Boolean& isValidScript) { - char* aScript = "def RebuildData(theStudy): pass"; + const char* aScript = "def RebuildData(theStudy): pass"; char* aBuffer = new char[strlen(aScript)+1]; strcpy(aBuffer, aScript); CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer; @@ -784,38 +784,10 @@ Engines::TMPFile* Engines_Parallel_Component_i::DumpPython(CORBA::Object_ptr the return aStreamFile._retn(); } -// This is a parallel method -Engines::Salome_file_ptr -Engines_Parallel_Component_i::getInputServiceSalome_file(const char* service_name, - const char* Salome_file_name) -{ - // Try to find the service, if it doesn't exist, we throw an exception. - _Proxy_Service_file_map_it = _Proxy_Input_Service_file_map.find(service_name); - if (_Proxy_Service_file_map_it == _Proxy_Input_Service_file_map.end()) { - SALOME::ExceptionStruct es; - es.type = SALOME::INTERNAL_ERROR; - es.text = "service doesn't have salome files"; - throw SALOME::SALOME_Exception(es); - } - _t_Proxy_Salome_file_map * _map = _Proxy_Input_Service_file_map[service_name]; - - // Try to find the Salome_file ... - _Proxy_Salome_file_map_it = _map->find(Salome_file_name); - if (_Proxy_Salome_file_map_it == _map->end()) { - SALOME::ExceptionStruct es; - es.type = SALOME::INTERNAL_ERROR; - es.text = "service doesn't have this Salome_file"; - throw SALOME::SALOME_Exception(es); - } - - // Client get the proxy object - Engines::Parallel_Salome_file_proxy_impl * Sfile = (*_map)[Salome_file_name]; - return Sfile->_this(); -} Engines::Salome_file_ptr Engines_Parallel_Component_i::setInputFileToService(const char* service_name, - const char* Salome_file_name) + const char* Salome_file_name) { // Try to find the service, if it doesn't exist, we add it. _Service_file_map_it = _Input_Service_file_map.find(service_name); @@ -828,7 +800,7 @@ Engines_Parallel_Component_i::setInputFileToService(const char* service_name, _t_Salome_file_map * _map = _Input_Service_file_map[service_name]; _t_Proxy_Salome_file_map * _proxy_map = _Proxy_Input_Service_file_map[service_name]; - char * proxy_ior; + std::string proxy_ior; // Try to find the Salome_file ... _Salome_file_map_it = _map->find(Salome_file_name); @@ -855,9 +827,9 @@ Engines_Parallel_Component_i::setInputFileToService(const char* service_name, proxy->setTopo(serveur_topo); // We initialize the object with the context of the Parallel component - PaCO_operation * compo_global_ptr = this->getContext("global_paco_context"); - compo_global_ptr->init_context(proxy_global_ptr); - + PaCO_operation * compo_global_ptr = getContext("global_paco_context"); + //compo_global_ptr->init_context(proxy_global_ptr); + proxy_global_ptr->init_context(compo_global_ptr); // We register the CORBA objet into the POA CORBA::Object_ptr proxy_ref = proxy->_this(); @@ -880,12 +852,13 @@ Engines_Parallel_Component_i::setInputFileToService(const char* service_name, for (int i = 0; i < getTotalNode(); i++) { if (i == getMyRank()) { Parallel_Salome_file_i * servant = - new Parallel_Salome_file_i(CORBA::ORB::_duplicate(_orb), proxy_ior); + new Parallel_Salome_file_i(CORBA::ORB::_duplicate(_orb), proxy_ior.c_str()); PaCO_operation * servant_global_ptr = servant->getContext("global_paco_context"); // We initialize the object with the context of the Parallel component PaCO_operation * compo_global_ptr = this->getContext("global_paco_context"); - compo_global_ptr->init_context(servant_global_ptr); +// compo_global_ptr->init_context(servant_global_ptr); + servant_global_ptr->init_context(compo_global_ptr); // We register the CORBA objet into the POA servant->POA_PaCO::InterfaceParallel::_this(); @@ -900,6 +873,7 @@ Engines_Parallel_Component_i::setInputFileToService(const char* service_name, PaCO_operation * compo_global_ptr = this->getContext("global_paco_context"); compo_global_ptr->my_com->paco_barrier(); } + // Parallel_Salome_file is created and deployed delete _proxy; _proxy = NULL; @@ -914,102 +888,203 @@ Engines_Parallel_Component_i::setInputFileToService(const char* service_name, throw SALOME::SALOME_Exception(es); } - CORBA::Object_ptr obj = _orb->string_to_object(proxy_ior); + CORBA::Object_ptr obj = _orb->string_to_object(proxy_ior.c_str()); return Engines::Salome_file::_narrow(obj); } -void -Engines_Parallel_Component_i::checkInputServiceFiles(const char* service_name) +Engines::Salome_file_ptr +Engines_Parallel_Component_i::setOutputFileToService(const char* service_name, + const char* Salome_file_name) { - // Try to find the service, if it doesn't exist, nothing to do. - _Proxy_Service_file_map_it = _Proxy_Input_Service_file_map.find(service_name); - if (_Proxy_Service_file_map_it != _Proxy_Input_Service_file_map.end()) { - _t_Proxy_Salome_file_map * _proxy_map = _Proxy_Input_Service_file_map[service_name]; - _t_Proxy_Salome_file_map::iterator begin = _proxy_map->begin(); - _t_Proxy_Salome_file_map::iterator end = _proxy_map->end(); + // Try to find the service, if it doesn't exist, we add it. + _Service_file_map_it = _Output_Service_file_map.find(service_name); + if (_Service_file_map_it == _Output_Service_file_map.end()) { + _t_Salome_file_map * _map = new _t_Salome_file_map(); + _Output_Service_file_map[service_name] = _map; + _t_Proxy_Salome_file_map * _proxy_map = new _t_Proxy_Salome_file_map(); + _Proxy_Output_Service_file_map[service_name] = _proxy_map; + } + _t_Salome_file_map * _map = _Output_Service_file_map[service_name]; + _t_Proxy_Salome_file_map * _proxy_map = _Proxy_Output_Service_file_map[service_name]; + + std::string proxy_ior; - for(;begin!=end;begin++) { - Engines::Parallel_Salome_file_proxy_impl * file = begin->second; - file->recvFiles(); + // Try to find the Salome_file ... + _Salome_file_map_it = _map->find(Salome_file_name); + if (_Salome_file_map_it == _map->end()) { + + // We create a new PaCO++ object. + // He has the same configuration than + // his component + + pthread_mutex_lock(deploy_mutex); + // Firstly, we have to create the proxy object + // of the Salome_file and transmit his + // reference to the other nodes. + if (getMyRank() == 0) { + Engines::Parallel_Salome_file_proxy_impl * proxy = + new Engines::Parallel_Salome_file_proxy_impl(CORBA::ORB::_duplicate(_orb)); + PaCO_operation * proxy_global_ptr = proxy->getContext("global_paco_context"); + proxy_global_ptr->setTypeClient(true); + PaCO::PacoTopology_t client_topo; + client_topo.total = 1; + proxy_global_ptr->setClientTopo(client_topo); + PaCO::PacoTopology_t serveur_topo; + serveur_topo.total = getTotalNode(); + proxy->setTopo(serveur_topo); + + // We initialize the object with the context of the Parallel component + PaCO_operation * compo_global_ptr = getContext("global_paco_context"); + //compo_global_ptr->init_context(proxy_global_ptr); + proxy_global_ptr->init_context(compo_global_ptr); + // We register the CORBA objet into the POA + CORBA::Object_ptr proxy_ref = proxy->_this(); + + // We send the reference to all the nodes... + CORBA::Object_ptr comp_proxy = _orb->string_to_object(_ior.c_str()); + Engines::Parallel_Component_var component_proxy = Engines::Parallel_Component::_narrow(comp_proxy); + component_proxy->send_parallel_proxy_object(proxy_ref); + + // Adding proxy into the map + (*_proxy_map)[Salome_file_name] = proxy; } + else { + this->wait_parallel_object_proxy(); + } + + proxy_ior = this->get_parallel_proxy_object(); + + // We register each node of the parallel Salome_file object + // into the proxy. + for (int i = 0; i < getTotalNode(); i++) { + if (i == getMyRank()) { + Parallel_Salome_file_i * servant = + new Parallel_Salome_file_i(CORBA::ORB::_duplicate(_orb), proxy_ior.c_str()); + PaCO_operation * servant_global_ptr = servant->getContext("global_paco_context"); + + // We initialize the object with the context of the Parallel component + PaCO_operation * compo_global_ptr = this->getContext("global_paco_context"); +// compo_global_ptr->init_context(servant_global_ptr); + servant_global_ptr->init_context(compo_global_ptr); + + // We register the CORBA objet into the POA + servant->POA_PaCO::InterfaceParallel::_this(); + + // Register the servant + servant->deploy(getMyRank()); + + // Adding servant to the map + (*_map)[Salome_file_name] = servant; + } + + PaCO_operation * compo_global_ptr = this->getContext("global_paco_context"); + compo_global_ptr->my_com->paco_barrier(); + } + + // Parallel_Salome_file is created and deployed + delete _proxy; + _proxy = NULL; + pthread_mutex_unlock(deploy_mutex); } + else { + // Salome_file_name already added into the service + // throw Exception + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "Salome_file_name already added"; + throw SALOME::SALOME_Exception(es); + } + + CORBA::Object_ptr obj = _orb->string_to_object(proxy_ior.c_str()); + return Engines::Salome_file::_narrow(obj); } Engines::Salome_file_ptr -Engines_Parallel_Component_i::getOutputServiceSalome_file(const char* service_name, +Engines_Parallel_Component_i::getInputServiceSalome_file(const char* service_name, const char* Salome_file_name) { // Try to find the service, if it doesn't exist, we throw an exception. - _Service_file_map_it = _Output_Service_file_map.find(service_name); - if (_Service_file_map_it == _Output_Service_file_map.end()) { + _Proxy_Service_file_map_it = _Proxy_Input_Service_file_map.find(service_name); + if (_Proxy_Service_file_map_it == _Proxy_Input_Service_file_map.end()) { SALOME::ExceptionStruct es; es.type = SALOME::INTERNAL_ERROR; es.text = "service doesn't have salome files"; throw SALOME::SALOME_Exception(es); } - _t_Salome_file_map * _map = _Output_Service_file_map[service_name]; + _t_Proxy_Salome_file_map * _map = _Proxy_Input_Service_file_map[service_name]; // Try to find the Salome_file ... - _Salome_file_map_it = _map->find(Salome_file_name); - if (_Salome_file_map_it == _map->end()) { + _Proxy_Salome_file_map_it = _map->find(Salome_file_name); + if (_Proxy_Salome_file_map_it == _map->end()) { SALOME::ExceptionStruct es; es.type = SALOME::INTERNAL_ERROR; es.text = "service doesn't have this Salome_file"; throw SALOME::SALOME_Exception(es); } - Salome_file_i * Sfile = (*_map)[Salome_file_name]; + // Client get the proxy object + Engines::Parallel_Salome_file_proxy_impl * Sfile = (*_map)[Salome_file_name]; return Sfile->_this(); } Engines::Salome_file_ptr -Engines_Parallel_Component_i::setOutputFileToService(const char* service_name, - const char* Salome_file_name) +Engines_Parallel_Component_i::getOutputServiceSalome_file(const char* service_name, + const char* Salome_file_name) { - // Try to find the service, if it doesn't exist, we add it. - _Service_file_map_it = _Output_Service_file_map.find(service_name); - if (_Service_file_map_it == _Output_Service_file_map.end()) { - _t_Salome_file_map * _map = new _t_Salome_file_map(); - _Output_Service_file_map[service_name] = _map; + // Try to find the service, if it doesn't exist, we throw an exception. + _Proxy_Service_file_map_it = _Proxy_Output_Service_file_map.find(service_name); + if (_Proxy_Service_file_map_it == _Proxy_Output_Service_file_map.end()) { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "service doesn't have salome files"; + throw SALOME::SALOME_Exception(es); } - _t_Salome_file_map * _map = _Output_Service_file_map[service_name]; - + _t_Proxy_Salome_file_map * _map = _Proxy_Output_Service_file_map[service_name]; + // Try to find the Salome_file ... - _Salome_file_map_it = _map->find(Salome_file_name); - if (_Salome_file_map_it == _map->end()) { -// Salome_file_i * Sfile = new Salome_file_i(); -// (*_map)[Salome_file_name] = Sfile; -// -// -// -// TODO -// - } - else { - // Salome_file_name already added into the service - // throw Exception + _Proxy_Salome_file_map_it = _map->find(Salome_file_name); + if (_Proxy_Salome_file_map_it == _map->end()) { SALOME::ExceptionStruct es; es.type = SALOME::INTERNAL_ERROR; - es.text = "Salome_file_name already added"; + es.text = "service doesn't have this Salome_file"; throw SALOME::SALOME_Exception(es); } - Salome_file_i * Sfile = (*_map)[Salome_file_name]; + // Client get the proxy object + Engines::Parallel_Salome_file_proxy_impl * Sfile = (*_map)[Salome_file_name]; return Sfile->_this(); } + +void +Engines_Parallel_Component_i::checkInputServiceFiles(const char* service_name) +{ + // Try to find the service, if it doesn't exist, nothing to do. + _Proxy_Service_file_map_it = _Proxy_Input_Service_file_map.find(service_name); + if (_Proxy_Service_file_map_it != _Proxy_Input_Service_file_map.end()) { + _t_Proxy_Salome_file_map * _proxy_map = _Proxy_Input_Service_file_map[service_name]; + _t_Proxy_Salome_file_map::iterator begin = _proxy_map->begin(); + _t_Proxy_Salome_file_map::iterator end = _proxy_map->end(); + + for(;begin!=end;begin++) { + Engines::Parallel_Salome_file_proxy_impl * file = begin->second; + file->recvFiles(); + } + } +} + void Engines_Parallel_Component_i::checkOutputServiceFiles(const char* service_name) { // Try to find the service, if it doesn't exist, nothing to do. - _Service_file_map_it = _Output_Service_file_map.find(service_name); - if (_Service_file_map_it != _Output_Service_file_map.end()) { - _t_Salome_file_map * _map = _Output_Service_file_map[service_name]; - _t_Salome_file_map::iterator begin = _map->begin(); - _t_Salome_file_map::iterator end = _map->end(); + _Proxy_Service_file_map_it = _Proxy_Output_Service_file_map.find(service_name); + if (_Proxy_Service_file_map_it != _Proxy_Output_Service_file_map.end()) { + _t_Proxy_Salome_file_map * _map = _Proxy_Output_Service_file_map[service_name]; + _t_Proxy_Salome_file_map::iterator begin = _map->begin(); + _t_Proxy_Salome_file_map::iterator end = _map->end(); for(;begin!=end;begin++) { - Salome_file_i * file = begin->second; + Engines::Parallel_Salome_file_proxy_impl * file = begin->second; file->recvFiles(); } } diff --git a/src/ParallelContainer/SALOME_ParallelContainerNodeDummy.cxx b/src/ParallelContainer/SALOME_ParallelContainerNodeDummy.cxx index f08a384c7..4f5d0d274 100644 --- a/src/ParallelContainer/SALOME_ParallelContainerNodeDummy.cxx +++ b/src/ParallelContainer/SALOME_ParallelContainerNodeDummy.cxx @@ -63,13 +63,63 @@ void handler(int t) { } #endif +typedef void (*sighandler_t)(int); +sighandler_t setsig(int sig, sighandler_t handler) +{ + struct sigaction context, ocontext; + context.sa_handler = handler; + sigemptyset(&context.sa_mask); + context.sa_flags = 0; + if (sigaction(sig, &context, &ocontext) == -1) + return SIG_ERR; + return ocontext.sa_handler; +} + +void AttachDebugger() +{ + if(getenv ("DEBUGGER")) + { + std::stringstream exec; + exec << "$DEBUGGER SALOME_ParallelContainerNodeDummy " << getpid() << "&"; + std::cerr << exec.str() << std::endl; + system(exec.str().c_str()); + while(1); + } +} + +void Handler(int theSigId) +{ + std::cerr << "SIGSEGV: " << std::endl; + AttachDebugger(); + //to exit or not to exit + exit(1); +} + +void terminateHandler(void) +{ + std::cerr << "Terminate: not managed exception !" << std::endl; + AttachDebugger(); +} + +void unexpectedHandler(void) +{ + std::cerr << "Unexpected: unexpected exception !" << std::endl; + AttachDebugger(); +} + int main(int argc, char* argv[]) { INFOS("Launching a parallel container node"); #ifdef _DEBUG_ - signal(SIGSEGV, handler); +// signal(SIGSEGV, handler); #endif + if(getenv ("DEBUGGER")) + { + setsig(SIGSEGV,&Handler); + set_terminate(&terminateHandler); + set_unexpected(&unexpectedHandler); + } // Initialise the ORB. ORB_INIT &init = *SINGLETON_::Instance(); diff --git a/src/Registry/SALOME_Registry.hxx b/src/Registry/SALOME_Registry.hxx index 899bc5586..4ca01a2c7 100755 --- a/src/Registry/SALOME_Registry.hxx +++ b/src/Registry/SALOME_Registry.hxx @@ -44,4 +44,5 @@ #define REGISTRY_EXPORT #endif -#endif \ No newline at end of file +#endif + -- 2.39.2