Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package manager
import (
"sync"
"ascend-common/common-utils/hwlog"
"nodeD/pkg/common"
)
type ConfigManager interface {
GetFaultConfig() *common.FaultConfig
SetFaultConfig(*common.FaultConfig)
}
func NewConfigManager() ConfigManager {
return &ConfigTools{
config: &common.FaultConfig{&common.FaultTypeCode{}},
configLock: &sync.Mutex{},
}
}
type ConfigTools struct {
config *common.FaultConfig
configLock *sync.Mutex
}
func (c *ConfigTools) GetFaultConfig() *common.FaultConfig {
if c.config == nil {
hwlog.RunLog.Error("config is nil when get fault config")
return nil
}
c.configLock.Lock()
defer c.configLock.Unlock()
return c.config
}
func (c *ConfigTools) SetFaultConfig(faultConfig *common.FaultConfig) {
if c.config == nil || faultConfig == nil {
hwlog.RunLog.Error("fault config is nil when set fault config")
return
}
c.configLock.Lock()
defer c.configLock.Unlock()
common.DeepCopyFaultConfig(c.config, faultConfig)
}