b69e8589ad46980dce5a1a9056fcc4bba5a4cb72
[platform/framework/web/web-provider.git] / src / Daemon / BoxDaemonUtil.cpp
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Flora License, Version 1.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://floralicense.org/license/
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  * @file    BoxDaemonUtil.cpp
18  * @author  Yunchan Cho (yunchan.cho@samsung.com)
19  */
20 #include <string>
21 #include <memory>
22 #include <app_service.h>
23 #include <Core/Util/Log.h>
24 #include <API/web_provider_livebox_info.h>
25 #include "BoxDaemonUtil.h"
26
27 const std::string BoxDaemonUtil::boxIdKey("box-id");
28 const std::string BoxDaemonUtil::instanceIdKey("instance-id");
29
30 bool BoxDaemonUtil::launchApplication(std::string& boxId, std::string& instanceId)
31 {
32     LogD("enter");
33
34     std::shared_ptr<const char> appId(web_provider_livebox_get_app_id(boxId.c_str()));
35     if (!appId) {
36         LogD("no appid of %s", boxId.c_str());
37         return false;
38     }
39
40     service_h handle = NULL;
41     int ret = SERVICE_ERROR_NONE;
42
43     ret = service_create(&handle);
44     if (ret != SERVICE_ERROR_NONE && !handle) {
45         LogD("failed to create service");
46         return false;
47     }
48
49     ret = service_set_package(handle, appId.get());
50     if (ret != SERVICE_ERROR_NONE) {
51         LogD("failed to set package");
52         service_destroy(handle);
53         return false;
54     }
55
56     service_add_extra_data(handle, boxIdKey.c_str(), boxId.c_str());
57     service_add_extra_data(handle, instanceIdKey.c_str(), instanceId.c_str());
58
59     ret = service_send_launch_request(handle, NULL, NULL);
60     if (ret != SERVICE_ERROR_NONE) {
61         LogD("failed to launch package");
62         service_destroy(handle);
63         return false;
64     }
65
66     service_destroy(handle);
67     LogD("success to launch app of %s", boxId.c_str());
68
69     return true;
70 }