Revert "[Tizen](ATSPI) Fix Native TC fails"
[platform/core/uifw/dali-adaptor.git] / dali / internal / accessibility / bridge / bridge-action.cpp
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/accessibility/bridge/bridge-action.h>
20
21 // EXTERNAL INCLUDES
22 #include <iostream>
23
24 using namespace Dali::Accessibility;
25
26 void BridgeAction::RegisterInterfaces()
27 {
28   DBus::DBusInterfaceDescription desc{AtspiDbusInterfaceAction};
29
30   AddGetPropertyToInterface( desc, "NActions", &BridgeAction::GetActionCount );
31
32   AddFunctionToInterface( desc, "GetName", &BridgeAction::GetActionName );
33   AddFunctionToInterface( desc, "GetLocalizedName", &BridgeAction::GetLocalizedActionName );
34   AddFunctionToInterface( desc, "GetDescription", &BridgeAction::GetActionDescription );
35   AddFunctionToInterface( desc, "GetKeyBinding", &BridgeAction::GetActionKeyBinding );
36   AddFunctionToInterface( desc, "DoAction", &BridgeAction::DoAction );
37   AddFunctionToInterface( desc, "DoActionName", &BridgeAction::DoActionName );
38   dbusServer.addInterface( "/", desc, true );
39 }
40
41 Action* BridgeAction::FindSelf() const
42 {
43   auto s = BridgeBase::FindSelf();
44   assert( s );
45   auto s2 = dynamic_cast< Action* >( s );
46   if( !s2 )
47     throw std::domain_error{"object " + s->GetAddress().ToString() + " doesn't have Action interface"};
48   return s2;
49 }
50
51 DBus::ValueOrError< std::string > BridgeAction::GetActionName( int32_t index )
52 {
53   return FindSelf()->GetActionName( index );
54 }
55
56 DBus::ValueOrError< std::string > BridgeAction::GetLocalizedActionName( int32_t index )
57 {
58   return FindSelf()->GetLocalizedActionName( index );
59 }
60
61 DBus::ValueOrError< std::string > BridgeAction::GetActionDescription( int32_t index )
62 {
63   return FindSelf()->GetActionDescription( index );
64 }
65
66 DBus::ValueOrError< std::string > BridgeAction::GetActionKeyBinding( int32_t index )
67 {
68   return FindSelf()->GetActionKeyBinding( index );
69 }
70
71 DBus::ValueOrError< int32_t > BridgeAction::GetActionCount()
72 {
73   return FindSelf()->GetActionCount();
74   ;
75 }
76
77 DBus::ValueOrError< bool > BridgeAction::DoAction( int32_t index )
78 {
79   return FindSelf()->DoAction( index );
80 }
81
82 DBus::ValueOrError< bool > BridgeAction::DoActionName( std::string name )
83 {
84   auto self = FindSelf();
85   auto cnt = self->GetActionCount();
86   for( auto i = 0u; i < cnt; ++i )
87   {
88     if( self->GetActionName( i ) == name )
89     {
90       return self->DoAction( i );
91     }
92   }
93   throw std::domain_error{"object " + self->GetAddress().ToString() + " doesn't have action '" + name + "'"};
94 }