]> SALOME platform Git repositories - modules/kernel.git/blob - src/Batch/Batch_JobInfo_ePBS.cxx
Salome HOME
BUG 0020024: a --gdb-session option to runSalome ...
[modules/kernel.git] / src / Batch / Batch_JobInfo_ePBS.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 /*
21  * JobInfo_ePBS.cxx :  emulation of PBS client
22  *
23  * Auteur : Bernard SECHER - CEA DEN
24  * Mail   : mailto:bernard.secher@cea.fr
25  * Date   : Thu Apr 24 10:17:22 2008
26  * Projet : PAL Salome 
27  *
28  */
29
30 #include <cstdio>
31 #include <iostream>
32 #include <fstream>
33 #include <sstream>
34 #include "Batch_Parametre.hxx"
35 #include "Batch_Environnement.hxx"
36 #include "Batch_RunTimeException.hxx"
37 #include "Batch_APIInternalFailureException.hxx"
38 #include "Batch_JobInfo_ePBS.hxx"
39
40 using namespace std;
41
42 namespace Batch {
43
44
45
46   // Constructeurs
47   JobInfo_ePBS::JobInfo_ePBS(int id, string logFile) : JobInfo()
48   {
49     // On remplit les membres _param et _env
50     ostringstream oss;
51     oss << id;
52     _param[ID] = oss.str();
53
54     // read of log file
55     char line[128];
56     ifstream fp(logFile.c_str(),ios::in);
57       
58     string status;
59     string sline;
60     int pos = string::npos;
61     while( (pos == string::npos) && fp.getline(line,80,'\n') ){
62       sline = string(line);
63       pos = sline.find("job_state");
64     };
65       
66     if(pos!=string::npos){
67       istringstream iss(sline);
68       iss >> status;
69       iss >> status;
70       iss >> status;
71     }
72     else
73       status = "U";
74
75     _param[STATE] = status;
76
77     if( status.find("R") != string::npos)
78       _running = true;
79
80   }
81
82   // Teste si un job est present en machine
83   bool JobInfo_ePBS::isRunning() const
84   {
85     return _running;
86   }
87
88
89   // Destructeur
90   JobInfo_ePBS::~JobInfo_ePBS()
91   {
92     // Nothing to do
93   }
94
95   // Convertit une date HH:MM:SS en secondes
96   long JobInfo_ePBS::HMStoLong(const string & s)
97   {
98     long hour, min, sec;
99
100     sscanf( s.c_str(), "%ld:%ld:%ld", &hour, &min, &sec);
101     return ( ( ( hour * 60L ) + min ) * 60L ) + sec;
102   }
103
104   // Methode pour l'interfacage avec Python (SWIG) : affichage en Python
105   string JobInfo_ePBS::__str__() const
106   {
107     ostringstream sst;
108     sst << "<JobInfo_ePBS (" << this << ") :" << endl;
109     sst << " ID = " <<_param[ID] << endl;
110     sst << " STATE = " <<_param[STATE] << endl;
111
112     return sst.str();
113   }
114
115
116 }