aurum: improve implementation
authorWonki Kim <wonki_.kim@samsung.com>
Fri, 27 Dec 2019 01:23:53 +0000 (10:23 +0900)
committerWonki Kim <wonki_.kim@samsung.com>
Tue, 3 Mar 2020 06:59:56 +0000 (15:59 +0900)
this patch improves implementation little

Change-Id: If3cb3f9d56f4b08b800990d7dd88e822e5f18413

19 files changed:
bootstrap/server/inc/Commands/GetAttributeCommand.h
bootstrap/server/inc/Commands/LongClickCommand.h
bootstrap/server/src/Commands/ClearCommand.cc
bootstrap/server/src/Commands/ClickCommand.cc
bootstrap/server/src/Commands/FlickCommand.cc
bootstrap/server/src/Commands/GetAttributeCommand.cc
bootstrap/server/src/Commands/GetSizeCommand.cc
bootstrap/server/src/Commands/GetValueCommand.cc
bootstrap/server/src/Commands/LongClickCommand.cc
bootstrap/server/src/Commands/SendKeyCommand.cc
libaurum/inc/AccessibleNode.h
libaurum/inc/DeviceImpl/TM1Impl.h
libaurum/inc/IDevice.h
libaurum/inc/UiDevice.h
libaurum/inc/UiObject.h
libaurum/src/AccessibleNode.cc
libaurum/src/DeviceImpl/TM1Impl.cc
libaurum/src/UiDevice.cc
libaurum/src/UiObject.cc

index 5bed89e..a69fc46 100644 (file)
@@ -20,4 +20,17 @@ public:
     ::grpc::Status execute() override;
 };
 
+class AttributeGetter {
+private:
+public:
+    static AttributeGetter *Creator(::aurum::ReqGetAttribute_RequestType type);
+    virtual bool getPerform(UiObject *obj,  ::aurum::RspGetAttribute* mResponse){}
+};
+
+class VisibleGetter : public AttributeGetter{
+private:
+public:
+    bool getPerform(UiObject *obj, ::aurum::RspGetAttribute* rsp) override;
+};
+
 #endif
\ No newline at end of file
index 73e1ed2..86a0b83 100644 (file)
@@ -17,6 +17,8 @@ public:
     LongClickCommand(const ::aurum::ReqClick* request,
                      ::aurum::RspClick*       response);
     ::grpc::Status execute() override;
+private:
+    const static unsigned int LOGNCLICK_INTERVAL = 50;
 };
 
 #endif
\ No newline at end of file
index ed26d1b..60683ae 100644 (file)
@@ -2,6 +2,8 @@
 #include <UiObject.h>
 #include <loguru.hpp>
 
+#include <string>
+
 ClearCommand::ClearCommand(const ::aurum::ReqClear* request,
                            ::aurum::RspClear*       response)
     : mRequest{request}, mResponse{response}
@@ -13,8 +15,12 @@ ClearCommand::ClearCommand(const ::aurum::ReqClear* request,
     LOG_SCOPE_F(INFO, "Clear --------------- ");
     ObjectMapper* mObjMap = ObjectMapper::getInstance();
     UiObject*     obj = mObjMap->getElement(mRequest->elementid());
+
     if (obj) {
-        ;
+        std::string empty{};
+        obj->setText(empty);
+        mResponse->set_status(::aurum::RspStatus::OK);
     }
+
     return grpc::Status::OK;
 }
\ No newline at end of file
index b8e24b9..374eb9f 100644 (file)
@@ -1,6 +1,7 @@
 #include "ClickCommand.h"
 
 #include "UiObject.h"
+#include "UiDevice.h"
 
 #include <loguru.hpp>
 
@@ -25,7 +26,10 @@ ClickCommand::ClickCommand(const ::aurum::ReqClick* request,
         } else
             mResponse->set_status(::aurum::RspStatus::ERROR);
     } else if (type == ::aurum::ReqClick_RequestType_COORD) {
-        mResponse->set_status(::aurum::RspStatus::ERROR);
+        UiDevice* obj = UiDevice::getInstance(DeviceType::DEFAULT);
+        const ::aurum::Point& point = mRequest->coordination();
+        obj->click(point.x(), point.y());
+        mResponse->set_status(::aurum::RspStatus::OK);
     } else if (type == ::aurum::ReqClick_RequestType_ATSPI) {
         mResponse->set_status(::aurum::RspStatus::ERROR);
     }
