2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file FCnt_ContentManagerImpl.cpp
18 * @brief This is the implementation file for the %_ContentManagerImpl class.
20 * This file contains implementation of the %_ContentManagerImpl class.
24 #include <FBaseSysLog.h>
26 #include <FBaseInteger.h>
27 #include <FBaseByteBuffer.h>
28 #include <FCntContentManager.h>
29 #include <FCntImageContentInfo.h>
30 #include <FCntAudioContentInfo.h>
31 #include <FCntVideoContentInfo.h>
32 #include <FCntOtherContentInfo.h>
33 #include <FCntImageMetadata.h>
34 #include <FCntAudioMetadata.h>
35 #include <FCntVideoMetadata.h>
36 #include <FCntIContentScanListener.h>
37 #include <FCntIContentUpdateEventListener.h>
38 #include <FIoDirectory.h>
39 #include <FSysEnvironment.h>
40 #include <FCnt_ContentManagerImpl.h>
41 #include <FCnt_ContentManagerUtilImpl.h>
42 #include <FBase_StringConverter.h>
43 #include <FIo_FileImpl.h>
44 #include <FApp_AppInfo.h>
46 using namespace Tizen::Base;
47 using namespace Tizen::Base::Collection;
48 using namespace Tizen::Io;
49 using namespace Tizen::App;
50 using namespace Tizen::System;
53 namespace Tizen { namespace Content
56 static RequestId requestId = 0;
58 static const int SYSTEM_TYPE_IMAGE = 0;
59 static const int SYSTEM_TYPE_VIDEO = 1;
60 static const int SYSTEM_TYPE_SOUND = 2;
61 static const int SYSTEM_TYPE_MUSIC = 3;
62 static const int SYSTEM_TYPE_OTHER = 4;
63 static const double DEFAULT_COORDINATE = -200.0;
65 // For extern declaration in FCntTypes.h
66 const wchar_t OSP_HOME[] = L"/Home/";
67 const wchar_t OSP_HOME_EXT[] = L"/HomeExt/";
68 const wchar_t OSP_MEDIA_PHONE[] = L"/Media/";
69 const wchar_t OSP_MEDIA_MMC[] = L"/Storagecard/Media/";
72 ConvertError(int error)
78 case MEDIA_CONTENT_ERROR_NONE:
82 case MEDIA_CONTENT_ERROR_INVALID_PARAMETER:
86 case MEDIA_CONTENT_ERROR_OUT_OF_MEMORY:
90 case MEDIA_CONTENT_ERROR_DB_BUSY:
94 case MEDIA_CONTENT_ERROR_DB_FAILED:
107 OnScanCompleted(media_content_error_e error, void* user_data)
109 SysLog(NID_CNT, "OnScanCompleted callback method is called.");
112 result r = E_SUCCESS;
113 String scanPath(L"");
114 IContentScanListener* pListener = null;
116 unique_ptr< ScanResult > pScanResult;
118 SysTryLogCatch(NID_CNT, user_data != null, , "OnScanCompleted failed.");
120 pScanResult = unique_ptr< ScanResult >(static_cast< ScanResult* >(user_data));
122 SysTryLogCatch(NID_CNT, pScanResult != null, , "OnScanCompleted failed.");
123 SysTryLogCatch(NID_CNT, pScanResult->pScanListener != null, , "Listener is null. OnScanCompleted succeeded.");
125 scanPath = pScanResult->scanPath;
126 pListener = pScanResult->pScanListener;
127 reqId = pScanResult->requestId;
129 r = ConvertError(error);
131 pListener->OnContentScanCompleted(reqId, scanPath, r);
132 SysLog(NID_CNT, "OnContentScanCompleted fired.");
135 int val = media_content_disconnect();
136 SysTryLog(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, "The disconnection failed[%d].", val);
140 OnContentUpdateCompleted(media_content_error_e error, int pid, media_content_db_update_item_type_e update_item,
141 media_content_db_update_type_e update_type, media_content_type_e media_type, char* uuid, char* path, char* mime_type, void* user_data)
143 SysLog(NID_CNT, "OnContentUpdateCompleted callback method is called.");
145 result r = E_SUCCESS;
147 SysTryLogReturn(NID_CNT, user_data != null, , "OnContentUpdateCompleted failed.");
149 _ContentManagerImpl* pTempManagerImpl = static_cast< _ContentManagerImpl* >(user_data);
150 SysTryLogReturn(NID_CNT, pTempManagerImpl != null, , "pTempManagerImpl is null.");
152 IContentUpdateEventListener* pListener = pTempManagerImpl->GetListener();
153 SysTryLogReturn(NID_CNT, pListener != null, , "IContentUpdateEventListener is null.");
155 if (error != MEDIA_CONTENT_ERROR_NONE)
162 case MEDIA_ITEM_FILE:
164 ContentType contentType = CONTENT_TYPE_UNKNOWN;
168 case MEDIA_CONTENT_TYPE_IMAGE:
169 contentType = CONTENT_TYPE_IMAGE;
172 case MEDIA_CONTENT_TYPE_VIDEO:
173 contentType = CONTENT_TYPE_VIDEO;
176 case MEDIA_CONTENT_TYPE_SOUND:
178 case MEDIA_CONTENT_TYPE_MUSIC:
179 contentType = CONTENT_TYPE_AUDIO;
182 case MEDIA_CONTENT_TYPE_OTHERS:
183 contentType = CONTENT_TYPE_OTHER;
188 SysLog(NID_CNT, "media_type is invalid.");
195 result res = UuId::Parse(str, contentId);
196 SysTryLogReturn(NID_CNT, !IsFailed(res), , "Failed to parse to the content ID.");
200 case MEDIA_CONTENT_INSERT:
201 pListener->OnContentFileCreated(contentId, contentType, r);
204 case MEDIA_CONTENT_DELETE:
205 pListener->OnContentFileDeleted(contentId, contentType, r);
208 case MEDIA_CONTENT_UPDATE:
209 pListener->OnContentFileUpdated(contentId, contentType, r);
213 SysLog(NID_CNT, "update_type is invalid.");
219 case MEDIA_ITEM_DIRECTORY:
221 String directoryPath(path);
223 pListener->OnContentDirectoryScanCompleted(directoryPath, r);
228 SysLog(NID_CNT, "update_item is invalid.");
232 SysLog(NID_CNT, "Fire the OnContentUpdateCompleted method.");
235 _ContentManagerImpl::_ContentManagerImpl(void)
237 , __isConnected(false)
243 _ContentManagerImpl::~_ContentManagerImpl(void)
249 val = media_content_unset_db_updated_cb();
250 SysLog(NID_CNT, "media_content_unset_db_updated_cb result[%d].", val);
255 val = media_content_disconnect();
256 SysLog(NID_CNT, "media_content_disconnect result[%d].", val);
258 __isConnected = false;
262 _ContentManagerImpl::GetInstance(ContentManager& contentManager)
264 return contentManager.__pImpl;
267 const _ContentManagerImpl*
268 _ContentManagerImpl::GetInstance(const ContentManager& contentManager)
270 return contentManager.__pImpl;
276 // E_OUT_OF_MEMORY(in public)
279 _ContentManagerImpl::Construct(void)
281 SysAssertf(!__isConnected,
282 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
286 int val = media_content_connect();
287 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM,
288 "The connection failed[%d].", val);
290 SysLog(NID_CNT, "media_content_connect result[%d].", val);
292 __isConnected = true;
304 // E_PRIVILEGE_DENIED(in public)
308 _ContentManagerImpl::CreateContent(const ContentInfo& contentInfo)
310 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
314 // Get common data from ContentInfo class
315 ContentInfo::_ContentData* pContentData = (const_cast <ContentInfo*>(&contentInfo))->GetContentData();
316 SysTryReturn(NID_CNT, pContentData != null, UuId::GetInvalidUuId(), E_INVALID_ARG,
317 "[E_INVALID_ARG] pContentData is null.");
319 SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(pContentData->contentPath, true), UuId::GetInvalidUuId(),
320 E_INVALID_ARG, "[E_INVALID_ARG] The contentPath is not compatible.");
321 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(pContentData->contentPath), UuId::GetInvalidUuId(), E_FILE_NOT_FOUND,
322 "[E_FILE_NOT_FOUND] The file corresponding to contentInfo could not be found.");
323 SysTryReturn(NID_CNT, pContentData->contentId == UuId::GetInvalidUuId(), UuId::GetInvalidUuId(),
324 E_INVALID_ARG, "[E_INVALID_ARG] The contentId is not empty.");
326 // Compare the type of input parameter and system
327 ContentType inputType = pContentData->contentType;
328 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(pContentData->contentPath, true);
330 if (inputType != sysType)
332 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
334 SysLogException(NID_CNT, E_INVALID_ARG,
335 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
336 return UuId::GetInvalidUuId();
340 // Save data to database with contentPath.
341 unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(pContentData->contentPath));
342 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
343 "[E_OUT_OF_MEMORY] The memory is insufficient.");
345 media_info_h tempMediaInfo = null;
346 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
348 // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
349 int val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
350 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
351 "The registration to database failed[%d].", val);
353 pMediaInfo.reset(tempMediaInfo);
355 // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
356 ContentId contentId = SaveDataToDatabase(pMediaInfo.get(), pContentData);
357 result r = GetLastResult();
358 SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
359 "[%s] The registration to database failed.", GetErrorMessage(r));
364 // There are two steps(insert and update) for content registration.
365 // If the update failed after inserting, the inserted data SHOULD be deleted from here.
366 val = media_info_delete_from_db(pStr.get());
367 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
369 return UuId::GetInvalidUuId();
376 // E_FILE_ALREADY_EXIST
383 // E_PRIVILEGE_DENIED(in public)
386 _ContentManagerImpl::CreateContent(const ByteBuffer& byteBuffer, const String& destinationPath,
387 const ContentInfo* pContentInfo)
389 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
393 // Check parameters(for length)
394 SysTryReturn(NID_CNT, byteBuffer.GetRemaining() > 0, UuId::GetInvalidUuId(), E_INVALID_ARG,
395 "[E_INVALID_ARG] byteBuffer is invalid.");
397 // Check parameters(for path compatibility)
398 SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(destinationPath, false), UuId::GetInvalidUuId(),
399 E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", destinationPath.GetPointer());
400 SysTryReturn(NID_CNT, !_FileImpl::IsFileExist(destinationPath), UuId::GetInvalidUuId(), E_FILE_ALREADY_EXIST,
401 "[E_FILE_ALREADY_EXIST] The specified file already exists.");
403 // Create a file with bytebuffer
404 unique_ptr<File> pFile(new (nothrow) File);
405 SysTryReturn(NID_CNT, pFile != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
406 "[E_OUT_OF_MEMORY] The memory is insufficient.");
408 // Exception : E_SUCCESS, E_OUT_OF_MEMORY, E_INVALID_ARG, E_ILLEGAL_ACCESS, E_MAX_EXCEEDED, E_STORAGE_FULL, E_IO, (E_FILE_NOT_FOUND), E_SYSTEM
409 result r = pFile->Construct(destinationPath, L"w+");
410 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r,
411 "[%s] The destination file can not be created.", GetErrorMessage(r));
413 _FileImpl* pFileImpl = _FileImpl::GetInstance(*pFile);
414 SysTryReturn(NID_CNT, pFileImpl != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
415 "[E_OUT_OF_MEMORY] The memory is insufficient.");
417 // Exception : E_SUCCESS, E_INVALID_ARG, E_ILLEGAL_ACCESS, E_STORAGE_FULL, E_IO
418 r = pFileImpl->Write(byteBuffer);
419 SysTryReturn(NID_CNT, !(IsFailed(r)), UuId::GetInvalidUuId(), r,
420 "[%s] The data can not be written in the destination file.", GetErrorMessage(r));
422 // for release file pointer
423 delete pFile.release();
427 ContentInfo::_ContentData contentData;
428 ContentInfo::_ContentData* pContentData = null;
429 media_info_h tempMediaInfo = null;
430 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
431 unique_ptr<char[]> pStr(null);
433 if (pContentInfo != null)
435 pContentData = (const_cast <ContentInfo*>(pContentInfo))->GetContentData();
436 SysTryCatch(NID_CNT, pContentData != null, , E_INVALID_ARG, "[E_INVALID_ARG] GetContentData failed.");
438 SysTryCatch(NID_CNT, pContentData->contentId == UuId::GetInvalidUuId(), , E_INVALID_ARG,
439 "[E_INVALID_ARG] The content already exists in database.");
441 // Compare the type of input parameter and system
442 // CheckContentType() need actual file. so it should be checked after creating the file.
443 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
444 ContentType inputType = pContentData->contentType;
446 if (inputType != sysType)
448 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
450 SysLogException(NID_CNT, E_INVALID_ARG,
451 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
456 // Sets the content path
457 (pContentData->contentPath).Clear();
458 pContentData->contentPath = destinationPath;
462 // Set the content path
463 contentData.contentPath = destinationPath;
465 pContentData = &contentData;
468 // Register the content to database directly.
469 pStr.reset(_StringConverter::CopyToCharArrayN(destinationPath));
470 SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
472 val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
473 SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
474 "media_info_insert_to_db failed[%d].", val);
476 pMediaInfo.reset(tempMediaInfo);
478 // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
479 contentId = SaveDataToDatabase(pMediaInfo.get(), pContentData);
481 SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
482 "[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
487 result saveResult = GetLastResult();
489 // If the destination file is made by this method, it should be deleted when error occurs.
490 r = _FileImpl::Remove(destinationPath);
491 SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
493 if (pMediaInfo != null)
495 val = media_info_delete_from_db(pStr.get());
496 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
499 SetLastResult(saveResult);
500 return UuId::GetInvalidUuId();
508 // E_FILE_ALREADY_EXIST
515 // E_PRIVILEGE_DENIED(in public)
518 _ContentManagerImpl::CreateContent(const String& sourcePath, const String& destinationPath, bool deleteSource,
519 const ContentInfo* pContentInfo)
521 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
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.");
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, false), UuId::GetInvalidUuId(),
533 E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", destinationPath.GetPointer());
535 result r = E_SUCCESS;
537 if (deleteSource) // move
539 // Exception : E_SUCCESS, E_INVALID_ARG, E_ILLEGAL_ACCESS, E_FILE_NOT_FOUND, E_FILE_ALREADY_EXIST, E_MAX_EXCEEDED, E_STORAGE_FULL, E_IO
540 r = _FileImpl::Move(sourcePath, destinationPath);
541 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Moving the file failed.", GetErrorMessage(r));
545 // Exception : E_SUCCESS, E_INVALID_ARG, E_ILLEGAL_ACCESS, E_FILE_NOT_FOUND, E_FILE_ALREADY_EXIST, E_MAX_EXCEEDED, E_STORAGE_FULL, E_IO
546 r = _FileImpl::Copy(sourcePath, destinationPath, true);
547 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Copying the file failed.", GetErrorMessage(r));
552 ContentInfo::_ContentData contentData;
553 ContentInfo::_ContentData* pContentData = null;
554 media_info_h tempMediaInfo = null;
555 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
556 unique_ptr<char[]> pStr(null);
558 if (pContentInfo != null)
560 pContentData = (const_cast <ContentInfo*>(pContentInfo))->GetContentData();
561 SysTryCatch(NID_CNT, pContentData != null, , E_INVALID_ARG, "[E_INVALID_ARG] GetContentData failed.");
563 SysTryCatch(NID_CNT, pContentData->contentId == UuId::GetInvalidUuId(), , E_INVALID_ARG,
564 "[E_INVALID_ARG] The content already exists in database.");
566 // Compare the type of input parameter and system
567 // CheckContentType() need actual file. so it should be checked after creating the file.
568 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
569 ContentType inputType = pContentData->contentType;
571 if (inputType != sysType)
573 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
575 SysLogException(NID_CNT, E_INVALID_ARG,
576 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
581 // Set the content path
582 (pContentData->contentPath).Clear();
583 pContentData->contentPath = destinationPath;
587 // Set the content path
588 contentData.contentPath = destinationPath;
590 pContentData = &contentData;
593 pStr.reset(_StringConverter::CopyToCharArrayN(destinationPath));
594 SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
596 val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
597 SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
598 "media_info_insert_to_db failed[%d].", val);
600 pMediaInfo.reset(tempMediaInfo);
602 contentId = SaveDataToDatabase(pMediaInfo.get(), pContentData);
604 SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
605 "[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
610 result saveResult = GetLastResult();
612 // If the destination file is made by this method, it should be deleted when error occurs.
613 r = _FileImpl::Remove(destinationPath);
614 SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
616 if (pMediaInfo != null)
618 val = media_info_delete_from_db(pStr.get());
619 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
622 SetLastResult(saveResult);
623 return UuId::GetInvalidUuId();
633 // E_PRIVILEGE_DENIED(in public)
636 _ContentManagerImpl::GetContentInfoN(const ContentId& contentId) const
638 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
642 SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), null, E_INVALID_ARG,
643 "[E_INVALID_ARG] The contentId is invalid.");
645 unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(contentId.ToString()));
646 SysTryReturn(NID_CNT, pStr != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
648 media_info_h tempMediaInfo = null;
649 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
650 int val = media_info_get_media_from_db(pStr.get(), &tempMediaInfo);
651 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
652 "media_info_get_media_from_db failed[%d].", val);
654 pMediaInfo.reset(tempMediaInfo);
656 media_content_type_e systemType = MEDIA_CONTENT_TYPE_IMAGE;
657 val = media_info_get_media_type(pMediaInfo.get(), &systemType);
658 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
659 "media_info_get_media_type failed[%d].", val);
661 char* __pFilePath = null;
662 val = media_info_get_file_path(pMediaInfo.get(), &__pFilePath);
663 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
664 "media_info_get_file_path failed[%d].", val);
666 unique_ptr<char, CharDeleter> pFilePath(__pFilePath);
668 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(String(pFilePath.get())), null, E_FILE_NOT_FOUND,
669 "[E_FILE_NOT_FOUND] The file corresponding to contentId could not be found.");
671 result r = E_SUCCESS;
673 if (systemType == SYSTEM_TYPE_IMAGE)
675 unique_ptr<ImageContentInfo> pImageContentInfo(new (nothrow) ImageContentInfo);
676 SysTryReturn(NID_CNT, pImageContentInfo != null, null, E_OUT_OF_MEMORY,
677 "[E_OUT_OF_MEMORY] The memory is insufficient.");
680 ContentInfo::_ContentData* pContentData = pImageContentInfo->GetContentData();
681 SysTryReturn(NID_CNT, pContentData != null, null, E_OUT_OF_MEMORY,
682 "[E_OUT_OF_MEMORY] The memory is insufficient.");
684 // Get image metadata
685 ImageContentInfo::_ImageContentData* pImageContentData = pImageContentInfo->GetImageContentData();
686 SysTryReturn(NID_CNT, pImageContentData != null, null, E_OUT_OF_MEMORY,
687 "[E_OUT_OF_MEMORY] The memory is insufficient.");
690 // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
691 r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, pImageContentData);
692 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
694 return pImageContentInfo.release();
696 else if (systemType == SYSTEM_TYPE_SOUND || systemType == SYSTEM_TYPE_MUSIC)
698 unique_ptr<AudioContentInfo> pAudioContentInfo(new (nothrow) AudioContentInfo);
699 SysTryReturn(NID_CNT, pAudioContentInfo != null, null, E_OUT_OF_MEMORY,
700 "[E_OUT_OF_MEMORY] The memory is insufficient.");
702 ContentInfo::_ContentData* pContentData = pAudioContentInfo->GetContentData();
703 SysTryReturn(NID_CNT, pContentData != null, null, E_OUT_OF_MEMORY,
704 "[E_OUT_OF_MEMORY] The memory is insufficient.");
706 AudioContentInfo::_AudioContentData* pAudioContentData = pAudioContentInfo->GetAudioContentData();
707 SysTryReturn(NID_CNT, pAudioContentData != null, null, E_OUT_OF_MEMORY,
708 "[E_OUT_OF_MEMORY] The memory is insufficient.");
710 r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, pAudioContentData);
711 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
713 return pAudioContentInfo.release();
715 else if (systemType == SYSTEM_TYPE_VIDEO)
717 unique_ptr<VideoContentInfo> pVideoContentInfo(new (nothrow) VideoContentInfo);
718 SysTryReturn(NID_CNT, pVideoContentInfo != null, null, E_OUT_OF_MEMORY,
719 "[E_OUT_OF_MEMORY] The memory is insufficient.");
721 ContentInfo::_ContentData* pContentData = pVideoContentInfo->GetContentData();
722 SysTryReturn(NID_CNT, pContentData != null, null, E_OUT_OF_MEMORY,
723 "[E_OUT_OF_MEMORY] The memory is insufficient.");
725 VideoContentInfo::_VideoContentData* pVideoContentData = pVideoContentInfo->GetVideoContentData();
726 SysTryReturn(NID_CNT, pVideoContentData != null, null, E_OUT_OF_MEMORY,
727 "[E_OUT_OF_MEMORY] The memory is insufficient.");
729 r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, pVideoContentData);
730 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
732 return pVideoContentInfo.release();
734 else if (systemType == SYSTEM_TYPE_OTHER)
736 unique_ptr<OtherContentInfo> pOtherContentInfo(new (nothrow) OtherContentInfo);
737 SysTryReturn(NID_CNT, pOtherContentInfo != null, null, E_OUT_OF_MEMORY,
738 "[E_OUT_OF_MEMORY] The memory is insufficient.");
740 ContentInfo::_ContentData* pContentData = pOtherContentInfo->GetContentData();
741 SysTryReturn(NID_CNT, pContentData != null, null, E_OUT_OF_MEMORY,
742 "[E_OUT_OF_MEMORY] The memory is insufficient.");
744 r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, null);
745 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
747 return pOtherContentInfo.release();
751 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] Unsupported type");
763 // E_PRIVILEGE_DENIED(in public)
766 _ContentManagerImpl::UpdateContent(const ContentInfo& contentInfo)
768 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
772 ContentId contentId = contentInfo.GetContentId();
773 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, "The content id is invalid.");
774 SysTryReturnResult(NID_CNT, _FileImpl::IsFileExist(contentInfo.GetContentPath()), E_FILE_NOT_FOUND,
775 "The file corresponding to contentInfo could not be found.");
777 // Get common data from ContentInfo class
778 ContentInfo::_ContentData* pContentData = (const_cast <ContentInfo*>(&contentInfo))->GetContentData();
779 SysTryReturnResult(NID_CNT, pContentData != null, E_INVALID_ARG, "pContentData is null.");
781 // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SYSTEM, E_SERVICE_BUSY
782 result r = this->UpdateDataToDatabase(pContentData);
783 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "UpdateDataToDatabase failed.");
795 // E_PRIVILEGE_DENIED(in public)
796 // - E_ILLEGAL_ACCESS
799 _ContentManagerImpl::DeleteContent(const ContentId& contentId)
801 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
805 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, "The contentId is invalid.");
807 unique_ptr<char[]> pContentId(_StringConverter::CopyToCharArrayN(contentId.ToString()));
808 SysTryReturnResult(NID_CNT, pContentId != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
810 result r = E_SUCCESS;
812 media_info_h tempMediaInfo = null;
813 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
815 val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
816 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
817 "media_info_get_media_from_db failed[%d].", val);
819 pMediaInfo.reset(tempMediaInfo);
821 char* __pContentPath = null;
823 val = media_info_get_file_path(pMediaInfo.get(), &__pContentPath);
824 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
825 "media_info_get_file_path failed[%d].", val);
827 unique_ptr<char, CharDeleter> pContentPath(__pContentPath);
829 String contentPath = String(pContentPath.get());
830 SysTryReturnResult(NID_CNT, _FileImpl::IsFileExist(contentPath), E_FILE_NOT_FOUND,
831 "The file corresponding to contentId could not be found.");
833 val = media_info_delete_from_db(pContentId.get());
834 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
835 "media_info_delete_From_db failed[%d].", val);
837 r = _FileImpl::Remove(contentPath);
838 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The file is not deleted.");
845 // E_OBJ_ALREADY_EXIST
849 _ContentManagerImpl::AddContentUpdateEventListener(IContentUpdateEventListener& listener)
853 SysTryReturnResult(NID_CNT, GetListener() == null, E_OBJ_ALREADY_EXIST, "IContentUpdateEventListener is already set.");
855 SetListener(&listener);
857 int val = media_content_set_db_updated_cb(OnContentUpdateCompleted, this);
858 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "media_content_set_db_updated_cb failed[%d].", val);
869 _ContentManagerImpl::RemoveContentUpdateEventListener(IContentUpdateEventListener& listener)
873 SysTryReturnResult(NID_CNT, GetListener() == &listener, E_OBJ_NOT_FOUND, "The input listener is not equal to the registered listener.");
875 int val = media_content_unset_db_updated_cb();
876 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "media_content_unset_db_updated_cb failed[%d].", val);
888 // E_PRIVILEGE_DENIED(in public)
891 _ContentManagerImpl::ScanFile(const Tizen::Base::String& contentPath)
895 SysSecureLog(NID_CNT, "The scan path is [%ls].", contentPath.GetPointer());
897 unique_ptr<char[]> pContentPath(_StringConverter::CopyToCharArrayN(contentPath));
898 SysTryReturnResult(NID_CNT, pContentPath, E_SYSTEM, "pContentPath is NULL.");
900 int val = media_content_connect();
901 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The connection failed[%d].", val);
903 val = media_content_scan_file(pContentPath.get());
904 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val), "media_content_scan_file failed[%d].", val);
906 val = media_content_disconnect();
907 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The disconnection failed[%d].", val);
917 // E_PRIVILEGE_DENIED(in public)
920 _ContentManagerImpl::ScanDirectory(const Tizen::Base::String& directoryPath, bool recursive, IContentScanListener* pListener, RequestId& reqId)
924 SysLog(NID_CNT, "The scan path is [%ls].", directoryPath.GetPointer());
926 unique_ptr<char[]> pDirPath(_StringConverter::CopyToCharArrayN(directoryPath));
927 SysTryReturnResult(NID_CNT, pDirPath, E_SYSTEM, "pDirPath is NULL.");
929 int val = media_content_connect();
930 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The connection failed[%d].", val);
932 unique_ptr< ScanResult > pScanResult(new (nothrow) ScanResult);
933 SysTryReturnResult(NID_CNT, pScanResult != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
937 pScanResult->scanPath = directoryPath;
938 pScanResult->pScanListener = pListener;
939 pScanResult->requestId = reqId;
941 val = media_content_scan_folder(pDirPath.get(), recursive, OnScanCompleted, pScanResult.release());
942 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val), "media_content_scan_folder failed[%d].", val);
955 _ContentManagerImpl::UpdateDataToDatabase(const ContentInfo::_ContentData* pContentData) const
959 SysTryReturnResult(NID_CNT, pContentData != null, E_INVALID_ARG, "pContentData is null.");
961 media_info_h tempMediaInfo = null;
962 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
963 unique_ptr<char[]> pContentId(_StringConverter::CopyToCharArrayN((pContentData->contentId).ToString()));
964 SysTryReturnResult(NID_CNT, pContentId != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
966 int val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
967 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
968 "media_info_get_media_from_db failed[%d].", val);
970 pMediaInfo.reset(tempMediaInfo);
972 result r = E_SUCCESS;
973 unique_ptr<char[]> pValue(null);
975 if (pContentData->pAuthor != null)
977 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pAuthor)));
978 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
980 val = media_info_set_author(pMediaInfo.get(), pValue.get());
981 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
982 "media_info_set_author failed[%d].", val);
984 if (pContentData->pCategory != null)
986 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pCategory)));
987 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
989 val = media_info_set_category(pMediaInfo.get(), pValue.get());
990 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
991 "media_info_set_category failed[%d].", val);
993 if (pContentData->pContentName != null)
995 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pContentName)));
996 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
998 val = media_info_set_content_name(pMediaInfo.get(), pValue.get());
999 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1000 "media_info_set_content_name failed[%d].", val);
1002 if (pContentData->pDescription != null)
1004 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pDescription)));
1005 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1007 val = media_info_set_description(pMediaInfo.get(), pValue.get());
1008 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1009 "media_info_set_description failed[%d].", val);
1011 if (pContentData->pKeyword != null)
1013 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pKeyword)));
1014 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1016 val = media_info_set_keyword(pMediaInfo.get(), pValue.get());
1017 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1018 "media_info_set_keyword failed[%d].", val);
1020 if (pContentData->pLocationTag != null)
1022 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pLocationTag)));
1023 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1025 val = media_info_set_location_tag(pMediaInfo.get(), pValue.get());
1026 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1027 "media_info_set_location_tag failed[%d].", val);
1029 if (pContentData->pProvider != null)
1031 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pProvider)));
1032 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1034 val = media_info_set_provider(pMediaInfo.get(), pValue.get());
1035 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1036 "media_info_set_provider failed[%d].", val);
1038 if (pContentData->pRating != null)
1040 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pRating)));
1041 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1043 val = media_info_set_age_rating(pMediaInfo.get(), pValue.get());
1044 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1045 "media_info_set_age_rating failed[%d].", val);
1047 if (Double::Compare(pContentData->latitude, DEFAULT_COORDINATE) != 0 &&
1048 Double::Compare(pContentData->longitude, DEFAULT_COORDINATE) != 0)
1050 val = media_info_set_latitude(pMediaInfo.get(), pContentData->latitude);
1051 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1052 "media_info_set_latitude failed[%d].", val);
1054 val = media_info_set_longitude(pMediaInfo.get(), pContentData->longitude);
1055 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1056 "media_info_set_longitude failed[%d].", val);
1058 if (Double::Compare(pContentData->altitude, DEFAULT_COORDINATE) != 0)
1060 val = media_info_set_altitude(pMediaInfo.get(), pContentData->altitude);
1061 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1062 "media_info_set_altitude failed[%d].", val);
1066 val = media_info_update_to_db(pMediaInfo.get());
1067 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1068 "media_info_update_to_db failed[%d].", val);
1081 _ContentManagerImpl::SaveDataToDatabase(const media_info_h pMediaInfo,
1082 ContentInfo::_ContentData* pContentData) const
1086 SysTryReturn(NID_CNT, pContentData != null, UuId::GetInvalidUuId(), E_INVALID_ARG,
1087 "[E_INVALID_ARG] pContentData is null.");
1089 // Exception : E_SUCCESS, E_INVALID_ARG
1090 String extension = _FileImpl::GetFileExtension(pContentData->contentPath);
1091 result r = GetLastResult();
1092 SysTryReturn(NID_CNT, !(IsFailed(r)), UuId::GetInvalidUuId(), r, "[%s] Propagating.", GetErrorMessage(r));
1094 // If the content format is JPG and it has GPS data, it will be saved in database automatically.
1095 if (extension == L"jpg" || extension == L"jpeg" || extension == L"JPG" || extension == L"JPEG")
1097 SysLog(NID_CNT, "The format of content is jpg.");
1099 ImageMetadata* pImageMetadata = _ContentManagerUtilImpl::GetImageMetaN(pContentData->contentPath, true);
1100 if (pImageMetadata != null)
1102 pContentData->latitude = pImageMetadata->GetLatitude();
1103 pContentData->longitude = pImageMetadata->GetLongitude();
1105 delete pImageMetadata;
1106 pImageMetadata = null;
1111 unique_ptr<char[]> pStr(null);
1113 if (pContentData->pAuthor != null)
1115 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pAuthor)));
1116 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1117 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1119 val = media_info_set_author(pMediaInfo, pStr.get());
1120 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1121 "media_info_set_author failed[%d].", val);
1123 if (pContentData->pCategory != null)
1125 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pCategory)));
1126 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1127 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1129 val = media_info_set_category(pMediaInfo, pStr.get());
1130 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1131 "media_info_set_category failed[%d].", val);
1133 if (pContentData->pContentName != null)
1135 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pContentName)));
1136 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1137 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1139 val = media_info_set_content_name(pMediaInfo, pStr.get());
1140 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1141 "media_info_set_content_name failed[%d].", val);
1143 if (pContentData->pDescription != null)
1145 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pDescription)));
1146 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1147 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1149 val = media_info_set_description(pMediaInfo, pStr.get());
1150 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1151 "media_info_set_description failed[%d].", val);
1153 if (pContentData->pKeyword != null)
1155 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pKeyword)));
1156 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1157 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1159 val = media_info_set_keyword(pMediaInfo, pStr.get());
1160 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1161 "media_info_set_keyword failed[%d].", val);
1163 if (pContentData->pLocationTag != null)
1165 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pLocationTag)));
1166 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1167 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1169 val = media_info_set_location_tag(pMediaInfo, pStr.get());
1170 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1171 "media_info_set_location_tag failed[%d].", val);
1173 if (pContentData->pProvider != null)
1175 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pProvider)));
1176 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1177 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1179 val = media_info_set_provider(pMediaInfo, pStr.get());
1180 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1181 "media_info_set_provider failed[%d].", val);
1183 if (pContentData->pRating != null)
1185 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pRating)));
1186 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1187 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1189 val = media_info_set_age_rating(pMediaInfo, pStr.get());
1190 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1191 "media_info_set_age_rating failed[%d].", val);
1193 if (Double::Compare(pContentData->latitude, DEFAULT_COORDINATE) != 0 &&
1194 Double::Compare(pContentData->longitude, DEFAULT_COORDINATE) != 0)
1196 val = media_info_set_latitude(pMediaInfo, pContentData->latitude);
1197 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1198 "media_info_set_latitude failed[%d].", val);
1200 val = media_info_set_longitude(pMediaInfo, pContentData->longitude);
1201 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1202 "media_info_set_longitude failed[%d].", val);
1204 if (Double::Compare(pContentData->altitude, DEFAULT_COORDINATE) != 0)
1206 val = media_info_set_altitude(pMediaInfo, pContentData->altitude);
1207 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1208 "media_info_set_altitude failed[%d].", val);
1212 val = media_info_update_to_db(pMediaInfo);
1213 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1214 "media_info_update_to_db failed[%d].", val);
1216 char* __pMediaId = null;
1217 unique_ptr<char, CharDeleter> pMediaId(null);
1219 val = media_info_get_media_id(pMediaInfo, &__pMediaId);
1220 if (__pMediaId != null)
1222 pMediaId.reset(__pMediaId);
1226 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1227 "media_info_get_media_id failed[%d].", val);
1230 String contentId(pMediaId.get());
1232 r = UuId::Parse(contentId, pContentData->contentId);
1233 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_INVALID_ARG,
1234 "[E_INVALID_ARG] UuId::Parse failed.");
1236 return pContentData->contentId;
1247 _ContentManagerImpl::MakeContentInfo(const media_info_h pMediaInfo, ContentInfo::_ContentData* pContentData,
1248 int systemType, void* pMetadata) const
1252 if (systemType != SYSTEM_TYPE_OTHER)
1254 SysTryReturnResult(NID_CNT, pMediaInfo != null && pContentData != null && pMetadata != null, E_INVALID_ARG,
1255 "The specified parameter is invalid.");
1257 else // There is no metadata in Other type
1259 SysTryReturnResult(NID_CNT, pMediaInfo != null && pContentData != null, E_INVALID_ARG,
1260 "The specified parameter is invalid.");
1263 result r = E_SUCCESS;
1264 char* __pStrValue = null;
1265 unique_ptr<char, CharDeleter> pStrValue(null);
1268 int val = media_info_get_media_id(pMediaInfo, &__pStrValue);
1269 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1270 "media_info_get_media_id failed[%d].", val);
1272 if (__pStrValue != null)
1274 pStrValue.reset(__pStrValue);
1276 String strContentId(pStrValue.get());
1278 r = UuId::Parse(strContentId, pContentData->contentId);
1279 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The content id can not be parsed.");
1281 SysLog(NID_CNT, "INFO: contentId[%ls]", strContentId.GetPointer());
1285 val = media_info_get_file_path(pMediaInfo, &__pStrValue);
1286 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1287 "media_info_get_file_path failed[%d].", val);
1289 if (__pStrValue != null)
1291 pStrValue.reset(__pStrValue);
1293 String strFilePath(pStrValue.get());
1295 // If the api version is 2.0, the content path has to be changed.
1296 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
1298 if (strFilePath.StartsWith(Environment::GetMediaPath(), 0))
1300 r = strFilePath.Replace(Environment::GetMediaPath(), OSP_MEDIA_PHONE);
1301 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The content path is not changed.");
1303 else if (strFilePath.StartsWith(Environment::GetExternalStoragePath(), 0))
1305 r = strFilePath.Replace(Environment::GetExternalStoragePath(), OSP_MEDIA_MMC);
1306 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Replace failed.");
1310 SysLogException(NID_CNT, E_INVALID_ARG,
1311 "[E_INVALID_ARG] The content path is not supported.");
1312 return E_INVALID_ARG;
1316 pContentData->contentPath = strFilePath;
1318 SysSecureLog(NID_CNT, "INFO: contentPath[%ls]", strFilePath.GetPointer());
1322 val = media_info_get_mime_type(pMediaInfo, &__pStrValue);
1323 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1324 "media_info_get_mime_type failed[%d].", val);
1326 if (__pStrValue != null)
1328 pStrValue.reset(__pStrValue);
1330 pContentData->mimeType = pStrValue.get();
1332 SysLog(NID_CNT, "INFO: mimeType[%ls]", (pContentData->mimeType).GetPointer());
1336 unsigned long long longlongValue = 0;
1337 val = media_info_get_size(pMediaInfo, &longlongValue);
1338 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1339 "media_info_get_size failed[%d].", val);
1340 pContentData->contentSize = longlongValue;
1341 SysLog(NID_CNT, "INFO: contentSize[%llu]", longlongValue);
1344 media_content_storage_e storageType;
1345 val = media_info_get_storage_type(pMediaInfo, &storageType);
1346 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1347 "media_info_get_storage_type failed[%d].", val);
1348 pContentData->storageType = storageType;
1349 SysLog(NID_CNT, "INFO: storageType[%d]", storageType);
1352 val = media_info_is_drm(pMediaInfo, &(pContentData->isDrm));
1353 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1354 "media_info_is_drm failed[%d].", val);
1355 SysLog(NID_CNT, "INFO: isDrm[%d]", pContentData->isDrm);
1359 val = media_info_get_added_time(pMediaInfo, &time);
1360 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1361 "media_info_get_added_time failed[%d].", val);
1362 r = (pContentData->dateTime).SetValue(1970, 1, 1);
1363 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "SetValue failed.");
1364 r = (pContentData->dateTime).AddSeconds(time);
1365 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "AddSeconds failed.");
1366 SysLog(NID_CNT, "INFO: dateTime[%ls]", ((pContentData->dateTime).ToString()).GetPointer());
1369 val = media_info_get_thumbnail_path(pMediaInfo, &__pStrValue);
1370 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1371 "media_info_get_thumbnail_path failed[%d].", val);
1373 if (__pStrValue != null)
1375 pStrValue.reset(__pStrValue);
1377 pContentData->pThumbnailPath = new (nothrow) String(pStrValue.get());
1379 SysLog(NID_CNT, "INFO: thumbnailPath[%ls]", (*pContentData->pThumbnailPath).GetPointer());
1383 val = media_info_get_author(pMediaInfo, &__pStrValue);
1384 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1385 "media_info_get_author failed[%d].", val);
1387 if (__pStrValue != null)
1389 pStrValue.reset(__pStrValue);
1391 pContentData->pAuthor = new (nothrow) String(pStrValue.get());
1393 SysLog(NID_CNT, "INFO: author[%ls]", (*pContentData->pAuthor).GetPointer());
1397 val = media_info_get_category(pMediaInfo, &__pStrValue);
1398 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1399 "media_info_get_category failed[%d].", val);
1401 if (__pStrValue != null)
1403 pStrValue.reset(__pStrValue);
1405 pContentData->pCategory = new (nothrow) String(pStrValue.get());
1407 SysLog(NID_CNT, "INFO: category[%ls]", (*pContentData->pCategory).GetPointer());
1411 val = media_info_get_content_name(pMediaInfo, &__pStrValue);
1412 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1413 "media_info_get_content_name failed[%d].", val);
1415 if (__pStrValue != null)
1417 pStrValue.reset(__pStrValue);
1419 pContentData->pContentName = new (nothrow) String(pStrValue.get());
1421 SysSecureLog(NID_CNT, "INFO: contentName[%ls]", (*pContentData->pContentName).GetPointer());
1425 val = media_info_get_description(pMediaInfo, &__pStrValue);
1426 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1427 "media_info_get_description failed[%d].", val);
1429 if (__pStrValue != null)
1431 pStrValue.reset(__pStrValue);
1433 pContentData->pDescription = new (nothrow) String(pStrValue.get());
1435 SysLog(NID_CNT, "INFO: description[%ls]", (*pContentData->pDescription).GetPointer());
1439 val = media_info_get_keyword(pMediaInfo, &__pStrValue);
1440 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1441 "media_info_get_keyword failed[%d].", val);
1443 if (__pStrValue != null)
1445 pStrValue.reset(__pStrValue);
1447 pContentData->pKeyword = new (nothrow) String(pStrValue.get());
1449 SysLog(NID_CNT, "INFO: keyword[%ls]", (*pContentData->pKeyword).GetPointer());
1453 val = media_info_get_location_tag(pMediaInfo, &__pStrValue);
1454 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1455 "media_info_get_location_tag failed[%d].", val);
1457 if (__pStrValue != null)
1459 pStrValue.reset(__pStrValue);
1461 pContentData->pLocationTag = new (nothrow) String(pStrValue.get());
1463 SysSecureLog(NID_CNT, "INFO: locationTag[%ls]", (*pContentData->pLocationTag).GetPointer());
1467 val = media_info_get_provider(pMediaInfo, &__pStrValue);
1468 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1469 "media_info_get_provider failed[%d].", val);
1471 if (__pStrValue != null)
1473 pStrValue.reset(__pStrValue);
1475 pContentData->pProvider = new (nothrow) String(pStrValue.get());
1477 SysLog(NID_CNT, "INFO: provider[%ls]", (*pContentData->pProvider).GetPointer());
1481 val = media_info_get_age_rating(pMediaInfo, &__pStrValue);
1482 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1483 "media_info_get_age_rating failed[%d].", val);
1485 if (__pStrValue != null)
1487 pStrValue.reset(__pStrValue);
1489 pContentData->pRating = new (nothrow) String(pStrValue.get());
1491 SysLog(NID_CNT, "INFO: rating[%ls]", (*pContentData->pRating).GetPointer());
1495 double doubleValue = 0;
1496 val = media_info_get_latitude(pMediaInfo, &doubleValue);
1497 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1498 "media_info_get_latitude failed[%d].", val);
1500 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1502 pContentData->latitude = doubleValue;
1504 SysSecureLog(NID_CNT, "INFO: latitude[%f]", pContentData->latitude);
1506 val = media_info_get_longitude(pMediaInfo, &doubleValue);
1507 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1508 "media_info_get_longitude failed[%d].", val);
1510 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1512 pContentData->longitude = doubleValue;
1514 SysSecureLog(NID_CNT, "INFO: longitude[%f]", pContentData->longitude);
1516 val = media_info_get_altitude(pMediaInfo, &doubleValue);
1517 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1518 "media_info_get_altitude failed[%d].", val);
1520 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1522 pContentData->altitude = doubleValue;
1524 SysLog(NID_CNT, "INFO: altitude[%f]", pContentData->altitude);
1528 // contentType and metadata
1529 if (systemType == SYSTEM_TYPE_IMAGE)
1531 image_meta_h __pImageMeta = null;
1532 unique_ptr<image_meta_h, ImageMetaDeleter> pImageMeta(null);
1534 pContentData->contentType = CONTENT_TYPE_IMAGE;
1535 SysLog(NID_CNT, "META: ContentType[%d]", pContentData->contentType);
1537 val = media_info_get_image(pMediaInfo, &__pImageMeta);
1538 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1539 "media_info_get_image failed[%d].", val);
1541 pImageMeta.reset(&__pImageMeta);
1544 val = image_meta_get_width(*(pImageMeta.get()), &intValue);
1545 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1546 "image_meta_get_width failed[%d].", val);
1548 (static_cast<ImageContentInfo::_ImageContentData*>(pMetadata))->width = intValue;
1549 SysLog(NID_CNT, "META: width[%d]", intValue);
1552 val = image_meta_get_height(*(pImageMeta.get()), &intValue);
1553 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1554 "image_meta_get_height failed[%d].", val);
1556 (static_cast<ImageContentInfo::_ImageContentData*>(pMetadata))->height = intValue;
1557 SysLog(NID_CNT, "META: height[%d]", intValue);
1560 media_content_orientation_e orientation;
1561 val = image_meta_get_orientation(*(pImageMeta.get()), &orientation);
1562 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1563 "image_meta_get_orientation failed[%d].", val);
1565 (static_cast<ImageContentInfo::_ImageContentData*>(pMetadata))->orientationType =
1566 static_cast<ImageOrientationType>(orientation);
1567 SysLog(NID_CNT, "META: orientation[%d]", orientation);
1570 val = media_info_get_display_name(pMediaInfo, &__pStrValue);
1571 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1572 "media_info_get_display_name failed[%d].", val);
1574 if (__pStrValue != null)
1576 pStrValue.reset(__pStrValue);
1580 String strTitle(pStrValue.get());
1582 r = strTitle.LastIndexOf(L'.', strTitle.GetLength() - 1, pos);
1585 r = strTitle.SubString(0, pos, fileName);
1586 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The title is invalid.");
1590 // Without extension
1592 fileName = strTitle;
1595 (static_cast<ImageContentInfo::_ImageContentData*>(pMetadata))->title = fileName;
1597 SysLog(NID_CNT, "META: title[%ls]", fileName.GetPointer());
1600 else if (systemType == SYSTEM_TYPE_SOUND || systemType == SYSTEM_TYPE_MUSIC)
1602 audio_meta_h __pAudioMeta = null;
1603 unique_ptr<audio_meta_h, AudioMetaDeleter> pAudioMeta(null);
1605 pContentData->contentType = CONTENT_TYPE_AUDIO;
1606 SysLog(NID_CNT, "META: ContentType[%d]", pContentData->contentType);
1608 val = media_info_get_audio(pMediaInfo, &__pAudioMeta);
1609 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1610 "media_info_get_audio failed[%d].", val);
1612 pAudioMeta.reset(&__pAudioMeta);
1615 val = audio_meta_get_bit_rate(*(pAudioMeta.get()), &intValue);
1616 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1617 "audio_meta_get_bit_rate failed[%d].", val);
1619 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->bitrate = intValue;
1620 SysLog(NID_CNT, "META: bitrate[%d]", intValue);
1623 val = audio_meta_get_year(*(pAudioMeta.get()), &__pStrValue);
1624 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1625 "audio_meta_get_year failed[%d].", val);
1627 if (__pStrValue != null)
1629 pStrValue.reset(__pStrValue);
1631 String strYear(pStrValue.get());
1633 if (strYear.CompareTo(L"Unknown") != 0)
1635 r = Integer::Parse(strYear, intValue);
1638 // It is one of the metadata. If error occurs, skip it for other metadata.
1641 SysLog(NID_CNT, "META: releaseYear - invalid data[%ls]", strYear.GetPointer());
1644 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->releaseYear = intValue;
1645 SysLog(NID_CNT, "META: releaseYear[%d]", intValue);
1650 val = audio_meta_get_title(*(pAudioMeta.get()), &__pStrValue);
1651 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1652 "audio_meta_get_title failed[%d].", val);
1654 if (__pStrValue != null)
1656 pStrValue.reset(__pStrValue);
1658 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pTitle =
1659 new (nothrow) String(pStrValue.get());
1661 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
1665 val = audio_meta_get_album(*(pAudioMeta.get()), &__pStrValue);
1666 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1667 "audio_meta_get_album failed[%d].", val);
1669 if (__pStrValue != null)
1671 pStrValue.reset(__pStrValue);
1673 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pAlbumName =
1674 new (nothrow) String(pStrValue.get());
1676 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
1680 val = audio_meta_get_artist(*(pAudioMeta.get()), &__pStrValue);
1681 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1682 "audio_meta_get_artist failed[%d].", val);
1684 if (__pStrValue != null)
1686 pStrValue.reset(__pStrValue);
1688 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pArtist =
1689 new (nothrow) String(pStrValue.get());
1691 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
1695 val = audio_meta_get_composer(*(pAudioMeta.get()), &__pStrValue);
1696 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1697 "audio_meta_get_composer failed[%d].", val);
1699 if (__pStrValue != null)
1701 pStrValue.reset(__pStrValue);
1703 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pComposer =
1704 new (nothrow) String(pStrValue.get());
1706 SysLog(NID_CNT, "META: composer[%ls]", (String(pStrValue.get())).GetPointer());
1710 val = audio_meta_get_genre(*(pAudioMeta.get()), &__pStrValue);
1711 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1712 "audio_meta_get_genre failed[%d].", val);
1714 if (__pStrValue != null)
1716 pStrValue.reset(__pStrValue);
1718 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pGenre =
1719 new (nothrow) String(pStrValue.get());
1721 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
1725 val = audio_meta_get_copyright(*(pAudioMeta.get()), &__pStrValue);
1726 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1727 "audio_meta_get_copyright failed[%d].", val);
1729 if (__pStrValue != null)
1731 pStrValue.reset(__pStrValue);
1733 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pCopyright =
1734 new (nothrow) String(pStrValue.get());
1736 SysLog(NID_CNT, "META: copyright[%ls]", (String(pStrValue.get())).GetPointer());
1740 val = audio_meta_get_track_num(*(pAudioMeta.get()), &__pStrValue);
1741 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1742 "audio_meta_get_track_num failed[%d].", val);
1744 if (__pStrValue != null)
1746 pStrValue.reset(__pStrValue);
1748 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pTrackInfo
1749 = new (nothrow) String(pStrValue.get());
1751 SysLog(NID_CNT, "META: trackInfo[%ls]", (String(pStrValue.get())).GetPointer());
1755 val = audio_meta_get_duration(*(pAudioMeta.get()), &intValue);
1756 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1757 "audio_meta_get_duration failed[%d].", val);
1759 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->duration = intValue;
1760 SysLog(NID_CNT, "META: duration[%d]", intValue);
1763 else if (systemType == MEDIA_CONTENT_TYPE_VIDEO)
1765 video_meta_h __pVideoMeta = null;
1766 unique_ptr<video_meta_h, VideoMetaDeleter> pVideoMeta(null);
1768 pContentData->contentType = CONTENT_TYPE_VIDEO;
1769 SysLog(NID_CNT, "META: ContentType[%d]", pContentData->contentType);
1771 val = media_info_get_video(pMediaInfo, &__pVideoMeta);
1772 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1773 "media_info_get_video failed[%d].", val);
1775 pVideoMeta.reset(&__pVideoMeta);
1778 val = video_meta_get_width(*(pVideoMeta.get()), &intValue);
1779 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1780 "video_meta_get_width failed[%d].", val);
1782 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->width = intValue;
1783 SysLog(NID_CNT, "META: width[%d]", intValue);
1786 val = video_meta_get_height(*(pVideoMeta.get()), &intValue);
1787 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1788 "video_meta_get_height failed[%d].", val);
1790 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->height = intValue;
1791 SysLog(NID_CNT, "META: height[%d]", intValue);
1793 // Get from metadata extractor (framerate, audio bitrate, video bitrate)
1796 val = video_meta_get_artist(*(pVideoMeta.get()), &__pStrValue);
1797 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1798 "video_meta_get_artist failed[%d].", val);
1800 if (__pStrValue != null)
1802 pStrValue.reset(__pStrValue);
1804 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->pArtist
1805 = new (nothrow) String(pStrValue.get());
1807 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
1811 val = video_meta_get_genre(*(pVideoMeta.get()), &__pStrValue);
1812 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1813 "video_meta_get_genre failed[%d].", val);
1815 if (__pStrValue != null)
1817 pStrValue.reset(__pStrValue);
1819 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->pGenre
1820 = new (nothrow) String(pStrValue.get());
1822 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
1826 val = video_meta_get_title(*(pVideoMeta.get()), &__pStrValue);
1827 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1828 "video_meta_get_title failed[%d].", val);
1830 if (__pStrValue != null)
1832 pStrValue.reset(__pStrValue);
1834 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->pTitle
1835 = new (nothrow) String(pStrValue.get());
1837 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
1841 val = video_meta_get_album(*(pVideoMeta.get()), &__pStrValue);
1842 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1843 "video_meta_get_album failed[%d].", val);
1845 if (__pStrValue != null)
1847 pStrValue.reset(__pStrValue);
1849 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->pAlbumName
1850 = new (nothrow) String(pStrValue.get());
1852 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
1856 val = video_meta_get_duration(*(pVideoMeta.get()), &intValue);
1857 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1858 "video_meta_get_duration failed[%d].", val);
1860 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->duration = intValue;
1861 SysLog(NID_CNT, "META: duration[%d]", intValue);
1863 else if (systemType == SYSTEM_TYPE_OTHER)
1865 pContentData->contentType = CONTENT_TYPE_OTHER;
1866 SysLog(NID_CNT, "META: ContentType[%d]", pContentData->contentType);
1873 _ContentManagerImpl::VerifyHomeFilePathCompatibility(const String& contentPath) const
1875 if (!_AppInfo::IsOspCompat())
1877 if (contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0))
1879 SysLogException(NID_CNT, E_INVALID_ARG,
1880 "[E_INVALID_ARG] /Home/ or /HomeExt/ is not supported from Tizen 2.0.");
1883 if (!(contentPath.StartsWith(App::App::GetInstance()->GetAppRootPath(), 0) ||
1884 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
1886 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] The path is not supported.");
1892 SysTryReturn(NID_CNT, contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0),
1893 false, E_INVALID_ARG, "[E_INVALID_ARG] The path should start with /Home or /HomeExt.");
1900 _ContentManagerImpl::VerifyMediaFilePathCompatibility(const String& contentPath, bool checkVersion) const
1904 result r = E_SUCCESS;
1906 if (!_AppInfo::IsOspCompat())
1908 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0) || contentPath.StartsWith(OSP_MEDIA_MMC, 0))
1910 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] /Media or /Storagecard/Media is not supported.");
1913 if (!(contentPath.StartsWith(Environment::GetMediaPath(), 0) ||
1914 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
1916 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] This path is not supported.");
1923 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0))
1925 r = (const_cast<String*>(&contentPath))->Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
1926 SysTryReturn(NID_CNT, !IsFailed(r), false, E_INVALID_ARG, "[E_INVALID_ARG] Replace failed.");
1928 else if (contentPath.StartsWith(OSP_MEDIA_MMC, 0))
1930 r = (const_cast<String*>(&contentPath))->Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
1931 SysTryReturn(NID_CNT, !IsFailed(r), false, E_INVALID_ARG, "[E_INVALID_ARG] Replace failed.");
1935 // CreateContent(const ByteBuffer&, ...) and CreateContent (const Sring&, ...) can receive old path like /Media/.
1936 // but CreateContent(const ContentInfo&) always receive new path like /opt/media/ because ContentInfo class convert the path from /Media/ to /opt/media.
1939 SysLogException(NID_CNT, E_INVALID_ARG,
1940 "[E_INVALID_ARG] The path should start with /Home, /Media, or /Storagecard/Media.");
1950 _ContentManagerImpl::SetListener(IContentUpdateEventListener* pListener)
1952 __pListener = pListener;
1955 IContentUpdateEventListener*
1956 _ContentManagerImpl::GetListener(void) const