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/JSUtils.h>
20 #include <CommonsJavaScript/Validator.h>
21 #include <CommonsJavaScript/ScopedJSStringRef.h>
23 #include "MediaConverter.h"
29 #include "JSMediacontent.h"
30 #include "JSMediaLyrics.h"
36 namespace Mediacontent {
38 MediaConverter::MediaConverter(JSContextRef context) : Converter(context)
43 JSValueRef MediaConverter::toFunctionOrNull(const JSValueRef& arg)
45 if (Validator(m_context).isCallback(arg))
48 } else if (!JSValueIsNull(m_context,arg) && !JSValueIsUndefined(m_context, arg))
50 ThrowMsg(ConversionException, "Not a function nor JS null.");
55 JSValueRef MediaConverter::toFunction(const JSValueRef& arg)
57 if (Validator(m_context).isCallback(arg))
60 } else if (JSValueIsNull(m_context,arg) || JSValueIsUndefined(m_context, arg))
62 ThrowMsg(InvalidArgumentException, "JS null passed as function.");
64 ThrowMsg(ConversionException, "Not a function nor JS null.");
67 JSValueRef MediaConverter::toJSValueRefMediacontent(const IMediacontentPtr& arg)
69 MediacontentPrivObject *priv = new MediacontentPrivObject(m_context, arg);
70 return JSObjectMake(m_context, JSMediacontent::getClassRef(), priv);
74 JSValueRef MediaConverter::toJSValueRefMedia(const MediacontentMediaPtr& arg)
76 if(arg->getMediaType() == "IMAGE")
78 return JSUtils::makeObject(m_context, JSImage::getClassRef(), arg);
80 if(arg->getMediaType() == "VIDEO")
82 return JSUtils::makeObject(m_context, JSVideo::getClassRef(), arg);
84 if(arg->getMediaType() == "AUDIO")
86 return JSUtils::makeObject(m_context, JSAudio::getClassRef(), arg);
88 return JSUtils::makeObject(m_context, JSMedia::getClassRef(), arg);
91 JSValueRef MediaConverter::toJSValueRefFolder(const MediacontentFolderPtr& arg)
93 return JSUtils::makeObject(m_context, JSFolder::getClassRef(), arg);
96 JSValueRef MediaConverter::toJSValueRef(const std::vector<MediacontentMediaPtr> &arg)
98 return toJSValueRef_(arg, &MediaConverter::toJSValueRefMedia, this);
101 JSValueRef MediaConverter::toJSValueRef(const std::vector<MediacontentFolderPtr> &arg)
103 return toJSValueRef_(arg, &MediaConverter::toJSValueRefFolder, this);
106 JSValueRef MediaConverter::toJSValueRef(const MediacontentLyricsPtr &arg)
108 return JSUtils::makeObject(m_context, JSMediaLyrics::getClassRef(), arg);