00001 #ifndef artdaq_mfextensions_extensions_throttle_hh 00002 #define artdaq_mfextensions_extensions_throttle_hh 00003 00004 #include <string> 00005 00006 #include <sys/time.h> 00007 00008 #include <boost/regex.hpp> 00009 00010 typedef boost::regex regex_t; 00011 typedef boost::smatch smatch_t; 00012 00017 class throttle 00018 { 00019 public: 00026 throttle(std::string const& name, int limit, long timespan); 00027 00034 bool reach_limit(std::string const& name, timeval tm); 00035 00036 void use(bool flag) { in_use_ = flag; } 00037 00038 private: 00039 std::string name_; 00040 regex_t expr_; 00041 smatch_t what_; 00042 int limit_; 00043 long timespan_; 00044 long last_window_start_; 00045 int count_; 00046 bool in_use_; 00047 }; 00048 00049 #endif //artdaq_mfextensions_extensions_throttle_hh