1 #ifndef DALI_INTERNAL_ACCESSIBILITY_BRIDGE_BASE_H
2 #define DALI_INTERNAL_ACCESSIBILITY_BRIDGE_BASE_H
5 * Copyright (c) 2021 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/public-api/signals/connection-tracker.h>
26 #include <dali/internal/accessibility/bridge/accessibility-common.h>
28 class AppAccessible : public virtual Dali::Accessibility::Accessible, public virtual Dali::Accessibility::Collection
31 Dali::Accessibility::EmptyAccessibleWithAddress parent;
32 std::vector<Dali::Accessibility::Accessible*> children;
35 std::string GetName() override
40 std::string GetDescription() override
45 Dali::Accessibility::Accessible* GetParent() override
50 size_t GetChildCount() override
52 return children.size();
55 Dali::Accessibility::Accessible* GetChildAtIndex(size_t index) override
57 auto s = children.size();
59 throw std::domain_error{"invalid index " + std::to_string(index) + " for object with " + std::to_string(s) + " children"};
60 return children[index];
63 size_t GetIndexInParent() override
65 throw std::domain_error{"can't call GetIndexInParent on application object"};
68 Dali::Accessibility::Role GetRole() override
70 return Dali::Accessibility::Role::APPLICATION;
73 Dali::Accessibility::States GetStates() override
78 Dali::Accessibility::Attributes GetAttributes() override
83 Dali::Accessibility::Accessible* getActiveWindow()
85 return children.empty() ? nullptr : children[0];
88 bool DoGesture(const Dali::Accessibility::GestureInfo& gestureInfo) override
93 std::vector<Dali::Accessibility::Relation> GetRelationSet() override
98 Dali::Accessibility::Address GetAddress() override
104 enum class FilteredEvents
112 struct hash<std::pair<FilteredEvents, Dali::Accessibility::Accessible*>>
114 size_t operator()(std::pair<FilteredEvents, Dali::Accessibility::Accessible*> v) const
116 return (static_cast<size_t>(v.first) * 131) ^ reinterpret_cast<size_t>(v.second);
121 class BridgeBase : public Dali::Accessibility::Bridge, public Dali::ConnectionTracker
123 std::unordered_map<std::pair<FilteredEvents, Dali::Accessibility::Accessible*>, std::pair<unsigned int, std::function<void()>>> filteredEvents;
125 bool tickFilteredEvents();
128 void addFilteredEvent(FilteredEvents kind, Dali::Accessibility::Accessible* obj, float delay, std::function<void()> functor);
130 const std::string& GetBusName() const override;
131 void AddTopLevelWindow(Dali::Accessibility::Accessible* window) override;
132 void RemoveTopLevelWindow(Dali::Accessibility::Accessible* window) override;
133 void AddPopup(Dali::Accessibility::Accessible* object) override;
134 void RemovePopup(Dali::Accessibility::Accessible* object) override;
136 Dali::Accessibility::Accessible* GetApplication() const override
141 template<typename SELF, typename... RET, typename... ARGS>
142 void AddFunctionToInterface(
143 DBus::DBusInterfaceDescription& desc, const std::string& funcName, DBus::ValueOrError<RET...> (SELF::*funcPtr)(ARGS...))
145 if(auto self = dynamic_cast<SELF*>(this))
146 desc.addMethod<DBus::ValueOrError<RET...>(ARGS...)>(
148 [=](ARGS... args) -> DBus::ValueOrError<RET...> {
151 return (self->*funcPtr)(std::move(args)...);
153 catch(std::domain_error& e)
155 return DBus::Error{e.what()};
160 template<typename T, typename SELF>
161 void AddGetPropertyToInterface(DBus::DBusInterfaceDescription& desc,
162 const std::string& funcName,
163 T (SELF::*funcPtr)())
165 if(auto self = dynamic_cast<SELF*>(this))
166 desc.addProperty<T>(funcName,
167 [=]() -> DBus::ValueOrError<T> {
170 return (self->*funcPtr)();
172 catch(std::domain_error& e)
174 return DBus::Error{e.what()};
180 template<typename T, typename SELF>
181 void AddSetPropertyToInterface(DBus::DBusInterfaceDescription& desc,
182 const std::string& funcName,
183 void (SELF::*funcPtr)(T))
185 if(auto self = dynamic_cast<SELF*>(this))
186 desc.addProperty<T>(funcName, {}, [=](T t) -> DBus::ValueOrError<void> {
189 (self->*funcPtr)(std::move(t));
192 catch(std::domain_error& e)
194 return DBus::Error{e.what()};
199 template<typename T, typename T1, typename SELF>
200 void AddGetSetPropertyToInterface(DBus::DBusInterfaceDescription& desc,
201 const std::string& funcName,
202 T1 (SELF::*funcPtrGet)(),
203 DBus::ValueOrError<void> (SELF::*funcPtrSet)(T))
205 if(auto self = dynamic_cast<SELF*>(this))
208 [=]() -> DBus::ValueOrError<T> {
211 return (self->*funcPtrGet)();
213 catch(std::domain_error& e)
215 return DBus::Error{e.what()};
218 [=](T t) -> DBus::ValueOrError<void> {
221 (self->*funcPtrSet)(std::move(t));
224 catch(std::domain_error& e)
226 return DBus::Error{e.what()};
230 template<typename T, typename T1, typename SELF>
231 void AddGetSetPropertyToInterface(DBus::DBusInterfaceDescription& desc,
232 const std::string& funcName,
233 T1 (SELF::*funcPtrGet)(),
234 void (SELF::*funcPtrSet)(T))
236 if(auto self = dynamic_cast<SELF*>(this))
239 [=]() -> DBus::ValueOrError<T> {
242 return (self->*funcPtrGet)();
244 catch(std::domain_error& e)
246 return DBus::Error{e.what()};
249 [=](T t) -> DBus::ValueOrError<void> {
252 (self->*funcPtrSet)(std::move(t));
255 catch(std::domain_error& e)
257 return DBus::Error{e.what()};
261 static std::string StripPrefix(const std::string& path);
263 Dali::Accessibility::Accessible* Find(const std::string& path) const;
264 Dali::Accessibility::Accessible* Find(const Dali::Accessibility::Address& ptr) const;
265 Dali::Accessibility::Accessible* FindSelf() const;
266 Dali::Accessibility::Accessible* FindByPath(const std::string& name) const override;
267 void SetApplicationName(std::string name) override
269 application.name = std::move(name);
273 mutable AppAccessible application;
274 std::vector<Dali::Accessibility::Accessible*> popups;
279 void RegisteredEventsUpdate();
281 using CacheElementType = std::tuple<
282 Dali::Accessibility::Address,
283 Dali::Accessibility::Address,
284 Dali::Accessibility::Address,
285 std::vector<Dali::Accessibility::Address>,
286 std::vector<std::string>,
288 Dali::Accessibility::Role,
290 std::array<uint32_t, 2>>;
291 DBus::ValueOrError<std::vector<CacheElementType>> GetItems();
292 CacheElementType CreateCacheElement(Dali::Accessibility::Accessible* item);
296 virtual ~BridgeBase();
298 ForceUpResult ForceUp() override;
299 void ForceDown() override;
301 DBus::DBusServer dbusServer;
302 DBusWrapper::ConnectionPtr con;
304 DBus::DBusClient registry;
305 bool allowObjectBoundsChangedEvent{false};
308 #endif // DALI_INTERNAL_ACCESSIBILITY_BRIDGE_BASE_H