status.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package rpcore
  2. import (
  3. "fmt"
  4. "strconv"
  5. "time"
  6. )
  7. type ProcStatus int8
  8. const (
  9. PROCSTAT_PendingToRun ProcStatus = iota
  10. PROCSTAT_Running ProcStatus = iota
  11. PROCSTAT_Exited ProcStatus = iota
  12. PROCSTAT_PendingToStop ProcStatus = iota
  13. PROCSTAT_PendingToDelete ProcStatus = iota
  14. PROCSTAT_ManuallyStopped
  15. )
  16. func (ps ProcStatus) ToString() string {
  17. switch ps {
  18. case PROCSTAT_PendingToRun:
  19. return "PendingR"
  20. case PROCSTAT_Running:
  21. return "Running"
  22. case PROCSTAT_Exited:
  23. return "Exited"
  24. case PROCSTAT_PendingToStop:
  25. return "PendingS"
  26. case PROCSTAT_ManuallyStopped:
  27. return "Stopped"
  28. case PROCSTAT_PendingToDelete:
  29. return "PendingD"
  30. default:
  31. return "Unknown"
  32. }
  33. }
  34. func (ps ProcStatus) ToStringAbbr() string {
  35. switch ps {
  36. case PROCSTAT_PendingToRun:
  37. return "PDR"
  38. case PROCSTAT_Running:
  39. return "RUN"
  40. case PROCSTAT_Exited:
  41. return "END"
  42. case PROCSTAT_PendingToStop:
  43. return "PDS"
  44. case PROCSTAT_ManuallyStopped:
  45. return "OFF"
  46. case PROCSTAT_PendingToDelete:
  47. return "PDD"
  48. default:
  49. return "UKN"
  50. }
  51. }
  52. type DisplayStatusInfo struct {
  53. CPID int64 `json:"cpid"`
  54. Name string `json:"name"`
  55. Status ProcStatus `json:"status"`
  56. StatusText string `json:"statusText"`
  57. StatusAbbr string `json:"statusAbbr"`
  58. PID int `json:"pid"`
  59. LastStartTime time.Time `json:"lastStartTime"`
  60. }
  61. func (i DisplayStatusInfo) ToPrintableTableData() []string {
  62. tmstr := "-"
  63. if !i.LastStartTime.IsZero() {
  64. tmstr = i.LastStartTime.Format(time.RFC3339Nano)
  65. }
  66. pid := "-"
  67. if i.PID > 0 {
  68. pid = strconv.Itoa(i.PID)
  69. }
  70. return []string{
  71. fmt.Sprintf("%16X", i.CPID),
  72. i.Name,
  73. i.StatusAbbr,
  74. pid,
  75. tmstr,
  76. }
  77. }