RICPLT-2707 - Create RNIB reader in C
[ric-plt/nodeb-rnib.git] / creader / rNibReader_c.go
diff --git a/creader/rNibReader_c.go b/creader/rNibReader_c.go
new file mode 100644 (file)
index 0000000..9ac32ff
--- /dev/null
@@ -0,0 +1,58 @@
+package main
+
+import (
+       "encoding/json"
+       "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
+       "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
+       "gerrit.o-ran-sc.org/r/ric-plt/sdlgo"
+       "unsafe"
+)
+
+//#include <string.h>
+import "C"
+
+var sdl common.ISdlInstance
+var instance reader.RNibReader
+
+type response struct {
+       GnbList []string        `json:"gnb_list"`
+}
+
+//export open
+func open() {
+       sdl = sdlgo.NewSdlInstance("e2Manager", sdlgo.NewDatabase())
+       instance = reader.GetRNibReader(sdl)
+}
+
+//export close
+func close() {
+       _ = sdl.Close()
+}
+
+//export getListGnbIds
+func getListGnbIds() unsafe.Pointer {
+       listGnbIds, err := instance.GetListGnbIds()
+       if err != nil || listGnbIds == nil{
+               return nil
+       }
+
+       var gnbList []string
+       for _, value := range listGnbIds {
+               gnbList = append(gnbList, value.InventoryName)
+       }
+       res := &response{
+               GnbList:gnbList,
+       }
+
+       byteResponse, err := json.Marshal(res)
+       if err != nil {
+               return nil
+       }
+
+       return C.CBytes(byteResponse)
+}
+
+
+
+func main() {
+}
\ No newline at end of file