From 381ca583d239fdc47a62fa1a8f49a47e1ce6dbf9 Mon Sep 17 00:00:00 2001 From: Lukasz Wlazly Date: Thu, 5 Oct 2017 09:50:10 +0200 Subject: [PATCH] Integration of AccessoriesSwitchProvider with e-mod-tizen-screen-reader AccessoriesSwitchProvider receives notificaton about pressed keys from enlightenment module via dbus instead of ecore events. Change-Id: Iffba114b5dfd370d4d890b82118a1b35f32ae940 --- src/AccessoriesSwitchProvider.cpp | 35 ++++++++------ src/AccessoriesSwitchProvider.hpp | 5 +- src/ScreenSwitchProvider.cpp | 10 ++-- src/ScreenSwitchProvider.hpp | 3 +- src/dbusLocators.hpp | 8 ++++ src/utils.cpp | 63 ++++++++++++++++++++++---- src/utils.hpp | 6 +-- tests/ui-scenarios/ActivityProcessingTests.cpp | 2 - tests/ui-scenarios/ActivityProcessingTests.hpp | 1 - tests/ui-scenarios/ConfigurationTests.cpp | 1 - tests/ui-scenarios/ConfigurationTests.hpp | 9 ++++ 11 files changed, 105 insertions(+), 38 deletions(-) diff --git a/src/AccessoriesSwitchProvider.cpp b/src/AccessoriesSwitchProvider.cpp index 565abce..2e926cc 100644 --- a/src/AccessoriesSwitchProvider.cpp +++ b/src/AccessoriesSwitchProvider.cpp @@ -1,6 +1,7 @@ #include "AccessoriesSwitchProvider.hpp" #include "UniversalSwitch.hpp" #include "VConfKeys.hpp" +#include "dbusLocators.hpp" AccessoriesSwitchProvider::AccessoriesSwitchProvider() : SwitchProvider("AccessoriesSwitchProvider"), keys( @@ -688,17 +689,22 @@ AccessoriesSwitchProvider::~AccessoriesSwitchProvider() void AccessoriesSwitchProvider::enable() { - mainWindow = Singleton::instance().getMainWindow(); - DEBUG("Main window acquired"); + DEBUG("invoked"); - if (!keyDownHandler.isSet()) - keyDownHandler.reset(ECORE_EVENT_KEY_DOWN, [this](Ecore_Event_Key * event) { - return processKeyDownEvent(event->key); + if (dbusClient) + return; + + DEBUG("turning on"); + + dbusClient = std::make_unique(dbusLocators::accessibilityEMod::BUS, dbusLocators::accessibilityEMod::OBJ_PATH, dbusLocators::accessibilityEMod::INTERFACE, DBus::ConnectionType::SYSTEM); + dbusClient->method(dbusLocators::accessibilityEMod::ACCESSORIES_SP_ENABLED).call(true); + + dbusClient->addSignal(dbusLocators::accessibilityEMod::KEY_DOWN_SIGNAL, [this](auto x) { + this->processKeyDownEvent(x); }); - if (!keyUpHandler.isSet()) - keyUpHandler.reset(ECORE_EVENT_KEY_UP, [this](Ecore_Event_Key * event) { - return processKeyUpEvent(event->key); + dbusClient->addSignal(dbusLocators::accessibilityEMod::KEY_UP_SIGNAL, [this](auto x) { + this->processKeyUpEvent(x); }); // Due to platform restrictions, vconf key used below is being set to 'true' only if hardware keyboard (either usb or bluetooth) started to input data @@ -711,11 +717,15 @@ void AccessoriesSwitchProvider::enable() void AccessoriesSwitchProvider::disable() { - mainWindow.reset(); - DEBUG("Main window released"); + DEBUG("invoked"); - keyDownHandler.reset(); - keyUpHandler.reset(); + if (!dbusClient) + return; + + DEBUG("turning off"); + + dbusClient->method(dbusLocators::accessibilityEMod::ACCESSORIES_SP_ENABLED).call(false); + dbusClient.reset(); if (switchInInteraction) interactionManager.stopInteraction(switchInInteraction); @@ -750,7 +760,6 @@ Eina_Bool AccessoriesSwitchProvider::processKeyDownEvent(const std::string &keyI return ECORE_CALLBACK_DONE; } - Eina_Bool AccessoriesSwitchProvider::processKeyUpEvent(const std::string &keyId) { DEBUG("key released: %s", keyId.c_str()); diff --git a/src/AccessoriesSwitchProvider.hpp b/src/AccessoriesSwitchProvider.hpp index 22ba20c..18000de 100644 --- a/src/AccessoriesSwitchProvider.hpp +++ b/src/AccessoriesSwitchProvider.hpp @@ -4,6 +4,7 @@ #include "SwitchProvider.hpp" #include "Window.hpp" #include "ecore.hpp" +#include "DBus.hpp" #include #include @@ -16,6 +17,7 @@ class AccessoriesSwitchProvider : public SwitchProvider, public std::enable_shar { public: AccessoriesSwitchProvider(); + AccessoriesSwitchProvider(AccessoriesSwitchProvider &&) = delete; ~AccessoriesSwitchProvider(); void enable() override; @@ -30,10 +32,9 @@ private: ecore::EventHandler keyDownHandler; ecore::EventHandler keyUpHandler; + std::unique_ptr dbusClient; VConfInterface::CallbackHandle onDisconnectionHandler; - std::shared_ptr mainWindow; - std::string currentKeyId; std::shared_ptr switchInInteraction; }; diff --git a/src/ScreenSwitchProvider.cpp b/src/ScreenSwitchProvider.cpp index 8675469..f0ec9a2 100644 --- a/src/ScreenSwitchProvider.cpp +++ b/src/ScreenSwitchProvider.cpp @@ -4,15 +4,15 @@ ScreenSwitchProvider::ScreenSwitchProvider() - : SwitchProvider("ScreenSwitchProvider"), dbus(dbusLocators::accessibilityEMod::BUS, dbusLocators::accessibilityEMod::OBJ_PATH, dbusLocators::accessibilityEMod::INTERFACE, DBus::ConnectionType::SYSTEM) + : SwitchProvider("ScreenSwitchProvider"), dbusClient(dbusLocators::accessibilityEMod::BUS, dbusLocators::accessibilityEMod::OBJ_PATH, dbusLocators::accessibilityEMod::INTERFACE, DBus::ConnectionType::SYSTEM) { switches.emplace_back(std::make_shared("touch", switchProviderId)); - dbus.addSignal("MouseDown", [this](auto x) { + dbusClient.addSignal(dbusLocators::accessibilityEMod::MOUSE_DOWN_SIGNAL, [this](auto x) { this->onTouch(x); }); - dbus.addSignal("MouseUp", [this](auto x) { + dbusClient.addSignal(dbusLocators::accessibilityEMod::MOUSE_UP_SIGNAL, [this](auto x) { this->onRelease(x); }); } @@ -24,12 +24,12 @@ ScreenSwitchProvider::~ScreenSwitchProvider() void ScreenSwitchProvider::enable() { - dbus.method("ScreenSwitchProviderEnabled").call(true); + dbusClient.method(dbusLocators::accessibilityEMod::SCREEN_SP_ENABLED).call(true); } void ScreenSwitchProvider::disable() { - dbus.method("ScreenSwitchProviderEnabled").call(false); + dbusClient.method(dbusLocators::accessibilityEMod::SCREEN_SP_ENABLED).call(false); interactionManager.stopInteraction(switches[0]); } diff --git a/src/ScreenSwitchProvider.hpp b/src/ScreenSwitchProvider.hpp index 9f83cd2..4567135 100644 --- a/src/ScreenSwitchProvider.hpp +++ b/src/ScreenSwitchProvider.hpp @@ -11,6 +11,7 @@ class ScreenSwitchProvider : public SwitchProvider { public: ScreenSwitchProvider(); + ScreenSwitchProvider(ScreenSwitchProvider &&) = delete; ~ScreenSwitchProvider(); void enable() override; @@ -22,7 +23,7 @@ private: static bool isSingleTouch(int deviceId); - DBus::DBusClient dbus; + DBus::DBusClient dbusClient; static constexpr int SINGLE_TOUCH = 0; //When event comes multitouch is recognized as touch with indexes higher than 0 }; diff --git a/src/dbusLocators.hpp b/src/dbusLocators.hpp index d21d843..fc07d8f 100644 --- a/src/dbusLocators.hpp +++ b/src/dbusLocators.hpp @@ -15,6 +15,14 @@ namespace dbusLocators static constexpr const char *BUS = "org.enlightenment.wm-screen-reader"; static constexpr const char *OBJ_PATH = "/org/tizen/GestureNavigation"; static constexpr const char *INTERFACE = "org.tizen.GestureNavigation"; + + static constexpr const char *ACCESSORIES_SP_ENABLED = "AccessoriesSwitchProviderEnabled"; + static constexpr const char *KEY_DOWN_SIGNAL = "KeyDown"; + static constexpr const char *KEY_UP_SIGNAL = "KeyUp"; + + static constexpr const char *SCREEN_SP_ENABLED = "ScreenSwitchProviderEnabled"; + static constexpr const char *MOUSE_DOWN_SIGNAL = "MouseDown"; + static constexpr const char *MOUSE_UP_SIGNAL = "MouseUp"; } } diff --git a/src/utils.cpp b/src/utils.cpp index ce3c4eb..a10e0d3 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -4,12 +4,53 @@ #include +#include + namespace utils { + class EflKeyInputGenerator + { + public: + EflKeyInputGenerator() + : handler(nullptr, efl_util_input_deinitialize_generator) + { + auto h = efl_util_input_initialize_generator(EFL_UTIL_INPUT_DEVTYPE_KEYBOARD); + + if (!h) + ERROR("No input generator"); + + handler.reset(h); + } + + void generateKeyDown(const std::string &id) + { + auto ret = efl_util_input_generate_key(handler.get(), id.c_str(), KEY_DOWN); + + if (ret != EFL_UTIL_ERROR_NONE) + ERROR("Event cannot be generated because %s", ret == EFL_UTIL_ERROR_INVALID_PARAMETER ? "invalid parameter" : "permission denied"); + } + + void generateKeyUp(const std::string &id) + { + auto ret = efl_util_input_generate_key(handler.get(), id.c_str(), KEY_UP); + + if (ret != EFL_UTIL_ERROR_NONE) + ERROR("Event cannot be generated because %s", ret == EFL_UTIL_ERROR_INVALID_PARAMETER ? "invalid parameter" : "permission denied"); + } + + private: + static constexpr int KEY_DOWN = 1; + static constexpr int KEY_UP = 0; + + std::unique_ptr<_efl_util_inputgen_h, int(*)(_efl_util_inputgen_h *)> handler; + }; + ecore::Timer EventGenerator::timer = {}; void EventGenerator::generateKeyPress(const std::string &keyId, unsigned multiplicity, PressType type) { + DEBUG("key: %s, multiplicity: %d", keyId.c_str(), multiplicity); + auto delay = 0.0; switch (type) { case PressType::SHORT: @@ -27,31 +68,35 @@ namespace utils GeneratorData genData{keyId, multiplicity, delay}; timer.reset(NO_DELAY, [genData]() { - return generateKeyDown(genData); + return createKeyDownEvent(genData); }); } - ecore::TimerRepetitionPolicy EventGenerator::generateKeyDown(GeneratorData genData) + ecore::TimerRepetitionPolicy EventGenerator::createKeyDownEvent(GeneratorData genData) { - auto inputgen = efl_util_input_initialize_generator(EFL_UTIL_INPUT_DEVTYPE_KEYBOARD); - efl_util_input_generate_key(inputgen, genData.key.c_str(), KEY_DOWN); + DEBUG("invoked"); + + EflKeyInputGenerator inputgen; + inputgen.generateKeyDown(genData.key); timer.reset(genData.releaseDelay, [genData]() { - return generateKeyUp(genData); + return createKeyUpEvent(genData); }); return ecore::TimerRepetitionPolicy::cancel; } - ecore::TimerRepetitionPolicy EventGenerator::generateKeyUp(GeneratorData genData) + ecore::TimerRepetitionPolicy EventGenerator::createKeyUpEvent(GeneratorData genData) { - auto inputgen = efl_util_input_initialize_generator(EFL_UTIL_INPUT_DEVTYPE_KEYBOARD); - efl_util_input_generate_key(inputgen, genData.key.c_str(), KEY_UP); + DEBUG("invoked"); + + EflKeyInputGenerator inputgen; + inputgen.generateKeyUp(genData.key); --(genData.multiplicity); if (genData.multiplicity > 0) timer.reset(SHORT_DELAY, [genData]() { - return generateKeyDown(genData); + return createKeyDownEvent(genData); }); return ecore::TimerRepetitionPolicy::cancel; diff --git a/src/utils.hpp b/src/utils.hpp index 1fd52e8..b0daad0 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -35,14 +35,12 @@ namespace utils static void generateKeyPress(const std::string &keyId, unsigned multiplicity = SINGLE_PRESS, PressType type = PressType::SHORT); private: - static ecore::TimerRepetitionPolicy generateKeyDown(GeneratorData genData); - static ecore::TimerRepetitionPolicy generateKeyUp(GeneratorData genData); + static ecore::TimerRepetitionPolicy createKeyDownEvent(GeneratorData genData); + static ecore::TimerRepetitionPolicy createKeyUpEvent(GeneratorData genData); static ecore::Timer timer; static constexpr unsigned SINGLE_PRESS = 1; - static constexpr int KEY_DOWN = 1; - static constexpr int KEY_UP = 0; static constexpr double SHORT_DELAY = 0.1; static constexpr double LONG_DELAY = 1.0; static constexpr double NO_DELAY = 0.0; diff --git a/tests/ui-scenarios/ActivityProcessingTests.cpp b/tests/ui-scenarios/ActivityProcessingTests.cpp index 11f3f38..5156291 100644 --- a/tests/ui-scenarios/ActivityProcessingTests.cpp +++ b/tests/ui-scenarios/ActivityProcessingTests.cpp @@ -70,5 +70,3 @@ TEST_F(ActivityProcessingFixture, ActivityAbandoned) ASSERT_NE(activity, nullptr); EXPECT_EQ(activity->getType(), "TWO_STEP_PROCESS_ACTIVITY"); } - - diff --git a/tests/ui-scenarios/ActivityProcessingTests.hpp b/tests/ui-scenarios/ActivityProcessingTests.hpp index 6bab73e..a69ebae 100644 --- a/tests/ui-scenarios/ActivityProcessingTests.hpp +++ b/tests/ui-scenarios/ActivityProcessingTests.hpp @@ -24,7 +24,6 @@ public: void initialEnvironmentExpect() { simulateKeyPress(keyMappedToTwoStepProcessActivity_); - runMainLoop(); EXPECT_EQ(switchManager_->updatedWithSwitch, 1); } diff --git a/tests/ui-scenarios/ConfigurationTests.cpp b/tests/ui-scenarios/ConfigurationTests.cpp index a5d4ea6..e7dff76 100644 --- a/tests/ui-scenarios/ConfigurationTests.cpp +++ b/tests/ui-scenarios/ConfigurationTests.cpp @@ -68,4 +68,3 @@ TEST_F(ConfigurationTestsFixture, MappingAddedAndUpdated_BeUpdatedWithNewValue) if (switchManager->receivedItem) EXPECT_EQ(switchManager->receivedItem->getId()->getGlobalId(), switchId_); } - diff --git a/tests/ui-scenarios/ConfigurationTests.hpp b/tests/ui-scenarios/ConfigurationTests.hpp index c1f022c..efef650 100644 --- a/tests/ui-scenarios/ConfigurationTests.hpp +++ b/tests/ui-scenarios/ConfigurationTests.hpp @@ -11,6 +11,7 @@ #include "SwitchManager.hpp" #include "ActivityFactory.hpp" #include "utils.hpp" +#include "dbusLocators.hpp" #include @@ -53,6 +54,8 @@ public: void SetUp() { + dbusClient = std::make_unique(dbusLocators::accessibilityEMod::BUS, dbusLocators::accessibilityEMod::OBJ_PATH, dbusLocators::accessibilityEMod::INTERFACE, DBus::ConnectionType::SYSTEM); + dbusClient->method(dbusLocators::accessibilityEMod::ACCESSORIES_SP_ENABLED).call(true); auto SQLiteConfig = std::make_shared(true); SQLiteConfig->clearTable(); configuration_ = SQLiteConfig; @@ -71,6 +74,11 @@ public: item_ = std::make_shared(switch_->getId()->getGlobalId(), activityType_); } + void TearDown() + { + dbusClient->method(dbusLocators::accessibilityEMod::ACCESSORIES_SP_ENABLED).call(false); + } + void simulateKeyPress(const std::string &key) { EXPECT_TRUE(ecore_timer_add(SMALL_DELAY_, addEventCb, key.c_str())); @@ -102,6 +110,7 @@ protected: std::shared_ptr activityFactory_; std::shared_ptr switch_; std::shared_ptr item_; + std::unique_ptr dbusClient; std::string key_ = "Down"; std::string switchId_ = "AccessoriesSwitchProvider_Down"; std::string activityType_ = "TWO_STEP_PROCESS_ACTIVITY"; -- 2.7.4