00001 00034 #ifndef ALARMSERVERCONNECTOR_H 00035 #define ALARMSERVERCONNECTOR_H 00036 00037 #include "oldgcccompat.h" // Compatibilty macros for GCC < 4.7 00038 00039 #include <map> 00040 #include <limits> 00041 #include <string> 00042 #include <thread> 00043 00044 #include <boost/thread.hpp> 00045 00046 #include "alarmstatusentry.h" 00047 #include "cmsclient.h" 00048 00049 #if ( __WORDSIZE < 64 ) || ( LONG_MAX < 9223372036854775807L ) 00050 #warning Using this application on non-64bit architecture may cause it suffer from the year-2038-bug on 19 Jan 2038 03:14:07 UTC. Linux on 64bit is not affected as time_t is a long int and long int is 64bit wide there. 00051 #endif 00052 00053 namespace AlarmNotifications 00054 { 00055 00063 class AlarmServerConnector 00064 { 00065 private: 00066 #if ( OLDGCC46COMPAT == 0 ) 00067 00078 static const time_t noAlarmActive = std::numeric_limits<long int>::min(); // Proper definition 00079 #else 00080 static const time_t noAlarmActive = LONG_MIN; // Fallback to preprocessor macro for old compilers 00081 #endif 00082 00087 const bool _desktopVersion; 00093 const bool _activateBeedo; 00099 CMSClient _cmsclient; 00107 std::map<std::string, AlarmStatusEntry> _statusmap; 00113 boost::mutex _statusmapmutex; 00119 boost::mutex _flashlightmutex; 00125 bool _runwatcher; 00131 bool _flashlighton; 00137 boost::thread _watcher; 00143 boost::thread _flashlightthread; 00149 time_t _oldestAlarm; 00150 00158 bool checkSeverityString ( const std::string& severity ); 00165 void startWatcher(); 00172 void checkStatusMap(); 00179 void operateFlashLight(); 00186 void switchFlashLightOn(); 00193 void switchFlashLightOff(); 00202 void prepareDesktopNotification(); 00210 void sendDesktopNotification ( const std::vector<AlarmStatusEntry > alarm ); 00219 void prepareEMailNotification(); 00227 void sendEMailNotification ( const std::vector< AlarmStatusEntry > alarm ); 00228 public: 00237 AlarmServerConnector ( const bool desktopVersion = false, const bool activateBeedo = false ); 00243 ~AlarmServerConnector(); 00250 AlarmServerConnector ( const AlarmServerConnector& other ) = delete; 00257 AlarmServerConnector ( AlarmServerConnector&& other ) = delete; 00265 AlarmServerConnector& operator= ( const AlarmServerConnector& other ) = delete; 00273 AlarmServerConnector& operator= ( AlarmServerConnector&& other ) = delete; 00281 void notifyStatusChange ( const AlarmStatusEntry status ); 00288 size_t getNumberOfAlarms() const noexcept; 00289 }; 00290 00291 } 00292 00293 #endif // ALARMSERVERCONNECTOR_H