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.
19 #include <dpl/log/log.h>
20 #include <CommonsJavaScript/PrivateObject.h>
21 #include <CommonsJavaScript/Converter.h>
22 #include <CommonsJavaScript/JSUtils.h>
23 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
25 #include <API/Mediacontent/IMediacontent.h>
26 #include <API/Mediacontent/MediacontentFactory.h>
27 //#include <API/Mediacontent/IEventFolderFindMedia.h>
30 #include "MediacontentController.h"
31 #include "JSMediacontent.h"
37 namespace Mediacontent {
39 #define TIZEN_MEDIACONTENT_FOLDER_ATTRIBUTENAME "Folder"
40 #define TIZEN_MEDIACONTENT_FOLDER_UID "id"
41 #define TIZEN_MEDIACONTENT_FOLDER_NAME "title"
42 #define TIZEN_MEDIACONTENT_FOLDER_PATH "folderURI"
43 #define TIZEN_MEDIACONTENT_FOLDER_STORAGE_TYPE "storageType"
44 #define TIZEN_MEDIACONTENT_FOLDER_MODIFIEDDATE "modifiedDate"
47 JSClassDefinition JSFolder::m_classInfo =
50 kJSClassAttributeNone,
51 TIZEN_MEDIACONTENT_FOLDER_ATTRIBUTENAME,
54 m_function, // m_function,
60 NULL, //DeleteProperty,
61 NULL, //GetPropertyNames,
62 NULL, //CallAsFunction,
63 NULL, //CallAsConstructor,
68 JSStaticValue JSFolder::m_property[] =
71 { TIZEN_MEDIACONTENT_FOLDER_UID, getPropertyId, NULL, kJSPropertyAttributeReadOnly},
72 { TIZEN_MEDIACONTENT_FOLDER_NAME, getPropertyName, NULL, kJSPropertyAttributeReadOnly},
73 { TIZEN_MEDIACONTENT_FOLDER_PATH, getPropertyPath, NULL, kJSPropertyAttributeReadOnly},
74 { TIZEN_MEDIACONTENT_FOLDER_STORAGE_TYPE, getPropertyStorageType, NULL, kJSPropertyAttributeReadOnly},
75 { TIZEN_MEDIACONTENT_FOLDER_MODIFIEDDATE, getPropertyModifiedDate, NULL, kJSPropertyAttributeReadOnly},
79 JSStaticFunction JSFolder::m_function[] =
85 JSClassRef JSFolder::m_jsClassRef = JSClassCreate(JSFolder::getClassInfo());
87 void JSFolder::initialize(JSContextRef context, JSObjectRef object)
89 LogDebug( "entered" );
90 FolderPrivObject *priv = static_cast<FolderPrivObject*>( JSObjectGetPrivate( object ) );
93 MediacontentFolderPtr privateData(new MediacontentFolder());
94 priv = new FolderPrivObject(context, privateData);
95 JSObjectSetPrivate(object, static_cast<void*>(priv));
96 LogDebug("new event is created" );
100 LogDebug("private object already exists");
105 void JSFolder::finalize(JSObjectRef object)
107 LogDebug( "entered" );
108 FolderPrivObject *priv = static_cast<FolderPrivObject*>( JSObjectGetPrivate( object ) ) ;
114 const JSClassRef JSFolder::getClassRef()
118 m_jsClassRef = JSClassCreate(&m_classInfo);
123 const JSClassDefinition* JSFolder::getClassInfo()
129 MediacontentFolderPtr JSFolder::getFolderObject(JSObjectRef object)
132 FolderPrivObject *priv = static_cast<FolderPrivObject*>(JSObjectGetPrivate(object));
134 ThrowMsg(NullPointerException, "Private object is null");
136 MediacontentFolderPtr result = priv->getObject();
138 ThrowMsg(NullPointerException, "Private object is null");
145 JSValueRef JSFolder::getPropertyId(
146 JSContextRef context,
148 JSStringRef propertyName,
149 JSValueRef* exception)
154 Converter converter(context);
155 MediacontentFolderPtr folder = getFolderObject(object);
157 return converter.toJSValueRef(folder->getFolderUUID());
161 LogWarning("trying to get incorrect value");
163 return JSValueMakeUndefined(context);
167 JSValueRef JSFolder::getPropertyName(
168 JSContextRef context,
170 JSStringRef propertyName,
171 JSValueRef* exception)
176 Converter converter(context);
177 MediacontentFolderPtr folder = getFolderObject(object);
178 return converter.toJSValueRef(folder->getFolderName());
182 LogWarning("trying to get incorrect value");
184 return JSValueMakeUndefined(context);
188 JSValueRef JSFolder::getPropertyPath(
189 JSContextRef context,
191 JSStringRef propertyName,
192 JSValueRef* exception)
194 LogDebug("getPropertyPath::entered");
197 Converter converter(context);
198 MediacontentFolderPtr folder = getFolderObject(object);
199 return converter.toJSValueRef(folder->getFolderPath());
203 LogWarning("trying to get incorrect value");
205 return JSValueMakeUndefined(context);
209 JSValueRef JSFolder::getPropertyStorageType(
210 JSContextRef context,
212 JSStringRef propertyName,
213 JSValueRef* exception)
218 Converter converter(context);
219 MediacontentFolderPtr folder = getFolderObject(object);
220 return converter.toJSValueRef(folder->getFolderStorageType());
224 LogWarning("trying to get incorrect value");
226 return JSValueMakeUndefined(context);
230 JSValueRef JSFolder::getPropertyModifiedDate(
231 JSContextRef context,
233 JSStringRef propertyName,
234 JSValueRef* exception)
239 Converter converter(context);
240 MediacontentFolderPtr folder = getFolderObject(object);
241 return converter.toJSValueRef(folder->getFolderModifiedDate());
245 LogWarning("trying to get incorrect value");
247 return JSValueMakeUndefined(context);
251 JSValueRef JSFolder::getPropertyMediaId(
252 JSContextRef context,
254 JSStringRef propertyName,
255 JSValueRef* exception)
260 Converter converter(context);
261 MediacontentFolderPtr folder = getFolderObject(object);
262 //folder->getMediaIdList()
263 //MediaIdListPtr getMediaIdList() const;
264 //typedef vector<std::string> MediaIdList;
265 //typedef DPL::SharedPtr<MediaIdList> MediaIdListPtr;
266 MediaIdListPtr mediaIdLstPtr = folder->getMediaIdList();
267 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
271 if (NULL == jsResult)
273 ThrowMsg(NullPointerException, "Could not create js array object");
275 for(unsigned int i=0; i<mediaIdLstPtr->size(); i++)
277 JSValueRef val = converter.toJSValueRef(mediaIdLstPtr->at(i));
278 if(!JSSetArrayElement(context, jsResult, i, val))
280 ThrowMsg(UnknownException, "Could not insert value into js array");
288 LogWarning("trying to get incorrect value");
290 return JSValueMakeUndefined(context);