b396188d4f808bafa8ab0519ea864002656e3b62
[o-du/l2.git] / src / o1 / AlarmManager.cpp
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2020] [HCL Technologies Ltd.]                               #
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
19 /* This file contains AlarmManager singleton class which is responsible for 
20    storing and managing alarms. 
21 */ 
22
23 #include <iostream>
24 #include "AlarmManager.hpp"
25
26 using std::pair;
27
28 /* Default constructor */
29 AlarmManager::AlarmManager()
30 {
31
32 }
33
34 /* Destructor */
35 AlarmManager::~AlarmManager()
36 {
37
38 }
39
40
41
42 /********************************************************************** 
43    Description : Raise an Alarm and store it in alarm list
44    Params[In]  : Alarm
45    Return      : true  - insert in map successful
46                  false - insert in map unsuccessful 
47 **********************************************************************/
48 bool AlarmManager::raiseAlarm(const Alarm& alarm)
49 {
50
51    pair<map<uint16_t,Alarm>::iterator,bool> ret;
52    ret = mAlarmList.insert(pair<uint16_t,Alarm>(alarm.getAlarmId(),alarm));
53    return ret.second;
54
55    
56 }
57
58
59
60 /********************************************************************** 
61    Description : Clear an Alarm and delete it from alarm list 
62    Params[In]  : Alarm instance
63    Return      : true  - delete successful
64                  false - delete unsuccessful 
65 **********************************************************************/
66 bool AlarmManager::clearAlarm(const Alarm& alarm)
67 {
68    map<uint16_t,Alarm>::iterator it;
69    bool ret = false;
70    it = mAlarmList.find(alarm.getAlarmId());
71    if( it != mAlarmList.end() )
72    {
73       mAlarmList.erase(it);
74       ret = true;
75    }    
76    return ret;
77 }
78
79
80 /********************************************************************** 
81    Description : Clear an Alarm and delete it from alarm list with
82                  alarmId 
83    Params[In]  : Alarm Id
84    Return      : true  - delete successful
85                  false - delete unsuccessful 
86 **********************************************************************/
87 bool AlarmManager::clearAlarm(const uint16_t& alarmId)
88 {
89    return (mAlarmList.erase(alarmId) > 0);
90 }
91
92
93 /********************************************************************** 
94    Description : Return the list of active alarms
95    Params[In]  : None
96    Return      : constant reference to the map<int, Alarm> 
97 **********************************************************************/
98 const map<uint16_t, Alarm>& AlarmManager::getAlarmList()const
99 {
100    return mAlarmList;
101 }
102
103
104 /**********************************************************************
105          End of file
106 **********************************************************************/