00001 00034 #ifndef FLASHLIGHT_H 00035 #define FLASHLIGHT_H 00036 00037 #include "oldgcccompat.h" // Compatibilty macros for GCC < 4.7 00038 00039 #include <string> 00040 #include <termios.h> 00041 #include <vector> 00042 00043 #include <boost/thread.hpp> 00044 00045 namespace AlarmNotifications 00046 { 00047 00055 class FlashLight 00056 { 00062 typedef std::vector<uint8_t> deviceCommand ; 00063 private: 00069 const std::string _deviceNode; 00075 boost::mutex _serialLineMutex; 00081 int _fd; 00087 bool _fdOpen; 00093 static const unsigned int deviceBaudRate = B9600; // Taken from the manual of the USB relais 00094 00100 FlashLight(); 00108 void switchInternal ( const bool lightSwitch ); 00116 static deviceCommand createCommand ( const bool lightSwitch ); 00124 void openSerialInterface(); 00133 void configureSerialInterface(); 00144 void writeSerialInteface ( const deviceCommand command ); 00151 void closeSerialInterface(); 00152 public: 00159 static FlashLight& instance() noexcept; 00165 ~FlashLight(); 00174 static void switchOn() noexcept; 00183 static void switchOff() noexcept; 00190 FlashLight ( const FlashLight& other ) = delete; 00197 FlashLight ( FlashLight&& other ) = delete; 00205 FlashLight& operator= ( const FlashLight& other ) = delete; 00213 FlashLight& operator= ( FlashLight&& other ) = delete; 00214 }; 00215 00216 } 00217 00218 #endif // FLASHLIGHT_H