[content] Apply secure log
[platform/framework/native/content.git] / src / FCntAudioContentInfo.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 /**
19  * @file                FCntAudioContentInfo.cpp
20  * @brief               This is the implementation file for the %AudioContentInfo class.
21  *
22  * This file contains implementation of the %AudioContentInfo class.
23  */
24
25 #include <FBaseSysLog.h>
26 #include <FCntAudioContentInfo.h>
27 #include <FIoFile.h>
28 #include <FIoDirectory.h>
29 #include <FSysEnvironment.h>
30 #include <FIo_FileImpl.h>
31 #include <FApp_AppInfo.h>
32
33 using namespace Tizen::Base;
34 using namespace Tizen::Io;
35 using namespace Tizen::Locations;
36 using namespace Tizen::App;
37 using namespace Tizen::System;
38 using namespace std;
39
40 namespace Tizen { namespace Content
41 {
42
43 AudioContentInfo::AudioContentInfo(void)
44         : ContentInfo()
45         , __pAudioContentData(null)
46         , __pImpl(null)
47 {
48
49 }
50
51 AudioContentInfo::~AudioContentInfo(void)
52 {
53         if (__pAudioContentData != null)
54         {
55                 if (__pAudioContentData->pTitle != null)
56                 {
57                         delete __pAudioContentData->pTitle;
58                         __pAudioContentData->pTitle = null;
59                 }
60                 if (__pAudioContentData->pAlbumName != null)
61                 {
62                         delete __pAudioContentData->pAlbumName;
63                         __pAudioContentData->pAlbumName = null;
64                 }
65                 if (__pAudioContentData->pArtist != null)
66                 {
67                         delete __pAudioContentData->pArtist;
68                         __pAudioContentData->pArtist = null;
69                 }
70                 if (__pAudioContentData->pComposer != null)
71                 {
72                         delete __pAudioContentData->pComposer;
73                         __pAudioContentData->pComposer = null;
74                 }
75                 if (__pAudioContentData->pGenre != null)
76                 {
77                         delete __pAudioContentData->pGenre;
78                         __pAudioContentData->pGenre = null;
79                 }
80                 if (__pAudioContentData->pCopyright != null)
81                 {
82                         delete __pAudioContentData->pCopyright;
83                         __pAudioContentData->pCopyright = null;
84                 }
85                 if (__pAudioContentData->pTrackInfo != null)
86                 {
87                         delete __pAudioContentData->pTrackInfo;
88                         __pAudioContentData->pTrackInfo = null;
89                 }
90
91                 delete __pAudioContentData;
92                 __pAudioContentData = null;
93         }
94 }
95
96 /**
97  * E_SUCCESS
98  * E_FILE_NOT_FOUND
99  * E_INVALID_ARG
100  * E_OUT_OF_MEMORY
101  * - E_IO
102  */
103 result
104 AudioContentInfo::Construct(const String& contentPath, const String& thumbnailPath, bool setGps)
105 {
106         ClearLastResult();
107
108         SysAssertf(__pAudioContentData == null,
109                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
110
111         result r = E_SUCCESS;
112         _ContentData contentData;
113         int contentLength = 0;
114         FileAttributes attribute;
115
116         // checks parameters
117         contentLength = contentPath.GetLength();
118         SysTryReturnResult(NID_CNT, _FileImpl::IsMediaPath(contentPath), E_INVALID_ARG,
119                         "The contentPath should start with /Media or /Storagecard/Media.");
120         SysTryReturnResult(NID_CNT, File::IsFileExist(contentPath), E_FILE_NOT_FOUND,
121                         "The file corresponding to contentPath could not be found.");
122
123         if (!thumbnailPath.IsEmpty())
124         {
125                 SysLog(NID_CNT,
126                                 "The thumbnailPath is not supported but you can get the thumbnail managed by Tizen from ContentInfo::GetThumbnailN().");
127         }
128
129         if (setGps)
130         {
131                 SysLog(NID_CNT, "The setGps is not supported.");
132         }
133
134         // Sets the content path
135         contentData.contentPath = contentPath;
136
137         // Sets the content type
138         contentData.contentType = CONTENT_TYPE_AUDIO;
139
140         // E_INVALID_ARG, E_OUT_OF_MEMORY
141         r = SetContentData(&contentData);
142         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
143
144         _AudioContentData* pAudioContentData = new (nothrow) _AudioContentData();
145         SysTryReturnResult(NID_CNT, pAudioContentData != null, E_OUT_OF_MEMORY, "Construct() failed.");
146
147         __pAudioContentData = pAudioContentData;
148
149         return r;
150 }
151
152 /**
153  * E_SUCCESS
154  * E_FILE_NOT_FOUND
155  * E_INVALID_ARG
156  * E_OUT_OF_MEMORY
157  * - E_IO
158  * - E_SYSTEM
159  */
160 result
161 AudioContentInfo::Construct(const String* pContentPath)
162 {
163         ClearLastResult();
164
165         SysAssertf(__pAudioContentData == null,
166                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
167
168         result r = E_SUCCESS;
169         _ContentData contentData;
170
171         if (pContentPath != null)
172         {
173                 if (!_AppInfo::IsOspCompat())
174                 {
175                         if (pContentPath->StartsWith(OSP_MEDIA_PHONE, 0) || pContentPath->StartsWith(OSP_MEDIA_MMC, 0))
176                         {
177                                 SysLogException(NID_CNT, E_INVALID_ARG,
178                                                 "[E_INVALID_ARG] /Media/ and /Storagecard/Media/ are not supported from Tizen 2.0.");
179                                 return E_INVALID_ARG;
180                         }
181                         if (!(pContentPath->StartsWith(Environment::GetMediaPath(), 0)
182                                 || pContentPath->StartsWith(Environment::GetExternalStoragePath(), 0)))
183                         {
184                                 SysLogException(NID_CNT, E_INVALID_ARG,
185                                                 "[E_INVALID_ARG] %ls is not supported.", pContentPath->GetPointer());
186                                 return E_INVALID_ARG;
187                         }
188                 }
189                 else
190                 {
191                         // prior to 2.0
192                         if (pContentPath->StartsWith(OSP_MEDIA_PHONE, 0))
193                         {
194                                 // Because the content path is saved like /opt/media or /opt/storage/sdcard/ in SLP database,
195                                 // it should be converted in 2.0.
196                                 r = (const_cast<String*>(pContentPath))->Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
197                                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
198                         }
199                         else if (pContentPath->StartsWith(OSP_MEDIA_MMC, 0))
200                         {
201                                 r = (const_cast<String*>(pContentPath))->Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
202                                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
203                         }
204                         else
205                         {
206                                 SysLogException(NID_CNT, E_INVALID_ARG,
207                                                 "[E_INVALID_ARG] The contentPath should start with /Media or /Storagecard/Media.");
208                                 return E_INVALID_ARG;
209                         }
210                 }
211
212                 int length = pContentPath->GetLength();
213                 SysTryReturnResult(NID_CNT, length != 0, E_INVALID_ARG,
214                                 "The length of pContentPath is 0.");
215                 SysTryReturnResult(NID_CNT, File::IsFileExist(*pContentPath), E_FILE_NOT_FOUND,
216                                 "The file corresponding to pContentPath could not be found.");
217
218                 // Sets the content path
219                 contentData.contentPath = *pContentPath;
220
221                 // Sets the content type
222                 contentData.contentType = CONTENT_TYPE_AUDIO;
223
224                 r = SetContentData(&contentData);
225                 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
226         }
227         else
228         {
229                 contentData.contentType = CONTENT_TYPE_AUDIO;
230
231                 r = SetContentData(&contentData);
232                 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
233         }
234
235         _AudioContentData* pAudioContentData = new (nothrow) _AudioContentData();
236         SysTryReturnResult(NID_CNT, pAudioContentData != null, E_OUT_OF_MEMORY, "Construct() failed.");
237
238         __pAudioContentData = pAudioContentData;
239
240         return r;
241 }
242
243 /**
244  * E_SUCCESS
245  * E_INVALID_ARG
246  * E_OUT_OF_MEMORY
247  */
248 result
249 AudioContentInfo::SetAudioContentData(const _AudioContentData* pAudioContentData)
250 {
251         ClearLastResult();
252
253         SysTryReturnResult(NID_CNT, pAudioContentData != null, E_INVALID_ARG, "pAudioContentData is null.");
254
255         if (__pAudioContentData == null)
256         {
257                 __pAudioContentData = new (nothrow) _AudioContentData;
258                 SysTryReturnResult(NID_CNT, __pAudioContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
259         }
260
261         __pAudioContentData->bitrate = pAudioContentData->bitrate;
262         __pAudioContentData->releaseYear = pAudioContentData->releaseYear;
263         __pAudioContentData->duration = pAudioContentData->duration;
264
265         if (pAudioContentData->pTitle != null)
266         {
267                 __pAudioContentData->pTitle = new (nothrow) String(*(pAudioContentData->pTitle));
268                 SysTryReturnResult(NID_CNT, __pAudioContentData->pTitle != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
269         }
270         if (pAudioContentData->pAlbumName != null)
271         {
272                 __pAudioContentData->pAlbumName = new (nothrow) String(*(pAudioContentData->pAlbumName));
273                 SysTryReturnResult(NID_CNT, __pAudioContentData->pAlbumName != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
274         }
275         if (pAudioContentData->pArtist != null)
276         {
277                 __pAudioContentData->pArtist = new (nothrow) String(*(pAudioContentData->pArtist));
278                 SysTryReturnResult(NID_CNT, __pAudioContentData->pArtist != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
279         }
280         if (pAudioContentData->pComposer != null)
281         {
282                 __pAudioContentData->pComposer = new (nothrow) String(*(pAudioContentData->pComposer));
283                 SysTryReturnResult(NID_CNT, __pAudioContentData->pComposer != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
284         }
285         if (pAudioContentData->pGenre != null)
286         {
287                 __pAudioContentData->pGenre = new (nothrow) String(*(pAudioContentData->pGenre));
288                 SysTryReturnResult(NID_CNT, __pAudioContentData->pGenre != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
289         }
290         if (pAudioContentData->pCopyright != null)
291         {
292                 __pAudioContentData->pCopyright = new (nothrow) String(*(pAudioContentData->pCopyright));
293                 SysTryReturnResult(NID_CNT, __pAudioContentData->pCopyright != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
294         }
295         if (pAudioContentData->pTrackInfo != null)
296         {
297                 __pAudioContentData->pTrackInfo = new (nothrow) String(*(pAudioContentData->pTrackInfo));
298                 SysTryReturnResult(NID_CNT, __pAudioContentData->pTrackInfo != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
299         }
300
301         return E_SUCCESS;
302 }
303
304 AudioContentInfo::_AudioContentData*
305 AudioContentInfo::GetAudioContentData(void)
306 {
307         if (__pAudioContentData == null)
308         {
309                 __pAudioContentData = new (nothrow) AudioContentInfo::_AudioContentData;
310                 SysTryReturn(NID_CNT, __pAudioContentData != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
311         }
312         return __pAudioContentData;
313 }
314
315 String
316 AudioContentInfo::GetGenre(void) const
317 {
318         SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
319
320         if (__pAudioContentData->pGenre == null)
321         {
322                 SysLog(NID_CNT, "GetGenre() failed.");
323                 return String(L"Unknown");
324         }
325
326         return *(__pAudioContentData->pGenre);
327 }
328
329 String
330 AudioContentInfo::GetArtist(void) const
331 {
332         SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
333
334         if (__pAudioContentData->pArtist == null)
335         {
336                 SysLog(NID_CNT, "GetArtist() failed.");
337                 return String(L"Unknown");
338         }
339
340         return *(__pAudioContentData->pArtist);
341 }
342
343 String
344 AudioContentInfo::GetComposer(void) const
345 {
346         SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
347
348         if (__pAudioContentData->pComposer == null)
349         {
350                 SysLog(NID_CNT, "GetComposer() failed.");
351                 return String(L"Unknown");
352         }
353
354         return *(__pAudioContentData->pComposer);
355 }
356
357 String
358 AudioContentInfo::GetAlbumName(void) const
359 {
360         SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
361
362         if (__pAudioContentData->pAlbumName == null)
363         {
364                 SysLog(NID_CNT, "GetAlbumName() failed.");
365                 return String(L"Unknown");
366         }
367
368         return *(__pAudioContentData->pAlbumName);
369 }
370
371 int
372 AudioContentInfo::GetReleaseYear(void) const
373 {
374         SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
375
376         return __pAudioContentData->releaseYear;
377 }
378
379 int
380 AudioContentInfo::GetBitrate(void) const
381 {
382         SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
383
384         return __pAudioContentData->bitrate;
385 }
386
387 String
388 AudioContentInfo::GetTitle(void) const
389 {
390         SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
391
392         if (__pAudioContentData->pTitle == null)
393         {
394                 SysLog(NID_CNT, "GetTitle() failed.");
395                 return String(L"Unknown");
396         }
397
398         return *(__pAudioContentData->pTitle);
399 }
400
401 String
402 AudioContentInfo::GetCopyright(void) const
403 {
404         SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
405
406         if (__pAudioContentData->pCopyright == null)
407         {
408                 SysLog(NID_CNT, "GetCopyright() failed.");
409                 return String(L"Unknown");
410         }
411
412         return *(__pAudioContentData->pCopyright);
413 }
414
415 String
416 AudioContentInfo::GetTrackInfo(void) const
417 {
418         SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
419
420         if (__pAudioContentData->pTrackInfo == null)
421         {
422                 SysLog(NID_CNT, "GetTrackInfo() failed.");
423                 return String(L"Unknown");
424         }
425
426         return *(__pAudioContentData->pTrackInfo);
427 }
428
429 long
430 AudioContentInfo::GetDuration(void) const
431 {
432         SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
433
434         return __pAudioContentData->duration;
435 }
436
437 }}