From 57694d32a19d6d5c5e7275daf29c5af0f19b54d0 Mon Sep 17 00:00:00 2001 From: Hosang Kim Date: Wed, 24 Apr 2024 19:43:22 +0900 Subject: [PATCH] libaurum: Introduce new getParent API Change-Id: I9d7be2d670286b949d5461a9ab0d1d59b1659416 --- libaurum/inc/UiObject.h | 2 +- libaurum/src/UiObject.cc | 4 +- .../inc/AurumServiceImpl.h | 3 + .../inc/Commands/Commands.h | 1 + .../inc/Commands/GetParentCommand.h | 29 +++++ org.tizen.aurum-bootstrap/meson.build | 1 + .../src/AurumServiceImpl.cc | 8 ++ .../src/Commands/GetParentCommand.cc | 108 ++++++++++++++++++ protocol/aurum.proto | 10 ++ 9 files changed, 163 insertions(+), 3 deletions(-) create mode 100644 org.tizen.aurum-bootstrap/inc/Commands/GetParentCommand.h create mode 100644 org.tizen.aurum-bootstrap/src/Commands/GetParentCommand.cc diff --git a/libaurum/inc/UiObject.h b/libaurum/inc/UiObject.h index 18046da..a3d1962 100644 --- a/libaurum/inc/UiObject.h +++ b/libaurum/inc/UiObject.h @@ -276,7 +276,7 @@ public: * * @since_tizen 6.5 */ - UiObject *getParent() const; + std::shared_ptr getParent() const; /** * @brief Gets object's child count. diff --git a/libaurum/src/UiObject.cc b/libaurum/src/UiObject.cc index fc18345..d8b3ab4 100644 --- a/libaurum/src/UiObject.cc +++ b/libaurum/src/UiObject.cc @@ -148,11 +148,11 @@ bool UiObject::waitFor( return mWaiter->waitFor(condition); } -UiObject *UiObject::getParent() const +std::shared_ptr UiObject::getParent() const { std::shared_ptr node = mNode->getParent(); if (!node) return nullptr; - return new UiObject(mDevice, mSelector, std::move(node)); + return std::make_shared(mDevice, mSelector, node); } int UiObject::getChildCount() const diff --git a/org.tizen.aurum-bootstrap/inc/AurumServiceImpl.h b/org.tizen.aurum-bootstrap/inc/AurumServiceImpl.h index 584ef7b..e99d966 100644 --- a/org.tizen.aurum-bootstrap/inc/AurumServiceImpl.h +++ b/org.tizen.aurum-bootstrap/inc/AurumServiceImpl.h @@ -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; }; diff --git a/org.tizen.aurum-bootstrap/inc/Commands/Commands.h b/org.tizen.aurum-bootstrap/inc/Commands/Commands.h index 21f37a8..5add72f 100644 --- a/org.tizen.aurum-bootstrap/inc/Commands/Commands.h +++ b/org.tizen.aurum-bootstrap/inc/Commands/Commands.h @@ -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 index 0000000..4b66ed5 --- /dev/null +++ b/org.tizen.aurum-bootstrap/inc/Commands/GetParentCommand.h @@ -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; +}; diff --git a/org.tizen.aurum-bootstrap/meson.build b/org.tizen.aurum-bootstrap/meson.build index f945c55..62ae5fc 100644 --- a/org.tizen.aurum-bootstrap/meson.build +++ b/org.tizen.aurum-bootstrap/meson.build @@ -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 = [ diff --git a/org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc b/org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc index dd94866..80b0992 100644 --- a/org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc +++ b/org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc @@ -342,4 +342,12 @@ aurumServiceImpl::~aurumServiceImpl() { std::unique_ptr cmd = std::make_unique(request, response); return execute(cmd.get(), true); +} + +::grpc::Status aurumServiceImpl::getParent(::grpc::ServerContext *context, + const ::aurum::ReqGetParent *request, + ::aurum::RspGetParent *response) +{ + std::unique_ptr cmd = std::make_unique(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 index 0000000..0a09c9f --- /dev/null +++ b/org.tizen.aurum-bootstrap/src/Commands/GetParentCommand.cc @@ -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 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 &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 &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; +} diff --git a/protocol/aurum.proto b/protocol/aurum.proto index 9bba1ff..33bf56d 100644 --- a/protocol/aurum.proto +++ b/protocol/aurum.proto @@ -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; +} -- 2.34.1