1 #ifndef DALI_INTERNAL_ATSPI_ACCESSIBILITY_COMMON_H
2 #define DALI_INTERNAL_ATSPI_ACCESSIBILITY_COMMON_H
5 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/integration-api/debug.h>
28 #include <dali/devel-api/adaptor-framework/accessibility-bridge.h>
29 #include <dali/internal/accessibility/bridge/dbus/dbus-locators.h>
30 #include <dali/internal/accessibility/bridge/dbus/dbus.h>
31 #include <dali/public-api/dali-adaptor-common.h>
35 #define A11yDbusName "org.a11y.Bus"
36 #define A11yDbusStatusInterface "org.a11y.Status"
37 #define AtspiDbusNameRegistry "org.a11y.atspi.Registry"
38 #define DirectReadingDBusName "org.tizen.ScreenReader"
39 #define DirectReadingDBusInterface "org.tizen.DirectReading"
43 #define A11yDbusPath "/org/a11y/bus"
44 #define AtspiDbusPathCache "/org/a11y/atspi/cache"
45 #define AtspiDbusPathDec "/org/a11y/atspi/registry/deviceeventcontroller"
46 #define AtspiDbusPathRegistry "/org/a11y/atspi/registry"
47 #define AtspiDbusPathRoot "/org/a11y/atspi/accessible/root"
48 #define AtspiPath "/org/a11y/atspi/accessible"
49 #define DirectReadingDBusPath "/org/tizen/DirectReading"
54 * @brief Enumeration used for quering Accessibility objects
56 enum class MatchType : int32_t
66 * @brief Enumeration used for quering Accessibility objects
67 * SortOrder::Canonical uses breadth-first search and sort objects in order of indexes in parent
68 * SortOrder::ReverseCanonical uses SortOrder::Canonical and reverse collection
69 * The rest of orders is not supported.
71 enum class SortOrder : uint32_t
86 * @brief The CurrentBridgePtr class is to save the current Accessibility Bridge.
88 class CurrentBridgePtr
90 static Dali::Accessibility::Bridge*& Get()
92 static thread_local Dali::Accessibility::Bridge* bridge = nullptr;
95 Dali::Accessibility::Bridge* mPrev;
96 CurrentBridgePtr(const CurrentBridgePtr&) = delete;
97 CurrentBridgePtr(CurrentBridgePtr&&) = delete;
98 CurrentBridgePtr& operator=(const CurrentBridgePtr&) = delete;
99 CurrentBridgePtr& operator=(CurrentBridgePtr&&) = delete;
102 CurrentBridgePtr(Dali::Accessibility::Bridge* bridge)
113 static Dali::Accessibility::Bridge* GetCurrentBridge()
117 }; // CurrentBridgePtr
119 // Templates for setting and getting Accessible values
123 struct signature<Dali::Accessibility::Address> : signature_helper<signature<Dali::Accessibility::Address>>
125 using subtype = std::pair<std::string, ObjectPath>;
127 static constexpr auto name_v = concat("AtspiAccessiblePtr");
128 static constexpr auto sig_v = signature<subtype>::sig_v; // "(so)"
131 * @brief Marshals value address as marshalled type into message
133 static void set(const DBusWrapper::MessageIterPtr& iter, const Dali::Accessibility::Address& address)
137 signature<subtype>::set(iter, {address.GetBus(), ObjectPath{std::string{ATSPI_PREFIX_PATH} + address.GetPath()}});
141 signature<subtype>::set(iter, {address.GetBus(), ObjectPath{ATSPI_NULL_PATH}});
146 * @brief Marshals value from marshalled type into variable address
148 static bool get(const DBusWrapper::MessageIterPtr& iter, Dali::Accessibility::Address& address)
151 if(!signature<subtype>::get(iter, tmp))
156 if(tmp.second.value == ATSPI_NULL_PATH)
161 if(tmp.second.value.substr(0, strlen(ATSPI_PREFIX_PATH)) != ATSPI_PREFIX_PATH)
166 address = {std::move(tmp.first), tmp.second.value.substr(strlen(ATSPI_PREFIX_PATH))};
172 struct SignatureAccessibleImpl : signature_helper<SignatureAccessibleImpl<T>>
174 using subtype = Dali::Accessibility::Address;
176 static constexpr auto name_v = signature<subtype>::name_v;
177 static constexpr auto sig_v = signature<subtype>::sig_v;
180 * @brief Marshals value address as marshalled type into message
182 static void set(const DBusWrapper::MessageIterPtr& iter, T* accessible)
184 signature<subtype>::set(iter, accessible ? accessible->GetAddress() : subtype{});
188 * @brief Marshals value from marshalled type into variable path
190 static bool get(const DBusWrapper::MessageIterPtr& iter, T*& path)
194 signature<subtype>::get(iter, address);
196 auto currentBridge = CurrentBridgePtr::GetCurrentBridge();
197 if(currentBridge->GetBusName() != address.GetBus())
202 path = currentBridge->FindByPath(address.GetPath());
203 return path != nullptr;
208 struct signature<Dali::Accessibility::Accessible*> : public SignatureAccessibleImpl<Dali::Accessibility::Accessible>
213 struct signature<Dali::Accessibility::States> : signature_helper<signature<Dali::Accessibility::States>>
215 using subtype = std::array<uint32_t, 2>;
217 static constexpr auto name_v = signature<subtype>::name_v;
218 static constexpr auto sig_v = signature<subtype>::sig_v;
221 * @brief Marshals value state as marshalled type into message
223 static void set(const DBusWrapper::MessageIterPtr& iter, const Dali::Accessibility::States& states)
225 signature<subtype>::set(iter, states.GetRawData());
229 * @brief Marshals value from marshalled type into variable state
231 static bool get(const DBusWrapper::MessageIterPtr& iter, Dali::Accessibility::States& state)
234 if(!signature<subtype>::get(iter, tmp))
238 state = Dali::Accessibility::States{tmp};
242 } // namespace detail
249 std::ostringstream mTmp;
251 _Logger(const char* file, int line)
259 Dali::Integration::Log::LogMessage(Dali::Integration::Log::INFO, "%s:%d: %s", mFile, mLine, mTmp.str().c_str());
263 _Logger& operator<<(T&& t)
265 mTmp << std::forward<T>(t);
273 _LoggerEmpty& operator<<(T&& t)
284 _LoggerScope(const char* file, int line)
288 Dali::Integration::Log::LogMessage(Dali::Integration::Log::INFO, "%s:%d: +", mFile, mLine);
293 Dali::Integration::Log::LogMessage(Dali::Integration::Log::INFO, "%s:%d: -", mFile, mLine);
297 #define LOG() _Logger(__FILE__, __LINE__)
298 #define SCOPE() _LoggerScope _l##__LINE__(__FILE__, __LINE__)
300 #endif // DALI_INTERNAL_ATSPI_ACCESSIBILITY_COMMON_H