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