Salome HOME
Merge branch 'V9_2_2_BR'
[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   _NS->Destroy_Name(_LauncherNameInNS);
484   _ContManager->Shutdown();
485   _ResManager->Shutdown();
486   PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
487   _poa->deactivate_object(oid);
488   if(!CORBA::is_nil(_orb))
489     _orb->shutdown(0);
490 }
491
492 //=============================================================================
493 /*! CORBA Method:
494  *  Returns the PID of the process
495  */
496 //=============================================================================
497 CORBA::Long SALOME_Launcher::getPID()
498 {
499   return 
500 #ifndef WIN32
501     (CORBA::Long)getpid();
502 #else
503     (CORBA::Long)_getpid();
504 #endif
505 }
506
507 //=============================================================================
508 /*! CORBA Method:
509  *  Returns current launcher jobs list
510  */
511 //=============================================================================
512 Engines::JobsList *
513 SALOME_Launcher::getJobsList()
514 {
515   Engines::JobsList_var jobs_list = new Engines::JobsList();
516   std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
517   std::map<int, Launcher::Job *>::const_iterator it_job;
518   int list_id = 0;
519   for(it_job = cpp_jobs.begin(); it_job != cpp_jobs.end(); it_job++)
520   {
521     int number          = it_job->first;
522     try
523     {
524       // Prepare CORBA job description
525       Engines::JobDescription_var job_descr = new Engines::JobDescription();
526       Engines::JobParameters_var job_parameters = getJobParameters(number);
527       job_descr->job_id = number;
528       job_descr->job_parameters = job_parameters;
529
530       // Add job description to the sequence
531       jobs_list->length(list_id + 1);
532       jobs_list[list_id] = job_descr;
533       list_id++;
534     }
535     catch (...) {}
536   }
537   return jobs_list._retn();
538 }
539
540 //=============================================================================
541 /*! CORBA Method:
542  * Returns the job description
543  */
544 //=============================================================================
545 Engines::JobParameters *
546 SALOME_Launcher::getJobParameters(CORBA::Long job_id)
547 {
548   std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
549   std::map<int, Launcher::Job *>::const_iterator it_job = cpp_jobs.find(job_id);
550   if (it_job == cpp_jobs.end())
551   {
552     INFOS("Cannot find the job, is it created ? job number: " << job_id);
553     THROW_SALOME_CORBA_EXCEPTION("Job does not exist", SALOME::INTERNAL_ERROR);
554   }
555
556   Launcher::Job * job = it_job->second;
557   Engines::JobParameters_var job_parameters = new Engines::JobParameters;
558   job_parameters->job_name         = CORBA::string_dup(job->getJobName().c_str());
559   job_parameters->job_type         = CORBA::string_dup(job->getJobType().c_str());
560   job_parameters->job_file         = CORBA::string_dup(job->getJobFile().c_str());
561   job_parameters->env_file         = CORBA::string_dup(job->getEnvFile().c_str());
562   job_parameters->work_directory   = CORBA::string_dup(job->getWorkDirectory().c_str());
563   job_parameters->local_directory  = CORBA::string_dup(job->getLocalDirectory().c_str());
564   job_parameters->result_directory = CORBA::string_dup(job->getResultDirectory().c_str());
565   job_parameters->pre_command      = CORBA::string_dup(job->getPreCommand().c_str());
566
567   // Parameters for COORM
568   job_parameters->launcher_file = CORBA::string_dup(job->getLauncherFile().c_str());
569   job_parameters->launcher_args = CORBA::string_dup(job->getLauncherArgs().c_str());
570
571   int i = 0;
572   int j = 0;
573   std::list<std::string> in_files  = job->get_in_files();
574   std::list<std::string> out_files = job->get_out_files();
575   job_parameters->in_files.length(in_files.size());
576   for(std::list<std::string>::iterator it = in_files.begin(); it != in_files.end(); it++)
577   {
578     job_parameters->in_files[i] = CORBA::string_dup((*it).c_str());
579     i++;
580   }
581   job_parameters->out_files.length(out_files.size());
582   for(std::list<std::string>::iterator it = out_files.begin(); it != out_files.end(); it++)
583   {
584     job_parameters->out_files[j] = CORBA::string_dup((*it).c_str());
585     j++;
586   }
587
588   job_parameters->maximum_duration = CORBA::string_dup(job->getMaximumDuration().c_str());
589   job_parameters->queue            = CORBA::string_dup(job->getQueue().c_str());
590   job_parameters->partition        = CORBA::string_dup(job->getPartition().c_str());
591   job_parameters->exclusive        = job->getExclusive();
592   job_parameters->mem_per_cpu      = job->getMemPerCpu();
593   job_parameters->wckey            = CORBA::string_dup(job->getWCKey().c_str());
594   job_parameters->extra_params     = CORBA::string_dup(job->getExtraParams().c_str());
595
596   resourceParams resource_params = job->getResourceRequiredParams();
597   job_parameters->resource_required.name             = CORBA::string_dup(resource_params.name.c_str());
598   job_parameters->resource_required.hostname         = CORBA::string_dup(resource_params.hostname.c_str());
599   job_parameters->resource_required.OS               = CORBA::string_dup(resource_params.OS.c_str());
600   job_parameters->resource_required.nb_proc          = resource_params.nb_proc;
601   job_parameters->resource_required.nb_node          = resource_params.nb_node;
602   job_parameters->resource_required.nb_proc_per_node = resource_params.nb_proc_per_node;
603   job_parameters->resource_required.cpu_clock        = resource_params.cpu_clock;
604   job_parameters->resource_required.mem_mb           = resource_params.mem_mb;
605
606   std::map<std::string, std::string> specific_parameters = job->getSpecificParameters();
607   if (!specific_parameters.empty())
608   {
609     job_parameters->specific_parameters.length(specific_parameters.size());
610     std::map<std::string, std::string>::const_iterator it_specific;
611     CORBA::ULong i = 0;
612     for (it_specific = specific_parameters.begin() ; it_specific != specific_parameters.end(); it_specific++)
613     {
614       Engines::Parameter_var new_param = new Engines::Parameter;
615       new_param->name  = CORBA::string_dup((it_specific->first).c_str());
616       new_param->value = CORBA::string_dup((it_specific->second).c_str());
617       job_parameters->specific_parameters[i] = new_param;
618       i++;
619     }
620   }
621
622   return job_parameters._retn();
623 }
624
625 //=============================================================================
626 /*! CORBA Method:
627  *  Loads jobs saved in jobs_file
628  */
629 //=============================================================================
630 void
631 SALOME_Launcher::loadJobs(const char* jobs_file)
632 {
633   list<int> new_jobs_id_list;
634   try
635   {
636     // Load the jobs in Launcher
637     new_jobs_id_list = _l.loadJobs(jobs_file);
638   }
639   catch (const LauncherException & ex)
640   {
641     INFOS(ex.msg.c_str());
642     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(), SALOME::INTERNAL_ERROR);
643   }
644
645   // Notify observers of the new jobs
646   list<int>::const_iterator it_jobs_id;
647   for (it_jobs_id = new_jobs_id_list.begin(); it_jobs_id != new_jobs_id_list.end(); it_jobs_id++)
648   {
649     ostringstream job_id_sstr;
650     job_id_sstr << *it_jobs_id;
651     notifyObservers("NEW_JOB", job_id_sstr.str());
652   }
653   notifyObservers("LOAD_JOBS", jobs_file);
654 }
655
656 //=============================================================================
657 /*! CORBA Method:
658  *  Save jobs of Launcher (in any steps) in file jobs_file
659  */
660 //=============================================================================
661 void
662 SALOME_Launcher::saveJobs(const char* jobs_file)
663 {
664   _l.saveJobs(jobs_file);
665   notifyObservers("SAVE_JOBS", jobs_file);
666 }
667
668 //=============================================================================
669 /*! CORBA Method:
670  *  Add a new observer to the launcher
671  */
672 //=============================================================================
673 void
674 SALOME_Launcher::addObserver(Engines::SalomeLauncherObserver_ptr observer)
675 {
676   bool new_observer = true;
677   std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
678   while(iter != _observers.end())
679   {
680     if (std::string(_orb->object_to_string(*iter)) ==
681         std::string(_orb->object_to_string(observer)))
682     {
683       new_observer = false;
684       break;
685     }
686     iter++;
687   }
688   if (new_observer)
689     _observers.push_back(Engines::SalomeLauncherObserver::_duplicate(observer));
690
691   // We notify the new observer with all jobs that are currently in the Launcher
692   std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
693   std::map<int, Launcher::Job *>::const_iterator it_job;
694   for(it_job = cpp_jobs.begin(); it_job != cpp_jobs.end(); it_job++)
695   {
696     int number = it_job->first;
697     std::ostringstream job_id;
698     job_id << number;
699     try
700     {
701       observer->notify("NEW_JOB", job_id.str().c_str());
702     }
703     catch (...) 
704     {
705        MESSAGE("Notify Observer, exception catch");
706     }
707
708   }
709 }
710
711 //=============================================================================
712 /*! CORBA Method:
713  *  Add a new observer to the launcher
714  */
715 //=============================================================================
716 void
717 SALOME_Launcher::removeObserver(Engines::SalomeLauncherObserver_ptr observer)
718 {
719   std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
720   while(iter != _observers.end())
721   {
722     if (std::string(_orb->object_to_string(*iter)) ==
723         std::string(_orb->object_to_string(observer)))
724     {
725       // Observer found
726       iter =_observers.erase(iter++);
727     }
728     else
729     {
730       iter++;
731     }
732   }
733 }
734
735 //=============================================================================
736 /*! Internal Method:
737  *  Notify observers on a new event
738  */
739 //=============================================================================
740 void
741 SALOME_Launcher::notifyObservers(const std::string & event_name,
742                                  const std::string & event_data)
743 {
744   std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
745   while(iter != _observers.end())
746   {
747     try
748     {
749       (*iter)->notify(CORBA::string_dup(event_name.c_str()),
750                       CORBA::string_dup(event_data.c_str()));
751     }
752     catch (...) 
753     {
754        MESSAGE("Notify Observer, exception catch");
755     }
756     iter++;
757   }
758
759 }