2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
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.
18 #include "bootstrap.h"
19 #include "TakeScreenshotCommand.h"
24 TakeScreenshotCommand::TakeScreenshotCommand(
25 const ::aurum::ReqTakeScreenshot *request,
26 ::grpc::ServerWriter< ::aurum::RspTakeScreenshot> *writer)
27 : mRequest{request}, mWriter{writer}
31 ::grpc::Status TakeScreenshotCommand::execute()
33 LOGI("TakeScreenshot --------------- ");
37 if (!localtime_r(&now, &timeinfo)) {
38 LOGE("fail to get localtime. Screenshot cancelled");
39 return grpc::Status::CANCELLED;
43 std::snprintf(name, 128, "/tmp/screenshot-%d-%d-%d-%d:%d:%d.png",
44 (timeinfo.tm_year + 1900), (timeinfo.tm_mon + 1), timeinfo.tm_mday,
45 timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec);
46 std::string path(name);
47 std::shared_ptr<UiDevice> mDevice = UiDevice::getInstance();
48 mDevice->takeScreenshot(path, 1.0, 1);
50 std::ifstream ifs(path, std::ifstream::binary);
51 ::aurum::RspTakeScreenshot rsp;
52 int size = mDevice->getScreenSize().width * mDevice->getScreenSize().height;
57 rsp.set_image(buf, ifs.gcount());
62 return grpc::Status::OK;