From 6fa3e50dfaf7923cf7b7873894ecb9ab3f8ada92 Mon Sep 17 00:00:00 2001 From: ANZ1217 Date: Thu, 20 Apr 2023 17:49:33 +0900 Subject: [PATCH] Aurum: Introduce SetXMLSync Command Change-Id: I495fe584ecb55fe4036f305aa73a40fc0a9ed245 --- libaurum/inc/Accessibility/AccessibleWatcher.h | 9 ++++ libaurum/inc/AurumXML.h | 4 ++ .../Impl/Accessibility/AtspiAccessibleWatcher.h | 8 +++ .../inc/Impl/Accessibility/MockAccessibleWatcher.h | 2 + .../Impl/Accessibility/AtspiAccessibleWatcher.cc | 62 +++++++++++++++------- .../Impl/Accessibility/MockAccessibleWatcher.cc | 4 ++ org.tizen.aurum-bootstrap/inc/AurumServiceImpl.h | 3 ++ org.tizen.aurum-bootstrap/inc/Commands/Commands.h | 1 + .../inc/Commands/SetXMLSyncCommand.h | 34 ++++++++++++ org.tizen.aurum-bootstrap/meson.build | 1 + org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc | 8 +++ .../src/Commands/SetXMLSyncCommand.cc | 34 ++++++++++++ protocol/aurum.proto | 9 ++++ 13 files changed, 161 insertions(+), 18 deletions(-) create mode 100644 org.tizen.aurum-bootstrap/inc/Commands/SetXMLSyncCommand.h create mode 100644 org.tizen.aurum-bootstrap/src/Commands/SetXMLSyncCommand.cc diff --git a/libaurum/inc/Accessibility/AccessibleWatcher.h b/libaurum/inc/Accessibility/AccessibleWatcher.h index 42e0756..533b857 100644 --- a/libaurum/inc/Accessibility/AccessibleWatcher.h +++ b/libaurum/inc/Accessibility/AccessibleWatcher.h @@ -151,6 +151,15 @@ public: */ virtual bool registerCallback(const A11yEvent type, EventHandler cb, void *data) = 0; + /** + * @brief Set AurumXML synchronization. + * + * @param[in] sync Whether to synchronize + * + * @since_tizen 7.5 + */ + virtual void setXMLsync(bool sync) = 0; + public: /** * @brief Gets active application vector. diff --git a/libaurum/inc/AurumXML.h b/libaurum/inc/AurumXML.h index f4cf4c8..d1c8548 100644 --- a/libaurum/inc/AurumXML.h +++ b/libaurum/inc/AurumXML.h @@ -158,6 +158,10 @@ private: void findXNodes(std::vector> &ret, std::string xpath, bool earlyReturn); private: + + AurumXML(const AurumXML&) = delete; + AurumXML& operator=(const AurumXML&) = delete; + xml_document *mDoc; const std::shared_ptr mRoot; std::unordered_map> mXNodeMap; diff --git a/libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h b/libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h index 19c0791..802bc28 100644 --- a/libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h +++ b/libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h @@ -142,6 +142,11 @@ public: */ virtual bool registerCallback(const A11yEvent type, EventHandler cb, void *data) override; + /** + * @copydoc @AccessibleWatcher::setXMLsync() + */ + virtual void setXMLsync(bool sync) override; + public: /** * @brief Listen atspi events. @@ -172,6 +177,7 @@ private: static gpointer timerThread(gpointer data); void appendApp(AtspiAccessibleWatcher *instance, AtspiAccessible *app, char *pkg); void removeApp(AtspiAccessibleWatcher *instance, AtspiAccessible *app, char *pkg); + void setXMLsync(); private: GDBusProxy *mDbusProxy; @@ -195,6 +201,8 @@ private: std::mutex mXMLMutex; std::condition_variable mXMLConditionVar; + bool mXMLSync; + static GThread *mTimerThread; static std::chrono::system_clock::time_point mStartTime; static IdleEventState isIdle; diff --git a/libaurum/inc/Impl/Accessibility/MockAccessibleWatcher.h b/libaurum/inc/Impl/Accessibility/MockAccessibleWatcher.h index cfe66c3..6de46f8 100644 --- a/libaurum/inc/Impl/Accessibility/MockAccessibleWatcher.h +++ b/libaurum/inc/Impl/Accessibility/MockAccessibleWatcher.h @@ -81,6 +81,8 @@ public: std::shared_ptr getXMLDoc(std::string pkgName); + void setXMLsync(bool sync); + public: /** * @brief TBD diff --git a/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc b/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc index f691d9e..a8c42d4 100644 --- a/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc +++ b/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc @@ -136,6 +136,7 @@ AtspiAccessibleWatcher::AtspiAccessibleWatcher() mAppCount = 0; mAppXMLLoadedCount = 0; + mXMLSync = false; atspi_init(); @@ -203,15 +204,19 @@ void AtspiAccessibleWatcher::appendApp(AtspiAccessibleWatcher *instance, AtspiAc LOGI("app(%s) is already in map", pkg); } - std::string package(pkg); - if (!package.empty()) { - if (instance->mXMLDocMap.count(package)) { - instance->mXMLDocMap.erase(package); - } + if (mXMLSync) + { + std::string package(pkg); + if (!package.empty()) { + + if (instance->mXMLDocMap.count(package)) { + instance->mXMLDocMap.erase(package); + } - mAppCount++; - instance->mXMLDocMap.insert(std::pair>(package, - std::make_shared(std::make_shared(app), &mAppXMLLoadedCount, &mXMLMutex, &mXMLConditionVar))); + mAppCount++; + instance->mXMLDocMap.insert(std::pair>(package, + std::make_shared(std::make_shared(app), &mAppXMLLoadedCount, &mXMLMutex, &mXMLConditionVar))); + } } } @@ -226,8 +231,11 @@ void AtspiAccessibleWatcher::removeApp(AtspiAccessibleWatcher *instance, AtspiAc LOGE("deactivated window's app(%s) is not in map", pkg); } - if (instance->mXMLDocMap.count(std::string(pkg))) { - instance->mXMLDocMap.erase(std::string(pkg)); + if (mXMLSync) + { + if (instance->mXMLDocMap.count(std::string(pkg))) { + instance->mXMLDocMap.erase(std::string(pkg)); + } } g_object_unref(app); @@ -457,24 +465,32 @@ std::map> AtspiAccessi std::map> AtspiAccessibleWatcher::getXMLDocMap(void) { - std::unique_lock lk(mXMLMutex); + LOGI("XMLsync: %s", (mXMLSync ? "TRUE" : "FALSE")); + if(mXMLSync) + { + std::unique_lock lk(mXMLMutex); - //LOGI("mAppCount: %d, mAppXMLLoadedCount: %d", mAppCount, mAppXMLLoadedCount); - mXMLConditionVar.wait(lk, [&] {return mAppCount <= mAppXMLLoadedCount;}); + //LOGI("mAppCount: %d, mAppXMLLoadedCount: %d", mAppCount, mAppXMLLoadedCount); + mXMLConditionVar.wait(lk, [&] {return mAppCount <= mAppXMLLoadedCount;}); - lk.unlock(); + lk.unlock(); + } return mXMLDocMap; } std::shared_ptr AtspiAccessibleWatcher::getXMLDoc(std::string pkgName) { - std::unique_lock lk(mXMLMutex); + LOGI("XMLsync: %s", (mXMLSync ? "TRUE" : "FALSE")); + if(mXMLSync) + { + std::unique_lock lk(mXMLMutex); - //LOGI("mAppCount: %d, mAppXMLLoadedCount: %d", mAppCount, mAppXMLLoadedCount); - mXMLConditionVar.wait(lk, [&] {return mAppCount <= mAppXMLLoadedCount;}); + //LOGI("mAppCount: %d, mAppXMLLoadedCount: %d", mAppCount, mAppXMLLoadedCount); + mXMLConditionVar.wait(lk, [&] {return mAppCount <= mAppXMLLoadedCount;}); - lk.unlock(); + lk.unlock(); + } if (mXMLDocMap.count(pkgName) > 0) return mXMLDocMap[pkgName]; @@ -551,3 +567,13 @@ bool AtspiAccessibleWatcher::registerCallback(const A11yEvent type, EventHandler } return true; } + +void AtspiAccessibleWatcher::setXMLsync(bool sync) +{ + LOGI("setXMLSync: %s", (sync ? "TRUE" : "FALSE")); + mXMLSync = sync; + + if(!sync) { + mXMLDocMap.clear(); + } +} \ No newline at end of file diff --git a/libaurum/src/Impl/Accessibility/MockAccessibleWatcher.cc b/libaurum/src/Impl/Accessibility/MockAccessibleWatcher.cc index 1303e28..d5b1ec0 100644 --- a/libaurum/src/Impl/Accessibility/MockAccessibleWatcher.cc +++ b/libaurum/src/Impl/Accessibility/MockAccessibleWatcher.cc @@ -82,3 +82,7 @@ bool MockAccessibleWatcher::registerCallback(const A11yEvent type, EventHandler { return true; } + +void MockAccessibleWatcher::setXMLsync(bool sync) +{ +} diff --git a/org.tizen.aurum-bootstrap/inc/AurumServiceImpl.h b/org.tizen.aurum-bootstrap/inc/AurumServiceImpl.h index a47581e..939adcb 100644 --- a/org.tizen.aurum-bootstrap/inc/AurumServiceImpl.h +++ b/org.tizen.aurum-bootstrap/inc/AurumServiceImpl.h @@ -132,6 +132,9 @@ public: ::grpc::Status setTimeout(::grpc::ServerContext *context, const ::aurum::ReqSetTimeout *request, ::aurum::RspSetTimeout *response) override; + ::grpc::Status setXMLSync(::grpc::ServerContext *context, + const ::aurum::ReqSetXMLSync *request, + ::aurum::RspSetXMLSync *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 650b31b..2d80fcc 100644 --- a/org.tizen.aurum-bootstrap/inc/Commands/Commands.h +++ b/org.tizen.aurum-bootstrap/inc/Commands/Commands.h @@ -53,3 +53,4 @@ #include "Commands/EnableScreenAnalyzerCommand.h" #include "Commands/GetTextMinBoundingRectCommand.h" +#include "Commands/SetXMLSyncCommand.h" \ No newline at end of file diff --git a/org.tizen.aurum-bootstrap/inc/Commands/SetXMLSyncCommand.h b/org.tizen.aurum-bootstrap/inc/Commands/SetXMLSyncCommand.h new file mode 100644 index 0000000..b26310a --- /dev/null +++ b/org.tizen.aurum-bootstrap/inc/Commands/SetXMLSyncCommand.h @@ -0,0 +1,34 @@ +/* + * 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 +#include +#include "Commands/Command.h" +#include "ObjectMapper.h" +#include +#include "config.h" + +class SetXMLSyncCommand : public Command { +private: + const ::aurum::ReqSetXMLSync *mRequest; + ::aurum::RspSetXMLSync *mResponse; + +public: + SetXMLSyncCommand(const ::aurum::ReqSetXMLSync *request, + ::aurum::RspSetXMLSync *response); + ::grpc::Status execute() override; +}; \ No newline at end of file diff --git a/org.tizen.aurum-bootstrap/meson.build b/org.tizen.aurum-bootstrap/meson.build index 3f20d19..a6295b3 100644 --- a/org.tizen.aurum-bootstrap/meson.build +++ b/org.tizen.aurum-bootstrap/meson.build @@ -48,6 +48,7 @@ bootstrap_svr_src += [ files('src/Commands/GetActiveAppToolkitNameCommand.cc'), files('src/Commands/EnableScreenAnalyzerCommand.cc'), files('src/Commands/GetTextMinBoundingRectCommand.cc'), + files('src/Commands/SetXMLSyncCommand.cc'), ] bootstrap_svr_dep = [ diff --git a/org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc b/org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc index 0cb4f82..ef684d1 100644 --- a/org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc +++ b/org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc @@ -300,3 +300,11 @@ aurumServiceImpl::~aurumServiceImpl() response->set_status(::aurum::RspStatus::OK); return ::grpc::Status::OK; } + +::grpc::Status aurumServiceImpl::setXMLSync(::grpc::ServerContext *context, + const ::aurum::ReqSetXMLSync *request, + ::aurum::RspSetXMLSync *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/SetXMLSyncCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/SetXMLSyncCommand.cc new file mode 100644 index 0000000..5b09d66 --- /dev/null +++ b/org.tizen.aurum-bootstrap/src/Commands/SetXMLSyncCommand.cc @@ -0,0 +1,34 @@ +/* + * 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" +#include "SetXMLSyncCommand.h" + +SetXMLSyncCommand::SetXMLSyncCommand(const ::aurum::ReqSetXMLSync* request, + ::aurum::RspSetXMLSync* response) + : mRequest{request}, mResponse{response} +{ +} + +::grpc::Status SetXMLSyncCommand::execute() +{ + bool sync = mRequest->enable(); + AccessibleWatcher::getInstance()->setXMLsync(sync); + + mResponse->set_status(::aurum::RspStatus::OK); + return grpc::Status::OK; +} diff --git a/protocol/aurum.proto b/protocol/aurum.proto index da7bee5..7fd3338 100644 --- a/protocol/aurum.proto +++ b/protocol/aurum.proto @@ -37,6 +37,7 @@ service Bootstrap { rpc enableScreenAnalyzer(ReqEnableScreenAnalyzer) returns (RspEnableScreenAnalyzer) {} rpc getTextMinBoundingRect(ReqGetTextMinBoundingRect) returns (RspGetTextMinBoundingRect) {} rpc setTimeout(ReqSetTimeout) returns (RspSetTimeout) {} + rpc setXMLSync(ReqSetXMLSync) returns (RspSetXMLSync) {} } // ------------------------------------ // @@ -649,3 +650,11 @@ message ReqSetTimeout { message RspSetTimeout { RspStatus status = 1; } + +message ReqSetXMLSync { + bool enable = 1; +} + +message RspSetXMLSync { + RspStatus status = 1; +} \ No newline at end of file -- 2.7.4