libaurum: apply smart pointer wider and extract impl out
[platform/core/uifw/aurum.git] / org.tizen.aurum-bootstrap / src / Commands / SendKeyCommand.cc
1 #include "SendKeyCommand.h"
2 #include <loguru.hpp>
3
4 #include <UiDevice.h>
5
6 SendKeyCommand::SendKeyCommand(const ::aurum::ReqKey* request,
7                                ::aurum::RspKey*       response)
8     : mRequest{request}, mResponse{response}
9 {
10 }
11
12 ::grpc::Status SendKeyCommand::execute()
13 {
14     LOG_SCOPE_F(INFO, "SendKey --------------- ");
15     std::shared_ptr<UiDevice> mDevice = UiDevice::getInstance();
16     ::aurum::ReqKey_KeyType type = mRequest->type();
17     ::aurum::ReqKey_KeyActionType action_type = mRequest->actiontype();
18     KeyRequestType actionType = static_cast<KeyRequestType>(action_type);
19
20     if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_BACK)
21         mDevice->pressBack(actionType);
22     else if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_HOME)
23         mDevice->pressHome(actionType);
24     else if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_MENU)
25         mDevice->pressMenu(actionType);
26     else if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_VOLUP)
27         mDevice->pressVolUp(actionType);
28     else if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_VOLDOWN)
29         mDevice->pressVolDown(actionType);
30     else if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_POWER)
31         mDevice->pressPower(actionType);
32     else if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_WHEELUP)
33         mDevice->wheelUp(1, 167);
34     else if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_WHEELDOWN)
35         mDevice->wheelDown(1, 167);
36     else if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_XF86) {
37         mDevice->pressKeyCode(mRequest->xf86keycode(), actionType);
38     }
39     return grpc::Status::OK;
40 }