RICPLT-2571 Make code change for MEID support
[ric-plt/submgr.git] / pkg / control / registry.go
index 3d70d63..1adb4f7 100644 (file)
@@ -21,26 +21,82 @@ package control
 
 import (
        "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
+       "strconv"
        "sync"
 )
 
+//-----------------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------------
 type Subscription struct {
+       mutex  sync.Mutex
        Seq    uint16
        Active bool
+       //
+       Meid        *xapp.RMRMeid
+       RmrEndpoint // xapp endpoint
+       Trans       *Transaction
+}
+
+func (s *Subscription) String() string {
+       s.mutex.Lock()
+       defer s.mutex.Unlock()
+       return strconv.FormatUint(uint64(s.Seq), 10) + "/" + s.RmrEndpoint.String() + "/" + s.Meid.RanName
 }
 
 func (s *Subscription) Confirmed() {
+       s.mutex.Lock()
+       defer s.mutex.Unlock()
        s.Active = true
 }
 
 func (s *Subscription) UnConfirmed() {
+       s.mutex.Lock()
+       defer s.mutex.Unlock()
        s.Active = false
 }
 
 func (s *Subscription) IsConfirmed() bool {
+       s.mutex.Lock()
+       defer s.mutex.Unlock()
        return s.Active
 }
 
+func (s *Subscription) SetTransaction(trans *Transaction) bool {
+       s.mutex.Lock()
+       defer s.mutex.Unlock()
+       if s.Trans == nil {
+               s.Trans = trans
+               return true
+       }
+       return false
+}
+
+func (s *Subscription) UnSetTransaction(trans *Transaction) bool {
+       s.mutex.Lock()
+       defer s.mutex.Unlock()
+       if trans == nil || trans == s.Trans {
+               s.Trans = nil
+               return true
+       }
+       return false
+}
+
+func (s *Subscription) GetTransaction() *Transaction {
+       s.mutex.Lock()
+       defer s.mutex.Unlock()
+       return s.Trans
+}
+
+func (s *Subscription) SubRouteInfo(act Action) SubRouteInfo {
+       s.mutex.Lock()
+       defer s.mutex.Unlock()
+       return SubRouteInfo{act, s.RmrEndpoint.Addr, s.RmrEndpoint.Port, s.Seq}
+}
+
+//-----------------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------------
 type Registry struct {
        register map[uint16]*Subscription
        counter  uint16
@@ -54,7 +110,7 @@ func (r *Registry) Initialize(seedsn uint16) {
 }
 
 // Reserves and returns the next free sequence number
-func (r *Registry) ReserveSubscription() *Subscription {
+func (r *Registry) ReserveSubscription(endPoint RmrEndpoint, meid *xapp.RMRMeid) *Subscription {
        // Check is current SequenceNumber valid
        // Allocate next SequenceNumber value and retry N times
        r.mutex.Lock()
@@ -69,14 +125,19 @@ func (r *Registry) ReserveSubscription() *Subscription {
                        r.counter++
                }
                if _, ok := r.register[sequenceNumber]; ok == false {
-                       r.register[sequenceNumber] = &Subscription{sequenceNumber, false}
+                       r.register[sequenceNumber] = &Subscription{
+                               Seq:         sequenceNumber,
+                               Active:      false,
+                               RmrEndpoint: endPoint,
+                               Meid:        meid,
+                               Trans:       nil,
+                       }
                        return r.register[sequenceNumber]
                }
        }
        return nil
 }
 
-// This function checks the validity of the given subscription id
 func (r *Registry) GetSubscription(sn uint16) *Subscription {
        r.mutex.Lock()
        defer r.mutex.Unlock()
@@ -87,31 +148,6 @@ func (r *Registry) GetSubscription(sn uint16) *Subscription {
        return nil
 }
 
-// This function checks the validity of the given subscription id
-func (r *Registry) IsValidSequenceNumber(sn uint16) bool {
-       r.mutex.Lock()
-       defer r.mutex.Unlock()
-       xapp.Logger.Debug("Registry map: %v", r.register)
-       if _, ok := r.register[sn]; ok {
-               return true
-       }
-       return false
-}
-
-// This function sets the give id as confirmed in the register
-func (r *Registry) setSubscriptionToConfirmed(sn uint16) {
-       r.mutex.Lock()
-       defer r.mutex.Unlock()
-       r.register[sn].Confirmed()
-}
-
-//This function sets the given id as unused in the register
-func (r *Registry) setSubscriptionToUnConfirmed(sn uint16) {
-       r.mutex.Lock()
-       defer r.mutex.Unlock()
-       r.register[sn].UnConfirmed()
-}
-
 //This function releases the given id as unused in the register
 func (r *Registry) releaseSequenceNumber(sn uint16) bool {
        r.mutex.Lock()