00001 /* -*- mode: c++ -*- */ 00002 #ifndef __DAQpp_IOhandler_h__ 00003 #define __DAQpp_IOhandler_h__ 00004 #include <csignal> 00005 #include <pthread.h> 00006 00007 namespace DAQpp 00008 { 00016 class IOhandler 00017 { 00018 private: 00020 int signum; 00022 double nTrg; 00024 bool newData; 00025 #ifdef USE_MUTEX 00027 pthread_mutex_t mtx; 00028 #else 00030 int sem; 00031 #endif 00033 struct sigaction actIO; 00034 00036 void (*func)(void *); 00038 void *ptr; 00040 static IOhandler *instance; 00041 00043 int lock (); 00045 bool trylock(); 00047 int unlock(); 00048 public: 00050 IOhandler(int s); 00052 ~IOhandler(); 00053 00055 void Register( void (*f)(void *), void *p ); 00057 void Unregister(); 00059 void ResetTrg() 00060 { 00061 nTrg = 0.; 00062 newData = false; 00063 } 00065 void PrepareForData(); 00067 double GetNtrg() 00068 { 00069 return nTrg; 00070 } 00072 bool Data() 00073 { 00074 return newData; 00075 } 00077 void WaitForData(); 00079 static void gotIO(int); 00080 }; 00081 } 00082 #endif