1
0

Status.h 914 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #ifndef HV_STATUS_HPP_
  2. #define HV_STATUS_HPP_
  3. #include <atomic>
  4. namespace hv {
  5. class Status {
  6. public:
  7. enum KStatus {
  8. kNull = 0,
  9. kInitializing = 1,
  10. kInitialized = 2,
  11. kStarting = 3,
  12. kStarted = 4,
  13. kRunning = 5,
  14. kPause = 6,
  15. kStopping = 7,
  16. kStopped = 8,
  17. kDestroyed = 9,
  18. };
  19. Status() {
  20. status_ = kNull;
  21. }
  22. ~Status() {
  23. status_ = kDestroyed;
  24. }
  25. KStatus status() {
  26. return status_;
  27. }
  28. void setStatus(KStatus status) {
  29. status_ = status;
  30. }
  31. bool isRunning() {
  32. return status_ == kRunning;
  33. }
  34. bool isPause() {
  35. return status_ == kPause;
  36. }
  37. bool isStopped() {
  38. return status_ == kStopped;
  39. }
  40. private:
  41. std::atomic<KStatus> status_;
  42. };
  43. }
  44. #endif // HV_STATUS_HPP_