discoverymgr : enhancement error handling 72/204472/1
authorjaehoon.hyun <jaehoon.hyun@samsung.com>
Wed, 24 Apr 2019 06:27:59 +0000 (15:27 +0900)
committerjaehoon.hyun <jaehoon.hyun@samsung.com>
Wed, 24 Apr 2019 06:27:59 +0000 (15:27 +0900)
Change-Id: I5050ca24d6354700335b2139d579536fb196deb2

src/discoverymgr/discovery_execution.go
src/discoverymgr/discovery_init.go

index 9f02add..dfc4b50 100755 (executable)
@@ -18,7 +18,6 @@ package discoverymgr
 
 import (
        "context"
-       "errors"
        "log"
        "net"
        "time"
@@ -28,8 +27,20 @@ import (
 
 //GetDeviceList return device list
 func GetDeviceList() ([]DeviceReturnInfo, error) {
-       if gServer == nil {
-               return nil, errors.New("zeroconf server is nil")
+
+       if err := getPollingOutBoundError(); err != nil {
+               return nil, err
+       }
+
+       //NOTE :
+       //it can be happend, pollingOutbound function is out,
+       //but gServer is not initialized because InitDiscovery go routine
+       for {
+               if IsNilServer() == true {
+                       time.Sleep(0)
+               } else {
+                       break
+               }
        }
 
        gServer.IsInterfaceChange()
@@ -49,9 +60,22 @@ func GetDeviceList() ([]DeviceReturnInfo, error) {
 
 //GetDeviceListWithService retune device list
 func GetDeviceListWithService(target string) ([]string, error) {
-       if gServer == nil {
-               return nil, errors.New("zeroconf server is nil")
+
+       if err := getPollingOutBoundError(); err != nil {
+               return nil, err
+       }
+
+       //NOTE :
+       //it can be happend, pollingOutbound function is out,
+       //but gServer is not initialized because InitDiscovery go routine
+       for {
+               if IsNilServer() == true {
+                       time.Sleep(0)
+               } else {
+                       break
+               }
        }
+
        gServer.IsInterfaceChange()
 
        zeroconf.MapMTX.Lock()
index 047a875..101e6ce 100755 (executable)
@@ -27,6 +27,7 @@ import (
 )
 
 var gServer *zeroconf.Server
+var gPollingError error
 
 //InitDiscovery deploy Orchestration service
 func InitDiscovery() (err error) {
@@ -35,6 +36,11 @@ func InitDiscovery() (err error) {
        ExitPollingOutBoundCh = make(chan int, 1)
        ExitChan = make(chan int, 1)
 
+       //NOTE : Need to gPollingError Because it can call not initialized.
+       _, gPollingError = common.GetOutboundIP()
+
+       log.Println("poilling Errrrrrrrrrrror ", gPollingError)
+
        go func() {
 
                gServer, err = registerDevice(getMacAddr(pollGettingOutBoundIP()))
@@ -148,6 +154,7 @@ func acceptWifi(hostIPAddr []string) ([]string, []net.Interface) {
 }
 
 func pollGettingOutBoundIP() (string, error) {
+
        ticker := time.NewTicker(time.Duration(1) * time.Second)
        defer func() { ticker.Stop() }()
 
@@ -155,14 +162,18 @@ func pollGettingOutBoundIP() (string, error) {
                select {
                case <-ticker.C:
                        log.Println("pollGettingOutBoundIP")
-                       ip, _ := common.GetOutboundIP()
+                       ip, gPollingError := common.GetOutboundIP()
                        if len(ip) != 0 {
-                               return ip, nil
+                               return ip, gPollingError
                        }
                case <-ExitPollingOutBoundCh:
                        log.Printf("ExitPollingOutBoundCh")
-                       return "", errors.New("polling outboundIP terminated")
+                       return "", gPollingError
                }
 
        }
 }
+
+func getPollingOutBoundError() error {
+       return gPollingError
+}