1 #include "BridgeBase.hpp"
5 using namespace Dali::Accessibility;
7 BridgeBase::BridgeBase()
11 BridgeBase::ForceUpResult BridgeBase::ForceUp()
13 if( Bridge::ForceUp() == ForceUpResult::alreadyUp )
14 return ForceUpResult::alreadyUp;
15 auto proxy = DBus::DBusClient{dbusLocators::atspi::BUS, dbusLocators::atspi::OBJ_PATH,
16 dbusLocators::atspi::BUS_INTERFACE, DBus::ConnectionType::SESSION};
17 auto addr = proxy.method< std::string() >( dbusLocators::atspi::GET_ADDRESS ).call();
20 throw AccessibleError{std::string( "failed at call '" ) + dbusLocators::atspi::GET_ADDRESS +
21 "': " + addr.getError().message};
23 con = std::make_shared< DBus::EldbusConnection >( eldbus_address_connection_get( std::get< 0 >( addr ).c_str() ) );
24 data->busName = DBus::getConnectionName( con );
25 data->root = &application;
29 DBus::DBusInterfaceDescription desc{"org.a11y.atspi.Cache"};
30 AddFunctionToInterface( desc, "GetItems", &BridgeBase::GetItems );
31 dbusServer.addInterface( "/org/a11y/atspi/cache", desc );
34 DBus::DBusInterfaceDescription desc{"org.a11y.atspi.Application"};
35 AddGetSetPropertyToInterface( desc, "Id", &BridgeBase::IdGet, &BridgeBase::IdSet );
36 dbusServer.addInterface( ATSPI_PATH, desc );
38 return ForceUpResult::justStarted;
41 void BridgeBase::ForceDown()
48 const std::string& BridgeBase::GetBusName() const
50 static std::string empty;
51 return data ? data->busName : empty;
54 Accessible* BridgeBase::FindByPath( const std::string& name ) const
60 catch( AccessibleError )
66 void BridgeBase::SetApplicationChild( Accessible* root )
68 // for now you can set root only once.
69 // to set it multiple times you'd have to remove old one first, which usually involves
70 // a lot of messy events and cornercases (imagine old root becoming child of new-not-yet-announced one)
71 application.children.push_back( root );
72 SetIsOnRootLevel( root );
75 // Accessible *BridgeBase::getApplicationRoot() const
77 // return rootElement;
80 std::string BridgeBase::StripPrefix( const std::string& path )
82 auto size = strlen( ATSPI_PATH );
83 return path.substr( size + 1 );
86 Accessible* BridgeBase::Find( const std::string& path ) const
91 auto val = std::strtoll( path.c_str(), &p, 10 );
92 if( p == path.c_str() )
93 throw AccessibleError{"invalid path '" + path + "'"};
94 auto it = data->objects.find( val );
95 if( it == data->objects.end() )
96 throw AccessibleError{"unknown object '" + path + "'"};
100 Accessible* BridgeBase::Find( const Address& ptr ) const
102 assert( ptr.GetBus() == data->busName );
103 return Find( ptr.GetPath() );
106 Accessible* BridgeBase::FindSelf() const
108 auto pth = DBus::DBusServer::getCurrentObjectPath();
109 auto size = strlen( ATSPI_PATH );
110 if( pth.size() <= size )
111 throw AccessibleError{"invalid path '" + pth + "'"};
112 if( pth.substr( 0, size ) != ATSPI_PATH )
113 throw AccessibleError{"invalid path '" + pth + "'"};
114 if( pth[size] != '/' )
115 throw AccessibleError{"invalid path '" + pth + "'"};
116 return Find( StripPrefix( pth ) );
119 void BridgeBase::IdSet( int id )
123 int BridgeBase::IdGet()
128 auto BridgeBase::GetItems() -> DBus::ValueOrError< std::vector< CacheElementType > >
130 auto root = &application;
132 std::vector< CacheElementType > res;
134 res.emplace_back( std::move( CreateCacheElement( root ) ) );
135 for( auto const& it : data->objects )
136 res.emplace_back( std::move( CreateCacheElement( it.second ) ) );
141 auto BridgeBase::CreateCacheElement( Accessible* item ) -> CacheElementType
146 auto root = &application;
147 auto parent = item->GetParent();
149 std::vector< Address > children;
150 for( auto i = 0u; i < item->GetChildCount(); ++i )
152 children.emplace_back( item->GetChildAtIndex( i )->GetAddress() );
155 return std::make_tuple(
158 parent->GetAddress(),
160 item->GetInterfaces(),
163 item->GetDescription(),
164 item->GetStates().GetRawData() );