index.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package priority
  2. import (
  3. "os"
  4. "strconv"
  5. "github.com/sirupsen/logrus"
  6. "gopkg.in/ini.v1"
  7. )
  8. var ICPAnswer = 0
  9. var OCCAnswer = 0
  10. var RunningType = 0
  11. var SpecialVoice = 0
  12. type PriorityAll struct {
  13. ManuPa string `json:"manualPa"`
  14. CabCab string `json:"cabCab"`
  15. PADICP string `json:"padIcp"`
  16. PADTMS string `json:"padTms"`
  17. PADOCC string `json:"padOcc"`
  18. CPA string `json:"cpa"`
  19. EMGTMS string `json:"emgTms"`
  20. SPCTMS string `json:"spcTms"`
  21. DCS string `json:"dcs"`
  22. STN string `json:"stn"`
  23. CHK string `json:"chk"`
  24. }
  25. var Priority PriorityAll
  26. func GetPriority() {
  27. filePath := "/etc/asterisk/priority.conf"
  28. _, err := os.Stat(filePath)
  29. if err != nil {
  30. logrus.Error(err)
  31. return
  32. }
  33. iniFile, err := ini.Load(filePath)
  34. if err != nil {
  35. logrus.Error(err)
  36. return
  37. }
  38. Priority.CHK = iniFile.Section("general").Key("ManuPa").Value()
  39. Priority.STN = iniFile.Section("general").Key("CabCab").Value()
  40. Priority.DCS = iniFile.Section("general").Key("PAD-ICP").Value()
  41. Priority.SPCTMS = iniFile.Section("general").Key("PAD-TMS").Value()
  42. Priority.EMGTMS = iniFile.Section("general").Key("PAD-OCC").Value()
  43. Priority.CPA = iniFile.Section("general").Key("CPA").Value()
  44. Priority.PADOCC = iniFile.Section("general").Key("EMG-TMS").Value()
  45. Priority.PADTMS = iniFile.Section("general").Key("SPC-TMS").Value()
  46. Priority.PADICP = iniFile.Section("general").Key("DCS").Value()
  47. Priority.CabCab = iniFile.Section("general").Key("STN").Value()
  48. Priority.ManuPa = iniFile.Section("general").Key("CHK").Value()
  49. }
  50. func GetPriorityByKey(key string) string {
  51. filePath := "/etc/asterisk/priority.conf"
  52. _, err := os.Stat(filePath)
  53. if err != nil {
  54. logrus.Error(err)
  55. return ""
  56. }
  57. iniFile, err := ini.Load(filePath)
  58. if err != nil {
  59. logrus.Error(err)
  60. return ""
  61. }
  62. return iniFile.Section("general").Key(key).Value()
  63. }
  64. // check priority , if the running priority is lowwer than the to run priority
  65. func CheckPriority(runType string) bool {
  66. //check special voice
  67. if SpecialVoice == 1 {
  68. return false
  69. }
  70. //no any runing task
  71. if RunningType == 0 {
  72. return true
  73. }
  74. //get the priority to run in the config file
  75. ret, err := strconv.Atoi(GetPriorityByKey(runType))
  76. if err != nil {
  77. logrus.Error(err)
  78. return false
  79. }
  80. //if the running task priority is lowwer
  81. if ret < RunningType && ret != 0 {
  82. return true
  83. }
  84. return false
  85. }