From b0b6fe33c99b1caae8aec3992e6f5f27fcbf5b19 Mon Sep 17 00:00:00 2001 From: Gabriel Ozouf Date: Tue, 6 Oct 2020 16:11:28 +0200 Subject: [PATCH] [ion/events] Factor includes of layout_events.h Change-Id: Id7f68f4dfb4727453a02437a0b824492a8c94730 --- ion/include/ion/events.h | 3 +++ ion/src/device/shared/events.cpp | 12 ++---------- ion/src/shared/events.cpp | 15 +++++++++++++++ ion/src/simulator/shared/events.cpp | 17 ++++++----------- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/ion/include/ion/events.h b/ion/include/ion/events.h index 12079586a..fdffb1cef 100644 --- a/ion/include/ion/events.h +++ b/ion/include/ion/events.h @@ -36,6 +36,9 @@ public: bool isDefined() const; static constexpr int PageSize = Keyboard::NumberOfKeys; private: + bool defaultIsDefined() const; + const char * defaultText() const; + uint8_t m_id; }; diff --git a/ion/src/device/shared/events.cpp b/ion/src/device/shared/events.cpp index 12cb1c272..c19b6b12d 100644 --- a/ion/src/device/shared/events.cpp +++ b/ion/src/device/shared/events.cpp @@ -1,5 +1,4 @@ #include -#include namespace Ion { namespace Events { @@ -8,18 +7,11 @@ void didPressNewKey() { } bool Event::isDefined() const { - if (isKeyboardEvent()) { - return s_dataForEvent[m_id].isDefined(); - } else { - return (*this == None || *this == Termination || *this == USBEnumeration || *this == USBPlug || *this == BatteryCharging); - } + return defaultIsDefined(); } const char * Event::text() const { - if (m_id >= 4*PageSize) { - return nullptr; - } - return s_dataForEvent[m_id].text(); + return defaultText(); } } diff --git a/ion/src/shared/events.cpp b/ion/src/shared/events.cpp index d09501822..7346afd09 100644 --- a/ion/src/shared/events.cpp +++ b/ion/src/shared/events.cpp @@ -52,5 +52,20 @@ bool Event::hasText() const { return text() != nullptr; } +bool Event::defaultIsDefined() const { + if (isKeyboardEvent()) { + return s_dataForEvent[m_id].isDefined(); + } else { + return (*this == None || *this == Termination || *this == USBEnumeration || *this == USBPlug || *this == BatteryCharging); + } +} + +const char * Event::defaultText() const { + if (m_id >= 4*PageSize) { + return nullptr; + } + return s_dataForEvent[m_id].text(); +} + } } diff --git a/ion/src/simulator/shared/events.cpp b/ion/src/simulator/shared/events.cpp index 5fb318e73..e2e3e766a 100644 --- a/ion/src/simulator/shared/events.cpp +++ b/ion/src/simulator/shared/events.cpp @@ -1,7 +1,6 @@ #include "events.h" #include "haptics.h" #include -#include #include namespace Ion { @@ -17,21 +16,17 @@ char * sharedExternalTextBuffer() { } const char * Event::text() const { - if (m_id >= 4*PageSize) { - if (*this == ExternalText) { - return const_cast(sharedExternalTextBuffer()); - } - return nullptr; + if (*this == ExternalText) { + return const_cast(sharedExternalTextBuffer()); } - return s_dataForEvent[m_id].text(); + return defaultText(); } bool Event::isDefined() const { - if (isKeyboardEvent()) { - return s_dataForEvent[m_id].isDefined(); - } else { - return (*this == None || *this == Termination || *this == USBEnumeration || *this == USBPlug || *this == BatteryCharging || *this == ExternalText); + if (*this == ExternalText) { + return true; } + return defaultIsDefined(); } }