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.
19 #include <dpl/log/log.h>
20 #include <CommonsJavaScript/PrivateObject.h>
21 #include <CommonsJavaScript/Converter.h>
22 #include <CommonsJavaScript/JSUtils.h>
23 #include <Tizen/Common/JSTizenException.h>
24 #include <Tizen/Common/JSTizenExceptionFactory.h>
26 #include "JSMediacontent.h"
29 #define TIZEN_MEDIACONTENT_VIDEO_ATTRIBUTENAME "Video"
30 #define TIZEN_MEDIACONTENT_VIDEO_GEOLOCATION "geolocation"
31 #define TIZEN_MEDIACONTENT_VIDEO_ALBUM "album"
32 #define TIZEN_MEDIACONTENT_VIDEO_ARTIST "artist"
33 #define TIZEN_MEDIACONTENT_VIDEO_PLAYEDTIME "playedTime"
34 #define TIZEN_MEDIACONTENT_VIDEO_PLAYCOUNT "playCount"
35 #define TIZEN_MEDIACONTENT_VIDEO_DURATION "duration"
36 #define TIZEN_MEDIACONTENT_VIDEO_WIDTH "width"
37 #define TIZEN_MEDIACONTENT_VIDEO_HEIGHT "height"
39 using namespace WrtDeviceApis::Commons;
40 using namespace WrtDeviceApis::CommonsJavaScript;
41 using namespace TizenApis::Api::Mediacontent;
46 namespace Mediacontent {
49 JSClassDefinition JSVideo::m_classInfo =
52 kJSClassAttributeNone,
53 TIZEN_MEDIACONTENT_VIDEO_ATTRIBUTENAME,
54 JSMedia::getClassRef(),
62 NULL, //DeleteProperty,
63 NULL, //GetPropertyNames,
64 NULL, //CallAsFunction,
65 NULL, //CallAsConstructor,
70 JSStaticValue JSVideo::m_property[] =
72 { TIZEN_MEDIACONTENT_VIDEO_GEOLOCATION, getPropertyGeoLocation, NULL, kJSPropertyAttributeReadOnly},
73 { TIZEN_MEDIACONTENT_VIDEO_ALBUM, getPropertyAlbum, NULL, kJSPropertyAttributeReadOnly},
74 { TIZEN_MEDIACONTENT_VIDEO_ARTIST, getPropertyArtist, NULL, kJSPropertyAttributeReadOnly},
75 { TIZEN_MEDIACONTENT_VIDEO_PLAYEDTIME, getPropertyPlayedTime, setPropertyPlayedTime, kJSPropertyAttributeNone},
76 { TIZEN_MEDIACONTENT_VIDEO_PLAYCOUNT, getPropertyPlayCount, setPropertyPlayCount, kJSPropertyAttributeNone},
77 { TIZEN_MEDIACONTENT_VIDEO_DURATION, getPropertyDuration, NULL, kJSPropertyAttributeReadOnly},
78 { TIZEN_MEDIACONTENT_VIDEO_WIDTH, getPropertyWidth, NULL, kJSPropertyAttributeReadOnly},
79 { TIZEN_MEDIACONTENT_VIDEO_HEIGHT, getPropertyHeight, NULL, kJSPropertyAttributeReadOnly},
84 JSClassRef JSVideo::m_jsClassRef = JSClassCreate(JSVideo::getClassInfo());
86 void JSVideo::initialize(JSContextRef context, JSObjectRef object)
88 LogDebug( "entered" );
89 VideoPrivObject *priv = static_cast<VideoPrivObject*>( JSObjectGetPrivate( object ) );
92 MediacontentVideoPtr privateData(new MediacontentVideo());
93 priv = new VideoPrivObject(context, privateData);
94 JSObjectSetPrivate(object, static_cast<void*>(priv));
95 LogDebug("new event is created" );
98 LogDebug("private object already exists");
102 void JSVideo::finalize(JSObjectRef object)
104 LogDebug( "entered" );
105 VideoPrivObject *priv = static_cast<VideoPrivObject*>( JSObjectGetPrivate( object ) ) ;
109 const JSClassRef JSVideo::getClassRef()
111 LogDebug("JSVideo::getClassRef()");
115 m_jsClassRef = JSClassCreate(&m_classInfo);
120 const JSClassDefinition* JSVideo::getClassInfo()
126 MediacontentVideoPtr JSVideo::getVideoObject(JSObjectRef object)
129 VideoPrivObject *priv = static_cast<VideoPrivObject*>(JSObjectGetPrivate(object));
132 ThrowMsg(NullPointerException, "Private object is null");
134 MediacontentVideoPtr result = priv->getObject();
137 ThrowMsg(NullPointerException, "Private object is null");
143 JSValueRef JSVideo::getPropertyGeoLocation(
144 JSContextRef context,
146 JSStringRef propertyName,
147 JSValueRef* exception)
152 Converter converter(context);
153 MediacontentVideoPtr event = getVideoObject(object);
155 return converter.toJSValueRef(event->getVideoLongitude());
159 LogWarning("trying to get incorrect value");
161 return JSValueMakeUndefined(context);
165 JSValueRef JSVideo::getPropertyAlbum(
166 JSContextRef context,
168 JSStringRef propertyName,
169 JSValueRef* exception)
174 Converter converter(context);
175 MediacontentVideoPtr event = getVideoObject(object);
176 return converter.toJSValueRef(event->getVideoAlbum());
180 LogWarning("trying to get incorrect value");
182 return JSValueMakeUndefined(context);
186 JSValueRef JSVideo::getPropertyArtist(
187 JSContextRef context,
189 JSStringRef propertyName,
190 JSValueRef* exception)
195 Converter converter(context);
196 MediacontentVideoPtr event = getVideoObject(object);
197 return converter.toJSValueRef(event->getVideoArtist());
201 LogWarning("trying to get incorrect value");
203 return JSValueMakeUndefined(context);
207 JSValueRef JSVideo::getPropertyPlayedTime(
208 JSContextRef context,
210 JSStringRef propertyName,
211 JSValueRef* exception)
216 Converter converter(context);
217 MediacontentVideoPtr event = getVideoObject(object);
218 return converter.toJSValueRef(event->getVideoPlayedTime());
222 LogWarning("trying to get incorrect value");
224 return JSValueMakeUndefined(context);
227 JSValueRef JSVideo::getPropertyPlayCount(
228 JSContextRef context,
230 JSStringRef propertyName,
231 JSValueRef* exception)
236 Converter converter(context);
237 MediacontentVideoPtr event = getVideoObject(object);
238 return converter.toJSValueRef(event->getVideoPlayCount());
242 LogWarning("trying to get incorrect value");
244 return JSValueMakeUndefined(context);
249 JSValueRef JSVideo::getPropertyDuration(
250 JSContextRef context,
252 JSStringRef propertyName,
253 JSValueRef* exception)
258 Converter converter(context);
259 MediacontentVideoPtr event = getVideoObject(object);
260 return converter.toJSValueRef(event->getVideoDuration());
264 LogWarning("trying to get incorrect value");
266 return JSValueMakeUndefined(context);
269 JSValueRef JSVideo::getPropertyWidth(
270 JSContextRef context,
272 JSStringRef propertyName,
273 JSValueRef* exception)
278 Converter converter(context);
279 MediacontentVideoPtr event = getVideoObject(object);
280 return converter.toJSValueRef(event->getVideoWidth());
284 LogWarning("trying to get incorrect value");
286 return JSValueMakeUndefined(context);
290 JSValueRef JSVideo::getPropertyHeight(
291 JSContextRef context,
293 JSStringRef propertyName,
294 JSValueRef* exception)
299 Converter converter(context);
300 MediacontentVideoPtr event = getVideoObject(object);
301 return converter.toJSValueRef(event->getVideoHeight());
305 LogWarning("trying to get incorrect value");
307 return JSValueMakeUndefined(context);
312 bool JSVideo::setPropertyPlayedTime(
313 JSContextRef context,
315 JSStringRef propertyName,
317 JSValueRef* exception)
322 Converter converter(context);
323 MediacontentVideoPtr event = getVideoObject(object);
324 int rating = converter.toLong(value);
325 event->setVideoPlayedTime(rating);
330 LogWarning("trying to set incorrect value");
331 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
338 bool JSVideo::setPropertyPlayCount(
339 JSContextRef context,
341 JSStringRef propertyName,
343 JSValueRef* exception)
348 Converter converter(context);
349 MediacontentVideoPtr event = getVideoObject(object);
350 int rating = converter.toInt(value);
351 event->setVideoPlayCount(rating);
356 LogWarning("trying to set incorrect value");
357 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);