watchConfPath.go file has created
authorjaehoon.hyun <jaehoon.hyun@samsung.com>
Wed, 27 Mar 2019 07:31:26 +0000 (16:31 +0900)
committerjaehoon.hyun <jaehoon.hyun@samsung.com>
Wed, 27 Mar 2019 07:31:26 +0000 (16:31 +0900)
src/configuremgr/watchConfPath.go [new file with mode: 0644]

diff --git a/src/configuremgr/watchConfPath.go b/src/configuremgr/watchConfPath.go
new file mode 100644 (file)
index 0000000..880fa96
--- /dev/null
@@ -0,0 +1,105 @@
+package configuremgr
+
+import (
+
+  "strings"
+  
+  confdescription "configuremgr/description"
+
+       "github.com/fsnotify/fsnotify"
+  "gopkg.in/sconf/ini.v0"
+       "gopkg.in/sconf/sconf.v0"
+)
+
+type ConfigureMgr struct {
+
+  IDeviceDiscoveryMgr struct {
+    PushConfPath func(*confdescription.Doc) (error)
+  }
+
+  IAppExecuteMgr struct {
+    PushConfPath func(*confdescription.Doc) (error)
+  }
+
+  IScoringMgr struct {
+    PushLibPath func(libPath string) (error)
+  }
+
+  Done chan bool
+}
+
+func (cfgMgr *ConfigureMgr) installConfigure(path string) {
+
+//1. libPath, conf := diretoryname get
+//2. push libPath to scoringMgr
+//3. conf context send discoverydevicemgr
+//4. conf context send executeappmgr
+
+  cfg := new(confdescription.Doc)
+
+  libPath, confPath := cfgMgr.getdirname(path)
+  sconf.Must(cfg).Read(ini.File(confPath))
+  cfgMgr.IScoringMgr.PushLibPath(libPath)
+  cfgMgr.IDeviceDiscoveryMgr.PushConfPath(cfg)
+  cfgMgr.IAppExecuteMgr.PushConfPath(cfg)
+
+}
+
+func (cfgMgr *ConfigureMgr) getdirname(path string) (libPath, confPath string) {
+
+  idx := strings.LastIndex(path, "/")
+  if idx == len(path) - 1 {
+    path = path[:len(path)-1]
+  }
+  
+  dirname := path[strings.LastIndex(path, "/") + 1:]
+
+  libPath  = path + "/" + "lib"+ dirname + ".so"
+  confPath = path + "/" +        dirname + ".conf"
+
+  DLog.Println("libPath  : " + libPath)
+  DLog.Println("confPath : " + confPath)
+
+  return
+
+}
+
+func (cfgMgr *ConfigureMgr) Watch(path string) {
+
+  watcher, err := fsnotify.NewWatcher()
+  if err != nil {
+      ELog.Fatal(err)
+  }
+  defer watcher.Close()
+
+  go func() {
+    for {
+      select {
+        case event, ok := <-watcher.Events:
+          if !ok {
+              return
+          }
+
+          ELog.Println("log event:", event)
+          if event.Op & fsnotify.Create == fsnotify.Create {
+            cfgMgr.installConfigure(event.Name)
+          }
+      case err, ok := <-watcher.Errors:
+          if !ok {
+              return
+          }
+          ELog.Println("error:", err)
+      }
+  }
+  }()
+
+  err = watcher.Add(path)
+  if err != nil {
+    ELog.Fatal(err)
+  }
+
+  
+  <- cfgMgr.Done 
+  ILog.Println("configuremgr watch end")
+
+}
\ No newline at end of file