/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// INTERNAL INCLUDES
#include <dali/devel-api/adaptor-framework/environment-variable.h>
#include <dali/devel-api/adaptor-framework/window-devel.h>
+#include <dali/internal/accessibility/bridge/accessibility-common.h>
#include <dali/internal/accessibility/bridge/bridge-accessible.h>
#include <dali/internal/accessibility/bridge/bridge-action.h>
#include <dali/internal/accessibility/bridge/bridge-collection.h>
#include <dali/internal/accessibility/bridge/bridge-component.h>
#include <dali/internal/accessibility/bridge/bridge-editable-text.h>
+#include <dali/internal/accessibility/bridge/bridge-hypertext.h>
+#include <dali/internal/accessibility/bridge/bridge-hyperlink.h>
#include <dali/internal/accessibility/bridge/bridge-object.h>
#include <dali/internal/accessibility/bridge/bridge-selection.h>
+#include <dali/internal/accessibility/bridge/bridge-socket.h>
#include <dali/internal/accessibility/bridge/bridge-text.h>
#include <dali/internal/accessibility/bridge/bridge-value.h>
#include <dali/internal/accessibility/bridge/bridge-application.h>
-#include <dali/internal/accessibility/bridge/dummy-atspi.h>
+#include <dali/internal/accessibility/bridge/dummy/dummy-atspi.h>
#include <dali/internal/adaptor/common/adaptor-impl.h>
#include <dali/internal/system/common/environment-variables.h>
using namespace Dali::Accessibility;
+namespace // unnamed namespace
+{
+
+const int RETRY_INTERVAL = 1000;
+
+} // unnamed namespace
+
+/**
+ * @brief The BridgeImpl class is to implement some Bridge functions.
+ */
class BridgeImpl : public virtual BridgeBase,
public BridgeAccessible,
public BridgeObject,
public BridgeText,
public BridgeEditableText,
public BridgeSelection,
- public BridgeApplication
+ public BridgeApplication,
+ public BridgeHypertext,
+ public BridgeHyperlink,
+ public BridgeSocket
{
- DBus::DBusClient listenOnAtspiEnabledSignalClient;
- DBus::DBusClient registryClient, directReadingClient;
- bool screenReaderEnabled = false;
- bool isEnabled = false;
- bool isShown = false;
- std::unordered_map<int32_t, std::function<void(std::string)>> directReadingCallbacks;
- Dali::Actor highlightedActor;
- std::function<void(Dali::Actor)> highlightClearAction;
+ DBus::DBusClient mAccessibilityStatusClient;
+ DBus::DBusClient mRegistryClient;
+ DBus::DBusClient mDirectReadingClient;
+ bool mIsScreenReaderEnabled = false;
+ bool mIsEnabled = false;
+ std::unordered_map<int32_t, std::function<void(std::string)>> mDirectReadingCallbacks;
+ Dali::Actor mHighlightedActor;
+ std::function<void(Dali::Actor)> mHighlightClearAction;
+ Dali::CallbackBase* mIdleCallback = NULL;
+ Dali::Timer mInitializeTimer;
+ Dali::Timer mReadIsEnabledTimer;
+ Dali::Timer mReadScreenReaderEnabledTimer;
+ Dali::Timer mForceUpTimer;
+ std::string mPreferredBusName;
public:
BridgeImpl()
{
- listenOnAtspiEnabledSignalClient = DBus::DBusClient{A11yDbusName, A11yDbusPath, A11yDbusStatusInterface, DBus::ConnectionType::SESSION};
-
- listenOnAtspiEnabledSignalClient.addPropertyChangedEvent<bool>("ScreenReaderEnabled", [this](bool res) {
- screenReaderEnabled = res;
- if(screenReaderEnabled || isEnabled)
- {
- ForceUp();
- }
- else
- {
- ForceDown();
- }
- });
-
- listenOnAtspiEnabledSignalClient.addPropertyChangedEvent<bool>("IsEnabled", [this](bool res) {
- isEnabled = res;
- if(screenReaderEnabled || isEnabled)
- {
- ForceUp();
- }
- else
- {
- ForceDown();
- }
- });
}
+ /**
+ * @copydoc Dali::Accessibility::Bridge::Emit()
+ */
Consumed Emit(KeyEventType type, unsigned int keyCode, const std::string& keyName, unsigned int timeStamp, bool isText) override
{
if(!IsUp())
return Consumed::NO;
}
}
- auto m = registryClient.method<bool(std::tuple<uint32_t, int32_t, int32_t, int32_t, int32_t, std::string, bool>)>("NotifyListenersSync");
- auto result = m.call(std::tuple<uint32_t, int32_t, int32_t, int32_t, int32_t, std::string, bool>{keyType, 0, static_cast<int32_t>(keyCode), 0, static_cast<int32_t>(timeStamp), keyName, isText ? 1 : 0});
- if(!result)
- {
- LOG() << result.getError().message;
- return Consumed::NO;
- }
- return std::get<0>(result) ? Consumed::YES : Consumed::NO;
+
+ return Consumed::NO;
}
+ /**
+ * @copydoc Dali::Accessibility::Bridge::Pause()
+ */
void Pause() override
{
if(!IsUp())
return;
}
- directReadingClient.method<DBus::ValueOrError<void>(bool)>("PauseResume").asyncCall([](DBus::ValueOrError<void> msg) {
+ mDirectReadingClient.method<DBus::ValueOrError<void>(bool)>("PauseResume").asyncCall([](DBus::ValueOrError<void> msg) {
if(!msg)
{
- LOG() << "Direct reading command failed (" << msg.getError().message << ")";
+ LOG() << "Direct reading command failed (" << msg.getError().message << ")\n";
}
},
true);
}
+ /**
+ * @copydoc Dali::Accessibility::Bridge::Resume()
+ */
void Resume() override
{
if(!IsUp())
return;
}
- directReadingClient.method<DBus::ValueOrError<void>(bool)>("PauseResume").asyncCall([](DBus::ValueOrError<void> msg) {
+ mDirectReadingClient.method<DBus::ValueOrError<void>(bool)>("PauseResume").asyncCall([](DBus::ValueOrError<void> msg) {
if(!msg)
{
- LOG() << "Direct reading command failed (" << msg.getError().message << ")";
+ LOG() << "Direct reading command failed (" << msg.getError().message << ")\n";
}
},
false);
}
+ /**
+ * @copydoc Dali::Accessibility::Bridge::StopReading()
+ */
void StopReading(bool alsoNonDiscardable) override
{
if(!IsUp())
return;
}
- directReadingClient.method<DBus::ValueOrError<void>(bool)>("StopReading").asyncCall([](DBus::ValueOrError<void> msg) {
+ mDirectReadingClient.method<DBus::ValueOrError<void>(bool)>("StopReading").asyncCall([](DBus::ValueOrError<void> msg) {
if(!msg)
{
- LOG() << "Direct reading command failed (" << msg.getError().message << ")";
+ LOG() << "Direct reading command failed (" << msg.getError().message << ")\n";
}
},
alsoNonDiscardable);
}
+ /**
+ * @copydoc Dali::Accessibility::Bridge::Say()
+ */
void Say(const std::string& text, bool discardable, std::function<void(std::string)> callback) override
{
if(!IsUp())
return;
}
- directReadingClient.method<DBus::ValueOrError<std::string, bool, int32_t>(std::string, bool)>("ReadCommand").asyncCall([=](DBus::ValueOrError<std::string, bool, int32_t> msg) {
+ mDirectReadingClient.method<DBus::ValueOrError<std::string, bool, int32_t>(std::string, bool)>("ReadCommand").asyncCall([=](DBus::ValueOrError<std::string, bool, int32_t> msg) {
if(!msg)
{
- LOG() << "Direct reading command failed (" << msg.getError().message << ")";
+ LOG() << "Direct reading command failed (" << msg.getError().message << ")\n";
}
else if(callback)
{
- directReadingCallbacks.emplace(std::get<2>(msg), callback);
+ mDirectReadingCallbacks.emplace(std::get<2>(msg), callback);
}
},
text,
discardable);
}
+ /**
+ * @copydoc Dali::Accessibility::Bridge::ForceDown()
+ */
void ForceDown() override
{
if(mData)
}
mData->mCurrentlyHighlightedActor = {};
mData->mHighlightActor = {};
+
+ mDisabledSignal.Emit();
+ UnembedSocket(mApplication.GetAddress(), {AtspiDbusNameRegistry, "root"});
+ ReleaseBusName(mPreferredBusName);
}
- highlightedActor = {};
- highlightClearAction = {};
+
+ mHighlightedActor = {};
+ mHighlightClearAction = {};
BridgeAccessible::ForceDown();
- registryClient = {};
- directReadingClient = {};
- directReadingCallbacks.clear();
+ mRegistryClient = {};
+ mDirectReadingClient = {};
+ mDirectReadingCallbacks.clear();
+ mApplication.mChildren.clear();
+ ClearTimer();
}
+ void ClearTimer()
+ {
+ if(mInitializeTimer)
+ {
+ mInitializeTimer.Stop();
+ mInitializeTimer.Reset();
+ }
+
+ if(mReadIsEnabledTimer)
+ {
+ mReadIsEnabledTimer.Stop();
+ mReadIsEnabledTimer.Reset();
+ }
+
+ if(mReadScreenReaderEnabledTimer)
+ {
+ mReadScreenReaderEnabledTimer.Stop();
+ mReadScreenReaderEnabledTimer.Reset();
+ }
+
+ if(mForceUpTimer)
+ {
+ mForceUpTimer.Stop();
+ mForceUpTimer.Reset();
+ }
+ }
+
+ /**
+ * @copydoc Dali::Accessibility::Bridge::Terminate()
+ */
void Terminate() override
{
if(mData)
{
+ // The ~Window() after this point cannot emit DESTROY, because Bridge is not available. So emit DESTROY here.
+ for(auto windowAccessible : mApplication.mChildren)
+ {
+ BridgeObject::Emit(windowAccessible, WindowEvent::DESTROY);
+ }
mData->mCurrentlyHighlightedActor = {};
mData->mHighlightActor = {};
}
ForceDown();
- listenOnAtspiEnabledSignalClient = {};
- dbusServer = {};
- con = {};
+ if((NULL != mIdleCallback) && Dali::Adaptor::IsAvailable())
+ {
+ Dali::Adaptor::Get().RemoveIdle(mIdleCallback);
+ }
+ mAccessibilityStatusClient = {};
+ mDbusServer = {};
+ mConnectionPtr = {};
+ }
+
+ bool ForceUpTimerCallback()
+ {
+ if(ForceUp() != ForceUpResult::FAILED)
+ {
+ return false;
+ }
+ return true;
}
+ /**
+ * @copydoc Dali::Accessibility::Bridge::ForceUp()
+ */
ForceUpResult ForceUp() override
{
- if(BridgeAccessible::ForceUp() == ForceUpResult::ALREADY_UP)
+ auto forceUpResult = BridgeAccessible::ForceUp();
+ if(forceUpResult == ForceUpResult::ALREADY_UP)
{
- return ForceUpResult::ALREADY_UP;
+ return forceUpResult;
+ }
+ else if(forceUpResult == ForceUpResult::FAILED)
+ {
+ if(!mForceUpTimer)
+ {
+ mForceUpTimer = Dali::Timer::New(RETRY_INTERVAL);
+ mForceUpTimer.TickSignal().Connect(this, &BridgeImpl::ForceUpTimerCallback);
+ mForceUpTimer.Start();
+ }
+ return forceUpResult;
}
BridgeObject::RegisterInterfaces();
BridgeEditableText::RegisterInterfaces();
BridgeSelection::RegisterInterfaces();
BridgeApplication::RegisterInterfaces();
+ BridgeHypertext::RegisterInterfaces();
+ BridgeHyperlink::RegisterInterfaces();
+ BridgeSocket::RegisterInterfaces();
- RegisterOnBridge(&application);
+ RegisterOnBridge(&mApplication);
- registryClient = {AtspiDbusNameRegistry, AtspiDbusPathDec, AtspiDbusInterfaceDec, con};
- directReadingClient = DBus::DBusClient{DirectReadingDBusName, DirectReadingDBusPath, DirectReadingDBusInterface, con};
- directReadingClient.addSignal<void(int32_t, std::string)>("ReadingStateChanged", [=](int32_t id, std::string readingState) {
- auto it = directReadingCallbacks.find(id);
- if(it != directReadingCallbacks.end())
+ mRegistryClient = {AtspiDbusNameRegistry, AtspiDbusPathDec, Accessible::GetInterfaceName(AtspiInterface::DEVICE_EVENT_CONTROLLER), mConnectionPtr};
+ mDirectReadingClient = DBus::DBusClient{DirectReadingDBusName, DirectReadingDBusPath, DirectReadingDBusInterface, mConnectionPtr};
+
+ mDirectReadingClient.addSignal<void(int32_t, std::string)>("ReadingStateChanged", [=](int32_t id, std::string readingState) {
+ auto it = mDirectReadingCallbacks.find(id);
+ if(it != mDirectReadingCallbacks.end())
{
it->second(readingState);
if(readingState != "ReadingPaused" && readingState != "ReadingResumed" && readingState != "ReadingStarted")
- directReadingCallbacks.erase(it);
+ {
+ mDirectReadingCallbacks.erase(it);
+ }
}
});
- auto proxy = DBus::DBusClient{AtspiDbusNameRegistry, AtspiDbusPathRoot, AtspiDbusInterfaceSocket, con};
- Address root{"", "root"};
- auto res = proxy.method<Address(Address)>("Embed").call(root);
- if(!res)
+ RequestBusName(mPreferredBusName);
+
+ auto parentAddress = EmbedSocket(mApplication.GetAddress(), {AtspiDbusNameRegistry, "root"});
+ mApplication.mParent.SetAddress(std::move(parentAddress));
+ mEnabledSignal.Emit();
+
+ return ForceUpResult::JUST_STARTED;
+ }
+
+ /**
+ * @brief Sends a signal to dbus that the window is shown.
+ *
+ * @param[in] window The window to be shown
+ * @see Accessible::EmitShowing() and BridgeObject::EmitStateChanged()
+ */
+ void EmitShown(Dali::Window window)
+ {
+ auto windowAccessible = mApplication.GetWindowAccessible(window);
+ if(windowAccessible)
+ {
+ windowAccessible->EmitShowing(true);
+ }
+ }
+
+ /**
+ * @brief Sends a signal to dbus that the window is hidden.
+ *
+ * @param[in] window The window to be hidden
+ * @see Accessible::EmitShowing() and BridgeObject::EmitStateChanged()
+ */
+ void EmitHidden(Dali::Window window)
+ {
+ auto windowAccessible = mApplication.GetWindowAccessible(window);
+ if(windowAccessible)
{
- LOG() << "Call to Embed failed: " << res.getError().message;
+ windowAccessible->EmitShowing(false);
}
- assert(res);
- application.parent.SetAddress(std::move(std::get<0>(res)));
- if(isShown)
+ }
+
+ /**
+ * @brief Sends a signal to dbus that the window is activated.
+ *
+ * @param[in] window The window to be activated
+ * @see BridgeObject::Emit()
+ */
+ void EmitActivate(Dali::Window window)
+ {
+ auto windowAccessible = mApplication.GetWindowAccessible(window);
+ if(windowAccessible)
{
- EmitActivate();
+ windowAccessible->Emit(WindowEvent::ACTIVATE, 0);
}
- return ForceUpResult::JUST_STARTED;
}
- void EmitActivate()
+ /**
+ * @brief Sends a signal to dbus that the window is deactivated.
+ *
+ * @param[in] window The window to be deactivated
+ * @see BridgeObject::Emit()
+ */
+ void EmitDeactivate(Dali::Window window)
{
- auto win = application.getActiveWindow();
- if(win)
+ auto windowAccessible = mApplication.GetWindowAccessible(window);
+ if(windowAccessible)
{
- win->Emit(WindowEvent::ACTIVATE, 0);
+ windowAccessible->Emit(WindowEvent::DEACTIVATE, 0);
}
}
- void EmitDeactivate()
+ /**
+ * @copydoc Dali::Accessibility::Bridge::WindowShown()
+ */
+ void WindowShown(Dali::Window window) override
{
- auto win = application.getActiveWindow();
- if(win)
+ if(IsUp())
{
- win->Emit(WindowEvent::DEACTIVATE, 0);
+ EmitShown(window);
}
}
- void ApplicationHidden() override
+ /**
+ * @copydoc Dali::Accessibility::Bridge::WindowHidden()
+ */
+ void WindowHidden(Dali::Window window) override
{
- if(isShown && IsUp())
+ if(IsUp())
{
- EmitDeactivate();
+ EmitHidden(window);
}
- isShown = false;
}
- void ApplicationShown() override
+ /**
+ * @copydoc Dali::Accessibility::Bridge::WindowFocused()
+ */
+ void WindowFocused(Dali::Window window) override
{
- if(!isShown && IsUp())
+ if(IsUp())
{
- EmitActivate();
+ EmitActivate(window);
}
- isShown = true;
}
- void Initialize() override
+ /**
+ * @copydoc Dali::Accessibility::Bridge::WindowUnfocused()
+ */
+ void WindowUnfocused(Dali::Window window) override
{
- auto dbusClient = DBus::DBusClient{A11yDbusName, A11yDbusPath, A11yDbusStatusInterface, DBus::ConnectionType::SESSION};
- auto enabled = dbusClient.property<bool>("ScreenReaderEnabled").get();
- if(enabled)
+ if(IsUp())
{
- screenReaderEnabled = std::get<0>(enabled);
+ EmitDeactivate(window);
}
+ }
- enabled = dbusClient.property<bool>("IsEnabled").get();
- if(enabled)
+ /**
+ * @copydoc Dali::Accessibility::Bridge::SuppressScreenReader()
+ */
+ void SuppressScreenReader(bool suppress) override
+ {
+ if(mIsScreenReaderSuppressed == suppress)
{
- isEnabled = std::get<0>(enabled);
+ return;
}
+ mIsScreenReaderSuppressed = suppress;
+ ReadScreenReaderEnabledProperty();
+ }
- if(screenReaderEnabled || isEnabled)
+ void SwitchBridge()
+ {
+ if((!mIsScreenReaderSuppressed && mIsScreenReaderEnabled) || mIsEnabled)
{
ForceUp();
}
+ else
+ {
+ ForceDown();
+ }
+ }
+
+ bool ReadIsEnabledTimerCallback()
+ {
+ ReadIsEnabledProperty();
+ return false;
+ }
+
+ void ReadIsEnabledProperty()
+ {
+ mAccessibilityStatusClient.property<bool>("IsEnabled").asyncGet([this](DBus::ValueOrError<bool> msg) {
+ if(!msg)
+ {
+ DALI_LOG_ERROR("Get IsEnabled property error: %s\n", msg.getError().message.c_str());
+ if(msg.getError().errorType == DBus::ErrorType::INVALID_REPLY)
+ {
+ if(!mReadIsEnabledTimer)
+ {
+ mReadIsEnabledTimer = Dali::Timer::New(RETRY_INTERVAL);
+ mReadIsEnabledTimer.TickSignal().Connect(this, &BridgeImpl::ReadIsEnabledTimerCallback);
+ }
+ mReadIsEnabledTimer.Start();
+ }
+ return;
+ }
+
+ if(mReadIsEnabledTimer)
+ {
+ mReadIsEnabledTimer.Stop();
+ mReadIsEnabledTimer.Reset();
+ }
+
+ mIsEnabled = std::get<0>(msg);
+ SwitchBridge();
+ });
+ }
+
+ void ListenIsEnabledProperty()
+ {
+ mAccessibilityStatusClient.addPropertyChangedEvent<bool>("IsEnabled", [this](bool res) {
+ mIsEnabled = res;
+ SwitchBridge();
+ });
+ }
+
+ bool ReadScreenReaderEnabledTimerCallback()
+ {
+ ReadScreenReaderEnabledProperty();
+ return false;
+ }
+
+ void ReadScreenReaderEnabledProperty()
+ {
+ // can be true because of SuppressScreenReader before init
+ if (!mAccessibilityStatusClient)
+ {
+ return;
+ }
+
+ mAccessibilityStatusClient.property<bool>("ScreenReaderEnabled").asyncGet([this](DBus::ValueOrError<bool> msg) {
+ if(!msg)
+ {
+ DALI_LOG_ERROR("Get ScreenReaderEnabled property error: %s\n", msg.getError().message.c_str());
+ if(msg.getError().errorType == DBus::ErrorType::INVALID_REPLY)
+ {
+ if(!mReadScreenReaderEnabledTimer)
+ {
+ mReadScreenReaderEnabledTimer = Dali::Timer::New(RETRY_INTERVAL);
+ mReadScreenReaderEnabledTimer.TickSignal().Connect(this, &BridgeImpl::ReadScreenReaderEnabledTimerCallback);
+ }
+ mReadScreenReaderEnabledTimer.Start();
+ }
+ return;
+ }
+
+ if(mReadScreenReaderEnabledTimer)
+ {
+ mReadScreenReaderEnabledTimer.Stop();
+ mReadScreenReaderEnabledTimer.Reset();
+ }
+
+ mIsScreenReaderEnabled = std::get<0>(msg);
+ SwitchBridge();
+ });
+ }
+
+ void EmitScreenReaderEnabledSignal()
+ {
+ if (mIsScreenReaderEnabled)
+ {
+ mScreenReaderEnabledSignal.Emit();
+ }
+ else
+ {
+ mScreenReaderDisabledSignal.Emit();
+ }
+ }
+
+ void ListenScreenReaderEnabledProperty()
+ {
+ mAccessibilityStatusClient.addPropertyChangedEvent<bool>("ScreenReaderEnabled", [this](bool res) {
+ mIsScreenReaderEnabled = res;
+ EmitScreenReaderEnabledSignal();
+ SwitchBridge();
+ });
+ }
+
+ void ReadAndListenProperties()
+ {
+ ReadIsEnabledProperty();
+ ListenIsEnabledProperty();
+
+ ReadScreenReaderEnabledProperty();
+ ListenScreenReaderEnabledProperty();
+ }
+
+ bool InitializeAccessibilityStatusClient()
+ {
+ mAccessibilityStatusClient = DBus::DBusClient{A11yDbusName, A11yDbusPath, A11yDbusStatusInterface, DBus::ConnectionType::SESSION};
+
+ if (!mAccessibilityStatusClient)
+ {
+ DALI_LOG_ERROR("Accessibility Status DbusClient is not ready\n");
+ return false;
+ }
+
+ return true;
+ }
+
+ bool InitializeTimerCallback()
+ {
+ if ( InitializeAccessibilityStatusClient() )
+ {
+ ReadAndListenProperties();
+ return false;
+ }
+ return true;
+ }
+
+ bool OnIdleSignal()
+ {
+ if ( InitializeAccessibilityStatusClient() )
+ {
+ ReadAndListenProperties();
+ mIdleCallback = NULL;
+ return false;
+ }
+
+ if(!mInitializeTimer)
+ {
+ mInitializeTimer = Dali::Timer::New(RETRY_INTERVAL);
+ mInitializeTimer.TickSignal().Connect(this, &BridgeImpl::InitializeTimerCallback);
+ }
+ mInitializeTimer.Start();
+
+ mIdleCallback = NULL;
+ return false;
+ }
+
+ /**
+ * @copydoc Dali::Accessibility::Bridge::Initialize()
+ */
+ void Initialize() override
+ {
+ if ( InitializeAccessibilityStatusClient() )
+ {
+ ReadAndListenProperties();
+ return;
+ }
+
+ // Initialize failed. Try it again on Idle
+ if( Dali::Adaptor::IsAvailable() )
+ {
+ Dali::Adaptor& adaptor = Dali::Adaptor::Get();
+ if( NULL == mIdleCallback )
+ {
+ mIdleCallback = MakeCallback( this, &BridgeImpl::OnIdleSignal );
+ adaptor.AddIdle( mIdleCallback, true );
+ }
+ }
+ }
+
+ /**
+ * @copydoc Dali::Accessibility::Bridge::GetScreenReaderEnabled()
+ */
+ bool GetScreenReaderEnabled() override
+ {
+ return mIsScreenReaderEnabled;
+ }
+
+ /**
+ * @copydoc Dali::Accessibility::Bridge::IsEnabled()
+ */
+ bool IsEnabled() override
+ {
+ return mIsEnabled;
+ }
+
+ Address EmbedSocket(const Address& plug, const Address& socket) override
+ {
+ auto client = CreateSocketClient(socket);
+ auto reply = client.method<Address(Address)>("Embed").call(plug);
+
+ if(!reply)
+ {
+ DALI_LOG_ERROR("Failed to embed socket %s: %s", socket.ToString().c_str(), reply.getError().message.c_str());
+ return {};
+ }
+
+ return std::get<0>(reply.getValues());
+ }
+
+ void EmbedAtkSocket(const Address& plug, const Address& socket) override
+ {
+ auto client = CreateSocketClient(socket);
+
+ client.method<void(std::string)>("Embedded").call(ATSPI_PREFIX_PATH + plug.GetPath());
+ }
+
+ void UnembedSocket(const Address& plug, const Address& socket) override
+ {
+ auto client = CreateSocketClient(socket);
+
+ client.method<void(Address)>("Unembed").call(plug);
+ }
+
+ void SetSocketOffset(ProxyAccessible* socket, std::int32_t x, std::int32_t y) override
+ {
+ AddCoalescableMessage(CoalescableMessages::SET_OFFSET, socket, 1.0f, [=]() {
+ auto client = CreateSocketClient(socket->GetAddress());
+
+ client.method<void(std::int32_t, std::int32_t)>("SetOffset").asyncCall([](DBus::ValueOrError<void>) {}, x, y);
+ });
+ }
+
+ void SetExtentsOffset(std::int32_t x, std::int32_t y) override
+ {
+ if(mData)
+ {
+ mData->mExtentsOffset = {x, y};
+ }
}
- bool GetScreenReaderEnabled()
+ void SetPreferredBusName(std::string_view preferredBusName) override
{
- return screenReaderEnabled;
+ if(preferredBusName == mPreferredBusName)
+ {
+ return;
+ }
+
+ std::string oldPreferredBusName = std::move(mPreferredBusName);
+ mPreferredBusName = std::string{preferredBusName};
+
+ if(IsUp())
+ {
+ ReleaseBusName(oldPreferredBusName);
+ RequestBusName(mPreferredBusName);
+ }
+ // else: request/release will be handled by ForceUp/ForceDown, respectively
}
- bool IsEnabled()
+private:
+ DBus::DBusClient CreateSocketClient(const Address& socket)
{
- return isEnabled;
+ return {socket.GetBus(), ATSPI_PREFIX_PATH + socket.GetPath(), Accessible::GetInterfaceName(AtspiInterface::SOCKET), mConnectionPtr};
}
-};
-static bool bridgeInitialized;
+ void RequestBusName(const std::string& busName)
+ {
+ if(busName.empty())
+ {
+ return;
+ }
+
+ DBus::requestBusName(mConnectionPtr, busName);
+ }
+
+ void ReleaseBusName(const std::string& busName)
+ {
+ if(busName.empty())
+ {
+ return;
+ }
+
+ DBus::releaseBusName(mConnectionPtr, busName);
+ }
+}; // BridgeImpl
-static Bridge* CreateBridge()
+namespace // unnamed namespace
+{
+
+bool INITIALIZED_BRIDGE = false;
+
+/**
+ * @brief Creates BridgeImpl instance.
+ *
+ * @return The BridgeImpl instance
+ * @note This method is to check environment variable first. If ATSPI is disable using env, it returns dummy bridge instance.
+ */
+std::shared_ptr<Bridge> CreateBridge()
{
- bridgeInitialized = true;
+ INITIALIZED_BRIDGE = true;
try
{
return Dali::Accessibility::DummyBridge::GetInstance();
}
- return new BridgeImpl;
+ return std::make_shared<BridgeImpl>();
}
catch(const std::exception&)
{
}
}
-Bridge* Bridge::GetCurrentBridge()
+} // unnamed namespace
+
+// Dali::Accessibility::Bridge class implementation
+
+std::shared_ptr<Bridge> Bridge::GetCurrentBridge()
{
- static Bridge* bridge;
+ static std::shared_ptr<Bridge> bridge;
if(bridge)
{
return bridge;
}
- else if(autoInitState == AutoInitState::ENABLED)
+ else if(mAutoInitState == AutoInitState::ENABLED)
{
bridge = CreateBridge();
void Bridge::DisableAutoInit()
{
- if(bridgeInitialized)
+ if(INITIALIZED_BRIDGE)
{
DALI_LOG_ERROR("Bridge::DisableAutoInit() called after bridge auto-initialization");
}
- autoInitState = AutoInitState::DISABLED;
+ mAutoInitState = AutoInitState::DISABLED;
}
void Bridge::EnableAutoInit()
{
- autoInitState = AutoInitState::ENABLED;
+ mAutoInitState = AutoInitState::ENABLED;
- if(bridgeInitialized)
+ if(INITIALIZED_BRIDGE)
{
return;
}
- auto rootLayer = Dali::Stage::GetCurrent().GetRootLayer();
+ auto rootLayer = Dali::Stage::GetCurrent().GetRootLayer(); // A root layer of the default window.
auto window = Dali::DevelWindow::Get(rootLayer);
auto applicationName = Dali::Internal::Adaptor::Adaptor::GetApplicationPackageName();
- auto* bridge = Bridge::GetCurrentBridge();
- bridge->AddTopLevelWindow(Dali::Accessibility::Accessible::Get(rootLayer, true));
+ auto accessible = Accessibility::Accessible::Get(rootLayer);
+
+ auto bridge = Bridge::GetCurrentBridge();
+ bridge->AddTopLevelWindow(accessible);
bridge->SetApplicationName(applicationName);
bridge->Initialize();
if(window && window.IsVisible())
{
- bridge->ApplicationShown();
+ bridge->WindowShown(window);
+ }
+}
+
+std::string Bridge::MakeBusNameForWidget(std::string_view widgetInstanceId)
+{
+ // The bus name should consist of dot-separated alphanumeric elements, e.g. "com.example.BusName123".
+ // Allowed characters in each element: "[A-Z][a-z][0-9]_", but no element may start with a digit.
+
+ static const char prefix[] = "com.samsung.dali.widget_";
+ static const char underscore = '_';
+
+ std::stringstream tmp;
+
+ tmp << prefix;
+
+ for(char ch : widgetInstanceId)
+ {
+ tmp << (std::isalnum(ch) ? ch : underscore);
}
+
+ return tmp.str();
}