[AT-SPI] Fix not working screen reader when rerunning it
[platform/core/uifw/dali-adaptor.git] / dali / internal / accessibility / bridge / bridge-action.cpp
1 /*
2  * Copyright (c) 2021 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   mDbusServer.addInterface("/", desc, true);
39 }
40
41 Action* BridgeAction::FindSelf() const
42 {
43   auto self = BridgeBase::FindSelf();
44   assert(self);
45   auto actionInterface = dynamic_cast<Action*>(self);
46   if(!actionInterface)
47   {
48     throw std::domain_error{"object " + self->GetAddress().ToString() + " doesn't have Action interface"};
49   }
50   return actionInterface;
51 }
52
53 DBus::ValueOrError<std::string> BridgeAction::GetActionName(int32_t index)
54 {
55   return FindSelf()->GetActionName(index);
56 }
57
58 DBus::ValueOrError<std::string> BridgeAction::GetLocalizedActionName(int32_t index)
59 {
60   return FindSelf()->GetLocalizedActionName(index);
61 }
62
63 DBus::ValueOrError<std::string> BridgeAction::GetActionDescription(int32_t index)
64 {
65   return FindSelf()->GetActionDescription(index);
66 }
67
68 DBus::ValueOrError<std::string> BridgeAction::GetActionKeyBinding(int32_t index)
69 {
70   return FindSelf()->GetActionKeyBinding(index);
71 }
72
73 DBus::ValueOrError<int32_t> BridgeAction::GetActionCount()
74 {
75   return FindSelf()->GetActionCount();
76 }
77
78 DBus::ValueOrError<bool> BridgeAction::DoAction(int32_t index)
79 {
80   return FindSelf()->DoAction(index);
81 }
82
83 DBus::ValueOrError<bool> BridgeAction::DoActionName(std::string name)
84 {
85   auto self = FindSelf();
86   auto cnt  = self->GetActionCount();
87   for(auto i = 0u; i < cnt; ++i)
88   {
89     if(self->GetActionName(i) == name)
90     {
91       return self->DoAction(i);
92     }
93   }
94   throw std::domain_error{"object " + self->GetAddress().ToString() + " doesn't have action '" + name + "'"};
95 }