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()
48 ApplicationLauncher::~ApplicationLauncher()
52 void ApplicationLauncher::OnEventReceived(
53 const ApplicationLauncherEvents::LaunchApplicationByAppService &event)
56 bundle *args = event.GetArg0();
57 appsvc_res_fn responseCallback = event.GetArg1();
58 void *userData = event.GetArg2();
59 result = appsvc_run_service(args, 0, responseCallback, userData);
62 LogError("Failed to run AppService : " << result);
65 void ApplicationLauncher::OnEventReceived(
66 const ApplicationLauncherEvents::LaunchApplicationByPkgname &event)
68 using namespace ApplicationLauncherPkgname;
69 LogDebug("LaunchApplicationByPkgname");
70 std::string pkgName(event.GetArg0());
72 if (PKG_NAME_DOWNLOAD_PROVIDER == pkgName) {
73 std::string url(event.GetArg1());
74 // This value needs for checking video, music contents later.
75 //std::string mime_type(event.GetArg2());
76 std::string cookie(event.GetArg3());
79 LogError("url is empty");
83 service_h serviceHandle = NULL;
84 int ret = SERVICE_ERROR_NONE;
87 ret = service_create(&serviceHandle);
88 if (SERVICE_ERROR_NONE != ret && NULL == serviceHandle) {
89 LogError("Fail to create service");
93 // set service operation
94 ret = service_set_operation(serviceHandle, SERVICE_OPERATION_DOWNLOAD);
95 if (SERVICE_ERROR_NONE != ret) {
96 LogError("Fail to set operation [" << ret << "]");
97 service_destroy(serviceHandle);
102 ret = service_set_uri(serviceHandle, url.c_str());
103 if (SERVICE_ERROR_NONE != ret) {
104 LogError("Fail to set uri [" << ret << "]");
105 service_destroy(serviceHandle);
110 if (cookie != "null") {
111 ret = service_add_extra_data(serviceHandle,
112 SERVICE_EXTRA_DATA_KEY_COOKIE,
114 if (SERVICE_ERROR_NONE != ret) {
115 LogError("Fail to add cookie [" << ret << "]");
116 service_destroy(serviceHandle);
122 ret = service_send_launch_request(serviceHandle, NULL, NULL);
123 if (SERVICE_ERROR_NONE != ret) {
124 LogError("Fail to launch service [" << ret << "]");
125 service_destroy(serviceHandle);
129 LogDebug("Success launch " << SERVICE_OPERATION_DOWNLOAD);
130 service_destroy(serviceHandle);
132 } else if (PKG_NAME_VIDEO_PLAYER == pkgName) {
133 bool isRunning = false;
134 if (APP_MANAGER_ERROR_NONE !=
135 app_manager_is_running(PKG_NAME_VT_MAIN.c_str(), &isRunning))
137 LogError("Fail to get app running information");
140 if (true == isRunning) {
141 LogError("video-call is running");
145 std::string scheme(event.GetArg1());
146 std::string uri(event.GetArg2());
147 std::string cookie(event.GetArg3());
150 if ("null" == scheme) {
151 LogError("scheme is empty");
155 LogError("uri is empty");
159 LogDebug("scheme: " << scheme);
160 if (SCHEME_TYPE_YOUTUBE == scheme) {
161 YouTubeHD *youtube = new YouTubeHD(m_tizenId);
162 url = youtube->getYouTubeHD(uri.c_str());
164 } else if (SCHEME_TYPE_RTSP == scheme ||
165 (SCHEME_TYPE_HTML5_VIDEO == scheme))
169 LogError("scheme is invalid!!");
173 service_h serviceHandle = NULL;
174 int ret = SERVICE_ERROR_NONE;
177 ret = service_create(&serviceHandle);
178 if (SERVICE_ERROR_NONE != ret && NULL == serviceHandle) {
179 LogError("Fail to create service");
184 if (!url || strlen(url) == 0) {
185 LogError("Fail to get url");
186 service_destroy(serviceHandle);
189 ret = service_add_extra_data(serviceHandle,
190 SERVICE_EXTRA_DATA_KEY_PATH,
192 if (SERVICE_ERROR_NONE != ret) {
193 LogError("Fail to set url [" << ret << "]");
194 service_destroy(serviceHandle);
199 if (SCHEME_TYPE_HTML5_VIDEO == scheme) {
200 if ("null" != cookie) {
201 ret = service_add_extra_data(serviceHandle,
202 SERVICE_EXTRA_DATA_KEY_COOKIE,
204 if (SERVICE_ERROR_NONE != ret) {
205 LogError("Fail to add cookie [" << ret << "]");
206 service_destroy(serviceHandle);
213 ret = service_set_package(serviceHandle, PKG_NAME_VIDEO_PLAYER.c_str());
214 if (SERVICE_ERROR_NONE != ret) {
215 LogError("Fail to set package [" << ret << "]");
216 service_destroy(serviceHandle);
221 ret = service_send_launch_request(serviceHandle, NULL, NULL);
222 if (SERVICE_ERROR_NONE != ret) {
223 LogError("Fail to launch service [" << ret << "]");
224 service_destroy(serviceHandle);
228 LogDebug("Success launch " << PKG_NAME_VIDEO_PLAYER);
229 service_destroy(serviceHandle);
234 void ApplicationLauncher::setWidgetTizenId(const std::string& tizenId)
236 LogDebug("tizen id: " << tizenId);