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},
82 JSClassRef JSMediacontentManager::m_jsClassRef = NULL;
84 JSClassDefinition JSMediacontentManager::m_classInfo =
87 kJSClassAttributeNone,
88 TIZEN_CONTENT_MANAGER_ATTRIBUTENAME,
97 NULL, //deleteProperty,
98 NULL, //getPropertyNames,
99 NULL, //callAsFunction,
100 NULL, //callAsConstructor,
102 NULL, //convertToType
105 JSValueRef JSMediacontentManager::getFolders(
106 JSContextRef context,
108 JSObjectRef thisObject,
109 size_t argumentCount,
110 const JSValueRef arguments[],
111 JSValueRef* exception )
113 LogDebug("JSContentManagerManager::getFolders entered");
116 MediacontentManagerPrivObject *privateObject;
117 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
118 if (!privateObject) {
119 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
122 JSContextRef globalContext = privateObject->getContext();
123 Validator validator(context);
124 JSCallbackManagerPtr cbm(NULL);
125 FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
126 MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
128 cbm = JSCallbackManager::createObject(globalContext);
129 cbm->setObject(thisObject);
133 IMediacontentManagerPtr contentMgr = getContentManagerPrivObject(context, thisObject, exception);
135 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
137 if(argumentCount >= 1) //MediaFolderArraySuccessCB successCallback
139 if(validator.isCallback(arguments[0]))
141 onSuccessForCbm = arguments[0];
145 ThrowMsg(ConversionException, "SuccessCallback type mismatched.");
150 ThrowMsg(ConversionException,"There is no successCallback.");
152 if(argumentCount >= 2) //optional ErrorCallback? errorCallback
154 if(validator.isCallback(arguments[1]))
156 onErrorForCbm = arguments[1];
158 else if(!validator.isNullOrUndefined(arguments[1])) //nullable
160 ThrowMsg(ConversionException,"ErrorCallback type mismatched.");
165 cbm->setOnSuccess(onSuccessForCbm);
166 cbm->setOnError(onErrorForCbm);
169 IEventFindFolderPtr dplEvent(new IEventFindFolder());
170 dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
171 dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
173 contentMgr->findFolder(dplEvent);
175 MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
177 Catch(WrtDeviceApis::Commons::UnsupportedException)
179 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
180 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
182 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
184 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
185 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
187 Catch(WrtDeviceApis::Commons::ConversionException)
189 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
190 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
192 Catch(WrtDeviceApis::Commons::NotFoundException)
194 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
195 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
197 Catch(WrtDeviceApis::Commons::Exception)
199 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
200 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
203 return JSValueMakeUndefined(context);
209 JSValueRef JSMediacontentManager::findItems(
210 JSContextRef context,
212 JSObjectRef thisObject,
213 size_t argumentCount,
214 const JSValueRef arguments[],
215 JSValueRef* exception )
218 LogDebug("JSContentManagerManager::findItems entered");
220 MediacontentManagerPrivObject *privateObject;
221 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
222 if (!privateObject) {
223 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
228 AceSecurityStatus status = CONTENT_CHECK_ACCESS(
229 CONTENT_FUNCTION_API_FIND_ITEMS);
231 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
234 JSContextRef globalContext = privateObject->getContext();
235 Validator validator(context);
236 JSCallbackManagerPtr cbm(NULL);
237 FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
238 MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
239 MediaConverter mediaConverter(globalContext);
241 cbm = JSCallbackManager::createObject(globalContext);
242 cbm->setObject(thisObject);
247 IMediacontentManagerPtr contentMgr = getContentManagerPrivObject(context, thisObject, exception);
248 IEventBrowseFolderPtr dplEvent(new IEventBrowseFolder());
249 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
251 if(argumentCount >= 1) //MediaItemArraySuccessCB successCallback
253 if(validator.isCallback(arguments[0]))
255 onSuccessForCbm = arguments[0];
259 ThrowMsg(ConversionException,"SuccessCallback type mismatched.");
264 ThrowMsg(ConversionException,"There is no SuccessCallback.");
266 if(argumentCount >= 2) //ErrorCallback? errorCallback
268 if(validator.isCallback(arguments[1]))
270 onErrorForCbm = arguments[1];
272 else if(!validator.isNullOrUndefined(arguments[1])) //nullable
274 ThrowMsg(ConversionException,"ErrorCallback type mismatched.");
279 cbm->setOnSuccess(onSuccessForCbm);
280 cbm->setOnError(onErrorForCbm);
283 if(argumentCount >= 3) //MediaFolderId id,
285 string folderId = mediaConverter.toString(arguments[2]);
286 if(!(validator.isNullOrUndefined(arguments[2])) && (folderId.length() > 0) )
288 LogDebug("folderId:"+ folderId);
291 istringstream(folderId) >> nFolderId; //string -> int
295 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
296 JSTizenException::INVALID_VALUES_ERROR, "Argument is invalid"));
297 return JSValueMakeUndefined(context);
300 dplEvent->setFolderID(folderId);
304 if(argumentCount >= 4) //optional AbstractFilter? filter
306 if(JSValueIsObject(context, arguments[3]))
308 dplEvent->setFilter(filterConverter->toFilter(arguments[3]));
310 else if(!validator.isNullOrUndefined(arguments[3])) //nullable
312 ThrowMsg(ConversionException,"Filter type mismatched.");
315 if(argumentCount >= 5) //optional SortMode? sortMode
318 if ( JSValueIsObject(context, arguments[4]) &&
319 !JSValueIsNull(context, arguments[4]) &&
320 !JSValueIsUndefined(context, arguments[4]) &&
321 !JSIsArrayValue(context, arguments[4]))
323 LogDebug("sortmode is object");
324 dplEvent->setSortMode(filterConverter->toSortMode(arguments[4]));
326 else if(!validator.isNullOrUndefined(arguments[4])) //nullable
328 ThrowMsg(ConversionException,"SortMode type mismatched.");
331 if(argumentCount >= 6) //optional unsigned long? count
333 if(!JSValueIsNull(context, arguments[5]) && !JSValueIsUndefined(context, arguments[5])){
334 long count = filterConverter->toLong(arguments[5]);
336 dplEvent->setLimit(count);
339 ThrowMsg(InvalidArgumentException, "count should be positive.");
343 if(argumentCount >= 7) //optional unsigned long? offset
345 long offset = filterConverter->toLong(arguments[6]);
347 dplEvent->setOffset(offset);
350 ThrowMsg(InvalidArgumentException, "offset should be positive.");
353 dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
354 dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
355 contentMgr->browseFolder(dplEvent);
357 MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
359 Catch(WrtDeviceApis::Commons::UnsupportedException)
361 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
362 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
364 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
366 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
367 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
369 Catch(WrtDeviceApis::Commons::ConversionException)
371 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
372 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
374 Catch(WrtDeviceApis::Commons::NotFoundException)
376 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
377 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
379 Catch(WrtDeviceApis::Commons::Exception)
381 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
382 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
385 return JSValueMakeUndefined(context);
390 JSValueRef JSMediacontentManager::updateItemsBatch(JSContextRef context,
392 JSObjectRef thisObject,
393 size_t argumentCount,
394 const JSValueRef arguments[],
395 JSValueRef* exception)
397 LogDebug("JSContentManagerManager::updateItemsBatch entered");
398 MediacontentManagerPrivObject *privateObject;
399 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
400 if (!privateObject) {
401 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
405 JSContextRef globalContext = privateObject->getContext();
406 AceSecurityStatus status = CONTENT_CHECK_ACCESS(
407 CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH);
408 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
410 Validator validator(context);
411 JSCallbackManagerPtr cbm(NULL);
412 FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
413 MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
415 cbm = JSCallbackManager::createObject(globalContext);
416 cbm->setObject(thisObject);
421 IMediacontentManagerPtr contentMgr = getContentManagerPrivObject(context, thisObject, exception);
423 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
424 MediacontentMediaListPtr events;
425 if((argumentCount >= 1) && (JSIsArrayValue(context, arguments[0]))) //MediaItem[] items
427 events = converter->toVectorOfMediaItem(arguments[0]);
430 ThrowMsg(ConversionException, "Items type mismatched.");
435 ThrowMsg(ConversionException, "Items type mismatched.");
438 if(argumentCount >= 2) //Function? successCallback,
440 if(validator.isCallback(arguments[1]))
442 onSuccessForCbm = arguments[1];
444 else if(!validator.isNullOrUndefined(arguments[1])) //nullable
446 ThrowMsg(ConversionException,"successCallback type mismatched.");
450 if(argumentCount >= 3) //ErrorCallback? errorCallback,
452 if(validator.isCallback(arguments[2]))
454 onErrorForCbm = arguments[2];
456 else if(!validator.isNullOrUndefined(arguments[2])) //nullable
458 ThrowMsg(ConversionException,"ErrorCallback type is mismatched.");
464 cbm->setOnSuccess(onSuccessForCbm);
465 cbm->setOnError(onErrorForCbm);
468 IEventUpdateMediaItemsPtr dplEvent(new IEventUpdateMediaItems());
469 dplEvent->setMediaItems(events);
470 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
472 dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
473 contentMgr->updateMediaItems(dplEvent);
475 MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
477 Catch(WrtDeviceApis::Commons::UnsupportedException)
479 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
480 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
482 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
484 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
485 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
487 Catch(WrtDeviceApis::Commons::ConversionException)
489 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
490 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
492 Catch(WrtDeviceApis::Commons::NotFoundException)
494 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
495 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
497 Catch(WrtDeviceApis::Commons::Exception)
499 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
500 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
503 return JSValueMakeUndefined(context);
508 JSValueRef JSMediacontentManager::updateItem(
509 JSContextRef context,
511 JSObjectRef thisObject,
512 size_t argumentCount,
513 const JSValueRef arguments[],
514 JSValueRef* exception)
516 LogDebug("JSContentManagerManager::updateItem entered");
519 MediacontentManagerPrivObject *privateObject;
520 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
521 if (!privateObject) {
522 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
527 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_UPDATE_ITEM);
529 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
531 Validator validator(context);
535 IMediacontentManagerPtr contentMgr = getContentManagerPrivObject(context, thisObject, exception);
537 //parameter : MediaItem item
540 if(argumentCount >= 1)
542 if (!JSValueIsObjectOfClass(context, arguments[0], JSMedia::getClassRef()) &&
543 !JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef()) &&
544 !JSValueIsObjectOfClass(context, arguments[0], JSAudio::getClassRef()) &&
545 !JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())) {
546 ThrowMsg(ConversionException, "Item type mismatched.");
548 arg = JSValueToObject(context, arguments[0], exception);
552 ThrowMsg(ConversionException, "Item type mismatched.");
555 MediacontentMediaPtr event;
556 IEventUpdateMediaPtr dplEvent(new IEventUpdateMedia());
558 if(JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef())){
560 JSValueRef geoValRef = JSUtil::getProperty(context ,
561 JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
562 JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
563 double latitude = JSUtil::JSValueToDouble(context,
564 JSUtil::getProperty(context, geoObjRef, "latitude"));
566 double longitude = JSUtil::JSValueToDouble(context,
567 JSUtil::getProperty(context, geoObjRef, "longitude"));
569 MediacontentImagePtr imgPtr = JSImage::getImageObject(arg);
570 imgPtr->setImageLatitude(latitude);
571 imgPtr->setImageLongitude(longitude);
574 else if(JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())){
575 JSValueRef geoValRef = JSUtil::getProperty(context ,
576 JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
577 JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
579 double latitude = JSUtil::JSValueToDouble(context,
580 JSUtil::getProperty(context, geoObjRef, "latitude"));
582 double longitude = JSUtil::JSValueToDouble(context,
583 JSUtil::getProperty(context, geoObjRef, "longitude"));
585 MediacontentVideoPtr vedioPtr = JSVideo::getVideoObject(arg);
586 vedioPtr->setVideoLatitude(latitude);
587 vedioPtr->setVideoLongitude(longitude);
590 event = JSMedia::getMediaObject(arg);
591 dplEvent->setMediaItem(event);
593 dplEvent->setForSynchronousCall();
594 contentMgr->updateMedia(dplEvent);
596 if (!(dplEvent->getResult())) {
597 ThrowMsg(WrtDeviceApis::Commons::Exception, "updating failed by unknown reason.");
600 Catch(WrtDeviceApis::Commons::UnsupportedException)
602 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
603 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
605 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
607 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
608 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
610 Catch(WrtDeviceApis::Commons::ConversionException)
612 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
613 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
615 Catch(WrtDeviceApis::Commons::NotFoundException)
617 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
618 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
620 Catch(WrtDeviceApis::Commons::Exception)
622 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
623 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
626 return JSValueMakeUndefined(context);
630 static void _scanCompletedCallback(std::string err_msg, std::string path, void *user_data){
631 CallbackUserData *cb = static_cast<CallbackUserData*>(user_data);
633 if(err_msg.empty() ){
634 Converter converter(cb->getContext());
635 JSValueRef jsPath = converter.toJSValueRef(path);
636 cb->callSuccessCallback(jsPath);
639 JSValueRef errorObject = JSTizenExceptionFactory::makeErrorObject(cb->getContext(), JSTizenException::UNKNOWN_ERROR, err_msg);
640 cb->callErrorCallback(errorObject);
646 JSValueRef JSMediacontentManager::scanFile(
647 JSContextRef context,
649 JSObjectRef thisObject,
650 size_t argumentCount,
651 const JSValueRef arguments[],
652 JSValueRef* exception)
654 LogDebug("JSContentManagerManager::scanFile entered");
657 MediacontentManagerPrivObject *privateObject;
658 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
660 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SCAN_FILE);
661 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
667 ThrowMsg(ConversionException, "private object is null");
670 CallbackUserData *callback = new CallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context));
672 Converter convert(context);
673 Validator validator(context);
674 IMediacontentManagerPtr contentMgr = privateObject->getObject();
677 if(argumentCount >= 1){ //directoryURI
678 path = convert.toString(arguments[0]);
679 if(validator.isNullOrUndefined(arguments[0])){
680 ThrowMsg(InvalidArgumentException, path+" is not available");
684 ThrowMsg(InvalidArgumentException, "file path is not available");
687 if(argumentCount >= 2){ //successCallback[optional|nullable]
688 if(validator.isCallback(arguments[1])){
689 callback->setSuccessCallback(arguments[1]);
691 else if(!(JSValueIsNull(context,arguments[1]))){
692 ThrowMsg(ConversionException, path + ":successCallback is not available");
696 if(argumentCount >= 3){ //errorCallback
697 if(validator.isCallback(arguments[2])){
698 callback->setErrorCallback(arguments[2]);
700 else if(!(JSValueIsNull(context,arguments[2]))){
701 ThrowMsg(ConversionException, path + ":errorCallback is not available");
705 contentMgr->scanFile(_scanCompletedCallback,path,(void*)callback);
708 Catch(WrtDeviceApis::Commons::UnsupportedException)
710 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
711 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
713 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
715 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
716 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
718 Catch(WrtDeviceApis::Commons::ConversionException)
720 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
721 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
723 Catch(WrtDeviceApis::Commons::NotFoundException)
725 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
726 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
728 Catch(WrtDeviceApis::Commons::Exception)
730 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
731 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
734 return JSValueMakeUndefined(context);
739 JSValueRef JSMediacontentManager::setChangeListener(
740 JSContextRef context,
742 JSObjectRef thisObject,
743 size_t argumentCount,
744 const JSValueRef arguments[],
745 JSValueRef* exception)
747 LogDebug("JSContentManagerManager::setChangeListener entered");
749 MediacontentManagerPrivObject *privateObject;
750 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
752 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
753 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
759 ThrowMsg(ConversionException, "private object is null");
762 if(argumentCount>=1) {
763 if (!JSValueIsObject(context, arguments[0])) {
764 ThrowMsg(ConversionException, "Wrong first parameter type.");
768 ThrowMsg(ConversionException, "Wrong first parameter type.");
771 Converter convert(context);
772 Validator validator(context);
774 JSContextRef globalCtx = GlobalContextManager::getInstance()->getGlobalContext(context);
776 // changeCallback Object
777 JSObjectRef callbackObj = convert.toJSObjectRef(arguments[0]);
779 ContentListener *listener = new ContentListener(globalCtx, callbackObj);
782 IMediacontentManagerPtr contentMgr = privateObject->getObject();
783 if(!(contentMgr->setListener(listener)))
785 ThrowMsg(Exception, "Unknown exception is occured by platfrom");
788 Catch(WrtDeviceApis::Commons::UnsupportedException)
790 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
791 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
793 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
795 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
796 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
798 Catch(WrtDeviceApis::Commons::ConversionException)
800 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
801 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
803 Catch(WrtDeviceApis::Commons::NotFoundException)
805 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
806 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
808 Catch(WrtDeviceApis::Commons::Exception)
810 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
811 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
814 return JSValueMakeUndefined(context);
819 JSValueRef JSMediacontentManager::unsetChangeListener(
820 JSContextRef context,
822 JSObjectRef thisObject,
823 size_t argumentCount,
824 const JSValueRef arguments[],
825 JSValueRef* exception)
827 LogDebug("JSContentManagerManager::unsetChangeListener entered");
829 MediacontentManagerPrivObject *privateObject;
830 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
832 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
833 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
838 ThrowMsg(ConversionException, "private object is null");
842 IMediacontentManagerPtr contentMgr = privateObject->getObject();
843 if(!(contentMgr->unsetListener()))
845 ThrowMsg(Exception, "Unknown exception is occured by platfrom");
848 Catch(WrtDeviceApis::Commons::UnsupportedException)
850 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
851 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
853 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
855 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
856 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
858 Catch(WrtDeviceApis::Commons::ConversionException)
860 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
861 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
863 Catch(WrtDeviceApis::Commons::NotFoundException)
865 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
866 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
868 Catch(WrtDeviceApis::Commons::Exception)
870 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
871 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
874 return JSValueMakeUndefined(context);
878 const JSClassRef JSMediacontentManager::getClassRef() {
880 m_jsClassRef = JSClassCreate(&m_classInfo);
886 const JSClassDefinition* JSMediacontentManager::getClassInfo()
891 void JSMediacontentManager::initialize(JSContextRef context, JSObjectRef object)
893 LogDebug("JSContentManager initialize entered");
894 MediacontentManagerPrivObject *privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
895 if (NULL == privateObject)
897 LogDebug("Create ContenttManagerPrivObject");
898 IMediacontentManagerPtr contentManager = MediacontentFactory::getInstance().createMediacontentManagerObject();
899 privateObject = new MediacontentManagerPrivObject(context, contentManager);
900 if (!JSObjectSetPrivate(object, static_cast<void*>(privateObject)))
902 delete privateObject;
908 void JSMediacontentManager::finalize(JSObjectRef object)
911 MediacontentManagerPrivObject* priv = static_cast<MediacontentManagerPrivObject*> (JSObjectGetPrivate(object));
914 LogDebug("Deleting coordinates object");
916 JSObjectSetPrivate(object, NULL);
922 IMediacontentManagerPtr JSMediacontentManager::getContentManagerPrivObject(
924 const JSObjectRef object,
925 JSValueRef* exception)
927 MediacontentManagerPrivObject *priv = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
930 return priv->getObject();
932 ThrowMsg(ConversionException, "Private object is NULL.");