From 7ebbed5075ca2f82a393cbdc09db96564d0b3657 Mon Sep 17 00:00:00 2001 From: Hosang Kim Date: Thu, 10 Apr 2025 14:37:11 +0900 Subject: [PATCH] libaurum: Update accessibility event handling to use shared pointers Changed the EventHandler typedef to use std::function with a shared pointer to AccessibleNode instead of a string package name. Updated the A11yEventHandler operator() to accept a shared pointer to AccessibleNode instead of a string package name. Updated the AtspiAccessibleWatcher processCallback method to accept an optional AtspiAccessible pointer and create a shared pointer to AtspiAccessibleNode when available. Change-Id: I4911407a203a73c3c65d80fbc3843ac8762d9903 --- libaurum/inc/A11yEventHandler.h | 5 +++-- libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h | 2 +- libaurum/src/A11yEventHandler.cc | 5 ++--- libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc | 7 ++++--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/libaurum/inc/A11yEventHandler.h b/libaurum/inc/A11yEventHandler.h index 7687308..87e83b8 100644 --- a/libaurum/inc/A11yEventHandler.h +++ b/libaurum/inc/A11yEventHandler.h @@ -19,10 +19,11 @@ #define _A11Y_EVENT_HANDLER_H_ #include "A11yEvent.h" +#include namespace Aurum { -typedef bool (*EventHandler)(void *data, const A11yEvent type, std::string pkg); +using EventHandler = std::function)>; /** * @class A11yEventHandler @@ -62,7 +63,7 @@ public: * * @since_tizen 7.5 */ - bool operator() (std::string pkg); + bool operator() (std::shared_ptr node); private: A11yEvent mType; diff --git a/libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h b/libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h index 56706a2..32f26c4 100644 --- a/libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h +++ b/libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h @@ -163,7 +163,7 @@ private: 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 processCallback(char *type, char *name, char *pkg, AtspiAccessible *node = nullptr); void processWindowEvent(AtspiEvent *event); void processPostRender(); diff --git a/libaurum/src/A11yEventHandler.cc b/libaurum/src/A11yEventHandler.cc index b0cb63d..9bf1a8f 100644 --- a/libaurum/src/A11yEventHandler.cc +++ b/libaurum/src/A11yEventHandler.cc @@ -27,8 +27,7 @@ A11yEvent A11yEventHandler::getType() const { return mType; } -bool A11yEventHandler::operator() (std::string pkg) +bool A11yEventHandler::operator() (std::shared_ptr node) { - return mCb(mData, mType, pkg); + return mCb(mData, mType, node); } - diff --git a/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc b/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc index 3579329..72b5499 100644 --- a/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc +++ b/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc @@ -298,7 +298,7 @@ gpointer AtspiAccessibleWatcher::timerThread(gpointer data) return NULL; } -void AtspiAccessibleWatcher::processCallback(char *type, char *name, char *pkg) +void AtspiAccessibleWatcher::processCallback(char *type, char *name, char *pkg, AtspiAccessible *node) { mMutex.lock(); auto a11yEvent = std::make_shared(std::string(type), std::string(name), std::string(pkg)); @@ -313,7 +313,8 @@ void AtspiAccessibleWatcher::processCallback(char *type, char *name, char *pkg) { LOGI("Callback call type %s pkg %s", type, pkg); auto handler = *it; - bool res = (*handler)(std::string(pkg)); + if (node) g_object_ref(node); + bool res = (*handler)(std::make_shared(node)); if (!res) it = list.erase(it); else ++it; } @@ -420,7 +421,7 @@ void AtspiAccessibleWatcher::onAtspiEvents(AtspiEvent *event, void *watcher) 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); + instance->processCallback(event->type, name, pkg, event->source); if (name) g_free(name); if (pkg) g_free(pkg); } -- 2.34.1