Back to index

nordugrid-arc-nox  1.1.0~rc6
JobState.h
Go to the documentation of this file.
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(UNDEFINED, "Undefined")\
00034     JOBSTATE_X(ACCEPTED, "Accepted")\
00035     JOBSTATE_X(PREPARING, "Preparing")\
00036     JOBSTATE_X(SUBMITTING, "Submitting")\
00037     JOBSTATE_X(HOLD, "Hold")\
00038     JOBSTATE_X(QUEUING, "Queuing")\
00039     JOBSTATE_X(RUNNING, "Running")\
00040     JOBSTATE_X(FINISHING, "Finishing")\
00041     JOBSTATE_X(FINISHED, "Finished")\
00042     JOBSTATE_X(KILLED, "Killed")\
00043     JOBSTATE_X(FAILED, "Failed")\
00044     JOBSTATE_X(DELETED, "Deleted")\
00045     JOBSTATE_X(OTHER, "Other")
00046 
00047 #define JOBSTATE_X(a, b) a,
00048     enum StateType { JOBSTATE_TABLE };
00049 #undef JOBSTATE_X
00050     static const std::string StateTypeString[];
00051 
00052     JobState() : type(UNDEFINED) {}
00053 
00054     JobState& operator=(const JobState& newState) { type = newState.type; state = newState.state; return *this; }
00055 
00056     operator bool() const { return type != UNDEFINED; }
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 
00061     bool IsFinished() const { return type == FINISHED || type == KILLED || type == FAILED || type == DELETED; }
00062 
00063     std::string operator()() const { return state; }
00064 
00065     std::string GetGeneralState() const { return StateTypeString[type]; }
00066 
00067   protected:
00068     JobState(const std::string& state, JobState::StateType (*map)(const std::string&))
00069       : state(state), type((*map)(state)) {};
00070 
00071   private:
00072     std::string state;
00073     StateType type;
00074   };
00075 
00076   typedef JobState::StateType (*JobStateMap)(const std::string&);
00077 }
00078 
00079 #endif // __ARC_JOBSTATE_H__