2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
24 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
32 type Subscription struct {
39 EpList RmrEndpointList
43 func (s *Subscription) stringImpl() string {
44 return "subs(" + strconv.FormatUint(uint64(s.Seq), 10) + "/" + s.Meid.RanName + "/" + s.EpList.String() + ")"
47 func (s *Subscription) String() string {
49 defer s.mutex.Unlock()
53 func (s *Subscription) GetSubId() uint16 {
55 defer s.mutex.Unlock()
59 func (s *Subscription) GetMeid() *xapp.RMRMeid {
61 defer s.mutex.Unlock()
68 func (s *Subscription) Confirmed() {
70 defer s.mutex.Unlock()
74 func (s *Subscription) UnConfirmed() {
76 defer s.mutex.Unlock()
80 func (s *Subscription) IsConfirmed() bool {
82 defer s.mutex.Unlock()
86 func (s *Subscription) IsEndpoint(ep *RmrEndpoint) bool {
88 defer s.mutex.Unlock()
89 return s.EpList.HasEndpoint(ep)
92 func (s *Subscription) SetTransaction(trans *Transaction) error {
94 defer s.mutex.Unlock()
97 return fmt.Errorf("subs(%s) trans(%s) exist, can not register trans(%s)", s.stringImpl(), s.Trans, trans)
102 if len(s.EpList.Endpoints) == 0 {
103 s.EpList.Endpoints = append(s.EpList.Endpoints, trans.RmrEndpoint)
104 return s.updateRouteImpl(CREATE)
105 } else if s.EpList.HasEndpoint(&trans.RmrEndpoint) == false {
106 s.EpList.Endpoints = append(s.EpList.Endpoints, trans.RmrEndpoint)
107 return s.updateRouteImpl(MERGE)
112 func (s *Subscription) UnSetTransaction(trans *Transaction) bool {
114 defer s.mutex.Unlock()
115 if trans == nil || trans == s.Trans {
122 func (s *Subscription) GetTransaction() *Transaction {
124 defer s.mutex.Unlock()
128 func (s *Subscription) updateRouteImpl(act Action) error {
129 subRouteAction := SubRouteInfo{act, s.EpList, s.Seq}
130 err := s.registry.rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
132 return fmt.Errorf("subs(%s) %s", s.stringImpl(), err.Error())
137 func (s *Subscription) UpdateRoute(act Action) error {
139 defer s.mutex.Unlock()
140 return s.updateRouteImpl(act)
143 func (s *Subscription) Release() {
144 s.registry.DelSubscription(s.Seq)
145 err := s.UpdateRoute(DELETE)
147 xapp.Logger.Error("%s", err.Error())