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>
25 #include <Tizen/Tizen/JSSimpleCoordinates.h>
28 #include "JSMediacontent.h"
31 #define TIZEN_MEDIACONTENT_VIDEO_ATTRIBUTENAME "Video"
32 #define TIZEN_MEDIACONTENT_VIDEO_GEOLOCATION "geolocation"
33 #define TIZEN_MEDIACONTENT_VIDEO_ALBUM "album"
34 #define TIZEN_MEDIACONTENT_VIDEO_ARTIST "artist"
35 #define TIZEN_MEDIACONTENT_VIDEO_PLAYEDTIME "playedTime"
36 #define TIZEN_MEDIACONTENT_VIDEO_PLAYCOUNT "playCount"
37 #define TIZEN_MEDIACONTENT_VIDEO_DURATION "duration"
38 #define TIZEN_MEDIACONTENT_VIDEO_WIDTH "width"
39 #define TIZEN_MEDIACONTENT_VIDEO_HEIGHT "height"
41 using namespace TizenApis::Tizen1_0::Tizen;
45 namespace Mediacontent {
48 JSClassDefinition JSVideo::m_classInfo =
51 kJSClassAttributeNone,
52 TIZEN_MEDIACONTENT_VIDEO_ATTRIBUTENAME,
53 JSMedia::getClassRef(),
61 NULL, //DeleteProperty,
62 NULL, //GetPropertyNames,
63 NULL, //CallAsFunction,
64 NULL, //CallAsConstructor,
69 JSStaticValue JSVideo::m_property[] =
71 { TIZEN_MEDIACONTENT_VIDEO_GEOLOCATION, getPropertyGeoLocation, NULL, kJSPropertyAttributeReadOnly},
72 { TIZEN_MEDIACONTENT_VIDEO_ALBUM, getPropertyAlbum, NULL, kJSPropertyAttributeReadOnly},
73 { TIZEN_MEDIACONTENT_VIDEO_ARTIST, getPropertyArtist, NULL, kJSPropertyAttributeReadOnly},
74 { TIZEN_MEDIACONTENT_VIDEO_PLAYEDTIME, getPropertyPlayedTime, setPropertyPlayedTime, kJSPropertyAttributeNone},
75 { TIZEN_MEDIACONTENT_VIDEO_PLAYCOUNT, getPropertyPlayCount, setPropertyPlayCount, kJSPropertyAttributeNone},
76 { TIZEN_MEDIACONTENT_VIDEO_DURATION, getPropertyDuration, NULL, kJSPropertyAttributeReadOnly},
77 { TIZEN_MEDIACONTENT_VIDEO_WIDTH, getPropertyWidth, NULL, kJSPropertyAttributeReadOnly},
78 { TIZEN_MEDIACONTENT_VIDEO_HEIGHT, getPropertyHeight, NULL, kJSPropertyAttributeReadOnly},
83 JSClassRef JSVideo::m_jsClassRef = JSClassCreate(JSVideo::getClassInfo());
85 void JSVideo::initialize(JSContextRef context, JSObjectRef object)
87 LogDebug( "entered" );
88 VideoPrivObject *priv = static_cast<VideoPrivObject*>( JSObjectGetPrivate( object ) );
91 MediacontentVideoPtr privateData(new MediacontentVideo());
92 priv = new VideoPrivObject(context, privateData);
93 JSObjectSetPrivate(object, static_cast<void*>(priv));
94 LogDebug("new event is created" );
97 LogDebug("private object already exists");
101 void JSVideo::finalize(JSObjectRef object)
103 LogDebug( "entered" );
104 VideoPrivObject *priv = static_cast<VideoPrivObject*>( JSObjectGetPrivate( object ) ) ;
108 const JSClassRef JSVideo::getClassRef()
110 LogDebug("JSVideo::getClassRef()");
114 m_jsClassRef = JSClassCreate(&m_classInfo);
119 const JSClassDefinition* JSVideo::getClassInfo()
125 MediacontentVideoPtr JSVideo::getVideoObject(JSObjectRef object)
128 VideoPrivObject *priv = static_cast<VideoPrivObject*>(JSObjectGetPrivate(object));
131 ThrowMsg(NullPointerException, "Private object is null");
133 MediacontentVideoPtr result = priv->getObject();
136 ThrowMsg(NullPointerException, "Private object is null");
142 JSValueRef JSVideo::getPropertyGeoLocation(
143 JSContextRef context,
145 JSStringRef propertyName,
146 JSValueRef* exception)
151 Converter converter(context);
152 MediacontentVideoPtr event = getVideoObject(object);
153 SimpleCoordinatesPtr geoPtr(new SimpleCoordinates(event->getVideoLatitude(),event->getVideoLongitude()));
154 return JSSimpleCoordinates::createJSObject(context,geoPtr);
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);