Fix release notes
[ric-plt/e2mgr.git] / tools / xapp_mock / rmr / rmrCgoTypes.go
1 //
2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //      http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16
17 //  This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 //  platform project (RICP).
19
20
21 package rmr
22
23 // #cgo LDFLAGS: -L/usr/local/lib -lrmr_nng -lnng
24 // #include <rmr/rmr.h>
25 // #include <stdlib.h>
26 import "C"
27 import (
28         "fmt"
29         "unsafe"
30 )
31
32 func NewMBuf(mType int, len int, payload []byte, xAction []byte) *MBuf {
33         return &MBuf{
34                 MType:   mType,
35                 Len:     len,
36                 Payload: payload,
37                 XAction: xAction,
38         }
39 }
40
41 func NewContext(maxMsgSize int, maxRetries, flags int, ctx unsafe.Pointer) *Context {
42         return &Context{
43                 MaxMsgSize: maxMsgSize,
44                 MaxRetries: maxRetries,
45                 Flags:      flags,
46                 RmrCtx:     ctx,
47         }
48 }
49
50 const (
51         RMR_MAX_XACTION_LEN = int(C.RMR_MAX_XID)
52         RMR_MAX_MSG_SIZE    = int(C.RMR_MAX_RCV_BYTES)
53         RMR_MAX_MEID_LEN    = int(C.RMR_MAX_MEID)
54
55         //states
56         RMR_OK             = C.RMR_OK
57         RMR_ERR_BADARG     = C.RMR_ERR_BADARG
58         RMR_ERR_NOENDPT    = C.RMR_ERR_NOENDPT
59         RMR_ERR_EMPTY      = C.RMR_ERR_EMPTY
60         RMR_ERR_NOHDR      = C.RMR_ERR_NOHDR
61         RMR_ERR_SENDFAILED = C.RMR_ERR_SENDFAILED
62         RMR_ERR_CALLFAILED = C.RMR_ERR_CALLFAILED
63         RMR_ERR_NOWHOPEN   = C.RMR_ERR_NOWHOPEN
64         RMR_ERR_WHID       = C.RMR_ERR_WHID
65         RMR_ERR_OVERFLOW   = C.RMR_ERR_OVERFLOW
66         RMR_ERR_RETRY      = C.RMR_ERR_RETRY
67         RMR_ERR_RCVFAILED  = C.RMR_ERR_RCVFAILED
68         RMR_ERR_TIMEOUT    = C.RMR_ERR_TIMEOUT
69         RMR_ERR_UNSET      = C.RMR_ERR_UNSET
70         RMR_ERR_TRUNC      = C.RMR_ERR_TRUNC
71         RMR_ERR_INITFAILED = C.RMR_ERR_INITFAILED
72 )
73
74 var states = map[int]string{
75         RMR_OK:             "state is good",
76         RMR_ERR_BADARG:     "argument passd to function was unusable",
77         RMR_ERR_NOENDPT:    "send/call could not find an endpoint based on msg type",
78         RMR_ERR_EMPTY:      "msg received had no payload; attempt to send an empty message",
79         RMR_ERR_NOHDR:      "message didn't contain a valid header",
80         RMR_ERR_SENDFAILED: "send failed; errno has nano reason",
81         RMR_ERR_CALLFAILED: "unable to send call() message",
82         RMR_ERR_NOWHOPEN:   "no wormholes are open",
83         RMR_ERR_WHID:       "wormhole id was invalid",
84         RMR_ERR_OVERFLOW:   "operation would have busted through a buffer/field size",
85         RMR_ERR_RETRY:      "request (send/call/rts) failed, but caller should retry (EAGAIN for wrappers)",
86         RMR_ERR_RCVFAILED:  "receive failed (hard error)",
87         RMR_ERR_TIMEOUT:    "message processing call timed out",
88         RMR_ERR_UNSET:      "the message hasn't been populated with a transport buffer",
89         RMR_ERR_TRUNC:      "received message likely truncated",
90         RMR_ERR_INITFAILED: "initialisation of something (probably message) failed",
91 }
92
93 type MBuf struct {
94         MType   int
95         Len     int
96         Meid    string //Managed entity id (RAN name)*/
97         Payload []byte
98         XAction []byte
99 }
100
101
102 func (m MBuf) String() string {
103         return fmt.Sprintf("{ MType: %d, Len: %d, Meid: %q, Xaction: %q, Payload: [%x] }", m.MType, m.Len, m.Meid, m.XAction, m.Payload)
104 }
105
106
107 type Context struct {
108         MaxMsgSize     int
109         MaxRetries     int
110         Flags          int
111         RmrCtx         unsafe.Pointer
112 }
113
114 type Messenger interface {
115         Init(port string, maxMsgSize int, maxRetries int, flags int) *Messenger
116         SendMsg(msg *MBuf) (*MBuf, error)
117         RecvMsg() (*MBuf, error)
118         IsReady() bool
119         Close()
120 }
121 type Config struct {
122         Port       int
123         MaxMsgSize int
124         MaxRetries int
125         Flags      int
126 }