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 public:
00025 throttle(std::string const& name, int limit, long timespan);
00026
00033 bool reach_limit(std::string const& name, timeval tm);
00034
00039 void use(bool flag) { in_use_ = flag; }
00040
00041 private:
00042 std::string name_;
00043 regex_t expr_;
00044 smatch_t what_;
00045 int limit_;
00046 long timespan_;
00047 long last_window_start_;
00048 int count_;
00049 bool in_use_;
00050 };
00051
00052 #endif // artdaq_mfextensions_extensions_throttle_hh