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 ==================================================================================
27 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap"
28 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
34 type TransactionIf interface {
37 SendEvent(interface{}, time.Duration) (bool, bool)
38 WaitEvent(time.Duration) (interface{}, bool)
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 type Transaction struct {
47 Seq uint64 //transaction sequence
48 tracker *Tracker //tracker instance
49 Meid *xapp.RMRMeid //meid transaction related
50 Mtype int //Encoded message type to be send
51 Payload *e2ap.PackedData //Encoded message to be send
52 EventChan chan interface{}
55 func (t *Transaction) String() string {
58 meidstr = t.Meid.String()
60 return "trans(" + strconv.FormatUint(uint64(t.Seq), 10) + "/" + meidstr + ")"
63 func (t *Transaction) SendEvent(event interface{}, waittime time.Duration) (bool, bool) {
66 case t.EventChan <- event:
68 case <-time.After(waittime):
77 func (t *Transaction) WaitEvent(waittime time.Duration) (interface{}, bool) {
80 case event := <-t.EventChan:
82 case <-time.After(waittime):
86 event := <-t.EventChan
90 func (t *Transaction) GetMtype() int {
92 defer t.mutex.Unlock()
96 func (t *Transaction) GetMeid() *xapp.RMRMeid {
98 defer t.mutex.Unlock()
105 /* // This function is not used. Commented out to get better test coverage result
106 func (t *Transaction) GetPayload() *e2ap.PackedData {
108 defer t.mutex.Unlock()
112 //-----------------------------------------------------------------------------
114 //-----------------------------------------------------------------------------
115 type TransactionSubs struct {
119 func (t *TransactionSubs) String() string {
120 return "transsubs(" + t.Transaction.String() + ")"
123 func (t *TransactionSubs) Release() {
125 xapp.Logger.Debug("RELEASE %s", t.String())
130 //-----------------------------------------------------------------------------
132 //-----------------------------------------------------------------------------
133 type TransactionXappKey struct {
136 Xid string // xapp xid in req
139 func (key *TransactionXappKey) String() string {
140 return "transkey(" + key.RmrEndpoint.String() + "/" + key.Xid + ")"
143 //-----------------------------------------------------------------------------
145 //-----------------------------------------------------------------------------
146 type TransactionXapp struct {
148 XappKey *TransactionXappKey
149 RequestId e2ap.RequestId
152 func (t *TransactionXapp) String() string {
153 var transkey string = "transkey(N/A)"
154 if t.XappKey != nil {
155 transkey = t.XappKey.String()
157 return "transxapp(" + t.Transaction.String() + "/" + transkey + "/" + strconv.FormatUint(uint64(t.RequestId.InstanceId), 10) + ")"
160 func (t *TransactionXapp) GetEndpoint() *xapp.RmrEndpoint {
162 defer t.mutex.Unlock()
163 if t.XappKey != nil {
164 return &t.XappKey.RmrEndpoint
169 func (t *TransactionXapp) GetXid() string {
171 defer t.mutex.Unlock()
172 if t.XappKey != nil {
178 /* // This function is not used. Commented out to get better test coverage result
179 func (t *TransactionXapp) GetSrc() string {
181 defer t.mutex.Unlock()
182 if t.XappKey != nil {
183 return t.XappKey.RmrEndpoint.String()
188 func (t *TransactionXapp) GetSubId() uint32 {
190 defer t.mutex.Unlock()
191 return t.RequestId.InstanceId
194 func (t *TransactionXapp) Release() {
196 xapp.Logger.Debug("RELEASE %s", t.String())
202 if tracker != nil && xappkey != nil {
203 _, err := tracker.UnTrackTransaction(*xappkey)
205 xapp.Logger.Error("tracker.UnTrackTransaction() failed:%s", err.Error())