index a0592f7..a2ff94f 100644 (file)
@@ -12,15 +12,14 @@ FlickCommand::FlickCommand(const ::aurum::ReqFlick *request,
 ::grpc::Status FlickCommand::execute()
 {
     LOG_SCOPE_F(INFO, "Flick --------------- ");
-    // ObjectMapper *mObjMap = ObjectMapper::getInstance();
 
     const ::aurum::Point &startPoint = mRequest->startpoint();
     const ::aurum::Point &endPoint = mRequest->endpoint();
     int                   durationMs = mRequest->durationms();
 
     UiDevice *device = UiDevice::getInstance(DeviceType::DEFAULT);
-
-    device->drag(10, 200, 400, 400, durationMs);
+    device->drag(startPoint.x(), startPoint.y(), endPoint.x(), endPoint.y(), durationMs);
+    mResponse->set_status(::aurum::RspStatus::OK);
 
     return grpc::Status::OK;
 }
\ No newline at end of file
index 9e4d50b..eec2835 100644 (file)
@@ -1,6 +1,9 @@
 #include "GetAttributeCommand.h"
 #include <loguru.hpp>
 
+#include <UiDevice.h>
+#include <UiObject.h>
+
 GetAttributeCommand::GetAttributeCommand(
     const ::aurum::ReqGetAttribute* request, ::aurum::RspGetAttribute* response)
     : mRequest{request}, mResponse{response}
@@ -10,6 +13,37 @@ GetAttributeCommand::GetAttributeCommand(
 ::grpc::Status GetAttributeCommand::execute()
 {
     LOG_SCOPE_F(INFO, "GetAttribute --------------- ");
-    // ObjectMapper *mObjMap = ObjectMapper::getInstance();
+    ObjectMapper* mObjMap = ObjectMapper::getInstance();
+    UiObject*     obj = mObjMap->getElement(mRequest->elementid());
+
+    ::aurum::ReqGetAttribute_RequestType type = mRequest->attribute();
+    AttributeGetter *getter = AttributeGetter::Creator(type);
+
+    if (getter)
+        getter->getPerform(obj, mResponse);
+
     return grpc::Status::OK;
-}
\ No newline at end of file
+}
+
+AttributeGetter* AttributeGetter::Creator(::aurum::ReqGetAttribute_RequestType type)
+{
+    switch(type)
+    {
+        case ::aurum::ReqGetAttribute_RequestType::ReqGetAttribute_RequestType_VISIBLE:
+            return new VisibleGetter();
+        default:
+            return nullptr;
+    }
+}
+
+bool VisibleGetter::getPerform(UiObject *obj, ::aurum::RspGetAttribute* rsp)
+{
+    bool isVisible = obj->isVisible();
+
+    rsp->set_boolvalue(isVisible);
+    rsp->set_status(aurum::RspStatus::OK);
+
+    return true;
+}
+AttributeGetter::~AttributeGetter(){}
+VisibleGetter::~VisibleGetter(){}
\ No newline at end of file
index d831453..88d896f 100644 (file)
@@ -1,6 +1,8 @@
 #include "GetSizeCommand.h"
 #include <loguru.hpp>
 
+#include <UiObject.h>
+
 GetSizeCommand::GetSizeCommand(const ::aurum::ReqGetSize* request,
                                ::aurum::RspGetSize*       response)
     : mRequest{request}, mResponse{response}
@@ -10,6 +12,18 @@ GetSizeCommand::GetSizeCommand(const ::aurum::ReqGetSize* request,
 ::grpc::Status GetSizeCommand::execute()
 {
     LOG_SCOPE_F(INFO, "GetSize --------------- ");
-    // ObjectMapper *mObjMap = ObjectMapper::getInstance();
+    ObjectMapper *mObjMap = ObjectMapper::getInstance();
+    UiObject* obj = mObjMap->getElement(mRequest->elementid());
+
+    const Rect<int> &size = obj->getBoundingBox();
+
+    ::aurum::Rect rect;
+    rect.set_x(size.mTopLeft.x);
+    rect.set_y(size.mTopLeft.y);
+    rect.set_width(size.width());
+    rect.set_height(size.height());
+
+    mResponse->mutable_size()->CopyFrom(rect);
+
     return grpc::Status::OK;
 }
\ No newline at end of file
index 60033a5..0eabcb5 100644 (file)
@@ -1,6 +1,8 @@
 #include "GetValueCommand.h"
 #include <loguru.hpp>
 
+#include <UiObject.h>
+
 GetValueCommand::GetValueCommand(const ::aurum::ReqGetValue* request,
                                  ::aurum::RspGetValue*       response)
     : mRequest{request}, mResponse{response}
@@ -10,6 +12,14 @@ GetValueCommand::GetValueCommand(const ::aurum::ReqGetValue* request,
 ::grpc::Status GetValueCommand::execute()
 {
     LOG_SCOPE_F(INFO, "GetValue --------------- ");
-    // ObjectMapper *mObjMap = ObjectMapper::getInstance();
+    ObjectMapper* mObjMap = ObjectMapper::getInstance();
+    UiObject*     obj = mObjMap->getElement(mRequest->elementid());
+
+    if (obj) {
+        std::string text = obj->getText();
+        mResponse->set_stringvalue(text.c_str());
+        mResponse->set_status(::aurum::RspStatus::OK);
+    }
+
     return grpc::Status::OK;
 }
\ No newline at end of file
index 8197dd6..6dcc5a1 100644 (file)
@@ -1,6 +1,9 @@
 #include "LongClickCommand.h"
 #include <loguru.hpp>
 
+#include <UiObject.h>
+#include <UiDevice.h>
+
 LongClickCommand::LongClickCommand(const ::aurum::ReqClick* request,
                                    ::aurum::RspClick*       response)
     : mRequest{request}, mResponse{response}
@@ -10,6 +13,25 @@ LongClickCommand::LongClickCommand(const ::aurum::ReqClick* request,
 ::grpc::Status LongClickCommand::execute()
 {
     LOG_SCOPE_F(INFO, "LongClick --------------- ");
-    // ObjectMapper *mObjMap = ObjectMapper::getInstance();
+
+    ObjectMapper* mObjMap = ObjectMapper::getInstance();
+    ::aurum::ReqClick_RequestType type = mRequest->type();
+
+    if (type == ::aurum::ReqClick_RequestType_ELEMENTID) {
+        UiObject* obj = mObjMap->getElement(mRequest->elementid());
+        if (obj) {
+            obj->longClick(LOGNCLICK_INTERVAL);
+            mResponse->set_status(::aurum::RspStatus::OK);
+        } else
+            mResponse->set_status(::aurum::RspStatus::ERROR);
+    } else if (type == ::aurum::ReqClick_RequestType_COORD) {
+        UiDevice* obj = UiDevice::getInstance(DeviceType::DEFAULT);
+        const ::aurum::Point& point = mRequest->coordination();
+        obj->click(point.x(), point.y(), LOGNCLICK_INTERVAL);
+        mResponse->set_status(::aurum::RspStatus::OK);
+    } else if (type == ::aurum::ReqClick_RequestType_ATSPI) {
+        mResponse->set_status(::aurum::RspStatus::ERROR);
+    }
+
     return grpc::Status::OK;
 }
\ No newline at end of file
index b519133..7897a7f 100644 (file)
@@ -21,8 +21,17 @@ SendKeyCommand::SendKeyCommand(const ::aurum::ReqKey* request,
         mDevice->pressHome();
     else if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_MENU)
         mDevice->pressMenu();
-    else {
-        // TODO : handle keycode
+    else if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_VOLUP)
+        mDevice->pressVolUp();
+    else if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_VOLDOWN)
+        mDevice->pressVolDown();
+    else if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_POWER)
+        mDevice->pressPower();
+    else if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_KEY) {
+        ; // TODO
+    }
+    else if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_XF86) {
+        ; // TODO
     }
     return grpc::Status::OK;
 }
