Beta merge 2
[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
26 #include <Tizen/Common/JSTizenExceptionFactory.h>
27 #include <Tizen/Common/JSTizenException.h>
28 #include <Tizen/Common/SecurityExceptions.h>
29 #include <Tizen/Tizen/FilterConverter.h>
30
31
32
33 #include <API/Mediacontent/MediacontentFactory.h>
34 #include "MediacontentController.h"
35 #include "JSMediacontent.h"
36 #include "JSMediacontentManager.h"
37 #include "JSMedia.h"
38 #include "MediaConverter.h"
39
40 using namespace TizenApis::Commons;
41 using namespace TizenApis::Api::Tizen;
42 using namespace TizenApis::Tizen1_0::Tizen;
43
44
45 #define TIZEN_MEDIACONTENT_ATTRIBUTENAME        "MediaSource"
46
47 namespace {
48     /**
49      * @throw InvalidArgumentException If not a callback nor JS null nor JS undefined.
50      */
51     JSValueRef getFunctionOrNull(JSContextRef ctx, JSValueRef arg) 
52     {
53       if (Validator(ctx).isCallback(arg)) 
54       {
55         return arg;
56       }
57       else if (!JSValueIsNull(ctx, arg) && !JSValueIsUndefined(ctx, arg)) 
58       {
59         ThrowMsg(InvalidArgumentException, "Not a function nor JS null.");
60       }
61       return NULL;
62     }
63 }
64
65 namespace TizenApis {
66 namespace Tizen1_0 { 
67 namespace Mediacontent {
68
69
70 JSClassDefinition JSMediacontent::m_classInfo =
71 {
72     0,
73     kJSClassAttributeNone,
74     TIZEN_MEDIACONTENT_ATTRIBUTENAME,
75     NULL,
76     m_property,
77     m_function,
78     initialize,
79     finalize,
80     NULL,//HasProperty,
81     NULL,//GetProperty,
82     NULL,//SetProperty,
83     NULL,//DeleteProperty,
84     NULL,//GetPropertyNames,
85     NULL,//CallAsFunction,
86     NULL,//CallAsConstructor,
87     NULL,//HasInstance,
88     NULL//ConvertToType
89 };
90
91 JSStaticValue JSMediacontent::m_property[] =
92 {
93     {0, 0, 0, 0}
94 };
95
96 JSStaticFunction JSMediacontent::m_function[] =
97 {
98     { "findItems", findMedia, kJSPropertyAttributeNone },
99     { "findFolders", findFolders, kJSPropertyAttributeNone },
100     { "updateItem", updateItem, kJSPropertyAttributeNone },    
101     { 0, 0, 0 }
102 };
103
104 JSClassRef JSMediacontent::m_jsClassRef = JSClassCreate(JSMediacontent::getClassInfo());
105
106 void JSMediacontent::initialize(JSContextRef context, JSObjectRef object)
107 {
108     LogDebug("JSMediacontent::initialize entered");
109     MediacontentPrivObject *priv = static_cast<MediacontentPrivObject*>(JSObjectGetPrivate(object));
110     if (!priv) 
111         {
112         //create default instance
113         LogWarning("create default instance");
114         IMediacontentPtr mediacontent = MediacontentFactory::getInstance().createMediacontentObject();
115         priv = new MediacontentPrivObject(context, mediacontent);
116         if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) 
117                 {
118             delete priv;
119         }
120     } 
121         else
122     {
123         LogDebug("private object alrerady exists");
124     }
125
126 }
127
128 void JSMediacontent::finalize(JSObjectRef object)
129 {
130     LogDebug("entered");
131     MediacontentPrivObject *priv = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( object ) ) ;
132     delete priv;
133 }
134
135 const JSClassRef JSMediacontent::getClassRef()
136 {
137     if (!m_jsClassRef) 
138         {
139         m_jsClassRef = JSClassCreate(&m_classInfo);
140     }
141     return m_jsClassRef;
142 }
143
144 const JSClassDefinition* JSMediacontent::getClassInfo()
145 {
146     return &m_classInfo;
147 }
148
149
150 JSValueRef JSMediacontent::findMedia(
151                                                         JSContextRef context,
152                                                         JSObjectRef object,
153                                                         JSObjectRef thisObject,
154                                                         size_t argumentCount,
155                                                         const JSValueRef arguments[],
156                                                         JSValueRef* exception )
157 {
158     LogDebug("JSMediacontent::findMedia entered");
159
160     MediacontentPrivObject *privateObject = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( thisObject ) ) ;
161     assert(privateObject);
162     
163         JSContextRef globalContext = privateObject->getContext();
164         
165         Validator validator(context);
166     JSCallbackManagerPtr cbm(NULL);
167     FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
168         MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
169         cbm = JSCallbackManager::createObject(globalContext);
170
171         IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
172
173     Try
174     {
175         if (argumentCount == 0 ||
176             (!validator.isCallback(arguments[0])) ||
177             (argumentCount >= 2 && (!validator.isCallback(arguments[1]))) //||
178 //            (argumentCount >= 3 && (!JSValueIsObject(context, arguments[2]) /*&& !validator.isNullOrUndefined(arguments[2])*/)) 
179 //            (argumentCount >= 4 && (!JSValueIsObject(context, arguments[3]) /*&& !validator.isNullOrUndefined(arguments[3])*/)) ||
180 //            (argumentCount >= 5 && (!JSValueIsObject(context, arguments[4]) /*&& !validator.isNullOrUndefined(arguments[4]))*/)) ||
181             /*(argumentCount >= 6 && (!JSValueIsObject(context, arguments[5]) && !validator.isNullOrUndefined(arguments[4]))))*/)
182         {
183             LogDebug("Argument type mismatch");
184             Throw(InvalidArgumentException);
185         }
186         if (cbm) 
187         {
188             JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
189             onSuccessForCbm = arguments[0];
190             if (argumentCount >= 2) 
191             {
192                 onErrorForCbm = arguments[1];
193             }
194             cbm->setOnSuccess(onSuccessForCbm);
195             cbm->setOnError(onErrorForCbm);
196                 }
197
198         
199                 IEventFindMediaPtr dplEvent(new IEventFindMedia());
200                 dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
201                 dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
202                 
203         if (argumentCount >= 3 && !validator.isNullOrUndefined(arguments[2]))
204         {
205             dplEvent->setFilter(filterConverter->toFilter(arguments[2]));
206         }
207                 if (argumentCount >= 4 && !validator.isNullOrUndefined(arguments[3])) 
208                 {
209                         SortModeArrayPtr sortModes(new SortModeArray());
210                         sortModes->push_back(filterConverter->toSortMode(arguments[3]));
211                         dplEvent->setSortModes(sortModes);
212                 }
213                 if (argumentCount >= 5 && !validator.isNullOrUndefined(arguments[4])) 
214                 {
215                         long limit = filterConverter->toLong(arguments[4]);
216                         dplEvent->setLimit(limit);
217                 }
218                 if (argumentCount >= 6 && !validator.isNullOrUndefined(arguments[5])) 
219                 {
220                         long offset = filterConverter->toLong(arguments[5]);
221                         dplEvent->setOffset(offset);
222                 }               
223
224                 mediacontent->findMedia(dplEvent);
225                 
226         }
227         Catch(InvalidArgumentException)
228         {
229                 return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
230         }
231         Catch(ConversionException)
232         {
233                 return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
234         }
235         Catch(Exception)
236         {
237                 return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
238         }
239         
240         return JSValueMakeNull(context);
241
242 }
243
244
245 JSValueRef JSMediacontent::findFolders(
246                                                         JSContextRef context, 
247                                                         JSObjectRef object,
248                                                         JSObjectRef thisObject, 
249                                                         size_t argumentCount,
250                                                         const JSValueRef arguments[], 
251                                                         JSValueRef* exception )
252 {
253
254         LogDebug("JSMediacontent::findFolders entered");
255
256     MediacontentPrivObject *privateObject = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( thisObject ) ) ;
257     assert(privateObject);
258
259
260         //TODO.
261         //AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_FIND);
262         //TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
263
264         JSContextRef globalContext = privateObject->getContext();
265         Validator validator(context);
266     JSCallbackManagerPtr cbm(NULL);
267     FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
268         MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
269
270         cbm = JSCallbackManager::createObject(globalContext);
271
272         IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
273
274     Try
275     {
276
277         if (argumentCount == 0 ||
278             (!validator.isCallback(arguments[0])) ||
279             (argumentCount >= 2 && (!validator.isCallback(arguments[1]))) ||
280             (argumentCount >= 3 && (!JSValueIsObject(context, arguments[2]) /*&& !validator.isNullOrUndefined(arguments[2])*/)) 
281 //            (argumentCount >= 4 && (!JSValueIsObject(context, arguments[3]) /*&& !validator.isNullOrUndefined(arguments[3])*/)) ||
282 //            (argumentCount >= 5 && (!JSValueIsObject(context, arguments[4]) /*&& !validator.isNullOrUndefined(arguments[4]))*/)) ||
283             /*(argumentCount >= 6 && (!JSValueIsObject(context, arguments[5]) && !validator.isNullOrUndefined(arguments[4]))))*/)
284         {
285             LogDebug("Argument type mismatch");
286             Throw(InvalidArgumentException);
287         }
288
289         if (cbm) 
290         {
291             JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
292             onSuccessForCbm = arguments[0];
293             if (argumentCount >= 2) 
294             {
295                 onErrorForCbm = arguments[1];
296             }
297             cbm->setOnSuccess(onSuccessForCbm);
298             cbm->setOnError(onErrorForCbm);
299                 }
300
301         IEventFindFolderPtr dplEvent(new IEventFindFolder());
302         dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
303         dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
304
305         if (argumentCount >= 3 && !validator.isNullOrUndefined(arguments[2]))
306         {
307             dplEvent->setFilter(filterConverter->toFilter(arguments[2]));
308         }
309                 if (argumentCount >= 4 && !validator.isNullOrUndefined(arguments[3])) 
310                 {
311                         SortModeArrayPtr sortModes(new SortModeArray());
312                         sortModes->push_back(filterConverter->toSortMode(arguments[3]));
313                         dplEvent->setSortModes(sortModes);
314                 }
315                 if (argumentCount >= 5 && !validator.isNullOrUndefined(arguments[4])) 
316                 {
317                         long limit = filterConverter->toLong(arguments[4]);
318                         dplEvent->setLimit(limit);
319                 }
320                 if (argumentCount >= 6 && !validator.isNullOrUndefined(arguments[5])) 
321                 {
322                         long offset = filterConverter->toLong(arguments[5]);
323                         dplEvent->setOffset(offset);
324
325                 }               
326
327         mediacontent->findFolder(dplEvent);
328     }
329     Catch(InvalidArgumentException)
330     {
331         return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
332     }
333     Catch(ConversionException)
334     {
335         return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
336     }
337     Catch(Exception)
338     {
339         return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
340     }
341
342     return JSValueMakeNull(context);
343
344 }
345
346
347 JSValueRef JSMediacontent::updateItem(
348                                                 JSContextRef context,
349                                                 JSObjectRef object,
350                                                 JSObjectRef thisObject,
351                                                 size_t argumentCount,
352                                                 const JSValueRef arguments[],
353                                                 JSValueRef* exception)
354 {
355                 LogDebug("updateItem::entered");
356
357         
358                 MediacontentPrivObject *privateObject = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( thisObject ) ) ;
359                 assert(privateObject);
360
361                 //AceSecurityStatus
362                 //TIZEN_SYNC_ACCESS_HANDLER
363                 Validator validator(context);
364                 IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
365
366                 Try
367                 {               
368                 if (argumentCount == 0 ||
369                     (!JSValueIsObject(context, arguments[0])) ||
370                     (argumentCount >= 2 && (!validator.isNullOrUndefined(arguments[1]) && (!validator.isCallback(arguments[1])))) ||
371                     (argumentCount >= 3 && (!validator.isNullOrUndefined(arguments[2]) && (!validator.isCallback(arguments[2])))) )
372                 {
373                     LogDebug("Argument type mismatch");
374                     Throw(InvalidArgumentException);
375                 }               
376
377                         
378                         JSObjectRef arg = JSValueToObject(context, arguments[0], exception);
379                         MediacontentMediaPtr event = JSMedia::getMediaObject(arg);
380
381                         IEventUpdateMediaPtr dplEvent(new IEventUpdateMedia());
382                         dplEvent->setMediaItem(event);
383                         dplEvent->setForSynchronousCall();
384
385                         mediacontent->updateMedia(dplEvent);
386                     if (dplEvent->getResult()) 
387                     {
388                     return JSValueMakeNull(context);
389             } 
390             else
391             {
392                 ThrowMsg(UnknownException, "Updating failed by unkown reason.");
393                 }
394                 }
395                 Catch(InvalidArgumentException)
396                 {
397                     return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
398                 }
399                 Catch(ConversionException)
400                 {
401                     return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
402                 }
403                 Catch(Exception)
404                 {
405                     return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
406                 }
407
408                 return JSValueMakeNull(context);                
409 }
410
411
412
413 /*
414 JSValueRef JSMediacontent::findPlaylist(
415                                                         JSContextRef context,
416                                                         JSObjectRef object,
417                                                         JSObjectRef thisObject,
418                                                         size_t argumentCount,
419                                                         const JSValueRef arguments[],
420                                                         JSValueRef* exception )
421 {
422     LogDebug("JSMediacontent::findMedia entered");
423
424     MediacontentPrivObject *privateObject = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( thisObject ) ) ;
425     assert(privateObject);
426
427
428
429     JSCallbackManagerPtr cbm(NULL);
430     Try
431     {
432         IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
433         if (argumentCount < 1) 
434                 {
435             LogError("No callback parameters");
436             Throw(InvalidArgumentException);
437         }
438         JSValueRef onError = (argumentCount > 1 ? getFunctionOrNull(context, arguments[1]) : NULL);
439         JSContextRef globalContext = privateObject->getContext();
440         JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext, NULL, onError);
441
442
443         Validator validator(context);
444         if (validator.isCallback(arguments[0])) 
445                 {
446             cbm->setOnSuccess(arguments[0]);
447         }
448         else if (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]))
449                 {
450             Throw(InvalidArgumentException);
451         }
452
453
454                 //dy.kim-todo:Filter 
455                 
456         IEventFindPlaylistPtr dplEvent(new IEventFindPlaylist());
457         dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
458         dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
459         mediacontent->findPlaylist(dplEvent);
460
461     }
462     Catch(InvalidArgumentException)
463     {
464         return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
465     }
466     Catch(ConversionException)
467     {
468         return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
469     }
470     Catch(Exception)
471     {
472         return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
473     }
474
475     return JSValueMakeNull(context);
476 }
477
478
479
480
481 JSValueRef JSMediacontent::deletePlaylist(
482                                                 JSContextRef context,
483                                                 JSObjectRef object,
484                                                 JSObjectRef thisObject,
485                                                 size_t argumentCount,
486                                                 const JSValueRef arguments[],
487                                                 JSValueRef* exception)
488 {
489                 LogDebug("deletePlaylist::entered");
490         
491                 MediacontentPrivObject *privateObject = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( thisObject ) ) ;
492                 assert(privateObject);
493         
494                 //CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_ADD_EVENT);
495         
496                 Try
497                 {
498                         IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
499                         if (argumentCount != 1) 
500                         {
501                                 LogError("Wrong number of parameters.");
502                                 Throw(InvalidArgumentException);
503                         }
504         
505                         if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) 
506                         {
507                                 Throw(InvalidArgumentException);
508                                 //return JSValueMakeNull(context);
509                         }
510         
511                         MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
512                         string playlistID = converter->toString(arguments[0]);
513
514                         LogDebug("deletePlaylist::entered" << playlistID);
515                         IEventDeletePlaylistPtr dplEvent(new IEventDeletePlaylist());
516                         LogDebug("deletePlaylist::entered11");
517                         dplEvent->setPlaylistId(playlistID);
518                         LogDebug("deletePlaylist::entered22");
519                         dplEvent->setForSynchronousCall();
520                         LogDebug("deletePlaylist::entered33");
521                         mediacontent->deletePlaylist(dplEvent);
522                         LogDebug("deletePlaylist::entered44");
523         
524                         if (dplEvent->getResult()) 
525                         {;
526 //                              return converter->toJSValueRef(dplEvent->getPlaylist()->getPlaylistId());
527                         } else
528                         {
529                                 Throw(InvalidArgumentException);
530                         }
531                 }
532                 Catch(InvalidArgumentException)
533                 {
534                         return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
535                 }
536                 Catch(ConversionException)
537                 {
538                         return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
539                 }
540                 Catch(Exception)
541                 {
542                         return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
543                 }
544
545                 return JSValueMakeNull(context);
546 }
547
548
549
550 JSValueRef JSMediacontent::addAudioToPlaylist(
551                                                 JSContextRef context,
552                                                 JSObjectRef object,
553                                                 JSObjectRef thisObject,
554                                                 size_t argumentCount,
555                                                 const JSValueRef arguments[],
556                                                 JSValueRef* exception)
557 {
558                         LogDebug("addAudioToPlaylist::entered");
559                 
560                         MediacontentPrivObject *privateObject = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( thisObject ) ) ;
561                         assert(privateObject);
562                 
563                         //CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_ADD_EVENT);
564                 
565                         Try
566                         {
567                                 IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
568                                 if (argumentCount != 2) 
569                                 {
570                                         LogError("Wrong number of parameters.");
571                                         Throw(InvalidArgumentException);
572                                 }
573                 
574                                 if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) 
575                                 {
576                                         Throw(InvalidArgumentException);
577                                         //return JSValueMakeNull(context);
578                                 }
579                 
580                                 MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
581                                 string playlistID = converter->toString(arguments[0]);
582                                 string mediaUID = converter->toString(arguments[1]);
583                 
584                                 IEventAddAudioToPlaylistPtr dplEvent(new IEventAddAudioToPlaylist());
585                                 dplEvent->setPlaylistId(playlistID);
586                                 dplEvent->setMediaUID(mediaUID);                                
587                                 dplEvent->setForSynchronousCall();
588                                 mediacontent->addAudioToPlaylist(dplEvent);
589                 
590                                 if (dplEvent->getResult()) 
591                                 {
592                                 ;
593 //                                      return converter->toJSValueRef(dplEvent->getPlaylist()->getPlaylistId());
594                                 } else
595                                 {
596                                         Throw(InvalidArgumentException);
597                                 }
598                         }
599                     Catch(InvalidArgumentException)
600                     {
601                         return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
602                     }
603                     Catch(ConversionException)
604                     {
605                         return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
606                     }
607                     Catch (NotFoundException)
608                     {
609                         return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::NOT_FOUND_ERROR);
610                     }
611                     Catch(Exception)
612                     {
613                         return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
614                     }                   
615         
616                         return JSValueMakeNull(context);
617
618 }
619
620 JSValueRef JSMediacontent::deleteAudioToPlaylist(
621                                                 JSContextRef context,
622                                                 JSObjectRef object,
623                                                 JSObjectRef thisObject,
624                                                 size_t argumentCount,
625                                                 const JSValueRef arguments[],
626                                                 JSValueRef* exception)
627 {
628                         LogDebug("deleteAudioToPlaylist::entered");
629                 
630                         MediacontentPrivObject *privateObject = static_cast<MediacontentPrivObject*>( JSObjectGetPrivate( thisObject ) ) ;
631                         assert(privateObject);
632                 
633                         //CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_ADD_EVENT);
634                 
635                         Try
636                         {
637                                 IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception);
638                                 if (argumentCount != 2) 
639                                 {
640                                         LogError("Wrong number of parameters.");
641                                         Throw(InvalidArgumentException);
642                                 }
643                 
644                                 if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) 
645                                 {
646                                         Throw(InvalidArgumentException);
647                                         //return JSValueMakeNull(context);
648                                 }
649                 
650                                 MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
651                                 string playlistID = converter->toString(arguments[0]);
652                                 string mediaUID = converter->toString(arguments[1]);
653                 
654                                 IEventDeleteAudioToPlaylistPtr dplEvent(new IEventDeleteAudioToPlaylist());
655                                 dplEvent->setPlaylistId(playlistID);
656                                 dplEvent->setMediaUID(mediaUID);                                
657                                 dplEvent->setForSynchronousCall();
658                                 mediacontent->deleteAudioToPlaylist(dplEvent);
659                 
660                                 if (dplEvent->getResult()) 
661                                 {;
662         //                              return converter->toJSValueRef(dplEvent->getPlaylist()->getPlaylistId());
663                                 } else
664                                 {
665                                         Throw(NotFoundException);
666                                 }
667                         }
668                         Catch(InvalidArgumentException)
669                         {
670                                 return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
671                         }
672                         Catch(ConversionException)
673                         {
674                                 return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
675                         }
676                         Catch(Exception)
677                         {
678                                 return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
679                         }
680
681                         return JSValueMakeNull(context);
682
683 }
684
685
686 */
687
688
689
690 IMediacontentPtr JSMediacontent::getMediacontentObject(
691                                                 JSContextRef ctx,
692                                         const JSObjectRef object,
693                                         JSValueRef* exception)
694 {
695     MediacontentPrivObject *priv = static_cast<MediacontentPrivObject*>(JSObjectGetPrivate(object));
696     if (priv) 
697         {
698         return priv->getObject();
699     }
700     ThrowMsg(NullPointerException, "Private object is NULL.");
701 }
702
703
704 }
705 }
706 }