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"
36 JSClassDefinition JSMediaLyrics::m_classInfo =
39 kJSClassAttributeNone,
40 TIZEN_MEDIACONTENT_MEDIA_LYRICS,
49 NULL, //DeleteProperty,
50 NULL, //GetPropertyNames,
51 NULL, //CallAsFunction,
52 NULL, //CallAsConstructor,
57 JSStaticValue JSMediaLyrics::m_property[] =
60 { TIZEN_MEDIACONTENT_LYRICS_TYPE, getPropertyLyricsType, NULL, kJSPropertyAttributeReadOnly},
61 { TIZEN_MEDIACONTENT_LYRICS_TIMESTAMP, getPropertyTimeStamps, NULL, kJSPropertyAttributeReadOnly},
62 { TIZEN_MEDIACONTENT_LYRICS_TEXT, getPropertyTexts, NULL, kJSPropertyAttributeReadOnly},
67 JSClassRef JSMediaLyrics::m_jsClassRef = JSClassCreate(JSMediaLyrics::getClassInfo());
69 void JSMediaLyrics::initialize(JSContextRef context, JSObjectRef object)
71 LogDebug( "entered" );
72 LyricsPrivObject *priv = static_cast<LyricsPrivObject*>( JSObjectGetPrivate( object ) );
75 MediacontentLyricsPtr privateData(new MediacontentLyrics());
76 priv = new LyricsPrivObject(context, privateData);
77 JSObjectSetPrivate(object, static_cast<void*>(priv));
78 LogDebug("private object is created");
82 LogDebug("private object already exists");
86 void JSMediaLyrics::finalize(JSObjectRef object)
88 LogDebug( "entered" );
89 LyricsPrivObject *priv = static_cast<LyricsPrivObject*>( JSObjectGetPrivate( object ) ) ;
93 const JSClassRef JSMediaLyrics::getClassRef()
95 LogDebug("JSMediaLyrics::getClassRef()");
98 m_jsClassRef = JSClassCreate(&m_classInfo);
103 const JSClassDefinition* JSMediaLyrics::getClassInfo()
108 MediacontentLyricsPtr JSMediaLyrics::getLyricsObject(JSObjectRef object)
111 LyricsPrivObject *priv = static_cast<LyricsPrivObject*>(JSObjectGetPrivate(object));
114 ThrowMsg(NullPointerException, "Private object is null");
116 MediacontentLyricsPtr result = priv->getObject();
119 ThrowMsg(NullPointerException, "Private object is null");
125 JSValueRef JSMediaLyrics::getPropertyLyricsType(
126 JSContextRef context,
128 JSStringRef propertyName,
129 JSValueRef* exception)
134 Converter converter(context);
136 MediacontentLyricsPtr lyrics = getLyricsObject(object);
138 return converter.toJSValueRef(lyrics->getMediaLyricsType());
142 LogWarning("trying to get incorrect value");
145 return JSValueMakeUndefined(context);
149 JSValueRef JSMediaLyrics::getPropertyTimeStamps(
150 JSContextRef context,
152 JSStringRef propertyName,
153 JSValueRef* exception)
158 Converter converter(context);
159 MediacontentLyricsPtr lyrics = getLyricsObject(object);
161 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
162 vector<unsigned long> timeStamps = lyrics->getMediaLyricsTimeStamps();
163 if(timeStamps.size() > 0)
165 if (NULL == jsResult)
167 ThrowMsg(NullPointerException, "Could not create js array object");
169 for(unsigned int i=0; i<timeStamps.size(); i++)
171 JSValueRef val = converter.toJSValueRef(timeStamps.at(i));
172 if(!JSSetArrayElement(context, jsResult, i, val))
174 ThrowMsg(UnknownException, "Could not insert value into js array");
183 LogWarning("trying to get incorrect value");
186 return JSValueMakeUndefined(context);
190 JSValueRef JSMediaLyrics::getPropertyTexts(
191 JSContextRef context,
193 JSStringRef propertyName,
194 JSValueRef* exception)
199 Converter converter(context);
200 MediacontentLyricsPtr lyrics = getLyricsObject(object);
201 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
202 vector<string> texts = lyrics->getMediaLyricsTexts();
205 if (NULL == jsResult)
207 ThrowMsg(NullPointerException, "Could not create js array object");
209 for(unsigned int i=0; i<texts.size(); i++)
211 JSValueRef val = converter.toJSValueRef(texts.at(i));
212 if(!JSSetArrayElement(context, jsResult, i, val))
214 ThrowMsg(UnknownException, "Could not insert value into js array");
223 LogWarning("trying to get incorrect value");
226 return JSValueMakeUndefined(context);