implement screenshot feature
[platform/core/uifw/aurum.git] / org.tizen.aurum-bootstrap / src / Commands / TakeScreenshotCommand.cc
1 #include "TakeScreenshotCommand.h"
2 #include <loguru.hpp>
3 #include "UiObject.h"
4 #include "UiDevice.h"
5 #include <fstream>
6
7 TakeScreenshotCommand::TakeScreenshotCommand(
8     const ::aurum::ReqTakeScreenshot*                  request,
9     ::grpc::ServerWriter< ::aurum::RspTakeScreenshot>* writer)
10     : mRequest{request}, mWriter{writer}
11 {
12 }
13
14 ::grpc::Status TakeScreenshotCommand::execute()
15 {
16     LOG_SCOPE_F(INFO, "TakeScreenshot --------------- ");
17
18     std::string path = "/tmp/screenshot.png";
19     UiDevice* mDevice = UiDevice::getInstance(DeviceType::DEFAULT);
20     mDevice->takeScreenshot(path, 1.0, 1);
21
22     std::ifstream ifs(path, std::ifstream::binary);
23     ::aurum::RspTakeScreenshot rsp;
24     int size = 1024 * 1024;
25     char buf[size];
26
27     while (!ifs.eof()) {
28         ifs.read(buf, size);
29         rsp.set_image(buf, ifs.gcount());
30         mWriter->Write(rsp);
31     }
32     ifs.close();
33
34     return grpc::Status::OK;
35 }