upload tizen1.0 source
[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
45 using namespace TizenApis::Commons;
46 using namespace TizenApis::Api::Tizen;
47 using namespace TizenApis::Tizen1_0::Tizen;
48 using namespace WrtDeviceApis::Commons;
49 using namespace WrtDeviceApis::CommonsJavaScript;
50
51
52 #define TIZEN_MEDIACONTENT_ATTRIBUTENAME        "MediaSource"
53
54 namespace {
55     /**
56      * @throw InvalidArgumentException If not a callback nor JS null nor JS undefined.
57      */
58     JSValueRef getFunctionOrNull(JSContextRef ctx, JSValueRef arg) 
59     {
60       if (Validator(ctx).isCallback(arg)) 
61       {
62         return arg;
63       }
64       else if (!JSValueIsNull(ctx, arg) && !JSValueIsUndefined(ctx, arg)) 
65       {
66         ThrowMsg(InvalidArgumentException, "Not a function nor JS null.");
67       }
68       return NULL;
69     }
70 }
71
72 namespace TizenApis {
73 namespace Tizen1_0 { 
74 namespace Mediacontent {
75
76
77 JSClassDefinition JSMediacontent::m_classInfo =
78 {
79     0,
80     kJSClassAttributeNone,
81     TIZEN_MEDIACONTENT_ATTRIBUTENAME,
82     NULL,
83     m_property,
84     m_function,
85     initialize,
86     finalize,
87     NULL,//HasProperty,
88     NULL,//GetProperty,
89     NULL,//SetProperty,
90     NULL,//DeleteProperty,
91     NULL,//GetPropertyNames,
92     NULL,//CallAsFunction,
93     NULL,//CallAsConstructor,
94     NULL,//HasInstance,
95     NULL//ConvertToType
96 };
97
98 JSStaticValue JSMediacontent::m_property[] =
99 {
100     {0, 0, 0, 0}
101 };
102
103 JSStaticFunction JSMediacontent::m_function[] =
104 {
105     { "findItems", findItems, kJSPropertyAttributeNone },
106     { "getFolders", getFolders, kJSPropertyAttributeNone },
107     { "updateItem", updateItem, kJSPropertyAttributeNone },        
108     { "updateItemsBatch", updateItemsBatch, kJSPropertyAttributeNone },            
109     { 0, 0, 0 }
110 };
111
112 JSClassRef JSMediacontent::m_jsClassRef = JSClassCreate(JSMediacontent::getClassInfo());
113
114 void JSMediacontent::initialize(JSContextRef context, JSObjectRef object)
115 {
116     LogDebug("JSMediacontent::initialize entered");
117     MediacontentPrivObject *priv = static_cast<MediacontentPrivObject*>(JSObjectGetPrivate(object));
118     if (!priv) 
119         {
120         //create default instance
121         LogWarning("create default instance");
122         IMediacontentPtr mediacontent = MediacontentFactory::getInstance().createMediacontentObject();
123         priv = new MediacontentPrivObject(context, mediacontent);
124         if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) 
125                 {
126             delete priv;
127         }
128     } 
129         else
130     {
131         LogDebug("private object alrerady exists");
132     }
133
134 }
135
136 void JSMediacontent::finalize(JSObjectRef object)
137 {
138     LogDebug("entered");
139     MediacontentPrivObject *priv = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( object ) ) ;
140     if(priv != NULL)
141     {
142                 delete priv;
143                 priv = NULL;
144                 LogDebug("JSMediacontent::finalize entered");
145     }
146
147 }
148
149 const JSClassRef JSMediacontent::getClassRef()
150 {
151     if (!m_jsClassRef) 
152         {
153         m_jsClassRef = JSClassCreate(&m_classInfo);
154     }
155     return m_jsClassRef;
156 }
157
158 const JSClassDefinition* JSMediacontent::getClassInfo()
159 {
160     return &m_classInfo;
161 }
162
163 JSValueRef JSMediacontent::getFolders(
164                                                         JSContextRef context, 
165                                                         JSObjectRef object,
166                                                         JSObjectRef thisObject, 
167                                                         size_t argumentCount,
168                                                         const JSValueRef arguments[], 
169                                                         JSValueRef* exception )
170 {
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
195         // Protect the super object until the callback operation is finished.
196         JSValueProtect(globalContext, thisObject);
197
198     Try
199     {
200                 IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
201
202                 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
203
204                 if(argumentCount >= 1)  //MediaFolderArraySuccessCB successCallback
205                 {
206                         if(validator.isCallback(arguments[0]))
207                         {
208                                 onSuccessForCbm = arguments[0];
209                         }
210                         else
211                         {
212                                 LogDebug("SuccessCallback type mismatched.");
213                                 Throw(ConversionException);
214                         }
215                 }
216                 else
217                 {
218                         LogDebug("There is no successCallback.");
219                         Throw(ConversionException);
220                 }               
221                 if(argumentCount >= 2)  //optional ErrorCallback? errorCallback
222                 {       
223                         if(validator.isCallback(arguments[1]))
224                         {
225                                 onErrorForCbm = arguments[1];
226                         }
227                         else if(!validator.isNullOrUndefined(arguments[1]))             //nullable
228                         {
229                                 LogDebug("ErrorCallback type mismatched.");
230                                 Throw(ConversionException);                             
231                         }
232                 }
233                 if(cbm)
234                 {
235                         cbm->setOnSuccess(onSuccessForCbm);
236                         cbm->setOnError(onErrorForCbm);
237                 }
238
239         IEventFindFolderPtr dplEvent(new IEventFindFolder());
240         dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
241         dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
242
243         mediacontent->findFolder(dplEvent);
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
296         AceSecurityStatus status = MEDIACONTENT_CHECK_ACCESS(
297             MEDIACONTENT_FUNCTION_API_FIND_ITEMS);
298
299         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
300
301
302         JSContextRef globalContext = privateObject->getContext();
303         Validator validator(context);
304     JSCallbackManagerPtr cbm(NULL);
305     FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
306         MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
307         MediaConverter mediaConverter(globalContext);
308
309         cbm = JSCallbackManager::createObject(globalContext);
310
311         // Protect the super object until the callback operation is finished.
312         JSValueProtect(globalContext, thisObject);
313
314     Try
315     {
316                 IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
317                 IEventBrowseFolderPtr dplEvent(new IEventBrowseFolder());
318         JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
319
320                 if(argumentCount >= 1)  //MediaItemArraySuccessCB successCallback
321                 {
322                         if(validator.isCallback(arguments[0]))
323                         {
324                                 onSuccessForCbm = arguments[0];
325                         }
326                         else
327                         {
328                                 LogDebug("SuccessCallback type mismatched.");
329                                 Throw(ConversionException);
330                         }
331                 }
332                 else
333                 {
334                         LogDebug("There is no SuccessCallback.");
335                         Throw(ConversionException);
336                 }  
337                 if(argumentCount >= 2)  //ErrorCallback? errorCallback
338                 {       
339                         if(validator.isCallback(arguments[1]))
340                         {
341                                 onErrorForCbm = arguments[1];
342                         }
343                         else if(!validator.isNullOrUndefined(arguments[1]))             //nullable
344                         {
345                                 LogDebug("ErrorCallback type mismatched.");
346                                 Throw(ConversionException);                             
347                         }
348                 }
349                 if(cbm)
350                 {
351                         cbm->setOnSuccess(onSuccessForCbm);
352                         cbm->setOnError(onErrorForCbm);
353                 }
354
355                 if(argumentCount >= 3)  //MediaFolderId id,
356                 {
357                         string folderId = mediaConverter.toString(arguments[2]);
358                         if(!(validator.isNullOrUndefined(arguments[2])) && (folderId.length() > 0)  )
359                         {
360                                 LogDebug("folderId:"+ folderId);
361                                 dplEvent->setFolderID(folderId);
362                         }
363                 }               
364                 
365                 if(argumentCount >= 4)  //optional AbstractFilter? filter
366                 {
367                         if(JSValueIsObject(context, arguments[3]))
368                         {
369                                 dplEvent->setFilter(filterConverter->toFilter(arguments[3]));
370                         }
371                         else if(!validator.isNullOrUndefined(arguments[3]))             //nullable
372                         {
373                                 LogDebug("Filter type mismatched.");
374                                 Throw(ConversionException);
375                         }
376                 }
377                 if(argumentCount >= 5)  //optional SortMode? sortMode
378                 {
379                         if(JSValueIsObject(context, arguments[4]))
380                         {
381                                 LogDebug("sortmode is object");
382                                 // Though the sortMode is a single type, we save it in an array internally.
383                                 TizenApis::Api::Tizen::SortModeArrayPtr sortModes(new TizenApis::Api::Tizen::SortModeArray());
384                                 sortModes->push_back(filterConverter->toSortMode(arguments[4]));
385                                 dplEvent->setSortModes(sortModes);
386                         }
387                         else if(!validator.isNullOrUndefined(arguments[4]))             //nullable
388                         {
389                                 LogDebug("SortMode type mismatched.");
390                                 Throw(ConversionException);
391                         }
392                 }               
393                 if(argumentCount >= 6)  //optional unsigned long? count
394                 {
395                         long count = filterConverter->toLong(arguments[5]);
396                         if(count != 0.0)
397                         {
398                                 dplEvent->setLimit(count);
399                         }
400                         else
401                         {
402                                 dplEvent->setLimit(-1);
403                         }
404
405                 }               
406                 if(argumentCount >= 7)  //optional unsigned long? offset
407                 {
408                         long limit = filterConverter->toLong(arguments[6]);
409                         if(limit != 0.0)
410                         {
411                                 dplEvent->setLimit(limit);
412                         }
413                         else
414                         {
415                                 dplEvent->setLimit(-1);
416                         }
417                 }               
418         dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
419         dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
420         mediacontent->browseFolder(dplEvent);
421     }
422     Catch(UnsupportedException)
423     {
424                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
425         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
426     }
427     Catch(InvalidArgumentException)
428     {
429                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
430         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
431     }
432     Catch(ConversionException)
433     {
434                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
435         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
436     }
437     Catch (NotFoundException)
438     {
439                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
440         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
441     }
442     Catch(Exception)
443     {
444                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
445         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
446     }
447
448     return JSValueMakeUndefined(context);
449 }
450
451
452
453 JSValueRef JSMediacontent::updateItemsBatch(JSContextRef context,
454         JSObjectRef object,
455         JSObjectRef thisObject,
456         size_t argumentCount,
457         const JSValueRef arguments[],
458         JSValueRef* exception)
459 {
460     LogDebug("entered");
461
462         MediacontentPrivObject *privateObject;
463         
464         privateObject = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( thisObject ) ) ;
465         if (!privateObject)
466         {
467                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
468         }
469
470         JSContextRef globalContext = privateObject->getContext();
471         AceSecurityStatus status = MEDIACONTENT_CHECK_ACCESS(
472             MEDIACONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH);
473         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
474
475         Validator validator(context);
476     JSCallbackManagerPtr cbm(NULL);
477     FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
478         MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
479
480         cbm = JSCallbackManager::createObject(globalContext);
481
482         // Protect the super object until the callback operation is finished.
483         JSValueProtect(globalContext, thisObject);
484
485         Try
486     {
487
488                 IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
489
490                 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
491                 MediacontentMediaListPtr events;
492                 if((argumentCount >= 1) && (JSIsArrayValue(context, arguments[0])))     //MediaItem[] items
493                 {       
494                         events = converter->toVectorOfMediaItem(arguments[0]);
495                         if(!events) 
496                         {
497                                 ThrowMsg(ConversionException, "Items type mismatched.");
498                         }
499                 }
500                 else
501                 {
502                         ThrowMsg(ConversionException, "Items type mismatched.");
503                 }                       
504
505                 if(argumentCount >= 2)  //Function? successCallback, 
506                 {
507                         if(validator.isCallback(arguments[1]))
508                         {
509                                 onSuccessForCbm = arguments[1];
510                         }
511                         else if(!validator.isNullOrUndefined(arguments[1]))             //nullable
512                         {
513                                 LogDebug("successCallback type mismatched.");
514                                 Throw(ConversionException);                             
515                         }
516                 }
517         
518                 if(argumentCount >= 3)  //ErrorCallback? errorCallback, 
519                 {       
520                         if(validator.isCallback(arguments[2]))
521                         {
522                                 onErrorForCbm = arguments[2];
523                         }
524                         else if(!validator.isNullOrUndefined(arguments[2]))             //nullable
525                         {
526                                 LogDebug("ErrorCallback type is mismatched.");
527                                 Throw(ConversionException);                             
528                         }
529                 }
530
531                 if(cbm)
532                 {
533                         cbm->setOnSuccess(onSuccessForCbm);
534                         cbm->setOnError(onErrorForCbm);
535                 }
536                 
537         IEventUpdateMediaItemsPtr dplEvent(new IEventUpdateMediaItems());
538         dplEvent->setMediaItems(events);
539         dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
540         
541         dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance()); 
542         mediacontent->updateMediaItems(dplEvent);
543
544     }
545     Catch(UnsupportedException)
546     {
547                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
548         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
549     }
550     Catch(InvalidArgumentException)
551     {
552                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
553         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
554     }
555     Catch(ConversionException)
556     {
557                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
558         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
559     }
560     Catch (NotFoundException)
561     {
562                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
563         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
564     }
565     Catch(Exception)
566     {
567                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
568         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
569     }
570
571     return JSValueMakeUndefined(context);
572 }
573
574
575
576 JSValueRef JSMediacontent::updateItem(
577                                                 JSContextRef context,
578                                                 JSObjectRef object,
579                                                 JSObjectRef thisObject,
580                                                 size_t argumentCount,
581                                                 const JSValueRef arguments[],
582                                                 JSValueRef* exception)
583 {
584 LogDebug("updateItem::entered");
585
586
587         MediacontentPrivObject *privateObject;
588
589         privateObject = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( thisObject ) ) ;
590         if (!privateObject)
591         {
592                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
593         }
594         
595         AceSecurityStatus status = MEDIACONTENT_CHECK_ACCESS(
596             MEDIACONTENT_FUNCTION_API_UPDATE_ITEM);
597         
598         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
599
600         Validator validator(context);
601
602         Try
603         {               
604                 IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
605         
606                 //parameter : MediaItem item
607                 
608                 JSObjectRef arg;
609                 if(argumentCount >= 1)
610                 {
611                         if (!JSValueIsObjectOfClass(context, arguments[0], JSMedia::getClassRef()) &&
612                                 !JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef()) &&
613                                 !JSValueIsObjectOfClass(context, arguments[0], JSAudio::getClassRef()) &&                       
614                                 !JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())) {
615                                     ThrowMsg(ConversionException, "Item type mismatched.");
616                         }                       
617                         arg = JSValueToObject(context, arguments[0], exception);
618                 }
619                 else
620                 {
621                          ThrowMsg(ConversionException, "Item type mismatched.");
622                 }
623
624                 MediacontentMediaPtr event = JSMedia::getMediaObject(arg);
625
626                 IEventUpdateMediaPtr dplEvent(new IEventUpdateMedia());
627                 dplEvent->setMediaItem(event);
628                 dplEvent->setForSynchronousCall();
629                 mediacontent->updateMedia(dplEvent);
630
631         if (dplEvent->getResult()) {
632             return JSValueMakeUndefined(context);
633         } else {
634             ThrowMsg(UnknownException, "updating failed by unknown reason.");
635         }
636
637         }
638         Catch(UnsupportedException)
639         {
640                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
641                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
642         }
643         Catch(InvalidArgumentException)
644         {
645                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
646                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
647         }
648         Catch(ConversionException)
649         {
650                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
651                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
652         }
653         Catch (NotFoundException)
654         {
655                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
656                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
657         }
658         Catch(Exception)
659         {
660                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
661                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
662         }
663
664         return JSValueMakeUndefined(context);
665
666 }
667
668
669 IMediacontentPtr JSMediacontent::getMediacontentObject(
670                                                 JSContextRef ctx,
671                                         const JSObjectRef object,
672                                         JSValueRef* exception)
673 {
674     MediacontentPrivObject *priv = static_cast<MediacontentPrivObject*>(JSObjectGetPrivate(object));
675     if (priv) 
676         {
677         return priv->getObject();
678     }
679     ThrowMsg(ConversionException, "Private object is NULL.");
680 }
681
682
683 }
684 }
685 }