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
39 std::string GetDescription() override
43 Dali::Accessibility::Accessible* GetParent() override
47 size_t GetChildCount() override
49 return children.size();
51 Dali::Accessibility::Accessible* GetChildAtIndex( size_t index ) override
53 auto s = children.size();
55 throw std::domain_error{"invalid index " + std::to_string( index ) + " for object with " + std::to_string( s ) + " children"};
56 return children[index];
58 size_t GetIndexInParent() override
60 throw std::domain_error{"can't call GetIndexInParent on application object"};
62 Dali::Accessibility::Role GetRole() override
64 return Dali::Accessibility::Role::APPLICATION;
66 Dali::Accessibility::States GetStates() override
70 Dali::Accessibility::Attributes GetAttributes() override
74 Dali::Accessibility::Accessible* getActiveWindow()
76 return children.empty() ? nullptr : children[0];
78 bool DoGesture(const Dali::Accessibility::GestureInfo &gestureInfo) override
82 std::vector<Dali::Accessibility::Relation> GetRelationSet() override
86 Dali::Accessibility::Address GetAddress() override {
87 return { "", "root" };
91 enum class FilteredEvents {
96 template <> struct hash<std::pair<FilteredEvents, Dali::Accessibility::Accessible*>> {
97 size_t operator () (std::pair<FilteredEvents, Dali::Accessibility::Accessible*> v) const {
98 return (static_cast<size_t>(v.first) * 131) ^ reinterpret_cast<size_t>(v.second);
103 class BridgeBase : public Dali::Accessibility::Bridge, public Dali::ConnectionTracker
105 std::unordered_map<std::pair<FilteredEvents, Dali::Accessibility::Accessible*>, std::pair<unsigned int, std::function<void()>>> filteredEvents;
107 bool tickFilteredEvents();
110 void addFilteredEvent(FilteredEvents kind, Dali::Accessibility::Accessible* obj, float delay, std::function<void()> functor);
112 const std::string& GetBusName() const override;
113 void AddTopLevelWindow( Dali::Accessibility::Accessible* window ) override;
114 void RemoveTopLevelWindow( Dali::Accessibility::Accessible* window ) override;
115 void AddPopup( Dali::Accessibility::Accessible* ) override;
116 void RemovePopup( Dali::Accessibility::Accessible* ) override;
118 Dali::Accessibility::Accessible* GetApplication() const override
123 template < typename SELF, typename... RET, typename... ARGS >
124 void AddFunctionToInterface(
125 DBus::DBusInterfaceDescription& desc, const std::string& funcName,
126 DBus::ValueOrError< RET... > ( SELF::*funcPtr )( ARGS... ) )
128 if ( auto self = dynamic_cast< SELF* >( this ) )
129 desc.addMethod< DBus::ValueOrError< RET... >( ARGS... ) >( funcName,
130 [=]( ARGS... args ) -> DBus::ValueOrError< RET... > {
133 return ( self->*funcPtr )( std::move( args )... );
135 catch( std::domain_error& e )
137 return DBus::Error{e.what()};
141 template < typename T, typename SELF >
142 void AddGetPropertyToInterface( DBus::DBusInterfaceDescription& desc,
143 const std::string& funcName, T ( SELF::*funcPtr )() )
145 if ( auto self = dynamic_cast< SELF* >( this ) )
146 desc.addProperty< T >( funcName,
147 [=]() -> DBus::ValueOrError< T > {
150 return ( self->*funcPtr )();
152 catch( std::domain_error& e )
154 return DBus::Error{e.what()};
159 template < typename T, typename SELF >
160 void AddSetPropertyToInterface( DBus::DBusInterfaceDescription& desc,
161 const std::string& funcName, void ( SELF::*funcPtr )( T ) )
163 if ( auto self = dynamic_cast< SELF* >( this ) )
164 desc.addProperty< T >( funcName, {},
165 [=]( T t ) -> DBus::ValueOrError< void > {
168 ( self->*funcPtr )( std::move( t ) );
171 catch( std::domain_error& e )
173 return DBus::Error{e.what()};
177 template < typename T, typename T1, typename SELF >
178 void AddGetSetPropertyToInterface( DBus::DBusInterfaceDescription& desc,
179 const std::string& funcName, T1 ( SELF::*funcPtrGet )(), DBus::ValueOrError< void > ( SELF::*funcPtrSet )( T ) )
181 if ( auto self = dynamic_cast< SELF* >( this ) )
182 desc.addProperty< T >( funcName,
183 [=]() -> DBus::ValueOrError< T > {
186 return ( self->*funcPtrGet )();
188 catch( std::domain_error& e )
190 return DBus::Error{e.what()};
193 [=]( T t ) -> DBus::ValueOrError< void > {
196 ( self->*funcPtrSet )( std::move( t ) );
199 catch( std::domain_error& e )
201 return DBus::Error{e.what()};
205 template < typename T, typename T1, typename SELF >
206 void AddGetSetPropertyToInterface( DBus::DBusInterfaceDescription& desc,
207 const std::string& funcName, T1 ( SELF::*funcPtrGet )(), void ( SELF::*funcPtrSet )( T ) )
209 if ( auto self = dynamic_cast< SELF* >( this ) )
210 desc.addProperty< T >( funcName,
211 [=]() -> DBus::ValueOrError< T > {
214 return ( self->*funcPtrGet )();
216 catch( std::domain_error& e )
218 return DBus::Error{e.what()};
221 [=]( T t ) -> DBus::ValueOrError< void > {
224 ( self->*funcPtrSet )( std::move( t ) );
227 catch( std::domain_error& e )
229 return DBus::Error{e.what()};
233 static std::string StripPrefix( const std::string& path );
235 Dali::Accessibility::Accessible* Find( const std::string& path ) const;
236 Dali::Accessibility::Accessible* Find( const Dali::Accessibility::Address& ptr ) const;
237 Dali::Accessibility::Accessible* FindSelf() const;
238 Dali::Accessibility::Accessible* FindByPath( const std::string& name ) const override;
239 void SetApplicationName( std::string name ) override
241 application.name = std::move( name );
245 mutable AppAccessible application;
246 std::vector<Dali::Accessibility::Accessible*> popups;
248 void IdSet( int id );
251 using CacheElementType = std::tuple<
252 Dali::Accessibility::Address, Dali::Accessibility::Address, Dali::Accessibility::Address,
253 std::vector< Dali::Accessibility::Address >,
254 std::vector< std::string >,
256 Dali::Accessibility::Role,
258 std::array< uint32_t, 2 > >;
259 DBus::ValueOrError< std::vector< CacheElementType > > GetItems();
260 CacheElementType CreateCacheElement( Dali::Accessibility::Accessible* item );
264 virtual ~BridgeBase();
266 ForceUpResult ForceUp() override;
267 void ForceDown() override;
269 DBus::DBusServer dbusServer;
270 DBusWrapper::ConnectionPtr con;
274 #endif // DALI_INTERNAL_ACCESSIBILITY_BRIDGE_BASE_H