[ATSPI] Read property in Async way 13/265913/5
authorShinwoo Kim <cinoo.kim@samsung.com>
Mon, 1 Nov 2021 11:45:53 +0000 (20:45 +0900)
committerShinwoo Kim <cinoo.kim@samsung.com>
Wed, 10 Nov 2021 11:37:24 +0000 (20:37 +0900)
An application could launch and read a property before at-spi-bus-launcher
is running. The at-spi-bus-launcher is a process writing the property.
If the application reads the property in syncronous way, then it is waiting
until the at-spi-bus-launcher can respond.

For the performance reason we will not read properties in syncronous way.

Change-Id: I0c7f33b25f99d37d57c67bca48e2e617ab5b1b1a

dali/internal/accessibility/bridge/bridge-impl.cpp
dali/internal/accessibility/bridge/dbus.h

index f46f5ea..3f4914b 100644 (file)
@@ -403,29 +403,30 @@ public:
     }
   }
 
-  void ReadAndListenProperty()
+  void ReadIsEnabledProperty()
   {
-    // read property
-    auto enabled = mAccessibilityStatusClient.property<bool>("ScreenReaderEnabled").get();
-    if(enabled)
-    {
-      mIsScreenReaderEnabled = std::get<0>(enabled);
-    }
-
-    enabled = mAccessibilityStatusClient.property<bool>("IsEnabled").get();
-    if(enabled)
-    {
-      mIsEnabled = std::get<0>(enabled);
-    }
-
-    if(mIsScreenReaderEnabled || mIsEnabled)
-    {
-      ForceUp();
-    }
+    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)
+        {
+          ReadIsEnabledProperty();
+        }
+        return;
+      }
+      mIsEnabled = std::get<0>(msg);
+      if(mIsEnabled)
+      {
+        ForceUp();
+      }
+    });
+  }
 
-    // listen property change
-    mAccessibilityStatusClient.addPropertyChangedEvent<bool>("ScreenReaderEnabled", [this](bool res) {
-      mIsScreenReaderEnabled = res;
+  void ListenIsEnabledProperty()
+  {
+    mAccessibilityStatusClient.addPropertyChangedEvent<bool>("IsEnabled", [this](bool res) {
+      mIsEnabled = res;
       if(mIsScreenReaderEnabled || mIsEnabled)
       {
         ForceUp();
@@ -435,9 +436,32 @@ public:
         ForceDown();
       }
     });
+  }
 
-    mAccessibilityStatusClient.addPropertyChangedEvent<bool>("IsEnabled", [this](bool res) {
-      mIsEnabled = res;
+  void ReadScreenReaderEnabledProperty()
+  {
+    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)
+        {
+          ReadScreenReaderEnabledProperty();
+        }
+        return;
+      }
+      mIsScreenReaderEnabled = std::get<0>(msg);
+      if(mIsScreenReaderEnabled)
+      {
+        ForceUp();
+      }
+    });
+  }
+
+  void ListenScreenReaderEnabledProperty()
+  {
+    mAccessibilityStatusClient.addPropertyChangedEvent<bool>("ScreenReaderEnabled", [this](bool res) {
+      mIsScreenReaderEnabled = res;
       if(mIsScreenReaderEnabled || mIsEnabled)
       {
         ForceUp();
@@ -449,6 +473,15 @@ public:
     });
   }
 
+  void ReadAndListenProperties()
+  {
+    ReadIsEnabledProperty();
+    ListenIsEnabledProperty();
+
+    ReadScreenReaderEnabledProperty();
+    ListenScreenReaderEnabledProperty();
+  }
+
   bool InitializeAccessibilityStatusClient()
   {
     mAccessibilityStatusClient = DBus::DBusClient{A11yDbusName, A11yDbusPath, A11yDbusStatusInterface, DBus::ConnectionType::SESSION};
@@ -466,7 +499,7 @@ public:
   {
     if ( InitializeAccessibilityStatusClient() )
     {
-      ReadAndListenProperty();
+      ReadAndListenProperties();
       mIdleCallback = NULL;
       return false;
     }
@@ -481,7 +514,7 @@ public:
   {
     if ( InitializeAccessibilityStatusClient() )
     {
-      ReadAndListenProperty();
+      ReadAndListenProperties();
       return;
     }
 
index c983902..8f6a6ed 100644 (file)
@@ -471,13 +471,24 @@ void debugPrint(const char* file, size_t line, const char* format, ...);
    */
 void setDebugPrinter(std::function<void(const char*, size_t)>);
 
+/**
+ * @brief Enumeration indicatng DBus error type
+ */
+enum class ErrorType
+{
+  DEFAULT,      ///< default
+  INVALID_REPLY ///< reply message has error
+};
+
 struct Error
 {
   std::string message;
+  ErrorType errorType;
 
   Error() = default;
-  Error(std::string msg)
-  : message(std::move(msg))
+  Error(std::string msg, ErrorType errorType = ErrorType::DEFAULT)
+  : message(std::move(msg)),
+    errorType(errorType)
   {
     assert(!message.empty());
   }
@@ -1842,7 +1853,7 @@ void asyncCall(CallId callId, const ConnectionState& connectionState, bool prope
       if(DBUS_W->eldbus_message_error_get_impl(reply, errname, errmsg))
       {
         DBUS_DEBUG("call %d: %s: %s", callId.id, errname.c_str(), errmsg.c_str());
-        callback(Error{errname + ": " + errmsg});
+        callback(Error{errname + ": " + errmsg, ErrorType::INVALID_REPLY});
       }
       else
       {