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 view_logic_apps_support.cpp
18 * @author Pawel Sikorski (p.sikorski@samsung.com)
19 * @brief Implementation file of AppsSupport class used by ViewLogic
22 #include "view_logic_apps_support.h"
23 #include <dpl/assert.h>
24 #include <dpl/log/log.h>
27 #include <widget_model.h>
28 #include <application_launcher.h>
30 namespace ViewModule {
33 const char* const SCHEME_TYPE_HTML5_VIDEO = "html5video";
34 const char* const HTTP_STREAMING_MPEG_MIMETYPE = "application/x-mpegurl";
35 const char* const HTTP_STREAMING_APPLE_MIMETYPE =
36 "application/vnd.apple.mpegurl";
39 //Implementation class
40 class AppsSupportImplementation
43 WidgetModel *m_widgetModel;
52 AppsSupportImplementation() :
58 ~AppsSupportImplementation()
60 Assert(!m_initialized &&
61 "AppsSupport has to be deinitialized prior destroying!");
64 void initialize(WidgetModel *widgetModel)
66 Assert(!m_initialized && "Already initialized!");
68 LogDebug("Initializing Apps Support");
69 Assert(widgetModel && "Passed widgetModel is NULL!");
70 m_widgetModel = widgetModel;
72 ApplicationLauncherSingleton::Instance().Touch();
74 ApplicationLauncherSingleton::Instance().setWidgetTizenId(
75 DPL::ToUTF8String(m_widgetModel->TizenId));
77 LogDebug("Initialized");
83 Assert(m_initialized && "Not initialized!");
84 LogDebug("Deinitialized");
86 m_initialized = false;
89 bool httpMultimediaRequest(std::string mimeType, std::string uri)
91 LogInfo("httpMultimediaRequest called");
93 if ("null" == mimeType || "null" == uri) {
94 LogError("uri/mimeType is null");
99 args = bundle_create();
100 void *userData = NULL;
101 appsvc_res_fn responseCallback = NULL;
103 // ignore case match of string of mime type
104 // if needed, define appsvc response callback
105 // and its user data per mimetype
106 if (!strcasecmp(mimeType.c_str(), HTTP_STREAMING_APPLE_MIMETYPE) ||
107 !strcasecmp(mimeType.c_str(), HTTP_STREAMING_MPEG_MIMETYPE))
109 appsvc_set_operation(args, APPSVC_OPERATION_VIEW);
110 appsvc_set_mime(args, mimeType.c_str());
111 appsvc_set_uri(args, uri.c_str());
112 } else if (!strcasecmp(mimeType.c_str(), "video/mp4") ||
113 !strcasecmp(mimeType.c_str(), "vidoe/3gp"))
115 CONTROLLER_POST_EVENT(
117 ApplicationLauncherEvents::LaunchApplicationByPkgname(
118 ApplicationLauncherPkgname::PKG_NAME_VIDEO_PLAYER,
119 SCHEME_TYPE_HTML5_VIDEO,
123 LogInfo("Not Supported MIME type in WRT");
128 CONTROLLER_POST_EVENT(
130 ApplicationLauncherEvents::LaunchApplicationByAppService(
138 void downloadRequest(const char *url,
139 const char *mimeType,
140 const char *userParam)
142 LogInfo("Download info : " << url << "(" <<
143 mimeType << ", " << userParam << ")");
145 // ignore case match of string of mime type
146 int isAppServiceable = httpMultimediaRequest(
147 mimeType ? std::string(mimeType) : "null",
148 url ? std::string(url) : "null");
150 if (isAppServiceable) {
151 LogInfo("Application Service start");
155 CONTROLLER_POST_EVENT(
157 ApplicationLauncherEvents::LaunchApplicationByPkgname(
158 ApplicationLauncherPkgname::PKG_NAME_DOWNLOAD_PROVIDER,
159 url ? std::string(url) : "null",
160 mimeType ? mimeType : "null",
161 userParam ? userParam : "null"));
164 void html5VideoRequest(void* event_info)
166 LogInfo("html5VideoRequestCallback called");
168 HTML5Video* video = static_cast<HTML5Video*>(event_info);
170 LogDebug("video->path : " << video->path);
171 LogDebug("video->cookie : " << video->cookie);
172 if (NULL == video->path) {
173 LogError("path is null");
176 CONTROLLER_POST_EVENT(
178 ApplicationLauncherEvents::LaunchApplicationByPkgname(
179 ApplicationLauncherPkgname::PKG_NAME_VIDEO_PLAYER,
180 SCHEME_TYPE_HTML5_VIDEO,
181 video->path ? video->path : "null",
182 video->cookie ? video->cookie : "null"));
186 AppsSupport::AppsSupport(): m_impl(new AppsSupportImplementation)
190 AppsSupport::~AppsSupport()
194 void AppsSupport::initialize(WidgetModel *widgetModel)
196 m_impl->initialize(widgetModel);
199 void AppsSupport::deinitialize()
201 m_impl->deinitialize();
204 void AppsSupport::html5VideoRequest(void* event_info)
206 m_impl->html5VideoRequest(event_info);
209 void AppsSupport::downloadRequest(const char *url,
210 const char *mimeType,
211 const char *userParam)
213 m_impl->downloadRequest(url, mimeType, userParam);