2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 #include <SecurityExceptions.h>
21 #include <JSWebAPIError.h>
22 #include <ArgumentValidator.h>
23 #include <GlobalContextManager.h>
24 #include <MultiCallbackUserData.h>
25 #include <PlatformException.h>
27 #include "plugin_config.h"
29 #include "JSAudioContentLyrics.h"
31 using namespace WrtDeviceApis::Commons;
36 using namespace DeviceAPI::Common;
39 AudioContentLyricsPtr ptr;
42 JSClassDefinition JSAudioContentLyrics::m_classInfo = {
44 kJSClassAttributeNone,
47 m_property, //StaticValues
48 NULL, //StaticFunctions
49 initialize, //Initialize
54 NULL, //DeleteProperty,
55 NULL, //GetPropertyNames,
56 NULL, //CallAsFunction,
57 NULL, //CallAsConstructor,
62 JSStaticValue JSAudioContentLyrics::m_property[] = {
63 { AUDIO_CONTENT_LYRICS_TYPE, getType, NULL, kJSPropertyAttributeReadOnly },
64 { AUDIO_CONTENT_LYRICS_TIMESTAMPS, getTimestamps, NULL, kJSPropertyAttributeReadOnly },
65 { AUDIO_CONTENT_LYRICS_TEXTS, getTexts, NULL, kJSPropertyAttributeReadOnly },
69 JSClassRef JSAudioContentLyrics::m_jsClassRef = JSClassCreate(JSAudioContentLyrics::getClassInfo());
71 const JSClassRef JSAudioContentLyrics::getClassRef()
74 m_jsClassRef = JSClassCreate(&m_classInfo);
79 const JSClassDefinition* JSAudioContentLyrics::getClassInfo()
84 void JSAudioContentLyrics::initialize(JSContextRef context, JSObjectRef object)
89 void JSAudioContentLyrics::finalize(JSObjectRef object)
92 LyricsHolder* priv = static_cast<LyricsHolder*>(JSObjectGetPrivate(object));
94 JSObjectSetPrivate(object, NULL);
100 JSValueRef JSAudioContentLyrics::CreateJSObject(JSContextRef context,
101 AudioContentLyricsPtr native)
103 JSObjectRef obj = JSObjectMake(context, getClassRef(), NULL);
106 LOGE("AudioContentLyrics private object is NULL.");
107 throw TypeMismatchException("AudioContentLyrics private object is NULL.");
110 LyricsHolder* priv = new(std::nothrow) LyricsHolder;
112 LOGE("Can not be allocated memory");
113 throw UnknownException("Can not be allocated memory");
117 JSObjectSetPrivate(obj, static_cast<void*>(priv));
121 AudioContentLyricsPtr JSAudioContentLyrics::getPrivateObject(JSContextRef context,
124 if (!JSValueIsObjectOfClass(context, object, getClassRef())) {
125 LOGE("TypeMismatch");
126 throw TypeMismatchException("TypeMismatch");
129 LyricsHolder* priv = static_cast<LyricsHolder*>(JSObjectGetPrivate(object));
131 LOGE("Priv is null");
132 throw UnknownException("Priv is null");
136 LOGE("Native is null");
137 throw UnknownException("Native is null");
140 return std::static_pointer_cast<AudioContentLyrics>(priv->ptr);
143 void JSAudioContentLyrics::setPrivateObject(JSObjectRef object,
144 AudioContentLyricsPtr native)
146 LyricsHolder* priv = static_cast<LyricsHolder*>(JSObjectGetPrivate(object));
148 LOGE("AudioContentLyrics private object is NULL.");
149 throw TypeMismatchException("AudioContentLyrics private object is NULL.");
154 JSValueRef JSAudioContentLyrics::getType(JSContextRef context,
156 JSStringRef propertyName,
157 JSValueRef* exception)
161 AudioContentLyricsPtr priv = JSAudioContentLyrics::getPrivateObject(context, object);
162 return JSUtil::toJSValueRef(context, priv->getType());
164 catch (const BasePlatformException &error) {
165 LOGE("Attribute get failed: %s", error.getMessage().c_str());
168 LOGE("Attribute get failed");
170 return JSValueMakeUndefined(context);
173 JSValueRef JSAudioContentLyrics::getTimestamps(JSContextRef context,
175 JSStringRef propertyName,
176 JSValueRef* exception)
180 AudioContentLyricsPtr priv = JSAudioContentLyrics::getPrivateObject(context, object);
181 if ("UNSYNCHRONIZED" != priv->getType()) {
182 return JSUtil::toJSValueRef_(context, priv->getTimestamps());
185 catch (const BasePlatformException &error) {
186 LOGE("Attribute get failed: %s", error.getMessage().c_str());
189 LOGE("Attribute get failed");
191 return JSValueMakeUndefined(context);
194 JSValueRef JSAudioContentLyrics::getTexts(JSContextRef context,
196 JSStringRef propertyName,
197 JSValueRef* exception)
201 AudioContentLyricsPtr priv = JSAudioContentLyrics::getPrivateObject(context, object);
202 return JSUtil::toJSValueRef(context, priv->getTexts());
204 catch (const BasePlatformException &error) {
205 LOGE("Attribute get failed: %s", error.getMessage().c_str());
208 LOGE("Attribute get failed");
210 return JSValueMakeUndefined(context);