\ No newline at end of file
index cc19f2c..89981ca 100644 (file)
@@ -39,6 +39,7 @@ enum class NodeFeatureProperties {
 
     SELECTABLE = 0X0100,
     SELECTED = 0X0200,
+    VISIBILITY = 0X0400,
 };
 
 template <typename T>
@@ -123,6 +124,7 @@ public:
     bool isScrollable() const;
     bool isSelectable() const;
     bool isSelected() const;
+    bool isVisible() const;
 
 public:
     void print(int) const;
index d24f14f..7b97db7 100644 (file)
@@ -14,6 +14,8 @@ public:
     ~TM1Impl();
 
     bool click(const int x, const int y) override;
+    bool click(const int x, const int y, const unsigned int intv) override;
+
     bool drag(const int sx, const int sy, const int ex, const int ey,
               const int steps) override;
 
@@ -34,8 +36,8 @@ private:
 #ifdef GBS_BUILD
     efl_util_inputgen_h mFakeTouchHandle;
     efl_util_inputgen_h mFakeKeyboardHandle;
-
 #endif
+    static const unsigned int INTV_CLICK = 5;
 };
 
 #endif
\ No newline at end of file
index 32abd39..29b01de 100644 (file)
@@ -9,6 +9,7 @@ public:
     virtual ~IDevice() {}
 
     virtual bool click(const int x, const int y) = 0;
+    virtual bool click(const int x, const int y, const unsigned int intv) = 0;
     virtual bool drag(const int sx, const int sy, const int ex, const int ey,
                       const int steps) = 0;
 
