- Update configuration & service map
authorjw_wonny.cha <jw_wonny.cha@samsung.com>
Thu, 28 Mar 2019 12:36:29 +0000 (21:36 +0900)
committerjw_wonny.cha <jw_wonny.cha@samsung.com>
Thu, 28 Mar 2019 12:36:29 +0000 (21:36 +0900)
src/servicemgr/configure.go
src/servicemgr/service_map.go

index df72941..106c714 100644 (file)
@@ -3,23 +3,23 @@ package servicemgr
 import "errors"
 
 const (
-       // IPCMsgChan is number of message channel for receving data
-       IPCMsgChan = 10
-
-       // ConstKeyAppName is key of app name
-       ConstKeyAppName = "AppName"
+       // ConstKeyServiceID is key of service id
+       ConstKeyServiceID = "ServiceID"
 
        // ConstKeyServiceName is key of service name
        ConstKeyServiceName = "ServiceName"
 
-       // ConstKeyCmd is key of command
-       ConstKeyCmd = "Cmd"
+       // ConstKeyNotiChan is key of notification channel
+       ConstKeyNotiChan = "NotiChan"
+
+       // ConstKeyStatus is key of status
+       ConstKeyStatus = "Status"
 
-       // ConstKeyMsgChan is key of message channel
-       ConstKeyMsgChan = "MsgChan"
+       // ConstKeyUserArgs is key of user argument
+       ConstKeyUserArgs = "UserArgs"
 
-       // ConstKeyCtlChan is key of control channels
-       ConstKeyCtlChan = "CtlChan"
+       // ConstKeyNotiTargetURL is key of notification target URL
+       ConstKeyNotiTargetURL = "NotificationTargetURL"
 
        // ConstServiceStatusFailed is service status is failed
        ConstServiceStatusFailed = "Failed"
@@ -36,17 +36,29 @@ const (
        // ConstServiceNotFound is service status is not found
        ConstServiceNotFound = "NotFound"
 
-       // ConstFWWellknownPort is wellknonw port of framework
-       ConstFWWellknownPort = 56002
+       // ConstWellknownPort is wellknonw port
+       ConstWellknownPort = 56001
+
+       //ConstServiceExecuteURI is URI for creating & executing service
+       ConstServiceExecuteURI = "/api/v1/servicemgr/services"
+
+       //ConstServiceStatusNotiURI is URI for notification status of service
+       ConstServiceStatusNotiURI = "/api/v1/servicemgr/services/notification/"
+
+       //ConstLocalTarget is for knowing local environments
+       ConstLocalTarget = "local"
+
+       //ConstPrefixHTTP is "http://"
+       ConstPrefixHTTP = "http://"
 )
 
 var (
        // ErrInvalidService is for error type of invalid service
        ErrInvalidService = errors.New("It is Invalid Service")
 
-       // ServiceMap is that map has service information
+       // ServiceMap is service map
        ServiceMap ConcurrentMap
 
-       // ServiceIdx is for unique service ID
+       // ServiceIdx is for unique service ID (process id)
        ServiceIdx uint64
 )
index a9517d8..7c2dbf3 100644 (file)
 package servicemgr
 
 import (
-       "os/exec"
        "sync/atomic"
 )
 
-// CreateServiceMap function
-func CreateServiceMap(cmd *exec.Cmd, serviceName string, appName string) (uint64, chan MsgFormat, chan bool) {
-       serviceID := getServiceIdx()
-       msgChan := make(chan MsgFormat, IPCMsgChan)
-       ctlChan := make(chan bool)
-
-       value := make(map[string]interface{})
-
-       value[ConstKeyAppName] = appName
-       value[ConstKeyServiceName] = serviceName
-       value[ConstKeyCmd] = cmd
-       value[ConstKeyMsgChan] = msgChan
-       value[ConstKeyCtlChan] = ctlChan
-
-       ServiceMap.Set(serviceID, value)
-
-       return serviceID, msgChan, ctlChan
-}
-
-// InitServiceMap function
+// InitServiceMap is for initializing service map
 func InitServiceMap() {
        ServiceMap = ConcurrentMap{items: make(map[uint64]interface{})}
 }
 
-// DeleteServiceMap function
-func DeleteServiceMap(serviceID uint64) {
-       ServiceMap.Remove(serviceID)
-}
+func createServiceMap(name string, notiChan chan string) uint64 {
+       serviceID := getServiceIdx()
 
-// GetAppName function
-func GetAppName(serviceID uint64) (string, error) {
-       value, _ := ServiceMap.Get(serviceID)
-       if value == nil {
-               return "", ErrInvalidService
-       }
+       value := make(map[string]interface{})
 
-       valueList := value.(map[string]interface{})
-       return valueList[ConstKeyAppName].(string), nil
-}
+       value[ConstKeyServiceName] = name
+       value[ConstKeyNotiChan] = notiChan
 
-// GetServiceName function
-func GetServiceName(serviceID uint64) (string, error) {
-       value, _ := ServiceMap.Get(serviceID)
-       if value == nil {
-               return "", ErrInvalidService
-       }
+       ServiceMap.Set(serviceID, value)
 
-       valueList := value.(map[string]interface{})
-       return valueList[ConstKeyServiceName].(string), nil
+       return serviceID
 }
 
-// GetCmd function
-func GetCmd(serviceID uint64) (*exec.Cmd, error) {
-       value, _ := ServiceMap.Get(serviceID)
-       if value == nil {
-               return nil, ErrInvalidService
-       }
-
-       valueList := value.(map[string]interface{})
-       return valueList[ConstKeyCmd].(*exec.Cmd), nil
+func deleteServiceMap(serviceID uint64) {
+       ServiceMap.Remove(serviceID)
 }
 
-// SetCmd function
-func SetCmd(serviceID uint64, cmd *exec.Cmd) error {
+func getNotiChan(serviceID uint64) (notiChan chan string, err error) {
        value, _ := ServiceMap.Get(serviceID)
        if value == nil {
-               return ErrInvalidService
+               return
        }
 
        valueList := value.(map[string]interface{})
-       valueList[ConstKeyCmd] = cmd
-       return nil
+       return valueList[ConstKeyNotiChan].(chan string), nil
 }
 
-// @TODO GetMsgChan function
-// func GetMsgChan(serviceID uint64) (chan MsgFormat, error) {
-//     value, _ := ServiceMap.Get(serviceID)
-//     if value == nil {
-//             return nil, ErrInvalidService
-//     }
-
-//     valueList := value.(map[string]interface{})
-//     return valueList[ConstKeyMsgChan].(chan MsgFormat), nil
-// }
-
-// @TODO GetCtlChan function
-// func GetCtlChan(serviceID uint64) (chan bool, error) {
-//     value, _ := ServiceMap.Get(serviceID)
-//     if value == nil {
-//             return nil, ErrInvalidService
-//     }
-
-//     valueList := value.(map[string]interface{})
-//     return valueList[ConstKeyCtlChan].(chan bool), nil
-// }
-
 // getServiceIdx() is for getting global serviceID
 func getServiceIdx() uint64 {
        atomic.AddUint64(&ServiceIdx, 1)