2 * Copyright (c) 2011 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.
17 * @file application_launcher.cpp
18 * @author Lukasz Wrzosek (l.wrzosek@samsung.com)
20 * @brief Implementation file for application launcher
23 #include "application_launcher.h"
25 #include <dpl/log/wrt_log.h>
26 #include <dpl/singleton_impl.h>
29 #include <app_manager.h>
31 #include <notification.h>
32 #include <widget_string.h>
34 IMPLEMENT_SINGLETON(ApplicationLauncher)
37 const char * const APP_CONTROL_EXTRA_DATA_KEY_PATH = "path";
38 const char * const APP_CONTROL_EXTRA_DATA_KEY_COOKIE = "cookie";
39 const char * const APP_CONTROL_EXTRA_DATA_KEY_MODE = "mode";
40 const char * const APP_CONTROL_EXTRA_DATA_VALUE_SLIENT = "silent";
42 const char * const SCHEME_TYPE_RTSP = "rtsp";
43 const char * const SCHEME_TYPE_HTML5_VIDEO = "html5video";
46 ApplicationLauncher::ApplicationLauncher() :
51 ApplicationLauncher::~ApplicationLauncher()
54 void ApplicationLauncher::OnEventReceived(
55 const ApplicationLauncherEvents::LaunchApplicationByAppService &event)
58 app_control_h app_control = event.GetArg0();
59 app_control_reply_cb responseCallback = event.GetArg1();
60 void *userData = event.GetArg2();
63 app_control_set_window(app_control, m_windowHandle);
66 result = app_control_send_launch_request(app_control, responseCallback, userData);
67 if (result != APP_CONTROL_ERROR_NONE) {
68 app_control_destroy(app_control);
69 WrtLogE("Failed to run app_control : %d", result);
72 app_control_destroy(app_control);
73 WrtLogD("Success to run app_control");
76 void ApplicationLauncher::OnEventReceived(
77 const ApplicationLauncherEvents::LaunchApplicationByPkgname &event)
79 using namespace ApplicationLauncherPkgname;
80 std::string pkgName(event.GetArg0());
82 if (PKG_NAME_DOWNLOAD_PROVIDER == pkgName) {
83 std::string url(event.GetArg1());
84 // This value needs for checking video, music contents later.
85 //std::string mime_type(event.GetArg2());
86 std::string cookie(event.GetArg3());
89 WrtLogE("url is empty");
93 app_control_h app_control = NULL;
94 int ret = APP_CONTROL_ERROR_NONE;
97 ret = app_control_create(&app_control);
98 if (APP_CONTROL_ERROR_NONE != ret && NULL == app_control) {
99 WrtLogE("Fail to create app_control");
103 // set app_control operation
104 ret = app_control_set_operation(app_control, APP_CONTROL_OPERATION_DOWNLOAD);
105 if (APP_CONTROL_ERROR_NONE != ret) {
106 WrtLogE("Fail to set operation [%d]", ret);
107 app_control_destroy(app_control);
111 // set app_control uri
112 ret = app_control_set_uri(app_control, url.c_str());
113 if (APP_CONTROL_ERROR_NONE != ret) {
114 WrtLogE("Fail to set uri [%d]", ret);
115 app_control_destroy(app_control);
120 if (cookie != "null") {
121 ret = app_control_add_extra_data(app_control,
122 APP_CONTROL_EXTRA_DATA_KEY_COOKIE,
124 if (APP_CONTROL_ERROR_NONE != ret) {
125 WrtLogD("Fail to add cookie [%d]", ret);
126 app_control_destroy(app_control);
131 ret = app_control_add_extra_data(app_control,
132 APP_CONTROL_EXTRA_DATA_KEY_MODE,
133 APP_CONTROL_EXTRA_DATA_VALUE_SLIENT);
134 if (APP_CONTROL_ERROR_NONE != ret) {
135 WrtLogE("Fail to set app_control extra data [%d]", ret);
136 app_control_destroy(app_control);
140 if (m_windowHandle) {
141 app_control_set_window(app_control, m_windowHandle);
145 ret = app_control_send_launch_request(app_control, NULL, NULL);
146 if (APP_CONTROL_ERROR_NONE != ret) {
147 WrtLogE("Fail to launch app_control [%d]", ret);
148 app_control_destroy(app_control);
151 app_control_destroy(app_control);
152 notification_status_message_post(WRT_POP_STARTING_DOWNLOADING);
154 } else if (PKG_NAME_VIDEO_PLAYER == pkgName) {
155 bool isRunning = false;
156 if (APP_MANAGER_ERROR_NONE !=
157 app_manager_is_running(PKG_NAME_VT_MAIN.c_str(), &isRunning))
159 WrtLogE("Fail to get app running information");
162 if (true == isRunning) {
163 WrtLogE("video-call is running");
167 std::string scheme(event.GetArg1());
168 std::string uri(event.GetArg2());
169 std::string cookie(event.GetArg3());
172 if ("null" == scheme) {
173 WrtLogE("scheme is empty");
177 WrtLogE("uri is empty");
181 if (SCHEME_TYPE_RTSP == scheme ||
182 SCHEME_TYPE_HTML5_VIDEO == scheme)
186 WrtLogE("scheme is invalid!!");
190 app_control_h app_control = NULL;
191 int ret = APP_CONTROL_ERROR_NONE;
193 // create app_control
194 ret = app_control_create(&app_control);
195 if (APP_CONTROL_ERROR_NONE != ret && NULL == app_control) {
196 WrtLogE("Fail to create app_control");
201 if (!url || strlen(url) == 0) {
202 WrtLogE("Fail to get url");
203 app_control_destroy(app_control);
206 ret = app_control_add_extra_data(app_control,
207 APP_CONTROL_EXTRA_DATA_KEY_PATH,
209 if (APP_CONTROL_ERROR_NONE != ret) {
210 WrtLogE("Fail to set url [%d]", ret);
211 app_control_destroy(app_control);
216 if (SCHEME_TYPE_HTML5_VIDEO == scheme) {
217 if ("null" != cookie) {
218 ret = app_control_add_extra_data(app_control,
219 APP_CONTROL_EXTRA_DATA_KEY_COOKIE,
221 if (APP_CONTROL_ERROR_NONE != ret) {
222 WrtLogE("Fail to add cookie [%d]", ret);
223 app_control_destroy(app_control);
230 ret = app_control_set_app_id(app_control, PKG_NAME_VIDEO_PLAYER.c_str());
231 if (APP_CONTROL_ERROR_NONE != ret) {
232 WrtLogE("Fail to set package app_control [%d]", ret);
233 app_control_destroy(app_control);
237 // set window handle when available
238 if (m_windowHandle) {
239 app_control_set_window(app_control, m_windowHandle);
243 ret = app_control_send_launch_request(app_control, NULL, NULL);
244 if (APP_CONTROL_ERROR_NONE != ret) {
245 WrtLogE("Fail to launch app_control [%d]", ret);
246 app_control_destroy(app_control);
249 app_control_destroy(app_control);
252 WrtLogE("Not implemented application : %s", pkgName.c_str());
255 WrtLogD("Success to launch application : %s", pkgName.c_str());
259 void ApplicationLauncher::setWidgetTizenId(const std::string& tizenId)
264 void ApplicationLauncher::setWindowHandle(unsigned windowHandle)
266 m_windowHandle = windowHandle;