Subscription REST interface update
[ric-plt/xapp-frame.git] / pkg / xapp / db.go
index afb52b5..e422cfd 100755 (executable)
@@ -73,6 +73,9 @@ type RNIBClient struct {
 
 // NewSDLClient returns a new SDLClient.
 func NewSDLClient(ns string) *SDLClient {
+       if ns == "" {
+               ns = "sdl"
+       }
        return &SDLClient{
                db:    sdl.NewSdlInstance(ns, sdl.NewDatabase()),
                stat:  Metric.RegisterCounterGroup(SDLCounterOpts, "SDL"),
@@ -165,7 +168,7 @@ func (c *SDLClient) GetStat() (t SDLStatistics) {
        return
 }
 
-func NewRNIBClient(ns string) *RNIBClient {
+func NewRNIBClient() *RNIBClient {
        s := sdl.NewSdlInstance("e2Manager", sdl.NewDatabase())
        return &RNIBClient{
                db:     s,
@@ -174,6 +177,14 @@ func NewRNIBClient(ns string) *RNIBClient {
        }
 }
 
+func (r *RNIBClient) Subscribe(cb func(string, ...string), channel string) error {
+       return r.db.SubscribeChannel(cb, channel)
+}
+
+func (r *RNIBClient) StoreAndPublish(channel string, event string, pairs ...interface{}) error {
+       return r.db.SetAndPublish([]string{channel, event}, pairs...)
+}
+
 func (r *RNIBClient) GetNodeb(invName string) (*RNIBNodebInfo, RNIBIRNibError) {
        return rnibreader.GetRNibReader(r.db).GetNodeb(invName)
 }