Salome HOME
shutdown launcher
[modules/kernel.git] / src / Launcher / SALOME_Launcher.cxx
1 // Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "SALOME_Launcher.hxx"
24 #include "BatchTest.hxx"
25 #include "OpUtil.hxx"
26 #include "SALOME_ContainerManager.hxx"
27 #include "SALOME_NamingService.hxx"
28 #include "SALOME_ResourcesManager.hxx"
29 #include "Utils_CorbaException.hxx"
30
31
32 #include "Launcher_Job_Command.hxx"
33 #include "Launcher_Job_YACSFile.hxx"
34 #include "Launcher_Job_PythonSALOME.hxx"
35 #include "Launcher_Job_CommandSALOME.hxx"
36
37 #include "utilities.h"
38
39 #ifdef WIN32
40 # include <process.h>
41 #else
42 # include <unistd.h>
43 #endif
44 #include <sys/types.h>
45 #include <vector>
46 #include <list>
47
48 #include <stdio.h>
49 #include <sstream>
50
51 using namespace std;
52
53 const char *SALOME_Launcher::_LauncherNameInNS = "/SalomeLauncher";
54
55 //=============================================================================
56 /*! 
57  *  Constructor
58  *  \param orb
59  */
60 //=============================================================================
61 SALOME_Launcher::SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa) : _l()
62 {
63   MESSAGE("SALOME_Launcher constructor");
64   _NS = new SALOME_NamingService(orb);
65   _ResManager = new SALOME_ResourcesManager(orb,poa,_NS);
66   _l.SetResourcesManager(_ResManager->GetImpl());
67   _ContManager = new SALOME_ContainerManager(orb,poa,_NS);
68   _ResManager->_remove_ref();
69   _ContManager->_remove_ref();
70
71   _orb = CORBA::ORB::_duplicate(orb) ;
72   _poa = PortableServer::POA::_duplicate(poa) ;
73   PortableServer::ObjectId_var id = _poa->activate_object(this);
74   CORBA::Object_var obj = _poa->id_to_reference(id);
75   Engines::SalomeLauncher_var refContMan = Engines::SalomeLauncher::_narrow(obj);
76
77   _NS->Register(refContMan,_LauncherNameInNS);
78   MESSAGE("SALOME_Launcher constructor end");
79 }
80
81 //=============================================================================
82 /*! 
83  * destructor
84  */
85 //=============================================================================
86 SALOME_Launcher::~SALOME_Launcher()
87 {
88   MESSAGE("SALOME_Launcher destructor");
89   delete _NS;
90   MESSAGE("SALOME_Launcher destructor end");
91 }
92
93
94 CORBA::Long 
95 SALOME_Launcher::createJob(const Engines::JobParameters & job_parameters)
96 {
97   std::string job_type = job_parameters.job_type.in();
98
99   Launcher::Job * new_job; // It is Launcher_cpp that is going to destroy it
100
101   if (job_type == Launcher::Job_Command::TYPE_NAME)
102     new_job = new Launcher::Job_Command();
103   else if (job_type == Launcher::Job_CommandSALOME::TYPE_NAME)
104     new_job = new Launcher::Job_CommandSALOME();
105   else if (job_type == Launcher::Job_YACSFile::TYPE_NAME)
106     new_job = new Launcher::Job_YACSFile();
107   else if (job_type == Launcher::Job_PythonSALOME::TYPE_NAME)
108     new_job = new Launcher::Job_PythonSALOME();
109   else
110   {
111     std::string message("SALOME_Launcher::createJob: bad job type: ");
112     message += job_type;
113     THROW_SALOME_CORBA_EXCEPTION(message.c_str(), SALOME::INTERNAL_ERROR);
114   }
115
116   // Name
117   new_job->setJobName(job_parameters.job_name.in());
118
119   // Directories
120   std::string work_directory = job_parameters.work_directory.in();
121   std::string local_directory = job_parameters.local_directory.in();
122   std::string result_directory = job_parameters.result_directory.in();
123   new_job->setWorkDirectory(work_directory);
124   new_job->setLocalDirectory(local_directory);
125   new_job->setResultDirectory(result_directory);
126
127   // Parameters for COORM
128   std::string launcher_file = job_parameters.launcher_file.in();
129   std::string launcher_args = job_parameters.launcher_args.in();
130   new_job->setLauncherFile(launcher_file);
131   new_job->setLauncherArgs(launcher_args);
132
133   // Job File
134   std::string job_file = job_parameters.job_file.in();
135   try
136   {
137     new_job->setJobFile(job_file);
138   }
139   catch(const LauncherException &ex)
140   {
141     INFOS(ex.msg.c_str());
142     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
143   }
144   new_job->setPreCommand(job_parameters.pre_command.in());
145
146   // Files
147   std::string env_file = job_parameters.env_file.in();
148   new_job->setEnvFile(env_file);
149   for (CORBA::ULong i = 0; i < job_parameters.in_files.length(); i++)
150     new_job->add_in_file(job_parameters.in_files[i].in());
151   for (CORBA::ULong i = 0; i < job_parameters.out_files.length(); i++)
152     new_job->add_out_file(job_parameters.out_files[i].in());
153
154   // Expected During Time
155   try
156   {
157     std::string maximum_duration = job_parameters.maximum_duration.in();
158     new_job->setMaximumDuration(maximum_duration);
159   }
160   catch(const LauncherException &ex){
161     INFOS(ex.msg.c_str());
162     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
163   }
164
165   // Queue
166   std::string queue = job_parameters.queue.in();
167   new_job->setQueue(queue);
168
169   // Partition
170   std::string partition = job_parameters.partition.in();
171   new_job->setPartition(partition);
172
173   // Exclusive
174   new_job->setExclusive(job_parameters.exclusive);
175
176   // Memory required per CPU
177   new_job->setMemPerCpu(job_parameters.mem_per_cpu);
178
179   // WC Key
180   std::string wckey = job_parameters.wckey.in();
181   new_job->setWCKey(wckey);
182
183   // Extra params
184   std::string extra_params = job_parameters.extra_params.in();
185   new_job->setExtraParams(extra_params);
186
187   // Resources requirements
188   try
189   {
190     resourceParams p;
191     p.name = job_parameters.resource_required.name;
192     p.hostname = job_parameters.resource_required.hostname;
193     p.OS = job_parameters.resource_required.OS;
194     p.nb_proc = job_parameters.resource_required.nb_proc;
195     p.nb_node = job_parameters.resource_required.nb_node;
196     p.nb_proc_per_node = job_parameters.resource_required.nb_proc_per_node;
197     p.cpu_clock = job_parameters.resource_required.cpu_clock;
198     p.mem_mb = job_parameters.resource_required.mem_mb;
199     new_job->setResourceRequiredParams(p);
200   }
201   catch(const LauncherException &ex){
202     INFOS(ex.msg.c_str());
203     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
204   }
205
206   // Adding specific parameters to the job
207   for (CORBA::ULong i = 0; i < job_parameters.specific_parameters.length(); i++)
208     new_job->addSpecificParameter(job_parameters.specific_parameters[i].name.in(),
209                                   job_parameters.specific_parameters[i].value.in());
210   try
211   {
212     new_job->checkSpecificParameters();
213   }
214   catch(const LauncherException &ex)
215   {
216     INFOS(ex.msg.c_str());
217     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
218   }
219
220   try
221   {
222     _l.createJob(new_job);
223     std::ostringstream job_id;
224     job_id << new_job->getNumber();
225     notifyObservers("NEW_JOB", job_id.str());
226   }
227   catch(const LauncherException &ex)
228   {
229     INFOS(ex.msg.c_str());
230     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
231   }
232   return new_job->getNumber();
233 }
234
235 void 
236 SALOME_Launcher::launchJob(CORBA::Long job_id)
237 {
238   try
239   {
240     _l.launchJob(job_id);
241   }
242   catch(const LauncherException &ex)
243   {
244     INFOS(ex.msg.c_str());
245     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
246   }
247 }
248
249 char *
250 SALOME_Launcher::getJobState(CORBA::Long job_id)
251 {
252   std::string result;
253   try
254   {
255     result = _l.getJobState(job_id);
256   }
257   catch(const LauncherException &ex)
258   {
259     INFOS(ex.msg.c_str());
260     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
261   }
262   return CORBA::string_dup(result.c_str());
263 }
264
265 // Get names or ids of hosts assigned to the job
266 char *
267 SALOME_Launcher::getAssignedHostnames(CORBA::Long job_id)
268 {
269   std::string result;
270   try
271   {
272     result = _l.getAssignedHostnames(job_id);
273   }
274   catch(const LauncherException &ex)
275   {
276     INFOS(ex.msg.c_str());
277     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
278   }
279   return CORBA::string_dup(result.c_str());
280 }
281
282 void
283 SALOME_Launcher::getJobResults(CORBA::Long job_id, const char * directory)
284 {
285   try
286   {
287     _l.getJobResults(job_id, directory);
288   }
289   catch(const LauncherException &ex)
290   {
291     INFOS(ex.msg.c_str());
292     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
293   }
294 }
295
296 void
297 SALOME_Launcher::clearJobWorkingDir(CORBA::Long job_id)
298 {
299   try
300   {
301     _l.clearJobWorkingDir(job_id);
302   }
303   catch(const LauncherException &ex)
304   {
305     INFOS(ex.msg.c_str());
306     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
307   }
308 }
309
310 CORBA::Boolean
311 SALOME_Launcher::getJobDumpState(CORBA::Long job_id, const char * directory)
312 {
313   CORBA::Boolean rtn = false;
314   try
315   {
316     rtn = _l.getJobDumpState(job_id, directory);
317   }
318   catch(const LauncherException &ex)
319   {
320     INFOS(ex.msg.c_str());
321     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
322   }
323   return rtn;
324 }
325
326 CORBA::Boolean
327 SALOME_Launcher::getJobWorkFile(CORBA::Long job_id, const char * work_file, const char * directory)
328 {
329   CORBA::Boolean rtn = false;
330   try
331   {
332     rtn = _l.getJobWorkFile(job_id, work_file, directory);
333   }
334   catch(const LauncherException &ex)
335   {
336     INFOS(ex.msg.c_str());
337     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
338   }
339   return rtn;
340 }
341
342 void 
343 SALOME_Launcher::removeJob(CORBA::Long job_id)
344 {
345   try
346   {
347     _l.removeJob(job_id);
348     std::ostringstream job_id_str;
349     job_id_str << job_id;
350     notifyObservers("REMOVE_JOB", job_id_str.str());
351   }
352   catch(const LauncherException &ex)
353   {
354     INFOS(ex.msg.c_str());
355     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
356   }
357 }
358
359 void 
360 SALOME_Launcher::stopJob(CORBA::Long job_id)
361 {
362   try
363   {
364     _l.stopJob(job_id);
365     std::ostringstream job_id_str;
366     job_id_str << job_id;
367     notifyObservers("UPDATE_JOB_STATE", job_id_str.str());
368   }
369   catch(const LauncherException &ex)
370   {
371     INFOS(ex.msg.c_str());
372     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
373   }
374 }
375
376 char *
377 SALOME_Launcher::dumpJob(CORBA::Long job_id)
378 {
379   std::string result;
380   try
381   {
382     result = _l.dumpJob(job_id);
383   }
384   catch(const LauncherException &ex)
385   {
386     INFOS(ex.msg.c_str());
387     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
388   }
389   return CORBA::string_dup(result.c_str());
390 }
391
392 CORBA::Long
393 SALOME_Launcher::restoreJob(const char * dumpedJob)
394 {
395   CORBA::Long jobId;
396   try{
397     jobId = _l.restoreJob(dumpedJob);
398     if(jobId >= 0)
399     {
400       std::ostringstream job_str;
401       job_str << jobId;
402       notifyObservers("NEW_JOB", job_str.str());
403     }
404   }
405   catch(const LauncherException &ex){
406     INFOS(ex.msg.c_str());
407     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
408   }
409
410   return jobId;
411 }
412
413 //=============================================================================
414 /*! CORBA Method:
415  *  Create a job in the launcher with a file
416  *  \param xmlExecuteFile     : .xml to parse that contains job description
417  *  \param clusterName        : machine chosen
418  */
419 //=============================================================================
420 CORBA::Long 
421 SALOME_Launcher::createJobWithFile(const char * xmlExecuteFile,
422                                    const char * clusterName)
423 {
424   CORBA::Long jobId;
425   try{
426     jobId = _l.createJobWithFile(xmlExecuteFile, clusterName);
427   }
428   catch(const LauncherException &ex){
429     INFOS(ex.msg.c_str());
430     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
431   }
432
433   return jobId;
434 }
435
436 //=============================================================================
437 /*! CORBA Method:
438  *  the test batch configuration 
439  *  \param params             : The batch cluster
440  */
441 //=============================================================================
442 CORBA::Boolean 
443 SALOME_Launcher::testBatch(const Engines::ResourceParameters& params)
444 {
445   MESSAGE("BEGIN OF SALOME_Launcher::testBatch");
446   CORBA::Boolean rtn = false;
447   try
448   {
449     // Consider only resources that can run batch jobs
450     Engines::ResourceParameters new_params(params);
451     new_params.can_launch_batch_jobs = true;
452
453     // find a resource matching the required parameters
454     Engines::ResourceList *aMachineList = _ResManager->GetFittingResources(new_params);
455     if (aMachineList->length() == 0)
456       throw SALOME_Exception("No resources have been found with your parameters");
457
458     const Engines::ResourceDefinition* p = _ResManager->GetResourceDefinition((*aMachineList)[0]);
459         std::string resource_name(p->name);
460     INFOS("Choose resource for test: " <<  resource_name);
461     
462     BatchTest t(*p);
463     if (t.test()) 
464     {
465       rtn = true;
466     }
467   }
468   catch(const LauncherException &ex){
469     INFOS(ex.msg.c_str());
470     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
471   }
472   return rtn;
473 }
474
475 //=============================================================================
476 /*! CORBA method:
477  *  shutdown all the containers, then the ContainerManager servant
478  */
479 //=============================================================================
480 void SALOME_Launcher::Shutdown()
481 {
482   MESSAGE("Shutdown");
483   std::cout << "Shutdown Launcher" << std::endl;
484   _NS->Destroy_Name(_LauncherNameInNS);
485   _ContManager->Shutdown();
486   _ResManager->Shutdown();
487   PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
488   _poa->deactivate_object(oid);
489   if(!CORBA::is_nil(_orb))
490     _orb->shutdown(0);
491 }
492
493 //=============================================================================
494 /*! CORBA Method:
495  *  Returns the PID of the process
496  */
497 //=============================================================================
498 CORBA::Long SALOME_Launcher::getPID()
499 {
500   return 
501 #ifndef WIN32
502     (CORBA::Long)getpid();
503 #else
504     (CORBA::Long)_getpid();
505 #endif
506 }
507
508 //=============================================================================
509 /*! CORBA Method:
510  *  Returns current launcher jobs list
511  */
512 //=============================================================================
513 Engines::JobsList *
514 SALOME_Launcher::getJobsList()
515 {
516   Engines::JobsList_var jobs_list = new Engines::JobsList();
517   std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
518   std::map<int, Launcher::Job *>::const_iterator it_job;
519   int list_id = 0;
520   for(it_job = cpp_jobs.begin(); it_job != cpp_jobs.end(); it_job++)
521   {
522     int number          = it_job->first;
523     try
524     {
525       // Prepare CORBA job description
526       Engines::JobDescription_var job_descr = new Engines::JobDescription();
527       Engines::JobParameters_var job_parameters = getJobParameters(number);
528       job_descr->job_id = number;
529       job_descr->job_parameters = job_parameters;
530
531       // Add job description to the sequence
532       jobs_list->length(list_id + 1);
533       jobs_list[list_id] = job_descr;
534       list_id++;
535     }
536     catch (...) {}
537   }
538   return jobs_list._retn();
539 }
540
541 //=============================================================================
542 /*! CORBA Method:
543  * Returns the job description
544  */
545 //=============================================================================
546 Engines::JobParameters *
547 SALOME_Launcher::getJobParameters(CORBA::Long job_id)
548 {
549   std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
550   std::map<int, Launcher::Job *>::const_iterator it_job = cpp_jobs.find(job_id);
551   if (it_job == cpp_jobs.end())
552   {
553     INFOS("Cannot find the job, is it created ? job number: " << job_id);
554     THROW_SALOME_CORBA_EXCEPTION("Job does not exist", SALOME::INTERNAL_ERROR);
555   }
556
557   Launcher::Job * job = it_job->second;
558   Engines::JobParameters_var job_parameters = new Engines::JobParameters;
559   job_parameters->job_name         = CORBA::string_dup(job->getJobName().c_str());
560   job_parameters->job_type         = CORBA::string_dup(job->getJobType().c_str());
561   job_parameters->job_file         = CORBA::string_dup(job->getJobFile().c_str());
562   job_parameters->env_file         = CORBA::string_dup(job->getEnvFile().c_str());
563   job_parameters->work_directory   = CORBA::string_dup(job->getWorkDirectory().c_str());
564   job_parameters->local_directory  = CORBA::string_dup(job->getLocalDirectory().c_str());
565   job_parameters->result_directory = CORBA::string_dup(job->getResultDirectory().c_str());
566   job_parameters->pre_command      = CORBA::string_dup(job->getPreCommand().c_str());
567
568   // Parameters for COORM
569   job_parameters->launcher_file = CORBA::string_dup(job->getLauncherFile().c_str());
570   job_parameters->launcher_args = CORBA::string_dup(job->getLauncherArgs().c_str());
571
572   int i = 0;
573   int j = 0;
574   std::list<std::string> in_files  = job->get_in_files();
575   std::list<std::string> out_files = job->get_out_files();
576   job_parameters->in_files.length(in_files.size());
577   for(std::list<std::string>::iterator it = in_files.begin(); it != in_files.end(); it++)
578   {
579     job_parameters->in_files[i] = CORBA::string_dup((*it).c_str());
580     i++;
581   }
582   job_parameters->out_files.length(out_files.size());
583   for(std::list<std::string>::iterator it = out_files.begin(); it != out_files.end(); it++)
584   {
585     job_parameters->out_files[j] = CORBA::string_dup((*it).c_str());
586     j++;
587   }
588
589   job_parameters->maximum_duration = CORBA::string_dup(job->getMaximumDuration().c_str());
590   job_parameters->queue            = CORBA::string_dup(job->getQueue().c_str());
591   job_parameters->partition        = CORBA::string_dup(job->getPartition().c_str());
592   job_parameters->exclusive        = job->getExclusive();
593   job_parameters->mem_per_cpu      = job->getMemPerCpu();
594   job_parameters->wckey            = CORBA::string_dup(job->getWCKey().c_str());
595   job_parameters->extra_params     = CORBA::string_dup(job->getExtraParams().c_str());
596
597   resourceParams resource_params = job->getResourceRequiredParams();
598   job_parameters->resource_required.name             = CORBA::string_dup(resource_params.name.c_str());
599   job_parameters->resource_required.hostname         = CORBA::string_dup(resource_params.hostname.c_str());
600   job_parameters->resource_required.OS               = CORBA::string_dup(resource_params.OS.c_str());
601   job_parameters->resource_required.nb_proc          = resource_params.nb_proc;
602   job_parameters->resource_required.nb_node          = resource_params.nb_node;
603   job_parameters->resource_required.nb_proc_per_node = resource_params.nb_proc_per_node;
604   job_parameters->resource_required.cpu_clock        = resource_params.cpu_clock;
605   job_parameters->resource_required.mem_mb           = resource_params.mem_mb;
606
607   std::map<std::string, std::string> specific_parameters = job->getSpecificParameters();
608   if (!specific_parameters.empty())
609   {
610     job_parameters->specific_parameters.length(specific_parameters.size());
611     std::map<std::string, std::string>::const_iterator it_specific;
612     CORBA::ULong i = 0;
613     for (it_specific = specific_parameters.begin() ; it_specific != specific_parameters.end(); it_specific++)
614     {
615       Engines::Parameter_var new_param = new Engines::Parameter;
616       new_param->name  = CORBA::string_dup((it_specific->first).c_str());
617       new_param->value = CORBA::string_dup((it_specific->second).c_str());
618       job_parameters->specific_parameters[i] = new_param;
619       i++;
620     }
621   }
622
623   return job_parameters._retn();
624 }
625
626 //=============================================================================
627 /*! CORBA Method:
628  *  Loads jobs saved in jobs_file
629  */
630 //=============================================================================
631 void
632 SALOME_Launcher::loadJobs(const char* jobs_file)
633 {
634   list<int> new_jobs_id_list;
635   try
636   {
637     // Load the jobs in Launcher
638     new_jobs_id_list = _l.loadJobs(jobs_file);
639   }
640   catch (const LauncherException & ex)
641   {
642     INFOS(ex.msg.c_str());
643     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(), SALOME::INTERNAL_ERROR);
644   }
645
646   // Notify observers of the new jobs
647   list<int>::const_iterator it_jobs_id;
648   for (it_jobs_id = new_jobs_id_list.begin(); it_jobs_id != new_jobs_id_list.end(); it_jobs_id++)
649   {
650     ostringstream job_id_sstr;
651     job_id_sstr << *it_jobs_id;
652     notifyObservers("NEW_JOB", job_id_sstr.str());
653   }
654   notifyObservers("LOAD_JOBS", jobs_file);
655 }
656
657 //=============================================================================
658 /*! CORBA Method:
659  *  Save jobs of Launcher (in any steps) in file jobs_file
660  */
661 //=============================================================================
662 void
663 SALOME_Launcher::saveJobs(const char* jobs_file)
664 {
665   _l.saveJobs(jobs_file);
666   notifyObservers("SAVE_JOBS", jobs_file);
667 }
668
669 //=============================================================================
670 /*! CORBA Method:
671  *  Add a new observer to the launcher
672  */
673 //=============================================================================
674 void
675 SALOME_Launcher::addObserver(Engines::SalomeLauncherObserver_ptr observer)
676 {
677   bool new_observer = true;
678   std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
679   while(iter != _observers.end())
680   {
681     if (std::string(_orb->object_to_string(*iter)) ==
682         std::string(_orb->object_to_string(observer)))
683     {
684       new_observer = false;
685       break;
686     }
687     iter++;
688   }
689   if (new_observer)
690     _observers.push_back(Engines::SalomeLauncherObserver::_duplicate(observer));
691
692   // We notify the new observer with all jobs that are currently in the Launcher
693   std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
694   std::map<int, Launcher::Job *>::const_iterator it_job;
695   for(it_job = cpp_jobs.begin(); it_job != cpp_jobs.end(); it_job++)
696   {
697     int number = it_job->first;
698     std::ostringstream job_id;
699     job_id << number;
700     try
701     {
702       observer->notify("NEW_JOB", job_id.str().c_str());
703     }
704     catch (...) 
705     {
706        MESSAGE("Notify Observer, exception catch");
707     }
708
709   }
710 }
711
712 //=============================================================================
713 /*! CORBA Method:
714  *  Add a new observer to the launcher
715  */
716 //=============================================================================
717 void
718 SALOME_Launcher::removeObserver(Engines::SalomeLauncherObserver_ptr observer)
719 {
720   std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
721   while(iter != _observers.end())
722   {
723     if (std::string(_orb->object_to_string(*iter)) ==
724         std::string(_orb->object_to_string(observer)))
725     {
726       // Observer found
727       iter =_observers.erase(iter++);
728     }
729     else
730     {
731       iter++;
732     }
733   }
734 }
735
736 //=============================================================================
737 /*! Internal Method:
738  *  Notify observers on a new event
739  */
740 //=============================================================================
741 void
742 SALOME_Launcher::notifyObservers(const std::string & event_name,
743                                  const std::string & event_data)
744 {
745   std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
746   while(iter != _observers.end())
747   {
748     try
749     {
750       (*iter)->notify(CORBA::string_dup(event_name.c_str()),
751                       CORBA::string_dup(event_data.c_str()));
752     }
753     catch (...) 
754     {
755        MESSAGE("Notify Observer, exception catch");
756     }
757     iter++;
758   }
759
760 }