index 56d5cec..66b1b84 100644 (file)
@@ -22,6 +22,8 @@ enum class DeviceType {
 class UiDevice : public IDevice, public ISearchable {
 public:
     bool click(const int x, const int y) override;
+    bool click(const int x, const int y, const unsigned int intv) override;
+
     bool drag(const int sx, const int sy, const int ex, const int ey,
               const int steps) override;
 
index a776f92..d6ff0d9 100644 (file)
@@ -46,6 +46,8 @@ public:
     std::string getText() const;
     void        setText(std::string &text);
 
+    const Rect<int> getBoundingBox() const;
+
     bool isCheckable() const;
     bool isChecked() const;
     bool isClickable() const;
@@ -56,13 +58,16 @@ public:
     bool isScrollable() const;
     bool isSelectable() const;
     bool isSelected() const;
+    bool isVisible() const;
 
     void click() const;
+    void longClick(const unsigned int intv = LOGNCLICK_INTERVAL) const;
     void refresh() const;
 
 private:
     UiObject();
     const AccessibleNode *getAccessibleNode() const;
+    static const unsigned int LOGNCLICK_INTERVAL = 50;
 
 private:
     const UiDevice *      mDevice;
index 565b868..d60df30 100644 (file)
@@ -286,6 +286,11 @@ bool AccessibleNode::isSelected() const
     return hasFeatureProperty(NodeFeatureProperties::SELECTED);
 }
 
+bool AccessibleNode::isVisible() const
+{
+    return hasFeatureProperty(NodeFeatureProperties::VISIBILITY);
+}
+
 AtspiAccessible *AccessibleNode::getAccessible()
 {
     return mNode;
index 087841c..9338726 100644 (file)
@@ -27,11 +27,16 @@ TM1Impl::~TM1Impl()
 
 bool TM1Impl::click(const int x, const int y)
 {
-    LOG_SCOPE_F(INFO, "click at (%d, %d)", x, y);
+    click(x, y, INTV_CLICK);
+}
+
+bool TM1Impl::click(const int x, const int y, const unsigned int intv)
+{
+LOG_SCOPE_F(INFO, "click at (%d, %d)", x, y);
 #ifdef GBSBUILD
     efl_util_input_generate_touch(mFakeTouchHandle, 0,
                                   EFL_UTIL_INPUT_TOUCH_BEGIN, x, y);
-    usleep(5*10000);
+    usleep(intv*10000);
     efl_util_input_generate_touch(mFakeTouchHandle, 0, EFL_UTIL_INPUT_TOUCH_END,
                                   x, y);
     return true;
@@ -40,6 +45,7 @@ bool TM1Impl::click(const int x, const int y)
 #endif
 }
 
+
 bool TM1Impl::touchDown(const int x, const int y)
 {
 #ifdef GBSBUILD
index afc9398..4646cb9 100644 (file)
@@ -83,6 +83,11 @@ bool UiDevice::click(const int x, const int y)
     return mDeviceImpl->click(x, y);
 }
 
+bool UiDevice::click(const int x, const int y, const unsigned int intv)
+{
+    return mDeviceImpl->click(x, y, intv);
+}
+
 bool UiDevice::drag(const int sx, const int sy, const int ex, const int ey,
                     const int steps)
 {
index 7bb91dd..3520a79 100644 (file)
@@ -184,11 +184,22 @@ bool UiObject::isSelected() const
     return getAccessibleNode()->isSelected();
 }
 
+bool UiObject::isVisible() const
+{
+    return getAccessibleNode()->isVisible();
+}
+
 void UiObject::refresh() const
 {
     mNode->refresh();
 }
 
+const Rect<int> UiObject::getBoundingBox() const
+{
+    mNode->refresh();
+    return mNode->getBoundingBox();
+}
+
 void UiObject::click() const
 {
     LOG_SCOPE_F(INFO, "click on obj %p", this);
@@ -200,6 +211,16 @@ void UiObject::click() const
     // todo click implementation
 }
 
+void UiObject::longClick(const unsigned int intv) const
+{
+    LOG_SCOPE_F(INFO, "click on obj %p", this);
+    mNode->refresh();
+    const Rect<int> rect = mNode->getBoundingBox();
+    std::cout << rect.mTopLeft.x << ", " << rect.mTopLeft.y << std::endl;
+    const Point2D<int> midPoint = rect.midPoint();
+    const_cast<UiDevice *>(mDevice)->click(midPoint.x, midPoint.y, intv);
+}
+
 const AccessibleNode *UiObject::getAccessibleNode() const
 {
     if (mNode == nullptr) throw;