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 <app_manager.h>
27 #include <youtubehd.h>
28 #include <dpl/singleton_impl.h>
31 IMPLEMENT_SINGLETON(ApplicationLauncher)
33 using namespace WrtDB;
36 const char * const SERVICE_EXTRA_DATA_KEY_PATH = "path";
37 const char * const SERVICE_EXTRA_DATA_KEY_COOKIE = "cookie";
39 const char * const SCHEME_TYPE_YOUTUBE = "vnd.youtube";
40 const char * const SCHEME_TYPE_RTSP = "rtsp";
41 const char * const SCHEME_TYPE_HTML5_VIDEO = "html5video";
44 ApplicationLauncher::ApplicationLauncher()
47 ApplicationLauncher::~ApplicationLauncher()
50 void ApplicationLauncher::OnEventReceived(
51 const ApplicationLauncherEvents::LaunchApplicationByAppService &event)
54 bundle *args = event.GetArg0();
55 appsvc_res_fn responseCallback = event.GetArg1();
56 void *userData = event.GetArg2();
57 result = appsvc_run_service(args, 0, responseCallback, userData);
60 LogError("Failed to run AppService : " << result);
64 void ApplicationLauncher::OnEventReceived(
65 const ApplicationLauncherEvents::LaunchApplicationByPkgname &event)
67 using namespace ApplicationLauncherPkgname;
68 LogDebug("LaunchApplicationByPkgname");
69 std::string pkgName(event.GetArg0());
71 if (PKG_NAME_DOWNLOAD_PROVIDER == pkgName) {
72 std::string url(event.GetArg1());
73 // This value needs for checking video, music contents later.
74 //std::string mime_type(event.GetArg2());
75 std::string cookie(event.GetArg3());
78 LogError("url is empty");
82 service_h serviceHandle = NULL;
83 int ret = SERVICE_ERROR_NONE;
86 ret = service_create(&serviceHandle);
87 if (SERVICE_ERROR_NONE != ret && NULL == serviceHandle) {
88 LogError("Fail to create service");
92 // set service operation
93 ret = service_set_operation(serviceHandle, SERVICE_OPERATION_DOWNLOAD);
94 if (SERVICE_ERROR_NONE != ret) {
95 LogError("Fail to set operation [" << ret << "]");
96 service_destroy(serviceHandle);
101 ret = service_set_uri(serviceHandle, url.c_str());
102 if (SERVICE_ERROR_NONE != ret) {
103 LogError("Fail to set uri [" << ret << "]");
104 service_destroy(serviceHandle);
109 if (cookie != "null") {
110 ret = service_add_extra_data(serviceHandle,
111 SERVICE_EXTRA_DATA_KEY_COOKIE,
113 if (SERVICE_ERROR_NONE != ret) {
114 LogError("Fail to add cookie [" << ret << "]");
115 service_destroy(serviceHandle);
121 ret = service_send_launch_request(serviceHandle, NULL, NULL);
122 if (SERVICE_ERROR_NONE != ret) {
123 LogError("Fail to launch service [" << ret << "]");
124 service_destroy(serviceHandle);
128 LogDebug("Success launch " << SERVICE_OPERATION_DOWNLOAD);
129 service_destroy(serviceHandle);
131 } else if (PKG_NAME_VIDEO_PLAYER == pkgName) {
132 bool isRunning = false;
133 if (APP_MANAGER_ERROR_NONE !=
134 app_manager_is_running(PKG_NAME_VT_MAIN.c_str(), &isRunning))
136 LogError("Fail to get app running information");
139 if (true == isRunning) {
140 LogError("video-call is running");
144 std::string scheme(event.GetArg1());
145 std::string uri(event.GetArg2());
146 std::string cookie(event.GetArg3());
149 if ("null" == scheme) {
150 LogError("scheme is empty");
154 LogError("uri is empty");
158 LogDebug("scheme: " << scheme);
159 if (SCHEME_TYPE_YOUTUBE == scheme) {
160 YouTubeHD *youtube = new YouTubeHD(m_tizenId);
161 url = youtube->getYouTubeHD(uri.c_str());
163 } else if (SCHEME_TYPE_RTSP == scheme ||
164 (SCHEME_TYPE_HTML5_VIDEO == scheme))
168 LogError("scheme is invalid!!");
172 service_h serviceHandle = NULL;
173 int ret = SERVICE_ERROR_NONE;
176 ret = service_create(&serviceHandle);
177 if (SERVICE_ERROR_NONE != ret && NULL == serviceHandle) {
178 LogError("Fail to create service");
183 if (!url || strlen(url) == 0) {
184 LogError("Fail to get url");
185 service_destroy(serviceHandle);
188 ret = service_add_extra_data(serviceHandle,
189 SERVICE_EXTRA_DATA_KEY_PATH,
191 if (SERVICE_ERROR_NONE != ret) {
192 LogError("Fail to set url [" << ret << "]");
193 service_destroy(serviceHandle);
198 if (SCHEME_TYPE_HTML5_VIDEO == scheme) {
199 if ("null" != cookie) {
200 ret = service_add_extra_data(serviceHandle,
201 SERVICE_EXTRA_DATA_KEY_COOKIE,
203 if (SERVICE_ERROR_NONE != ret) {
204 LogError("Fail to add cookie [" << ret << "]");
205 service_destroy(serviceHandle);
212 ret = service_set_package(serviceHandle, PKG_NAME_VIDEO_PLAYER.c_str());
213 if (SERVICE_ERROR_NONE != ret) {
214 LogError("Fail to set package [" << ret << "]");
215 service_destroy(serviceHandle);
220 ret = service_send_launch_request(serviceHandle, NULL, NULL);
221 if (SERVICE_ERROR_NONE != ret) {
222 LogError("Fail to launch service [" << ret << "]");
223 service_destroy(serviceHandle);
227 LogDebug("Success launch " << PKG_NAME_VIDEO_PLAYER);
228 service_destroy(serviceHandle);
233 void ApplicationLauncher::setWidgetTizenId(const std::string& tizenId)
235 LogDebug("tizen id: " << tizenId);