upload tizen1.0 source
[profile/ivi/wrt-plugins-tizen.git] / src / standards / Tizen / Mediacontent / JSMediacontent.cpp
index 3829db3..5ebcb25 100644 (file)
@@ -22,6 +22,9 @@
 #include <CommonsJavaScript/JSCallbackManager.h>
 #include <CommonsJavaScript/JSUtils.h>
 #include <CommonsJavaScript/JSPendingOperation.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/Utils.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
 
 #include <Tizen/Common/JSTizenExceptionFactory.h>
 #include <Tizen/Common/JSTizenException.h>
 #include "JSMediacontent.h"
 #include "JSMediacontentManager.h"
 #include "JSMedia.h"
+#include "JSImage.h"
+#include "JSVideo.h"
+#include "JSAudio.h"
 #include "MediaConverter.h"
 #include "plugin_config.h"
 
-
-
-
 using namespace TizenApis::Commons;
 using namespace TizenApis::Api::Tizen;
 using namespace TizenApis::Tizen1_0::Tizen;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
 
 
 #define TIZEN_MEDIACONTENT_ATTRIBUTENAME       "MediaSource"
@@ -97,9 +102,8 @@ JSStaticValue JSMediacontent::m_property[] =
 
 JSStaticFunction JSMediacontent::m_function[] =
 {
-    { "findItems", findMedia, kJSPropertyAttributeNone },
+    { "findItems", findItems, kJSPropertyAttributeNone },
     { "getFolders", getFolders, kJSPropertyAttributeNone },
-    { "browseFolder", browseFolder, kJSPropertyAttributeNone },    
     { "updateItem", updateItem, kJSPropertyAttributeNone },        
     { "updateItemsBatch", updateItemsBatch, kJSPropertyAttributeNone },            
     { 0, 0, 0 }
@@ -133,7 +137,13 @@ void JSMediacontent::finalize(JSObjectRef object)
 {
     LogDebug("entered");
     MediacontentPrivObject *priv = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( object ) ) ;
-    delete priv;
+    if(priv != NULL)
+    {
+               delete priv;
+               priv = NULL;
+               LogDebug("JSMediacontent::finalize entered");
+    }
+
 }
 
 const JSClassRef JSMediacontent::getClassRef()
@@ -150,104 +160,6 @@ const JSClassDefinition* JSMediacontent::getClassInfo()
     return &m_classInfo;
 }
 
