1 #ifndef DALI_INTERNAL_ACCESSIBILITY_BRIDGE_BASE_H
2 #define DALI_INTERNAL_ACCESSIBILITY_BRIDGE_BASE_H
5 * Copyright (c) 2019 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 {
99 return { "", "root" };
105 enum class FilteredEvents {
111 template <> struct hash<std::pair<FilteredEvents, Dali::Accessibility::Accessible*>> {
112 size_t operator () (std::pair<FilteredEvents, Dali::Accessibility::Accessible*> v) const {
113 return (static_cast<size_t>(v.first) * 131) ^ reinterpret_cast<size_t>(v.second);
119 class BridgeBase : public Dali::Accessibility::Bridge, public Dali::ConnectionTracker
121 std::unordered_map<std::pair<FilteredEvents, Dali::Accessibility::Accessible*>, std::pair<unsigned int, std::function<void()>>> filteredEvents;
123 bool tickFilteredEvents();
127 void addFilteredEvent(FilteredEvents kind, Dali::Accessibility::Accessible* obj, float delay, std::function<void()> functor);
129 const std::string& GetBusName() const override;
130 void AddTopLevelWindow( Dali::Accessibility::Accessible* window ) override;
131 void RemoveTopLevelWindow( Dali::Accessibility::Accessible* window ) override;
132 void AddPopup( Dali::Accessibility::Accessible* ) override;
133 void RemovePopup( Dali::Accessibility::Accessible* ) override;
135 Dali::Accessibility::Accessible* GetApplication() const override
140 template < typename SELF, typename... RET, typename... ARGS >
141 void AddFunctionToInterface(
142 DBus::DBusInterfaceDescription& desc, const std::string& funcName,
143 DBus::ValueOrError< RET... > ( SELF::*funcPtr )( ARGS... ) )
145 if ( auto self = dynamic_cast< SELF* >( this ) )
146 desc.addMethod< DBus::ValueOrError< RET... >( ARGS... ) >( funcName,
147 [=]( ARGS... args ) -> DBus::ValueOrError< RET... > {
150 return ( self->*funcPtr )( std::move( args )... );
152 catch( std::domain_error& e )
154 return DBus::Error{e.what()};
159 template < typename T, typename SELF >
160 void AddGetPropertyToInterface( DBus::DBusInterfaceDescription& desc,
161 const std::string& funcName, T ( SELF::*funcPtr )() )
163 if ( auto self = dynamic_cast< SELF* >( this ) )
164 desc.addProperty< T >( funcName,
165 [=]() -> DBus::ValueOrError< T > {
168 return ( self->*funcPtr )();
170 catch( std::domain_error& e )
172 return DBus::Error{e.what()};
178 template < typename T, typename SELF >
179 void AddSetPropertyToInterface( DBus::DBusInterfaceDescription& desc,
180 const std::string& funcName, void ( SELF::*funcPtr )( T ) )
182 if ( auto self = dynamic_cast< SELF* >( this ) )
183 desc.addProperty< T >( funcName, {},
184 [=]( T t ) -> DBus::ValueOrError< void > {
187 ( self->*funcPtr )( std::move( t ) );
190 catch( std::domain_error& e )
192 return DBus::Error{e.what()};
197 template < typename T, typename T1, typename SELF >
198 void AddGetSetPropertyToInterface( DBus::DBusInterfaceDescription& desc,
199 const std::string& funcName, T1 ( SELF::*funcPtrGet )(), DBus::ValueOrError< void > ( SELF::*funcPtrSet )( T ) )
201 if ( auto self = dynamic_cast< SELF* >( this ) )
202 desc.addProperty< T >( funcName,
203 [=]() -> DBus::ValueOrError< T > {
206 return ( self->*funcPtrGet )();
208 catch( std::domain_error& e )
210 return DBus::Error{e.what()};
213 [=]( T t ) -> DBus::ValueOrError< void > {
216 ( self->*funcPtrSet )( std::move( t ) );
219 catch( std::domain_error& e )
221 return DBus::Error{e.what()};
225 template < typename T, typename T1, typename SELF >
226 void AddGetSetPropertyToInterface( DBus::DBusInterfaceDescription& desc,
227 const std::string& funcName, T1 ( SELF::*funcPtrGet )(), void ( SELF::*funcPtrSet )( T ) )
229 if ( auto self = dynamic_cast< SELF* >( this ) )
230 desc.addProperty< T >( funcName,
231 [=]() -> DBus::ValueOrError< T > {
234 return ( self->*funcPtrGet )();
236 catch( std::domain_error& e )
238 return DBus::Error{e.what()};
241 [=]( T t ) -> DBus::ValueOrError< void > {
244 ( self->*funcPtrSet )( std::move( t ) );
247 catch( std::domain_error& e )
249 return DBus::Error{e.what()};
253 static std::string StripPrefix( const std::string& path );
255 Dali::Accessibility::Accessible* Find( const std::string& path ) const;
256 Dali::Accessibility::Accessible* Find( const Dali::Accessibility::Address& ptr ) const;
257 Dali::Accessibility::Accessible* FindSelf() const;
258 Dali::Accessibility::Accessible* FindByPath( const std::string& name ) const override;
259 void SetApplicationName( std::string name ) override
261 application.name = std::move( name );
265 mutable AppAccessible application;
266 std::vector<Dali::Accessibility::Accessible*> popups;
268 void IdSet( int id );
271 using CacheElementType = std::tuple<
272 Dali::Accessibility::Address, Dali::Accessibility::Address, Dali::Accessibility::Address,
273 std::vector< Dali::Accessibility::Address >,
274 std::vector< std::string >,
276 Dali::Accessibility::Role,
278 std::array< uint32_t, 2 > >;
279 DBus::ValueOrError< std::vector< CacheElementType > > GetItems();
280 CacheElementType CreateCacheElement( Dali::Accessibility::Accessible* item );
284 virtual ~BridgeBase();
286 ForceUpResult ForceUp() override;
287 void ForceDown() override;
289 DBus::DBusServer dbusServer;
290 DBusWrapper::ConnectionPtr con;
294 #endif // DALI_INTERNAL_ACCESSIBILITY_BRIDGE_BASE_H