From 192518d79ebcffe17bf569bf9037321a6fd26d44 Mon Sep 17 00:00:00 2001 From: Mohamed Abukar Date: Tue, 11 Jun 2019 18:06:50 +0300 Subject: [PATCH] Add new interfaces Change-Id: I6d8cb9fffaeb063c1b02882f0291682e2bb66f52 Signed-off-by: Mohamed Abukar --- pkg/xapp/db.go | 23 +++++++++++++++++++---- pkg/xapp/rmr.go | 20 +++++++++++--------- pkg/xapp/xapp.go | 6 +++--- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/pkg/xapp/db.go b/pkg/xapp/db.go index f2286b4..542c755 100755 --- a/pkg/xapp/db.go +++ b/pkg/xapp/db.go @@ -70,8 +70,8 @@ func (s *SDLClient) IsReady() bool { return s.ready } -func (s *SDLClient) Store(key string, value interface{}) (err error) { - err = s.db.Set(key, value) +func (s *SDLClient) doSet(pairs ...interface{}) (err error) { + err = s.db.Set(pairs) if err != nil { s.UpdateStatCounter("StoreError") } else { @@ -80,9 +80,24 @@ func (s *SDLClient) Store(key string, value interface{}) (err error) { return } +func (s *SDLClient) Store(key string, value interface{}) (err error) { + return s.doSet(key, value) +} + +func (s *SDLClient) MStore(pairs ...interface{}) (err error) { + return s.doSet(pairs) +} + func (s *SDLClient) Read(key string) (value map[string]interface{}, err error) { - value, err = s.db.Get([]string{key}) - return + return s.db.Get([]string{key}) +} + +func (s *SDLClient) MRead(key []string) (value map[string]interface{}, err error) { + return s.db.Get(key) +} + +func (s *SDLClient) ReadAllKeys(key string) (value []string, err error) { + return s.db.GetAll() } func (s *SDLClient) Subscribe(cb func(string, ...string), channel string) error { diff --git a/pkg/xapp/rmr.go b/pkg/xapp/rmr.go index a4955d1..c835408 100755 --- a/pkg/xapp/rmr.go +++ b/pkg/xapp/rmr.go @@ -55,13 +55,14 @@ var RMRCounterOpts = []CounterOpts{ type RMRStatistics struct{} type RMRClient struct { - context unsafe.Pointer - ready int - wg sync.WaitGroup - mux sync.Mutex - stat map[string]Counter - consumers []MessageConsumer - readyCb ReadyCB + context unsafe.Pointer + ready int + wg sync.WaitGroup + mux sync.Mutex + stat map[string]Counter + consumers []MessageConsumer + readyCb ReadyCB + readyCbParams interface{} } type MessageConsumer interface { @@ -105,7 +106,7 @@ func (m *RMRClient) Start(c MessageConsumer) { } if m.readyCb != nil { - m.readyCb() + m.readyCb(m.readyCbParams) } m.Wait() @@ -216,8 +217,9 @@ func (m *RMRClient) IsReady() bool { return m.ready != 0 } -func (m *RMRClient) SetReadyCB(cb ReadyCB) { +func (m *RMRClient) SetReadyCB(cb ReadyCB, params interface{}) { m.readyCb = cb + m.readyCbParams = params } func (m *RMRClient) GetRicMessageId(name string) (int, bool) { diff --git a/pkg/xapp/xapp.go b/pkg/xapp/xapp.go index c51e0ac..1fd7ad6 100755 --- a/pkg/xapp/xapp.go +++ b/pkg/xapp/xapp.go @@ -25,7 +25,7 @@ import ( "net/http" ) -type ReadyCB func() +type ReadyCB func(interface{}) var ( // XApp is an application instance @@ -42,8 +42,8 @@ func IsReady() bool { return Rmr.IsReady() && Sdl.IsReady() } -func SetReadyCB(cb ReadyCB) { - Rmr.SetReadyCB(cb) +func SetReadyCB(cb ReadyCB, params interface{}) { + Rmr.SetReadyCB(cb, params) } func init() { -- 2.16.6