libaurum: Add window events for automate script
[platform/core/uifw/aurum.git] / org.tizen.aurum-bootstrap / src / Commands / ActionAndWaitEventCommand.cc
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
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 #include "bootstrap.h"
19 #include "ActionAndWaitEventCommand.h"
20 #include "ActionAndWaitEventRunnable.h"
21 #include "UiDevice.h"
22 #include <chrono>
23 #include <thread>
24
25 ActionAndWaitEventCommand::ActionAndWaitEventCommand(const ::aurum::ReqActionAndWaitEvent *request,
26                                    ::aurum::RspActionAndWaitEvent *response)
27     : mRequest{request}, mResponse{response}
28 {
29 }
30
31 A11yEvent convertEventType(const ::aurum::ReqActionAndWaitEvent_EventType type)
32 {
33     if (type == ::aurum::ReqActionAndWaitEvent_EventType::ReqActionAndWaitEvent_EventType_EVENT_WINDOW_ACTIVATE)
34         return A11yEvent::EVENT_WINDOW_ACTIVATE;
35     else if (type == ::aurum::ReqActionAndWaitEvent_EventType::ReqActionAndWaitEvent_EventType_EVENT_WINDOW_DEACTIVATE)
36         return A11yEvent::EVENT_WINDOW_DEACTIVATE;
37     else if (type == ::aurum::ReqActionAndWaitEvent_EventType::ReqActionAndWaitEvent_EventType_EVENT_WINDOW_IDLE)
38         return A11yEvent::EVENT_WINDOW_RENDER_POST;
39     else if (type == ::aurum::ReqActionAndWaitEvent_EventType::ReqActionAndWaitEvent_EventType_EVENT_WINDOW_MINIMIZE)
40         return A11yEvent::EVENT_WINDOW_MINIMIZE;
41     else if (type == ::aurum::ReqActionAndWaitEvent_EventType::ReqActionAndWaitEvent_EventType_EVENT_WINDOW_RAISE)
42         return A11yEvent::EVENT_WINDOW_RAISE;
43     else
44         return A11yEvent::EVENT_STATE_CHANGED_FOCUSED;
45 }
46
47 ::grpc::Status ActionAndWaitEventCommand::execute()
48 {
49     LOGI("ActionAndWaitEvent --------------- ");
50     std::unique_ptr<ActionAndWaitEventRunnable> cmd = std::make_unique<ActionAndWaitEventRunnable>(
51                                                       mRequest->type(), mRequest->elementid(), mRequest->xf86keycode());
52     std::shared_ptr<UiDevice> obj = UiDevice::getInstance();
53     //FIXME: Separation of params according to event type
54     bool ret = obj->executeAndWaitForEvents(cmd.get(), convertEventType(mRequest->eventtype()), mRequest->timeoutms(), mRequest->packagename(), mRequest->count());
55
56     if (ret) mResponse->set_status(::aurum::RspStatus::OK);
57     else mResponse->set_status(::aurum::RspStatus::ERROR);
58
59     return grpc::Status::OK;
60 }