tizen 2.3.1 release
[framework/web/wearable/wrt-plugins-tizen.git] / src / Content / PlaylistUtils.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include "PlaylistUtils.h"
19 #include "ContentUtility.h"
20
21 #include <Logger.h>
22 #include <sstream>
23
24 namespace DeviceAPI {
25 namespace Content {
26
27 int destroyMediaPlaylistHandle(media_playlist_h& playlist_handle)
28 {
29     if(!playlist_handle) {
30         return MEDIA_CONTENT_ERROR_NONE;
31     }
32
33     int ret_code = media_playlist_destroy(playlist_handle);
34     playlist_handle = NULL;
35
36     if(MEDIA_CONTENT_ERROR_NONE != ret_code) {
37         LOGE("%s", ContentUtility::getMediaContentLogMessage(
38                 ret_code, "media_playlist_destroy()").c_str());
39     }
40
41     return ret_code;
42 }
43
44 int destroyMediaFilterHandle(filter_h& filter_handle)
45 {
46     int ret_code = media_filter_destroy(filter_handle);
47     filter_handle = NULL;
48
49     if(MEDIA_CONTENT_ERROR_NONE != ret_code) {
50         LOGE("%s", ContentUtility::getMediaContentLogMessage(
51                 ret_code, "media_filter_destroy()").c_str());
52     }
53
54     return ret_code;
55 }
56
57 PlaylistItemPtr getPlaylistItemFromJSObjectRef(JSContextRef context,
58         JSObjectRef obj)
59 {
60     LOGD("Entered");
61     if(JSPlaylistItem::isObjectOfClass(context, obj)) {
62         return JSPlaylistItem::getPrivateObject(context, obj);
63     } else {
64         LOGE("Wrong content type");
65         throw TypeMismatchException("Wrong content type");
66     }
67 }
68
69 AudioContentPtr getAudioContentPtrFromJSObjectRef(JSContextRef context,
70         JSObjectRef obj)
71 {
72     LOGD("Entered");
73     if(JSAudioContent::isObjectOfClass(context, obj) ) {
74         return JSAudioContent::getPrivateObject(context, obj);
75     } else {
76         LOGE("Wrong content type");
77         throw TypeMismatchException("Wrong content type");
78     }
79 }
80
81
82 PlaylistUnknownException::PlaylistUnknownException(const char* message,
83         int core_api_error) :
84                 Common::UnknownException(message),
85                 m_core_api_error(core_api_error)
86 {
87 }
88
89 PlaylistUnknownException::PlaylistUnknownException(JSContextRef ctx,
90         JSValueRef exception, int core_api_error) :
91                 Common::UnknownException(ctx, exception),
92                 m_core_api_error(core_api_error)
93 {
94 }
95
96 int PlaylistUnknownException::getCoreAPIError() const
97 {
98     return m_core_api_error;
99 }
100
101
102 } //namespace Content
103 } //namespace DeviceAPI