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/xapp-frame/pkg/xapp"
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
33 type TransactionIf interface {
36 SendEvent(interface{}, time.Duration) (bool, bool)
37 WaitEvent(time.Duration) (interface{}, bool)
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
44 type Transaction struct {
46 Seq uint64 //transaction sequence
47 tracker *Tracker //tracker instance
48 Meid *xapp.RMRMeid //meid transaction related
49 Mtype int //Encoded message type to be send
50 Payload *e2ap.PackedData //Encoded message to be send
51 EventChan chan interface{}
54 func (t *Transaction) String() string {
57 meidstr = t.Meid.String()
59 return "trans(" + strconv.FormatUint(uint64(t.Seq), 10) + "/" + meidstr + ")"
62 func (t *Transaction) SendEvent(event interface{}, waittime time.Duration) (bool, bool) {
65 case t.EventChan <- event:
67 case <-time.After(waittime):
76 func (t *Transaction) WaitEvent(waittime time.Duration) (interface{}, bool) {
79 case event := <-t.EventChan:
81 case <-time.After(waittime):
85 event := <-t.EventChan
89 func (t *Transaction) GetMtype() int {
91 defer t.mutex.Unlock()
95 func (t *Transaction) GetMeid() *xapp.RMRMeid {
97 defer t.mutex.Unlock()
104 func (t *Transaction) GetPayload() *e2ap.PackedData {
106 defer t.mutex.Unlock()
110 //-----------------------------------------------------------------------------
112 //-----------------------------------------------------------------------------
113 type TransactionSubs struct {
117 func (t *TransactionSubs) String() string {
118 return "transsubs(" + t.Transaction.String() + ")"
121 func (t *TransactionSubs) Release() {
123 xapp.Logger.Debug("RELEASE %s", t.String())
128 //-----------------------------------------------------------------------------
130 //-----------------------------------------------------------------------------
131 type TransactionXappKey struct {
133 Xid string // xapp xid in req
136 func (key *TransactionXappKey) String() string {
137 return "transkey(" + key.RmrEndpoint.String() + "/" + key.Xid + ")"
140 //-----------------------------------------------------------------------------
142 //-----------------------------------------------------------------------------
143 type TransactionXapp struct {
145 XappKey *TransactionXappKey
149 func (t *TransactionXapp) String() string {
150 var transkey string = "transkey(N/A)"
151 if t.XappKey != nil {
152 transkey = t.XappKey.String()
154 return "transxapp(" + t.Transaction.String() + "/" + transkey + "/" + strconv.FormatUint(uint64(t.SubId), 10) + ")"
157 func (t *TransactionXapp) GetEndpoint() *xapp.RmrEndpoint {
159 defer t.mutex.Unlock()
160 if t.XappKey != nil {
161 return &t.XappKey.RmrEndpoint
166 func (t *TransactionXapp) GetXid() string {
168 defer t.mutex.Unlock()
169 if t.XappKey != nil {
175 func (t *TransactionXapp) GetSrc() string {
177 defer t.mutex.Unlock()
178 if t.XappKey != nil {
179 return t.XappKey.RmrEndpoint.String()
184 func (t *TransactionXapp) GetSubId() uint32 {
186 defer t.mutex.Unlock()
190 func (t *TransactionXapp) Release() {
192 xapp.Logger.Debug("RELEASE %s", t.String())
198 if tracker != nil && xappkey != nil {
199 tracker.UnTrackTransaction(*xappkey)