Add return value validation in GestureActivity 51/169151/2
authorLukasz Wlazly <l.wlazly@partner.samsung.com>
Fri, 2 Feb 2018 12:34:51 +0000 (13:34 +0100)
committerLukasz Wlazly <l.wlazly@partner.samsung.com>
Mon, 5 Feb 2018 11:40:10 +0000 (12:40 +0100)
Because e-mod call may fail, return value is checked
and proper error message is added to log

Change-Id: I0f42d2b3f9bfdf5ec4972f91a0f30a9e3e2db8eb

src/GestureActivity.cpp
src/utils.cpp
src/utils.hpp

index 581a286..e5cf1a8 100644 (file)
@@ -80,8 +80,12 @@ public:
                timer.reset(NO_DELAY, [this, doneCb = std::move(doneCb)]() {
                        ASSERT(uiElements.size() == requiredArguments);
                        auto coord = uiElements.front()->getScanningCoordinates();
-                       utils::EventGenerator::generateTapGesture(coord.x, coord.y, DerivedType::hold_time);
-                       doneCb.callAfterTimeElapsed(sideEffectDelays::eModGesture);
+                       auto res = utils::EventGenerator::generateTapGesture(coord.x, coord.y, DerivedType::hold_time);
+                       if (res) {
+                               doneCb.callAfterTimeElapsed(sideEffectDelays::eModGesture);
+                       } else {
+                               ERROR("%s", res.getError().message.c_str());
+                       }
                        markAsCompleted();
                        return ecore::TimerRepetitionPolicy::cancel;
                });
@@ -119,8 +123,13 @@ public:
                        auto from = getStartPoint();
                        auto to = getEndPoint();
 
-                       utils::EventGenerator::generateDragGesture(from.x, from.y, to.x, to.y, DEFAULT_STEPS_NUMBER, NO_DELAY);
-                       doneCb.callAfterTimeElapsed(sideEffectDelays::eModGesture);
+                       auto res = utils::EventGenerator::generateDragGesture(from.x, from.y, to.x, to.y, DEFAULT_STEPS_NUMBER, NO_DELAY);
+                       if (res) {
+                               doneCb.callAfterTimeElapsed(sideEffectDelays::eModGesture);
+                       } else {
+                               ERROR("%s", res.getError().message.c_str());
+                       }
+
                        markAsCompleted();
                        return ecore::TimerRepetitionPolicy::cancel;
                });
@@ -242,8 +251,13 @@ public:
                        auto from = uiElements.front()->getScanningCoordinates();
                        auto to = uiElements.back()->getScanningCoordinates();
 
-                       utils::EventGenerator::generateDragGesture(from.x, from.y, to.x, to.y, DerivedType::steps, DerivedType::hold_time);
-                       doneCb.callAfterTimeElapsed(sideEffectDelays::eModGesture);
+                       auto res = utils::EventGenerator::generateDragGesture(from.x, from.y, to.x, to.y, DerivedType::steps, DerivedType::hold_time);
+                       if (res) {
+                               doneCb.callAfterTimeElapsed(sideEffectDelays::eModGesture);
+                       } else {
+                               ERROR("%s", res.getError().message.c_str());
+                       }
+
                        markAsCompleted();
                        return ecore::TimerRepetitionPolicy::cancel;
                });
@@ -281,8 +295,13 @@ public:
                        ASSERT(GestureDispatcher<DerivedType>::uiElements.size() == requiredArguments);
                        auto coord = GestureDispatcher<DerivedType>::uiElements.front()->getScanningCoordinates();
 
-                       utils::EventGenerator::generatePinchGesture(coord.x, coord.y, DerivedType::radius_change, DEFAULT_STEPS_NUMBER);
-                       doneCb.callAfterTimeElapsed(sideEffectDelays::eModGesture);
+                       auto res = utils::EventGenerator::generatePinchGesture(coord.x, coord.y, DerivedType::radius_change, DEFAULT_STEPS_NUMBER);
+                       if (res) {
+                               doneCb.callAfterTimeElapsed(sideEffectDelays::eModGesture);
+                       } else {
+                               ERROR("%s", res.getError().message.c_str());
+                       }
+
                        markAsCompleted();
                        return ecore::TimerRepetitionPolicy::cancel;
                });
index 535b200..9051292 100644 (file)
@@ -18,7 +18,6 @@
 
 #include "UniversalSwitchLog.hpp"
 #include "DoneCallback.hpp"
-#include "DBus.hpp"
 #include "dbusLocators.hpp"
 
 #include <efl_util.h>
@@ -93,7 +92,7 @@ namespace utils
                });
        }
 
-       void EventGenerator::generateTapGesture(int x, int y, double press_time)
+       DBus::ValueOrError<void> EventGenerator::generateTapGesture(int x, int y, double press_time)
        {
                DEBUG("Tap with drag gesture, x: %d, y: %d, press time: %d", x, y, press_time);
 
@@ -103,11 +102,10 @@ namespace utils
                                                           DBus::ConnectionType::SYSTEM};
 
                static auto tap_steps = 1;
-               dbus.method<void(int, int, int, int, int, double)>("DispatchDragEvent").
-               call(x, y, x, y, tap_steps, press_time); //TODO: const for steps number
+               return dbus.method<void(int, int, int, int, int, double)>("DispatchDragEvent").call(x, y, x, y, tap_steps, press_time);
        }
 
-       void EventGenerator::generateDragGesture(int from_x, int from_y, int to_x, int to_y, int steps, double hold_time)
+       DBus::ValueOrError<void> EventGenerator::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);
 
@@ -115,11 +113,10 @@ namespace utils
                                                           dbusLocators::accessibilityEMod::OBJ_PATH,
                                                           dbusLocators::accessibilityEMod::INTERFACE,
                                                           DBus::ConnectionType::SYSTEM};
-               dbus.method<void(int, int, int, int, int, double)>("DispatchDragEvent").
-               call(from_x, from_y, to_x, to_y, steps, hold_time);
+               return dbus.method<void(int, int, int, int, int, double)>("DispatchDragEvent").call(from_x, from_y, to_x, to_y, steps, hold_time);
        }
 
-       void EventGenerator::generatePinchGesture(int x, int y, int radius_change, int steps)
+       DBus::ValueOrError<void> EventGenerator::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,8 +124,7 @@ namespace utils
                                                           dbusLocators::accessibilityEMod::OBJ_PATH,
                                                           dbusLocators::accessibilityEMod::INTERFACE,
                                                           DBus::ConnectionType::SYSTEM};
-               dbus.method<void(int, int, int, int)>("DispatchPinchEvent").
-               call(x, y, radius_change, steps);
+               return dbus.method<void(int, int, int, int)>("DispatchPinchEvent").call(x, y, radius_change, steps);
        }
 
        ecore::TimerRepetitionPolicy EventGenerator::createKeyDownEvent(GeneratorData genData, DoneCallback doneCb)
index 2294af8..80ea7c6 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "ecore.hpp"
 #include "Optional.hpp"
+#include "DBus.hpp"
 
 #include <string>
 #include <array>
@@ -77,9 +78,9 @@ namespace utils
                static void generateKeyPress(const std::string &keyId, DoneCallback doneCb, unsigned multiplicity = SINGLE_PRESS,
                                                                         PressType type = PressType::SHORT);
 
-               static void generateTapGesture(int x, int y, double press_time);
-               static void generateDragGesture(int from_x, int from_y, int to_x, int to_y, int steps, double hold_time);
-               static void generatePinchGesture(int x, int y, int radius_change, int steps);
+               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);