00001 #ifndef ALARMSMAP_H 00002 #define ALARMSMAP_H 00003 /******************************************************************************* 00004 * ALMA - Atacama Large Millimiter Array 00005 * (c) European Southern Observatory, 2011 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 * 00021 * "@(#) $Id: AlarmsMap.h,v 1.3 2011/06/27 20:26:35 javarias Exp $" 00022 * 00023 * who when what 00024 * -------- -------- ---------------------------------------------- 00025 * acaproni 2011-06-19 created 00026 */ 00027 00028 #ifndef __cplusplus 00029 #error This is a C++ include file and cannot be used from plain C 00030 #endif 00031 00032 #include <map> 00033 #include "ace/Task.h" 00034 00035 #include "acscommonC.h" 00036 00037 #include <acsThread.h> 00038 00039 namespace acsalarm { 00040 00044 struct AlarmInfo { 00045 // The time the alarm event has been submitted for the last time 00046 time_t acsTime_m; 00047 00048 // The state of the last submission 00049 // It is true if ACTIVE, false if TERMINATE 00050 bool active_m; 00051 00057 AlarmInfo(const bool isActive); 00058 00062 AlarmInfo(const AlarmInfo& ai); 00063 }; 00064 00086 class AlarmsMap: public ACS::Thread { 00087 public: 00088 00092 AlarmsMap(); 00093 00103 bool raise(std::string alarmID); 00104 00111 void start(); 00112 00119 void shutdown(); 00120 00130 bool clear(std::string alarmID); 00131 00136 virtual void runLoop(); 00137 00141 int size() { return alarmsMap.size(); } 00142 00148 void getAllAlarms(std::vector<AlarmInfo> alarms); 00149 00153 void clear() { alarmsMap.clear(); } 00154 00155 private: 00156 // Alarms are stored in the que for the KEEP_ALARMS_TIME seconds 00157 // and then they are removed from the queue 00158 static const ACS::Time KEEP_ALARMS_TIME=30; 00159 00160 // The map of the alarms 00161 // 00162 // The key is the alarm ID 00163 // The object is a pointer to an AlarmInfo (a pointer 00164 // because std::map does not support elements without 00165 // a default constructor while AlarmInfo needs at least the 00166 // state of the alarm 00167 std::map<std::string, AlarmInfo*> alarmsMap; 00168 00169 // Synchronize access to the map 00170 ACE_Recursive_Thread_Mutex m_mutex; 00171 00172 // true if the object has been shut down 00173 bool m_closed; 00174 00183 bool alarmSet(std::string alarmID, bool state); 00184 }; 00185 }; 00186 00187 00188 #endif