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 00040 void use(bool flag) { in_use_ = flag; } 00041 00042 private: 00043 std::string name_; 00044 regex_t expr_; 00045 smatch_t what_; 00046 int limit_; 00047 long timespan_; 00048 long last_window_start_; 00049 int count_; 00050 bool in_use_; 00051 }; 00052 00053 #endif //artdaq_mfextensions_extensions_throttle_hh