/**
* @brief TBD
*/
- static std::vector<std::shared_ptr<A11yEventInfo>> mEventQueue;
+ static std::vector<std::shared_ptr<A11yEventInfo>> mEventQueue;
+
+ static std::mutex mMutex;
};
static AtspiAccessible *Atspi_accessible_get_application (AtspiAccessible *node, GError **error);
static void Atspi_accessible_clear_cache (AtspiAccessible *node);
- static void lock();
- static void unlock();
private:
static std::recursive_mutex mMutex;
//static std::unique_lock<std::mutex> mLock;
int AtspiAccessibleNode::getChildCount() const
{
- AtspiWrapper::lock();
if (!isValid()) {
- AtspiWrapper::unlock();
return 0;
}
int count = AtspiWrapper::Atspi_accessible_get_child_count(mNode, NULL);
- AtspiWrapper::unlock();
if (count <= 0) return 0;
return count;
}
std::shared_ptr<AccessibleNode> AtspiAccessibleNode::getChildAt(int index) const
{
- AtspiWrapper::lock();
if (!isValid()) {
- AtspiWrapper::unlock();
return std::make_shared<AtspiAccessibleNode>(nullptr);
}
AtspiAccessible *rawChild = AtspiWrapper::Atspi_accessible_get_child_at_index(mNode, index, NULL);
- AtspiWrapper::unlock();
return std::make_shared<AtspiAccessibleNode>(rawChild);
}
std::shared_ptr<AccessibleNode> AtspiAccessibleNode::getParent() const
{
- AtspiWrapper::lock();
if (!isValid()) {
- AtspiWrapper::unlock();
return std::make_shared<AtspiAccessibleNode>(nullptr);
}
AtspiAccessible *rawParent = AtspiWrapper::Atspi_accessible_get_parent(mNode, NULL);
- AtspiWrapper::unlock();
return std::make_shared<AtspiAccessibleNode>(rawParent);
}
void AtspiAccessibleNode::refresh()
{
- AtspiWrapper::lock();
-
AtspiWrapper::Atspi_accessible_clear_cache(mNode);
if (isValid()) {
} else {
setFeatureProperty(ATSPI_STATE_INVALID);
}
- AtspiWrapper::unlock();
}
std::vector<std::string> AtspiAccessibleNode::getActions() const
{
- AtspiWrapper::lock();
-
std::vector<std::string> result{};
AtspiAction *action;
if (!isValid()) {
- AtspiWrapper::unlock();
return result;
}
g_object_unref(action);
}
- AtspiWrapper::unlock();
-
return result;
}
bool AtspiAccessibleNode::doAction(std::string actionName)
{
- AtspiWrapper::lock();
AtspiAction *action;
if (!isValid()) {
- AtspiWrapper::unlock();
return false;
}
for (a = 0; a < n_actions; a++) {
char *action_name = AtspiWrapper::Atspi_action_get_action_name(action, a, NULL);
if (!action_name) {
- AtspiWrapper::unlock();
return false;
}
AtspiWrapper::Atspi_action_do_action(action, a, NULL);
g_free(action_name);
g_object_unref(action);
- AtspiWrapper::unlock();
return true;
}
g_free(action_name);
}
g_object_unref(action);
}
- AtspiWrapper::unlock();
return false;
}
void AtspiAccessibleNode::setValue(std::string text)
{
- AtspiWrapper::lock();
if (!isValid()){
- AtspiWrapper::unlock();
return;
}
AtspiWrapper::Atspi_editable_text_insert_text(iface, 0, text.c_str(), text.length(),
NULL);
}
- AtspiWrapper::unlock();
}
void AtspiAccessibleNode::setFeatureProperty(AtspiStateType type)
std::vector<std::shared_ptr<A11yEventInfo>> AtspiAccessibleWatcher::mEventQueue;
GThread *AtspiAccessibleWatcher::mEventThread = nullptr;
+std::mutex AtspiAccessibleWatcher::mMutex = std::mutex{};
static bool iShowingNode(AtspiAccessible *node)
{
void AtspiAccessibleWatcher::onAtspiEvents(AtspiEvent *event, void *user_data)
{
- AtspiWrapper::lock();
if (!event->source)
{
- AtspiWrapper::unlock();
return;
}
char *name = NULL, *pkg = NULL;
else
pkg = strdup("");
+ mMutex.lock();
mEventQueue.push_back(std::make_shared<A11yEventInfo>(std::string(event->type), std::string(name), std::string(pkg)));
+ mMutex.unlock();
if (!strcmp(event->type, "object:state-changed:defunct")) {
instance->onObjectDefunct(
}
if (name) free(name);
if (pkg) free(pkg);
-
- AtspiWrapper::unlock();
}
void AtspiAccessibleWatcher::print_debug()
int AtspiAccessibleWatcher::getApplicationCount(void) const
{
- AtspiWrapper::lock();
-
AtspiAccessible *root = AtspiWrapper::Atspi_get_desktop(0);
int nchild = AtspiWrapper::Atspi_accessible_get_child_count(root, NULL);
g_object_unref(root);
- AtspiWrapper::unlock();
-
if (nchild <= 0) return 0;
return nchild;
}
std::shared_ptr<AccessibleApplication> AtspiAccessibleWatcher::getApplicationAt(int index) const
{
- AtspiWrapper::lock();
AtspiAccessible *root = AtspiWrapper::Atspi_get_desktop(0);
AtspiAccessible *child = AtspiWrapper::Atspi_accessible_get_child_at_index(root, index, NULL);
g_object_unref(root);
- AtspiWrapper::unlock();
return std::make_shared<AtspiAccessibleApplication>(std::make_shared<AtspiAccessibleNode>(child));
}
std::vector<std::shared_ptr<AccessibleApplication>> AtspiAccessibleWatcher::getApplications(void) const
{
- AtspiWrapper::lock();
std::vector<std::shared_ptr<AccessibleApplication>> ret{};
AtspiAccessible *root = AtspiWrapper::Atspi_get_desktop(0);
int nchild = AtspiWrapper::Atspi_accessible_get_child_count(root, NULL);
if (nchild <= 0) {
g_object_unref(root);
- AtspiWrapper::unlock();
return ret;
}
}
}
g_object_unref(root);
- AtspiWrapper::unlock();
return ret;
}
bool AtspiAccessibleWatcher::executeAndWaitForEvents(const Runnable *cmd, const A11yEvent type, const int timeout)
{
- AtspiWrapper::lock();
+ mMutex.lock();
mEventQueue.clear();
- AtspiWrapper::unlock();
+ mMutex.unlock();
if (cmd)
cmd->run();
while (true)
{
std::vector<std::shared_ptr<A11yEventInfo>> localEvents;
- AtspiWrapper::lock();
+ mMutex.lock();
localEvents.assign(mEventQueue.begin(), mEventQueue.end());
mEventQueue.clear();
- AtspiWrapper::unlock();
+ mMutex.unlock();
if (!localEvents.empty())
{
#include "AtspiWrapper.h"
std::recursive_mutex AtspiWrapper::mMutex = std::recursive_mutex{};
-//std::unique_lock<std::mutex> AtspiWrapper::mLock = std::unique_lock<std::mutex>(mMutex, std::defer_lock);
GArray *AtspiWrapper::Atspi_state_set_get_states(AtspiStateSet *set)
{
std::unique_lock<std::recursive_mutex> lock(mMutex);
return atspi_accessible_clear_cache(node);
}
-void AtspiWrapper::lock()
-{
- mMutex.lock();
-}
-
-void AtspiWrapper::unlock()
-{
- mMutex.unlock();
-}