2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
29 type RmrConfig struct {
36 func NewRmrConfig(port int, maxMsgSize int, flags int, logger *logger.Logger) *RmrConfig {
37 return &RmrConfig{port, maxMsgSize, flags, logger}
40 // RmrService holds an instance of RMR messenger as well as its configuration
41 type RmrService struct {
43 Messenger *rmrCgo.RmrMessenger
44 E2sessions sessions.E2Sessions
45 RmrResponse chan *models.NotificationResponse
48 // NewRmrService instantiates a new Rmr service instance
49 func NewRmrService(rmrConfig *RmrConfig, msrImpl rmrCgo.RmrMessenger, e2sessions sessions.E2Sessions, rmrResponse chan *models.NotificationResponse) *RmrService {
53 Messenger: msrImpl.Init("tcp:"+strconv.Itoa(rmrConfig.Port), rmrConfig.MaxMsgSize, rmrConfig.Flags, rmrConfig.Logger),
54 E2sessions: e2sessions,
55 RmrResponse: rmrResponse,
59 func (r *RmrService) SendMessage(messageType int, messageChannel chan *models.E2RequestMessage, errorChannel chan error,
63 setupRequestMessage := <-messageChannel
64 e2Message := setupRequestMessage.GetMessageAsBytes(r.Config.Logger)
66 transactionId := []byte(setupRequestMessage.TransactionId())
68 msg := rmrCgo.NewMBuf(messageType, len(e2Message) /*r.config.MaxMsgSize*/, setupRequestMessage.RanName(), &e2Message, &transactionId)
70 r.Config.Logger.Debugf("#rmr_service.SendMessage - Going to send the message: %#v\n", msg)
71 _, err := (*r.Messenger).SendMsg(msg, r.Config.MaxMsgSize)
77 func (r *RmrService) SendRmrMessage(response *models.NotificationResponse) error {
79 msgAsBytes := response.GetMessageAsBytes(r.Config.Logger)
80 transactionIdByteArr := []byte(response.RanName)
82 msg := rmrCgo.NewMBuf(response.MgsType, len(msgAsBytes), response.RanName, &msgAsBytes, &transactionIdByteArr)
84 _, err := (*r.Messenger).SendMsg(msg, r.Config.MaxMsgSize)
92 func (r *RmrService) SendResponse() {
95 response, ok := <-r.RmrResponse
98 r.Config.Logger.Errorf("#rmr_service.SendResponse - channel closed")
102 r.Config.Logger.Debugf("#rmr_service.SendResponse - Going to send message: %#v\n", response)
103 if err := r.SendRmrMessage(response); err != nil {
104 r.Config.Logger.Errorf("#rmr_service.SendResponse - error: %#v\n", err)
109 func (r *RmrService) CloseContext() {
110 if r.Config.Logger.DebugEnabled() {
111 r.Config.Logger.Debugf("#rmr_service.CloseContext - RMR is ready: %v", (*r.Messenger).IsReady())
112 (*r.Messenger).Close()
113 r.Config.Logger.Debugf("#rmr_service.CloseContext - RMR is ready: %v", (*r.Messenger).IsReady())