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.
21 #include <dpl/log/log.h>
22 #include <CommonsJavaScript/Utils.h>
23 #include <CommonsJavaScript/Validator.h>
24 #include <CommonsJavaScript/Converter.h>
25 #include <CommonsJavaScript/JSCallbackManager.h>
26 #include <CommonsJavaScript/JSUtils.h>
27 #include <CommonsJavaScript/JSPendingOperation.h>
28 #include <CommonsJavaScript/PrivateObject.h>
29 #include <CommonsJavaScript/ScopedJSStringRef.h>
30 #include <JSTizenExceptionFactory.h>
31 #include <JSTizenException.h>
32 #include <SecurityExceptions.h>
33 #include <CallbackUserData.h>
34 #include <MultiCallbackUserData.h>
35 #include <GlobalContextManager.h>
36 #include <FilterConverter.h>
39 #include "ContentFactory.h"
40 #include "ContentController.h"
41 #include "JSContentManager.h"
42 #include "JSContent.h"
46 #include "ContentConverter.h"
47 #include "plugin_config.h"
48 #include "ContentAsyncCallbackManager.h"
49 #include "ContentListener.h"
50 #include "ContentVideo.h"
51 #include "ContentImage.h"
54 using namespace DeviceAPI::Common;
55 using namespace DeviceAPI::Tizen;
56 using namespace WrtDeviceApis::Commons;
57 using namespace WrtDeviceApis::CommonsJavaScript;
59 #define TIZEN_CONTENT_MANAGER_ATTRIBUTENAME "content"
64 JSStaticValue JSMediacontentManager::m_property[] =
69 JSStaticFunction JSMediacontentManager::m_function[] =
71 { CONTENT_FUNCTION_API_FIND_ITEMS, findItems, kJSPropertyAttributeNone },
72 { CONTENT_FUNCTION_API_GET_FOLDERS, getFolders, kJSPropertyAttributeNone },
73 { CONTENT_FUNCTION_API_UPDATE_ITEM, updateItem, kJSPropertyAttributeNone },
74 { CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH, updateItemsBatch, kJSPropertyAttributeNone },
75 { CONTENT_FUNCTION_API_SCAN_FILE, scanFile, kJSPropertyAttributeNone },
76 { CONTENT_FUNCTION_API_SET_CHANGE_LISTENER, setChangeListener, kJSPropertyAttributeNone },
77 { CONTENT_FUNCTION_API_UNSET_CHANGE_LISTENER, unsetChangeListener,kJSPropertyAttributeNone},
78 { CONTENT_FUNCTION_API_UPDATE_METADATA, updateMetadata,kJSPropertyAttributeNone},
83 JSClassRef JSMediacontentManager::m_jsClassRef = NULL;
85 JSClassDefinition JSMediacontentManager::m_classInfo =
88 kJSClassAttributeNone,
89 TIZEN_CONTENT_MANAGER_ATTRIBUTENAME,
98 NULL, //deleteProperty,
99 NULL, //getPropertyNames,
100 NULL, //callAsFunction,
101 NULL, //callAsConstructor,
103 NULL, //convertToType
106 JSValueRef JSMediacontentManager::getFolders(
107 JSContextRef context,
109 JSObjectRef thisObject,
110 size_t argumentCount,
111 const JSValueRef arguments[],
112 JSValueRef* exception )
114 LogDebug("JSContentManagerManager::getFolders entered");
117 MediacontentManagerPrivObject *privateObject;
118 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
119 if (!privateObject) {
120 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
123 JSContextRef globalContext = privateObject->getContext();
124 Validator validator(context);
125 JSCallbackManagerPtr cbm(NULL);
126 FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
127 MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
129 cbm = JSCallbackManager::createObject(globalContext);
130 cbm->setObject(thisObject);
134 IMediacontentManagerPtr contentMgr = getContentManagerPrivObject(context, thisObject, exception);
136 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
138 if(argumentCount >= 1) //MediaFolderArraySuccessCB successCallback
140 if(validator.isCallback(arguments[0]))
142 onSuccessForCbm = arguments[0];
146 ThrowMsg(ConversionException, "SuccessCallback type mismatched.");
151 ThrowMsg(ConversionException,"There is no successCallback.");
153 if(argumentCount >= 2) //optional ErrorCallback? errorCallback
155 if(validator.isCallback(arguments[1]))
157 onErrorForCbm = arguments[1];
159 else if(!validator.isNullOrUndefined(arguments[1])) //nullable
161 ThrowMsg(ConversionException,"ErrorCallback type mismatched.");
166 cbm->setOnSuccess(onSuccessForCbm);
167 cbm->setOnError(onErrorForCbm);
170 IEventFindFolderPtr dplEvent(new IEventFindFolder());
171 dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
172 dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
174 contentMgr->findFolder(dplEvent);
176 MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
178 Catch(WrtDeviceApis::Commons::UnsupportedException)
180 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
181 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
183 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
185 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
186 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
188 Catch(WrtDeviceApis::Commons::ConversionException)
190 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
191 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
193 Catch(WrtDeviceApis::Commons::NotFoundException)
195 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
196 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
198 Catch(WrtDeviceApis::Commons::Exception)
200 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
201 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
204 return JSValueMakeUndefined(context);
210 JSValueRef JSMediacontentManager::findItems(
211 JSContextRef context,
213 JSObjectRef thisObject,
214 size_t argumentCount,
215 const JSValueRef arguments[],
216 JSValueRef* exception )
219 LogDebug("JSContentManagerManager::findItems entered");
221 MediacontentManagerPrivObject *privateObject;
222 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
223 if (!privateObject) {
224 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
229 AceSecurityStatus status = CONTENT_CHECK_ACCESS(
230 CONTENT_FUNCTION_API_FIND_ITEMS);
232 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
235 JSContextRef globalContext = privateObject->getContext();
236 Validator validator(context);
237 JSCallbackManagerPtr cbm(NULL);
238 FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
239 MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
240 MediaConverter mediaConverter(globalContext);
242 cbm = JSCallbackManager::createObject(globalContext);
243 cbm->setObject(thisObject);
248 IMediacontentManagerPtr contentMgr = getContentManagerPrivObject(context, thisObject, exception);
249 IEventBrowseFolderPtr dplEvent(new IEventBrowseFolder());
250 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
252 if(argumentCount >= 1) //MediaItemArraySuccessCB successCallback
254 if(validator.isCallback(arguments[0]))
256 onSuccessForCbm = arguments[0];
260 ThrowMsg(ConversionException,"SuccessCallback type mismatched.");
265 ThrowMsg(ConversionException,"There is no SuccessCallback.");
267 if(argumentCount >= 2) //ErrorCallback? errorCallback
269 if(validator.isCallback(arguments[1]))
271 onErrorForCbm = arguments[1];
273 else if(!validator.isNullOrUndefined(arguments[1])) //nullable
275 ThrowMsg(ConversionException,"ErrorCallback type mismatched.");
280 cbm->setOnSuccess(onSuccessForCbm);
281 cbm->setOnError(onErrorForCbm);
284 if(argumentCount >= 3) //MediaFolderId id,
286 string folderId = mediaConverter.toString(arguments[2]);
287 if(!(validator.isNullOrUndefined(arguments[2])) && (folderId.length() > 0) )
289 LogDebug("folderId:"+ folderId);
292 istringstream(folderId) >> nFolderId; //string -> int
296 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
297 JSTizenException::INVALID_VALUES_ERROR, "Argument is invalid"));
298 return JSValueMakeUndefined(context);
301 dplEvent->setFolderID(folderId);
305 if(argumentCount >= 4) //optional AbstractFilter? filter
307 if(JSValueIsObject(context, arguments[3]))
309 dplEvent->setFilter(filterConverter->toFilter(arguments[3]));
311 else if(!validator.isNullOrUndefined(arguments[3])) //nullable
313 ThrowMsg(ConversionException,"Filter type mismatched.");
316 if(argumentCount >= 5) //optional SortMode? sortMode
319 if ( JSValueIsObject(context, arguments[4]) &&
320 !JSValueIsNull(context, arguments[4]) &&
321 !JSValueIsUndefined(context, arguments[4]) &&
322 !JSIsArrayValue(context, arguments[4]))
324 LogDebug("sortmode is object");
325 dplEvent->setSortMode(filterConverter->toSortMode(arguments[4]));
327 else if(!validator.isNullOrUndefined(arguments[4])) //nullable
329 ThrowMsg(ConversionException,"SortMode type mismatched.");
332 if(argumentCount >= 6) //optional unsigned long? count
334 if(!JSValueIsNull(context, arguments[5]) && !JSValueIsUndefined(context, arguments[5])){
335 long count = filterConverter->toLong(arguments[5]);
337 dplEvent->setLimit(count);
340 ThrowMsg(InvalidArgumentException, "count should be positive.");
344 if(argumentCount >= 7) //optional unsigned long? offset
346 long offset = filterConverter->toLong(arguments[6]);
348 dplEvent->setOffset(offset);
351 ThrowMsg(InvalidArgumentException, "offset should be positive.");
354 dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
355 dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
356 contentMgr->browseFolder(dplEvent);
358 MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
360 Catch(WrtDeviceApis::Commons::UnsupportedException)
362 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
363 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
365 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
367 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
368 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
370 Catch(WrtDeviceApis::Commons::ConversionException)
372 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
373 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
375 Catch(WrtDeviceApis::Commons::NotFoundException)
377 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
378 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
380 Catch(WrtDeviceApis::Commons::Exception)
382 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
383 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
386 return JSValueMakeUndefined(context);
391 JSValueRef JSMediacontentManager::updateItemsBatch(JSContextRef context,
393 JSObjectRef thisObject,
394 size_t argumentCount,
395 const JSValueRef arguments[],
396 JSValueRef* exception)
398 LogDebug("JSContentManagerManager::updateItemsBatch entered");
399 MediacontentManagerPrivObject *privateObject;
400 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
401 if (!privateObject) {
402 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
406 JSContextRef globalContext = privateObject->getContext();
407 AceSecurityStatus status = CONTENT_CHECK_ACCESS(
408 CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH);
409 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
411 Validator validator(context);
412 JSCallbackManagerPtr cbm(NULL);
413 FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
414 MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
416 cbm = JSCallbackManager::createObject(globalContext);
417 cbm->setObject(thisObject);
422 IMediacontentManagerPtr contentMgr = getContentManagerPrivObject(context, thisObject, exception);
424 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
425 MediacontentMediaListPtr events;
426 if((argumentCount >= 1) && (JSIsArrayValue(context, arguments[0]))) //MediaItem[] items
428 events = converter->toVectorOfMediaItem(arguments[0]);
431 ThrowMsg(ConversionException, "Items type mismatched.");
436 ThrowMsg(ConversionException, "Items type mismatched.");
439 if(argumentCount >= 2) //Function? successCallback,
441 if(validator.isCallback(arguments[1]))
443 onSuccessForCbm = arguments[1];
445 else if(!validator.isNullOrUndefined(arguments[1])) //nullable
447 ThrowMsg(ConversionException,"successCallback type mismatched.");
451 if(argumentCount >= 3) //ErrorCallback? errorCallback,
453 if(validator.isCallback(arguments[2]))
455 onErrorForCbm = arguments[2];
457 else if(!validator.isNullOrUndefined(arguments[2])) //nullable
459 ThrowMsg(ConversionException,"ErrorCallback type is mismatched.");
465 cbm->setOnSuccess(onSuccessForCbm);
466 cbm->setOnError(onErrorForCbm);
469 IEventUpdateMediaItemsPtr dplEvent(new IEventUpdateMediaItems());
470 dplEvent->setMediaItems(events);
471 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
473 dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
474 contentMgr->updateMediaItems(dplEvent);
476 MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
478 Catch(WrtDeviceApis::Commons::UnsupportedException)
480 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
481 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
483 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
485 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
486 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
488 Catch(WrtDeviceApis::Commons::ConversionException)
490 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
491 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
493 Catch(WrtDeviceApis::Commons::NotFoundException)
495 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
496 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
498 Catch(WrtDeviceApis::Commons::Exception)
500 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
501 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
504 return JSValueMakeUndefined(context);
509 JSValueRef JSMediacontentManager::updateItem(
510 JSContextRef context,
512 JSObjectRef thisObject,
513 size_t argumentCount,
514 const JSValueRef arguments[],
515 JSValueRef* exception)
517 LogDebug("JSContentManagerManager::updateItem entered");
520 MediacontentManagerPrivObject *privateObject;
521 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
522 if (!privateObject) {
523 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
528 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_UPDATE_ITEM);
530 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
532 Validator validator(context);
536 IMediacontentManagerPtr contentMgr = getContentManagerPrivObject(context, thisObject, exception);
538 //parameter : MediaItem item
541 if(argumentCount >= 1)
543 if (!JSValueIsObjectOfClass(context, arguments[0], JSMedia::getClassRef()) &&
544 !JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef()) &&
545 !JSValueIsObjectOfClass(context, arguments[0], JSAudio::getClassRef()) &&
546 !JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())) {
547 ThrowMsg(ConversionException, "Item type mismatched.");
549 arg = JSValueToObject(context, arguments[0], exception);
553 ThrowMsg(ConversionException, "Item type mismatched.");
556 MediacontentMediaPtr event;
557 IEventUpdateMediaPtr dplEvent(new IEventUpdateMedia());
559 if(JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef())){
561 JSValueRef geoValRef = JSUtil::getProperty(context ,
562 JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
563 JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
564 double latitude = JSUtil::JSValueToDouble(context,
565 JSUtil::getProperty(context, geoObjRef, "latitude"));
567 double longitude = JSUtil::JSValueToDouble(context,
568 JSUtil::getProperty(context, geoObjRef, "longitude"));
570 MediacontentImagePtr imgPtr = JSImage::getImageObject(arg);
571 imgPtr->setImageLatitude(latitude);
572 imgPtr->setImageLongitude(longitude);
575 else if(JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())){
576 JSValueRef geoValRef = JSUtil::getProperty(context ,
577 JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
578 JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
580 double latitude = JSUtil::JSValueToDouble(context,
581 JSUtil::getProperty(context, geoObjRef, "latitude"));
583 double longitude = JSUtil::JSValueToDouble(context,
584 JSUtil::getProperty(context, geoObjRef, "longitude"));
586 MediacontentVideoPtr vedioPtr = JSVideo::getVideoObject(arg);
587 vedioPtr->setVideoLatitude(latitude);
588 vedioPtr->setVideoLongitude(longitude);
591 event = JSMedia::getMediaObject(arg);
592 dplEvent->setMediaItem(event);
594 dplEvent->setForSynchronousCall();
595 contentMgr->updateMedia(dplEvent);
597 if (!(dplEvent->getResult())) {
598 ThrowMsg(WrtDeviceApis::Commons::Exception, "updating failed by unknown reason.");
601 Catch(WrtDeviceApis::Commons::UnsupportedException)
603 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
604 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
606 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
608 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
609 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
611 Catch(WrtDeviceApis::Commons::ConversionException)
613 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
614 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
616 Catch(WrtDeviceApis::Commons::NotFoundException)
618 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
619 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
621 Catch(WrtDeviceApis::Commons::Exception)
623 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
624 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
627 return JSValueMakeUndefined(context);
631 static void _scanCompletedCallback(std::string err_msg, std::string path, void *user_data){
632 CallbackUserData *cb = static_cast<CallbackUserData*>(user_data);
634 if(err_msg.empty() ){
635 Converter converter(cb->getContext());
636 JSValueRef jsPath = converter.toJSValueRef(path);
637 cb->callSuccessCallback(jsPath);
640 JSValueRef errorObject = JSTizenExceptionFactory::makeErrorObject(cb->getContext(), JSTizenException::UNKNOWN_ERROR, err_msg);
641 cb->callErrorCallback(errorObject);
647 JSValueRef JSMediacontentManager::scanFile(
648 JSContextRef context,
650 JSObjectRef thisObject,
651 size_t argumentCount,
652 const JSValueRef arguments[],
653 JSValueRef* exception)
655 LogDebug("JSContentManagerManager::scanFile entered");
658 MediacontentManagerPrivObject *privateObject;
659 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
661 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SCAN_FILE);
662 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
668 ThrowMsg(ConversionException, "private object is null");
671 CallbackUserData *callback = new CallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context));
673 Converter convert(context);
674 Validator validator(context);
675 IMediacontentManagerPtr contentMgr = privateObject->getObject();
678 if(argumentCount >= 1){ //directoryURI
679 path = convert.toString(arguments[0]);
680 if(validator.isNullOrUndefined(arguments[0])){
681 ThrowMsg(InvalidArgumentException, path+" is not available");
685 ThrowMsg(InvalidArgumentException, "file path is not available");
688 if(argumentCount >= 2){ //successCallback[optional|nullable]
689 if(validator.isCallback(arguments[1])){
690 callback->setSuccessCallback(arguments[1]);
692 else if(!(JSValueIsNull(context,arguments[1]))){
693 ThrowMsg(ConversionException, path + ":successCallback is not available");
697 if(argumentCount >= 3){ //errorCallback
698 if(validator.isCallback(arguments[2])){
699 callback->setErrorCallback(arguments[2]);
701 else if(!(JSValueIsNull(context,arguments[2]))){
702 ThrowMsg(ConversionException, path + ":errorCallback is not available");
706 contentMgr->scanFile(_scanCompletedCallback,path,(void*)callback);
709 Catch(WrtDeviceApis::Commons::UnsupportedException)
711 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
712 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
714 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
716 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
717 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
719 Catch(WrtDeviceApis::Commons::ConversionException)
721 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
722 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
724 Catch(WrtDeviceApis::Commons::NotFoundException)
726 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
727 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
729 Catch(WrtDeviceApis::Commons::Exception)
731 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
732 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
735 return JSValueMakeUndefined(context);
740 JSValueRef JSMediacontentManager::setChangeListener(
741 JSContextRef context,
743 JSObjectRef thisObject,
744 size_t argumentCount,
745 const JSValueRef arguments[],
746 JSValueRef* exception)
748 LogDebug("JSContentManagerManager::setChangeListener entered");
750 MediacontentManagerPrivObject *privateObject;
751 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
753 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
754 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
760 ThrowMsg(ConversionException, "private object is null");
763 if(argumentCount>=1) {
764 if (!JSValueIsObject(context, arguments[0])) {
765 ThrowMsg(ConversionException, "Wrong first parameter type.");
769 ThrowMsg(ConversionException, "Wrong first parameter type.");
772 Converter convert(context);
773 Validator validator(context);
775 JSContextRef globalCtx = GlobalContextManager::getInstance()->getGlobalContext(context);
777 // changeCallback Object
778 JSObjectRef callbackObj = convert.toJSObjectRef(arguments[0]);
780 ContentListener *listener = new ContentListener(globalCtx, callbackObj);
783 IMediacontentManagerPtr contentMgr = privateObject->getObject();
784 if(!(contentMgr->setListener(listener)))
786 ThrowMsg(Exception, "Unknown exception is occured by platfrom");
789 Catch(WrtDeviceApis::Commons::UnsupportedException)
791 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
792 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
794 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
796 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
797 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
799 Catch(WrtDeviceApis::Commons::ConversionException)
801 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
802 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
804 Catch(WrtDeviceApis::Commons::NotFoundException)
806 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
807 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
809 Catch(WrtDeviceApis::Commons::Exception)
811 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
812 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
815 return JSValueMakeUndefined(context);
820 JSValueRef JSMediacontentManager::unsetChangeListener(
821 JSContextRef context,
823 JSObjectRef thisObject,
824 size_t argumentCount,
825 const JSValueRef arguments[],
826 JSValueRef* exception)
828 LogDebug("JSContentManagerManager::unsetChangeListener entered");
830 MediacontentManagerPrivObject *privateObject;
831 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
833 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
834 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
839 ThrowMsg(ConversionException, "private object is null");
843 IMediacontentManagerPtr contentMgr = privateObject->getObject();
844 if(!(contentMgr->unsetListener()))
846 ThrowMsg(Exception, "Unknown exception is occured by platfrom");
849 Catch(WrtDeviceApis::Commons::UnsupportedException)
851 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
852 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
854 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
856 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
857 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
859 Catch(WrtDeviceApis::Commons::ConversionException)
861 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
862 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
864 Catch(WrtDeviceApis::Commons::NotFoundException)
866 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
867 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
869 Catch(WrtDeviceApis::Commons::Exception)
871 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
872 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
875 return JSValueMakeUndefined(context);
879 JSValueRef JSMediacontentManager::updateMetadata(
880 JSContextRef context,
882 JSObjectRef thisObject,
883 size_t argumentCount,
884 const JSValueRef arguments[],
885 JSValueRef* exception)
887 LogDebug("JSContentManagerManager::updateMetadata entered");
890 MediacontentManagerPrivObject *privateObject;
891 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
892 if (!privateObject) {
893 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "private object is null");
896 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_UPDATE_METADATA);
897 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
899 Validator validator(context);
903 IMediacontentManagerPtr contentMgr = getContentManagerPrivObject(context, thisObject, exception);
906 if(argumentCount >= 1){
907 if (!JSValueIsObjectOfClass(context, arguments[0],JSImage::getClassRef())){
908 ThrowMsg(UnsupportedException, "Not supported type.");
910 arg = JSValueToObject(context, arguments[0], exception);
913 ThrowMsg(ConversionException, "Invalid content type.");
916 MediacontentImagePtr content = JSImage::getImageObject(arg);
918 if (!(contentMgr->updateMetadata(content))) {
919 ThrowMsg(WrtDeviceApis::Commons::Exception, "updating metadata is failed by unknown reason.");
922 Catch(WrtDeviceApis::Commons::UnsupportedException)
924 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
925 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
927 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
929 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
930 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
932 Catch(WrtDeviceApis::Commons::ConversionException)
934 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
935 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
937 Catch(WrtDeviceApis::Commons::NotFoundException)
939 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
940 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
942 Catch(WrtDeviceApis::Commons::Exception)
944 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
945 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
948 return JSValueMakeUndefined(context);
953 const JSClassRef JSMediacontentManager::getClassRef() {
955 m_jsClassRef = JSClassCreate(&m_classInfo);
961 const JSClassDefinition* JSMediacontentManager::getClassInfo()
966 void JSMediacontentManager::initialize(JSContextRef context, JSObjectRef object)
968 LogDebug("JSContentManager initialize entered");
969 MediacontentManagerPrivObject *privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
970 if (NULL == privateObject)
972 LogDebug("Create ContenttManagerPrivObject");
973 IMediacontentManagerPtr contentManager = MediacontentFactory::getInstance().createMediacontentManagerObject();
974 privateObject = new MediacontentManagerPrivObject(context, contentManager);
975 if (!JSObjectSetPrivate(object, static_cast<void*>(privateObject)))
977 delete privateObject;
983 void JSMediacontentManager::finalize(JSObjectRef object)
986 MediacontentManagerPrivObject* priv = static_cast<MediacontentManagerPrivObject*> (JSObjectGetPrivate(object));
989 LogDebug("Deleting coordinates object");
991 JSObjectSetPrivate(object, NULL);
997 IMediacontentManagerPtr JSMediacontentManager::getContentManagerPrivObject(
999 const JSObjectRef object,
1000 JSValueRef* exception)
1002 MediacontentManagerPrivObject *priv = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
1005 return priv->getObject();
1007 ThrowMsg(ConversionException, "Private object is NULL.");