diff --git a/ion/include/ion/events.h b/ion/include/ion/events.h index 6c1c64d76..c5a5fae5b 100644 --- a/ion/include/ion/events.h +++ b/ion/include/ion/events.h @@ -57,6 +57,7 @@ class Journal { public: virtual void pushEvent(Event e) = 0; virtual Event popEvent() = 0; + virtual bool isEmpty() = 0; }; void replayFrom(Journal * l); diff --git a/ion/src/shared/events_keyboard.cpp b/ion/src/shared/events_keyboard.cpp index c368b785e..fe0825a4b 100644 --- a/ion/src/shared/events_keyboard.cpp +++ b/ion/src/shared/events_keyboard.cpp @@ -125,11 +125,10 @@ void logTo(Journal * l) { sDestinationJournal = l; } Event getEvent(int * timeout) { if (sSourceJournal != nullptr) { - Event e = sSourceJournal->popEvent(); - if (e == None) { + if (sSourceJournal->isEmpty()) { sSourceJournal = nullptr; } else { - return e; + return sSourceJournal->popEvent(); } } Event e = innerGetEvent(timeout); diff --git a/ion/src/simulator/shared/journal.cpp b/ion/src/simulator/shared/journal.cpp index f6112d48c..8677fb40c 100644 --- a/ion/src/simulator/shared/journal.cpp +++ b/ion/src/simulator/shared/journal.cpp @@ -12,10 +12,16 @@ public: m_eventStorage.push(e); } virtual Event popEvent() override { + if (isEmpty()) { + return Ion::Events::None; + } Event e = m_eventStorage.front(); m_eventStorage.pop(); return e; } + virtual bool isEmpty() override { + return m_eventStorage.empty(); + } private: std::queue m_eventStorage; };