libaurum: Introduce new getParent API 49/310249/1
authorHosang Kim <hosang12.kim@samsung.com>
Wed, 24 Apr 2024 10:43:22 +0000 (19:43 +0900)
committerHosang Kim <hosang12.kim@samsung.com>
Wed, 24 Apr 2024 10:43:22 +0000 (19:43 +0900)
Change-Id: I9d7be2d670286b949d5461a9ab0d1d59b1659416

libaurum/inc/UiObject.h
libaurum/src/UiObject.cc
org.tizen.aurum-bootstrap/inc/AurumServiceImpl.h
org.tizen.aurum-bootstrap/inc/Commands/Commands.h
org.tizen.aurum-bootstrap/inc/Commands/GetParentCommand.h [new file with mode: 0644]
org.tizen.aurum-bootstrap/meson.build
org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc
org.tizen.aurum-bootstrap/src/Commands/GetParentCommand.cc [new file with mode: 0644]
protocol/aurum.proto

index 18046dab2787688573e3ebd2697ccc8ffa691629..a3d19620d7094b22919def8f77ed91cf7ec9c744 100644 (file)
@@ -276,7 +276,7 @@ public:
      *
      * @since_tizen 6.5
      */
-    UiObject *getParent() const;
+    std::shared_ptr<UiObject>  getParent() const;
 
     /**
      * @brief Gets object's child count.
index fc18345b610353c5ff602655253aeb286c0f665d..d8b3ab4313b33788810c067dd45f1598ae1bbeb8 100644 (file)
@@ -148,11 +148,11 @@ bool UiObject::waitFor(
     return mWaiter->waitFor(condition);
 }
 
-UiObject *UiObject::getParent() const
+std::shared_ptr<UiObject> UiObject::getParent() const
 {
     std::shared_ptr<AccessibleNode> node = mNode->getParent();
     if (!node) return nullptr;
-    return new UiObject(mDevice, mSelector, std::move(node));
+    return std::make_shared<UiObject>(mDevice, mSelector, node);
 }
 
 int UiObject::getChildCount() const
index 584ef7bec4db7eed101c7515ab29e4a90ec879c1..e99d9665b20ad7bcfb254131eac5ce7b656b5b76 100644 (file)
@@ -147,6 +147,9 @@ public:
     ::grpc::Status last(::grpc::ServerContext *context,
                             const ::aurum::ReqLast *request,
                             ::aurum::RspLast *response) override;
+    ::grpc::Status getParent(::grpc::ServerContext *context,
+                            const ::aurum::ReqGetParent *request,
+                            ::aurum::RspGetParent *response) override;
 public:
     int WAIT_TIMEOUT_MS;
 };
index 21f37a812271b0c4226ae7ff2660c87e11a19402..5add72fa6e1067ecbac4e2a5bb58b49204a07077 100644 (file)
@@ -51,3 +51,4 @@
 #include "Commands/PrevCommand.h"
 #include "Commands/FirstCommand.h"
 #include "Commands/LastCommand.h"
+#include "Commands/GetParentCommand.h"
diff --git a/org.tizen.aurum-bootstrap/inc/Commands/GetParentCommand.h b/org.tizen.aurum-bootstrap/inc/Commands/GetParentCommand.h
new file mode 100644 (file)
index 0000000..4b66ed5
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *               http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+#include "bootstrap.h"
+
+class GetParentCommand : public Command {
+protected:
+    const ::aurum::ReqGetParent *mRequest;
+    ::aurum::RspGetParent *mResponse;
+
+public:
+    GetParentCommand(const ::aurum::ReqGetParent *request,
+                       ::aurum::RspGetParent *response);
+    ::grpc::Status execute() override;
+};
index f945c55ad035b97c650c2c0a0f49b12e2253a028..62ae5fcbd43c98250593da2effe8ae5daaf62ed1 100644 (file)
@@ -54,6 +54,7 @@ bootstrap_svr_src += [
    files('src/Commands/PrevCommand.cc'),
    files('src/Commands/FirstCommand.cc'),
    files('src/Commands/LastCommand.cc'),
+   files('src/Commands/GetParentCommand.cc'),
 ]
 
 bootstrap_svr_dep = [
index dd94866de9190c0ee7582596283bd1e8de934519..80b09926ba711c95d01becaecc8224a14afd98bf 100644 (file)
@@ -342,4 +342,12 @@ aurumServiceImpl::~aurumServiceImpl()
 {
     std::unique_ptr<LastCommand> cmd = std::make_unique<LastCommand>(request, response);
     return execute(cmd.get(), true);
+}
+
+::grpc::Status aurumServiceImpl::getParent(::grpc::ServerContext *context,
+                                         const ::aurum::ReqGetParent *request,
+                                         ::aurum::RspGetParent *response)
+{
+    std::unique_ptr<GetParentCommand> cmd = std::make_unique<GetParentCommand>(request, response);
+    return execute(cmd.get(), true);
 }
\ No newline at end of file
diff --git a/org.tizen.aurum-bootstrap/src/Commands/GetParentCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/GetParentCommand.cc
new file mode 100644 (file)
index 0000000..0a09c9f
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *               http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+#include "GetParentCommand.h"
+#include "UiObject.h"
+
+GetParentCommand::GetParentCommand(const ::aurum::ReqGetParent *request,
+                               ::aurum::RspGetParent *response)
+    : mRequest{request}, mResponse{response}
+{
+}
+
+::grpc::Status GetParentCommand::execute()
+{
+    LOGI("GetParent --------------- ");
+
+    ObjectMapper *mObjMap = ObjectMapper::getInstance();
+    std::shared_ptr<UiObject> base = mObjMap->getElement(mRequest->elementid());
+
+    if (!base) {
+        mResponse->set_status(::aurum::RspStatus::ERROR);
+        return grpc::Status::OK;
+    }
+
+    auto found = base->getParent();
+
+    if (found != nullptr) {
+        UiObject *obj = found.get();
+        obj->refresh();
+        if (mObjMap->getElement(obj->getId()) == nullptr)
+            mObjMap->addElement(std::move(found));
+
+        LOGI("found object : %p elementId:%s", obj, obj->getId().c_str());
+
+        ::aurum::Element *elm = mResponse->mutable_element();
+        elm->set_elementid(obj->getId());
+        elm->set_package(obj->getApplicationPackage());
+
+        ::aurum::Rect   *rect = elm->mutable_geometry();
+        const Rect<int> &size = obj->getScreenBoundingBox();
+        rect->set_x(size.mTopLeft.x);
+        rect->set_y(size.mTopLeft.y);
+        rect->set_width(size.width());
+        rect->set_height(size.height());
+
+        ::aurum::Rect   *windowRect = elm->mutable_windowrelativegeometry();
+        const Rect<int> &windowRelativeSize = obj->getWindowBoundingBox();
+        windowRect->set_x(windowRelativeSize.mTopLeft.x);
+        windowRect->set_y(windowRelativeSize.mTopLeft.y);
+        windowRect->set_width(windowRelativeSize.width());
+        windowRect->set_height(windowRelativeSize.height());
+
+        elm->set_widgettype(obj->getType());
+        elm->set_widgetstyle(obj->getElementStyle());
+
+        elm->set_text(obj->getText());
+        elm->set_xpath(obj->getXPath());
+        elm->set_ocrtext(obj->getOcrText());
+        elm->set_automationid(obj->getAutomationId());
+        elm->set_package(obj->getApplicationPackage());
+        elm->set_role(obj->getRole());
+
+        elm->set_ischecked(obj->isChecked());
+        elm->set_ischeckable(obj->isCheckable());
+        elm->set_isclickable(obj->isClickable());
+        elm->set_isenabled(obj->isEnabled());
+        elm->set_isfocused(obj->isFocused());
+        elm->set_isfocusable(obj->isFocusable());
+        elm->set_isscrollable(obj->isScrollable());
+        elm->set_isselected(obj->isSelected());
+        elm->set_isshowing(obj->isShowing());
+        elm->set_isactive(obj->isActive());
+        elm->set_isvisible(obj->isVisible());
+        elm->set_isselectable(obj->isSelectable());
+        elm->set_ishighlightable(obj->isHighlightable());
+
+        elm->set_minvalue(obj->getMinValue());
+        elm->set_maxvalue(obj->getMaxValue());
+        elm->set_value(obj->getValue());
+        elm->set_increment(obj->getIncrement());
+
+        elm->set_windowangle(obj->getWindowAngle());
+        elm->set_targetangle(obj->getTargetAngle());
+
+        elm->set_interface(obj->getInterface());
+        elm->set_description(obj->getDescription());
+
+        mResponse->set_status(::aurum::RspStatus::OK);
+    } else {
+        mResponse->set_status(::aurum::RspStatus::ERROR);
+    }
+
+    return grpc::Status::OK;
+}
index 9bba1ff0b15fbc0630cd79933e75a793c48db79f..33bf56dd7b83913670c52573c2fe9d5bf9be3bf2 100644 (file)
@@ -43,6 +43,7 @@ service Bootstrap {
    rpc prev(ReqPrev) returns (RspPrev) {}
    rpc first(ReqFirst) returns (RspFirst) {}
    rpc last(ReqLast) returns (RspLast) {}
+   rpc getParent(ReqGetParent) returns (RspGetParent) {}
 }
 
 // ------------------------------------ //
@@ -723,3 +724,12 @@ message RspLast {
    RspStatus status = 1;
    Element element = 2;
 }
+
+message ReqGetParent {
+   string elementId = 1;
+}
+
+message RspGetParent {
+   RspStatus status = 1;
+   Element element = 2;
+}