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>
24 using namespace Dali::Accessibility;
26 void BridgeAction::RegisterInterfaces()
28 DBus::DBusInterfaceDescription desc{AtspiDbusInterfaceAction};
30 AddGetPropertyToInterface(desc, "NActions", &BridgeAction::GetActionCount);
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);
41 Action* BridgeAction::FindSelf() const
43 auto self = BridgeBase::FindSelf();
45 auto actionInterface = dynamic_cast<Action*>(self);
48 throw std::domain_error{"object " + self->GetAddress().ToString() + " doesn't have Action interface"};
50 return actionInterface;
53 DBus::ValueOrError<std::string> BridgeAction::GetActionName(int32_t index)
55 return FindSelf()->GetActionName(index);
58 DBus::ValueOrError<std::string> BridgeAction::GetLocalizedActionName(int32_t index)
60 return FindSelf()->GetLocalizedActionName(index);
63 DBus::ValueOrError<std::string> BridgeAction::GetActionDescription(int32_t index)
65 return FindSelf()->GetActionDescription(index);
68 DBus::ValueOrError<std::string> BridgeAction::GetActionKeyBinding(int32_t index)
70 return FindSelf()->GetActionKeyBinding(index);
73 DBus::ValueOrError<int32_t> BridgeAction::GetActionCount()
75 return FindSelf()->GetActionCount();
78 DBus::ValueOrError<bool> BridgeAction::DoAction(int32_t index)
80 return FindSelf()->DoAction(index);
83 DBus::ValueOrError<bool> BridgeAction::DoActionName(std::string name)
85 auto self = FindSelf();
86 auto cnt = self->GetActionCount();
87 for(auto i = 0u; i < cnt; ++i)
89 if(self->GetActionName(i) == name)
91 return self->DoAction(i);
94 throw std::domain_error{"object " + self->GetAddress().ToString() + " doesn't have action '" + name + "'"};