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 ==================================================================================
23 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap"
24 "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/xapptweaks"
25 "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 {
56 return "trans(" + strconv.FormatUint(uint64(t.Seq), 10) + "/" + (&xapptweaks.RMRMeid{t.Meid}).String() + ")"
59 func (t *Transaction) SendEvent(event interface{}, waittime time.Duration) (bool, bool) {
62 case t.EventChan <- event:
64 case <-time.After(waittime):
73 func (t *Transaction) WaitEvent(waittime time.Duration) (interface{}, bool) {
76 case event := <-t.EventChan:
78 case <-time.After(waittime):
82 event := <-t.EventChan
86 func (t *Transaction) GetMtype() int {
88 defer t.mutex.Unlock()
92 func (t *Transaction) GetMeid() *xapp.RMRMeid {
94 defer t.mutex.Unlock()
101 func (t *Transaction) GetPayload() *e2ap.PackedData {
103 defer t.mutex.Unlock()
107 //-----------------------------------------------------------------------------
109 //-----------------------------------------------------------------------------
110 type TransactionSubs struct {
114 func (t *TransactionSubs) String() string {
115 return "transsubs(" + t.Transaction.String() + ")"
118 func (t *TransactionSubs) Release() {
120 xapp.Logger.Debug("RELEASE %s", t.String())
125 //-----------------------------------------------------------------------------
127 //-----------------------------------------------------------------------------
128 type TransactionXappKey struct {
129 xapptweaks.RmrEndpoint
130 Xid string // xapp xid in req
133 func (key *TransactionXappKey) String() string {
134 return "transkey(" + key.RmrEndpoint.String() + "/" + key.Xid + ")"
137 //-----------------------------------------------------------------------------
139 //-----------------------------------------------------------------------------
140 type TransactionXapp struct {
142 XappKey *TransactionXappKey
146 func (t *TransactionXapp) String() string {
147 var transkey string = "transkey(N/A)"
148 if t.XappKey != nil {
149 transkey = t.XappKey.String()
151 return "transxapp(" + t.Transaction.String() + "/" + transkey + "/" + strconv.FormatUint(uint64(t.SubId), 10) + ")"
154 func (t *TransactionXapp) GetEndpoint() *xapptweaks.RmrEndpoint {
156 defer t.mutex.Unlock()
157 if t.XappKey != nil {
158 return &t.XappKey.RmrEndpoint
163 func (t *TransactionXapp) GetXid() string {
165 defer t.mutex.Unlock()
166 if t.XappKey != nil {
172 func (t *TransactionXapp) GetSrc() string {
174 defer t.mutex.Unlock()
175 if t.XappKey != nil {
176 return t.XappKey.RmrEndpoint.String()
181 func (t *TransactionXapp) GetSubId() uint32 {
183 defer t.mutex.Unlock()
187 func (t *TransactionXapp) Release() {
189 xapp.Logger.Debug("RELEASE %s", t.String())
195 if tracker != nil && xappkey != nil {
196 tracker.UnTrackTransaction(*xappkey)