2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/accessibility/bridge/bridge-action.h>
21 using namespace Dali::Accessibility;
23 void BridgeAction::RegisterInterfaces()
25 DBus::DBusInterfaceDescription desc{Accessible::GetInterfaceName(AtspiInterface::ACTION)};
27 AddGetPropertyToInterface(desc, "NActions", &BridgeAction::GetActionCount);
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);
38 Action* BridgeAction::FindSelf() const
40 return FindCurrentObjectWithInterface<Dali::Accessibility::AtspiInterface::ACTION>();
43 DBus::ValueOrError<std::string> BridgeAction::GetActionName(int32_t index)
45 return FindSelf()->GetActionName(index);
48 DBus::ValueOrError<std::string> BridgeAction::GetLocalizedActionName(int32_t index)
50 return FindSelf()->GetLocalizedActionName(index);
53 DBus::ValueOrError<std::string> BridgeAction::GetActionDescription(int32_t index)
55 return FindSelf()->GetActionDescription(index);
58 DBus::ValueOrError<std::string> BridgeAction::GetActionKeyBinding(int32_t index)
60 return FindSelf()->GetActionKeyBinding(index);
63 DBus::ValueOrError<int32_t> BridgeAction::GetActionCount()
65 return FindSelf()->GetActionCount();
68 DBus::ValueOrError<bool> BridgeAction::DoAction(int32_t index)
70 return FindSelf()->DoAction(index);
73 DBus::ValueOrError<bool> BridgeAction::DoActionName(std::string name)
75 auto self = FindSelf();
76 auto cnt = self->GetActionCount();
77 for(auto i = 0u; i < cnt; ++i)
79 if(self->GetActionName(i) == name)
81 return self->DoAction(i);
84 throw std::domain_error{"object " + self->GetAddress().ToString() + " doesn't have action '" + name + "'"};