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
87 * @brief The CurrentBridgePtr class is to save the current Accessibility Bridge.
89 class CurrentBridgePtr
91 static Dali::Accessibility::Bridge*& Get()
93 static thread_local Dali::Accessibility::Bridge* bridge = nullptr;
96 Dali::Accessibility::Bridge* mPrev;
97 CurrentBridgePtr(const CurrentBridgePtr&) = delete;
98 CurrentBridgePtr(CurrentBridgePtr&&) = delete;
99 CurrentBridgePtr& operator=(const CurrentBridgePtr&) = delete;
100 CurrentBridgePtr& operator=(CurrentBridgePtr&&) = delete;
103 CurrentBridgePtr(Dali::Accessibility::Bridge* bridge)
114 static Dali::Accessibility::Bridge* GetCurrentBridge()
118 }; // CurrentBridgePtr
121 // Templates for setting and getting Accessible values
125 struct signature<Dali::Accessibility::Address> : signature_helper<signature<Dali::Accessibility::Address>>
127 using subtype = std::pair<std::string, ObjectPath>;
129 static constexpr auto name_v = concat("AtspiAccessiblePtr");
130 static constexpr auto sig_v = signature<subtype>::sig_v; // "(so)"
133 * @brief Marshals value address as marshalled type into message
135 static void set(const DBusWrapper::MessageIterPtr& iter, const Dali::Accessibility::Address& address)
139 signature<subtype>::set(iter, {address.GetBus(), ObjectPath{std::string{ATSPI_PREFIX_PATH} + address.GetPath()}});
143 signature<subtype>::set(iter, {address.GetBus(), ObjectPath{ATSPI_NULL_PATH}});
148 * @brief Marshals value from marshalled type into variable address
150 static bool get(const DBusWrapper::MessageIterPtr& iter, Dali::Accessibility::Address& address)
153 if(!signature<subtype>::get(iter, tmp))
158 if(tmp.second.value == ATSPI_NULL_PATH)
163 if(tmp.second.value.substr(0, strlen(ATSPI_PREFIX_PATH)) != ATSPI_PREFIX_PATH)
168 address = {std::move(tmp.first), tmp.second.value.substr(strlen(ATSPI_PREFIX_PATH))};
174 struct SignatureAccessibleImpl : signature_helper<SignatureAccessibleImpl<T>>
176 using subtype = Dali::Accessibility::Address;
178 static constexpr auto name_v = signature<subtype>::name_v;
179 static constexpr auto sig_v = signature<subtype>::sig_v;
182 * @brief Marshals value address as marshalled type into message
184 static void set(const DBusWrapper::MessageIterPtr& iter, T* accessible)
186 signature<subtype>::set(iter, accessible ? accessible->GetAddress() : subtype{});
190 * @brief Marshals value from marshalled type into variable path
192 static bool get(const DBusWrapper::MessageIterPtr& iter, T*& path)
196 signature<subtype>::get(iter, address);
198 auto currentBridge = CurrentBridgePtr::GetCurrentBridge();
199 if(currentBridge->GetBusName() != address.GetBus())
204 path = currentBridge->FindByPath(address.GetPath());
205 return path != nullptr;
210 struct signature<Dali::Accessibility::Accessible*> : public SignatureAccessibleImpl<Dali::Accessibility::Accessible>
215 struct signature<Dali::Accessibility::States> : signature_helper<signature<Dali::Accessibility::States>>
217 using subtype = std::array<uint32_t, 2>;
219 static constexpr auto name_v = signature<subtype>::name_v;
220 static constexpr auto sig_v = signature<subtype>::sig_v;
223 * @brief Marshals value state as marshalled type into message
225 static void set(const DBusWrapper::MessageIterPtr& iter, const Dali::Accessibility::States& states)
227 signature<subtype>::set(iter, states.GetRawData());
231 * @brief Marshals value from marshalled type into variable state
233 static bool get(const DBusWrapper::MessageIterPtr& iter, Dali::Accessibility::States& state)
236 if(!signature<subtype>::get(iter, tmp))
240 state = Dali::Accessibility::States{tmp};
244 } // namespace detail
251 std::ostringstream mTmp;
253 _Logger(const char* file, int line)
261 Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugInfo, "%s:%d: %s", mFile, mLine, mTmp.str().c_str());
265 _Logger& operator<<(T&& t)
267 mTmp << std::forward<T>(t);
275 _LoggerEmpty& operator<<(T&& t)
286 _LoggerScope(const char* file, int line)
290 Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugInfo, "%s:%d: +", mFile, mLine);
295 Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugInfo, "%s:%d: -", mFile, mLine);
299 #define LOG() _Logger(__FILE__, __LINE__)
300 #define SCOPE() _LoggerScope _l##__LINE__(__FILE__, __LINE__)
302 #endif // DALI_INTERNAL_ATSPI_ACCESSIBILITY_COMMON_H