LaunchAppCommand: resolve possible memory leak
[platform/core/uifw/aurum.git] / org.tizen.aurum-bootstrap / src / Commands / LaunchAppCommand.cc
1 #include "LaunchAppCommand.h"
2 #include <loguru.hpp>
3 #include <chrono>
4 #include <thread>
5
6 #ifdef GBSBUILD
7 #include <app_control.h>
8 #endif
9
10 LaunchAppCommand::LaunchAppCommand(const ::aurum::ReqLaunchApp* request,
11                                    ::aurum::RspLaunchApp*       response)
12     : mRequest{request}, mResponse{response}
13 {
14 }
15
16 ::grpc::Status LaunchAppCommand::execute()
17 {
18     LOG_SCOPE_F(INFO, "LaunchApp --------------- ");
19 #ifdef GBSBUILD
20     app_control_h appControl;
21     std::string   packageName = mRequest->packagename();
22     int           ret = -1;
23
24     if (packageName.empty()) return grpc::Status::OK;
25
26     ret = app_control_create(&appControl);
27     if (ret) {
28         LOG_SCOPE_F(INFO, "Launch Failed(1/3) Err Code : %ull", ret);
29         mResponse->set_status(::aurum::RspStatus::ERROR);
30         return grpc::Status::OK;
31     }
32
33     ret = app_control_set_app_id(appControl, packageName.c_str());
34     if (ret) {
35         LOG_SCOPE_F(INFO, "Launch Failed(2/3) Err Code : %ull", ret);
36         mResponse->set_status(::aurum::RspStatus::ERROR);
37         app_control_destroy(appControl);
38         return grpc::Status::OK;
39     }
40
41     ret = app_control_send_launch_request(appControl, NULL, NULL);
42     if (ret) {
43         LOG_SCOPE_F(INFO, "Launch Failed(3/3) Err Code : %ull", ret);
44         mResponse->set_status(::aurum::RspStatus::ERROR);
45         app_control_destroy(appControl);
46         return grpc::Status::OK;
47     }
48
49     app_control_destroy(appControl);
50 #endif
51     return grpc::Status::OK;
52 }
53 ::grpc::Status LaunchAppCommand::executePost()
54 {
55     LOG_SCOPE_F(INFO, "LaunchAppCommand::executePost");
56     std::this_thread::sleep_for(std::chrono::milliseconds{2500});
57     return grpc::Status::OK;
58 }