bad5baa6dd1621675491ca5eaeb49ec47683493d
[profile/ivi/wrt-plugins-tizen.git] / src / standards / Tizen / Mediacontent / JSMediacontent.cpp
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. 
15 */
16
17
18
19 #include <dpl/log/log.h>
20 #include <CommonsJavaScript/Validator.h>
21 #include <CommonsJavaScript/Converter.h>
22 #include <CommonsJavaScript/JSCallbackManager.h>
23 #include <CommonsJavaScript/JSUtils.h>
24 #include <CommonsJavaScript/JSPendingOperation.h>
25 #include <CommonsJavaScript/PrivateObject.h>
26 #include <CommonsJavaScript/Utils.h>
27 #include <CommonsJavaScript/ScopedJSStringRef.h>
28
29 #include <Tizen/Common/JSTizenExceptionFactory.h>
30 #include <Tizen/Common/JSTizenException.h>
31 #include <Tizen/Common/SecurityExceptions.h>
32 #include <Tizen/Tizen/FilterConverter.h>
33
34 #include <API/Mediacontent/MediacontentFactory.h>
35 #include "MediacontentController.h"
36 #include "JSMediacontent.h"
37 #include "JSMediacontentManager.h"
38 #include "JSMedia.h"
39 #include "JSImage.h"
40 #include "JSVideo.h"
41 #include "JSAudio.h"
42 #include "MediaConverter.h"
43 #include "plugin_config.h"
44 #include "MediaContentAsyncCallbackManager.h"
45
46 using namespace TizenApis::Commons;
47 using namespace TizenApis::Api::Tizen;
48 using namespace TizenApis::Tizen1_0::Tizen;
49 using namespace WrtDeviceApis::Commons;
50 using namespace WrtDeviceApis::CommonsJavaScript;
51
52
53 #define TIZEN_MEDIACONTENT_ATTRIBUTENAME        "MediaSource"
54
55 namespace {
56     /**
57      * @throw InvalidArgumentException If not a callback nor JS null nor JS undefined.
58      */
59     JSValueRef getFunctionOrNull(JSContextRef ctx, JSValueRef arg) 
60     {
61       if (Validator(ctx).isCallback(arg)) 
62       {
63         return arg;
64       }
65       else if (!JSValueIsNull(ctx, arg) && !JSValueIsUndefined(ctx, arg)) 
66       {
67         ThrowMsg(InvalidArgumentException, "Not a function nor JS null.");
68       }
69       return NULL;
70     }
71 }
72
73 namespace TizenApis {
74 namespace Tizen1_0 { 
75 namespace Mediacontent {
76
77
78 JSClassDefinition JSMediacontent::m_classInfo =
79 {
80     0,
81     kJSClassAttributeNone,
82     TIZEN_MEDIACONTENT_ATTRIBUTENAME,
83     NULL,
84     m_property,
85     m_function,
86     initialize,
87     finalize,
88     NULL,//HasProperty,
89     NULL,//GetProperty,
90     NULL,//SetProperty,
91     NULL,//DeleteProperty,
92     NULL,//GetPropertyNames,
93     NULL,//CallAsFunction,
94     NULL,//CallAsConstructor,
95     NULL,//HasInstance,
96     NULL//ConvertToType
97 };
98
99 JSStaticValue JSMediacontent::m_property[] =
100 {
101     {0, 0, 0, 0}
102 };
103
104 JSStaticFunction JSMediacontent::m_function[] =
105 {
106     { "findItems", findItems, kJSPropertyAttributeNone },
107     { "getFolders", getFolders, kJSPropertyAttributeNone },
108     { "updateItem", updateItem, kJSPropertyAttributeNone },        
109     { "updateItemsBatch", updateItemsBatch, kJSPropertyAttributeNone },            
110     { 0, 0, 0 }
111 };
112
113 JSClassRef JSMediacontent::m_jsClassRef = JSClassCreate(JSMediacontent::getClassInfo());
114
115 void JSMediacontent::initialize(JSContextRef context, JSObjectRef object)
116 {
117     LogDebug("JSMediacontent::initialize entered");
118     MediacontentPrivObject *priv = static_cast<MediacontentPrivObject*>(JSObjectGetPrivate(object));
119     if (!priv) 
120         {
121         //create default instance
122         LogWarning("create default instance");
123         IMediacontentPtr mediacontent = MediacontentFactory::getInstance().createMediacontentObject();
124         priv = new MediacontentPrivObject(context, mediacontent);
125         if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) 
126                 {
127             delete priv;
128         }
129     } 
130         else
131     {
132         LogDebug("private object alrerady exists");
133     }
134
135 }
136
137 void JSMediacontent::finalize(JSObjectRef object)
138 {
139     LogDebug("entered");
140     MediacontentPrivObject *priv = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( object ) ) ;
141     if(priv != NULL)
142     {
143                 delete priv;
144                 priv = NULL;
145                 LogDebug("JSMediacontent::finalize entered");
146     }
147
148 }
149
150 const JSClassRef JSMediacontent::getClassRef()
151 {
152     if (!m_jsClassRef) 
153         {
154         m_jsClassRef = JSClassCreate(&m_classInfo);
155     }
156     return m_jsClassRef;
157 }
158
159 const JSClassDefinition* JSMediacontent::getClassInfo()
160 {
161     return &m_classInfo;
162 }
163
164 JSValueRef JSMediacontent::getFolders(
165                                                         JSContextRef context, 
166                                                         JSObjectRef object,
167                                                         JSObjectRef thisObject, 
168                                                         size_t argumentCount,
169                                                         const JSValueRef arguments[], 
170                                                         JSValueRef* exception )
171 {
172         LogDebug("JSMediacontent::findFolders entered");
173
174         MediacontentPrivObject *privateObject;
175         
176         privateObject = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( thisObject ) ) ;
177         if (!privateObject)
178         {
179                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
180         }
181
182         AceSecurityStatus status = MEDIACONTENT_CHECK_ACCESS(
183             MEDIACONTENT_FUNCTION_API_GET_FOLDERS);
184
185         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
186
187         JSContextRef globalContext = privateObject->getContext();
188         Validator validator(context);
189     JSCallbackManagerPtr cbm(NULL);
190     FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
191         MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
192
193         cbm = JSCallbackManager::createObject(globalContext);
194         cbm->setObject(thisObject);
195
196     Try
197     {
198                 IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
199
200                 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
201
202                 if(argumentCount >= 1)  //MediaFolderArraySuccessCB successCallback
203                 {
204                         if(validator.isCallback(arguments[0]))
205                         {
206                                 onSuccessForCbm = arguments[0];
207                         }
208                         else
209                         {
210                                 LogDebug("SuccessCallback type mismatched.");
211                                 Throw(ConversionException);
212                         }
213                 }
214                 else
215                 {
216                         LogDebug("There is no successCallback.");
217                         Throw(ConversionException);
218                 }               
219                 if(argumentCount >= 2)  //optional ErrorCallback? errorCallback
220                 {       
221                         if(validator.isCallback(arguments[1]))
222                         {
223                                 onErrorForCbm = arguments[1];
224                         }
225                         else if(!validator.isNullOrUndefined(arguments[1]))             //nullable
226                         {
227                                 LogDebug("ErrorCallback type mismatched.");
228                                 Throw(ConversionException);                             
229                         }
230                 }
231                 if(cbm)
232                 {
233                         cbm->setOnSuccess(onSuccessForCbm);
234                         cbm->setOnError(onErrorForCbm);
235                 }
236
237         IEventFindFolderPtr dplEvent(new IEventFindFolder());
238         dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
239         dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
240
241         mediacontent->findFolder(dplEvent);
242
243         MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
244     }
245     Catch(UnsupportedException)
246     {
247                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
248         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
249     }
250     Catch(InvalidArgumentException)
251     {
252                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
253         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
254     }
255     Catch(ConversionException)
256     {
257                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
258         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
259     }
260     Catch (NotFoundException)
261     {
262                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
263         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
264     }
265     Catch(Exception)
266     {
267                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
268         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
269     }
270
271     return JSValueMakeUndefined(context);
272
273 }
274
275
276 JSValueRef JSMediacontent::findItems(
277                                                         JSContextRef context, 
278                                                         JSObjectRef object,
279                                                         JSObjectRef thisObject, 
280                                                         size_t argumentCount,
281                                                         const JSValueRef arguments[], 
282                                                         JSValueRef* exception )
283 {
284
285         LogDebug("JSMediacontent::findItems entered");
286
287         MediacontentPrivObject *privateObject;
288         
289         privateObject = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( thisObject ) ) ;
290         if (!privateObject)
291         {
292                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
293         }
294
295         AceSecurityStatus status = MEDIACONTENT_CHECK_ACCESS(
296             MEDIACONTENT_FUNCTION_API_FIND_ITEMS);
297
298         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
299
300
301         JSContextRef globalContext = privateObject->getContext();
302         Validator validator(context);
303     JSCallbackManagerPtr cbm(NULL);
304     FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
305         MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
306         MediaConverter mediaConverter(globalContext);
307
308         cbm = JSCallbackManager::createObject(globalContext);
309         cbm->setObject(thisObject);
310
311
312     Try
313     {
314                 IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
315                 IEventBrowseFolderPtr dplEvent(new IEventBrowseFolder());
316                 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
317
318                 if(argumentCount >= 1)  //MediaItemArraySuccessCB successCallback
319                 {
320                         if(validator.isCallback(arguments[0]))
321                         {
322                                 onSuccessForCbm = arguments[0];
323                         }
324                         else
325                         {
326                                 LogDebug("SuccessCallback type mismatched.");
327                                 Throw(ConversionException);
328                         }
329                 }
330                 else
331                 {
332                         LogDebug("There is no SuccessCallback.");
333                         Throw(ConversionException);
334                 }  
335                 if(argumentCount >= 2)  //ErrorCallback? errorCallback
336                 {       
337                         if(validator.isCallback(arguments[1]))
338                         {
339                                 onErrorForCbm = arguments[1];
340                         }
341                         else if(!validator.isNullOrUndefined(arguments[1]))             //nullable
342                         {
343                                 LogDebug("ErrorCallback type mismatched.");
344                                 Throw(ConversionException);                             
345                         }
346                 }
347                 if(cbm)
348                 {
349                         cbm->setOnSuccess(onSuccessForCbm);
350                         cbm->setOnError(onErrorForCbm);
351                 }
352
353                 if(argumentCount >= 3)  //MediaFolderId id,
354                 {
355                         string folderId = mediaConverter.toString(arguments[2]);
356                         if(!(validator.isNullOrUndefined(arguments[2])) && (folderId.length() > 0)  )
357                         {
358                                 LogDebug("folderId:"+ folderId);
359                                 
360                                 int nFolderId = 0;
361                                 istringstream(folderId) >> nFolderId; //string -> int
362
363                                 if (nFolderId<0)
364                                 {
365                                         cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context,              
366                                                 JSTizenException::INVALID_VALUES_ERROR, "Argument is invalid"));
367                                         return JSValueMakeUndefined(context);
368                                 }
369                                 
370                                 dplEvent->setFolderID(folderId);
371                         }
372                 }               
373                 
374                 if(argumentCount >= 4)  //optional AbstractFilter? filter
375                 {
376                         if(JSValueIsObject(context, arguments[3]))
377                         {
378                                 dplEvent->setFilter(filterConverter->toFilter(arguments[3]));
379                         }
380                         else if(!validator.isNullOrUndefined(arguments[3]))             //nullable
381                         {
382                                 LogDebug("Filter type mismatched.");
383                                 Throw(ConversionException);
384                         }
385                 }
386                 if(argumentCount >= 5)  //optional SortMode? sortMode
387                 {
388
389                         if ( JSValueIsObject(context, arguments[4]) && 
390                                 !JSValueIsNull(context, arguments[4]) && 
391                                 !JSValueIsUndefined(context, arguments[4]) &&
392                                 !JSIsArrayValue(context, arguments[4]))
393                         {
394                                 LogDebug("sortmode is object");
395                                 dplEvent->setSortMode(filterConverter->toSortMode(arguments[4]));
396                         }
397                         else if(!validator.isNullOrUndefined(arguments[4]))             //nullable
398                         {
399                                 LogDebug("SortMode type mismatched.");
400                                 Throw(ConversionException);
401                         }
402                 }               
403                 if(argumentCount >= 6)  //optional unsigned long? count
404                 {
405                         long count = filterConverter->toLong(arguments[5]);
406
407                         if(count > 0.0)
408                         {
409                                 dplEvent->setLimit(count);
410                         }
411                         else if ( count == 0.0)
412                         {
413                                 dplEvent->setLimit(-1);
414                         }
415                         else
416                         {
417                                 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context,              
418                                         JSTizenException::INVALID_VALUES_ERROR, "Argument is invalid"));
419                                 return JSValueMakeUndefined(context);
420                         }
421
422                 }               
423                 if(argumentCount >= 7)  //optional unsigned long? offset
424                 {
425                         long offset = filterConverter->toLong(arguments[6]);
426                         if(offset != 0.0)
427                         {
428                                 dplEvent->setOffset(offset);
429                         }
430                         else
431                         {
432                                 dplEvent->setOffset(-1);
433                         }
434                 }               
435         dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
436         dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
437         mediacontent->browseFolder(dplEvent);
438
439         MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
440     }
441     Catch(UnsupportedException)
442     {
443                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
444         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
445     }
446     Catch(InvalidArgumentException)
447     {
448                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
449         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
450     }
451     Catch(ConversionException)
452     {
453                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
454         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
455     }
456     Catch (NotFoundException)
457     {
458                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
459         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
460     }
461     Catch(Exception)
462     {
463                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
464         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
465     }
466
467     return JSValueMakeUndefined(context);
468 }
469
470
471
472 JSValueRef JSMediacontent::updateItemsBatch(JSContextRef context,
473         JSObjectRef object,
474         JSObjectRef thisObject,
475         size_t argumentCount,
476         const JSValueRef arguments[],
477         JSValueRef* exception)
478 {
479     LogDebug("entered");
480
481         MediacontentPrivObject *privateObject;
482         
483         privateObject = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( thisObject ) ) ;
484         if (!privateObject)
485         {
486                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
487         }
488
489         JSContextRef globalContext = privateObject->getContext();
490         AceSecurityStatus status = MEDIACONTENT_CHECK_ACCESS(
491             MEDIACONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH);
492         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
493
494         Validator validator(context);
495     JSCallbackManagerPtr cbm(NULL);
496     FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
497         MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
498
499         cbm = JSCallbackManager::createObject(globalContext);
500         cbm->setObject(thisObject);
501
502         Try
503     {
504
505                 IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
506
507                 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
508                 MediacontentMediaListPtr events;
509                 if((argumentCount >= 1) && (JSIsArrayValue(context, arguments[0])))     //MediaItem[] items
510                 {       
511                         events = converter->toVectorOfMediaItem(arguments[0]);
512                         if(!events) 
513                         {
514                                 ThrowMsg(ConversionException, "Items type mismatched.");
515                         }
516                 }
517                 else
518                 {
519                         ThrowMsg(ConversionException, "Items type mismatched.");
520                 }                       
521
522                 if(argumentCount >= 2)  //Function? successCallback, 
523                 {
524                         if(validator.isCallback(arguments[1]))
525                         {
526                                 onSuccessForCbm = arguments[1];
527                         }
528                         else if(!validator.isNullOrUndefined(arguments[1]))             //nullable
529                         {
530                                 LogDebug("successCallback type mismatched.");
531                                 Throw(ConversionException);                             
532                         }
533                 }
534         
535                 if(argumentCount >= 3)  //ErrorCallback? errorCallback, 
536                 {       
537                         if(validator.isCallback(arguments[2]))
538                         {
539                                 onErrorForCbm = arguments[2];
540                         }
541                         else if(!validator.isNullOrUndefined(arguments[2]))             //nullable
542                         {
543                                 LogDebug("ErrorCallback type is mismatched.");
544                                 Throw(ConversionException);                             
545                         }
546                 }
547
548                 if(cbm)
549                 {
550                         cbm->setOnSuccess(onSuccessForCbm);
551                         cbm->setOnError(onErrorForCbm);
552                 }
553                 
554         IEventUpdateMediaItemsPtr dplEvent(new IEventUpdateMediaItems());
555         dplEvent->setMediaItems(events);
556         dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
557         
558         dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance()); 
559         mediacontent->updateMediaItems(dplEvent);
560
561         MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
562     }
563     Catch(UnsupportedException)
564     {
565                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
566         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
567     }
568     Catch(InvalidArgumentException)
569     {
570                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
571         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
572     }
573     Catch(ConversionException)
574     {
575                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
576         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
577     }
578     Catch (NotFoundException)
579     {
580                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
581         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
582     }
583     Catch(Exception)
584     {
585                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
586         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
587     }
588
589     return JSValueMakeUndefined(context);
590 }
591
592
593
594 JSValueRef JSMediacontent::updateItem(
595                                                 JSContextRef context,
596                                                 JSObjectRef object,
597                                                 JSObjectRef thisObject,
598                                                 size_t argumentCount,
599                                                 const JSValueRef arguments[],
600                                                 JSValueRef* exception)
601 {
602 LogDebug("updateItem::entered");
603
604
605         MediacontentPrivObject *privateObject;
606
607         privateObject = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( thisObject ) ) ;
608         if (!privateObject)
609         {
610                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
611         }
612         
613         AceSecurityStatus status = MEDIACONTENT_CHECK_ACCESS(MEDIACONTENT_FUNCTION_API_UPDATE_ITEM);
614         
615         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
616
617         Validator validator(context);
618
619         Try
620         {               
621                 IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
622         
623                 //parameter : MediaItem item
624                 
625                 JSObjectRef arg;
626                 if(argumentCount >= 1)
627                 {
628                         if (!JSValueIsObjectOfClass(context, arguments[0], JSMedia::getClassRef()) &&
629                                 !JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef()) &&
630                                 !JSValueIsObjectOfClass(context, arguments[0], JSAudio::getClassRef()) &&                       
631                                 !JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())) {
632                                     ThrowMsg(ConversionException, "Item type mismatched.");
633                         }                       
634                         arg = JSValueToObject(context, arguments[0], exception);
635                 }
636                 else
637                 {
638                          ThrowMsg(ConversionException, "Item type mismatched.");
639                 }
640
641                 MediacontentMediaPtr event = JSMedia::getMediaObject(arg);
642
643                 IEventUpdateMediaPtr dplEvent(new IEventUpdateMedia());
644                 dplEvent->setMediaItem(event);
645                 dplEvent->setForSynchronousCall();
646                 mediacontent->updateMedia(dplEvent);
647
648         if (dplEvent->getResult()) {
649             return JSValueMakeUndefined(context);
650         } else {
651             ThrowMsg(UnknownException, "updating failed by unknown reason.");
652         }
653
654         }
655         Catch(UnsupportedException)
656         {
657                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
658                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
659         }
660         Catch(InvalidArgumentException)
661         {
662                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
663                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
664         }
665         Catch(ConversionException)
666         {
667                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
668                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
669         }
670         Catch (NotFoundException)
671         {
672                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
673                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
674         }
675         Catch(Exception)
676         {
677                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
678                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
679         }
680
681         return JSValueMakeUndefined(context);
682
683 }
684
685
686 IMediacontentPtr JSMediacontent::getMediacontentObject(
687                                                 JSContextRef ctx,
688                                         const JSObjectRef object,
689                                         JSValueRef* exception)
690 {
691     MediacontentPrivObject *priv = static_cast<MediacontentPrivObject*>(JSObjectGetPrivate(object));
692     if (priv) 
693         {
694         return priv->getObject();
695     }
696     ThrowMsg(ConversionException, "Private object is NULL.");
697 }
698
699
700 }
701 }
702 }