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