Key event generator with e-mod method 30/169830/5
authorLukasz Wlazly <l.wlazly@partner.samsung.com>
Fri, 9 Feb 2018 12:58:45 +0000 (13:58 +0100)
committerLukasz Oleksak <l.oleksak@samsung.com>
Wed, 14 Feb 2018 10:06:27 +0000 (10:06 +0000)
This solution enables synchronous dispatching
of key events

Change-Id: If09762f767f28772e0210d496691cd2649a1ff86

src/GestureActivity.cpp
src/HardwareKeyActivity.cpp
src/RowScanner.cpp
src/utils.cpp
src/utils.hpp
tests/ui-scenarios/ConfigurationTests.hpp

index 51b6c12..33120d0 100644 (file)
@@ -93,7 +93,7 @@ public:
        {
                ASSERT(uiElements.size() == requiredArguments);
                auto coord = uiElements.front()->getScanningCoordinates();
-               return utils::EventGenerator::generateTapGesture(coord.x, coord.y, DerivedType::hold_time);
+               return utils::generateTapGesture(coord.x, coord.y, DerivedType::hold_time);
        }
 };
 
@@ -126,7 +126,7 @@ public:
                auto from = getStartPoint();
                auto to = getEndPoint();
 
-               return utils::EventGenerator::generateDragGesture(from.x, from.y, to.x, to.y, DEFAULT_STEPS_NUMBER, NO_DELAY);
+               return utils::generateDragGesture(from.x, from.y, to.x, to.y, DEFAULT_STEPS_NUMBER, NO_DELAY);
        }
 
 protected:
@@ -243,7 +243,7 @@ public:
                auto from = uiElements.front()->getScanningCoordinates();
                auto to = uiElements.back()->getScanningCoordinates();
 
-               return utils::EventGenerator::generateDragGesture(from.x, from.y, to.x, to.y, DerivedType::steps, DerivedType::hold_time);
+               return utils::generateDragGesture(from.x, from.y, to.x, to.y, DerivedType::steps, DerivedType::hold_time);
        }
 };
 
@@ -276,7 +276,7 @@ public:
                ASSERT(GestureDispatcher<DerivedType>::uiElements.size() == requiredArguments);
                auto coord = GestureDispatcher<DerivedType>::uiElements.front()->getScanningCoordinates();
 
-               return utils::EventGenerator::generatePinchGesture(coord.x, coord.y, DerivedType::radius_change, DEFAULT_STEPS_NUMBER);
+               return utils::generatePinchGesture(coord.x, coord.y, DerivedType::radius_change, DEFAULT_STEPS_NUMBER);
        }
 };
 
index dc5b6cd..f00ad32 100644 (file)
@@ -30,7 +30,12 @@ public:
 
        void process(DoneCallback doneCb) override
        {
-               utils::EventGenerator::generateKeyPress(DerivedType::buttonCode, std::move(doneCb), DerivedType::multiplicity);
+               auto res = utils::generateKeyPress(DerivedType::buttonCode, DerivedType::multiplicity);
+
+               if (res)
+                       doneCb.callAfterTimeElapsed(sideEffectDelays::eModGesture);
+               else
+                       ERROR("%s", res.getError().message.c_str());
                markAsCompleted();
        }
 };
