summaryrefslogtreecommitdiff
path: root/src/lib/event_history.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2017-05-09 16:38:36 +0100
committerCarl Hetherington <cth@carlh.net>2017-05-09 16:38:36 +0100
commit6a11232620e0006f6a2b1e8d2b56e56d84229d5c (patch)
tree5ea8d25d95aac54dbf7e45fa72c50215ff5fc437 /src/lib/event_history.cc
parent837a54744277a5252a1a69b0690305e9a669124d (diff)
Basic GUI for export.
Diffstat (limited to 'src/lib/event_history.cc')
-rw-r--r--src/lib/event_history.cc56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/lib/event_history.cc b/src/lib/event_history.cc
new file mode 100644
index 000000000..eb3438aab
--- /dev/null
+++ b/src/lib/event_history.cc
@@ -0,0 +1,56 @@
+/*
+ Copyright (C) 2017 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "event_history.h"
+#include "util.h"
+#include <boost/thread/mutex.hpp>
+
+EventHistory::EventHistory (int size)
+ : _size (size)
+{
+
+}
+
+float
+EventHistory::rate () const
+{
+ boost::mutex::scoped_lock lock (_mutex);
+ if (int (_history.size()) < _size) {
+ return 0;
+ }
+
+ struct timeval now;
+ gettimeofday (&now, 0);
+
+ return _size / (seconds (now) - seconds (_history.back ()));
+}
+
+void
+EventHistory::event ()
+{
+ boost::mutex::scoped_lock lock (_mutex);
+
+ struct timeval tv;
+ gettimeofday (&tv, 0);
+ _history.push_front (tv);
+ if (int (_history.size()) > _size) {
+ _history.pop_back ();
+ }
+}