[content] Fix compat TC fails
[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         if (!pContentInfoImpl->GetAuthor().IsEmpty())
971         {
972                 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetAuthor()));
973                 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
974
975                 val = media_info_set_author(pMediaInfo.get(), pValue.get());
976                 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
977                                 "media_info_set_author failed[%d].", val);
978         }
979         if (!pContentInfoImpl->GetCategory().IsEmpty())
980         {
981                 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetCategory()));
982                 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
983
984                 val = media_info_set_category(pMediaInfo.get(), pValue.get());
985                 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
986                                 "media_info_set_category failed[%d].", val);
987         }
988         if (!pContentInfoImpl->GetContentName().IsEmpty())
989         {
990                 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetContentName()));
991                 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
992
993                 val = media_info_set_content_name(pMediaInfo.get(), pValue.get());
994                 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
995                                 "media_info_set_content_name failed[%d].", val);
996         }
997         if (!pContentInfoImpl->GetDescription().IsEmpty())
998         {
999                 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetDescription()));
1000                 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1001
1002                 val = media_info_set_description(pMediaInfo.get(), pValue.get());
1003                 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1004                                 "media_info_set_description failed[%d].", val);
1005         }
1006         if (!pContentInfoImpl->GetKeyword().IsEmpty())
1007         {
1008                 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetKeyword()));
1009                 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1010
1011                 val = media_info_set_keyword(pMediaInfo.get(), pValue.get());
1012                 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1013                                 "media_info_set_keyword failed[%d].", val);
1014         }
1015         if (!pContentInfoImpl->GetLocationTag().IsEmpty())
1016         {
1017                 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetLocationTag()));
1018                 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1019
1020                 val = media_info_set_location_tag(pMediaInfo.get(), pValue.get());
1021                 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1022                                 "media_info_set_location_tag failed[%d].", val);
1023         }
1024         if (!pContentInfoImpl->GetProvider().IsEmpty())
1025         {
1026                 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetProvider()));
1027                 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1028
1029                 val = media_info_set_provider(pMediaInfo.get(), pValue.get());
1030                 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1031                                 "media_info_set_provider failed[%d].", val);
1032         }
1033         if (!pContentInfoImpl->GetRating().IsEmpty())
1034         {
1035                 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetRating()));
1036                 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1037
1038                 val = media_info_set_age_rating(pMediaInfo.get(), pValue.get());
1039                 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1040                                 "media_info_set_age_rating failed[%d].", val);
1041         }
1042         if (Double::Compare(pContentInfoImpl->GetLatitude(), DEFAULT_COORDINATE) != 0 &&
1043                         Double::Compare(pContentInfoImpl->GetLongitude(), DEFAULT_COORDINATE) != 0)
1044         {
1045                 val = media_info_set_latitude(pMediaInfo.get(), pContentInfoImpl->GetLatitude());
1046                 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1047                                 "media_info_set_latitude failed[%d].", val);
1048
1049                 val = media_info_set_longitude(pMediaInfo.get(), pContentInfoImpl->GetLongitude());
1050                 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1051                                 "media_info_set_longitude failed[%d].", val);
1052
1053                 if (Double::Compare(pContentInfoImpl->GetAltitude(), DEFAULT_COORDINATE) != 0)
1054                 {
1055                         val = media_info_set_altitude(pMediaInfo.get(), pContentInfoImpl->GetAltitude());
1056                         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1057                                         "media_info_set_altitude failed[%d].", val);
1058                 }
1059         }
1060
1061         val = media_info_update_to_db(pMediaInfo.get());
1062         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1063                         "media_info_update_to_db failed[%d].", val);
1064
1065         return r;
1066 }
1067
1068 ContentId
1069 _ContentManagerImpl::SaveDataToDatabase(const media_info_h pMediaInfo,
1070                                                                                                 _ContentInfoImpl* pContentInfoImpl) const
1071 {
1072         ClearLastResult();
1073         result r = E_SUCCESS;
1074
1075         SysTryReturn(NID_CNT, pContentInfoImpl != null, UuId::GetInvalidUuId(), E_INVALID_ARG,
1076                         "[E_INVALID_ARG] Invalid argument is used. ContentInfo is invalid.");
1077
1078         String contentPath(pContentInfoImpl->GetPhysicalContentPath());
1079         String changedPath(L"");
1080
1081         r = ChangeTizenPathToCompat(contentPath, changedPath);
1082         SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r,
1083                         "[%s] Failed to perform ChangeTizenPathToCompat.", GetErrorMessage(r));
1084
1085         String mimeType(L"");
1086         String extension = _FileImpl::GetFileExtension(changedPath);
1087         r = GetLastResult();
1088         if (IsFailed(r))
1089         {
1090                 ClearLastResult();
1091
1092                 SysLog(NID_CNT, "[%s] Failed to perform GetFileExtension operation.", GetErrorMessage(r));
1093
1094                 unique_ptr<char[]> pTempPath(_StringConverter::CopyToCharArrayN(contentPath));
1095                 SysTryReturn(NID_CNT, pTempPath != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1096                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1097
1098                 char tempType[255] = {0, };
1099                 int ret = aul_get_mime_from_file(pTempPath.get(), tempType, sizeof(tempType));
1100                 SysTryReturn(NID_CNT, ret == AUL_R_OK, UuId::GetInvalidUuId(), E_INVALID_ARG,
1101                                 "[E_INVALID_ARG] Failed to perform aul_get_mime_from_file operation.");
1102
1103                 r = mimeType.Append(tempType);
1104                 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1105                                 "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
1106
1107         }
1108
1109         // If the content format is JPG and it has GPS data, it will be saved in database automatically.
1110         if (extension == L"jpg" || extension == L"jpeg" || extension == L"JPG" || extension == L"JPEG" || mimeType.Contains(L"jpeg"))
1111         {
1112                 SysLog(NID_CNT, "The format of content is jpg.");
1113
1114                 ImageMetadata* pImageMetadata = _ContentManagerUtilImpl::GetImageMetaN(changedPath, true);
1115                 if (pImageMetadata != null)
1116                 {
1117                         pContentInfoImpl->SetLatitude(pImageMetadata->GetLatitude());
1118                         pContentInfoImpl->SetLongitude(pImageMetadata->GetLongitude());
1119
1120                         delete pImageMetadata;
1121                 }
1122
1123                 ClearLastResult();
1124         }
1125
1126         int val = 0;
1127         unique_ptr<char[]> pStr(null);
1128
1129         if (pContentInfoImpl->GetAuthor() != null)
1130         {
1131                 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetAuthor()));
1132                 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1133                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1134
1135                 val = media_info_set_author(pMediaInfo, pStr.get());
1136                 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1137                                 "media_info_set_author failed[%d].", val);
1138         }
1139         if (pContentInfoImpl->GetCategory() != null)
1140         {
1141                 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetCategory()));
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_category(pMediaInfo, pStr.get());
1146                 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1147                                 "media_info_set_category failed[%d].", val);
1148         }
1149         if (pContentInfoImpl->GetContentName() != null)
1150         {
1151                 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetContentName()));
1152                 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1153                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1154
1155                 val = media_info_set_content_name(pMediaInfo, pStr.get());
1156                 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1157                                 "media_info_set_content_name failed[%d].", val);
1158         }
1159         if (pContentInfoImpl->GetDescription() != null)
1160         {
1161                 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetDescription()));
1162                 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1163                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1164
1165                 val = media_info_set_description(pMediaInfo, pStr.get());
1166                 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1167                                 "media_info_set_description failed[%d].", val);
1168         }
1169         if (pContentInfoImpl->GetKeyword() != null)
1170         {
1171                 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetKeyword()));
1172                 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1173                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1174
1175                 val = media_info_set_keyword(pMediaInfo, pStr.get());
1176                 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1177                                 "media_info_set_keyword failed[%d].", val);
1178         }
1179         if (pContentInfoImpl->GetLocationTag() != null)
1180         {
1181                 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetLocationTag()));
1182                 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1183                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1184
1185                 val = media_info_set_location_tag(pMediaInfo, pStr.get());
1186                 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1187                                 "media_info_set_location_tag failed[%d].", val);
1188         }
1189         if (pContentInfoImpl->GetProvider() != null)
1190         {
1191                 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetProvider()));
1192                 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1193                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1194
1195                 val = media_info_set_provider(pMediaInfo, pStr.get());
1196                 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1197                                 "media_info_set_provider failed[%d].", val);
1198         }
1199         if (pContentInfoImpl->GetRating() != null)
1200         {
1201                 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetRating()));
1202                 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1203                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1204
1205                 val = media_info_set_age_rating(pMediaInfo, pStr.get());
1206                 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1207                                 "media_info_set_age_rating failed[%d].", val);
1208         }
1209         if (Double::Compare(pContentInfoImpl->GetLatitude(), DEFAULT_COORDINATE) != 0 &&
1210                         Double::Compare(pContentInfoImpl->GetLongitude(), DEFAULT_COORDINATE) != 0)
1211         {
1212                 val = media_info_set_latitude(pMediaInfo, pContentInfoImpl->GetLatitude());
1213                 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1214                                 "media_info_set_latitude failed[%d].", val);
1215
1216                 val = media_info_set_longitude(pMediaInfo, pContentInfoImpl->GetLongitude());
1217                 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1218                                 "media_info_set_longitude failed[%d].", val);
1219
1220                 if (Double::Compare(pContentInfoImpl->GetAltitude(), DEFAULT_COORDINATE) != 0)
1221                 {
1222                         val = media_info_set_altitude(pMediaInfo, pContentInfoImpl->GetAltitude());
1223                         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1224                                         "media_info_set_altitude failed[%d].", val);
1225                 }
1226         }
1227
1228         val = media_info_update_to_db(pMediaInfo);
1229         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1230                         "media_info_update_to_db failed[%d].", val);
1231
1232         char* pTempMediaId = null;
1233         unique_ptr<char, CharDeleter> pMediaId(null);
1234
1235         val = media_info_get_media_id(pMediaInfo, &pTempMediaId);
1236         if (pTempMediaId != null)
1237         {
1238                 pMediaId.reset(pTempMediaId);
1239         }
1240         else
1241         {
1242                 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1243                                 "media_info_get_media_id failed[%d].", val);
1244         }
1245
1246         String tempContentId(pMediaId.get());
1247         ContentId contentId;
1248
1249         r = UuId::Parse(tempContentId, contentId);
1250         SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_INVALID_ARG,
1251                         "[E_INVALID_ARG] UuId::Parse failed.");
1252
1253         return contentId;
1254 }
1255
1256 result
1257 _ContentManagerImpl::MakeContentInfo(const media_info_h pMediaInfo, int systemType, void* pInfoImpl) const
1258 {
1259         SysTryReturnResult(NID_CNT, pMediaInfo != null && pInfoImpl != null, E_INVALID_ARG,
1260                         "The specified parameter is invalid.");
1261
1262         _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1263
1264         result r = E_SUCCESS;
1265         char* pTempValue = null;
1266         unique_ptr<char, CharDeleter> pStrValue(null);
1267
1268         // contentId
1269         int val = media_info_get_media_id(pMediaInfo, &pTempValue);
1270         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1271                         "media_info_get_media_id failed[%d].", val);
1272
1273         if (pTempValue != null)
1274         {
1275                 pStrValue.reset(pTempValue);
1276
1277                 String strContentId(pStrValue.get());
1278                 ContentId contentId;
1279
1280                 r = UuId::Parse(strContentId, contentId);
1281                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The content id can not be parsed.");
1282
1283                 pContentInfoImpl->SetContentId(contentId);
1284
1285                 SysLog(NID_CNT, "INFO: contentId[%ls]", strContentId.GetPointer());
1286         }
1287
1288         // contentPath
1289         val = media_info_get_file_path(pMediaInfo, &pTempValue);
1290         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1291                         "media_info_get_file_path failed[%d].", val);
1292
1293         if (pTempValue != null)
1294         {
1295                 pStrValue.reset(pTempValue);
1296
1297                 String strFilePath(pStrValue.get());
1298
1299                 pContentInfoImpl->SetContentPath(strFilePath);
1300                 SysSecureLog(NID_CNT, "INFO: contentPath[%ls]", (pContentInfoImpl->GetContentPath()).GetPointer());
1301         }
1302
1303         // mimeType
1304         val = media_info_get_mime_type(pMediaInfo, &pTempValue);
1305         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1306                         "media_info_get_mime_type failed[%d].", val);
1307
1308         if (pTempValue != null)
1309         {
1310                 pStrValue.reset(pTempValue);
1311
1312                 pContentInfoImpl->SetMimeType(pStrValue.get());
1313
1314                 SysLog(NID_CNT, "INFO: mimeType[%ls]", (pContentInfoImpl->GetMimeType()).GetPointer());
1315         }
1316
1317         // contentSize
1318         unsigned long long longlongValue = 0;
1319         val = media_info_get_size(pMediaInfo, &longlongValue);
1320         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1321                         "media_info_get_size failed[%d].", val);
1322         pContentInfoImpl->SetContentSize(longlongValue);
1323         SysLog(NID_CNT, "INFO: contentSize[%llu]", longlongValue);
1324
1325         // storageType
1326         media_content_storage_e storageType;
1327         val = media_info_get_storage_type(pMediaInfo, &storageType);
1328         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1329                         "media_info_get_storage_type failed[%d].", val);
1330         pContentInfoImpl->SetStorageType(storageType);
1331         SysLog(NID_CNT, "INFO: storageType[%d]", storageType);
1332
1333         // isDrm
1334         bool tempDrm = false;
1335
1336         val = media_info_is_drm(pMediaInfo, &tempDrm);
1337         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1338                         "media_info_is_drm failed[%d].", val);
1339
1340         pContentInfoImpl->SetDrmProtected(tempDrm);
1341
1342         SysLog(NID_CNT, "INFO: isDrm[%d]", pContentInfoImpl->IsDrmProtected());
1343
1344         // dateTime
1345         time_t addedTime = 0;
1346         val = media_info_get_added_time(pMediaInfo, &addedTime);
1347         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1348                         "media_info_get_added_time failed[%d].", val);
1349
1350         DateTime dt;
1351         r = dt.SetValue(1970, 1, 1);
1352         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.SetValue operation.");
1353         r = dt.AddSeconds(addedTime);// need to check addedTime is secs/millisec
1354         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.AddSeconds operation.");
1355
1356         pContentInfoImpl->SetDateTime(dt);
1357         SysLog(NID_CNT, "INFO: dateTime[%ls]", ((pContentInfoImpl->GetDateTime()).ToString()).GetPointer());
1358
1359         // modifiedTime
1360         time_t modifiedTime = 0;
1361         val = media_info_get_modified_time(pMediaInfo, &modifiedTime);
1362         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1363                         "media_info_get_modified_time failed[%d].", val);
1364
1365         r = dt.SetValue(1970, 1, 1);
1366         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.SetValue operation.");
1367         r = dt.AddSeconds(modifiedTime);
1368         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.AddSeconds operation.");
1369
1370         pContentInfoImpl->SetModifiedTime(dt);
1371         SysLog(NID_CNT, "INFO: modifiedTime[%ls]", ((pContentInfoImpl->GetModifiedTime()).ToString()).GetPointer());
1372
1373         // thumbnailPath
1374         val = media_info_get_thumbnail_path(pMediaInfo, &pTempValue);
1375         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1376                         "media_info_get_thumbnail_path failed[%d].", val);
1377
1378         if (pTempValue != null)
1379         {
1380                 pStrValue.reset(pTempValue);
1381                 String thumbnailPath(pStrValue.get());
1382
1383                 pContentInfoImpl->SetThumbnailPath(thumbnailPath);
1384                 SysLog(NID_CNT, "INFO: thumbnailPath[%ls]", (pContentInfoImpl->GetThumbnailPath()).GetPointer());
1385         }
1386
1387         // author
1388         val = media_info_get_author(pMediaInfo, &pTempValue);
1389         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1390                         "media_info_get_author failed[%d].", val);
1391
1392         if (pTempValue != null)
1393         {
1394                 pStrValue.reset(pTempValue);
1395
1396                 pContentInfoImpl->SetAuthor(String(pStrValue.get()));
1397
1398                 SysLog(NID_CNT, "INFO: author[%ls]", (pContentInfoImpl->GetAuthor()).GetPointer());
1399         }
1400
1401         // category
1402         val = media_info_get_category(pMediaInfo, &pTempValue);
1403         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1404                         "media_info_get_category failed[%d].", val);
1405
1406         if (pTempValue != null)
1407         {
1408                 pStrValue.reset(pTempValue);
1409
1410                 pContentInfoImpl->SetCategory(String(pStrValue.get()));
1411
1412                 SysLog(NID_CNT, "INFO: category[%ls]", (pContentInfoImpl->GetCategory()).GetPointer());
1413         }
1414
1415         // contentName
1416         val = media_info_get_content_name(pMediaInfo, &pTempValue);
1417         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1418                         "media_info_get_content_name failed[%d].", val);
1419
1420         if (pTempValue != null)
1421         {
1422                 pStrValue.reset(pTempValue);
1423
1424                 pContentInfoImpl->SetContentName(String(pStrValue.get()));
1425
1426                 SysSecureLog(NID_CNT, "INFO: contentName[%ls]", (pContentInfoImpl->GetContentName()).GetPointer());
1427         }
1428
1429         // description
1430         val = media_info_get_description(pMediaInfo, &pTempValue);
1431         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1432                         "media_info_get_description failed[%d].", val);
1433
1434         if (pTempValue != null)
1435         {
1436                 pStrValue.reset(pTempValue);
1437
1438                 pContentInfoImpl->SetDescription(String(pStrValue.get()));
1439
1440                 SysLog(NID_CNT, "INFO: description[%ls]", (pContentInfoImpl->GetDescription()).GetPointer());
1441         }
1442
1443         // keyword
1444         val = media_info_get_keyword(pMediaInfo, &pTempValue);
1445         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1446                         "media_info_get_keyword failed[%d].", val);
1447
1448         if (pTempValue != null)
1449         {
1450                 pStrValue.reset(pTempValue);
1451
1452                 pContentInfoImpl->SetKeyword(String(pStrValue.get()));
1453
1454                 SysLog(NID_CNT, "INFO: keyword[%ls]", (pContentInfoImpl->GetKeyword()).GetPointer());
1455         }
1456
1457         // locationTag
1458         val = media_info_get_location_tag(pMediaInfo, &pTempValue);
1459         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1460                         "media_info_get_location_tag failed[%d].", val);
1461
1462         if (pTempValue != null)
1463         {
1464                 pStrValue.reset(pTempValue);
1465
1466                 pContentInfoImpl->SetLocationTag(String(pStrValue.get()));
1467
1468                 SysSecureLog(NID_CNT, "INFO: locationTag[%ls]", (pContentInfoImpl->GetLocationTag()).GetPointer());
1469         }
1470
1471         // provider
1472         val = media_info_get_provider(pMediaInfo, &pTempValue);
1473         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1474                         "media_info_get_provider failed[%d].", val);
1475
1476         if (pTempValue != null)
1477         {
1478                 pStrValue.reset(pTempValue);
1479
1480                 pContentInfoImpl->SetProvider(String(pStrValue.get()));
1481
1482                 SysLog(NID_CNT, "INFO: provider[%ls]", (pContentInfoImpl->GetProvider()).GetPointer());
1483         }
1484
1485         // rating
1486         val = media_info_get_age_rating(pMediaInfo, &pTempValue);
1487         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1488                         "media_info_get_age_rating failed[%d].", val);
1489
1490         if (pTempValue != null)
1491         {
1492                 pStrValue.reset(pTempValue);
1493
1494                 pContentInfoImpl->SetRating(String(pStrValue.get()));
1495
1496                 SysLog(NID_CNT, "INFO: rating[%ls]", (pContentInfoImpl->GetRating()).GetPointer());
1497         }
1498
1499         // coordinates
1500         Coordinates coordinates;
1501         double doubleValue = 0;
1502         val = media_info_get_latitude(pMediaInfo, &doubleValue);
1503         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1504                         "media_info_get_latitude failed[%d].", val);
1505
1506         if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1507         {
1508                 pContentInfoImpl->SetLatitude(doubleValue);
1509                 coordinates.SetLatitude(doubleValue);
1510         }
1511         SysSecureLog(NID_CNT, "INFO: latitude[%f]", pContentInfoImpl->GetLatitude());
1512
1513         val = media_info_get_longitude(pMediaInfo, &doubleValue);
1514         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1515                         "media_info_get_longitude failed[%d].", val);
1516
1517         if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1518         {
1519                 pContentInfoImpl->SetLongitude(doubleValue);
1520                 coordinates.SetLongitude(doubleValue);
1521         }
1522         SysSecureLog(NID_CNT, "INFO: longitude[%f]", pContentInfoImpl->GetLongitude());
1523
1524         val = media_info_get_altitude(pMediaInfo, &doubleValue);
1525         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1526                         "media_info_get_altitude failed[%d].", val);
1527
1528         if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1529         {
1530                 pContentInfoImpl->SetAltitude(doubleValue);
1531                 coordinates.SetAltitude(doubleValue);
1532         }
1533         SysLog(NID_CNT, "INFO: altitude[%f]", pContentInfoImpl->GetAltitude());
1534
1535         pContentInfoImpl->SetCoordinates(coordinates);
1536
1537         // contentType and metadata
1538         if (systemType == SYSTEM_TYPE_IMAGE)
1539         {
1540                 r = MakeImageContentInfo(pMediaInfo, pInfoImpl);
1541                 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform MakeImageContentInfo operation.");
1542         }
1543         else if (systemType == SYSTEM_TYPE_SOUND || systemType == SYSTEM_TYPE_MUSIC)
1544         {
1545                 r = MakeAudioContentInfo(pMediaInfo, pInfoImpl);
1546                 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform MakeAudioContentInfo operation.");
1547         }
1548         else if (systemType == MEDIA_CONTENT_TYPE_VIDEO)
1549         {
1550                 r = MakeVideoContentInfo(pMediaInfo, pInfoImpl);
1551                 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform MakeVideoContentInfo operation.");
1552         }
1553         else if (systemType == SYSTEM_TYPE_OTHER)
1554         {
1555                 pContentInfoImpl->SetContentType(CONTENT_TYPE_OTHER);
1556                 SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1557         }
1558
1559         return r;
1560 }
1561
1562 result
1563 _ContentManagerImpl::MakeImageContentInfo(const media_info_h pMediaInfo, void* pInfoImpl) const
1564 {
1565         result r = E_SUCCESS;
1566         int intValue = 0;
1567         bool boolValue = false;
1568         image_meta_h pTempMeta = null;
1569         unique_ptr<image_meta_h, _ImageMetaDeleter> pImageMeta(null);
1570
1571         SysTryReturnResult(NID_CNT, pInfoImpl != null, E_OUT_OF_MEMORY, "pInfoImpl is null.");
1572
1573         _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1574         SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ContentInfoImpl.");
1575
1576         pContentInfoImpl->SetContentType(CONTENT_TYPE_IMAGE);
1577         SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1578
1579         int val = media_info_get_image(pMediaInfo, &pTempMeta);
1580         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1581                         "media_info_get_image failed[%d].", val);
1582
1583         pImageMeta.reset(&pTempMeta);
1584
1585         _ImageContentInfoImpl* pImageContentInfoImpl = static_cast< _ImageContentInfoImpl* >(pInfoImpl);
1586         SysTryReturnResult(NID_CNT, pImageContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ImageContentInfoImpl.");
1587
1588         // width
1589         val = image_meta_get_width(*(pImageMeta.get()), &intValue);
1590         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1591                         "image_meta_get_width failed[%d].", val);
1592
1593         pImageContentInfoImpl->SetWidth(intValue);
1594         SysLog(NID_CNT, "META: width[%d]", intValue);
1595
1596         // height
1597         val = image_meta_get_height(*(pImageMeta.get()), &intValue);
1598         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1599                         "image_meta_get_height failed[%d].", val);
1600
1601         pImageContentInfoImpl->SetHeight(intValue);
1602         SysLog(NID_CNT, "META: height[%d]", intValue);
1603
1604         // orientation
1605         media_content_orientation_e orientation;
1606         val = image_meta_get_orientation(*(pImageMeta.get()), &orientation);
1607         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1608                         "image_meta_get_orientation failed[%d].", val);
1609
1610         pImageContentInfoImpl->SetOrientation(static_cast< ImageOrientationType >(orientation));
1611         SysLog(NID_CNT, "META: orientation[%d]", orientation);
1612
1613         char* pTempValue = null;
1614         unique_ptr<char, CharDeleter> pStrValue(null);
1615
1616         // title
1617         val = media_info_get_display_name(pMediaInfo, &pTempValue);
1618         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1619                         "media_info_get_display_name failed[%d].", val);
1620
1621         if (pTempValue != null)
1622         {
1623                 pStrValue.reset(pTempValue);
1624
1625                 int pos = 0;
1626                 String fileName;
1627                 String strTitle(pStrValue.get());
1628
1629                 result r = strTitle.LastIndexOf(L'.', strTitle.GetLength() - 1, pos);
1630                 if (r == E_SUCCESS)
1631                 {
1632                         r = strTitle.SubString(0, pos, fileName);
1633                         SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The title is invalid.");
1634                 }
1635                 else
1636                 {
1637                         // Without extension
1638                         r = E_SUCCESS;
1639                         fileName = strTitle;
1640                 }
1641
1642                 pImageContentInfoImpl->SetTitle(fileName);
1643
1644                 SysLog(NID_CNT, "META: title[%ls]", fileName.GetPointer());
1645         }
1646
1647         // dateTaken
1648         val = image_meta_get_date_taken(*(pImageMeta.get()), &pTempValue);
1649         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1650                         "image_meta_get_date_taken failed[%d].", val);
1651
1652         DateTime dt;
1653
1654         if (pTempValue != null)
1655         {
1656                 pStrValue.reset(pTempValue);
1657                 String dateTaken(pStrValue.get());
1658                 String newDateTaken(L"");
1659
1660                 // detour the unexpected datetaken format
1661                 String tempDelim(L"+-Z");
1662                 String token;
1663
1664                 StringTokenizer tempStrTok(dateTaken, tempDelim);
1665
1666                 r = tempStrTok.GetNextToken(token);
1667                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1668
1669                 dateTaken = token;
1670
1671                 String delim(L": ");
1672                 String year(L"");
1673
1674                 StringTokenizer strTok(dateTaken, delim);
1675
1676                 r = strTok.SetDelimiters(delim);
1677                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform SetDelimiters operation.");
1678
1679                 r = strTok.GetNextToken(token);
1680                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1681
1682                 year = token;
1683
1684                 // Append month
1685                 r = strTok.GetNextToken(token);
1686                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1687
1688                 r = newDateTaken.Append(token);
1689                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1690
1691                 r = newDateTaken.Append(L"/");
1692                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1693
1694                 // Append day
1695                 r = strTok.GetNextToken(token);
1696                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1697
1698                 r = newDateTaken.Append(token);
1699                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1700
1701                 r = newDateTaken.Append(L"/");
1702                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1703
1704                 // Append year
1705                 r = newDateTaken.Append(year);
1706                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1707
1708                 r = newDateTaken.Append(L" ");
1709                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1710
1711                 String newDelim(L" ");
1712
1713                 r = strTok.SetDelimiters(newDelim);
1714                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform SetDelimiters operation.");
1715
1716                 r = strTok.GetNextToken(token);
1717                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1718
1719                 r = newDateTaken.Append(token);
1720                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1721
1722                 r = DateTime::Parse(newDateTaken, dt);
1723                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform Parse operation for DateTime.");
1724         }
1725         else
1726         {
1727                 dt = DateTime::GetMinValue();
1728         }
1729
1730         pImageContentInfoImpl->SetImageTakenDate(dt);
1731         SysLog(NID_CNT, "META: dateTaken[%ls]", dt.ToString().GetPointer());
1732
1733         // isBurstShot
1734         val = image_meta_is_burst_shot(*(pImageMeta.get()), &boolValue);
1735         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1736                         "image_meta_is_burst_shot failed[%d].", val);
1737
1738         pImageContentInfoImpl->SetBurstShot(boolValue);
1739         SysLog(NID_CNT, "META: isBurstShot[%d]", boolValue);
1740
1741         // burstShotId
1742         val = image_meta_get_burst_id(*(pImageMeta.get()), &pTempValue);
1743         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1744                         "image_meta_get_burst_id failed[%d].", val);
1745
1746         if (pTempValue != null)
1747         {
1748                 pStrValue.reset(pTempValue);
1749                 String burstShotId(pStrValue.get());
1750
1751                 pImageContentInfoImpl->SetBurstShotId(burstShotId);
1752                 SysLog(NID_CNT, "META: burstShotId[%ls]", burstShotId.GetPointer());
1753         }
1754
1755         return E_SUCCESS;
1756 }
1757
1758 result
1759 _ContentManagerImpl::MakeAudioContentInfo(const media_info_h pMediaInfo, void* pInfoImpl) const
1760 {
1761         int intValue = 0;
1762         audio_meta_h pTempMeta = null;
1763         unique_ptr<audio_meta_h, _AudioMetaDeleter> pAudioMeta(null);
1764
1765         SysTryReturnResult(NID_CNT, pInfoImpl != null, E_OUT_OF_MEMORY, "pInfoImpl is null.");
1766
1767         _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1768         SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ContentInfoImpl.");
1769
1770         pContentInfoImpl->SetContentType(CONTENT_TYPE_AUDIO);
1771         SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1772
1773         int val = media_info_get_audio(pMediaInfo, &pTempMeta);
1774         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1775                         "media_info_get_audio failed[%d].", val);
1776
1777         pAudioMeta.reset(&pTempMeta);
1778
1779         _AudioContentInfoImpl* pAudioContentInfoImpl = static_cast< _AudioContentInfoImpl* >(pInfoImpl);
1780         SysTryReturnResult(NID_CNT, pAudioContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _AudioContentInfoImpl.");
1781
1782         // bitrate
1783         val = audio_meta_get_bit_rate(*(pAudioMeta.get()), &intValue);
1784         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1785                         "audio_meta_get_bit_rate failed[%d].", val);
1786
1787         pAudioContentInfoImpl->SetBitrate(intValue);
1788         SysLog(NID_CNT, "META: bitrate[%d]", intValue);
1789
1790         char* pTempValue = null;
1791         unique_ptr<char, CharDeleter> pStrValue(null);
1792
1793         // releaseYear
1794         val = audio_meta_get_year(*(pAudioMeta.get()), &pTempValue);
1795         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1796                         "audio_meta_get_year failed[%d].", val);
1797
1798         if (pTempValue != null)
1799         {
1800                 pStrValue.reset(pTempValue);
1801
1802                 String strYear(pStrValue.get());
1803
1804                 if (strYear.CompareTo(L"Unknown") != 0)
1805                 {
1806                         result r = Integer::Parse(strYear, intValue);
1807                         if (IsFailed(r))
1808                         {
1809                                 // It is one of the metadata. If error occurs, skip it for other metadata.
1810                                 intValue = 0;
1811                                 r = E_SUCCESS;
1812                                 SysLog(NID_CNT, "META: releaseYear - invalid data[%ls]", strYear.GetPointer());
1813                         }
1814
1815                         pAudioContentInfoImpl->SetReleaseYear(intValue);
1816                         SysLog(NID_CNT, "META: releaseYear[%d]", intValue);
1817                 }
1818         }
1819
1820         // title
1821         val = audio_meta_get_title(*(pAudioMeta.get()), &pTempValue);
1822         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1823                         "audio_meta_get_title failed[%d].", val);
1824
1825         if (pTempValue != null)
1826         {
1827                 pStrValue.reset(pTempValue);
1828
1829                 pAudioContentInfoImpl->SetTitle(String(pStrValue.get()));
1830
1831                 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
1832         }
1833
1834         // albumName
1835         val = audio_meta_get_album(*(pAudioMeta.get()), &pTempValue);
1836         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1837                         "audio_meta_get_album failed[%d].", val);
1838
1839         if (pTempValue != null)
1840         {
1841                 pStrValue.reset(pTempValue);
1842
1843                 pAudioContentInfoImpl->SetAlbumName(String(pStrValue.get()));
1844
1845                 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
1846         }
1847
1848         // artist
1849         val = audio_meta_get_artist(*(pAudioMeta.get()), &pTempValue);
1850         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1851                         "audio_meta_get_artist failed[%d].", val);
1852
1853         if (pTempValue != null)
1854         {
1855                 pStrValue.reset(pTempValue);
1856
1857                 pAudioContentInfoImpl->SetArtist(String(pStrValue.get()));
1858
1859                 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
1860         }
1861
1862         // composer
1863         val = audio_meta_get_composer(*(pAudioMeta.get()), &pTempValue);
1864         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1865                         "audio_meta_get_composer failed[%d].", val);
1866
1867         if (pTempValue != null)
1868         {
1869                 pStrValue.reset(pTempValue);
1870
1871                 pAudioContentInfoImpl->SetComposer(String(pStrValue.get()));
1872
1873                 SysLog(NID_CNT, "META: composer[%ls]", (String(pStrValue.get())).GetPointer());
1874         }
1875
1876         // genre
1877         val = audio_meta_get_genre(*(pAudioMeta.get()), &pTempValue);
1878         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1879                         "audio_meta_get_genre failed[%d].", val);
1880
1881         if (pTempValue != null)
1882         {
1883                 pStrValue.reset(pTempValue);
1884
1885                 pAudioContentInfoImpl->SetGenre(String(pStrValue.get()));
1886
1887                 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
1888         }
1889
1890         // copyright
1891         val = audio_meta_get_copyright(*(pAudioMeta.get()), &pTempValue);
1892         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1893                         "audio_meta_get_copyright failed[%d].", val);
1894
1895         if (pTempValue != null)
1896         {
1897                 pStrValue.reset(pTempValue);
1898
1899                 pAudioContentInfoImpl->SetCopyright(String(pStrValue.get()));
1900
1901                 SysLog(NID_CNT, "META: copyright[%ls]", (String(pStrValue.get())).GetPointer());
1902         }
1903
1904         // trackInfo
1905         val = audio_meta_get_track_num(*(pAudioMeta.get()), &pTempValue);
1906         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1907                         "audio_meta_get_track_num failed[%d].", val);
1908
1909         if (pTempValue != null)
1910         {
1911                 pStrValue.reset(pTempValue);
1912
1913                 pAudioContentInfoImpl->SetTrackInfo(String(pStrValue.get()));
1914
1915                 SysLog(NID_CNT, "META: trackInfo[%ls]", (String(pStrValue.get())).GetPointer());
1916         }
1917
1918         // duration
1919         val = audio_meta_get_duration(*(pAudioMeta.get()), &intValue);
1920         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1921                         "audio_meta_get_duration failed[%d].", val);
1922
1923         pAudioContentInfoImpl->SetDuration(intValue);
1924         SysLog(NID_CNT, "META: duration[%d]", intValue);
1925
1926         return E_SUCCESS;
1927 }
1928
1929 result
1930 _ContentManagerImpl::MakeVideoContentInfo(const media_info_h pMediaInfo, void* pInfoImpl) const
1931 {
1932         int intValue = 0;
1933         video_meta_h pTempMeta = null;
1934         unique_ptr<video_meta_h, _VideoMetaDeleter> pVideoMeta(null);
1935
1936         SysTryReturnResult(NID_CNT, pInfoImpl != null, E_OUT_OF_MEMORY, "pInfoImpl is null.");
1937
1938         _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1939         SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ContentInfoImpl.");
1940
1941         pContentInfoImpl->SetContentType(CONTENT_TYPE_VIDEO);
1942         SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1943
1944         int val = media_info_get_video(pMediaInfo, &pTempMeta);
1945         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1946                         "media_info_get_video failed[%d].", val);
1947
1948         pVideoMeta.reset(&pTempMeta);
1949
1950         _VideoContentInfoImpl* pVideoContentInfoImpl = static_cast< _VideoContentInfoImpl* >(pInfoImpl);
1951         SysTryReturnResult(NID_CNT, pVideoContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _VideoContentInfoImpl.");
1952
1953         // width
1954         val = video_meta_get_width(*(pVideoMeta.get()), &intValue);
1955         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1956                         "video_meta_get_width failed[%d].", val);
1957
1958         pVideoContentInfoImpl->SetWidth(intValue);
1959         SysLog(NID_CNT, "META: width[%d]", intValue);
1960
1961         // height
1962         val = video_meta_get_height(*(pVideoMeta.get()), &intValue);
1963         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1964                         "video_meta_get_height failed[%d].", val);
1965
1966         pVideoContentInfoImpl->SetHeight(intValue);
1967         SysLog(NID_CNT, "META: height[%d]", intValue);
1968
1969         char* pTempValue = null;
1970         unique_ptr<char, CharDeleter> pStrValue(null);
1971
1972         // artist
1973         val = video_meta_get_artist(*(pVideoMeta.get()), &pTempValue);
1974         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1975                         "video_meta_get_artist failed[%d].", val);
1976
1977         if (pTempValue != null)
1978         {
1979                 pStrValue.reset(pTempValue);
1980
1981                 pVideoContentInfoImpl->SetArtist(String(pStrValue.get()));
1982
1983                 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
1984         }
1985
1986         // genre
1987         val = video_meta_get_genre(*(pVideoMeta.get()), &pTempValue);
1988         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1989                         "video_meta_get_genre failed[%d].", val);
1990
1991         if (pTempValue != null)
1992         {
1993                 pStrValue.reset(pTempValue);
1994
1995                 pVideoContentInfoImpl->SetGenre(String(pStrValue.get()));
1996
1997                 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
1998         }
1999
2000         // title
2001         val = video_meta_get_title(*(pVideoMeta.get()), &pTempValue);
2002         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
2003                         "video_meta_get_title failed[%d].", val);
2004
2005         if (pTempValue != null)
2006         {
2007                 pStrValue.reset(pTempValue);
2008
2009                 pVideoContentInfoImpl->SetTitle(String(pStrValue.get()));
2010
2011                 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
2012         }
2013
2014         // albumName
2015         val = video_meta_get_album(*(pVideoMeta.get()), &pTempValue);
2016         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
2017                         "video_meta_get_album failed[%d].", val);
2018
2019         if (pTempValue != null)
2020         {
2021                 pStrValue.reset(pTempValue);
2022
2023                 pVideoContentInfoImpl->SetAlbumName(String(pStrValue.get()));
2024
2025                 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
2026         }
2027
2028         // duration
2029         val = video_meta_get_duration(*(pVideoMeta.get()), &intValue);
2030         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
2031                         "video_meta_get_duration failed[%d].", val);
2032
2033         pVideoContentInfoImpl->SetDuration(intValue);
2034         SysLog(NID_CNT, "META: duration[%d]", intValue);
2035
2036         // Get from metadata extractor (framerate, audio bitrate, video bitrate)
2037         VideoMetadata* pVideoMetadata = ContentManagerUtil::GetVideoMetaN(pVideoContentInfoImpl->GetContentPath());
2038         result r = GetLastResult();
2039         SysTryReturnResult(NID_CNT, pVideoMetadata != null, r, "GetVideoMetadata() failed.");
2040
2041         pVideoContentInfoImpl->SetFramerate(pVideoMetadata->GetFramerate());
2042         pVideoContentInfoImpl->SetAudioBitrate(pVideoMetadata->GetAudioBitrate());
2043         pVideoContentInfoImpl->SetVideoBitrate(pVideoMetadata->GetVideoBitrate());
2044
2045         return E_SUCCESS;
2046 }
2047
2048 bool
2049 _ContentManagerImpl::VerifyHomeFilePathCompatibility(const String& contentPath) const
2050 {
2051         if (!_AppInfo::IsOspCompat())
2052         {
2053                 if (contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0))
2054                 {
2055                         SysLogException(NID_CNT, E_INVALID_ARG,
2056                                         "[E_INVALID_ARG] /Home/ or /HomeExt/ is not supported from Tizen 2.0.");
2057                         return false;
2058                 }
2059                 if (!(contentPath.StartsWith(App::App::GetInstance()->GetAppRootPath(), 0) ||
2060                                 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
2061                 {
2062                         SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] The path is not supported.");
2063                         return false;
2064                 }
2065         }
2066         else
2067         {
2068                 SysTryReturn(NID_CNT, contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0),
2069                                 false, E_INVALID_ARG, "[E_INVALID_ARG] The path should start with /Home or /HomeExt.");
2070         }
2071
2072         return true;
2073 }
2074
2075 bool
2076 _ContentManagerImpl::VerifyMediaFilePathCompatibility(const String& contentPath) const
2077 {
2078         ClearLastResult();
2079
2080         if (!_AppInfo::IsOspCompat())
2081         {
2082                 if (!(contentPath.StartsWith(Environment::GetMediaPath(), 0) ||
2083                                 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
2084                 {
2085                         SysLogException(NID_CNT, E_INVALID_ARG, "[%s] This path is not supported.", GetErrorMessage(E_INVALID_ARG));
2086                         return false;
2087                 }
2088         }
2089         else
2090         {
2091                 // prior to 2.0
2092                 if (!(contentPath.StartsWith(OSP_MEDIA_PHONE, 0)) ||
2093                                 (contentPath.StartsWith(OSP_MEDIA_MMC, 0)))
2094                 {
2095                         SysLogException(NID_CNT, E_INVALID_ARG, "[%s] The path should start with /Media, or /Storagecard/Media.", GetErrorMessage(E_INVALID_ARG));
2096                         return false;
2097                 }
2098         }
2099
2100         return true;
2101 }
2102
2103 result
2104 _ContentManagerImpl::ChangeTizenPathToCompat(const String& contentPath, String& changedPath) const
2105 {
2106         result r = E_SUCCESS;
2107         changedPath = contentPath;
2108
2109         // If the api version is 2.0, the content path has to be changed.
2110         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
2111         {
2112                 r = _FileImpl::ConvertPhysicalToVirtualPath(contentPath, changedPath);
2113                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG,
2114                                 "[%s] Failed to convert physical path to virtual path.", GetErrorMessage(E_INVALID_ARG));
2115         }
2116
2117         return r;
2118 }
2119
2120 result
2121 _ContentManagerImpl::ChangeCompatPathToTizen(const String& contentPath, String& changedPath) const
2122 {
2123         result r = E_SUCCESS;
2124         changedPath = contentPath;
2125
2126         // If the api version is 2.0, the content path has to be changed.
2127         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
2128         {
2129                 r = _FileImpl::ConvertVirtualToPhysicalPath(contentPath, changedPath);
2130                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG,
2131                                 "[%s] Failed to convert virtual path to physical path.", GetErrorMessage(E_INVALID_ARG));
2132         }
2133
2134         return r;
2135 }
2136
2137 void
2138 _ContentManagerImpl::SetListener(IContentUpdateEventListener* pListener)
2139 {
2140         __pListener = pListener;
2141 }
2142
2143 IContentUpdateEventListener*
2144 _ContentManagerImpl::GetListener(void) const
2145 {
2146         return __pListener;
2147 }
2148
2149 result
2150 _ContentManagerImpl::ConvertErrorToResult(result res) const
2151 {
2152         result r = E_SUCCESS;
2153
2154         switch (res)
2155         {
2156         case E_IO:
2157                 r = E_SYSTEM;
2158                 break;
2159
2160         default:
2161                 r = res;
2162                 break;
2163         }
2164         return r;
2165 }
2166
2167 }}