index 27665ef..7045a6f 100644 (file)
@@ -192,10 +192,7 @@ void RowScannerImpl::acceptAutoscanningPhase(std::function<void(Optional<std::sh
                if (!currentNavState.childIndex) {
                        if (currentNavState.parent == rootNavigationElement) {
                                if (properties.isEscapeFrameEnabled()) {
-                                       utils::EventGenerator::generateKeyPress(BACK_BUTTON_CODE,
-                                       DoneCallback{[callback = std::move(callback)] {
-                                                       callback({});
-                                               } });
+                                       utils::generateKeyPress(BACK_BUTTON_CODE);
                                        eraseFrame();
                                        state = State::END;
                                } else {
index 2ee6eb3..278b451 100644 (file)
 
 namespace utils
 {
-       class EflKeyInputGenerator
+       DBus::ValueOrError<void> generateKeyPress(const std::string &keyId, unsigned multiplicity, double hold_time)
        {
-       public:
-               EflKeyInputGenerator()
-                       : handler(nullptr, efl_util_input_deinitialize_generator)
-               {
-                       auto h = efl_util_input_initialize_generator(EFL_UTIL_INPUT_DEVTYPE_KEYBOARD);
+               DEBUG("Key event, name: %s, multiplicity: %d, hold_time: %lf", keyId.c_str(), multiplicity, hold_time);
 
-                       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, DoneCallback doneCb, unsigned multiplicity, PressType type)
-       {
-               DEBUG("key: %s, multiplicity: %d", keyId.c_str(), multiplicity);
-
-               auto delay = 0.0;
-               switch (type) {
-               case PressType::SHORT:
-                       delay = SHORT_DELAY;
-                       break;
-
-               case PressType::LONG:
-                       delay = LONG_DELAY;
-                       break;
-
-               default:
-                       ASSERT(0, "Invalid press type");
-               }
-
-               GeneratorData genData{keyId, multiplicity, delay};
-
-               timer.reset(NO_DELAY, [genData, doneCb = std::move(doneCb)]() {
-                       return createKeyDownEvent(genData, std::move(doneCb));
-               });
+               DBus::DBusClient dbus {dbusLocators::accessibilityEMod::BUS,
+                                                          dbusLocators::accessibilityEMod::OBJ_PATH,
+                                                          dbusLocators::accessibilityEMod::INTERFACE,
+                                                          DBus::ConnectionType::SYSTEM};
+               return dbus.method<void(std::string, int, double)>("DispatchKeyEvent").call(keyId, static_cast<int>(multiplicity), hold_time);
        }
 
-       DBus::ValueOrError<void> EventGenerator::generateTapGesture(int x, int y, double press_time)
+       DBus::ValueOrError<void> generateTapGesture(int x, int y, double press_time)
        {
                DEBUG("Tap with drag gesture, x: %d, y: %d, press time: %lf", x, y, press_time);
 
@@ -105,7 +52,7 @@ namespace utils
                return dbus.method<void(int, int, int, int, int, double)>("DispatchDragEvent").call(x, y, x, y, tap_steps, press_time);
        }
 
-       DBus::ValueOrError<void> EventGenerator::generateDragGesture(int from_x, int from_y, int to_x, int to_y, int steps, double hold_time)
+       DBus::ValueOrError<void> generateDragGesture(int from_x, int from_y, int to_x, int to_y, int steps, double hold_time)
        {
                DEBUG("Drag gesture, from (x, y): (%d, %d), to (x, y): (%d, %d), steps: %d, hold on first time: %lf", from_x, from_y, to_x, to_y, steps, hold_time);
 
@@ -116,7 +63,7 @@ namespace utils
                return dbus.method<void(int, int, int, int, int, double)>("DispatchDragEvent").call(from_x, from_y, to_x, to_y, steps, hold_time);
        }
 
-       DBus::ValueOrError<void> EventGenerator::generatePinchGesture(int x, int y, int radius_change, int steps)
+       DBus::ValueOrError<void> generatePinchGesture(int x, int y, int radius_change, int steps)
        {
                DEBUG("Pinch gesture, x: %d, y: %d, radius change: %d, steps: %d", x, y, radius_change, steps);
 
@@ -127,36 +74,6 @@ namespace utils
                return dbus.method<void(int, int, int, int)>("DispatchPinchEvent").call(x, y, radius_change, steps);
        }
 
-       ecore::TimerRepetitionPolicy EventGenerator::createKeyDownEvent(GeneratorData genData, DoneCallback doneCb)
-       {
-               DEBUG("invoked");
-
-               EflKeyInputGenerator inputgen;
-               inputgen.generateKeyDown(genData.key);
-
-               timer.reset(genData.releaseDelay, [genData, doneCb = std::move(doneCb)]() {
-                       return createKeyUpEvent(genData, std::move(doneCb));
-               });
-
-               return ecore::TimerRepetitionPolicy::cancel;
-       }
-
-       ecore::TimerRepetitionPolicy EventGenerator::createKeyUpEvent(GeneratorData genData, DoneCallback doneCb)
-       {
-               DEBUG("invoked");
-
-               EflKeyInputGenerator inputgen;
-               inputgen.generateKeyUp(genData.key);
-
-               --(genData.multiplicity);
-               if (genData.multiplicity > 0)
-                       timer.reset(SHORT_DELAY, [genData, doneCb = std::move(doneCb)]() {
-                       return createKeyDownEvent(genData, std::move(doneCb));
-               });
-
-               return ecore::TimerRepetitionPolicy::cancel;
-       }
-
        std::array<Optional<std::string>, (size_t)Argument::_count> parseArguments(int argc, char **argv)
        {
                auto b = std::unique_ptr<bundle, int(*)(bundle *)>(bundle_import_from_argv(argc, argv), bundle_free);
index 80ea7c6..5883b34 100644 (file)
@@ -61,38 +61,10 @@ namespace utils
                return v;
        }
 
-       class EventGenerator
-       {
-       public:
-               enum class PressType {
-                       SHORT,
-                       LONG
-               };
-
-               struct GeneratorData {
-                       std::string key;
-                       unsigned multiplicity;
-                       double releaseDelay;
-               };
-
-               static void generateKeyPress(const std::string &keyId, DoneCallback doneCb, unsigned multiplicity = SINGLE_PRESS,
-                                                                        PressType type = PressType::SHORT);
-
-               static DBus::ValueOrError<void> generateTapGesture(int x, int y, double press_time);
-               static DBus::ValueOrError<void> generateDragGesture(int from_x, int from_y, int to_x, int to_y, int steps, double hold_time);
-               static DBus::ValueOrError<void> generatePinchGesture(int x, int y, int radius_change, int steps);
-
-       private:
-               static ecore::TimerRepetitionPolicy createKeyDownEvent(GeneratorData genData, DoneCallback doneCb);
-               static ecore::TimerRepetitionPolicy createKeyUpEvent(GeneratorData genData, DoneCallback doneCb);
-
-               static ecore::Timer timer;
-
-               static constexpr unsigned SINGLE_PRESS = 1;
-               static constexpr double SHORT_DELAY = 0.1;
-               static constexpr double LONG_DELAY = 1.0;
-               static constexpr double NO_DELAY = 0.0;
-       };
+       DBus::ValueOrError<void> generateKeyPress(const std::string &keyId, unsigned multiplicity = 1, double hold_time = 0.0);
+       DBus::ValueOrError<void> generateTapGesture(int x, int y, double press_time);
+       DBus::ValueOrError<void> generateDragGesture(int from_x, int from_y, int to_x, int to_y, int steps, double hold_time);
+       DBus::ValueOrError<void> generatePinchGesture(int x, int y, int radius_change, int steps);
 
        /**
         * @brief Enum representing allowed arguments
index 3c11d9f..61d43a0 100644 (file)
@@ -85,7 +85,9 @@ public:
        void simulateKeyPress(const std::string &key)
        {
                eventTimer.reset(SMALL_DELAY_, [&key]() {
-                       utils::EventGenerator::generateKeyPress(key, {});
+                       auto res = utils::generateKeyPress(key);
+                       if (!res)
+                               ERROR("%s", res.getError().message.c_str());
                        return ecore::TimerRepetitionPolicy::cancel;
                });
                mainloopTimer.reset(ESTIMATED_TIME_REQUIRED_TO_SAFELY_PASSING_THROUGH_TESTS_, []() {