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 ) ) ;
113 JSObjectSetPrivate(object, NULL);
120 const JSClassRef JSFolder::getClassRef()
124 m_jsClassRef = JSClassCreate(&m_classInfo);
129 const JSClassDefinition* JSFolder::getClassInfo()
135 MediacontentFolderPtr JSFolder::getFolderObject(JSObjectRef object)
138 FolderPrivObject *priv = static_cast<FolderPrivObject*>(JSObjectGetPrivate(object));
140 ThrowMsg(NullPointerException, "Private object is null");
142 MediacontentFolderPtr result = priv->getObject();
144 ThrowMsg(NullPointerException, "Private object is null");
151 JSValueRef JSFolder::getPropertyId(
152 JSContextRef context,
154 JSStringRef propertyName,
155 JSValueRef* exception)
160 Converter converter(context);
161 MediacontentFolderPtr folder = getFolderObject(object);
163 return converter.toJSValueRef(folder->getFolderUUID());
167 LogWarning("trying to get incorrect value");
169 return JSValueMakeUndefined(context);
173 JSValueRef JSFolder::getPropertyName(
174 JSContextRef context,
176 JSStringRef propertyName,
177 JSValueRef* exception)
182 Converter converter(context);
183 MediacontentFolderPtr folder = getFolderObject(object);
184 return converter.toJSValueRef(folder->getFolderName());
188 LogWarning("trying to get incorrect value");
190 return JSValueMakeUndefined(context);
194 JSValueRef JSFolder::getPropertyPath(
195 JSContextRef context,
197 JSStringRef propertyName,
198 JSValueRef* exception)
200 LogDebug("getPropertyPath::entered");
203 Converter converter(context);
204 MediacontentFolderPtr folder = getFolderObject(object);
205 return converter.toJSValueRef(folder->getFolderPath());
209 LogWarning("trying to get incorrect value");
211 return JSValueMakeUndefined(context);
215 JSValueRef JSFolder::getPropertyStorageType(
216 JSContextRef context,
218 JSStringRef propertyName,
219 JSValueRef* exception)
224 Converter converter(context);
225 MediacontentFolderPtr folder = getFolderObject(object);
226 return converter.toJSValueRef(folder->getFolderStorageType());
230 LogWarning("trying to get incorrect value");
232 return JSValueMakeUndefined(context);
236 JSValueRef JSFolder::getPropertyModifiedDate(
237 JSContextRef context,
239 JSStringRef propertyName,
240 JSValueRef* exception)
245 Converter converter(context);
246 MediacontentFolderPtr folder = getFolderObject(object);
247 return converter.toJSValueRef(folder->getFolderModifiedDate());
251 LogWarning("trying to get incorrect value");
253 return JSValueMakeUndefined(context);
257 JSValueRef JSFolder::getPropertyMediaId(
258 JSContextRef context,
260 JSStringRef propertyName,
261 JSValueRef* exception)
266 Converter converter(context);
267 MediacontentFolderPtr folder = getFolderObject(object);
268 //folder->getMediaIdList()
269 //MediaIdListPtr getMediaIdList() const;
270 //typedef vector<std::string> MediaIdList;
271 //typedef DPL::SharedPtr<MediaIdList> MediaIdListPtr;
272 MediaIdListPtr mediaIdLstPtr = folder->getMediaIdList();
273 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
277 if (NULL == jsResult)
279 ThrowMsg(NullPointerException, "Could not create js array object");
281 for(unsigned int i=0; i<mediaIdLstPtr->size(); i++)
283 JSValueRef val = converter.toJSValueRef(mediaIdLstPtr->at(i));
284 if(!JSSetArrayElement(context, jsResult, i, val))
286 ThrowMsg(UnknownException, "Could not insert value into js array");
294 LogWarning("trying to get incorrect value");
296 return JSValueMakeUndefined(context);