6dcc01e619a3136df0420d6a441b5ac454823218
[ric-plt/e2mgr.git] / E2Manager / services / receivers / rmr_service_receiver.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
18 package receivers
19
20 import (
21         "e2mgr/managers/notificationmanager"
22         "e2mgr/services"
23 )
24
25 // RmrService holds an instance of RMR messenger as well as its configuration
26 type RmrServiceReceiver struct {
27         services.RmrService
28         nManager *notificationmanager.NotificationManager
29 }
30
31 // NewRmrService instantiates a new Rmr service instance
32 func NewRmrServiceReceiver(rmrService services.RmrService, nManager *notificationmanager.NotificationManager) *RmrServiceReceiver {
33
34         return &RmrServiceReceiver{
35                 RmrService: rmrService,
36                 nManager:   nManager,
37         }
38 }
39
40 // ListenAndHandle waits for messages coming from rmr_rcv_msg and sends it to a designated message handler
41 func (r *RmrServiceReceiver) ListenAndHandle() {
42
43         for {
44                 mbuf, err := (*r.Messenger).RecvMsg()
45                 r.Config.Logger.Debugf("#rmr_service_receiver.ListenAndHandle - Going to handle received message: %#v\n", mbuf)
46
47                 // TODO: one mbuf received immediately execute goroutine
48                 if err != nil {
49                         continue //TODO log error
50                 }
51
52                 r.nManager.HandleMessage(r.Config.Logger, r.E2sessions, mbuf, r.RmrResponse)
53         }
54 }