aurum: rework touch command to support multi touch
authorWonki Kim <wonki_.kim@samsung.com>
Tue, 23 Jun 2020 09:15:05 +0000 (18:15 +0900)
committerJongmin Lee <jm105.lee@samsung.com>
Sun, 28 Jun 2020 23:59:14 +0000 (08:59 +0900)
when user call touchDown command, it will return touch sequenceId.
and touchMove and touchUp commands should be called with it.

if user call touchDown twice, the user gets 2 touch seq ids.
user can manipulate multi touch with them.

Change-Id: I6c6fdcdec4c14b2c547f167a9184427e7eda217a

libaurum/inc/DeviceImpl/TizenImpl.h
libaurum/inc/IDevice.h
libaurum/inc/UiDevice.h
libaurum/src/DeviceImpl/TizenImpl.cc
libaurum/src/UiDevice.cc
org.tizen.aurum-bootstrap/src/Commands/TouchDownCommand.cc
org.tizen.aurum-bootstrap/src/Commands/TouchMoveCommand.cc
org.tizen.aurum-bootstrap/src/Commands/TouchUpCommand.cc
protocol/examples/python/testFeatures.py
protocol/examples/python/testInternal.py

index 4aa0468..d9ea2ce 100644 (file)
@@ -3,6 +3,7 @@
 #include "config.h"
 
 #include "IDevice.h"
+#include <set>
 
 #ifdef GBS_BUILD
 #include <efl_util.h>
@@ -22,9 +23,9 @@ public:
     bool drag(const int sx, const int sy, const int ex, const int ey,
               const int steps, const int durationMs) override;
 
-    bool touchDown(const int x, const int y) override;
-    bool touchMove(const int x, const int y) override;
-    bool touchUp(const int x, const int y) override;
+    int touchDown(const int x, const int y) override;
+    bool touchMove(const int x, const int y, const int seq) override;
+    bool touchUp(const int x, const int y, const int seq) override;
 
     bool wheelUp(int amount, const int durationMs) override;
     bool wheelDown(int amount, const int durationMs) override;
@@ -44,6 +45,9 @@ protected:
     bool pressKeyCode(std::string keycode);
     bool releaseKeyCode(std::string keycode);
 
+    int grabTouchSeqNumber();
+    bool releaseTouchSeqNumber(int seq);
+
 private:
     void startTimer(void);
     int stopTimer(void);
@@ -60,9 +64,12 @@ private:
     static const unsigned int INTV_MINIMUM_USLEEP = 1000;
     static const unsigned int MINIMUM_DURATION_DRAG = 100;
     static const unsigned int MSEC_PER_SEC = 1000;
+    static const unsigned int MAX_FINGER_NUMBER = 2;
 
     struct timespec tStart;
     bool isTimerStarted;
+
+    std::set<int> mTouchSeq;
 };
 
 #endif
\ No newline at end of file
index 46cdc6a..edee43b 100644 (file)
@@ -59,19 +59,19 @@ public:
      * @brief TBD
      * @since_tizen 5.5
      */
-    virtual bool touchDown(const int x, const int y) = 0;
+    virtual int touchDown(const int x, const int y) = 0;
 
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    virtual bool touchMove(const int x, const int y) = 0;
+    virtual bool touchMove(const int x, const int y, const int seq) = 0;
 
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    virtual bool touchUp(const int x, const int y) = 0;
+    virtual bool touchUp(const int x, const int y, const int seq) = 0;
 
     /**
      * @brief TBD
index 2180363..9ed7e1f 100644 (file)
@@ -50,19 +50,19 @@ public:
      * @brief TBD
      * @since_tizen 5.5
      */
