| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- package priority
- import (
- "os"
- "strconv"
- "github.com/sirupsen/logrus"
- "gopkg.in/ini.v1"
- )
- var ICPAnswer = 0
- var OCCAnswer = 0
- var RunningType = 0
- var SpecialVoice = 0
- type PriorityAll struct {
- ManuPa string `json:"manualPa"`
- CabCab string `json:"cabCab"`
- PADICP string `json:"padIcp"`
- PADTMS string `json:"padTms"`
- PADOCC string `json:"padOcc"`
- CPA string `json:"cpa"`
- EMGTMS string `json:"emgTms"`
- SPCTMS string `json:"spcTms"`
- DCS string `json:"dcs"`
- STN string `json:"stn"`
- CHK string `json:"chk"`
- }
- var Priority PriorityAll
- func GetPriority() {
- filePath := "/etc/asterisk/priority.conf"
- _, err := os.Stat(filePath)
- if err != nil {
- logrus.Error(err)
- return
- }
- iniFile, err := ini.Load(filePath)
- if err != nil {
- logrus.Error(err)
- return
- }
- Priority.CHK = iniFile.Section("general").Key("ManuPa").Value()
- Priority.STN = iniFile.Section("general").Key("CabCab").Value()
- Priority.DCS = iniFile.Section("general").Key("PAD-ICP").Value()
- Priority.SPCTMS = iniFile.Section("general").Key("PAD-TMS").Value()
- Priority.EMGTMS = iniFile.Section("general").Key("PAD-OCC").Value()
- Priority.CPA = iniFile.Section("general").Key("CPA").Value()
- Priority.PADOCC = iniFile.Section("general").Key("EMG-TMS").Value()
- Priority.PADTMS = iniFile.Section("general").Key("SPC-TMS").Value()
- Priority.PADICP = iniFile.Section("general").Key("DCS").Value()
- Priority.CabCab = iniFile.Section("general").Key("STN").Value()
- Priority.ManuPa = iniFile.Section("general").Key("CHK").Value()
- }
- func GetPriorityByKey(key string) string {
- filePath := "/etc/asterisk/priority.conf"
- _, err := os.Stat(filePath)
- if err != nil {
- logrus.Error(err)
- return ""
- }
- iniFile, err := ini.Load(filePath)
- if err != nil {
- logrus.Error(err)
- return ""
- }
- return iniFile.Section("general").Key(key).Value()
- }
- // check priority , if the running priority is lowwer than the to run priority
- func CheckPriority(runType string) bool {
- //check special voice
- if SpecialVoice == 1 {
- return false
- }
- //no any runing task
- if RunningType == 0 {
- return true
- }
- //get the priority to run in the config file
- ret, err := strconv.Atoi(GetPriorityByKey(runType))
- if err != nil {
- logrus.Error(err)
- return false
- }
- //if the running task priority is lowwer
- if ret < RunningType && ret != 0 {
- return true
- }
- return false
- }
|