From: Hosang Kim Date: Fri, 21 Oct 2022 11:31:05 +0000 (+0900) Subject: Aurum: Introduce new atspi event callback system. X-Git-Tag: accepted/tizen/unified/20221209.014552~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F96%2F283296%2F4;p=platform%2Fcore%2Fuifw%2Faurum.git Aurum: Introduce new atspi event callback system. - usage : 1. callback function bool deactive_cb(void *data, A11yEvent type, std::string pkg) { return false; } AccessibleWatcher::getInstance()->registerCallback(A11yEvent::EVENT_WINDOW_DEACTIVATE, &deactive_cb, nullptr); 2. lambda expression AccessibleWatcher::getInstance()->registerCallback(A11yEvent::EVENT_WINDOW_ACTIVATE, [](void *data, A11yEvent type, std::string pkg) { return true; }, nullptr); Change-Id: I1401e6d71c5579967ab7094a8b84545bb3ad3c4b --- diff --git a/libaurum/inc/A11yEventHandler.h b/libaurum/inc/A11yEventHandler.h new file mode 100644 index 0000000..7687308 --- /dev/null +++ b/libaurum/inc/A11yEventHandler.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2022 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. + * + */ + +#ifndef _A11Y_EVENT_HANDLER_H_ +#define _A11Y_EVENT_HANDLER_H_ + +#include "A11yEvent.h" + +namespace Aurum { + +typedef bool (*EventHandler)(void *data, const A11yEvent type, std::string pkg); + +/** + * @class A11yEventHandler + * + * @ingroup aurum + * + * @brief Class that handles the A11yEvent. + */ +class A11yEventHandler { +public: + /** + * @brief A11yEventHandler constructor with event type, callback and data + * + * @param[in] type @A11yEvent + * @param[in] cb user callback + * @param[in] data user data + * + * @since_tizen 7.5 + */ + A11yEventHandler(A11yEvent type, EventHandler cb, void *data); + + /** + * @brief Gets A11yEvent + * + * @return @A11yEvent + * + * @since_tizen 7.5 + */ + A11yEvent getType() const; + + /** + * @brief Calls user callback function. + * + * @param[in] pkg package name + * + * @return false removes user callback + * + * @since_tizen 7.5 + */ + bool operator() (std::string pkg); + +private: + A11yEvent mType; + EventHandler mCb; + void *mData; +}; + +} + +#endif diff --git a/libaurum/inc/Accessibility/AccessibleWatcher.h b/libaurum/inc/Accessibility/AccessibleWatcher.h index 5f2c300..c3b9308 100644 --- a/libaurum/inc/Accessibility/AccessibleWatcher.h +++ b/libaurum/inc/Accessibility/AccessibleWatcher.h @@ -24,6 +24,7 @@ #include "IEventSource.h" #include "Runnable.h" #include "A11yEvent.h" +#include "A11yEventHandler.h" #include "AurumXML.h" #include @@ -126,6 +127,18 @@ public: */ virtual std::map> getXMLDocMap(void) = 0; + /** + * @brief Register atspi event callback. + * + * @param[in] type @A11yEvent + * @param[in] cb @EventHandler + * @param[in] data @void pointer + * + * @return true if callback is registered, else false + * @since_tizen 7.0 + */ + virtual bool registerCallback(const A11yEvent type, EventHandler cb, void *data) = 0; + public: /** * @brief Gets active application vector. diff --git a/libaurum/inc/Aurum.h b/libaurum/inc/Aurum.h index c916371..e2ecd24 100644 --- a/libaurum/inc/Aurum.h +++ b/libaurum/inc/Aurum.h @@ -61,6 +61,7 @@ #include "PartialMatch.h" #include "Comparer.h" #include "A11yEvent.h" +#include "A11yEventHandler.h" #include "Runnables.h" #ifdef MQTT_ENABLED #include "ScreenAnalyzerWatcher.h" diff --git a/libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h b/libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h index 9285e6a..967b010 100644 --- a/libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h +++ b/libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h @@ -117,6 +117,11 @@ public: */ virtual std::map> getXMLDocMap(void) override; + /** + * @copydoc @AccessibleWatcher::registerCallback() + */ + virtual bool registerCallback(const A11yEvent type, EventHandler cb, void *data) override; + public: /** * @brief Listen atspi events. @@ -137,23 +142,12 @@ public: */ void onObjectDefunct(AtspiAccessible *node) override; - /** - * @brief AtspiEvent listener. - * - * @param[in] event AtspiEvent - * @param[in] user_data data for event by user - * - * @since_tizen 6.5 - */ - static void onEventListener(AtspiEvent *event, void *user_data); private: /** Private methods for Mock Test **/ bool removeFromActivatedList(AtspiAccessible *node); bool addToActivatedList(AtspiAccessible *node); bool removeFromWindowSet(AtspiAccessible *node); bool addToWindowSet(AtspiAccessible *node); - void addEventListener(AtspiEventListener *listener, A11yEvent type); - void removeEventListener(AtspiEventListener *listener, A11yEvent type); static gpointer eventThreadLoop(gpointer data); void appendApp(AtspiAccessibleWatcher *instance, AtspiAccessible *app, char *pkg); void removeApp(AtspiAccessibleWatcher *instance, AtspiAccessible *app, char *pkg); @@ -171,6 +165,7 @@ private: static GMainLoop *mLoop; bool isTv; std::mutex XMLMutex; + std::map>> mHandlers; }; } diff --git a/libaurum/inc/Impl/Accessibility/MockAccessibleWatcher.h b/libaurum/inc/Impl/Accessibility/MockAccessibleWatcher.h index 0139365..80209bf 100644 --- a/libaurum/inc/Impl/Accessibility/MockAccessibleWatcher.h +++ b/libaurum/inc/Impl/Accessibility/MockAccessibleWatcher.h @@ -73,6 +73,8 @@ public: */ virtual bool executeAndWaitForEvents(const Runnable *cmd, const A11yEvent type, const int timeout, const std::string packageName) override; + virtual bool registerCallback(const A11yEvent type, EventHandler cb, void *data) override; + std::map> getActiveAppMap(void); std::map> getXMLDocMap(void); diff --git a/libaurum/inc/UiDevice.h b/libaurum/inc/UiDevice.h index fa4a22a..025221f 100644 --- a/libaurum/inc/UiDevice.h +++ b/libaurum/inc/UiDevice.h @@ -372,6 +372,19 @@ public: */ bool executeAndWaitForEvents( const Runnable *cmd, const A11yEvent type, const int timeout, const std::string packageName) const; + +/** + * @brief Register atspi event callback. + * + * @param[in] type @A11yEvent + * @param[in] cb @EventHandler + * @param[in] data @void pointer + * + * @return true if callback is registered, else false + * @since_tizen 7.0 + */ + bool registerCallback(const A11yEvent type, EventHandler cb, void *data) const; + public: /** * @brief Gets UiDevice instance. diff --git a/libaurum/meson.build b/libaurum/meson.build index df52fc4..58e8e18 100644 --- a/libaurum/meson.build +++ b/libaurum/meson.build @@ -15,6 +15,7 @@ libaurum_install_inc = [ './inc/PartialMatch.h', './inc/UiScrollable.h', './inc/A11yEvent.h', + './inc/A11yEventHandler.h', './inc/Comparer.h', './inc/AurumXML.h', './inc/Accessibility/AccessibleNode.h', diff --git a/libaurum/src/A11yEventHandler.cc b/libaurum/src/A11yEventHandler.cc new file mode 100644 index 0000000..b0cb63d --- /dev/null +++ b/libaurum/src/A11yEventHandler.cc @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2021 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 "Aurum.h" + +using namespace Aurum; + +A11yEventHandler::A11yEventHandler(A11yEvent type, EventHandler cb, void *data) + : mType(type), mCb(cb), mData(data) +{ +} +A11yEvent A11yEventHandler::getType() const +{ + return mType; +} +bool A11yEventHandler::operator() (std::string pkg) +{ + return mCb(mData, mType, pkg); +} + diff --git a/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc b/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc index f3d7d8e..27f332e 100644 --- a/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc +++ b/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc @@ -251,9 +251,24 @@ void AtspiAccessibleWatcher::onAtspiEvents(AtspiEvent *event, void *watcher) pkg = strdup(""); mMutex.lock(); - mEventQueue.push_back(std::make_shared(std::string(event->type), std::string(name), std::string(pkg))); + auto a11yEvent = std::make_shared(std::string(event->type), std::string(name), std::string(pkg)); + mEventQueue.push_back(a11yEvent); mMutex.unlock(); + if (instance->mHandlers.count(a11yEvent->getEvent())) { + auto &list = instance->mHandlers[a11yEvent->getEvent()]; + auto it = list.begin(); + + while (it != list.end()) + { + LOGI("Callback call type %s pkg %s", event->type, pkg); + auto handler = *it; + bool res = (*handler)(std::string(pkg)); + if (!res) it = list.erase(it); + else ++it; + } + } + if (!strcmp(event->type, "object:state-changed:defunct")) { instance->onObjectDefunct( static_cast(event->source)); @@ -417,3 +432,18 @@ bool AtspiAccessibleWatcher::addToWindowSet(AtspiAccessible *node) } return false; } + +bool AtspiAccessibleWatcher::registerCallback(const A11yEvent type, EventHandler cb, void *data) +{ + auto handler = std::make_shared(type, cb, data); + if (mHandlers.count(type)) { + auto list = mHandlers[type]; + list.push_back(handler); + mHandlers[type] = list; + } else { + std::list> list; + list.push_back(handler); + mHandlers.insert(std::pair>>(type, list)); + } + return true; +} diff --git a/libaurum/src/Impl/Accessibility/MockAccessibleWatcher.cc b/libaurum/src/Impl/Accessibility/MockAccessibleWatcher.cc index 4377d88..ac44651 100644 --- a/libaurum/src/Impl/Accessibility/MockAccessibleWatcher.cc +++ b/libaurum/src/Impl/Accessibility/MockAccessibleWatcher.cc @@ -72,3 +72,8 @@ bool MockAccessibleWatcher::executeAndWaitForEvents(const Runnable *cmd, const A { return true; } + +bool MockAccessibleWatcher::registerCallback(const A11yEvent type, EventHandler cb, void *data) +{ + return true; +} \ No newline at end of file diff --git a/libaurum/src/UiDevice.cc b/libaurum/src/UiDevice.cc index eccd630..4865aa6 100644 --- a/libaurum/src/UiDevice.cc +++ b/libaurum/src/UiDevice.cc @@ -475,3 +475,8 @@ bool UiDevice::getWithScreenAnalyzer() { return mIsWithSA; } + +bool UiDevice::registerCallback(const A11yEvent type, EventHandler cb, void *data) const +{ + return AccessibleWatcher::getInstance()->registerCallback(type, cb, data); +} \ No newline at end of file diff --git a/libaurum/src/meson.build b/libaurum/src/meson.build index 778c7b0..7e6a215 100644 --- a/libaurum/src/meson.build +++ b/libaurum/src/meson.build @@ -9,6 +9,7 @@ libaurum_src += [ files('Waiter.cc'), files('PartialMatch.cc'), files('A11yEvent.cc'), + files('A11yEventHandler.cc'), files('AurumXML.cc'), files('TizenWindow.cc'), ]