AtspiAccessibleWatcher: refactoring processing event for performance. 50/309750/4
authorHosang Kim <hosang12.kim@samsung.com>
Tue, 16 Apr 2024 07:39:41 +0000 (16:39 +0900)
committerHosang Kim <hosang12.kim@samsung.com>
Tue, 16 Apr 2024 10:29:25 +0000 (19:29 +0900)
1. add processWindowEvent
2. add processPostRender
3. only call dbus function when necessary.

Change-Id: I1e99244f868c7b540b8c7448328f7cbac4f84bbd

libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h
libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc

index e751791e77b2f8c12505bd9070379e23f0c26c5f..56706a2509eb20b01c3d522f1adf065884f10ae4 100644 (file)
@@ -160,10 +160,12 @@ private:
     bool addToWindowSet(AtspiAccessible *node);
     static gpointer eventThreadLoop(gpointer data);
     static gpointer timerThread(gpointer data);
-    void appendApp(AtspiAccessibleWatcher *instance, AtspiAccessible *app, char *pkg, int pid);
-    void removeApp(AtspiAccessibleWatcher *instance, AtspiAccessible *app, char *pkg, int pid);
+    void appendApp(AtspiAccessible *app, char *pkg, int pid);
+    void removeApp(char *pkg, int pid);
     void setXMLsync();
     void processCallback(char *type, char *name, char *pkg);
+    void processWindowEvent(AtspiEvent *event);
+    void processPostRender();
 
 private:
     GDBusProxy *mDbusProxy;
index be37001d95bbc4504f5270f56763b634f6d79bbf..eef77e116d8861579d248de8ac4ffdf42788b2da 100644 (file)
@@ -236,7 +236,7 @@ AtspiAccessibleWatcher::~AtspiAccessibleWatcher()
     atspi_exit();
 }
 
-void AtspiAccessibleWatcher::appendApp(AtspiAccessibleWatcher *instance, AtspiAccessible *app, char *pkg, int pid)
+void AtspiAccessibleWatcher::appendApp(AtspiAccessible *app, char *pkg, int pid)
 {
     LOGI("window activated in app(%s:%d)", pkg, pid);
     if (mXMLSync)
@@ -244,30 +244,30 @@ void AtspiAccessibleWatcher::appendApp(AtspiAccessibleWatcher *instance, AtspiAc
         std::string package(pkg);
         if (!package.empty()) {
 
-            if (instance->mXMLDocMap.count({package, pid})) {
+            if (mXMLDocMap.count({package, pid})) {
                 mAppCount--;
                 mAppXMLLoadedCount--;
-                instance->mXMLDocMap.erase({package, pid});
+                mXMLDocMap.erase({package, pid});
             }
 
             mAppCount++;
-            instance->mXMLDocMap.insert({{package, pid},
+            mXMLDocMap.insert({{package, pid},
                     std::make_shared<AurumXML>(std::make_shared<AtspiAccessibleNode>(app), &mAppXMLLoadedCount, &mXMLMutex, &mXMLConditionVar)});
             g_object_ref(app);
         }
     }
 }
 
-void AtspiAccessibleWatcher::removeApp(AtspiAccessibleWatcher *instance, AtspiAccessible *app, char *pkg, int pid)
+void AtspiAccessibleWatcher::removeApp(char *pkg, int pid)
 {
     LOGI("window deactivate in app(%s:%d)", pkg, pid);
     if (mXMLSync)
     {
         std::string package(pkg);
-        if (instance->mXMLDocMap.count({package, pid})) {
+        if (mXMLDocMap.count({package, pid})) {
             mAppCount--;
             mAppXMLLoadedCount--;
-            instance->mXMLDocMap.erase({package, pid});
+            mXMLDocMap.erase({package, pid});
         }
     }
 }
@@ -318,7 +318,52 @@ void AtspiAccessibleWatcher::processCallback(char *type, char *name, char *pkg)
             else ++it;
         }
     }
+}
+
+void AtspiAccessibleWatcher::processPostRender()
+{
+    if (isIdle == IdleEventState::IDLE_LISTEN_START)
+    {
+        if (mTimerThread == nullptr)
+        {
+            LOGI("Timer Thread Start");
+            mTimerThread = g_thread_new("TimerThread", timerThread, nullptr);
+        }
+        else
+        {
+            mStartTime = std::chrono::system_clock::now();
+        }
+
+        mRenderCount--;
+        if (mRenderCount == 0)
+        {
+          LOGI("RenderCount is 0. Stop to listen RenderPost");
+          isIdle = IdleEventState::IDLE_LISTEN_DONE;
+        }
+    }
+}
+void AtspiAccessibleWatcher::processWindowEvent(AtspiEvent *event)
+{
+    char *name = NULL, *pkg = NULL;
+    int pid = 0;
+    name = AtspiWrapper::Atspi_accessible_get_name(event->source, NULL);
+    pkg = AtspiWrapper::Atspi_accessible_get_name(event->sender, NULL);
+    pid = AtspiWrapper::Atspi_accessible_get_process_id(event->sender, NULL);
+
+    if (!strncmp(event->type, "window:create", 13)) appendApp(event->sender, pkg, pid);
+    else if (!strncmp(event->type, "window:activate", 15) && mXMLDocMap.count({pkg, pid}) == 0) appendApp(event->sender, pkg, pid);
+    else if (!strncmp(event->type, "window:destroy", 14)) removeApp(pkg, pid);
+
+    // To support focus skipped window
+    if (isTv) {
+        if (!strncmp(event->type, "window:restore", 14) && (!strncmp(name, "volume-app", 10) || !strncmp(name, "tv-viewer", 9)))
+            appendApp(event->sender, pkg, pid);
+        else if (!strncmp(event->type, "window:minimize", 15) && (!strncmp(name, "volume-app", 10) || !strncmp(name, "tv-viewer", 9)))
+            removeApp(pkg, pid);
+    }
 
+    if (name) g_free(name);
+    if (pkg) g_free(pkg);
 }
 
 void AtspiAccessibleWatcher::onAtspiEvents(AtspiEvent *event, void *watcher)
@@ -338,77 +383,38 @@ void AtspiAccessibleWatcher::onAtspiEvents(AtspiEvent *event, void *watcher)
         return;
     }
 
