[Release] livebox.web-provider-1.4
[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 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  * @file    BoxDaemonUtil.cpp
18  * @author  Yunchan Cho (yunchan.cho@samsung.com)
19  */
20 #include <string>
21 #include <app_service.h>
22 #include <Core/Util/Log.h>
23 #include <API/web_provider_livebox_info.h>
24 #include "BoxDaemonUtil.h"
25
26 const std::string BoxDaemonUtil::boxIdKey("box-id");
27 const std::string BoxDaemonUtil::instanceIdKey("instance-id");
28
29 bool BoxDaemonUtil::launchApplication(std::string& boxId, std::string& instanceId)
30 {
31     LogD("enter");
32
33     const char* appId = web_provider_livebox_get_app_id(boxId.c_str());
34     if (!appId) {
35         LogD("no appid of %s", boxId.c_str());
36         return false;
37     }
38
39     service_h handle = NULL;
40     int ret = SERVICE_ERROR_NONE;
41
42     ret = service_create(&handle);
43     if (ret != SERVICE_ERROR_NONE && !handle) {
44         LogD("failed to create service");
45         return false;
46     }
47
48     ret = service_set_package(handle, appId);
49     if (ret != SERVICE_ERROR_NONE) {
50         LogD("failed to set package");
51         service_destroy(handle);
52         return false;
53     }
54
55     service_add_extra_data(handle, boxIdKey.c_str(), boxId.c_str());
56     service_add_extra_data(handle, instanceIdKey.c_str(), instanceId.c_str());
57
58     ret = service_send_launch_request(handle, NULL, NULL);
59     if (ret != SERVICE_ERROR_NONE) {
60         LogD("failed to launch package");
61         service_destroy(handle);
62         return false;
63     }
64
65     service_destroy(handle);
66     LogD("success to launch app of %s", boxId.c_str());
67     return true;
68 }