[RICPLT-1703] - Reset Request - after acceptance
[ric-plt/e2mgr.git] / E2Manager / providers / notification_handler_provider.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 providers
19
20 import (
21         "e2mgr/handlers"
22         "e2mgr/rNibWriter"
23         "e2mgr/rmrCgo"
24         "fmt"
25         "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
26 )
27
28 type NotificationHandlerProvider struct{
29         notificationHandlers map[int]handlers.NotificationHandler
30 }
31
32 func NewNotificationHandlerProvider(rnibReaderProvider func() reader.RNibReader, rnibWriterProvider func() rNibWriter.RNibWriter) *NotificationHandlerProvider {
33         return &NotificationHandlerProvider{
34                 notificationHandlers: initNotificationHandlersMap(rnibReaderProvider, rnibWriterProvider),
35         }
36 }
37
38 func initNotificationHandlersMap(rnibReaderProvider func() reader.RNibReader, rnibWriterProvider func() rNibWriter.RNibWriter) map[int]handlers.NotificationHandler{
39         return  map[int]handlers.NotificationHandler{
40                 //TODO change handlers.NotificationHandler to *handlers.NotificationHandler
41                 rmrCgo.RIC_X2_SETUP_RESP:           handlers.X2SetupResponseNotificationHandler{},
42                 rmrCgo.RIC_X2_SETUP_FAILURE:        handlers.X2SetupFailureResponseNotificationHandler{},
43                 rmrCgo.RIC_ENDC_X2_SETUP_RESP:      handlers.EndcX2SetupResponseNotificationHandler{},
44                 rmrCgo.RIC_ENDC_X2_SETUP_FAILURE:   handlers.EndcX2SetupFailureResponseNotificationHandler{},
45                 rmrCgo.RIC_SCTP_CONNECTION_FAILURE: handlers.NewRanLostConnectionHandler(rnibReaderProvider, rnibWriterProvider),
46                 rmrCgo.RIC_ENB_LOAD_INFORMATION:    handlers.NewEnbLoadInformationNotificationHandler(rnibWriterProvider),
47                 rmrCgo.RIC_ENB_CONF_UPDATE:             handlers.X2EnbConfigurationUpdateHandler{},
48                 rmrCgo.RIC_ENDC_CONF_UPDATE:            handlers.EndcConfigurationUpdateHandler{},
49                 rmrCgo.RIC_X2_RESET_RESP:                       handlers.NewX2ResetResponseHandler(rnibReaderProvider),
50                 rmrCgo.RIC_X2_RESET:                            handlers.NewX2ResetRequestNotificationHandler(rnibReaderProvider),
51         }
52 }
53
54 func (provider NotificationHandlerProvider) GetNotificationHandler(messageType int) (handlers.NotificationHandler, error) {
55         handler, ok := provider.notificationHandlers[messageType]
56
57         if !ok {
58                 return nil, fmt.Errorf("notification handler not found for message %d",messageType)
59         }
60
61         return handler, nil
62
63 }