[content] Fix a sample app fail
[platform/framework/native/content.git] / src / FCnt_ContentManagerImpl.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                FCnt_ContentManagerImpl.cpp
18  * @brief               This is the implementation file for the %_ContentManagerImpl class.
19  *
20  * This file contains implementation of the %_ContentManagerImpl class.
21  */
22
23 #include <new>
24 #include <stdlib.h>
25 #include <aul/aul.h>
26 #include <FAppApp.h>
27 #include <FBaseSysLog.h>
28 #include <FBaseDateTime.h>
29 #include <FBaseInteger.h>
30 #include <FBaseByteBuffer.h>
31 #include <FBaseUtilStringTokenizer.h>
32 #include <FCntContentManager.h>
33 #include <FCntContentManagerUtil.h>
34 #include <FCntImageContentInfo.h>
35 #include <FCntAudioContentInfo.h>
36 #include <FCntVideoContentInfo.h>
37 #include <FCntOtherContentInfo.h>
38 #include <FCntImageMetadata.h>
39 #include <FCntAudioMetadata.h>
40 #include <FCntVideoMetadata.h>
41 #include <FCntIContentScanListener.h>
42 #include <FCntIContentUpdateEventListener.h>
43 #include <FIoDirectory.h>
44 #include <FSysEnvironment.h>
45 #include <FApp_AppInfo.h>
46 #include <FBase_StringConverter.h>
47 #include <FIo_FileImpl.h>
48 #include "FCnt_ContentManagerImpl.h"
49 #include "FCnt_ContentManagerUtilImpl.h"
50 #include "FCnt_ContentInfoImpl.h"
51 #include "FCnt_ImageContentInfoImpl.h"
52 #include "FCnt_AudioContentInfoImpl.h"
53 #include "FCnt_VideoContentInfoImpl.h"
54 #include "FCnt_OtherContentInfoImpl.h"
55 #include "FCnt_ContentInfoHelper.h"
56
57 using namespace std;
58 using namespace Tizen::App;
59 using namespace Tizen::Base;
60 using namespace Tizen::Base::Collection;
61 using namespace Tizen::Base::Utility;
62 using namespace Tizen::Io;
63 using namespace Tizen::Locations;
64 using namespace Tizen::System;
65
66 namespace Tizen { namespace Content
67 {
68
69 static const int SYSTEM_TYPE_IMAGE = 0;
70 static const int SYSTEM_TYPE_VIDEO = 1;
71 static const int SYSTEM_TYPE_SOUND = 2;
72 static const int SYSTEM_TYPE_MUSIC = 3;
73 static const int SYSTEM_TYPE_OTHER = 4;
74 static const double DEFAULT_COORDINATE = -200.0;
75
76 // For extern declaration in FCntTypes.h
77 const wchar_t OSP_HOME[] = L"/Home/";
78 const wchar_t OSP_HOME_EXT[] = L"/HomeExt/";
79 const wchar_t OSP_MEDIA_PHONE[] = L"/Media/";
80 const wchar_t OSP_MEDIA_MMC[] = L"/Storagecard/Media/";
81
82 static result
83 ConvertError(int error)
84 {
85         result r = E_SUCCESS;
86
87         switch (error)
88         {
89         case MEDIA_CONTENT_ERROR_NONE:
90                 r = E_SUCCESS;
91                 break;
92
93         case MEDIA_CONTENT_ERROR_INVALID_PARAMETER:
94                 r = E_INVALID_ARG;
95                 break;
96
97         case MEDIA_CONTENT_ERROR_OUT_OF_MEMORY:
98                 r = E_OUT_OF_MEMORY;
99                 break;
100
101         case MEDIA_CONTENT_ERROR_DB_BUSY:
102                 r = E_SERVICE_BUSY;
103                 break;
104
105         case MEDIA_CONTENT_ERROR_DB_FAILED:
106                 r = E_SYSTEM;
107                 break;
108
109         default:
110                 r = E_SYSTEM;
111                 break;
112         }
113
114         return r;
115 }
116
117 static void
118 OnScanCompleted(media_content_error_e error, void* user_data)
119 {
120         SysLog(NID_CNT, "OnScanCompleted callback method is called.");
121
122         ClearLastResult();
123         result r = E_SUCCESS;
124         String scanPath(L"");
125         IContentScanListener* pListener = null;
126         RequestId reqId;
127         unique_ptr< _ScanResult > pScanResult;
128
129         SysTryLogCatch(NID_CNT, user_data != null, , "OnScanCompleted failed.");
130
131         pScanResult = unique_ptr< _ScanResult >(static_cast< _ScanResult* >(user_data));
132
133         SysTryLogCatch(NID_CNT, pScanResult != null, , "OnScanCompleted failed.");
134         SysTryLogCatch(NID_CNT, pScanResult->pScanListener != null, , "Listener is null. OnScanCompleted succeeded.");
135
136         scanPath = pScanResult->scanPath;
137         pListener = pScanResult->pScanListener;
138         reqId = pScanResult->requestId;
139
140         r = ConvertError(error);
141
142         pListener->OnContentScanCompleted(reqId, scanPath, r);
143         SysLog(NID_CNT, "OnContentScanCompleted fired.");
144
145 CATCH:
146         int val = media_content_disconnect();
147         SysTryLog(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, "The disconnection failed[%d].", val);
148 }
149
150 static void
151 OnContentUpdateCompleted(media_content_error_e error, int pid, media_content_db_update_item_type_e update_item,
152                 media_content_db_update_type_e update_type, media_content_type_e media_type, char* uuid, char* path, char* mime_type, void* user_data)
153 {
154         SysLog(NID_CNT, "OnContentUpdateCompleted callback method is called.");
155
156         result r = E_SUCCESS;
157
158         SysTryLogReturn(NID_CNT, user_data != null, , "OnContentUpdateCompleted failed.");
159
160         _ContentManagerImpl* pTempManagerImpl = static_cast< _ContentManagerImpl* >(user_data);
161         SysTryLogReturn(NID_CNT, pTempManagerImpl != null, , "pTempManagerImpl is null.");
162
163         IContentUpdateEventListener* pListener = pTempManagerImpl->GetListener();
164         SysTryLogReturn(NID_CNT, pListener != null, , "IContentUpdateEventListener is null.");
165
166         if (error != MEDIA_CONTENT_ERROR_NONE)
167         {
168                 r = E_SYSTEM;
169         }
170
171         switch (update_item)
172         {
173         case MEDIA_ITEM_FILE:
174         {
175                 ContentType contentType = CONTENT_TYPE_UNKNOWN;
176
177                 switch (media_type)
178                 {
179                 case MEDIA_CONTENT_TYPE_IMAGE:
180                         contentType = CONTENT_TYPE_IMAGE;
181                         break;
182
183                 case MEDIA_CONTENT_TYPE_VIDEO:
184                         contentType = CONTENT_TYPE_VIDEO;
185                         break;
186
187                 case MEDIA_CONTENT_TYPE_SOUND:
188                         // fall through
189                 case MEDIA_CONTENT_TYPE_MUSIC:
190                         contentType = CONTENT_TYPE_AUDIO;
191                         break;
192
193                 case MEDIA_CONTENT_TYPE_OTHERS:
194                         contentType = CONTENT_TYPE_OTHER;
195                         break;
196
197                 default:
198                         r = E_SYSTEM;
199                         SysLog(NID_CNT, "media_type is invalid.");
200                         break;
201                 }
202
203                 String str(uuid);
204                 ContentId contentId;
205
206                 result res = UuId::Parse(str, contentId);
207                 SysTryLogReturn(NID_CNT, !IsFailed(res), , "Failed to parse to the content ID.");
208
209                 switch (update_type)
210                 {
211                 case MEDIA_CONTENT_INSERT:
212                         pListener->OnContentFileCreated(contentId, contentType, r);
213                         break;
214
215                 case MEDIA_CONTENT_DELETE:
216                         pListener->OnContentFileDeleted(contentId, contentType, r);
217                         break;
218
219                 case MEDIA_CONTENT_UPDATE:
220                         pListener->OnContentFileUpdated(contentId, contentType, r);
221                         break;
222
223                 default:
224                         SysLog(NID_CNT, "update_type is invalid.");
225                         break;
226                 }
227                 break;
228         }
229
230         case MEDIA_ITEM_DIRECTORY:
231         {
232                 String directoryPath(path);
233
234                 pListener->OnContentDirectoryScanCompleted(directoryPath, r);
235                 break;
236         }
237
238         default:
239                 SysLog(NID_CNT, "update_item is invalid.");
240                 break;
241         }
242
243         SysLog(NID_CNT, "Fire the OnContentUpdateCompleted method.");
244 }
245
246 _ContentManagerImpl::_ContentManagerImpl(void)
247         : __isConnected(false)
248         , __pListener(null)
249 {
250
251 }
252
253 _ContentManagerImpl::~_ContentManagerImpl(void)
254 {
255         int val;
256
257         if (GetListener())
258         {
259                 val = media_content_unset_db_updated_cb();
260                 SysLog(NID_CNT, "media_content_unset_db_updated_cb result[%d].", val);
261         }
262
263         val = media_content_disconnect();
264         SysLog(NID_CNT, "media_content_disconnect result[%d].", val);
265 }
266
267 _ContentManagerImpl*
268 _ContentManagerImpl::GetInstance(ContentManager& contentManager)
269 {
270         return contentManager.__pContentManagerImpl;
271 }
272
273 const _ContentManagerImpl*
274 _ContentManagerImpl::GetInstance(const ContentManager& contentManager)
275 {
276         return contentManager.__pContentManagerImpl;
277 }
278
279 result
280 _ContentManagerImpl::Construct(void)
281 {
282         int val = media_content_connect();
283         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM,
284                         "The connection failed[%d].", val);
285
286         SysLog(NID_CNT, "media_content_connect result[%d].", val);
287
288         __isConnected = true;
289
290         return E_SUCCESS;
291 }
292
293 ContentId
294 _ContentManagerImpl::CreateContent(const ContentInfo& contentInfo)
295 {
296         ClearLastResult();
297
298         _ContentInfoImpl* pInfoImpl = const_cast< _ContentInfoImpl* >(_ContentInfoImpl::GetInstance(contentInfo));
299         SysTryReturn(NID_CNT, pInfoImpl != null, UuId::GetInvalidUuId(), E_INVALID_ARG,
300                         "[E_INVALID_ARG] Invalid argument is used. ContentInfo is invalid.");
301
302         String contentPath(pInfoImpl->GetPhysicalContentPath());
303         String changedPath(L"");
304
305         result r = ChangeTizenPathToCompat(contentPath, changedPath);
306         SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] Failed to perform ChangeTizenPathToCompat.", GetErrorMessage(r));
307
308         SysTryReturn(NID_CNT, _FileImpl::IsFileExist(changedPath), UuId::GetInvalidUuId(), E_FILE_NOT_FOUND,
309                         "[%s] The file cound not be found.", GetErrorMessage(E_FILE_NOT_FOUND));
310
311         SysTryReturn(NID_CNT, pInfoImpl->GetContentId() == UuId::GetInvalidUuId(), UuId::GetInvalidUuId(),
312                         E_INVALID_ARG, "[E_INVALID_ARG] The contentId is not empty.");
313
314         // Compare the type of input parameter and system
315         ContentType inputType = pInfoImpl->GetContentType();
316         ContentType sysType = _ContentManagerUtilImpl::CheckContentType(contentPath, true);
317
318         ClearLastResult();
319
320         if (inputType != sysType)
321         {
322                 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
323                 {
324                         SysLogException(NID_CNT, E_INVALID_ARG,
325                                         "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
326                         return UuId::GetInvalidUuId();
327                 }
328         }
329
330         // Save data to database with contentPath.
331         unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(contentPath));
332         SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
333                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
334
335         media_info_h tempMediaInfo = null;
336         unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
337
338         int val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
339         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
340                         "The registration to database failed[%d].", val);
341
342         pMediaInfo.reset(tempMediaInfo);
343
344         ContentId contentId = SaveDataToDatabase(pMediaInfo.get(), pInfoImpl);
345         r = GetLastResult();
346         SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
347                         "[%s] The registration to database failed.", GetErrorMessage(r));
348
349         return contentId;
350
351 CATCH:
352         // There are two steps(insert and update) for content registration.
353         // If the update failed after inserting, the inserted data SHOULD be deleted from here.
354         val = media_info_delete_from_db(pStr.get());
355         SysLog(NID_CNT, "The result of deletion from database[%d].", val);
356
357         return UuId::GetInvalidUuId();
358 }
359
360 ContentId
361 _ContentManagerImpl::CreateContent(const ByteBuffer& byteBuffer, const String& destinationPath,
362                                             const ContentInfo* pContentInfo)
363 {
364         ClearLastResult();
365
366         // Check parameters(for length)
367         SysTryReturn(NID_CNT, byteBuffer.GetRemaining() > 0, UuId::GetInvalidUuId(), E_INVALID_ARG,
368                         "[E_INVALID_ARG] byteBuffer is invalid.");
369
370         // Check parameters(for path compatibility)
371         SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(destinationPath), UuId::GetInvalidUuId(),
372                         E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", destinationPath.GetPointer());
373         SysTryReturn(NID_CNT, !_FileImpl::IsFileExist(destinationPath), UuId::GetInvalidUuId(), E_FILE_ALREADY_EXIST,
374                         "[E_FILE_ALREADY_EXIST] The specified file already exists.");
375
376         // Create a file with bytebuffer
377         unique_ptr<File> pFile(new (nothrow) File);
378         SysTryReturn(NID_CNT, pFile != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
379                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
380
381         result r = pFile->Construct(destinationPath, L"w+");
382         SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r,
383                         "[%s] The destination file can not be created.", GetErrorMessage(r));
384
385         _FileImpl* pFileImpl = _FileImpl::GetInstance(*pFile);
386         SysTryReturn(NID_CNT, pFileImpl != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
387                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
388
389         r = pFileImpl->Write(byteBuffer);
390         SysTryReturn(NID_CNT, !(IsFailed(r)), UuId::GetInvalidUuId(), r,
391                         "[%s] The data can not be written in the destination file.", GetErrorMessage(r));
392
393         // for release file pointer
394         pFile.reset();
395
396         int val = 0;
397         ContentId contentId;
398         _ContentInfoImpl* pInfoImpl = null;
399         _ImageContentInfoImpl imageContentInfoImpl;
400         _AudioContentInfoImpl audioContentInfoImpl;
401         _VideoContentInfoImpl videoContentInfoImpl;
402         _OtherContentInfoImpl otherContentInfoImpl;
403         media_info_h tempMediaInfo = null;
404         unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
405         unique_ptr<char[]> pStr(null);
406         String destPath(L"");
407
408         r = ChangeCompatPathToTizen(destinationPath, destPath);
409         SysTryCatch(NID_CNT, !IsFailed(r), , r, "[%s] Failed to perform ChangedCompatPathToTizen.", GetErrorMessage(r));
410
411         if (pContentInfo != null)
412         {
413                 pInfoImpl = const_cast< _ContentInfoImpl* >(_ContentInfoImpl::GetInstance(*pContentInfo));
414                 SysTryCatch(NID_CNT, pInfoImpl != null, , E_INVALID_ARG,
415                                 "[E_INVALID_ARG] Invalid argument is used. ContentInfo is invalid.");
416
417                 SysTryCatch(NID_CNT, pInfoImpl->GetContentId() == UuId::GetInvalidUuId(), , E_INVALID_ARG,
418                                 "[E_INVALID_ARG] The content already exists in database.");
419
420                 // Compare the type of input parameter and system
421                 // CheckContentType() need actual file. so it should be checked after creating the file.
422                 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
423                 ContentType inputType = pInfoImpl->GetContentType();
424
425                 ClearLastResult();
426
427                 if (inputType != sysType)
428                 {
429                         if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
430                         {
431                                 SysLogException(NID_CNT, E_INVALID_ARG,
432                                                 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
433                                 goto CATCH;
434                         }
435                 }
436
437                 // Sets the content path
438                 pInfoImpl->SetContentPath(destPath);
439         }
440         else
441         {
442                 ContentType contentType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
443
444                 ClearLastResult();
445
446                 // Set the content path
447                 if (contentType == CONTENT_TYPE_IMAGE)
448                 {
449                         r = imageContentInfoImpl.Construct(&destinationPath);
450                         SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
451                                         "[E_OUT_OF_MEMORY] Failed to perform Construct for ImageContentInfoImpl.");
452
453                         imageContentInfoImpl.SetContentPath(destPath);
454                         pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&imageContentInfoImpl);
455                 }
456                 else if (contentType == CONTENT_TYPE_AUDIO)
457                 {
458                         r = audioContentInfoImpl.Construct(&destinationPath);
459                         SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
460                                         "[E_OUT_OF_MEMORY] Failed to perform Construct for AudioContentInfoImpl.");
461
462                         audioContentInfoImpl.SetContentPath(destPath);
463                         pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&audioContentInfoImpl);
464                 }
465                 else if (contentType == CONTENT_TYPE_VIDEO)
466                 {
467                         r = videoContentInfoImpl.Construct(&destinationPath);
468                         SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
469                                         "[E_OUT_OF_MEMORY] Failed to perform Construct for VideoContentInfoImpl.");
470
471                         videoContentInfoImpl.SetContentPath(destPath);
472                         pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&videoContentInfoImpl);
473                 }
474                 else
475                 {
476                         r = otherContentInfoImpl.Construct(&destinationPath);
477                         SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
478                                         "[E_OUT_OF_MEMORY] Failed to perform Construct for OtherContentInfoImpl.");
479
480                         otherContentInfoImpl.SetContentPath(destPath);
481                         pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&otherContentInfoImpl);
482                 }
483         }
484
485         // Register the content to database directly.
486         pStr.reset(_StringConverter::CopyToCharArrayN(destPath));
487         SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
488
489         val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
490         SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
491                         "media_info_insert_to_db failed[%d].", val);
492
493         pMediaInfo.reset(tempMediaInfo);
494
495         contentId = SaveDataToDatabase(pMediaInfo.get(), pInfoImpl);
496         r = GetLastResult();
497         SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
498                         "[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
499
500         return contentId;
501
502 CATCH:
503         result saveResult = GetLastResult();
504
505         // If the destination file is made by this method, it should be deleted when error occurs.
506         r = _FileImpl::Remove(destinationPath);
507         SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
508
509         if (pMediaInfo != null)
510         {
511                 val = media_info_delete_from_db(pStr.get());
512                 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
513         }
514
515         SetLastResult(saveResult);
516         return UuId::GetInvalidUuId();
517 }
518
519 ContentId
520 _ContentManagerImpl::CreateContent(const String& sourcePath, const String& destinationPath, bool deleteSource,
521                                             const ContentInfo* pContentInfo)
522 {
523         ClearLastResult();
524
525         // Check parameters(for type)
526         SysTryReturn(NID_CNT, _FileImpl::GetFileExtension(sourcePath) == _FileImpl::GetFileExtension(destinationPath),
527                         UuId::GetInvalidUuId(), E_INVALID_ARG, "[E_INVALID_ARG] There is a mismatch between the type of source and dest path.");
528
529         // Check parameters(for path compatibility)
530         SysTryReturn(NID_CNT, VerifyHomeFilePathCompatibility(sourcePath), UuId::GetInvalidUuId(), E_INVALID_ARG,
531                         "[E_INVALID_ARG] %ls is not compatible.", sourcePath.GetPointer());
532         SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(destinationPath), UuId::GetInvalidUuId(),
533                         E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", destinationPath.GetPointer());
534
535         result r = E_SUCCESS;
536         bool isCopy = false;
537
538         if (deleteSource) // move
539         {
540                 r = _FileImpl::Move(sourcePath, destinationPath);
541                 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Moving the file failed.", GetErrorMessage(r));
542         }
543         else // copy
544         {
545                 r = _FileImpl::Copy(sourcePath, destinationPath, true);
546                 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Copying the file failed.", GetErrorMessage(r));
547
548                 isCopy = true;
549         }
550
551         int val = 0;
552         ContentId contentId;
553         _ContentInfoImpl* pInfoImpl = null;
554         _ImageContentInfoImpl imageContentInfoImpl;
555         _AudioContentInfoImpl audioContentInfoImpl;
556         _VideoContentInfoImpl videoContentInfoImpl;
557         _OtherContentInfoImpl otherContentInfoImpl;
558         media_info_h tempMediaInfo = null;
559         unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
560         unique_ptr<char[]> pStr(null);
561         String destPath(L"");
562
563         r = ChangeCompatPathToTizen(destinationPath, destPath);
564         SysTryCatch(NID_CNT, !IsFailed(r), , r, "[%s] Failed to perform ChangedCompatPathToTizen.", GetErrorMessage(r));
565
566         if (pContentInfo != null)
567         {
568                 pInfoImpl = const_cast< _ContentInfoImpl* >(_ContentInfoImpl::GetInstance(*pContentInfo));
569                 SysTryCatch(NID_CNT, pInfoImpl != null, , E_INVALID_ARG,
570                                 "[E_INVALID_ARG] Invalid argument is used. ContentInfo is invalid.");
571
572                 SysTryCatch(NID_CNT, pInfoImpl->GetContentId() == UuId::GetInvalidUuId(), , E_INVALID_ARG,
573                                 "[E_INVALID_ARG] The content already exists in database.");
574
575                 // Compare the type of input parameter and system
576                 // CheckContentType() need actual file. so it should be checked after creating the file.
577                 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
578                 ContentType inputType = pInfoImpl->GetContentType();
579
580                 ClearLastResult();
581
582                 if (inputType != sysType)
583                 {
584                         if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
585                         {
586                                 SysLogException(NID_CNT, E_INVALID_ARG,
587                                                  "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
588                                 goto CATCH;
589                         }
590                 }
591
592                 // Set the content path
593                 pInfoImpl->SetContentPath(destPath);
594         }
595         else
596         {
597                 ContentType contentType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
598
599                 ClearLastResult();
600
601                 // Set the content path
602                 if (contentType == CONTENT_TYPE_IMAGE)
603                 {
604                         r = imageContentInfoImpl.Construct(&destinationPath);
605                         SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
606                                         "[E_OUT_OF_MEMORY] Failed to perform Construct for ImageContentInfoImpl.");
607
608                         imageContentInfoImpl.SetContentPath(destPath);
609                         pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&imageContentInfoImpl);
610                 }
611                 else if (contentType == CONTENT_TYPE_AUDIO)
612                 {
613                         r = audioContentInfoImpl.Construct(&destinationPath);
614                         SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
615                                         "[E_OUT_OF_MEMORY] Failed to perform Construct for AudioContentInfoImpl.");
616
617                         audioContentInfoImpl.SetContentPath(destPath);
618                         pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&audioContentInfoImpl);
619                 }
620                 else if (contentType == CONTENT_TYPE_VIDEO)
621                 {
622                         r = videoContentInfoImpl.Construct(&destinationPath);
623                         SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
624                                         "[E_OUT_OF_MEMORY] Failed to perform Construct for VideoContentInfoImpl.");
625
626                         videoContentInfoImpl.SetContentPath(destPath);
627                         pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&videoContentInfoImpl);
628                 }
629                 else
630                 {
631                         r = otherContentInfoImpl.Construct(&destinationPath);
632                         SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
633                                         "[E_OUT_OF_MEMORY] Failed to perform Construct for OtherContentInfoImpl.");
634
635                         otherContentInfoImpl.SetContentPath(destPath);
636                         pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&otherContentInfoImpl);
637                 }
638         }
639
640         pStr.reset(_StringConverter::CopyToCharArrayN(destPath));
641         SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
642
643         val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
644         SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
645                         "media_info_insert_to_db failed[%d].", val);
646
647         pMediaInfo.reset(tempMediaInfo);
648
649         contentId = SaveDataToDatabase(pMediaInfo.get(), pInfoImpl);
650         r = GetLastResult();
651         SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
652                         "[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
653
654         return contentId;
655
656 CATCH:
657         result saveResult = GetLastResult();
658
659         if (isCopy)
660         {
661                 r = _FileImpl::Remove(destinationPath);
662                 SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
663         }
664         else
665         {
666                 r = _FileImpl::Move(destinationPath, sourcePath);
667                 SysLog(NID_CNT, "Move[%s].", GetErrorMessage(r));
668         }
669
670         if (pMediaInfo != null)
671         {
672                 val = media_info_delete_from_db(pStr.get());
673                 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
674         }
675
676         SetLastResult(saveResult);
677         return UuId::GetInvalidUuId();
678 }
679
680 ContentInfo*
681 _ContentManagerImpl::GetContentInfoN(const ContentId& contentId) const
682 {
683         ClearLastResult();
684
685         SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), null, E_INVALID_ARG,
686                         "[E_INVALID_ARG] The contentId is invalid.");
687
688         unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(contentId.ToString()));
689         SysTryReturn(NID_CNT, pStr != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
690
691         media_info_h tempMediaInfo = null;
692         unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
693         int val = media_info_get_media_from_db(pStr.get(), &tempMediaInfo);
694         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
695                         "media_info_get_media_from_db failed[%d].", val);
696
697         pMediaInfo.reset(tempMediaInfo);
698
699         media_content_type_e systemType = MEDIA_CONTENT_TYPE_IMAGE;
700         val = media_info_get_media_type(pMediaInfo.get(), &systemType);
701         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
702                         "media_info_get_media_type failed[%d].", val);
703
704         char* pTempFilePath = null;
705         val = media_info_get_file_path(pMediaInfo.get(), &pTempFilePath);
706         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
707                         "media_info_get_file_path failed[%d].", val);
708
709         unique_ptr<char, CharDeleter> pFilePath(pTempFilePath);
710         String contentPath(pFilePath.get());
711         String changedPath(L"");
712
713         result r = E_SUCCESS;
714
715         r = ChangeTizenPathToCompat(contentPath, changedPath);
716         SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] Failed to perform ChangeTizenPathToCompat.", GetErrorMessage(r));
717
718         SysTryReturn(NID_CNT, _FileImpl::IsFileExist(changedPath), null, E_FILE_NOT_FOUND,
719                         "[E_FILE_NOT_FOUND] The file corresponding to contentId could not be found.");
720
721         if (systemType == SYSTEM_TYPE_IMAGE)
722         {
723                 unique_ptr< ImageContentInfo > pImageContentInfo(new (nothrow) ImageContentInfo);
724                 SysTryReturn(NID_CNT, pImageContentInfo != null, null, E_OUT_OF_MEMORY,
725                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
726
727                 r = pImageContentInfo->Construct(&changedPath);
728                 r = ConvertErrorToResult(r);
729                 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
730                                 "[%s] Failed to perform Construct operation to ImageContentInfo.", GetErrorMessage(r));
731
732                 _ImageContentInfoImpl* pImageContentInfoImpl = _ImageContentInfoImpl::GetInstance(*(pImageContentInfo.get()));
733                 SysTryReturn(NID_CNT, pImageContentInfoImpl != null, null, E_OUT_OF_MEMORY,
734                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
735
736                 r = MakeContentInfo(pMediaInfo.get(), systemType, pImageContentInfoImpl);
737                 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
738
739                 return pImageContentInfo.release();
740         }
741         else if (systemType == SYSTEM_TYPE_SOUND || systemType == SYSTEM_TYPE_MUSIC)
742         {
743                 unique_ptr< AudioContentInfo > pAudioContentInfo(new (nothrow) AudioContentInfo);
744                 SysTryReturn(NID_CNT, pAudioContentInfo != null, null, E_OUT_OF_MEMORY,
745                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
746
747                 r = pAudioContentInfo->Construct(&changedPath);
748                 r = ConvertErrorToResult(r);
749                 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
750                                 "[%s] Failed to perform Construct operation to AudioContentInfo.", GetErrorMessage(r));
751
752                 _AudioContentInfoImpl* pAudioContentInfoImpl = _AudioContentInfoImpl::GetInstance(*(pAudioContentInfo.get()));
753                 SysTryReturn(NID_CNT, pAudioContentInfoImpl != null, null, E_OUT_OF_MEMORY,
754                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
755
756                 r = MakeContentInfo(pMediaInfo.get(), systemType, pAudioContentInfoImpl);
757                 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
758
759                 return pAudioContentInfo.release();
760         }
761         else if (systemType == SYSTEM_TYPE_VIDEO)
762         {
763                 unique_ptr< VideoContentInfo > pVideoContentInfo(new (nothrow) VideoContentInfo);
764                 SysTryReturn(NID_CNT, pVideoContentInfo != null, null, E_OUT_OF_MEMORY,
765                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
766
767                 r = pVideoContentInfo->Construct(&changedPath);
768                 r = ConvertErrorToResult(r);
769                 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
770                                 "[%s] Failed to perform Construct operation to VideoContentInfo.", GetErrorMessage(r));
771
772                 _VideoContentInfoImpl* pVideoContentInfoImpl = _VideoContentInfoImpl::GetInstance(*(pVideoContentInfo.get()));
773                 SysTryReturn(NID_CNT, pVideoContentInfoImpl != null, null, E_OUT_OF_MEMORY,
774                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
775
776                 r = MakeContentInfo(pMediaInfo.get(), systemType, pVideoContentInfoImpl);
777                 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
778
779                 return pVideoContentInfo.release();
780         }
781         else if (systemType == SYSTEM_TYPE_OTHER)
782         {
783                 unique_ptr< OtherContentInfo > pOtherContentInfo(new (nothrow) OtherContentInfo);
784                 SysTryReturn(NID_CNT, pOtherContentInfo != null, null, E_OUT_OF_MEMORY,
785                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
786
787                 r = pOtherContentInfo->Construct(&changedPath);
788                 r = ConvertErrorToResult(r);
789                 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
790                                 "[%s] Failed to perform Construct operation to OtherContentInfo.", GetErrorMessage(r));
791
792                 _OtherContentInfoImpl* pOtherContentInfoImpl = _OtherContentInfoImpl::GetInstance(*(pOtherContentInfo.get()));
793                 SysTryReturn(NID_CNT, pOtherContentInfoImpl != null, null, E_OUT_OF_MEMORY,
794                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
795
796                 r = MakeContentInfo(pMediaInfo.get(), systemType, pOtherContentInfoImpl);
797                 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
798
799                 return pOtherContentInfo.release();
800         }
801         else
802         {
803                 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] Unsupported type");
804                 return null;
805         }
806 }
807
808 result
809 _ContentManagerImpl::UpdateContent(const ContentInfo& contentInfo)
810 {
811         const _ContentInfoImpl* pInfoImpl = _ContentInfoImpl::GetInstance(contentInfo);
812         SysTryReturnResult(NID_CNT, pInfoImpl != null, E_INVALID_ARG, "Invalid argument is used. ContentInfo is invalid.");
813
814         ContentId contentId = pInfoImpl->GetContentId();
815         SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, "The content id is invalid.");
816         SysTryReturnResult(NID_CNT, _FileImpl::IsFileExist(pInfoImpl->GetContentPath()), E_FILE_NOT_FOUND,
817                         "The file corresponding to contentInfo could not be found.");
818
819         result r = UpdateDataToDatabase(pInfoImpl);
820         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "UpdateDataToDatabase failed.");
821
822         return r;
823 }
824
825 result
826 _ContentManagerImpl::DeleteContent(const ContentId& contentId)
827 {
828         SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, "The contentId is invalid.");
829
830         unique_ptr<char[]> pContentId(_StringConverter::CopyToCharArrayN(contentId.ToString()));
831         SysTryReturnResult(NID_CNT, pContentId != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
832
833         result r = E_SUCCESS;
834         int val = 0;
835         media_info_h tempMediaInfo = null;
836         unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
837
838         val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
839         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
840                         "media_info_get_media_from_db failed[%d].", val);
841
842         pMediaInfo.reset(tempMediaInfo);
843
844         char* pTempPath = null;
845
846         val = media_info_get_file_path(pMediaInfo.get(), &pTempPath);
847         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
848                         "media_info_get_file_path failed[%d].", val);
849
850         unique_ptr<char, CharDeleter> pContentPath(pTempPath);
851         String contentPath(pContentPath.get());
852         String changedPath(L"");
853
854         r = ChangeTizenPathToCompat(contentPath, changedPath);
855         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "[%s] Failed to perform ChangeTizenPathToCompat.", GetErrorMessage(r));
856
857         SysTryReturnResult(NID_CNT, _FileImpl::IsFileExist(changedPath), E_FILE_NOT_FOUND,
858                         "The file corresponding to contentId could not be found.");
859
860         val = media_info_delete_from_db(pContentId.get());
861         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
862                         "media_info_delete_From_db failed[%d].", val);
863
864         r = _FileImpl::Remove(changedPath);
865         SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The file is not deleted.");
866
867         return r;
868 }
869
870 result
871 _ContentManagerImpl::AddContentUpdateEventListener(IContentUpdateEventListener& listener)
872 {
873         SysTryReturnResult(NID_CNT, GetListener() == null, E_OBJ_ALREADY_EXIST, "IContentUpdateEventListener is already set.");
874
875         SetListener(&listener);
876
877         int val = media_content_set_db_updated_cb(OnContentUpdateCompleted, this);
878         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "media_content_set_db_updated_cb failed[%d].", val);
879
880         return E_SUCCESS;
881 }
882
883 result
884 _ContentManagerImpl::RemoveContentUpdateEventListener(IContentUpdateEventListener& listener)
885 {
886         SysTryReturnResult(NID_CNT, GetListener() == &listener, E_OBJ_NOT_FOUND, "The input listener is not equal to the registered listener.");
887
888         int val = media_content_unset_db_updated_cb();
889         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "media_content_unset_db_updated_cb failed[%d].", val);
890
891         SetListener(null);
892
893         return E_SUCCESS;
894 }
895
896 result
897 _ContentManagerImpl::ScanFile(const Tizen::Base::String& contentPath)
898 {
899         SysSecureLog(NID_CNT, "The scan path is [%ls].", contentPath.GetPointer());
900
901         unique_ptr<char[]> pContentPath(_StringConverter::CopyToCharArrayN(contentPath));
902         SysTryReturnResult(NID_CNT, pContentPath, E_SYSTEM, "pContentPath is NULL.");
903
904         int val = media_content_connect();
905         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The connection failed[%d].", val);
906
907         val = media_content_scan_file(pContentPath.get());
908         result r = ConvertError(val);
909         SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , r, "[%s] media_content_scan_file failed[%d].", GetErrorMessage(r), val);
910
911         val = media_content_disconnect();
912         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The disconnection failed[%d].", val);
913
914         return E_SUCCESS;
915
916 CATCH:
917         val = media_content_disconnect();
918         SysTryLog(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, "The disconnection failed[%d].", val);
919
920         return r;
921 }
922
923 result
924 _ContentManagerImpl::ScanDirectory(const Tizen::Base::String& directoryPath, bool recursive, IContentScanListener* pListener, RequestId& reqId)
925 {
926         static RequestId requestId = 0;
927
928         SysLog(NID_CNT, "The scan path is [%ls].", directoryPath.GetPointer());
929
930         unique_ptr<char[]> pDirPath(_StringConverter::CopyToCharArrayN(directoryPath));
931         SysTryReturnResult(NID_CNT, pDirPath, E_SYSTEM, "pDirPath is NULL.");
932
933         int val = media_content_connect();
934         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The connection failed[%d].", val);
935
936         unique_ptr< _ScanResult > pScanResult(new (nothrow) _ScanResult);
937         SysTryReturnResult(NID_CNT, pScanResult != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
938
939         reqId = requestId++;
940
941         pScanResult->scanPath = directoryPath;
942         pScanResult->pScanListener = pListener;
943         pScanResult->requestId = reqId;
944
945         val = media_content_scan_folder(pDirPath.get(), recursive, OnScanCompleted, pScanResult.release());
946         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val), "media_content_scan_folder failed[%d].", val);
947
948         return E_SUCCESS;
949 }
950
951 result
952 _ContentManagerImpl::UpdateDataToDatabase(const _ContentInfoImpl* pContentInfoImpl) const
953 {
954         SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_INVALID_ARG, "pContentInfoImpl is null.");
955
956         media_info_h tempMediaInfo = null;
957         unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
958         unique_ptr<char[]> pContentId(_StringConverter::CopyToCharArrayN((pContentInfoImpl->GetContentId()).ToString()));
959         SysTryReturnResult(NID_CNT, pContentId != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
960
961         int val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
962         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
963                         "media_info_get_media_from_db failed[%d].", val);
964
965         pMediaInfo.reset(tempMediaInfo);
966
967         result r = E_SUCCESS;
968         unique_ptr<char[]> pValue(null);
969
970         // author
971         pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetAuthor()));
972         SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
973
974         val = media_info_set_author(pMediaInfo.get(), pValue.get());
975         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
976                         "media_info_set_author failed[%d].", val);
977
978         // category
979         pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetCategory()));
980         SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
981
982         val = media_info_set_category(pMediaInfo.get(), pValue.get());
983         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
984                         "media_info_set_category failed[%d].", val);
985
986         // content name
987         pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetContentName()));
988         SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
989
990         val = media_info_set_content_name(pMediaInfo.get(), pValue.get());
991         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
992                         "media_info_set_content_name failed[%d].", val);
993
994         // description
995         pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetDescription()));
996         SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
997
998         val = media_info_set_description(pMediaInfo.get(), pValue.get());
999         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1000                         "media_info_set_description failed[%d].", val);
1001
1002         // keyword
1003         pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetKeyword()));
1004         SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1005
1006         val = media_info_set_keyword(pMediaInfo.get(), pValue.get());
1007         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1008                         "media_info_set_keyword failed[%d].", val);
1009
1010         // location tag
1011         pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetLocationTag()));
1012         SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1013
1014         val = media_info_set_location_tag(pMediaInfo.get(), pValue.get());
1015         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1016                         "media_info_set_location_tag failed[%d].", val);
1017
1018         // provider
1019         pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetProvider()));
1020         SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1021
1022         val = media_info_set_provider(pMediaInfo.get(), pValue.get());
1023         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1024                         "media_info_set_provider failed[%d].", val);
1025
1026         // rating
1027         pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetRating()));
1028         SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1029
1030         val = media_info_set_age_rating(pMediaInfo.get(), pValue.get());
1031         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1032                         "media_info_set_age_rating failed[%d].", val);
1033
1034         // latitude, longitude, altitude
1035         if (Double::Compare(pContentInfoImpl->GetLatitude(), DEFAULT_COORDINATE) != 0 &&
1036                         Double::Compare(pContentInfoImpl->GetLongitude(), DEFAULT_COORDINATE) != 0)
1037         {
1038                 val = media_info_set_latitude(pMediaInfo.get(), pContentInfoImpl->GetLatitude());
1039                 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1040                                 "media_info_set_latitude failed[%d].", val);
1041
1042                 val = media_info_set_longitude(pMediaInfo.get(), pContentInfoImpl->GetLongitude());
1043                 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1044                                 "media_info_set_longitude failed[%d].", val);
1045
1046                 if (Double::Compare(pContentInfoImpl->GetAltitude(), DEFAULT_COORDINATE) != 0)
1047                 {
1048                         val = media_info_set_altitude(pMediaInfo.get(), pContentInfoImpl->GetAltitude());
1049                         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1050                                         "media_info_set_altitude failed[%d].", val);
1051                 }
1052         }
1053
1054         val = media_info_update_to_db(pMediaInfo.get());
1055         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1056                         "media_info_update_to_db failed[%d].", val);
1057
1058         return r;
1059 }
1060
1061 ContentId
1062 _ContentManagerImpl::SaveDataToDatabase(const media_info_h pMediaInfo,
1063                                                                                                 _ContentInfoImpl* pContentInfoImpl) const
1064 {
1065         ClearLastResult();
1066         result r = E_SUCCESS;
1067
1068         SysTryReturn(NID_CNT, pContentInfoImpl != null, UuId::GetInvalidUuId(), E_INVALID_ARG,
1069                         "[E_INVALID_ARG] Invalid argument is used. ContentInfo is invalid.");
1070
1071         String contentPath(pContentInfoImpl->GetPhysicalContentPath());
1072         String changedPath(L"");
1073
1074         r = ChangeTizenPathToCompat(contentPath, changedPath);
1075         SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r,
1076                         "[%s] Failed to perform ChangeTizenPathToCompat.", GetErrorMessage(r));
1077
1078         String mimeType(L"");
1079         String extension = _FileImpl::GetFileExtension(changedPath);
1080         r = GetLastResult();
1081         if (IsFailed(r))
1082         {
1083                 ClearLastResult();
1084
1085                 SysLog(NID_CNT, "[%s] Failed to perform GetFileExtension operation.", GetErrorMessage(r));
1086
1087                 unique_ptr<char[]> pTempPath(_StringConverter::CopyToCharArrayN(contentPath));
1088                 SysTryReturn(NID_CNT, pTempPath != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1089                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1090
1091                 char tempType[255] = {0, };
1092                 int ret = aul_get_mime_from_file(pTempPath.get(), tempType, sizeof(tempType));
1093                 SysTryReturn(NID_CNT, ret == AUL_R_OK, UuId::GetInvalidUuId(), E_INVALID_ARG,
1094                                 "[E_INVALID_ARG] Failed to perform aul_get_mime_from_file operation.");
1095
1096                 r = mimeType.Append(tempType);
1097                 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1098                                 "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
1099
1100         }
1101
1102         // If the content format is JPG and it has GPS data, it will be saved in database automatically.
1103         if (extension == L"jpg" || extension == L"jpeg" || extension == L"JPG" || extension == L"JPEG" || mimeType.Contains(L"jpeg"))
1104         {
1105                 SysLog(NID_CNT, "The format of content is jpg.");
1106
1107                 ImageMetadata* pImageMetadata = _ContentManagerUtilImpl::GetImageMetaN(changedPath, true);
1108                 if (pImageMetadata != null)
1109                 {
1110                         pContentInfoImpl->SetLatitude(pImageMetadata->GetLatitude());
1111                         pContentInfoImpl->SetLongitude(pImageMetadata->GetLongitude());
1112
1113                         delete pImageMetadata;
1114                 }
1115
1116                 ClearLastResult();
1117         }
1118
1119         int val = 0;
1120         unique_ptr<char[]> pStr(null);
1121
1122         // author
1123         pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetAuthor()));
1124         SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1125                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
1126
1127         val = media_info_set_author(pMediaInfo, pStr.get());
1128         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1129                         "media_info_set_author failed[%d].", val);
1130
1131         // category
1132         pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetCategory()));
1133         SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1134                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
1135
1136         val = media_info_set_category(pMediaInfo, pStr.get());
1137         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1138                         "media_info_set_category failed[%d].", val);
1139
1140         // content name
1141         pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetContentName()));
1142         SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1143                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
1144
1145         val = media_info_set_content_name(pMediaInfo, pStr.get());
1146         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1147                         "media_info_set_content_name failed[%d].", val);
1148
1149         // description
1150         pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetDescription()));
1151         SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1152                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
1153
1154         val = media_info_set_description(pMediaInfo, pStr.get());
1155         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1156                         "media_info_set_description failed[%d].", val);
1157
1158         // keyword
1159         pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetKeyword()));
1160         SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1161                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
1162
1163         val = media_info_set_keyword(pMediaInfo, pStr.get());
1164         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1165                         "media_info_set_keyword failed[%d].", val);
1166
1167         // location tag
1168         pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetLocationTag()));
1169         SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1170                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
1171
1172         val = media_info_set_location_tag(pMediaInfo, pStr.get());
1173         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1174                         "media_info_set_location_tag failed[%d].", val);
1175
1176         // provider
1177         pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetProvider()));
1178         SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1179                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
1180
1181         val = media_info_set_provider(pMediaInfo, pStr.get());
1182         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1183                         "media_info_set_provider failed[%d].", val);
1184
1185         // rating
1186         pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetRating()));
1187         SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1188                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
1189
1190         val = media_info_set_age_rating(pMediaInfo, pStr.get());
1191         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1192                         "media_info_set_age_rating failed[%d].", val);
1193
1194         // latitude, longitude, altitude
1195         if (Double::Compare(pContentInfoImpl->GetLatitude(), DEFAULT_COORDINATE) != 0 &&
1196                         Double::Compare(pContentInfoImpl->GetLongitude(), DEFAULT_COORDINATE) != 0)
1197         {
1198                 val = media_info_set_latitude(pMediaInfo, pContentInfoImpl->GetLatitude());
1199                 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1200                                 "media_info_set_latitude failed[%d].", val);
1201
1202                 val = media_info_set_longitude(pMediaInfo, pContentInfoImpl->GetLongitude());
1203                 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1204                                 "media_info_set_longitude failed[%d].", val);
1205
1206                 if (Double::Compare(pContentInfoImpl->GetAltitude(), DEFAULT_COORDINATE) != 0)
1207                 {
1208                         val = media_info_set_altitude(pMediaInfo, pContentInfoImpl->GetAltitude());
1209                         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1210                                         "media_info_set_altitude failed[%d].", val);
1211                 }
1212         }
1213
1214         val = media_info_update_to_db(pMediaInfo);
1215         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1216                         "media_info_update_to_db failed[%d].", val);
1217
1218         char* pTempMediaId = null;
1219         unique_ptr<char, CharDeleter> pMediaId(null);
1220
1221         val = media_info_get_media_id(pMediaInfo, &pTempMediaId);
1222         if (pTempMediaId != null)
1223         {
1224                 pMediaId.reset(pTempMediaId);
1225         }
1226         else
1227         {
1228                 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1229                                 "media_info_get_media_id failed[%d].", val);
1230         }
1231
1232         String tempContentId(pMediaId.get());
1233         ContentId contentId;
1234
1235         r = UuId::Parse(tempContentId, contentId);
1236         SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_INVALID_ARG,
1237                         "[E_INVALID_ARG] UuId::Parse failed.");
1238
1239         return contentId;
1240 }
1241
1242 result
1243 _ContentManagerImpl::MakeContentInfo(const media_info_h pMediaInfo, int systemType, void* pInfoImpl) const
1244 {
1245         SysTryReturnResult(NID_CNT, pMediaInfo != null && pInfoImpl != null, E_INVALID_ARG,
1246                         "The specified parameter is invalid.");
1247
1248         _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1249
1250         result r = E_SUCCESS;
1251         char* pTempValue = null;
1252         unique_ptr<char, CharDeleter> pStrValue(null);
1253
1254         // contentId
1255         int val = media_info_get_media_id(pMediaInfo, &pTempValue);
1256         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1257                         "media_info_get_media_id failed[%d].", val);
1258
1259         if (pTempValue != null)
1260         {
1261                 pStrValue.reset(pTempValue);
1262
1263                 String strContentId(pStrValue.get());
1264                 ContentId contentId;
1265
1266                 r = UuId::Parse(strContentId, contentId);
1267                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The content id can not be parsed.");
1268
1269                 pContentInfoImpl->SetContentId(contentId);
1270
1271                 SysLog(NID_CNT, "INFO: contentId[%ls]", strContentId.GetPointer());
1272         }
1273
1274         // contentPath
1275         val = media_info_get_file_path(pMediaInfo, &pTempValue);
1276         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1277                         "media_info_get_file_path failed[%d].", val);
1278
1279         if (pTempValue != null)
1280         {
1281                 pStrValue.reset(pTempValue);
1282
1283                 String strFilePath(pStrValue.get());
1284
1285                 pContentInfoImpl->SetContentPath(strFilePath);
1286                 SysSecureLog(NID_CNT, "INFO: contentPath[%ls]", (pContentInfoImpl->GetContentPath()).GetPointer());
1287         }
1288
1289         // mimeType
1290         val = media_info_get_mime_type(pMediaInfo, &pTempValue);
1291         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1292                         "media_info_get_mime_type failed[%d].", val);
1293
1294         if (pTempValue != null)
1295         {
1296                 pStrValue.reset(pTempValue);
1297
1298                 pContentInfoImpl->SetMimeType(pStrValue.get());
1299
1300                 SysLog(NID_CNT, "INFO: mimeType[%ls]", (pContentInfoImpl->GetMimeType()).GetPointer());
1301         }
1302
1303         // contentSize
1304         unsigned long long longlongValue = 0;
1305         val = media_info_get_size(pMediaInfo, &longlongValue);
1306         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1307                         "media_info_get_size failed[%d].", val);
1308         pContentInfoImpl->SetContentSize(longlongValue);
1309         SysLog(NID_CNT, "INFO: contentSize[%llu]", longlongValue);
1310
1311         // storageType
1312         media_content_storage_e storageType;
1313         val = media_info_get_storage_type(pMediaInfo, &storageType);
1314         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1315                         "media_info_get_storage_type failed[%d].", val);
1316         pContentInfoImpl->SetStorageType(storageType);
1317         SysLog(NID_CNT, "INFO: storageType[%d]", storageType);
1318
1319         // isDrm
1320         bool tempDrm = false;
1321
1322         val = media_info_is_drm(pMediaInfo, &tempDrm);
1323         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1324                         "media_info_is_drm failed[%d].", val);
1325
1326         pContentInfoImpl->SetDrmProtected(tempDrm);
1327
1328         SysLog(NID_CNT, "INFO: isDrm[%d]", pContentInfoImpl->IsDrmProtected());
1329
1330         // dateTime
1331         time_t addedTime = 0;
1332         val = media_info_get_added_time(pMediaInfo, &addedTime);
1333         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1334                         "media_info_get_added_time failed[%d].", val);
1335
1336         DateTime dt;
1337         r = dt.SetValue(1970, 1, 1);
1338         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.SetValue operation.");
1339         r = dt.AddSeconds(addedTime);// need to check addedTime is secs/millisec
1340         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.AddSeconds operation.");
1341
1342         pContentInfoImpl->SetDateTime(dt);
1343         SysLog(NID_CNT, "INFO: dateTime[%ls]", ((pContentInfoImpl->GetDateTime()).ToString()).GetPointer());
1344
1345         // modifiedTime
1346         time_t modifiedTime = 0;
1347         val = media_info_get_modified_time(pMediaInfo, &modifiedTime);
1348         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1349                         "media_info_get_modified_time failed[%d].", val);
1350
1351         r = dt.SetValue(1970, 1, 1);
1352         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.SetValue operation.");
1353         r = dt.AddSeconds(modifiedTime);
1354         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.AddSeconds operation.");
1355
1356         pContentInfoImpl->SetModifiedTime(dt);
1357         SysLog(NID_CNT, "INFO: modifiedTime[%ls]", ((pContentInfoImpl->GetModifiedTime()).ToString()).GetPointer());
1358
1359         // thumbnailPath
1360         val = media_info_get_thumbnail_path(pMediaInfo, &pTempValue);
1361         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1362                         "media_info_get_thumbnail_path failed[%d].", val);
1363
1364         if (pTempValue != null)
1365         {
1366                 pStrValue.reset(pTempValue);
1367                 String thumbnailPath(pStrValue.get());
1368
1369                 pContentInfoImpl->SetThumbnailPath(thumbnailPath);
1370                 SysLog(NID_CNT, "INFO: thumbnailPath[%ls]", (pContentInfoImpl->GetThumbnailPath()).GetPointer());
1371         }
1372
1373         // author
1374         val = media_info_get_author(pMediaInfo, &pTempValue);
1375         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1376                         "media_info_get_author failed[%d].", val);
1377
1378         if (pTempValue != null)
1379         {
1380                 pStrValue.reset(pTempValue);
1381
1382                 pContentInfoImpl->SetAuthor(String(pStrValue.get()));
1383
1384                 SysLog(NID_CNT, "INFO: author[%ls]", (pContentInfoImpl->GetAuthor()).GetPointer());
1385         }
1386
1387         // category
1388         val = media_info_get_category(pMediaInfo, &pTempValue);
1389         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1390                         "media_info_get_category failed[%d].", val);
1391
1392         if (pTempValue != null)
1393         {
1394                 pStrValue.reset(pTempValue);
1395
1396                 pContentInfoImpl->SetCategory(String(pStrValue.get()));
1397
1398                 SysLog(NID_CNT, "INFO: category[%ls]", (pContentInfoImpl->GetCategory()).GetPointer());
1399         }
1400
1401         // contentName
1402         val = media_info_get_content_name(pMediaInfo, &pTempValue);
1403         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1404                         "media_info_get_content_name failed[%d].", val);
1405
1406         if (pTempValue != null)
1407         {
1408                 pStrValue.reset(pTempValue);
1409
1410                 pContentInfoImpl->SetContentName(String(pStrValue.get()));
1411
1412                 SysSecureLog(NID_CNT, "INFO: contentName[%ls]", (pContentInfoImpl->GetContentName()).GetPointer());
1413         }
1414
1415         // description
1416         val = media_info_get_description(pMediaInfo, &pTempValue);
1417         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1418                         "media_info_get_description failed[%d].", val);
1419
1420         if (pTempValue != null)
1421         {
1422                 pStrValue.reset(pTempValue);
1423
1424                 pContentInfoImpl->SetDescription(String(pStrValue.get()));
1425
1426                 SysLog(NID_CNT, "INFO: description[%ls]", (pContentInfoImpl->GetDescription()).GetPointer());
1427         }
1428
1429         // keyword
1430         val = media_info_get_keyword(pMediaInfo, &pTempValue);
1431         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1432                         "media_info_get_keyword failed[%d].", val);
1433
1434         if (pTempValue != null)
1435         {
1436                 pStrValue.reset(pTempValue);
1437
1438                 pContentInfoImpl->SetKeyword(String(pStrValue.get()));
1439
1440                 SysLog(NID_CNT, "INFO: keyword[%ls]", (pContentInfoImpl->GetKeyword()).GetPointer());
1441         }
1442
1443         // locationTag
1444         val = media_info_get_location_tag(pMediaInfo, &pTempValue);
1445         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1446                         "media_info_get_location_tag failed[%d].", val);
1447
1448         if (pTempValue != null)
1449         {
1450                 pStrValue.reset(pTempValue);
1451
1452                 pContentInfoImpl->SetLocationTag(String(pStrValue.get()));
1453
1454                 SysSecureLog(NID_CNT, "INFO: locationTag[%ls]", (pContentInfoImpl->GetLocationTag()).GetPointer());
1455         }
1456
1457         // provider
1458         val = media_info_get_provider(pMediaInfo, &pTempValue);
1459         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1460                         "media_info_get_provider failed[%d].", val);
1461
1462         if (pTempValue != null)
1463         {
1464                 pStrValue.reset(pTempValue);
1465
1466                 pContentInfoImpl->SetProvider(String(pStrValue.get()));
1467
1468                 SysLog(NID_CNT, "INFO: provider[%ls]", (pContentInfoImpl->GetProvider()).GetPointer());
1469         }
1470
1471         // rating
1472         val = media_info_get_age_rating(pMediaInfo, &pTempValue);
1473         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1474                         "media_info_get_age_rating failed[%d].", val);
1475
1476         if (pTempValue != null)
1477         {
1478                 pStrValue.reset(pTempValue);
1479
1480                 pContentInfoImpl->SetRating(String(pStrValue.get()));
1481
1482                 SysLog(NID_CNT, "INFO: rating[%ls]", (pContentInfoImpl->GetRating()).GetPointer());
1483         }
1484
1485         // coordinates
1486         Coordinates coordinates;
1487         double doubleValue = 0;
1488         val = media_info_get_latitude(pMediaInfo, &doubleValue);
1489         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1490                         "media_info_get_latitude failed[%d].", val);
1491
1492         if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1493         {
1494                 pContentInfoImpl->SetLatitude(doubleValue);
1495                 coordinates.SetLatitude(doubleValue);
1496         }
1497         SysSecureLog(NID_CNT, "INFO: latitude[%f]", pContentInfoImpl->GetLatitude());
1498
1499         val = media_info_get_longitude(pMediaInfo, &doubleValue);
1500         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1501                         "media_info_get_longitude failed[%d].", val);
1502
1503         if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1504         {
1505                 pContentInfoImpl->SetLongitude(doubleValue);
1506                 coordinates.SetLongitude(doubleValue);
1507         }
1508         SysSecureLog(NID_CNT, "INFO: longitude[%f]", pContentInfoImpl->GetLongitude());
1509
1510         val = media_info_get_altitude(pMediaInfo, &doubleValue);
1511         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1512                         "media_info_get_altitude failed[%d].", val);
1513
1514         if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1515         {
1516                 pContentInfoImpl->SetAltitude(doubleValue);
1517                 coordinates.SetAltitude(doubleValue);
1518         }
1519         SysLog(NID_CNT, "INFO: altitude[%f]", pContentInfoImpl->GetAltitude());
1520
1521         pContentInfoImpl->SetCoordinates(coordinates);
1522
1523         // contentType and metadata
1524         if (systemType == SYSTEM_TYPE_IMAGE)
1525         {
1526                 r = MakeImageContentInfo(pMediaInfo, pInfoImpl);
1527                 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform MakeImageContentInfo operation.");
1528         }
1529         else if (systemType == SYSTEM_TYPE_SOUND || systemType == SYSTEM_TYPE_MUSIC)
1530         {
1531                 r = MakeAudioContentInfo(pMediaInfo, pInfoImpl);
1532                 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform MakeAudioContentInfo operation.");
1533         }
1534         else if (systemType == MEDIA_CONTENT_TYPE_VIDEO)
1535         {
1536                 r = MakeVideoContentInfo(pMediaInfo, pInfoImpl);
1537                 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform MakeVideoContentInfo operation.");
1538         }
1539         else if (systemType == SYSTEM_TYPE_OTHER)
1540         {
1541                 pContentInfoImpl->SetContentType(CONTENT_TYPE_OTHER);
1542                 SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1543         }
1544
1545         return r;
1546 }
1547
1548 result
1549 _ContentManagerImpl::MakeImageContentInfo(const media_info_h pMediaInfo, void* pInfoImpl) const
1550 {
1551         result r = E_SUCCESS;
1552         int intValue = 0;
1553         bool boolValue = false;
1554         image_meta_h pTempMeta = null;
1555         unique_ptr<image_meta_h, _ImageMetaDeleter> pImageMeta(null);
1556
1557         SysTryReturnResult(NID_CNT, pInfoImpl != null, E_OUT_OF_MEMORY, "pInfoImpl is null.");
1558
1559         _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1560         SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ContentInfoImpl.");
1561
1562         pContentInfoImpl->SetContentType(CONTENT_TYPE_IMAGE);
1563         SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1564
1565         int val = media_info_get_image(pMediaInfo, &pTempMeta);
1566         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1567                         "media_info_get_image failed[%d].", val);
1568
1569         pImageMeta.reset(&pTempMeta);
1570
1571         _ImageContentInfoImpl* pImageContentInfoImpl = static_cast< _ImageContentInfoImpl* >(pInfoImpl);
1572         SysTryReturnResult(NID_CNT, pImageContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ImageContentInfoImpl.");
1573
1574         // width
1575         val = image_meta_get_width(*(pImageMeta.get()), &intValue);
1576         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1577                         "image_meta_get_width failed[%d].", val);
1578
1579         pImageContentInfoImpl->SetWidth(intValue);
1580         SysLog(NID_CNT, "META: width[%d]", intValue);
1581
1582         // height
1583         val = image_meta_get_height(*(pImageMeta.get()), &intValue);
1584         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1585                         "image_meta_get_height failed[%d].", val);
1586
1587         pImageContentInfoImpl->SetHeight(intValue);
1588         SysLog(NID_CNT, "META: height[%d]", intValue);
1589
1590         // orientation
1591         media_content_orientation_e orientation;
1592         val = image_meta_get_orientation(*(pImageMeta.get()), &orientation);
1593         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1594                         "image_meta_get_orientation failed[%d].", val);
1595
1596         pImageContentInfoImpl->SetOrientation(static_cast< ImageOrientationType >(orientation));
1597         SysLog(NID_CNT, "META: orientation[%d]", orientation);
1598
1599         char* pTempValue = null;
1600         unique_ptr<char, CharDeleter> pStrValue(null);
1601
1602         // title
1603         val = media_info_get_display_name(pMediaInfo, &pTempValue);
1604         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1605                         "media_info_get_display_name failed[%d].", val);
1606
1607         if (pTempValue != null)
1608         {
1609                 pStrValue.reset(pTempValue);
1610
1611                 int pos = 0;
1612                 String fileName;
1613                 String strTitle(pStrValue.get());
1614
1615                 result r = strTitle.LastIndexOf(L'.', strTitle.GetLength() - 1, pos);
1616                 if (r == E_SUCCESS)
1617                 {
1618                         r = strTitle.SubString(0, pos, fileName);
1619                         SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The title is invalid.");
1620                 }
1621                 else
1622                 {
1623                         // Without extension
1624                         r = E_SUCCESS;
1625                         fileName = strTitle;
1626                 }
1627
1628                 pImageContentInfoImpl->SetTitle(fileName);
1629
1630                 SysLog(NID_CNT, "META: title[%ls]", fileName.GetPointer());
1631         }
1632
1633         // dateTaken
1634         val = image_meta_get_date_taken(*(pImageMeta.get()), &pTempValue);
1635         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1636                         "image_meta_get_date_taken failed[%d].", val);
1637
1638         DateTime dt;
1639
1640         if (pTempValue != null)
1641         {
1642                 pStrValue.reset(pTempValue);
1643                 String dateTaken(pStrValue.get());
1644                 String newDateTaken(L"");
1645
1646                 // detour the unexpected datetaken format
1647                 String tempDelim(L"+-Z");
1648                 String token;
1649
1650                 StringTokenizer tempStrTok(dateTaken, tempDelim);
1651
1652                 r = tempStrTok.GetNextToken(token);
1653                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1654
1655                 dateTaken = token;
1656
1657                 String delim(L": ");
1658                 String year(L"");
1659
1660                 StringTokenizer strTok(dateTaken, delim);
1661
1662                 r = strTok.SetDelimiters(delim);
1663                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform SetDelimiters operation.");
1664
1665                 r = strTok.GetNextToken(token);
1666                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1667
1668                 year = token;
1669
1670                 // Append month
1671                 r = strTok.GetNextToken(token);
1672                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1673
1674                 r = newDateTaken.Append(token);
1675                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1676
1677                 r = newDateTaken.Append(L"/");
1678                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1679
1680                 // Append day
1681                 r = strTok.GetNextToken(token);
1682                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1683
1684                 r = newDateTaken.Append(token);
1685                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1686
1687                 r = newDateTaken.Append(L"/");
1688                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1689
1690                 // Append year
1691                 r = newDateTaken.Append(year);
1692                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1693
1694                 r = newDateTaken.Append(L" ");
1695                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1696
1697                 String newDelim(L" ");
1698
1699                 r = strTok.SetDelimiters(newDelim);
1700                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform SetDelimiters operation.");
1701
1702                 r = strTok.GetNextToken(token);
1703                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1704
1705                 r = newDateTaken.Append(token);
1706                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1707
1708                 r = DateTime::Parse(newDateTaken, dt);
1709                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform Parse operation for DateTime.");
1710         }
1711         else
1712         {
1713                 dt = DateTime::GetMinValue();
1714         }
1715
1716         pImageContentInfoImpl->SetImageTakenDate(dt);
1717         SysLog(NID_CNT, "META: dateTaken[%ls]", dt.ToString().GetPointer());
1718
1719         // isBurstShot
1720         val = image_meta_is_burst_shot(*(pImageMeta.get()), &boolValue);
1721         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1722                         "image_meta_is_burst_shot failed[%d].", val);
1723
1724         pImageContentInfoImpl->SetBurstShot(boolValue);
1725         SysLog(NID_CNT, "META: isBurstShot[%d]", boolValue);
1726
1727         // burstShotId
1728         val = image_meta_get_burst_id(*(pImageMeta.get()), &pTempValue);
1729         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1730                         "image_meta_get_burst_id failed[%d].", val);
1731
1732         if (pTempValue != null)
1733         {
1734                 pStrValue.reset(pTempValue);
1735                 String burstShotId(pStrValue.get());
1736
1737                 pImageContentInfoImpl->SetBurstShotId(burstShotId);
1738                 SysLog(NID_CNT, "META: burstShotId[%ls]", burstShotId.GetPointer());
1739         }
1740
1741         return E_SUCCESS;
1742 }
1743
1744 result
1745 _ContentManagerImpl::MakeAudioContentInfo(const media_info_h pMediaInfo, void* pInfoImpl) const
1746 {
1747         int intValue = 0;
1748         audio_meta_h pTempMeta = null;
1749         unique_ptr<audio_meta_h, _AudioMetaDeleter> pAudioMeta(null);
1750
1751         SysTryReturnResult(NID_CNT, pInfoImpl != null, E_OUT_OF_MEMORY, "pInfoImpl is null.");
1752
1753         _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1754         SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ContentInfoImpl.");
1755
1756         pContentInfoImpl->SetContentType(CONTENT_TYPE_AUDIO);
1757         SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1758
1759         int val = media_info_get_audio(pMediaInfo, &pTempMeta);
1760         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1761                         "media_info_get_audio failed[%d].", val);
1762
1763         pAudioMeta.reset(&pTempMeta);
1764
1765         _AudioContentInfoImpl* pAudioContentInfoImpl = static_cast< _AudioContentInfoImpl* >(pInfoImpl);
1766         SysTryReturnResult(NID_CNT, pAudioContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _AudioContentInfoImpl.");
1767
1768         // bitrate
1769         val = audio_meta_get_bit_rate(*(pAudioMeta.get()), &intValue);
1770         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1771                         "audio_meta_get_bit_rate failed[%d].", val);
1772
1773         pAudioContentInfoImpl->SetBitrate(intValue);
1774         SysLog(NID_CNT, "META: bitrate[%d]", intValue);
1775
1776         char* pTempValue = null;
1777         unique_ptr<char, CharDeleter> pStrValue(null);
1778
1779         // releaseYear
1780         val = audio_meta_get_year(*(pAudioMeta.get()), &pTempValue);
1781         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1782                         "audio_meta_get_year failed[%d].", val);
1783
1784         if (pTempValue != null)
1785         {
1786                 pStrValue.reset(pTempValue);
1787
1788                 String strYear(pStrValue.get());
1789
1790                 if (strYear.CompareTo(L"Unknown") != 0)
1791                 {
1792                         result r = Integer::Parse(strYear, intValue);
1793                         if (IsFailed(r))
1794                         {
1795                                 // It is one of the metadata. If error occurs, skip it for other metadata.
1796                                 intValue = 0;
1797                                 r = E_SUCCESS;
1798                                 SysLog(NID_CNT, "META: releaseYear - invalid data[%ls]", strYear.GetPointer());
1799                         }
1800
1801                         pAudioContentInfoImpl->SetReleaseYear(intValue);
1802                         SysLog(NID_CNT, "META: releaseYear[%d]", intValue);
1803                 }
1804         }
1805
1806         // title
1807         val = audio_meta_get_title(*(pAudioMeta.get()), &pTempValue);
1808         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1809                         "audio_meta_get_title failed[%d].", val);
1810
1811         if (pTempValue != null)
1812         {
1813                 pStrValue.reset(pTempValue);
1814
1815                 pAudioContentInfoImpl->SetTitle(String(pStrValue.get()));
1816
1817                 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
1818         }
1819
1820         // albumName
1821         val = audio_meta_get_album(*(pAudioMeta.get()), &pTempValue);
1822         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1823                         "audio_meta_get_album failed[%d].", val);
1824
1825         if (pTempValue != null)
1826         {
1827                 pStrValue.reset(pTempValue);
1828
1829                 pAudioContentInfoImpl->SetAlbumName(String(pStrValue.get()));
1830
1831                 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
1832         }
1833
1834         // artist
1835         val = audio_meta_get_artist(*(pAudioMeta.get()), &pTempValue);
1836         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1837                         "audio_meta_get_artist failed[%d].", val);
1838
1839         if (pTempValue != null)
1840         {
1841                 pStrValue.reset(pTempValue);
1842
1843                 pAudioContentInfoImpl->SetArtist(String(pStrValue.get()));
1844
1845                 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
1846         }
1847
1848         // composer
1849         val = audio_meta_get_composer(*(pAudioMeta.get()), &pTempValue);
1850         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1851                         "audio_meta_get_composer failed[%d].", val);
1852
1853         if (pTempValue != null)
1854         {
1855                 pStrValue.reset(pTempValue);
1856
1857                 pAudioContentInfoImpl->SetComposer(String(pStrValue.get()));
1858
1859                 SysLog(NID_CNT, "META: composer[%ls]", (String(pStrValue.get())).GetPointer());
1860         }
1861
1862         // genre
1863         val = audio_meta_get_genre(*(pAudioMeta.get()), &pTempValue);
1864         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1865                         "audio_meta_get_genre failed[%d].", val);
1866
1867         if (pTempValue != null)
1868         {
1869                 pStrValue.reset(pTempValue);
1870
1871                 pAudioContentInfoImpl->SetGenre(String(pStrValue.get()));
1872
1873                 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
1874         }
1875
1876         // copyright
1877         val = audio_meta_get_copyright(*(pAudioMeta.get()), &pTempValue);
1878         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1879                         "audio_meta_get_copyright failed[%d].", val);
1880
1881         if (pTempValue != null)
1882         {
1883                 pStrValue.reset(pTempValue);
1884
1885                 pAudioContentInfoImpl->SetCopyright(String(pStrValue.get()));
1886
1887                 SysLog(NID_CNT, "META: copyright[%ls]", (String(pStrValue.get())).GetPointer());
1888         }
1889
1890         // trackInfo
1891         val = audio_meta_get_track_num(*(pAudioMeta.get()), &pTempValue);
1892         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1893                         "audio_meta_get_track_num failed[%d].", val);
1894
1895         if (pTempValue != null)
1896         {
1897                 pStrValue.reset(pTempValue);
1898
1899                 pAudioContentInfoImpl->SetTrackInfo(String(pStrValue.get()));
1900
1901                 SysLog(NID_CNT, "META: trackInfo[%ls]", (String(pStrValue.get())).GetPointer());
1902         }
1903
1904         // duration
1905         val = audio_meta_get_duration(*(pAudioMeta.get()), &intValue);
1906         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1907                         "audio_meta_get_duration failed[%d].", val);
1908
1909         pAudioContentInfoImpl->SetDuration(intValue);
1910         SysLog(NID_CNT, "META: duration[%d]", intValue);
1911
1912         return E_SUCCESS;
1913 }
1914
1915 result
1916 _ContentManagerImpl::MakeVideoContentInfo(const media_info_h pMediaInfo, void* pInfoImpl) const
1917 {
1918         int intValue = 0;
1919         video_meta_h pTempMeta = null;
1920         unique_ptr<video_meta_h, _VideoMetaDeleter> pVideoMeta(null);
1921
1922         SysTryReturnResult(NID_CNT, pInfoImpl != null, E_OUT_OF_MEMORY, "pInfoImpl is null.");
1923
1924         _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1925         SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ContentInfoImpl.");
1926
1927         pContentInfoImpl->SetContentType(CONTENT_TYPE_VIDEO);
1928         SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1929
1930         int val = media_info_get_video(pMediaInfo, &pTempMeta);
1931         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1932                         "media_info_get_video failed[%d].", val);
1933
1934         pVideoMeta.reset(&pTempMeta);
1935
1936         _VideoContentInfoImpl* pVideoContentInfoImpl = static_cast< _VideoContentInfoImpl* >(pInfoImpl);
1937         SysTryReturnResult(NID_CNT, pVideoContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _VideoContentInfoImpl.");
1938
1939         // width
1940         val = video_meta_get_width(*(pVideoMeta.get()), &intValue);
1941         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1942                         "video_meta_get_width failed[%d].", val);
1943
1944         pVideoContentInfoImpl->SetWidth(intValue);
1945         SysLog(NID_CNT, "META: width[%d]", intValue);
1946
1947         // height
1948         val = video_meta_get_height(*(pVideoMeta.get()), &intValue);
1949         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1950                         "video_meta_get_height failed[%d].", val);
1951
1952         pVideoContentInfoImpl->SetHeight(intValue);
1953         SysLog(NID_CNT, "META: height[%d]", intValue);
1954
1955         char* pTempValue = null;
1956         unique_ptr<char, CharDeleter> pStrValue(null);
1957
1958         // artist
1959         val = video_meta_get_artist(*(pVideoMeta.get()), &pTempValue);
1960         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1961                         "video_meta_get_artist failed[%d].", val);
1962
1963         if (pTempValue != null)
1964         {
1965                 pStrValue.reset(pTempValue);
1966
1967                 pVideoContentInfoImpl->SetArtist(String(pStrValue.get()));
1968
1969                 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
1970         }
1971
1972         // genre
1973         val = video_meta_get_genre(*(pVideoMeta.get()), &pTempValue);
1974         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1975                         "video_meta_get_genre failed[%d].", val);
1976
1977         if (pTempValue != null)
1978         {
1979                 pStrValue.reset(pTempValue);
1980
1981                 pVideoContentInfoImpl->SetGenre(String(pStrValue.get()));
1982
1983                 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
1984         }
1985
1986         // title
1987         val = video_meta_get_title(*(pVideoMeta.get()), &pTempValue);
1988         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1989                         "video_meta_get_title failed[%d].", val);
1990
1991         if (pTempValue != null)
1992         {
1993                 pStrValue.reset(pTempValue);
1994
1995                 pVideoContentInfoImpl->SetTitle(String(pStrValue.get()));
1996
1997                 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
1998         }
1999
2000         // albumName
2001         val = video_meta_get_album(*(pVideoMeta.get()), &pTempValue);
2002         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
2003                         "video_meta_get_album failed[%d].", val);
2004
2005         if (pTempValue != null)
2006         {
2007                 pStrValue.reset(pTempValue);
2008
2009                 pVideoContentInfoImpl->SetAlbumName(String(pStrValue.get()));
2010
2011                 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
2012         }
2013
2014         // duration
2015         val = video_meta_get_duration(*(pVideoMeta.get()), &intValue);
2016         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
2017                         "video_meta_get_duration failed[%d].", val);
2018
2019         pVideoContentInfoImpl->SetDuration(intValue);
2020         SysLog(NID_CNT, "META: duration[%d]", intValue);
2021
2022         // Get from metadata extractor (framerate, audio bitrate, video bitrate)
2023         VideoMetadata* pVideoMetadata = ContentManagerUtil::GetVideoMetaN(pVideoContentInfoImpl->GetContentPath());
2024         result r = GetLastResult();
2025         SysTryReturnResult(NID_CNT, pVideoMetadata != null, r, "GetVideoMetadata() failed.");
2026
2027         pVideoContentInfoImpl->SetFramerate(pVideoMetadata->GetFramerate());
2028         pVideoContentInfoImpl->SetAudioBitrate(pVideoMetadata->GetAudioBitrate());
2029         pVideoContentInfoImpl->SetVideoBitrate(pVideoMetadata->GetVideoBitrate());
2030
2031         return E_SUCCESS;
2032 }
2033
2034 bool
2035 _ContentManagerImpl::VerifyHomeFilePathCompatibility(const String& contentPath) const
2036 {
2037         if (!_AppInfo::IsOspCompat())
2038         {
2039                 if (contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0))
2040                 {
2041                         SysLogException(NID_CNT, E_INVALID_ARG,
2042                                         "[E_INVALID_ARG] /Home/ or /HomeExt/ is not supported from Tizen 2.0.");
2043                         return false;
2044                 }
2045                 if (!(contentPath.StartsWith(App::App::GetInstance()->GetAppRootPath(), 0) ||
2046                                 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
2047                 {
2048                         SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] The path is not supported.");
2049                         return false;
2050                 }
2051         }
2052         else
2053         {
2054                 SysTryReturn(NID_CNT, contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0),
2055                                 false, E_INVALID_ARG, "[E_INVALID_ARG] The path should start with /Home or /HomeExt.");
2056         }
2057
2058         return true;
2059 }
2060
2061 bool
2062 _ContentManagerImpl::VerifyMediaFilePathCompatibility(const String& contentPath) const
2063 {
2064         ClearLastResult();
2065
2066         if (!_AppInfo::IsOspCompat())
2067         {
2068                 if (!(contentPath.StartsWith(Environment::GetMediaPath(), 0) ||
2069                                 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
2070                 {
2071                         SysLogException(NID_CNT, E_INVALID_ARG, "[%s] This path is not supported.", GetErrorMessage(E_INVALID_ARG));
2072                         return false;
2073                 }
2074         }
2075         else
2076         {
2077                 // prior to 2.0
2078                 if (!(contentPath.StartsWith(OSP_MEDIA_PHONE, 0)) ||
2079                                 (contentPath.StartsWith(OSP_MEDIA_MMC, 0)))
2080                 {
2081                         SysLogException(NID_CNT, E_INVALID_ARG, "[%s] The path should start with /Media, or /Storagecard/Media.", GetErrorMessage(E_INVALID_ARG));
2082                         return false;
2083                 }
2084         }
2085
2086         return true;
2087 }
2088
2089 result
2090 _ContentManagerImpl::ChangeTizenPathToCompat(const String& contentPath, String& changedPath) const
2091 {
2092         result r = E_SUCCESS;
2093         changedPath = contentPath;
2094
2095         // If the api version is 2.0, the content path has to be changed.
2096         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
2097         {
2098                 r = _FileImpl::ConvertPhysicalToVirtualPath(contentPath, changedPath);
2099                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG,
2100                                 "[%s] Failed to convert physical path to virtual path.", GetErrorMessage(E_INVALID_ARG));
2101         }
2102
2103         return r;
2104 }
2105
2106 result
2107 _ContentManagerImpl::ChangeCompatPathToTizen(const String& contentPath, String& changedPath) const
2108 {
2109         result r = E_SUCCESS;
2110         changedPath = contentPath;
2111
2112         // If the api version is 2.0, the content path has to be changed.
2113         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
2114         {
2115                 r = _FileImpl::ConvertVirtualToPhysicalPath(contentPath, changedPath);
2116                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG,
2117                                 "[%s] Failed to convert virtual path to physical path.", GetErrorMessage(E_INVALID_ARG));
2118         }
2119
2120         return r;
2121 }
2122
2123 void
2124 _ContentManagerImpl::SetListener(IContentUpdateEventListener* pListener)
2125 {
2126         __pListener = pListener;
2127 }
2128
2129 IContentUpdateEventListener*
2130 _ContentManagerImpl::GetListener(void) const
2131 {
2132         return __pListener;
2133 }
2134
2135 result
2136 _ContentManagerImpl::ConvertErrorToResult(result res) const
2137 {
2138         result r = E_SUCCESS;
2139
2140         switch (res)
2141         {
2142         case E_IO:
2143                 r = E_SYSTEM;
2144                 break;
2145
2146         default:
2147                 r = res;
2148                 break;
2149         }
2150         return r;
2151 }
2152
2153 }}