664a665a17e666b57386b17a99016e281f6054cd
[platform/core/uifw/dali-adaptor.git] / dali / dali-bridge / src / BridgeAction.cpp
1 #include "BridgeAction.hpp"
2 #include <iostream>
3
4 using namespace Dali::Accessibility;
5
6 void BridgeAction::RegisterInterfaces()
7 {
8   DBus::DBusInterfaceDescription desc{ATSPI_DBUS_INTERFACE_ACTION};
9
10   AddGetPropertyToInterface( desc, "NActions", &BridgeAction::GetActionCount );
11
12   AddFunctionToInterface( desc, "GetName", &BridgeAction::GetActionName );
13   AddFunctionToInterface( desc, "GetLocalizedName", &BridgeAction::GetLocalizedActionName );
14   AddFunctionToInterface( desc, "GetDescription", &BridgeAction::GetActionDescription );
15   AddFunctionToInterface( desc, "GetKeyBinding", &BridgeAction::GetActionKeyBinding );
16   AddFunctionToInterface( desc, "DoAction", &BridgeAction::DoAction );
17   AddFunctionToInterface( desc, "DoActionName", &BridgeAction::DoActionName );
18   dbusServer.addInterface( "/", desc, true );
19 }
20
21 Action* BridgeAction::FindSelf() const
22 {
23   auto s = BridgeBase::FindSelf();
24   assert( s );
25   auto s2 = dynamic_cast< Action* >( s );
26   if( !s2 )
27     throw AccessibleError{"object " + s->GetAddress().ToString() + " doesn't have Action interface"};
28   return s2;
29 }
30
31 DBus::ValueOrError< std::string > BridgeAction::GetActionName( int32_t index )
32 {
33   auto self = FindSelf();
34   return self->GetActionName( index );
35 }
36
37 DBus::ValueOrError< std::string > BridgeAction::GetLocalizedActionName( int32_t index )
38 {
39   auto self = FindSelf();
40   return self->GetLocalizedActionName( index );
41 }
42
43 DBus::ValueOrError< std::string > BridgeAction::GetActionDescription( int32_t index )
44 {
45   auto self = FindSelf();
46   return self->GetActionDescription( index );
47 }
48
49 DBus::ValueOrError< std::string > BridgeAction::GetActionKeyBinding( int32_t index )
50 {
51   auto self = FindSelf();
52   return self->GetActionKeyBinding( index );
53 }
54
55 DBus::ValueOrError< int32_t > BridgeAction::GetActionCount()
56 {
57   auto self = FindSelf();
58   return self->GetActionCount();
59   ;
60 }
61
62 DBus::ValueOrError< bool > BridgeAction::DoAction( int32_t index )
63 {
64   auto self = FindSelf();
65   return self->DoAction( index );
66 }
67
68 DBus::ValueOrError< bool > BridgeAction::DoActionName( std::string name )
69 {
70   auto self = FindSelf();
71   auto cnt = self->GetActionCount();
72   for( auto i = 0u; i < cnt; ++i )
73   {
74     if( self->GetActionName( i ) == name )
75     {
76       return self->DoAction( i );
77     }
78   }
79   throw AccessibleError{"object " + self->GetAddress().ToString() + " doesn't have action '" + name + "'"};
80 }