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 <CommonsJavaScript/JSDOMExceptionFactory.h>
24 #include "JSMediacontent.h"
25 #include "JSMediaLyrics.h"
29 namespace Mediacontent {
31 #define TIZEN_MEDIACONTENT_MEDIA_LYRICS "MediaLyrics"
32 #define TIZEN_MEDIACONTENT_LYRICS_TYPE "type"
33 #define TIZEN_MEDIACONTENT_LYRICS_TIMESTAMP "timeStamps"
34 #define TIZEN_MEDIACONTENT_LYRICS_TEXT "texts"
41 JSClassDefinition JSMediaLyrics::m_classInfo =
44 kJSClassAttributeNone,
45 TIZEN_MEDIACONTENT_MEDIA_LYRICS,
54 NULL, //DeleteProperty,
55 NULL, //GetPropertyNames,
56 NULL, //CallAsFunction,
57 NULL, //CallAsConstructor,
62 JSStaticValue JSMediaLyrics::m_property[] =
65 { TIZEN_MEDIACONTENT_LYRICS_TYPE, getPropertyLyricsType, NULL, kJSPropertyAttributeReadOnly},
66 { TIZEN_MEDIACONTENT_LYRICS_TIMESTAMP, getPropertyTimeStamps, NULL, kJSPropertyAttributeReadOnly},
67 { TIZEN_MEDIACONTENT_LYRICS_TEXT, getPropertyTexts, NULL, kJSPropertyAttributeReadOnly},
72 JSClassRef JSMediaLyrics::m_jsClassRef = JSClassCreate(JSMediaLyrics::getClassInfo());
74 void JSMediaLyrics::initialize(JSContextRef context, JSObjectRef object)
76 LogDebug( "entered" );
77 LyricsPrivObject *priv = static_cast<LyricsPrivObject*>( JSObjectGetPrivate( object ) );
80 MediacontentLyricsPtr privateData(new MediacontentLyrics());
81 priv = new LyricsPrivObject(context, privateData);
82 JSObjectSetPrivate(object, static_cast<void*>(priv));
83 LogDebug("private object is created");
87 LogDebug("private object already exists");
91 void JSMediaLyrics::finalize(JSObjectRef object)
93 LogDebug( "entered" );
94 LyricsPrivObject *priv = static_cast<LyricsPrivObject*>( JSObjectGetPrivate( object ) ) ;
98 const JSClassRef JSMediaLyrics::getClassRef()
100 LogDebug("JSMediaLyrics::getClassRef()");
103 m_jsClassRef = JSClassCreate(&m_classInfo);
108 const JSClassDefinition* JSMediaLyrics::getClassInfo()
113 MediacontentLyricsPtr JSMediaLyrics::getLyricsObject(JSObjectRef object)
116 LyricsPrivObject *priv = static_cast<LyricsPrivObject*>(JSObjectGetPrivate(object));
119 ThrowMsg(NullPointerException, "Private object is null");
121 MediacontentLyricsPtr result = priv->getObject();
124 ThrowMsg(NullPointerException, "Private object is null");
130 JSValueRef JSMediaLyrics::getPropertyLyricsType(
131 JSContextRef context,
133 JSStringRef propertyName,
134 JSValueRef* exception)
139 Converter converter(context);
141 MediacontentLyricsPtr lyrics = getLyricsObject(object);
143 return converter.toJSValueRef(lyrics->getMediaLyricsType());
147 LogWarning("trying to get incorrect value");
150 return JSValueMakeUndefined(context);
154 JSValueRef JSMediaLyrics::getPropertyTimeStamps(
155 JSContextRef context,
157 JSStringRef propertyName,
158 JSValueRef* exception)
163 Converter converter(context);
164 MediacontentLyricsPtr lyrics = getLyricsObject(object);
166 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
167 vector<unsigned long> timeStamps = lyrics->getMediaLyricsTimeStamps();
168 if(timeStamps.size() > 0)
170 if (NULL == jsResult)
172 ThrowMsg(NullPointerException, "Could not create js array object");
174 for(unsigned int i=0; i<timeStamps.size(); i++)
176 JSValueRef val = converter.toJSValueRef(timeStamps.at(i));
177 if(!JSSetArrayElement(context, jsResult, i, val))
179 ThrowMsg(UnknownException, "Could not insert value into js array");
188 LogWarning("trying to get incorrect value");
191 return JSValueMakeUndefined(context);
195 JSValueRef JSMediaLyrics::getPropertyTexts(
196 JSContextRef context,
198 JSStringRef propertyName,
199 JSValueRef* exception)
204 Converter converter(context);
205 MediacontentLyricsPtr lyrics = getLyricsObject(object);
206 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
207 vector<string> texts = lyrics->getMediaLyricsTexts();
210 if (NULL == jsResult)
212 ThrowMsg(NullPointerException, "Could not create js array object");
214 for(unsigned int i=0; i<texts.size(); i++)
216 JSValueRef val = converter.toJSValueRef(texts.at(i));
217 if(!JSSetArrayElement(context, jsResult, i, val))
219 ThrowMsg(UnknownException, "Could not insert value into js array");
228 LogWarning("trying to get incorrect value");
231 return JSValueMakeUndefined(context);