summaryrefslogtreecommitdiff
path: root/wearable_src/Content/JSContentManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'wearable_src/Content/JSContentManager.cpp')
-rwxr-xr-xwearable_src/Content/JSContentManager.cpp816
1 files changed, 816 insertions, 0 deletions
diff --git a/wearable_src/Content/JSContentManager.cpp b/wearable_src/Content/JSContentManager.cpp
new file mode 100755
index 0000000..a5d864b
--- /dev/null
+++ b/wearable_src/Content/JSContentManager.cpp
@@ -0,0 +1,816 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include <cassert>
+#include <memory>
+#include <CommonsJavaScript/Utils.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSPendingOperation.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <SecurityExceptions.h>
+#include <CallbackUserData.h>
+#include <MultiCallbackUserData.h>
+#include <GlobalContextManager.h>
+#include <FilterConverter.h>
+#include <JSWebAPIErrorFactory.h>
+#include <ArgumentValidator.h>
+#include <TimeTracer.h>
+
+#include "JSUtil.h"
+#include "ContentFactory.h"
+#include "ContentController.h"
+#include "JSContentManager.h"
+#include "JSContent.h"
+#include "JSImage.h"
+#include "JSVideo.h"
+#include "JSAudio.h"
+#include "ContentConverter.h"
+#include "plugin_config.h"
+#include "ContentAsyncCallbackManager.h"
+#include "ContentListener.h"
+#include "ContentVideo.h"
+#include "ContentImage.h"
+#include "ContentFilterConverter.h"
+#include "ContentUtility.h"
+#include <Logger.h>
+
+using namespace DeviceAPI::Common;
+using namespace DeviceAPI::Tizen;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+#define TIZEN_CONTENT_MANAGER_ATTRIBUTENAME "content"
+
+namespace DeviceAPI {
+namespace Content {
+
+JSStaticValue JSMediacontentManager::m_property[] =
+{
+ { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSMediacontentManager::m_function[] =
+{
+ { CONTENT_FUNCTION_API_FIND_ITEMS, findItems, kJSPropertyAttributeNone },
+ { CONTENT_FUNCTION_API_GET_FOLDERS, getFolders, kJSPropertyAttributeNone },
+ { CONTENT_FUNCTION_API_UPDATE_ITEM, updateItem, kJSPropertyAttributeNone },
+ { CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH, updateItemsBatch, kJSPropertyAttributeNone },
+ { CONTENT_FUNCTION_API_SCAN_FILE, scanFile, kJSPropertyAttributeNone },
+ { CONTENT_FUNCTION_API_SET_CHANGE_LISTENER, setChangeListener, kJSPropertyAttributeNone },
+ { CONTENT_FUNCTION_API_UNSET_CHANGE_LISTENER, unsetChangeListener,kJSPropertyAttributeNone},
+ { 0, 0, 0 }
+};
+
+
+JSClassRef JSMediacontentManager::m_jsClassRef = NULL;
+
+JSClassDefinition JSMediacontentManager::m_classInfo =
+{
+ 0,
+ kJSClassAttributeNone,
+ TIZEN_CONTENT_MANAGER_ATTRIBUTENAME,
+ 0,
+ m_property,
+ m_function,
+ initialize,
+ finalize,
+ NULL, //hasProperty,
+ NULL, //getProperty,
+ NULL, //setProperty,
+ NULL, //deleteProperty,
+ NULL, //getPropertyNames,
+ NULL, //callAsFunction,
+ NULL, //callAsConstructor,
+ NULL,
+ NULL, //convertToType
+};
+
+JSValueRef JSMediacontentManager::getFolders(
+ JSContextRef context,
+ JSObjectRef object,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception )
+{
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+
+ MediacontentManagerPrivObject *privateObject;
+ privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+ if (!privateObject) {
+ DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+
+ JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
+
+ JSCallbackManagerPtr cbm(NULL);
+ cbm = JSCallbackManager::createObject(globalContext);
+
+ try{
+ ArgumentValidator argValidator(context, argumentCount, arguments);
+ JSObjectRef successCallbackObj = argValidator.toFunction(0);
+ if(successCallbackObj){
+ cbm->setOnSuccess(successCallbackObj);
+ }
+ else{
+ throw TypeMismatchException("SuccessCallback type mismatched.");
+ }
+
+ JSObjectRef errorCallbackObj = argValidator.toFunction(1,true);
+ if(errorCallbackObj){
+ cbm->setOnError(errorCallbackObj);
+ }
+ }catch(const BasePlatformException &err){
+ return JSWebAPIErrorFactory::postException(context,exception,err);
+ }
+ catch(...){
+ DeviceAPI::Common::UnknownException err("Unknown Error in ContentManager.getDirectories().");
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+
+ Try
+ {
+ IMediacontentManagerPtr contentMgr = privateObject->getObject();
+
+ IEventFindFolderPtr dplEvent(new IEventFindFolder());
+ dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
+ dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
+
+ contentMgr->findFolder(dplEvent);
+
+ MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+ }
+ Catch(WrtDeviceApis::Commons::UnsupportedException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(WrtDeviceApis::Commons::ConversionException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(WrtDeviceApis::Commons::NotFoundException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ }
+
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return JSValueMakeUndefined(context);
+
+}
+
+
+
+JSValueRef JSMediacontentManager::findItems(
+ JSContextRef context,
+ JSObjectRef object,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception )
+{
+
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+
+ MediacontentManagerPrivObject *privateObject;
+ privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+ if(!privateObject) {
+ DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+
+ AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_FIND_ITEMS);
+
+ TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+ JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
+
+ JSCallbackManagerPtr cbm(NULL);
+ MediaContentFilterConverterFactory::ConverterType fConverter = MediaContentFilterConverterFactory::getConverter(context);
+ MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
+
+ cbm = JSCallbackManager::createObject(globalContext);
+
+ string folderId;
+ Tizen::FilterPtr filter;
+ Tizen::SortModePtr sortPtr;
+ JSObjectRef filterObj;
+ JSObjectRef sortModeObj;
+ IEventBrowseFolderPtr dplEvent(new IEventBrowseFolder());
+ try{
+ ArgumentValidator argValidator(context, argumentCount, arguments);
+ JSObjectRef successCallbackObj = argValidator.toFunction(0);
+ if(successCallbackObj){
+ cbm->setOnSuccess(successCallbackObj);
+ }
+ else{
+ throw TypeMismatchException("SuccessCallback type mismatched.");
+ }
+
+ JSObjectRef errorCallbackObj = argValidator.toFunction(1,true);
+ if(errorCallbackObj){
+ cbm->setOnError(errorCallbackObj);
+ }
+
+ folderId = argValidator.toString(2, true);
+ if(!folderId.empty()){
+ if(folderId != "null" ){
+ dplEvent->setFolderID(folderId);
+ }
+ else if(folderId == "undefined"){
+ throw InvalidValuesException("folderId is not valid.");
+ }
+ }
+
+ //filter
+ filterObj = argValidator.toObject(3,true);
+
+ //sortMode
+ sortModeObj= argValidator.toObject(4,true);
+
+ // count
+ if(argumentCount >= 6){
+ if(!JSValueIsNull(context, arguments[5])){
+ long count = argValidator.toLong(5, true, 0);
+ if( count >= 0L ){
+ dplEvent->setLimit(count);
+ }
+ else{
+ throw InvalidValuesException( "count should be positive.");
+ }
+ }
+ }
+ if(argumentCount >= 7){
+ // offset
+ long offset = argValidator.toLong(6, true);
+ if( offset >= 0L ){
+ dplEvent->setOffset(offset);
+ }
+ else{
+ throw InvalidValuesException("offset should be positive.");
+ }
+ }
+ }catch(const BasePlatformException &err){
+ return JSWebAPIErrorFactory::postException(context,exception,err);
+ }
+ catch(...){
+ DeviceAPI::Common::UnknownException err("Unknown Error in find().");
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+
+ Try
+ {
+ if(filterObj){
+ dplEvent->setFilter(fConverter->toFilter(filterObj));
+ }
+ if(sortModeObj){
+ dplEvent->setSortMode(fConverter->toSortMode(sortModeObj));
+ }
+ IMediacontentManagerPtr contentMgr = privateObject->getObject();
+
+ dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
+ dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
+ contentMgr->browseFolder(dplEvent);
+ MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+ }
+ Catch(WrtDeviceApis::Commons::UnsupportedException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(WrtDeviceApis::Commons::ConversionException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(WrtDeviceApis::Commons::NotFoundException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ }
+
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return JSValueMakeUndefined(context);
+}
+
+
+
+JSValueRef JSMediacontentManager::updateItemsBatch(JSContextRef context,
+ JSObjectRef object,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+ MediacontentManagerPrivObject *privateObject;
+ privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+ if(!privateObject) {
+ DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+
+ JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
+ AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH);
+ TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+ JSCallbackManagerPtr cbm(NULL);
+ MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
+
+ cbm = JSCallbackManager::createObject(globalContext);
+
+ MediacontentMediaListPtr contents;
+ try{
+ ArgumentValidator argValidator(context, argumentCount, arguments);
+
+ if((argumentCount >= 1) && (JSIsArrayValue(context, arguments[0]))){
+ contents = converter->toVectorOfMediaItem(arguments[0]);
+ if(!contents)
+ {
+ throw TypeMismatchException( "content type mismatched.");
+ }
+ }
+ else{
+ throw TypeMismatchException("content type mismatched.");
+ }
+
+ JSObjectRef successCallbackObj = argValidator.toFunction(1,true);
+ if(successCallbackObj){
+ cbm->setOnSuccess(successCallbackObj);
+ }
+
+ JSObjectRef errorCallbackObj = argValidator.toFunction(2,true);
+ if(errorCallbackObj){
+ cbm->setOnError(errorCallbackObj);
+ }
+ }catch(const BasePlatformException &err){
+ return JSWebAPIErrorFactory::postException(context,exception,err);
+ }
+ catch(...){
+ DeviceAPI::Common::UnknownException err("Unknown Error in updateBatch().");
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+
+ Try
+ {
+ IMediacontentManagerPtr contentMgr = privateObject->getObject();
+
+ IEventUpdateMediaItemsPtr dplEvent(new IEventUpdateMediaItems());
+ dplEvent->setMediaItems(contents);
+ dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
+
+ dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
+ contentMgr->updateMediaItems(dplEvent);
+
+ MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+ }
+ Catch(WrtDeviceApis::Commons::UnsupportedException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(WrtDeviceApis::Commons::ConversionException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(WrtDeviceApis::Commons::NotFoundException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ }
+
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return JSValueMakeUndefined(context);
+}
+
+
+
+JSValueRef JSMediacontentManager::updateItem(
+ JSContextRef context,
+ JSObjectRef object,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+
+ MediacontentManagerPrivObject *privateObject;
+ privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+ if (!privateObject) {
+ DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+
+ AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_UPDATE_ITEM);
+ TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+ Try
+ {
+ IMediacontentManagerPtr contentMgr = privateObject->getObject();
+
+ //parameter : MediaItem item
+
+ JSObjectRef arg;
+ if(argumentCount >= 1)
+ {
+ if (!JSValueIsObjectOfClass(context, arguments[0], JSMedia::getClassRef()) &&
+ !JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef()) &&
+ !JSValueIsObjectOfClass(context, arguments[0], JSAudio::getClassRef()) &&
+ !JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())) {
+ ThrowMsg(ConversionException, "Content type mismatched.");
+ }
+ arg = JSValueToObject(context, arguments[0], exception);
+ }
+ else
+ {
+ ThrowMsg(ConversionException, "Content type mismatched.");
+ }
+
+ MediacontentMediaPtr event;
+ IEventUpdateMediaPtr dplEvent(new IEventUpdateMedia());
+
+ if(JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef())){
+ MediacontentImagePtr imgPtr = JSImage::getImageObject(arg);
+ JSValueRef geoValRef = JSUtil::getProperty(context , JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
+ if(!(JSValueIsNull(context, geoValRef) || JSValueIsUndefined(context, geoValRef))){
+ JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
+ double latitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "latitude"));
+ double longitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "longitude"));
+ if(ContentUtility::checkLocation(latitude, latitude)){
+ imgPtr->setImageLatitude(latitude);
+ imgPtr->setImageLongitude(longitude);
+ }
+ else{
+ ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "geolocation value is not valid.");
+ }
+ }
+ else
+ {
+ imgPtr->setImageLatitude(DEFAULT_GEOLOCATION);
+ imgPtr->setImageLongitude(DEFAULT_GEOLOCATION);
+ }
+ }
+ else if(JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())){
+ MediacontentVideoPtr vedioPtr = JSVideo::getVideoObject(arg);
+ JSValueRef geoValRef = JSUtil::getProperty(context , JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
+ if(!(JSValueIsNull(context, geoValRef) || JSValueIsUndefined(context, geoValRef))){
+ JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
+ double latitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "latitude"));
+ double longitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "longitude"));
+ if(ContentUtility::checkLocation(latitude, latitude)){
+ vedioPtr->setVideoLatitude(latitude);
+ vedioPtr->setVideoLongitude(longitude);
+ }
+ else{
+ ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "geolocation value is not valid.");
+ }
+ }
+ else
+ {
+ vedioPtr->setVideoLatitude(DEFAULT_GEOLOCATION);
+ vedioPtr->setVideoLongitude(DEFAULT_GEOLOCATION);
+ }
+ }
+
+ JSValueRef nameValRef = JSUtil::getProperty(context , JSUtil::JSValueToObject(context, arguments[0]), "name");
+ if((JSValueIsNull(context, nameValRef) || JSValueIsUndefined(context, nameValRef)) ||
+ JSUtil::JSValueToString(context, nameValRef) == ""){
+ ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "name is not valid.");
+ }
+ event = JSMedia::getMediaObject(arg);
+ dplEvent->setMediaItem(event);
+
+ dplEvent->setForSynchronousCall();
+ contentMgr->updateMedia(dplEvent);
+
+ if (!(dplEvent->getResult())) {
+ ThrowMsg(WrtDeviceApis::Commons::Exception, "updating failed by unknown reason.");
+ }
+ }
+ Catch(WrtDeviceApis::Commons::UnsupportedException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(WrtDeviceApis::Commons::ConversionException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(WrtDeviceApis::Commons::NotFoundException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ }
+
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return JSValueMakeUndefined(context);
+
+}
+
+static void _scanCompletedCallback(std::string err_msg, std::string path, void *user_data){
+ CallbackUserData *cb = static_cast<CallbackUserData*>(user_data);
+ if(cb != NULL){
+ if(err_msg.empty() ){
+ Converter converter(cb->getContext());
+ JSValueRef jsPath = converter.toJSValueRef(ContentUtility::convertPathToUri(path));
+ cb->callSuccessCallback(jsPath);
+ }
+ else{
+ DeviceAPI::Common::UnknownException err(err_msg.c_str());
+ JSObjectRef errorObject = JSWebAPIErrorFactory::makeErrorObject(cb->getContext(),err);
+ cb->callErrorCallback(errorObject);
+ }
+ delete cb;
+ }
+}
+
+JSValueRef JSMediacontentManager::scanFile(
+ JSContextRef context,
+ JSObjectRef object,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+
+ MediacontentManagerPrivObject *privateObject;
+ privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+ if(!privateObject) {
+ DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+
+ AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SCAN_FILE);
+ TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+ string path;
+ CallbackUserData *callback = NULL;
+ try{
+ callback = new CallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context));
+ ArgumentValidator argValidator(context, argumentCount, arguments);
+ path = argValidator.toString(0);
+ if(path.empty()){
+ throw TypeMismatchException("File path type mismatched.");
+ }
+ else if(path == "null" || path == "undefined"){
+ throw InvalidValuesException("File path is not valid.");
+ }
+ path = ContentUtility::convertUriToPath(path);
+
+ JSObjectRef successCallbackObj = argValidator.toFunction(1,true);
+ if(successCallbackObj){
+ callback->setSuccessCallback(successCallbackObj);
+ }
+
+ JSObjectRef errorCallbackObj = argValidator.toFunction(2,true);
+ if(errorCallbackObj){
+ callback->setErrorCallback(errorCallbackObj);
+ }
+ }catch(const BasePlatformException &err){
+ return JSWebAPIErrorFactory::postException(context,exception,err);
+ }
+ catch(...){
+ DeviceAPI::Common::UnknownException err("Unknown Error in scanFile().");
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+
+ Try
+ {
+ IMediacontentManagerPtr contentMgr = privateObject->getObject();
+ contentMgr->scanFile(_scanCompletedCallback,path,(void*)callback);
+ }
+ Catch(WrtDeviceApis::Commons::UnsupportedException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(WrtDeviceApis::Commons::ConversionException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(WrtDeviceApis::Commons::NotFoundException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ }
+
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSMediacontentManager::setChangeListener(
+ JSContextRef context,
+ JSObjectRef object,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+
+ MediacontentManagerPrivObject *privateObject;
+ privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+ if(!privateObject) {
+ DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+
+ AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
+ TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+ try{
+ ArgumentValidator argValidator(context, argumentCount, arguments);
+ JSContextRef globalCtx = GlobalContextManager::getInstance()->getGlobalContext(context);
+ JSObjectRef callbackObj = argValidator.toCallbackObject(0,false,"oncontentadded","oncontentupdated","oncontentremoved",NULL);
+ ContentListener *listener = new ContentListener(globalCtx, callbackObj);
+ IMediacontentManagerPtr contentMgr = privateObject->getObject();
+ if(!(contentMgr->setListener(listener)))
+ {
+ throw DeviceAPI::Common::UnknownException( "Unknown exception is occured by platfrom");
+ }
+ }catch(const BasePlatformException &err){
+ return JSWebAPIErrorFactory::postException(context,exception,err);
+ }
+ catch(...){
+ DeviceAPI::Common::UnknownException err("Unknown Error in setChangeListener().");
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMediacontentManager::unsetChangeListener(
+ JSContextRef context,
+ JSObjectRef object,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+ MediacontentManagerPrivObject *privateObject;
+ privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+ if(!privateObject) {
+ DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+
+ AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
+ TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+ try{
+ // perform
+ IMediacontentManagerPtr contentMgr = privateObject->getObject();
+ if(!(contentMgr->unsetListener()))
+ {
+ throw DeviceAPI::Common::UnknownException( "Unknown exception is occured by platfrom");
+ }
+ }catch(const BasePlatformException &err){
+ return JSWebAPIErrorFactory::postException(context,exception,err);
+ }
+ catch(...){
+ DeviceAPI::Common::UnknownException err("Unknown Error in unsetChangeListener().");
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return JSValueMakeUndefined(context);
+}
+
+const JSClassRef JSMediacontentManager::getClassRef() {
+ if (!m_jsClassRef) {
+ m_jsClassRef = JSClassCreate(&m_classInfo);
+ }
+ return m_jsClassRef;
+}
+
+
+const JSClassDefinition* JSMediacontentManager::getClassInfo()
+{
+ return &m_classInfo;
+}
+
+void JSMediacontentManager::initialize(JSContextRef context, JSObjectRef object)
+{
+ MediacontentManagerPrivObject *privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
+ if (NULL == privateObject)
+ {
+ IMediacontentManagerPtr contentManager = MediacontentFactory::getInstance().createMediacontentManagerObject();
+ privateObject = new MediacontentManagerPrivObject(context, contentManager);
+ if (!JSObjectSetPrivate(object, static_cast<void*>(privateObject)))
+ {
+ delete privateObject;
+ }
+ }
+
+}
+
+void JSMediacontentManager::finalize(JSObjectRef object)
+{
+ MediacontentManagerPrivObject* priv = static_cast<MediacontentManagerPrivObject*> (JSObjectGetPrivate(object));
+ if(priv != NULL)
+ {
+ delete priv;
+ JSObjectSetPrivate(object, NULL);
+ priv = NULL;
+ }
+
+}
+
+IMediacontentManagerPtr JSMediacontentManager::getContentManagerPrivObject(
+ JSContextRef ctx,
+ const JSObjectRef object,
+ JSValueRef* exception)
+{
+ MediacontentManagerPrivObject *priv = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
+ if (priv)
+ {
+ return priv->getObject();
+ }
+ ThrowMsg(ConversionException, "Private object is NULL.");
+}
+
+
+}
+}
+
+