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/secure_log.h>
26 #include <dpl/singleton_impl.h>
29 #include <app_manager.h>
32 #include <notification.h>
33 #include <widget_string.h>
35 IMPLEMENT_SINGLETON(ApplicationLauncher)
38 const char * const SERVICE_EXTRA_DATA_KEY_PATH = "path";
39 const char * const SERVICE_EXTRA_DATA_KEY_COOKIE = "cookie";
40 const char * const SERVICE_EXTRA_DATA_KEY_MODE = "mode";
41 const char * const SERVICE_EXTRA_DATA_VALUE_SLIENT = "silent";
43 const char * const SCHEME_TYPE_RTSP = "rtsp";
44 const char * const SCHEME_TYPE_HTML5_VIDEO = "html5video";
47 ApplicationLauncher::ApplicationLauncher() :
52 ApplicationLauncher::~ApplicationLauncher()
55 void ApplicationLauncher::OnEventReceived(
56 const ApplicationLauncherEvents::LaunchApplicationByAppService &event)
59 service_h serviceHandle = event.GetArg0();
60 service_reply_cb responseCallback = event.GetArg1();
61 void *userData = event.GetArg2();
64 service_set_window(serviceHandle, m_windowHandle);
67 result = service_send_launch_request(serviceHandle, responseCallback, userData);
68 if (result != SERVICE_ERROR_NONE) {
69 service_destroy(serviceHandle);
70 _E("Failed to run service : %d", result);
73 service_destroy(serviceHandle);
74 _D("Success to run service");
77 void ApplicationLauncher::OnEventReceived(
78 const ApplicationLauncherEvents::LaunchApplicationByPkgname &event)
80 using namespace ApplicationLauncherPkgname;
81 std::string pkgName(event.GetArg0());
83 if (PKG_NAME_DOWNLOAD_PROVIDER == pkgName) {
84 std::string url(event.GetArg1());
85 // This value needs for checking video, music contents later.
86 //std::string mime_type(event.GetArg2());
87 std::string cookie(event.GetArg3());
94 service_h serviceHandle = NULL;
95 int ret = SERVICE_ERROR_NONE;
98 ret = service_create(&serviceHandle);
99 if (SERVICE_ERROR_NONE != ret && NULL == serviceHandle) {
100 _E("Fail to create service");
104 // set service operation
105 ret = service_set_operation(serviceHandle, SERVICE_OPERATION_DOWNLOAD);
106 if (SERVICE_ERROR_NONE != ret) {
107 _E("Fail to set operation [%d]", ret);
108 service_destroy(serviceHandle);
113 ret = service_set_uri(serviceHandle, url.c_str());
114 if (SERVICE_ERROR_NONE != ret) {
115 _E("Fail to set uri [%d]");
116 service_destroy(serviceHandle);
121 if (cookie != "null") {
122 ret = service_add_extra_data(serviceHandle,
123 SERVICE_EXTRA_DATA_KEY_COOKIE,
125 if (SERVICE_ERROR_NONE != ret) {
126 _D("Fail to add cookie [%d]", ret);
127 service_destroy(serviceHandle);
132 ret = service_add_extra_data(serviceHandle,
133 SERVICE_EXTRA_DATA_KEY_MODE,
134 SERVICE_EXTRA_DATA_VALUE_SLIENT);
135 if (SERVICE_ERROR_NONE != ret) {
136 _E("Fail to set service extra data [%d]", ret);
137 service_destroy(serviceHandle);
141 if (m_windowHandle) {
142 service_set_window(serviceHandle, m_windowHandle);
146 ret = service_send_launch_request(serviceHandle, NULL, NULL);
147 if (SERVICE_ERROR_NONE != ret) {
148 _E("Fail to launch service [%d]", ret);
149 service_destroy(serviceHandle);
152 service_destroy(serviceHandle);
153 notification_status_message_post(WRT_POP_STARTING_DOWNLOADING);
155 } else if (PKG_NAME_VIDEO_PLAYER == pkgName) {
156 bool isRunning = false;
157 if (APP_MANAGER_ERROR_NONE !=
158 app_manager_is_running(PKG_NAME_VT_MAIN.c_str(), &isRunning))
160 _E("Fail to get app running information");
163 if (true == isRunning) {
164 _E("video-call is running");
168 std::string scheme(event.GetArg1());
169 std::string uri(event.GetArg2());
170 std::string cookie(event.GetArg3());
173 if ("null" == scheme) {
174 _E("scheme is empty");
182 if (SCHEME_TYPE_RTSP == scheme ||
183 SCHEME_TYPE_HTML5_VIDEO == scheme)
187 _E("scheme is invalid!!");
191 service_h serviceHandle = NULL;
192 int ret = SERVICE_ERROR_NONE;
195 ret = service_create(&serviceHandle);
196 if (SERVICE_ERROR_NONE != ret && NULL == serviceHandle) {
197 _E("Fail to create service");
202 if (!url || strlen(url) == 0) {
203 _E("Fail to get url");
204 service_destroy(serviceHandle);
207 ret = service_add_extra_data(serviceHandle,
208 SERVICE_EXTRA_DATA_KEY_PATH,
210 if (SERVICE_ERROR_NONE != ret) {
211 _E("Fail to set url [%d]", ret);
212 service_destroy(serviceHandle);
217 if (SCHEME_TYPE_HTML5_VIDEO == scheme) {
218 if ("null" != cookie) {
219 ret = service_add_extra_data(serviceHandle,
220 SERVICE_EXTRA_DATA_KEY_COOKIE,
222 if (SERVICE_ERROR_NONE != ret) {
223 _E("Fail to add cookie [%d]", ret);
224 service_destroy(serviceHandle);
231 ret = service_set_package(serviceHandle, PKG_NAME_VIDEO_PLAYER.c_str());
232 if (SERVICE_ERROR_NONE != ret) {
233 _E("Fail to set package service [%d]", ret);
234 service_destroy(serviceHandle);
238 // set window handle when available
239 if (m_windowHandle) {
240 service_set_window(serviceHandle, m_windowHandle);
244 ret = service_send_launch_request(serviceHandle, NULL, NULL);
245 if (SERVICE_ERROR_NONE != ret) {
246 _E("Fail to launch service [%d]", ret);
247 service_destroy(serviceHandle);
250 service_destroy(serviceHandle);
253 _E("Not implemented application : ", pkgName.c_str());
256 _D("Success to launch application : ", pkgName.c_str());
260 void ApplicationLauncher::setWidgetTizenId(const std::string& tizenId)
265 void ApplicationLauncher::setWindowHandle(unsigned windowHandle)
267 m_windowHandle = windowHandle;