[AT-SPI] simplify dbus sandbox/kimcinoo/simple_dbus
authorShinwoo Kim <cinoo.kim@samsung.com>
Mon, 21 Jun 2021 09:28:31 +0000 (18:28 +0900)
committerShinwoo Kim <cinoo.kim@samsung.com>
Mon, 21 Jun 2021 09:28:31 +0000 (18:28 +0900)
dali/internal/accessibility/bridge/bridge-impl.cpp
dali/internal/accessibility/bridge/dbus-tizen.cpp
dali/internal/accessibility/bridge/dbus.h

index 80b3fb4..f520ef4 100644 (file)
@@ -55,6 +55,7 @@ class BridgeImpl : public virtual BridgeBase,
 {
   DBus::DBusClient                                              listenOnAtspiEnabledSignalClient;
   DBus::DBusClient                                              registryClient, directReadingClient;
+  DBus::DBusClient2                                             atspiEnabledSignalClient;
   bool                                                          screenReaderEnabled = false;
   bool                                                          isEnabled           = false;
   bool                                                          isShown             = false;
@@ -314,6 +315,8 @@ public:
 
   void Initialize() override
   {
+    atspiEnabledSignalClient = DBus::DBusClient2{A11yDbusName, A11yDbusPath, A11yDbusStatusInterface, DBus::ConnectionType::SESSION};
+
     auto req = DBus::DBusClient{A11yDbusName, A11yDbusPath, A11yDbusStatusInterface, DBus::ConnectionType::SESSION};
     auto p   = req.property<bool>("ScreenReaderEnabled").get();
     if(p)
index cc2a45c..a02e9ae 100644 (file)
@@ -98,6 +98,125 @@ DBusWrapper::ConnectionPtr DBus::getDBusConnectionByType(ConnectionType connecti
   return DBUS_W->eldbus_connection_get_impl(connectionType);
 }
 
+static void PropertyChangedCb(void* data,
+                              Eldbus_Proxy* proxy EINA_UNUSED,
+                              void* event)
+{
+  DBus::DBusClient2* obj = static_cast<DBus::DBusClient2*>(data);
+  if (!obj) {
+    DALI_LOG_ERROR("obj is null\n");
+    return;
+  }
+
+  Eldbus_Proxy_Event_Property_Changed* ev =
+      static_cast<Eldbus_Proxy_Event_Property_Changed*>(event);
+  Eina_Bool val;
+  const char* ifc = eldbus_proxy_interface_get(ev->proxy);
+
+  if (ev->name &&
+      !strncmp(ev->name, "ScreenReaderEnabled",
+               strlen("ScreenReaderEnabled")) &&
+      ifc &&
+      !strncmp("org.a11y.Status", ifc,
+               strlen("org.a11y.Status"))) {
+    if (!eina_value_get(ev->value, &val)) {
+      DALI_LOG_ERROR("Unable to get ScreenReaderEnabled property\n");
+      return;
+    }
+
+    DALI_LOG_ERROR("property is: %d\n", val);
+  }
+}
+
+static void ScreenReaderEnabledGet(void* data,
+                                   const Eldbus_Message* msg,
+                                   Eldbus_Pending* pending)
+{
+  DBus::DBusClient2* obj = static_cast<DBus::DBusClient2*>(data);
+  if (!obj) {
+    DALI_LOG_ERROR("obj is null\n");
+    return;
+  }
+
+  const char* errname;
+  const char* errmsg;
+  Eina_Bool is_enabled;
+  Eldbus_Message_Iter* variant;
+
+  if (eldbus_message_error_get(msg, &errname, &errmsg)) {
+    DALI_LOG_ERROR("message error - name(%s) msg(%s)\n", errname, errmsg);
+    return;
+  }
+
+  if (!eldbus_message_arguments_get(msg, "v", &variant)) {
+    DALI_LOG_ERROR("ScreenReaderEnabled not packed into variant\n");
+    return;
+  }
+
+  if (!eldbus_message_iter_arguments_get(variant, "b", &is_enabled)) {
+    DALI_LOG_ERROR("could not get ScreenReaderEnabled bool property\n");
+    return;
+  }
+
+  DALI_LOG_ERROR("is enabled: %d\n", is_enabled);
+
+}
+
+DBus::DBusClient2::DBusClient2(std::string busName, std::string pathName, std::string interfaceName, ConnectionType tp)
+{
+  Eldbus_Connection_Type eldbusType = ELDBUS_CONNECTION_TYPE_SYSTEM;
+
+  switch( tp )
+  {
+    case ConnectionType::SYSTEM:
+    {
+      eldbusType = ELDBUS_CONNECTION_TYPE_SYSTEM;
+      break;
+    }
+    case ConnectionType::SESSION:
+    {
+      eldbusType = ELDBUS_CONNECTION_TYPE_SESSION;
+      break;
+    }
+  }
+
+  Eldbus_Connection *bus_con = nullptr;
+  if( !(bus_con = eldbus_connection_get(eldbusType)) )
+  {
+    DALI_LOG_ERROR("unable connect session bus\n");
+  }
+
+  Eldbus_Object *bus_obj = nullptr;
+  if( !(bus_obj = eldbus_object_get(bus_con, busName.c_str(), pathName.c_str())) )
+  {
+    eldbus_connection_unref(bus_con);
+    DALI_LOG_ERROR("unable to get object\n");
+  }
+
+  Eldbus_Proxy *bus_proxy = nullptr;
+  if( !(bus_proxy = eldbus_proxy_get(bus_obj, interfaceName.c_str())) )
+  {
+    DALI_LOG_ERROR("unable to get proxy\n");
+    eldbus_object_unref(bus_obj);
+    eldbus_connection_unref(bus_con);
+    return;
+  }
+
+  Eldbus_Pending *req = nullptr;
+  if (!(req = eldbus_proxy_property_get(bus_proxy, "ScreenReaderEnabled",
+                                        ScreenReaderEnabledGet, this))) {
+    DALI_LOG_ERROR("could not set PropertyGet reqeust\n");
+    eldbus_object_unref(bus_obj);
+    eldbus_connection_unref(bus_con);
+    return;
+  }
+
+  eldbus_proxy_properties_monitor(bus_proxy, EINA_TRUE);
+  eldbus_proxy_event_callback_add(bus_proxy, ELDBUS_PROXY_EVENT_PROPERTY_CHANGED,
+                                  PropertyChangedCb, this);
+
+}
+
 DBus::DBusClient::DBusClient(std::string busName, std::string pathName, std::string interfaceName, ConnectionType tp)
 : DBusClient(std::move(busName), std::move(pathName), std::move(interfaceName), getDBusConnectionByType(tp))
 {
index c983902..6397cd1 100644 (file)
@@ -2008,6 +2008,19 @@ using ConnectionType = DBusWrapper::ConnectionType;
    * Allows (synchronous and asynchronous) setting / getting properties.
    * Allows registering signals.
    */
+class DBusClient2
+{
+  struct ConnectionInfo
+  {
+    std::string interfaceName, busName, pathName;
+  };
+
+public:
+  DBusClient2() = default;
+  DBusClient2(std::string busName_, std::string pathName_, std::string interfaceName_, ConnectionType tp);
+
+};
+
 class DBusClient
 {
   struct ConnectionInfo