diff --git a/webstreamer/include/webstreamer/input_processor.hpp b/webstreamer/include/webstreamer/input_processor.hpp index 663eb09327c226c89b1fced61a1572ae9fbc31ed..5157e466692c0ee87cfdc9efd6ba7802593c58dd 100644 --- a/webstreamer/include/webstreamer/input_processor.hpp +++ b/webstreamer/include/webstreamer/input_processor.hpp @@ -57,6 +57,9 @@ class WEBSTREAMER_EXPORT SynchronousInputProcessor : public InputProcessor { void ProcessInput(); + Event::Ptr GetNextEvent(); + Event::Ptr GetNextEventOfType(EventType type); + protected: std::mutex events_mutex_; std::vector<Event::Ptr> events_; diff --git a/webstreamer/src/input_processor.cpp b/webstreamer/src/input_processor.cpp index ce9dfe5d9c0ba4746f052e0d5e25a64dbc1ddff2..a799ba3c3aac64f3bef8a0784f32cbf4acb4b6ed 100644 --- a/webstreamer/src/input_processor.cpp +++ b/webstreamer/src/input_processor.cpp @@ -64,6 +64,33 @@ void SynchronousInputProcessor::ProcessInput() { events_.clear(); } +Event::Ptr SynchronousInputProcessor::GetNextEvent() { + std::lock_guard<std::mutex> lock(events_mutex_); + if (events_.empty()) { + return Event::Ptr{}; + } else { + Event::Ptr event = std::move(events_.front()); + events_.erase(events_.begin()); // Not very efficient, but the vector + // should be usually very small so only + // few elements have to be copied. + return event; + } +} + +Event::Ptr SynchronousInputProcessor::GetNextEventOfType(EventType type) { + std::lock_guard<std::mutex> lock(events_mutex_); + for (auto i = events_.begin(); i != events_.end(); ++i) { + if (i->get()->type() == type) { + Event::Ptr event = std::move(*i); + events_.erase(i); // Not very efficient, but the vector + // should be usually very small so only + // few elements have to be copied. + return event; + } + } + return Event::Ptr{}; +} + void AsynchronousInputProcessor::PushEvent(Event::Ptr event) { ProcessEvent(*event); }