8 // CreateServiceMap function
9 func CreateServiceMap(cmd *exec.Cmd, serviceName string, appName string) (uint64, chan MsgFormat, chan bool) {
10 serviceID := getServiceIdx()
11 msgChan := make(chan MsgFormat, IPCMsgChan)
12 ctlChan := make(chan bool)
14 value := make(map[string]interface{})
16 value[KeyAppName] = appName
17 value[KeyServiceName] = serviceName
19 value[KeyMsgChan] = msgChan
20 value[KeyCtlChan] = ctlChan
22 ServiceMap.Set(serviceID, value)
24 return serviceID, msgChan, ctlChan
27 // InitServiceMap function
28 func InitServiceMap() {
29 ServiceMap = ConcurrentMap{items: make(map[uint64]interface{})}
32 // DeleteServiceMap function
33 func DeleteServiceMap(serviceID uint64) {
34 ServiceMap.Remove(serviceID)
37 // GetAppName function
38 func GetAppName(serviceID uint64) (string, error) {
39 value, _ := ServiceMap.Get(serviceID)
41 return "", errInvalidService
44 valueList := value.(map[string]interface{})
45 return valueList[KeyAppName].(string), nil
48 // GetServiceName function
49 func GetServiceName(serviceID uint64) (string, error) {
50 value, _ := ServiceMap.Get(serviceID)
52 return "", errInvalidService
55 valueList := value.(map[string]interface{})
56 return valueList[KeyServiceName].(string), nil
60 func GetCmd(serviceID uint64) (*exec.Cmd, error) {
61 value, _ := ServiceMap.Get(serviceID)
63 return nil, errInvalidService
66 valueList := value.(map[string]interface{})
67 return valueList[KeyCmd].(*exec.Cmd), nil
71 func SetCmd(serviceID uint64, cmd *exec.Cmd) error {
72 value, _ := ServiceMap.Get(serviceID)
74 return errInvalidService
77 valueList := value.(map[string]interface{})
78 valueList[KeyCmd] = cmd
82 // GetMsgChan function
83 func GetMsgChan(serviceID uint64) (chan MsgFormat, error) {
84 value, _ := ServiceMap.Get(serviceID)
86 return nil, errInvalidService
89 valueList := value.(map[string]interface{})
90 return valueList[KeyMsgChan].(chan MsgFormat), nil
93 // GetCtlChan function
94 func GetCtlChan(serviceID uint64) (chan bool, error) {
95 value, _ := ServiceMap.Get(serviceID)
97 return nil, errInvalidService
100 valueList := value.(map[string]interface{})
101 return valueList[KeyCtlChan].(chan bool), nil
104 // getServiceIdx() is for getting global serviceID
105 func getServiceIdx() uint64 {
106 atomic.AddUint64(&ServiceIdx, 1)
107 return atomic.LoadUint64(&ServiceIdx)