-    if (!strncmp(event->type, "w", 1))
-        isWindowEventEmitted = true;
-
-    char *name = NULL, *pkg = NULL;
-    int pid = 0;
     AtspiAccessibleWatcher *instance = (AtspiAccessibleWatcher *)watcher;
-    name = AtspiWrapper::Atspi_accessible_get_name(event->source, NULL);
 
-    if (isIdle == IdleEventState::IDLE_LISTEN_START && !strncmp(event->type, "window:post-render", 18))
-    {
-        if (mTimerThread == nullptr)
-        {
-            LOGI("Timer Thread Start");
-            mTimerThread = g_thread_new("TimerThread", timerThread, instance);
-        }
-        else
-        {
-            mStartTime = std::chrono::system_clock::now();
-        }
-
-        mRenderCount--;
-        if (mRenderCount == 0)
-        {
-          LOGI("RenderCount is 0. Stop to listen RenderPost");
-          isIdle = IdleEventState::IDLE_LISTEN_DONE;
-        }
-
-        if (name) free(name);
+    if (!strncmp(event->type, "object:state-changed:defunct", 28)) {
+        instance->onObjectDefunct(
+            static_cast<AtspiAccessible *>(event->source));
         g_boxed_free(ATSPI_TYPE_EVENT, event);
         return;
     }
-    else if (isIdle == IdleEventState::IDLE_LISTEN_DONE && !strncmp(event->type, "window:post-render", 18))
+
+    if (!strncmp(event->type, "window:post-render", 18))
     {
-        if (name) free(name);
+        instance->processPostRender();
         g_boxed_free(ATSPI_TYPE_EVENT, event);
         return;
     }
 
-    AtspiAccessible *app = AtspiWrapper::Atspi_accessible_get_application(event->source, NULL);
-    if (name && app)
+    if (!strncmp(event->type, "w", 1))
     {
-        pkg = AtspiWrapper::Atspi_accessible_get_name(app, NULL);
-        pid = AtspiWrapper::Atspi_accessible_get_process_id(app, NULL);
-        if (!strncmp(event->type, "window:create", 13)) instance->appendApp(instance, app, pkg, pid);
-        else if (!strncmp(event->type, "window:activate", 15) && instance->mXMLDocMap.count({pkg, pid}) == 0) instance->appendApp(instance, app, pkg, pid);
-        else if (!strncmp(event->type, "window:destroy", 14)) instance->removeApp(instance, app, pkg, pid);
-
-        // To support focus skipped window
-        if (instance->isTv) {
-            if (!strncmp(event->type, "window:restore", 14) && (!strncmp(name, "volume-app", 10) || !strncmp(name, "tv-viewer", 9)))
-                instance->appendApp(instance, app, pkg, pid);
-            else if (!strncmp(event->type, "window:minimize", 15) && (!strncmp(name, "volume-app", 10) || !strncmp(name, "tv-viewer", 9)))
-                instance->removeApp(instance, app, pkg, pid);
-        }
+        isWindowEventEmitted = true;
+        instance->processWindowEvent(event);
     }
-    else
-        pkg = strdup("");
 
-    if(app)
+    if (mWaitingForEvent || !instance->mHandlers.empty())
     {
-        g_object_unref(app);
+        char *name = NULL, *pkg = NULL;
+        name = AtspiWrapper::Atspi_accessible_get_name(event->source, NULL);
+        pkg = AtspiWrapper::Atspi_accessible_get_name(event->sender, NULL);
+        instance->processCallback(event->type, name, pkg);
+        if (name) g_free(name);
+        if (pkg) g_free(pkg);
     }
 
-    instance->processCallback(event->type, name, pkg);
-
-    if (!strcmp(event->type, "object:state-changed:defunct")) {
-         instance->onObjectDefunct(
-            static_cast<AtspiAccessible *>(event->source));
-    }
-    if (name) free(name);
-    if (pkg) free(pkg);
     g_boxed_free(ATSPI_TYPE_EVENT, event);
 }