-
-JSValueRef JSMediacontent::findMedia(
-                                                       JSContextRef context,
-                                                       JSObjectRef object,
-                                                       JSObjectRef thisObject,
-                                                       size_t argumentCount,
-                                                       const JSValueRef arguments[],
-                                                       JSValueRef* exception )
-{
-    LogDebug("JSMediacontent::findMedia entered");
-
-    MediacontentPrivObject *privateObject = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( thisObject ) ) ;
-    assert(privateObject);
-
-       AceSecurityStatus status = MEDIACONTENT_CHECK_ACCESS(privateObject->getContext(), MEDIACONTENT_FUNCTION_API_FIND_ITEMS);
-
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-    
-       JSContextRef globalContext = privateObject->getContext();
-       
-       Validator validator(context);
-    JSCallbackManagerPtr cbm(NULL);
-    FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
-       MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
-       cbm = JSCallbackManager::createObject(globalContext);
-
-       IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
-
-    Try
-    {
-        if (argumentCount == 0 ||
-            (!validator.isCallback(arguments[0])) ||
-            (argumentCount >= 2 && (!validator.isCallback(arguments[1]))) )
-        {
-            LogDebug("Argument type mismatch");
-            Throw(InvalidArgumentException);
-        }
-        if (cbm) 
-        {
-            JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-            onSuccessForCbm = arguments[0];
-            if (argumentCount >= 2) 
-            {
-                onErrorForCbm = arguments[1];
-            }
-            cbm->setOnSuccess(onSuccessForCbm);
-            cbm->setOnError(onErrorForCbm);
-               }
-
-       
-               IEventFindMediaPtr dplEvent(new IEventFindMedia());
-               dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
-               dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
-               
-        if (argumentCount >= 3 && !validator.isNullOrUndefined(arguments[2]))
-        {
-            dplEvent->setFilter(filterConverter->toFilter(arguments[2]));
-        }
-               if (argumentCount >= 4 && !validator.isNullOrUndefined(arguments[3])) 
-               {
-            // Though the sortMode is a single type, we save it in an array internally.
-            TizenApis::Api::Tizen::SortModeArrayPtr sortModes(new TizenApis::Api::Tizen::SortModeArray());
-            sortModes->push_back(filterConverter->toSortMode(arguments[3]));
-            dplEvent->setSortModes(sortModes);
-
-               }
-               if (argumentCount >= 5 && !validator.isNullOrUndefined(arguments[4])) 
-               {
-                       long limit = filterConverter->toLong(arguments[4]);
-                       dplEvent->setLimit(limit);
-               }
-               if (argumentCount >= 6 && !validator.isNullOrUndefined(arguments[5])) 
-               {
-                       long offset = filterConverter->toLong(arguments[5]);
-                       dplEvent->setOffset(offset);
-               }               
-
-               mediacontent->findMedia(dplEvent);
-               
-       }
-       Catch(InvalidArgumentException)
-       {
-               return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
-       }
-       Catch(ConversionException)
-       {
-               return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
-       }
-       Catch(Exception)
-       {
-               return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
-       }
-       
-       return JSValueMakeNull(context);
-
-}
-
-
 JSValueRef JSMediacontent::getFolders(
                                                        JSContextRef context, 
                                                        JSObjectRef object,
@@ -259,15 +171,19 @@ JSValueRef JSMediacontent::getFolders(
 
        LogDebug("JSMediacontent::findFolders entered");
 
-    MediacontentPrivObject *privateObject = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( thisObject ) ) ;
-    assert(privateObject);
-
+       MediacontentPrivObject *privateObject;
+       
+       privateObject = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( thisObject ) ) ;
+       if (!privateObject)
+       {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
 
-       AceSecurityStatus status = MEDIACONTENT_CHECK_ACCESS(privateObject->getContext(), MEDIACONTENT_FUNCTION_API_GET_FOLDERS);
+       AceSecurityStatus status = MEDIACONTENT_CHECK_ACCESS(
+            MEDIACONTENT_FUNCTION_API_GET_FOLDERS);
 
        TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
-
        JSContextRef globalContext = privateObject->getContext();
        Validator validator(context);
     JSCallbackManagerPtr cbm(NULL);
@@ -276,60 +192,88 @@ JSValueRef JSMediacontent::getFolders(
 
        cbm = JSCallbackManager::createObject(globalContext);
 
-       IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
+       // Protect the super object until the callback operation is finished.
+       JSValueProtect(globalContext, thisObject);
 
     Try
     {
+               IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
 
-        if ((!validator.isCallback(arguments[0])) ||
-            (argumentCount >= 2 && (!validator.isCallback(arguments[1]))) ||
-            (argumentCount >= 3 && (!JSValueIsObject(context, arguments[2]) && !validator.isNullOrUndefined(arguments[2])))) 
-               {
-            ThrowMsg(ConversionException, "Wrong parameter type.");
-        }
+               JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
 
-        if (cbm) 
-        {
-            JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-            onSuccessForCbm = arguments[0];
-            if (argumentCount >= 2) 
-            {
-                onErrorForCbm = arguments[1];
-            }
-                       if (argumentCount >= 3) 
-            {
-                               onErrorForCbm = arguments[2];
-            }
-            cbm->setOnSuccess(onSuccessForCbm);
-            cbm->setOnError(onErrorForCbm);
+               if(argumentCount >= 1)  //MediaFolderArraySuccessCB successCallback
+               {
+                       if(validator.isCallback(arguments[0]))
+                       {
+                               onSuccessForCbm = arguments[0];
+                       }
+                       else
+                       {
+                               LogDebug("SuccessCallback type mismatched.");
+                               Throw(ConversionException);
+                       }
+               }
+               else
+               {
+                       LogDebug("There is no successCallback.");
+                       Throw(ConversionException);
+               }               
+               if(argumentCount >= 2)  //optional ErrorCallback? errorCallback
+               {       
+                       if(validator.isCallback(arguments[1]))
+                       {
+                               onErrorForCbm = arguments[1];
+                       }
+                       else if(!validator.isNullOrUndefined(arguments[1]))             //nullable
+                       {
+                               LogDebug("ErrorCallback type mismatched.");
+                               Throw(ConversionException);                             
+                       }
+               }
+               if(cbm)
+               {
+                       cbm->setOnSuccess(onSuccessForCbm);
+                       cbm->setOnError(onErrorForCbm);
                }
 
         IEventFindFolderPtr dplEvent(new IEventFindFolder());
         dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
         dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
 
-
         mediacontent->findFolder(dplEvent);
     }
+    Catch(UnsupportedException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+    }
     Catch(InvalidArgumentException)
     {
-        return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(ConversionException)
     {
-        return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(Exception)
     {
-        return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
     }
 
-    return JSValueMakeNull(context);
+    return JSValueMakeUndefined(context);
 
 }
 
 
-JSValueRef JSMediacontent::browseFolder(
+JSValueRef JSMediacontent::findItems(
                                                        JSContextRef context, 
                                                        JSObjectRef object,
                                                        JSObjectRef thisObject, 
@@ -338,14 +282,19 @@ JSValueRef JSMediacontent::browseFolder(
                                                        JSValueRef* exception )
 {
 
-       LogDebug("JSMediacontent::browseFolder entered");
-
-    MediacontentPrivObject *privateObject = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( thisObject ) ) ;
-    assert(privateObject);
+       LogDebug("JSMediacontent::findItems entered");
 
+       MediacontentPrivObject *privateObject;
+       
+       privateObject = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( thisObject ) ) ;
+       if (!privateObject)
+       {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
 
 
-       AceSecurityStatus status = MEDIACONTENT_CHECK_ACCESS(privateObject->getContext(), MEDIACONTENT_FUNCTION_API_BROWSE_FOLDER);
+       AceSecurityStatus status = MEDIACONTENT_CHECK_ACCESS(
+            MEDIACONTENT_FUNCTION_API_FIND_ITEMS);
 
        TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
@@ -359,76 +308,144 @@ JSValueRef JSMediacontent::browseFolder(
 
        cbm = JSCallbackManager::createObject(globalContext);
 
-       IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
+       // Protect the super object until the callback operation is finished.
+       JSValueProtect(globalContext, thisObject);
 
     Try
     {
+               IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
+               IEventBrowseFolderPtr dplEvent(new IEventBrowseFolder());
+       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
 
-        if (argumentCount == 0 ||
-            (!validator.isCallback(arguments[1])) ||
-            (argumentCount >= 3 && (!validator.isCallback(arguments[2]))) ||
-            (argumentCount >= 4 && (!JSValueIsObject(context, arguments[3]) )) )
-        {
-            LogDebug("Argument type mismatch");
-            Throw(InvalidArgumentException);
-        }
-
-        if (cbm) 
-        {
-            JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-            onSuccessForCbm = arguments[1];
-            if (argumentCount >= 3) 
-            {
-                onErrorForCbm = arguments[2];
-            }
-            cbm->setOnSuccess(onSuccessForCbm);
-            cbm->setOnError(onErrorForCbm);
+               if(argumentCount >= 1)  //MediaItemArraySuccessCB successCallback
+               {
+                       if(validator.isCallback(arguments[0]))
+                       {
+                               onSuccessForCbm = arguments[0];
+                       }
+                       else
+                       {
+                               LogDebug("SuccessCallback type mismatched.");
+                               Throw(ConversionException);
+                       }
                }
-
-        IEventBrowseFolderPtr dplEvent(new IEventBrowseFolder());
-        dplEvent->setFolderID(mediaConverter.toString(arguments[0]));
-        dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
-        dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
-
-        if (argumentCount >= 4 && !validator.isNullOrUndefined(arguments[3]))
-        {
-            dplEvent->setFilter(filterConverter->toFilter(arguments[3]));
-        }
-               if (argumentCount >= 5 && !validator.isNullOrUndefined(arguments[4])) 
+               else
                {
-            TizenApis::Api::Tizen::SortModeArrayPtr sortModes(new TizenApis::Api::Tizen::SortModeArray());
-            sortModes->push_back(filterConverter->toSortMode(arguments[3]));
-            dplEvent->setSortModes(sortModes);
-
+                       LogDebug("There is no SuccessCallback.");
+                       Throw(ConversionException);
+               }  
+               if(argumentCount >= 2)  //ErrorCallback? errorCallback
+               {       
+                       if(validator.isCallback(arguments[1]))
+                       {
+                               onErrorForCbm = arguments[1];
+                       }
+                       else if(!validator.isNullOrUndefined(arguments[1]))             //nullable
+                       {
+                               LogDebug("ErrorCallback type mismatched.");
+                               Throw(ConversionException);                             
+                       }
                }
-               if (argumentCount >= 6 && !validator.isNullOrUndefined(arguments[5])) 
+               if(cbm)
+               {
+                       cbm->setOnSuccess(onSuccessForCbm);
+                       cbm->setOnError(onErrorForCbm);
+               }
+
+               if(argumentCount >= 3)  //MediaFolderId id,
+               {
+                       string folderId = mediaConverter.toString(arguments[2]);
+                       if(!(validator.isNullOrUndefined(arguments[2])) && (folderId.length() > 0)  )
+                       {
+                               LogDebug("folderId:"+ folderId);
+                               dplEvent->setFolderID(folderId);
+                       }
+               }               
+               
+               if(argumentCount >= 4)  //optional AbstractFilter? filter
                {
-                       long limit = filterConverter->toLong(arguments[5]);
-                       dplEvent->setLimit(limit);
+                       if(JSValueIsObject(context, arguments[3]))
+                       {
+                               dplEvent->setFilter(filterConverter->toFilter(arguments[3]));
+                       }
+                       else if(!validator.isNullOrUndefined(arguments[3]))             //nullable
+                       {
+                               LogDebug("Filter type mismatched.");
+                               Throw(ConversionException);
+                       }
                }
-               if (argumentCount >= 7 && !validator.isNullOrUndefined(arguments[6])) 
+               if(argumentCount >= 5)  //optional SortMode? sortMode
                {
-                       long offset = filterConverter->toLong(arguments[6]);
-                       dplEvent->setOffset(offset);
+                       if(JSValueIsObject(context, arguments[4]))
+                       {
+                               LogDebug("sortmode is object");
+                               // Though the sortMode is a single type, we save it in an array internally.
+                               TizenApis::Api::Tizen::SortModeArrayPtr sortModes(new TizenApis::Api::Tizen::SortModeArray());
+                               sortModes->push_back(filterConverter->toSortMode(arguments[4]));
+                               dplEvent->setSortModes(sortModes);
+                       }
+                       else if(!validator.isNullOrUndefined(arguments[4]))             //nullable
+                       {
+                               LogDebug("SortMode type mismatched.");
+                               Throw(ConversionException);
+                       }
                }               
+               if(argumentCount >= 6)  //optional unsigned long? count
+               {
+                       long count = filterConverter->toLong(arguments[5]);
+                       if(count != 0.0)
+                       {
+                               dplEvent->setLimit(count);
+                       }
+                       else
+                       {
+                               dplEvent->setLimit(-1);
+                       }
 
+               }               
+               if(argumentCount >= 7)  //optional unsigned long? offset
+               {
+                       long limit = filterConverter->toLong(arguments[6]);
+                       if(limit != 0.0)
+                       {
+                               dplEvent->setLimit(limit);
+                       }
+                       else
+                       {
+                               dplEvent->setLimit(-1);
+                       }
+               }               
+        dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
+        dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
         mediacontent->browseFolder(dplEvent);
     }
+    Catch(UnsupportedException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+    }
     Catch(InvalidArgumentException)
     {
-        return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(ConversionException)
     {
-        return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(Exception)
     {
-        return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
     }
 
-    return JSValueMakeNull(context);
-
+    return JSValueMakeUndefined(context);
 }
 
 
@@ -442,11 +459,17 @@ JSValueRef JSMediacontent::updateItemsBatch(JSContextRef context,
 {
     LogDebug("entered");
 
-    MediacontentPrivObject *privateObject = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( thisObject ) ) ;
-    assert(privateObject);
+       MediacontentPrivObject *privateObject;
+       
+       privateObject = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( thisObject ) ) ;
+       if (!privateObject)
+       {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
 
        JSContextRef globalContext = privateObject->getContext();
-       AceSecurityStatus status = MEDIACONTENT_CHECK_ACCESS(globalContext, MEDIACONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH);
+       AceSecurityStatus status = MEDIACONTENT_CHECK_ACCESS(
+            MEDIACONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH);
        TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
        Validator validator(context);
@@ -456,46 +479,68 @@ JSValueRef JSMediacontent::updateItemsBatch(JSContextRef context,
 
        cbm = JSCallbackManager::createObject(globalContext);
 
-       IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
+       // Protect the super object until the callback operation is finished.
+       JSValueProtect(globalContext, thisObject);
 
-    Try
+       Try
     {
-   
-        if (argumentCount>4 || argumentCount<1) {
-            ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
-        }
 
-        if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
-            ThrowMsg(ConversionException, "Wrong parameter type.");
-        }
+               IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
 
-        MediacontentMediaListPtr events;
-        
-               events = converter->toVectorOfEvents(arguments[0]);
-        if (!events) {
-            ThrowMsg(ConversionException, "Parameter conversion failed.");
-        }
-               if(cbm) 
-        {
-            JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-            if((argumentCount >= 2) && validator.isCallback(arguments[1]))
-            {
+               JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
+               MediacontentMediaListPtr events;
+               if((argumentCount >= 1) && (JSIsArrayValue(context, arguments[0])))     //MediaItem[] items
+               {       
+                       events = converter->toVectorOfMediaItem(arguments[0]);
+                       if(!events) 
+                       {
+                               ThrowMsg(ConversionException, "Items type mismatched.");
+                       }
+               }
+               else
+               {
+                       ThrowMsg(ConversionException, "Items type mismatched.");
+               }                       
+
+               if(argumentCount >= 2)  //Function? successCallback, 
+               {
+                       if(validator.isCallback(arguments[1]))
+                       {
                                onSuccessForCbm = arguments[1];
-            }
-            
-            if((argumentCount >= 3) && validator.isCallback(arguments[2])) 
-            {
+                       }
+                       else if(!validator.isNullOrUndefined(arguments[1]))             //nullable
+                       {
+                               LogDebug("successCallback type mismatched.");
+                               Throw(ConversionException);                             
+                       }
+               }
+       
+               if(argumentCount >= 3)  //ErrorCallback? errorCallback, 
+               {       
+                       if(validator.isCallback(arguments[2]))
+                       {
                                onErrorForCbm = arguments[2];
-            }
-            cbm->setOnSuccess(onSuccessForCbm);
-            cbm->setOnError(onErrorForCbm);
+                       }
+                       else if(!validator.isNullOrUndefined(arguments[2]))             //nullable
+                       {
+                               LogDebug("ErrorCallback type is mismatched.");
+                               Throw(ConversionException);                             
+                       }
+               }
+
+               if(cbm)
+               {
+                       cbm->setOnSuccess(onSuccessForCbm);
+                       cbm->setOnError(onErrorForCbm);
                }
+               
         IEventUpdateMediaItemsPtr dplEvent(new IEventUpdateMediaItems());
         dplEvent->setMediaItems(events);
         dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
         
         dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance()); 
         mediacontent->updateMediaItems(dplEvent);
+
     }
     Catch(UnsupportedException)
     {
@@ -523,7 +568,7 @@ JSValueRef JSMediacontent::updateItemsBatch(JSContextRef context,
         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
     }
 
-    return JSValueMakeNull(context);
+    return JSValueMakeUndefined(context);
 }
 
 
@@ -536,63 +581,89 @@ JSValueRef JSMediacontent::updateItem(
                                                const JSValueRef arguments[],
                                                JSValueRef* exception)
 {
-               LogDebug("updateItem::entered");
+LogDebug("updateItem::entered");
+
+
+       MediacontentPrivObject *privateObject;
 
+       privateObject = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( thisObject ) ) ;
+       if (!privateObject)
+       {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
        
-               MediacontentPrivObject *privateObject = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( thisObject ) ) ;
-               assert(privateObject);
-               
-               AceSecurityStatus status = MEDIACONTENT_CHECK_ACCESS(privateObject->getContext(), MEDIACONTENT_FUNCTION_API_UPDATE_ITEM);
-               
-               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+       AceSecurityStatus status = MEDIACONTENT_CHECK_ACCESS(
+            MEDIACONTENT_FUNCTION_API_UPDATE_ITEM);
+       
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
-               Validator validator(context);
-               IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
+       Validator validator(context);
 
-               Try
-               {               
-               if (argumentCount == 0 ||
-                   (!JSValueIsObject(context, arguments[0])) ||
-                   (argumentCount >= 2 && (!validator.isNullOrUndefined(arguments[1]) && (!validator.isCallback(arguments[1])))) ||
-                   (argumentCount >= 3 && (!validator.isNullOrUndefined(arguments[2]) && (!validator.isCallback(arguments[2])))) )
-               {
-                   LogDebug("Argument type mismatch");
-                   Throw(InvalidArgumentException);
-               }               
-                       JSObjectRef arg = JSValueToObject(context, arguments[0], exception);
-                       MediacontentMediaPtr event = JSMedia::getMediaObject(arg);
-
-                       IEventUpdateMediaPtr dplEvent(new IEventUpdateMedia());
-                       dplEvent->setMediaItem(event);
-                       dplEvent->setForSynchronousCall();
-                       mediacontent->updateMedia(dplEvent);
-                   if (dplEvent->getResult()) 
-                   {
-                   return JSValueMakeNull(context);
-           } 
-           else
-           {
-               ThrowMsg(UnknownException, "Updating failed by unkown reason.");
-               }
-               }
-               Catch(InvalidArgumentException)
-               {
-                   return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
-               }
-               Catch(ConversionException)
+       Try
+       {               
+               IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
+       
+               //parameter : MediaItem item
+               
+               JSObjectRef arg;
+               if(argumentCount >= 1)
                {
-                   return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
+                       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, "Item type mismatched.");
+                       }                       
+                       arg = JSValueToObject(context, arguments[0], exception);
                }
-               Catch(Exception)
+               else
                {
-                   return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
+                        ThrowMsg(ConversionException, "Item type mismatched.");
                }
 
-               return JSValueMakeNull(context);                
-}
+               MediacontentMediaPtr event = JSMedia::getMediaObject(arg);
 
+               IEventUpdateMediaPtr dplEvent(new IEventUpdateMedia());
+               dplEvent->setMediaItem(event);
+               dplEvent->setForSynchronousCall();
+               mediacontent->updateMedia(dplEvent);
 
+        if (dplEvent->getResult()) {
+            return JSValueMakeUndefined(context);
+        } else {
+            ThrowMsg(UnknownException, "updating failed by unknown reason.");
+        }
 
+       }
+       Catch(UnsupportedException)
+       {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+       }
+       Catch(InvalidArgumentException)
+       {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+       }
+       Catch(ConversionException)
+       {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+       }
+       Catch (NotFoundException)
+       {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+       }
+       Catch(Exception)
+       {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+       }
+
+       return JSValueMakeUndefined(context);
+
+}
 
 
 IMediacontentPtr JSMediacontent::getMediacontentObject(
@@ -605,7 +676,7 @@ IMediacontentPtr JSMediacontent::getMediacontentObject(
        {
         return priv->getObject();
     }
-    ThrowMsg(NullPointerException, "Private object is NULL.");
+    ThrowMsg(ConversionException, "Private object is NULL.");
 }