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.
18 #include <dpl/log/log.h>
19 #include <CommonsJavaScript/PrivateObject.h>
20 #include <CommonsJavaScript/Converter.h>
21 #include <CommonsJavaScript/JSUtils.h>
22 #include <Tizen/Common/JSTizenException.h>
23 #include <Tizen/Common/JSTizenExceptionFactory.h>
25 #include "JSMediacontent.h"
27 #include "MediaConverter.h"
30 #define TIZEN_MEDIACONTENT_AUDIO_ATTRIBUTENAME "Audio"
31 #define TIZEN_MEDIACONTENT_AUDIO_ALBUM "album"
32 #define TIZEN_MEDIACONTENT_AUDIO_GENRE "genres"
33 #define TIZEN_MEDIACONTENT_AUDIO_ARTIST "artists"
34 #define TIZEN_MEDIACONTENT_AUDIO_COMPOSER "composers"
35 #define TIZEN_MEDIACONTENT_AUDIO_LYIRICS "lyrics"
36 #define TIZEN_MEDIACONTENT_AUDIO_COPYRIGHT "copyright"
37 #define TIZEN_MEDIACONTENT_AUDIO_BITRATE "bitrate"
38 #define TIZEN_MEDIACONTENT_AUDIO_TRACKNUM "trackNumber"
39 #define TIZEN_MEDIACONTENT_AUDIO_DURATION "duration"
40 #define TIZEN_MEDIACONTENT_AUDIO_PLAYEDCOUNT "playedCount"
41 #define TIZEN_MEDIACONTENT_AUDIO_PLAYEDTIME "playedTime"
42 #define TIZEN_MEDIACONTENT_AUDIO_SIZE "size"
44 using namespace WrtDeviceApis::Commons;
45 using namespace WrtDeviceApis::CommonsJavaScript;
46 using namespace TizenApis::Api::Mediacontent;
50 namespace Mediacontent {
52 JSClassDefinition JSAudio::m_classInfo =
55 kJSClassAttributeNone,
56 TIZEN_MEDIACONTENT_AUDIO_ATTRIBUTENAME,
57 JSMedia::getClassRef(),
65 NULL, //DeleteProperty,
66 NULL, //GetPropertyNames,
67 NULL, //CallAsFunction,
68 NULL, //CallAsConstructor,
73 JSStaticValue JSAudio::m_property[] =
75 { TIZEN_MEDIACONTENT_AUDIO_ALBUM, getPropertyAlbum, NULL, kJSPropertyAttributeReadOnly},
76 { TIZEN_MEDIACONTENT_AUDIO_ARTIST, getPropertyArtist, NULL, kJSPropertyAttributeReadOnly},
77 { TIZEN_MEDIACONTENT_AUDIO_GENRE, getPropertyGenre, NULL, kJSPropertyAttributeReadOnly},
78 { TIZEN_MEDIACONTENT_AUDIO_COMPOSER , getPropertyComposer, NULL, kJSPropertyAttributeReadOnly},
79 { TIZEN_MEDIACONTENT_AUDIO_COPYRIGHT, getPropertyCopyright, NULL, kJSPropertyAttributeReadOnly},
80 { TIZEN_MEDIACONTENT_AUDIO_LYIRICS, getPropertyLyrics, NULL, kJSPropertyAttributeReadOnly},
81 { TIZEN_MEDIACONTENT_AUDIO_BITRATE, getPropertyBitrate, NULL, kJSPropertyAttributeReadOnly},
82 { TIZEN_MEDIACONTENT_AUDIO_TRACKNUM, getPropertyTrackNum, NULL, kJSPropertyAttributeReadOnly},
83 { TIZEN_MEDIACONTENT_AUDIO_DURATION, getPropertyDuration, NULL, kJSPropertyAttributeReadOnly},
84 { TIZEN_MEDIACONTENT_AUDIO_PLAYEDCOUNT, getPropertyPlayedCount, setPropertyPlayCount, kJSPropertyAttributeNone},
85 { TIZEN_MEDIACONTENT_AUDIO_PLAYEDTIME, getPropertyPlayedTime, setPropertyPlayedTime, kJSPropertyAttributeNone},
86 { TIZEN_MEDIACONTENT_AUDIO_SIZE, getPropertySize, NULL, kJSPropertyAttributeReadOnly},
91 JSClassRef JSAudio::m_jsClassRef = JSClassCreate(JSAudio::getClassInfo());
93 void JSAudio::initialize(JSContextRef context, JSObjectRef object)
95 LogDebug( "entered" );
96 AudioPrivObject *priv = static_cast<AudioPrivObject*>( JSObjectGetPrivate( object ) );
99 MediacontentAudioPtr privateData(new MediacontentAudio());
100 priv = new AudioPrivObject(context, privateData);
101 JSObjectSetPrivate(object, static_cast<void*>(priv));
102 LogDebug("new event is created" );
105 LogDebug("private object already exists");
109 void JSAudio::finalize(JSObjectRef object)
111 LogDebug( "entered" );
112 AudioPrivObject *priv = static_cast<AudioPrivObject*>( JSObjectGetPrivate( object ) ) ;
116 const JSClassRef JSAudio::getClassRef()
118 LogDebug("JSAudio::getClassRef()");
122 m_jsClassRef = JSClassCreate(&m_classInfo);
127 const JSClassDefinition* JSAudio::getClassInfo()
133 MediacontentAudioPtr JSAudio::getAudioObject(JSObjectRef object)
136 AudioPrivObject *priv = static_cast<AudioPrivObject*>(JSObjectGetPrivate(object));
139 ThrowMsg(NullPointerException, "Private object is null");
141 MediacontentAudioPtr result = priv->getObject();
144 ThrowMsg(NullPointerException, "Private object is null");
149 JSValueRef JSAudio::getPropertyAlbum(
150 JSContextRef context,
152 JSStringRef propertyName,
153 JSValueRef* exception)
158 Converter converter(context);
159 MediacontentAudioPtr event = getAudioObject(object);
160 return converter.toJSValueRef(event->getAudioAlbum());
164 LogWarning("trying to get incorrect value");
166 return JSValueMakeUndefined(context);
171 JSValueRef JSAudio::getPropertyArtist(
172 JSContextRef context,
174 JSStringRef propertyName,
175 JSValueRef* exception)
180 Converter converter(context);
181 MediacontentAudioPtr event = getAudioObject(object);
182 return converter.toJSValueRef(event->getAudioArtist());
186 LogWarning("trying to get incorrect value");
188 return JSValueMakeUndefined(context);
193 JSValueRef JSAudio::getPropertyGenre(
194 JSContextRef context,
196 JSStringRef propertyName,
197 JSValueRef* exception)
202 Converter converter(context);
203 MediacontentAudioPtr event = getAudioObject(object);
204 return converter.toJSValueRef(event->getAudioGenre());
208 LogWarning("trying to get incorrect value");
210 return JSValueMakeUndefined(context);
214 JSValueRef JSAudio::getPropertyComposer(
215 JSContextRef context,
217 JSStringRef propertyName,
218 JSValueRef* exception)
223 Converter converter(context);
224 MediacontentAudioPtr event = getAudioObject(object);
225 return converter.toJSValueRef(event->getAudioComposer());
229 LogWarning("trying to get incorrect value");
231 return JSValueMakeUndefined(context);
234 JSValueRef JSAudio::getPropertyCopyright(
235 JSContextRef context,
237 JSStringRef propertyName,
238 JSValueRef* exception)
243 Converter converter(context);
244 MediacontentAudioPtr event = getAudioObject(object);
245 return converter.toJSValueRef(event->getAudioCopyright());
249 LogWarning("trying to get incorrect value");
251 return JSValueMakeUndefined(context);
254 JSValueRef JSAudio::getPropertyLyrics(
255 JSContextRef context,
257 JSStringRef propertyName,
258 JSValueRef* exception)
263 MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
264 //MediaConverter converter(globalContext);
266 MediacontentAudioPtr event = getAudioObject(object);
268 return converter->toJSValueRef(event->getAudioLyrics());
272 LogWarning("trying to get incorrect value");
274 return JSValueMakeUndefined(context);
277 JSValueRef JSAudio::getPropertyBitrate(
278 JSContextRef context,
280 JSStringRef propertyName,
281 JSValueRef* exception)
286 Converter converter(context);
287 MediacontentAudioPtr event = getAudioObject(object);
288 return converter.toJSValueRef(event->getAudioBitrate());
292 LogWarning("trying to get incorrect value");
294 return JSValueMakeUndefined(context);
297 JSValueRef JSAudio::getPropertyTrackNum(
298 JSContextRef context,
300 JSStringRef propertyName,
301 JSValueRef* exception)
306 Converter converter(context);
307 MediacontentAudioPtr event = getAudioObject(object);
308 return converter.toJSValueRef(event->getAudioTrackNum());
312 LogWarning("trying to get incorrect value");
314 return JSValueMakeUndefined(context);
317 JSValueRef JSAudio::getPropertyDuration(
318 JSContextRef context,
320 JSStringRef propertyName,
321 JSValueRef* exception)
326 Converter converter(context);
327 MediacontentAudioPtr event = getAudioObject(object);
328 return converter.toJSValueRef(event->getAudioDuration());
332 LogWarning("trying to get incorrect value");
334 return JSValueMakeUndefined(context);
338 JSValueRef JSAudio::getPropertyPlayedCount(
339 JSContextRef context,
341 JSStringRef propertyName,
342 JSValueRef* exception)
347 Converter converter(context);
348 MediacontentAudioPtr event = getAudioObject(object);
349 return converter.toJSValueRef(event->getAudioPlayCount());
353 LogWarning("trying to get incorrect value");
355 return JSValueMakeUndefined(context);
360 JSValueRef JSAudio::getPropertyPlayedTime(
361 JSContextRef context,
363 JSStringRef propertyName,
364 JSValueRef* exception)
369 Converter converter(context);
370 MediacontentAudioPtr event = getAudioObject(object);
371 return converter.toJSValueRef(event->getAudioPlayedTime());
375 LogWarning("trying to get incorrect value");
377 return JSValueMakeUndefined(context);
380 JSValueRef JSAudio::getPropertySize(
381 JSContextRef context,
383 JSStringRef propertyName,
384 JSValueRef* exception)
389 Converter converter(context);
390 MediacontentAudioPtr event = getAudioObject(object);
391 return converter.toJSValueRef(event->getAudioSize());
395 LogWarning("trying to get incorrect value");
397 return JSValueMakeUndefined(context);
402 bool JSAudio::setPropertyPlayedTime(
403 JSContextRef context,
405 JSStringRef propertyName,
407 JSValueRef* exception)
412 Converter converter(context);
413 MediacontentAudioPtr event = getAudioObject(object);
414 int rating = converter.toLong(value);
415 event->setAudioPlayedTime(rating);
420 LogWarning("trying to set incorrect value");
421 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
428 bool JSAudio::setPropertyPlayCount(
429 JSContextRef context,
431 JSStringRef propertyName,
433 JSValueRef* exception)
438 Converter converter(context);
439 MediacontentAudioPtr event = getAudioObject(object);
440 int rating = converter.toInt(value);
441 event->setAudioPlayCount(rating);
446 LogWarning("trying to set incorrect value");
447 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);