Aurum: Introduce SetXMLSync Command 93/291693/6
authorANZ1217 <chihun.jeong@samsung.com>
Thu, 20 Apr 2023 08:49:33 +0000 (17:49 +0900)
committerChihun Jeong <chihun.jeong@samsung.com>
Fri, 21 Apr 2023 04:45:02 +0000 (04:45 +0000)
Change-Id: I495fe584ecb55fe4036f305aa73a40fc0a9ed245

13 files changed:
libaurum/inc/Accessibility/AccessibleWatcher.h
libaurum/inc/AurumXML.h
libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h
libaurum/inc/Impl/Accessibility/MockAccessibleWatcher.h
libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc
libaurum/src/Impl/Accessibility/MockAccessibleWatcher.cc
org.tizen.aurum-bootstrap/inc/AurumServiceImpl.h
org.tizen.aurum-bootstrap/inc/Commands/Commands.h
org.tizen.aurum-bootstrap/inc/Commands/SetXMLSyncCommand.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/SetXMLSyncCommand.cc [new file with mode: 0644]
protocol/aurum.proto

index 42e0756..533b857 100644 (file)
@@ -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.
index f4cf4c8..d1c8548 100644 (file)
@@ -158,6 +158,10 @@ private:
     void findXNodes(std::vector<std::shared_ptr<AccessibleNode>> &ret, std::string xpath, bool earlyReturn);
 
 private:
+
+    AurumXML(const AurumXML&) = delete;
+    AurumXML& operator=(const AurumXML&) = delete;
+
     xml_document                                *mDoc;
     const std::shared_ptr<AccessibleNode>        mRoot;
     std::unordered_map<std::string, std::shared_ptr<AccessibleNode>> mXNodeMap;
index 19c0791..802bc28 100644 (file)
@@ -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;
index cfe66c3..6de46f8 100644 (file)
@@ -81,6 +81,8 @@ public:
 
     std::shared_ptr<AurumXML> getXMLDoc(std::string pkgName);
 
+    void setXMLsync(bool sync);
+
 public:
     /**
      * @brief TBD
index f691d9e..a8c42d4 100644 (file)
@@ -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<std::string, std::shared_ptr<AurumXML>>(package,
-                std::make_shared<AurumXML>(std::make_shared<AtspiAccessibleNode>(app), &mAppXMLLoadedCount, &mXMLMutex, &mXMLConditionVar)));
+            mAppCount++;
+            instance->mXMLDocMap.insert(std::pair<std::string, std::shared_ptr<AurumXML>>(package,
+                    std::make_shared<AurumXML>(std::make_shared<AtspiAccessibleNode>(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<AtspiAccessible *, std::shared_ptr<AccessibleApplication>> AtspiAccessi
 
 std::map<std::string, std::shared_ptr<AurumXML>> 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<AurumXML> 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
index 1303e28..d5b1ec0 100644 (file)
@@ -82,3 +82,7 @@ bool MockAccessibleWatcher::registerCallback(const A11yEvent type, EventHandler
 {
     return true;
 }
+
+void MockAccessibleWatcher::setXMLsync(bool sync)
+{
+}
index a47581e..939adcb 100644 (file)
@@ -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;
 };
index 650b31b..2d80fcc 100644 (file)
@@ -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 (file)
index 0000000..b26310a
--- /dev/null
@@ -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 <gio/gio.h>
+#include <grpcpp/grpcpp.h>
+#include "Commands/Command.h"
+#include "ObjectMapper.h"
+#include <aurum.grpc.pb.h>
+#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
index 3f20d19..a6295b3 100644 (file)
@@ -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 = [
index 0cb4f82..ef684d1 100644 (file)
@@ -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<SetXMLSyncCommand> cmd = std::make_unique<SetXMLSyncCommand>(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 (file)
index 0000000..5b09d66
--- /dev/null
@@ -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;
+}
index da7bee5..7fd3338 100644 (file)
@@ -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