Capability to add rmr message name-id mapping via configuration
Change-Id: If765b1710a90db16145d8e98e8564c135a837209
Signed-off-by: Juha Hyttinen <juha.hyttinen@nokia.com>
diff --git a/pkg/xapp/config.go b/pkg/xapp/config.go
index 94e88a1..49c5e0a 100644
--- a/pkg/xapp/config.go
+++ b/pkg/xapp/config.go
@@ -27,6 +27,15 @@
"path/filepath"
)
+//-----------------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------------
+
+type mtype struct {
+ Name string
+ Id int
+}
+
type Configurator struct {
}
@@ -51,10 +60,42 @@
}
l.Info("Using config file: %s", viper.ConfigFileUsed())
+ updatemtypes := func() {
+ var mtypes []mtype
+ viper.UnmarshalKey("rmr.mtypes", &mtypes)
+
+ if len(mtypes) > 0 {
+ l.Info("Config mtypes before RICMessageTypes:%d RicMessageTypeToName:%d", len(RICMessageTypes), len(RicMessageTypeToName))
+ for _, v := range mtypes {
+ nadd := false
+ iadd := false
+ if _, ok := RICMessageTypes[v.Name]; ok == false {
+ nadd = true
+ }
+ if _, ok := RicMessageTypeToName[int(v.Id)]; ok == false {
+ iadd = true
+ }
+ if iadd != nadd {
+ l.Error("Config mtypes rmr.mtypes entry skipped due conflict with existing values %s(%t) %d(%t) ", v.Name, nadd, v.Id, iadd)
+ } else if iadd {
+ l.Info("Config mtypes rmr.mtypes entry added %s(%t) %d(%t) ", v.Name, nadd, v.Id, iadd)
+ RICMessageTypes[v.Name] = int(v.Id)
+ RicMessageTypeToName[int(v.Id)] = v.Name
+ } else {
+ l.Info("Config mtypes rmr.mtypes entry skipped %s(%t) %d(%t) ", v.Name, nadd, v.Id, iadd)
+ }
+ }
+ l.Info("Config mtypes after RICMessageTypes:%d RicMessageTypeToName:%d", len(RICMessageTypes), len(RicMessageTypeToName))
+ }
+ }
+
+ updatemtypes()
+
viper.WatchConfig()
viper.OnConfigChange(func(e fsnotify.Event) {
l.Info("config file %s changed ", e.Name)
+ updatemtypes()
Logger.SetLevel(viper.GetInt("logger.level"))
if len(ConfigChangeListeners) > 0 {
for _, f := range ConfigChangeListeners {