ARC SDK
JobState.h
1 #ifndef __ARC_JOBSTATE_H__
2 #define __ARC_JOBSTATE_H__
3 
4 #include <string>
5 #include <map>
6 
7 #ifdef JOBSTATE_TABLE
8 #undef JOBSTATE_TABLE
9 #endif
10 
11 #ifdef JOBSTATE_X
12 #undef JOBSTATE_X
13 #endif
14 
15 namespace Arc {
16 
42  class JobState {
43  public:
55  enum StateType {
59  UNDEFINED,
60 
64  ACCEPTED,
65 
69  PREPARING,
70 
74  SUBMITTING,
75 
79  HOLD,
80 
84  QUEUING,
85 
89  RUNNING,
90 
94  FINISHING,
95 
99  FINISHED,
100 
104  KILLED,
105 
109  FAILED,
110 
114  DELETED,
115 
119  OTHER
120  };
121 
122  static const std::string StateTypeString[];
123 
124  JobState() : ssf(FormatSpecificState), type(UNDEFINED) {}
126 
129  JobState(const std::string& jobstate) : ssf(FormatSpecificState), state(jobstate), type(GetStateType(jobstate)) {}
130 
131  JobState& operator=(const JobState& js) { type = js.type; state = js.state; ssf = js.ssf; return *this; }
132 
133  operator bool() const { return type != UNDEFINED; }
134  operator StateType() const { return type; }
135  bool operator!() const { return type == UNDEFINED; }
136  bool operator==(const StateType& st) const { return type == st; }
137  bool operator!=(const StateType& st) const { return type != st; }
138 
144  bool IsFinished() const { return type == FINISHED || type == KILLED || type == FAILED || type == DELETED; }
145 
147 
154  const std::string& operator()() const { return state; }
155 
157 
165  const std::string& GetGeneralState() const { return StateTypeString[type]; }
166 
168 
176  std::string GetSpecificState() const { return ssf(state); }
177 
178  static StateType GetStateType(const std::string& state);
179 
180  friend class Job;
181 
182  protected:
183  typedef std::string (*SpecificStateFormater)(const std::string&);
184  SpecificStateFormater ssf;
185  static std::string FormatSpecificState(const std::string& state) { return state; }
186 
187  JobState(const std::string& state, JobState::StateType (*map)(const std::string&), SpecificStateFormater ssf = FormatSpecificState)
188  : ssf(ssf), state(state), type((*map)(state)) {};
189  std::string state;
190  StateType type;
191  };
192 
197  typedef JobState::StateType (*JobStateMap)(const std::string&);
198 }
199 
200 #endif // __ARC_JOBSTATE_H__
Arc namespace contains all core ARC classes.
Definition: ArcConfig.h:11
Definition: JobState.h:85
Definition: JobState.h:60
std::string GetSpecificState() const
Specific string representation of job state.
Definition: JobState.h:172
Definition: JobState.h:55
Definition: JobState.h:70
Definition: JobState.h:100
Definition: JobState.h:90
const std::string & GetGeneralState() const
General string representation of job state.
Definition: JobState.h:161
Definition: JobState.h:105
Definition: JobState.h:65
Definition: JobState.h:80
Definition: JobState.h:95
Definition: JobState.h:75
Definition: JobState.h:115
StateType
Possible job states in libarccompute.
Definition: JobState.h:51
const std::string & operator()() const
Unformatted specific job state.
Definition: JobState.h:150
bool IsFinished() const
Check if state is finished.
Definition: JobState.h:140
Definition: JobState.h:42
Definition: JobState.h:110