1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2020-2022] [HCL Technologies Ltd.] #
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 #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
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 *******************************************************************************/
19 /* This file contains AlarmManager singleton class which is responsible for
20 storing and managing alarms.
24 #include "AlarmManager.hpp"
29 /* Default constructor */
30 AlarmManager::AlarmManager()
36 AlarmManager::~AlarmManager()
42 /*******************************************************************
44 * @brief Read the data from the connected client application
51 * - Reads the data from the connected client application
56 ******************************************************************/
58 void AlarmManager::update(char* recvBuf)
60 O1_LOG("\nO1 AlarmManager update received");
61 AlarmRecord *alrmRec = NULL;
63 MsgHeader *msgHdr = (MsgHeader*)recvBuf;
64 O1_LOG("\nO1 AlarmManager: MsgType %d",msgHdr->msgType);
67 if ( msgHdr->msgType == ALARM ){
69 alrmRec = (AlarmRecord*) recvBuf;
70 O1_LOG("\nO1 AlarmManager:Alarm info\n"
74 " Additional Text %s\n"
75 " Specific Problem %s\n"
76 " Additional Info %s\n"
77 " Alarm Raise Time %s\n",
78 alrmRec->msgHeader.action,
80 alrmRec->perceivedSeverity,
81 alrmRec->additionalText,
82 alrmRec->specificProblem,
83 alrmRec->additionalInfo,
84 alrmRec->alarmRaiseTime
87 /*Fill the alarm structure */
88 sscanf(alrmRec->alarmId,"%hu",&alrmId);
89 alrm.setAlarmId(alrmId);
90 alrm.setPerceivedSeverity(alrmRec->perceivedSeverity);
91 alrm.setAdditionalText(alrmRec->additionalText);
92 alrm.setEventType(alrmRec->eventType);
93 alrm.setSpecificProblem(alrmRec->specificProblem);
94 alrm.setAdditionalInfo(alrmRec->additionalInfo);
97 switch(msgHdr->action)
103 VesEventHandler vesEventHandler;
104 if (!vesEventHandler.prepare(VesEventType::FAULT_NOTIFICATION, &alrm))
105 return ;//O1::FAILURE;
107 O1_LOG("\nO1 AlarmManager : Sending Alarm Data");
108 if ( !vesEventHandler.send() )
109 return ;//O1::FAILURE;
111 O1_LOG("\nO1 AlarmManager : "
112 "Alarm raised for alarm Id %s",
118 O1_LOG("\nO1 AlarmManager : "
119 "Error in raising alarm for alrm Id %s",
127 O1_LOG("\nO1 AlarmManager : "
128 "Alarm cleared for alarm Id %s",
134 O1_LOG("\nO1 AlarmManager : "
135 "Error in clearing alarm for alarm Id %s",
140 O1_LOG("\nO1 AlarmManager : No action performed");
147 /**********************************************************************
148 Description : Raise an Alarm and store it in alarm list
150 Return : true - insert in map successful
151 false - insert in map unsuccessful
152 **********************************************************************/
153 bool AlarmManager::raiseAlarm(const Alarm& alarm)
156 pair<map<uint16_t,Alarm>::iterator,bool> ret;
157 ret = mAlarmList.insert(pair<uint16_t,Alarm>(alarm.getAlarmId(),alarm));
165 /**********************************************************************
166 Description : Clear an Alarm and delete it from alarm list
167 Params[In] : Alarm instance
168 Return : true - delete successful
169 false - delete unsuccessful
170 **********************************************************************/
171 bool AlarmManager::clearAlarm(const Alarm& alarm)
173 map<uint16_t,Alarm>::iterator it;
175 it = mAlarmList.find(alarm.getAlarmId());
176 if( it != mAlarmList.end() )
178 mAlarmList.erase(it);
186 /**********************************************************************
187 Description : Clear an Alarm and delete it from alarm list with
189 Params[In] : Alarm Id
190 Return : true - delete successful
191 false - delete unsuccessful
192 **********************************************************************/
193 bool AlarmManager::clearAlarm(const uint16_t& alarmId)
195 return (mAlarmList.erase(alarmId) > 0);
199 /**********************************************************************
200 Description : Return the list of active alarms
202 Return : constant reference to the map<int, Alarm>
203 **********************************************************************/
204 const map<uint16_t, Alarm>& AlarmManager::getAlarmList()const
210 /**********************************************************************
212 **********************************************************************/