-    bool touchDown(const int x, const int y) override;
+    int touchDown(const int x, const int y) override;
 
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    bool touchMove(const int x, const int y) override;
+    bool touchMove(const int x, const int y, const int seq) override;
 
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    bool touchUp(const int x, const int y) override;
+    bool touchUp(const int x, const int y, const int seq) override;
 
     /**
      * @brief TBD
index fc66d14..5df1182 100644 (file)
@@ -11,7 +11,7 @@
 #include <Ecore.h>
 
 TizenImpl::TizenImpl()
-: mFakeTouchHandle{0}, mFakeKeyboardHandle{0}, mFakeWheelHandle{0}, isTimerStarted{false}
+: mFakeTouchHandle{0}, mFakeKeyboardHandle{0}, mFakeWheelHandle{0}, isTimerStarted{false}, mTouchSeq{}
 {
     LOG_SCOPE_F(INFO, "device implementation init");
     ecore_main_loop_thread_safe_call_sync([](void *data)->void*{
@@ -42,60 +42,70 @@ bool TizenImpl::click(const int x, const int y)
 
 bool TizenImpl::click(const int x, const int y, const unsigned int intv)
 {
-    touchDown(x, y);
+    int seq = touchDown(x, y);
+    if (seq < 0) return false;
     usleep(intv * MSEC_PER_SEC);
-    touchUp(x, y);
+    touchUp(x, y, seq);
 
     return true;
 }
 
 
-bool TizenImpl::touchDown(const int x, const int y)
+int TizenImpl::touchDown(const int x, const int y)
 {
-    LOG_F(INFO, "touch down %d %d", x, y);
-    auto args = std::make_tuple(this, x, y);
-    ecore_main_loop_thread_safe_call_sync([](void *data)->void*{
-        TizenImpl *obj;
-        int x, y;
-        std::tie(obj, x, y) = *static_cast<std::tuple<TizenImpl*, int, int>*>(data);
-        efl_util_input_generate_touch(obj->mFakeTouchHandle, 0, EFL_UTIL_INPUT_TOUCH_BEGIN,
-                                  x, y);
+    int seq = grabTouchSeqNumber();
+    LOG_F(INFO, "touch down %d %d , seq:%d", x, y, seq);
+    if (seq >= 0) {
+        auto args = std::make_tuple(this, x, y, seq);
+        ecore_main_loop_thread_safe_call_sync([](void *data)->void*{
+            TizenImpl *obj;
+            int x, y, seq;
+            std::tie(obj, x, y, seq) = *static_cast<std::tuple<TizenImpl*, int, int, int>*>(data);
+            efl_util_input_generate_touch(obj->mFakeTouchHandle, seq, EFL_UTIL_INPUT_TOUCH_BEGIN,
+                                    x, y);
 
-        return NULL;
-    }, (void*)(&args));
-    return true;
+            return NULL;
+        }, (void*)(&args));
+    }
+    return seq;
 }
 
-bool TizenImpl::touchMove(const int x, const int y)
+bool TizenImpl::touchMove(const int x, const int y, const int seq)
 {
-    LOG_F(INFO, "touch move %d %d", x, y);
-    auto args = std::make_tuple(this, x, y);
-    ecore_main_loop_thread_safe_call_sync([](void *data)->void*{
-        TizenImpl *obj;
-        int x, y;
-        std::tie(obj, x, y) = *static_cast<std::tuple<TizenImpl*, int, int>*>(data);
+    LOG_F(INFO, "touch move %d %d, seq:%d", x, y, seq);
+    if (seq >= 0) {
+        auto args = std::make_tuple(this, x, y, seq);
+        ecore_main_loop_thread_safe_call_sync([](void *data)->void*{
+            TizenImpl *obj;
+            int x, y, seq;
+            std::tie(obj, x, y, seq) = *static_cast<std::tuple<TizenImpl*, int, int, int>*>(data);
 
-        efl_util_input_generate_touch(obj->mFakeTouchHandle, 0, EFL_UTIL_INPUT_TOUCH_UPDATE,
-                                  x, y);
+            efl_util_input_generate_touch(obj->mFakeTouchHandle, seq, EFL_UTIL_INPUT_TOUCH_UPDATE,
+                                    x, y);
 
-        return NULL;
-    }, (void*)(&args));
-    return true;
+            return NULL;
+        }, (void*)(&args));
+        return true;
+    }
+    return false;
 }
 
-bool TizenImpl::touchUp(const int x, const int y)
+bool TizenImpl::touchUp(const int x, const int y, const int seq)
 {
-    LOG_F(INFO, "touch up %d %d", x, y);
-    auto args = std::make_tuple(this, x, y);
-    ecore_main_loop_thread_safe_call_sync([](void *data)->void*{
-        TizenImpl *obj;
-        int x, y;
-        std::tie(obj, x, y) = *static_cast<std::tuple<TizenImpl*, int, int>*>(data);
-        efl_util_input_generate_touch(obj->mFakeTouchHandle, 0, EFL_UTIL_INPUT_TOUCH_END,
-                                  x, y);
-        return NULL;
-    }, (void*)(&args));
-    return true;
+    LOG_F(INFO, "touch up %d %d, seq:%d", x, y, seq);
+    if (seq >= 0) {
+        auto args = std::make_tuple(this, x, y, seq);
+        ecore_main_loop_thread_safe_call_sync([](void *data)->void*{
+            TizenImpl *obj;
+            int x, y, seq;
+            std::tie(obj, x, y, seq) = *static_cast<std::tuple<TizenImpl*, int, int, int>*>(data);
+            efl_util_input_generate_touch(obj->mFakeTouchHandle, seq, EFL_UTIL_INPUT_TOUCH_END,
+                                    x, y);
+            return NULL;
+        }, (void*)(&args));
+        return releaseTouchSeqNumber(seq);;
+    }
+    return false;
 }
 
 bool TizenImpl::wheelUp(int amount, const int durationMs)
@@ -168,18 +178,19 @@ bool TizenImpl::drag(const int sx, const int sy, const int ex, const int ey,
     }
     LOG_SCOPE_F(INFO, "flicking (%d, %d) -> (%d, %d) for (%d ms)", sx, sy, ex, ey, durationMs);
     startTimer();
-    touchDown(sx, sy);
+    int seq = touchDown(sx, sy);
+    if (seq < 0) return false;
     consumptionUs = stopTimer();
 
     for ( int s = 1; s <= _steps + 1; s++) {
         usleep((_stepUs - consumptionUs)>INTV_MINIMUM_USLEEP?(_stepUs - consumptionUs):INTV_MINIMUM_USLEEP);
         startTimer();
-        touchMove(sx + (ex - sx) * s / (steps + 1), sy + (ey - sy) * s / (steps + 1));
+        touchMove(sx + (ex - sx) * s / (steps + 1), sy + (ey - sy) * s / (steps + 1), seq);
         consumptionUs = stopTimer();
     }
     usleep((_stepUs - consumptionUs)>INTV_MINIMUM_USLEEP?(_stepUs - consumptionUs):INTV_MINIMUM_USLEEP);
-    touchMove(ex, ey);
-    touchUp(ex, ey);
+    touchMove(ex, ey, seq);
+    touchUp(ex, ey, seq);
 
     return true;
 }
@@ -314,3 +325,24 @@ long long TizenImpl::getSystemTime(TimeRequestType type)
     return clock->getTime();
 
 }
+
+int TizenImpl::grabTouchSeqNumber()
+{
+    for (int i = 0 ; i < MAX_FINGER_NUMBER; i++) {
+        if (mTouchSeq.count(i) == 0) {
+            mTouchSeq.insert(i);
+            return i;
+        }
+    }
+    return -1;
+}
+
+bool TizenImpl::releaseTouchSeqNumber(int seq)
+{
+    auto k = mTouchSeq.find(seq);
+    if (k != mTouchSeq.end()) {
+        mTouchSeq.erase(k);
+        return true;
+    }
+    return false;
+}
\ No newline at end of file
index c79d0c0..a3c55b6 100644 (file)
@@ -114,22 +114,21 @@ bool UiDevice::drag(const int sx, const int sy, const int ex, const int ey,
     return result;
 }
 
-bool UiDevice::touchDown(const int x, const int y)
+int UiDevice::touchDown(const int x, const int y)
 {
-    bool result =  mDeviceImpl->touchDown(x, y);
-
-    return result;
+    int seq =  mDeviceImpl->touchDown(x, y);
+    return seq;
 }
 
-bool UiDevice::touchMove(const int x, const int y)
+bool UiDevice::touchMove(const int x, const int y, const int seq)
 {
-    bool result =  mDeviceImpl->touchMove(x, y);
+    bool result =  mDeviceImpl->touchMove(x, y, seq);
     return result;
 }
 
-bool UiDevice::touchUp(const int x, const int y)
+bool UiDevice::touchUp(const int x, const int y, const int seq)
 {
-    bool result =  mDeviceImpl->touchUp(x, y);
+    bool result =  mDeviceImpl->touchUp(x, y, seq);
     waitForIdle();
     return result;
 }
index 4864cc5..5f3d45f 100644 (file)
@@ -12,8 +12,8 @@ TouchDownCommand::TouchDownCommand(const ::aurum::ReqTouchDown* request,
 {
     LOG_SCOPE_F(INFO, "TouchDown --------------- ");
     const aurum::Point& point_ = mRequest->coordination();
-    mResponse->set_seqid(0);
-    UiDevice::getInstance(DeviceType::DEFAULT)
+    int seq = UiDevice::getInstance(DeviceType::DEFAULT)
         ->touchDown(point_.x(), point_.y());
+    mResponse->set_seqid(seq);
     return grpc::Status::OK;
 }
\ No newline at end of file
index 18fbeb9..883199a 100644 (file)
@@ -12,6 +12,7 @@ TouchMoveCommand::TouchMoveCommand(const ::aurum::ReqTouchMove* request,
 {
     LOG_SCOPE_F(INFO, "TouchMove --------------- ");
     const aurum::Point& point = mRequest->coordination();
-    UiDevice::getInstance(DeviceType::DEFAULT)->touchMove(point.x(), point.y());
+    int seq = mRequest->seqid();
+    UiDevice::getInstance(DeviceType::DEFAULT)->touchMove(point.x(), point.y(), seq);
     return grpc::Status::OK;
 }
\ No newline at end of file
index 20d8083..0aa24a8 100644 (file)
@@ -12,6 +12,7 @@ TouchUpCommand::TouchUpCommand(const ::aurum::ReqTouchUp* request,
 {
     LOG_SCOPE_F(INFO, "TouchUp --------------- ");
     const aurum::Point& point = mRequest->coordination();
-    UiDevice::getInstance(DeviceType::DEFAULT)->touchUp(point.x(), point.y());
+    int seq = mRequest->seqid();
+    UiDevice::getInstance(DeviceType::DEFAULT)->touchUp(point.x(), point.y(), seq);
     return grpc::Status::OK;
 }
\ No newline at end of file
index 8927469..39aeba3 100644 (file)
@@ -179,10 +179,13 @@ def flickTest(stub):
     return False
 
 def touchTest(stub):
-    stub.touchDown(ReqTouchDown(coordination=Point(x=160,y=330)))
+    res = stub.touchDown(ReqTouchDown(coordination=Point(x=160,y=330)))
+    print(res)
+    seq = res.seqId
+    if seq < 0: return False
     for yy in range(330, 30, -10):
-        stub.touchMove(ReqTouchMove(coordination=Point(x=160,y=yy)))
-    stub.touchUp(ReqTouchUp(coordination=Point(x=160,y=30)))
+        stub.touchMove(ReqTouchMove(coordination=Point(x=160,y=yy), seqId=seq))
+    stub.touchUp(ReqTouchUp(coordination=Point(x=160,y=30), seqId=seq))
 
     return True
 
index 7e1a569..6c9f28d 100644 (file)
@@ -4,10 +4,26 @@ import aurum_pb2_grpc
 import logging
 import grpc
 import time
+def touchTest(stub):
+    stub.touchUp(ReqTouchUp(coordination=Point(x=160,y=30), seqId=0))
+    stub.touchUp(ReqTouchUp(coordination=Point(x=160,y=30), seqId=1))
+    stub.touchUp(ReqTouchUp(coordination=Point(x=160,y=30), seqId=2))
+
+    res = stub.touchDown(ReqTouchDown(coordination=Point(x=160,y=330)))
+    print(res)
+    seq = res.seqId
+    print(seq)
+    for yy in range(330, 30, -10):
+        stub.touchMove(ReqTouchMove(coordination=Point(x=160,y=yy), seqId=seq))
+    stub.touchUp(ReqTouchUp(coordination=Point(x=160,y=30), seqId=seq))
+
+    return True
+
 
 def run():
     with grpc.insecure_channel('127.0.0.1:50051') as channel:
         stub = aurum_pb2_grpc.BootstrapStub(channel)
+        touchTest(stub)
 
 #        print(stub.getLocation(ReqGetLocation()).status)
 #        print(stub.sync(ReqEmpty()))