From 4e8541b5fac02f2a31f4694b919a61c639e52d82 Mon Sep 17 00:00:00 2001 From: ribes Date: Wed, 28 Jul 2010 16:33:55 +0000 Subject: [PATCH] - Major update for launcher: - some bugs are fixed - save and load methods - can have observers --- idl/SALOME_ContainerManager.idl | 2 +- src/Launcher/Launcher.cxx | 6 +- src/Launcher/Launcher.hxx | 2 + src/Launcher/SALOME_Launcher.cxx | 86 ++++++++++++++++--- src/Launcher/SALOME_Launcher.hxx | 7 ++ .../SALOME_ResourcesManager.cxx | 4 +- 6 files changed, 88 insertions(+), 19 deletions(-) diff --git a/idl/SALOME_ContainerManager.idl b/idl/SALOME_ContainerManager.idl index 0392c3af5..364568b03 100644 --- a/idl/SALOME_ContainerManager.idl +++ b/idl/SALOME_ContainerManager.idl @@ -195,7 +195,7 @@ typedef sequence JobsList; interface SalomeLauncherObserver { - void notifyObserver(in string event_name, in string event_data); + void notify(in string event_name, in string event_data); }; /*! \brief Interface of the %salomelauncher diff --git a/src/Launcher/Launcher.cxx b/src/Launcher/Launcher.cxx index c169487a2..06e922aee 100644 --- a/src/Launcher/Launcher.cxx +++ b/src/Launcher/Launcher.cxx @@ -62,12 +62,12 @@ Launcher_cpp::~Launcher_cpp() { LAUNCHER_MESSAGE("Launcher_cpp destructor"); #ifdef WITH_LIBBATCH - std::map < std::string, Batch::BatchManager_eClient * >::const_iterator it1; - for(it1=_batchmap.begin();it1!=_batchmap.end();it1++) - delete it1->second; std::map::const_iterator it_job; for(it_job = _launcher_job_map.begin(); it_job != _launcher_job_map.end(); it_job++) delete it_job->second; + std::map < std::string, Batch::BatchManager_eClient * >::const_iterator it1; + for(it1=_batchmap.begin();it1!=_batchmap.end();it1++) + delete it1->second; #endif pthread_mutex_destroy(_job_cpt_mutex); diff --git a/src/Launcher/Launcher.hxx b/src/Launcher/Launcher.hxx index eeed0d000..662112034 100644 --- a/src/Launcher/Launcher.hxx +++ b/src/Launcher/Launcher.hxx @@ -75,6 +75,8 @@ public: protected: + virtual void notifyObservers(const std::string & event_name, const std::string & event_data) {} + // Methods used by user interface methods #ifdef WITH_LIBBATCH Batch::BatchManager_eClient *FactoryBatchManager(ParserResourcesType& params); diff --git a/src/Launcher/SALOME_Launcher.cxx b/src/Launcher/SALOME_Launcher.cxx index 5b799f44e..1195c2b6a 100644 --- a/src/Launcher/SALOME_Launcher.cxx +++ b/src/Launcher/SALOME_Launcher.cxx @@ -104,6 +104,9 @@ SALOME_Launcher::createJob(const Engines::JobParameters & job_parameters) new_job = new Launcher::Job_YACSFile(); else if (job_type == "python_salome") new_job = new Launcher::Job_PythonSALOME(); + + // Name + new_job->setJobName(job_parameters.job_name.in()); // Directories std::string work_directory = job_parameters.work_directory.in(); @@ -170,6 +173,9 @@ SALOME_Launcher::createJob(const Engines::JobParameters & job_parameters) try { _l.createJob(new_job); + std::ostringstream job_id; + job_id << new_job->getNumber(); + notifyObservers("NEW_JOB", job_id.str()); } catch(const LauncherException &ex) { @@ -229,6 +235,9 @@ SALOME_Launcher::removeJob(CORBA::Long job_id) try { _l.removeJob(job_id); + std::ostringstream job_id_str; + job_id_str << job_id; + notifyObservers("REMOVE_JOB", job_id_str.str()); } catch(const LauncherException &ex) { @@ -327,16 +336,6 @@ CORBA::Long SALOME_Launcher::getPID() #endif } -//============================================================================= -/*! CORBA Method: - * Add a new observer to the launcher - */ -//============================================================================= -void -SALOME_Launcher::addObserver(Engines::SalomeLauncherObserver_ptr observer) -{ -} - //============================================================================= /*! CORBA Method: * Returns current launcher jobs list @@ -752,14 +751,17 @@ SALOME_Launcher::loadJobs(const char* jobs_file) xmlFree(job_state_xml); xmlFree(resource_choosed_name_xml); xmlFree(job_reference_xml); - - // TODO: EVENT for observer ! + if (job_state == "CREATED") { // In this case, we ignore run_part informations try { _l.createJob(new_job); + + std::ostringstream job_id; + job_id << new_job->getNumber(); + notifyObservers("NEW_JOB", job_id.str()); } catch(const LauncherException &ex) { @@ -792,6 +794,10 @@ SALOME_Launcher::loadJobs(const char* jobs_file) INFOS("BatchManager type cannot resume a job - job state is set to ERROR"); new_job->setState("ERROR"); } + + std::ostringstream job_id; + job_id << new_job->getNumber(); + notifyObservers("NEW_JOB", job_id.str()); } catch(const LauncherException &ex) { @@ -816,6 +822,10 @@ SALOME_Launcher::loadJobs(const char* jobs_file) resource_definition.Name = resource_choosed_name; new_job->setResourceDefinition(resource_definition); _l.addJobDirectlyToMap(new_job, job_reference); + + std::ostringstream job_id; + job_id << new_job->getNumber(); + notifyObservers("NEW_JOB", job_id.str()); } catch(const LauncherException &ex) { @@ -845,6 +855,7 @@ SALOME_Launcher::loadJobs(const char* jobs_file) // Clean xmlFreeDoc(doc); fclose(xml_file); + notifyObservers("LOAD_JOBS", jobs_file); } //============================================================================= @@ -897,5 +908,54 @@ SALOME_Launcher::saveJobs(const char* jobs_file) xmlFreeDoc(doc); fclose(xml_file); MESSAGE("SALOME_Launcher::saveJobs : WRITING DONE!"); - //TODO: Generation evenement pour les observeurs + notifyObservers("SAVE_JOBS", jobs_file); +} + +//============================================================================= +/*! CORBA Method: + * Add a new observer to the launcher + */ +//============================================================================= +void +SALOME_Launcher::addObserver(Engines::SalomeLauncherObserver_ptr observer) +{ + bool new_observer = true; + std::list::iterator iter = _observers.begin(); + while(iter != _observers.end()) + { + if (std::string(_orb->object_to_string(*iter)) == + std::string(_orb->object_to_string(observer))) + { + new_observer = false; + break; + } + } + if (new_observer) + _observers.push_back(Engines::SalomeLauncherObserver::_duplicate(observer)); +} + +//============================================================================= +/*! Internal Method: + * Notify observers on a new event + */ +//============================================================================= +void +SALOME_Launcher::notifyObservers(const std::string & event_name, + const std::string & event_data) +{ + std::list::iterator iter = _observers.begin(); + while(iter != _observers.end()) + { + try + { + (*iter)->notify(CORBA::string_dup(event_name.c_str()), + CORBA::string_dup(event_data.c_str())); + } + catch (...) + { + MESSAGE("Notify Observer, exception catch"); + } + iter++; + } + } diff --git a/src/Launcher/SALOME_Launcher.hxx b/src/Launcher/SALOME_Launcher.hxx index 98bff0f66..871488b90 100644 --- a/src/Launcher/SALOME_Launcher.hxx +++ b/src/Launcher/SALOME_Launcher.hxx @@ -30,6 +30,7 @@ #include "Launcher.hxx" #include +#include class SALOME_NamingService; class SALOME_ContainerManager; @@ -71,6 +72,10 @@ public: static const char *_LauncherNameInNS; +protected: + // Internal methods + virtual void notifyObservers(const std::string & event_name, const std::string & event_data); + protected: CORBA::ORB_var _orb; PortableServer::POA_var _poa; @@ -78,6 +83,8 @@ protected: SALOME_ResourcesManager *_ResManager; SALOME_NamingService *_NS; + std::list _observers; + Launcher_cpp _l; }; diff --git a/src/ResourcesManager/SALOME_ResourcesManager.cxx b/src/ResourcesManager/SALOME_ResourcesManager.cxx index acdfe259d..454b9696a 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.cxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.cxx @@ -262,8 +262,8 @@ SALOME_ResourcesManager::GetResourceDefinition(const char * name) void SALOME_ResourcesManager::AddResource(const Engines::ResourceDefinition& new_resource, - CORBA::Boolean write, - const char * xml_file) + CORBA::Boolean write, + const char * xml_file) { ParserResourcesType resource; resource.Name = new_resource.name.in(); -- 2.39.2