--- /dev/null
+/*
+ * 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
#include "IEventSource.h"
#include "Runnable.h"
#include "A11yEvent.h"
+#include "A11yEventHandler.h"
#include "AurumXML.h"
#include <atspi/atspi.h>
*/
virtual std::map<std::string, std::shared_ptr<AurumXML>> 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.
#include "PartialMatch.h"
#include "Comparer.h"
#include "A11yEvent.h"
+#include "A11yEventHandler.h"
#include "Runnables.h"
#ifdef MQTT_ENABLED
#include "ScreenAnalyzerWatcher.h"
*/
virtual std::map<std::string, std::shared_ptr<AurumXML>> getXMLDocMap(void) override;
+ /**
+ * @copydoc @AccessibleWatcher::registerCallback()
+ */
+ virtual bool registerCallback(const A11yEvent type, EventHandler cb, void *data) override;
+
public:
/**
* @brief Listen atspi events.
*/
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);
static GMainLoop *mLoop;
bool isTv;
std::mutex XMLMutex;
+ std::map<const A11yEvent, std::list<std::shared_ptr<A11yEventHandler>>> mHandlers;
};
}
*/
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<AtspiAccessible *, std::shared_ptr<AccessibleApplication>> getActiveAppMap(void);
std::map<std::string, std::shared_ptr<AurumXML>> getXMLDocMap(void);
*/
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.
'./inc/PartialMatch.h',
'./inc/UiScrollable.h',
'./inc/A11yEvent.h',
+ './inc/A11yEventHandler.h',
'./inc/Comparer.h',
'./inc/AurumXML.h',
'./inc/Accessibility/AccessibleNode.h',
--- /dev/null
+/*
+ * 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);
+}
+
pkg = strdup("");
mMutex.lock();
- mEventQueue.push_back(std::make_shared<A11yEventInfo>(std::string(event->type), std::string(name), std::string(pkg)));
+ auto a11yEvent = std::make_shared<A11yEventInfo>(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<AtspiAccessible *>(event->source));
}
return false;
}
+
+bool AtspiAccessibleWatcher::registerCallback(const A11yEvent type, EventHandler cb, void *data)
+{
+ auto handler = std::make_shared<A11yEventHandler>(type, cb, data);
+ if (mHandlers.count(type)) {
+ auto list = mHandlers[type];
+ list.push_back(handler);
+ mHandlers[type] = list;
+ } else {
+ std::list<std::shared_ptr<A11yEventHandler>> list;
+ list.push_back(handler);
+ mHandlers.insert(std::pair<const A11yEvent, std::list<std::shared_ptr<A11yEventHandler>>>(type, list));
+ }
+ return true;
+}
{
return true;
}
+
+bool MockAccessibleWatcher::registerCallback(const A11yEvent type, EventHandler cb, void *data)
+{
+ return true;
+}
\ No newline at end of file
{
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
files('Waiter.cc'),
files('PartialMatch.cc'),
files('A11yEvent.cc'),
+ files('A11yEventHandler.cc'),
files('AurumXML.cc'),
files('TizenWindow.cc'),
]