Skip to content
Snippets Groups Projects
Commit 373fbe2f authored by Simon Oehrl's avatar Simon Oehrl
Browse files

Add GetNextEvent() and GetNextEventOfType() methods

parent e088933f
No related branches found
No related tags found
No related merge requests found
......@@ -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_;
......
......@@ -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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment