[dali_2.3.24] Merge branch 'devel/master'
[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 using namespace Dali::Accessibility;
22
23 void BridgeAction::RegisterInterfaces()
24 {
25   DBus::DBusInterfaceDescription desc{Accessible::GetInterfaceName(AtspiInterface::ACTION)};
26
27   AddGetPropertyToInterface(desc, "NActions", &BridgeAction::GetActionCount);
28
29   AddFunctionToInterface(desc, "GetName", &BridgeAction::GetActionName);
30   AddFunctionToInterface(desc, "GetLocalizedName", &BridgeAction::GetLocalizedActionName);
31   AddFunctionToInterface(desc, "GetDescription", &BridgeAction::GetActionDescription);
32   AddFunctionToInterface(desc, "GetKeyBinding", &BridgeAction::GetActionKeyBinding);
33   AddFunctionToInterface(desc, "DoAction", &BridgeAction::DoAction);
34   AddFunctionToInterface(desc, "DoActionName", &BridgeAction::DoActionName);
35   mDbusServer.addInterface("/", desc, true);
36 }
37
38 Action* BridgeAction::FindSelf() const
39 {
40   return FindCurrentObjectWithInterface<Dali::Accessibility::AtspiInterface::ACTION>();
41 }
42
43 DBus::ValueOrError<std::string> BridgeAction::GetActionName(int32_t index)
44 {
45   return FindSelf()->GetActionName(index);
46 }
47
48 DBus::ValueOrError<std::string> BridgeAction::GetLocalizedActionName(int32_t index)
49 {
50   return FindSelf()->GetLocalizedActionName(index);
51 }
52
53 DBus::ValueOrError<std::string> BridgeAction::GetActionDescription(int32_t index)
54 {
55   return FindSelf()->GetActionDescription(index);
56 }
57
58 DBus::ValueOrError<std::string> BridgeAction::GetActionKeyBinding(int32_t index)
59 {
60   return FindSelf()->GetActionKeyBinding(index);
61 }
62
63 DBus::ValueOrError<int32_t> BridgeAction::GetActionCount()
64 {
65   return FindSelf()->GetActionCount();
66 }
67
68 DBus::ValueOrError<bool> BridgeAction::DoAction(int32_t index)
69 {
70   return FindSelf()->DoAction(index);
71 }
72
73 DBus::ValueOrError<bool> BridgeAction::DoActionName(std::string name)
74 {
75   auto self = FindSelf();
76   auto cnt  = self->GetActionCount();
77   for(auto i = 0u; i < cnt; ++i)
78   {
79     if(self->GetActionName(i) == name)
80     {
81       return self->DoAction(i);
82     }
83   }
84   throw std::domain_error{"object " + self->GetAddress().ToString() + " doesn't have action '" + name + "'"};
85 }