00001 #ifndef __ARC_JOBSTATE_H__ 00002 #define __ARC_JOBSTATE_H__ 00003 00004 #include <string> 00005 #include <map> 00006 00007 #ifdef JOBSTATE_TABLE 00008 #undef JOBSTATE_TABLE 00009 #endif 00010 00011 #ifdef JOBSTATE_X 00012 #undef JOBSTATE_X 00013 #endif 00014 00015 namespace Arc { 00016 00030 class JobState { 00031 public: 00032 #define JOBSTATE_TABLE \ 00033 JOBSTATE_X(ACCEPTED, "Accepted")\ 00034 JOBSTATE_X(PREPARING, "Preparing")\ 00035 JOBSTATE_X(SUBMITTING, "Submitting")\ 00036 JOBSTATE_X(HOLD, "Hold")\ 00037 JOBSTATE_X(QUEUING, "Queuing")\ 00038 JOBSTATE_X(RUNNING, "Running")\ 00039 JOBSTATE_X(FINISHING, "Finishing")\ 00040 JOBSTATE_X(FINISHED, "Finished")\ 00041 JOBSTATE_X(KILLED, "Killed")\ 00042 JOBSTATE_X(FAILED, "Failed")\ 00043 JOBSTATE_X(DELETED, "Deleted")\ 00044 JOBSTATE_X(OTHER, "Other") 00045 00046 #define JOBSTATE_X(a, b) , a 00047 enum StateType { UNDEFINED JOBSTATE_TABLE }; 00048 #undef JOBSTATE_X 00049 static const std::string StateTypeString[]; 00050 00051 JobState() : type(UNDEFINED) {} 00052 00053 JobState& operator=(const JobState& newState) { type = newState.type; state = newState.state; return *this; } 00054 00055 operator bool() const { return type != UNDEFINED; } 00056 operator StateType() const { return type; } 00057 bool operator!() const { return type == UNDEFINED; } 00058 bool operator==(const StateType& st) const { return type == st; } 00059 bool operator!=(const StateType& st) const { return type != st; } 00060 00062 00066 bool IsFinished() const { return type == FINISHED || type == KILLED || type == FAILED || type == DELETED; } 00067 00068 const std::string& operator()() const { return state; } 00069 00070 const std::string& GetGeneralState() const { return StateTypeString[type]; } 00071 00072 static StateType GetStateType(const std::string& state); 00073 00074 friend class Job; 00075 00076 protected: 00077 JobState(const std::string& state, JobState::StateType (*map)(const std::string&)) 00078 : state(state), type((*map)(state)) {}; 00079 std::string state; 00080 StateType type; 00081 }; 00082 00083 typedef JobState::StateType (*JobStateMap)(const std::string&); 00084 } 00085 00086 #endif // __ARC_JOBSTATE_H__