Fix : The exception handling according to the situation
[platform/framework/native/content.git] / src / FCntPlayList.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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  * @file                FCntPlayList.cpp
18  * @brief               This is the implementation file for the %PlayList class.
19  *
20  * This is the implementation file for %PlayList class.
21  */
22
23 #include <FBaseSysLog.h>
24 #include <FCntPlayList.h>
25 #include <FBaseColIList.h>
26 #include <FIoFile.h>
27 #include <FSysEnvironment.h>
28 #include <FCnt_PlayListImpl.h>
29
30 using namespace Tizen::Io;
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::System;
34
35 namespace Tizen { namespace Content
36 {
37
38 PlayList::PlayList()
39         : Object()
40         , __pImpl(NULL)
41         , __playListName(L"")
42 {
43 }
44
45 PlayList::~PlayList(void)
46 {
47         delete __pImpl;
48 }
49
50 result
51 PlayList::Construct(const Tizen::Base::String& playListName)
52 {
53         result r = E_SUCCESS;
54
55         SysAssertf(__pImpl == null,
56                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
57
58         SysTryReturn(NID_CNT, !playListName.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] The playListName is empty.");
59
60         _PlayListImpl* pPlayListImpl = new (std::nothrow) _PlayListImpl();
61         SysTryReturn(NID_CNT, pPlayListImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Construct failed.");
62
63         r = pPlayListImpl->Construct(playListName);
64         SysTryCatch(NID_CNT, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
65
66         __pImpl = pPlayListImpl;
67
68         __playListName = playListName;
69
70         return r;
71
72 CATCH:
73         delete pPlayListImpl;
74         return r;
75 }
76
77 result
78 PlayList::ConstructPlayList(const Tizen::Base::String& playListName)
79 {
80         result r = E_SUCCESS;
81
82         SysAssertf(__pImpl == null,
83                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
84
85         SysTryReturn(NID_CNT, !playListName.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] The playListName is empty.");
86
87         _PlayListImpl* pPlayListImpl = new (std::nothrow) _PlayListImpl();
88         SysTryReturn(NID_CNT, pPlayListImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Construct failed.");
89
90         r = pPlayListImpl->Construct(playListName, false);
91         SysTryCatch(NID_CNT, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
92
93         __pImpl = pPlayListImpl;
94
95         __playListName = playListName;
96
97         return r;
98
99 CATCH:
100         delete pPlayListImpl;
101         return r;
102 }
103
104 int
105 PlayList::GetPlayListItemCount(void) const
106 {
107
108         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
109
110         return (__pImpl->GetPlayListItemCount(__playListName));
111
112 }
113
114 Tizen::Base::Collection::IList*
115 PlayList::GetContentInfoListN(void) const
116 {
117
118         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
119
120         return (__pImpl->GetContentInfoListN(__playListName));
121 }
122
123 result
124 PlayList::AddItem(const ContentId& contentId)
125 {
126         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
127
128         SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] contentId is not valid");
129
130         return (__pImpl->AddItem(__playListName, contentId));
131 }
132
133 result
134 PlayList::AddItems(const Tizen::Base::Collection::IList& contentIdList)
135 {
136         int listCount = contentIdList.GetCount();
137         ContentId *pContentId = NULL;
138
139         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
140
141         SysTryReturn(NID_CNT, listCount > 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] contentIdList count is zero");
142
143         for (int index = 0; index < listCount; index++)
144         {
145                 pContentId = (ContentId*)contentIdList.GetAt(index);
146                 SysTryReturn(NID_CNT, *pContentId != UuId::GetInvalidUuId(), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] contentId is not valid");
147         }
148
149         return (__pImpl->AddItems(__playListName, contentIdList));
150 }
151
152 result
153 PlayList::RemoveItem(const ContentId& contentId)
154 {
155         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
156
157         SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] contentId is not valid");
158
159         return (__pImpl->RemoveItem(contentId));
160 }
161
162 result
163 PlayList::RemoveItems(const Tizen::Base::Collection::IList& contentIdList)
164 {
165         int listCount = contentIdList.GetCount();
166         ContentId *pContentId = NULL;
167
168         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
169
170         SysTryReturn(NID_CNT, listCount > 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] contentIdList count is zero");
171
172         for (int index = 0; index < listCount; index++)
173         {
174                 pContentId = (ContentId*)contentIdList.GetAt(index);
175                 SysTryReturn(NID_CNT, *pContentId != UuId::GetInvalidUuId(), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] contentId is not valid");
176         }
177
178         return (__pImpl->RemoveItems(contentIdList));
179 }
180
181 Tizen::Base::String
182 PlayList::GetPlayListName(void) const
183 {
184         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
185         return __playListName;
186 }
187
188 result
189 PlayList::SetPlayListName(const Tizen::Base::String& playListName)
190 {
191         result r = E_SUCCESS;
192
193         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
194
195         SysTryReturn(NID_CNT, !playListName.IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The playListName is empty.");
196
197         r = __pImpl->SetPlayListName(__playListName, playListName); // impl need old and new name
198         SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] SetPlayListName failed. ", GetErrorMessage(r));
199
200         __playListName = playListName;
201
202         return r;
203 }
204
205 int
206 PlayList::GetPlayOrder(const ContentId& contentId) const
207 {
208         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
209
210         SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] contentId is not valid");
211
212         return (__pImpl->GetPlayOrder(contentId));
213 }
214
215 }}