Fix build breaks in contact
[profile/ivi/wrt-plugins-tizen.git] / src / standards / Tizen / Mediacontent / JSMediacontent.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 3829db3..3141372
@@ -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"
-
-
-
+#include "MediaContentAsyncCallbackManager.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 +103,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 +138,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 +161,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,
@@ -256,18 +169,21 @@ JSValueRef JSMediacontent::getFolders(
                                                        const JSValueRef arguments[], 
                                                        JSValueRef* exception )
 {
-
        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);
@@ -275,61 +191,89 @@ JSValueRef JSMediacontent::getFolders(
        MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
 
        cbm = JSCallbackManager::createObject(globalContext);
-
-       IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
+       cbm->setObject(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);
+
+       MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+    }
+    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,18 @@ 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);
 
@@ -358,77 +306,165 @@ JSValueRef JSMediacontent::browseFolder(
        MediaConverter mediaConverter(globalContext);
 
        cbm = JSCallbackManager::createObject(globalContext);
+       cbm->setObject(thisObject);
 
-       IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
 
     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)
                {
-                       long limit = filterConverter->toLong(arguments[5]);
-                       dplEvent->setLimit(limit);
+                       cbm->setOnSuccess(onSuccessForCbm);
+                       cbm->setOnError(onErrorForCbm);
                }
-               if (argumentCount >= 7 && !validator.isNullOrUndefined(arguments[6])) 
+
+               if(argumentCount >= 3)  //MediaFolderId id,
                {
-                       long offset = filterConverter->toLong(arguments[6]);
-                       dplEvent->setOffset(offset);
+                       string folderId = mediaConverter.toString(arguments[2]);
+                       if(!(validator.isNullOrUndefined(arguments[2])) && (folderId.length() > 0)  )
+                       {
+                               LogDebug("folderId:"+ folderId);
+                               
+                               int nFolderId = 0;
+                               istringstream(folderId) >> nFolderId; //string -> int
+
+                               if (nFolderId<0)
+                               {
+                                       cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context,              
+                                               JSTizenException::INVALID_VALUES_ERROR, "Argument is invalid"));
+                                       return JSValueMakeUndefined(context);
+                               }
+                               
+                               dplEvent->setFolderID(folderId);
+                       }
                }               
+               
+               if(argumentCount >= 4)  //optional AbstractFilter? filter
+               {
+                       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 >= 5)  //optional SortMode? sortMode
+               {
 
+                       if ( JSValueIsObject(context, arguments[4]) && 
+                               !JSValueIsNull(context, arguments[4]) && 
+                               !JSValueIsUndefined(context, arguments[4]) &&
+                               !JSIsArrayValue(context, arguments[4]))
+                       {
+                               LogDebug("sortmode is object");
+                               dplEvent->setSortMode(filterConverter->toSortMode(arguments[4]));
+                       }
+                       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)
+                       {
+                               dplEvent->setLimit(count);
+                       }
+                       else if ( count == 0)
+                       {
+                               dplEvent->setLimit(-1); // -1 is all row.
+                       }
+                       else
+                       {
+                               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context,              
+                                       JSTizenException::INVALID_VALUES_ERROR, "Argument is invalid"));
+                               return JSValueMakeUndefined(context);
+                       }
+
+               }               
+               if(argumentCount >= 7)  //optional unsigned long? offset
+               {
+                       long offset = filterConverter->toLong(arguments[6]);
+                       if(offset != 0)
+                       {
+                               dplEvent->setOffset(offset);
+                       }
+                       else
+                       {
+                               dplEvent->setOffset(0); 
+                       }
+               }               
+        dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
+        dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
         mediacontent->browseFolder(dplEvent);
+
+       MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+    }
+    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 +478,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);
@@ -455,47 +497,68 @@ JSValueRef JSMediacontent::updateItemsBatch(JSContextRef context,
        MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
 
        cbm = JSCallbackManager::createObject(globalContext);
+       cbm->setObject(thisObject);
 
-       IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
-
-    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);
+
+       MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
     }
     Catch(UnsupportedException)
     {
@@ -523,7 +586,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 +599,88 @@ 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 +693,7 @@ IMediacontentPtr JSMediacontent::getMediacontentObject(
        {
         return priv->getObject();
     }
-    ThrowMsg(NullPointerException, "Private object is NULL.");
+    ThrowMsg(ConversionException, "Private object is NULL.");
 }