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.
25 #include <FBaseSysLog.h>
27 #include <FBaseInteger.h>
28 #include <FBaseByteBuffer.h>
29 #include <FCntContentManager.h>
30 #include <FCntImageContentInfo.h>
31 #include <FCntAudioContentInfo.h>
32 #include <FCntVideoContentInfo.h>
33 #include <FCntOtherContentInfo.h>
34 #include <FCntImageMetadata.h>
35 #include <FCntAudioMetadata.h>
36 #include <FCntVideoMetadata.h>
37 #include <FCntIContentScanListener.h>
38 #include <FCntIContentUpdateEventListener.h>
39 #include <FIoDirectory.h>
40 #include <FSysEnvironment.h>
41 #include <FCnt_ContentManagerImpl.h>
42 #include <FCnt_ContentManagerUtilImpl.h>
43 #include <FBase_StringConverter.h>
44 #include <FIo_FileImpl.h>
45 #include <FApp_AppInfo.h>
47 using namespace Tizen::Base;
48 using namespace Tizen::Base::Collection;
49 using namespace Tizen::Io;
50 using namespace Tizen::App;
51 using namespace Tizen::System;
54 namespace Tizen { namespace Content
57 static RequestId requestId = 0;
59 static const int SYSTEM_TYPE_IMAGE = 0;
60 static const int SYSTEM_TYPE_VIDEO = 1;
61 static const int SYSTEM_TYPE_SOUND = 2;
62 static const int SYSTEM_TYPE_MUSIC = 3;
63 static const int SYSTEM_TYPE_OTHER = 4;
64 static const double DEFAULT_COORDINATE = -200.0;
66 // For extern declaration in FCntTypes.h
67 const wchar_t OSP_HOME[] = L"/Home/";
68 const wchar_t OSP_HOME_EXT[] = L"/HomeExt/";
69 const wchar_t OSP_MEDIA_PHONE[] = L"/Media/";
70 const wchar_t OSP_MEDIA_MMC[] = L"/Storagecard/Media/";
73 ConvertError(int error)
79 case MEDIA_CONTENT_ERROR_NONE:
83 case MEDIA_CONTENT_ERROR_INVALID_PARAMETER:
87 case MEDIA_CONTENT_ERROR_OUT_OF_MEMORY:
91 case MEDIA_CONTENT_ERROR_DB_BUSY:
95 case MEDIA_CONTENT_ERROR_DB_FAILED:
108 OnScanCompleted(media_content_error_e error, void* user_data)
110 SysLog(NID_CNT, "OnScanCompleted callback method is called.");
113 result r = E_SUCCESS;
114 String scanPath(L"");
115 IContentScanListener* pListener = null;
117 unique_ptr< ScanResult > pScanResult;
119 SysTryLogCatch(NID_CNT, user_data != null, , "OnScanCompleted failed.");
121 pScanResult = unique_ptr< ScanResult >(static_cast< ScanResult* >(user_data));
123 SysTryLogCatch(NID_CNT, pScanResult != null, , "OnScanCompleted failed.");
124 SysTryLogCatch(NID_CNT, pScanResult->pScanListener != null, , "Listener is null. OnScanCompleted succeeded.");
126 scanPath = pScanResult->scanPath;
127 pListener = pScanResult->pScanListener;
128 reqId = pScanResult->requestId;
130 r = ConvertError(error);
132 pListener->OnContentScanCompleted(reqId, scanPath, r);
133 SysLog(NID_CNT, "OnContentScanCompleted fired.");
136 int val = media_content_disconnect();
137 SysTryLog(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, "The disconnection failed[%d].", val);
141 OnContentUpdateCompleted(media_content_error_e error, int pid, media_content_db_update_item_type_e update_item,
142 media_content_db_update_type_e update_type, media_content_type_e media_type, char* uuid, char* path, char* mime_type, void* user_data)
144 SysLog(NID_CNT, "OnContentUpdateCompleted callback method is called.");
146 result r = E_SUCCESS;
148 SysTryLogReturn(NID_CNT, user_data != null, , "OnContentUpdateCompleted failed.");
150 _ContentManagerImpl* pTempManagerImpl = static_cast< _ContentManagerImpl* >(user_data);
151 SysTryLogReturn(NID_CNT, pTempManagerImpl != null, , "pTempManagerImpl is null.");
153 IContentUpdateEventListener* pListener = pTempManagerImpl->GetListener();
154 SysTryLogReturn(NID_CNT, pListener != null, , "IContentUpdateEventListener is null.");
156 if (error != MEDIA_CONTENT_ERROR_NONE)
163 case MEDIA_ITEM_FILE:
165 ContentType contentType = CONTENT_TYPE_UNKNOWN;
169 case MEDIA_CONTENT_TYPE_IMAGE:
170 contentType = CONTENT_TYPE_IMAGE;
173 case MEDIA_CONTENT_TYPE_VIDEO:
174 contentType = CONTENT_TYPE_VIDEO;
177 case MEDIA_CONTENT_TYPE_SOUND:
179 case MEDIA_CONTENT_TYPE_MUSIC:
180 contentType = CONTENT_TYPE_AUDIO;
183 case MEDIA_CONTENT_TYPE_OTHERS:
184 contentType = CONTENT_TYPE_OTHER;
189 SysLog(NID_CNT, "media_type is invalid.");
196 result res = UuId::Parse(str, contentId);
197 SysTryLogReturn(NID_CNT, !IsFailed(res), , "Failed to parse to the content ID.");
201 case MEDIA_CONTENT_INSERT:
202 pListener->OnContentFileCreated(contentId, contentType, r);
205 case MEDIA_CONTENT_DELETE:
206 pListener->OnContentFileDeleted(contentId, contentType, r);
209 case MEDIA_CONTENT_UPDATE:
210 pListener->OnContentFileUpdated(contentId, contentType, r);
214 SysLog(NID_CNT, "update_type is invalid.");
220 case MEDIA_ITEM_DIRECTORY:
222 String directoryPath(path);
224 pListener->OnContentDirectoryScanCompleted(directoryPath, r);
229 SysLog(NID_CNT, "update_item is invalid.");
233 SysLog(NID_CNT, "Fire the OnContentUpdateCompleted method.");
236 _ContentManagerImpl::_ContentManagerImpl(void)
238 , __isConnected(false)
244 _ContentManagerImpl::~_ContentManagerImpl(void)
250 val = media_content_unset_db_updated_cb();
251 SysLog(NID_CNT, "media_content_unset_db_updated_cb result[%d].", val);
256 val = media_content_disconnect();
257 SysLog(NID_CNT, "media_content_disconnect result[%d].", val);
259 __isConnected = false;
263 _ContentManagerImpl::GetInstance(ContentManager& contentManager)
265 return contentManager.__pImpl;
268 const _ContentManagerImpl*
269 _ContentManagerImpl::GetInstance(const ContentManager& contentManager)
271 return contentManager.__pImpl;
277 // E_OUT_OF_MEMORY(in public)
280 _ContentManagerImpl::Construct(void)
282 SysAssertf(!__isConnected,
283 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
287 int val = media_content_connect();
288 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM,
289 "The connection failed[%d].", val);
291 SysLog(NID_CNT, "media_content_connect result[%d].", val);
293 __isConnected = true;
305 // E_PRIVILEGE_DENIED(in public)
309 _ContentManagerImpl::CreateContent(const ContentInfo& contentInfo)
311 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
315 // Get common data from ContentInfo class
316 ContentInfo::_ContentData* pContentData = (const_cast <ContentInfo*>(&contentInfo))->GetContentData();
317 SysTryReturn(NID_CNT, pContentData != null, UuId::GetInvalidUuId(), E_INVALID_ARG,
318 "[E_INVALID_ARG] pContentData is null.");
320 SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(pContentData->contentPath, true), UuId::GetInvalidUuId(),
321 E_INVALID_ARG, "[E_INVALID_ARG] The contentPath is not compatible.");
322 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(pContentData->contentPath), UuId::GetInvalidUuId(), E_FILE_NOT_FOUND,
323 "[E_FILE_NOT_FOUND] The file corresponding to contentInfo could not be found.");
324 SysTryReturn(NID_CNT, pContentData->contentId == UuId::GetInvalidUuId(), UuId::GetInvalidUuId(),
325 E_INVALID_ARG, "[E_INVALID_ARG] The contentId is not empty.");
327 // Compare the type of input parameter and system
328 ContentType inputType = pContentData->contentType;
329 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(pContentData->contentPath, true);
333 if (inputType != sysType)
335 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
337 SysLogException(NID_CNT, E_INVALID_ARG,
338 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
339 return UuId::GetInvalidUuId();
343 // Save data to database with contentPath.
344 unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(pContentData->contentPath));
345 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
346 "[E_OUT_OF_MEMORY] The memory is insufficient.");
348 media_info_h tempMediaInfo = null;
349 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
351 // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
352 int val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
353 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
354 "The registration to database failed[%d].", val);
356 pMediaInfo.reset(tempMediaInfo);
358 // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
359 ContentId contentId = SaveDataToDatabase(pMediaInfo.get(), pContentData);
360 result r = GetLastResult();
361 SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
362 "[%s] The registration to database failed.", GetErrorMessage(r));
367 // There are two steps(insert and update) for content registration.
368 // If the update failed after inserting, the inserted data SHOULD be deleted from here.
369 val = media_info_delete_from_db(pStr.get());
370 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
372 return UuId::GetInvalidUuId();
379 // E_FILE_ALREADY_EXIST
386 // E_PRIVILEGE_DENIED(in public)
389 _ContentManagerImpl::CreateContent(const ByteBuffer& byteBuffer, const String& destinationPath,
390 const ContentInfo* pContentInfo)
392 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
396 // Check parameters(for length)
397 SysTryReturn(NID_CNT, byteBuffer.GetRemaining() > 0, UuId::GetInvalidUuId(), E_INVALID_ARG,
398 "[E_INVALID_ARG] byteBuffer is invalid.");
400 // Check parameters(for path compatibility)
401 SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(destinationPath, false), UuId::GetInvalidUuId(),
402 E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", destinationPath.GetPointer());
403 SysTryReturn(NID_CNT, !_FileImpl::IsFileExist(destinationPath), UuId::GetInvalidUuId(), E_FILE_ALREADY_EXIST,
404 "[E_FILE_ALREADY_EXIST] The specified file already exists.");
406 // Create a file with bytebuffer
407 unique_ptr<File> pFile(new (nothrow) File);
408 SysTryReturn(NID_CNT, pFile != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
409 "[E_OUT_OF_MEMORY] The memory is insufficient.");
411 // 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
412 result r = pFile->Construct(destinationPath, L"w+");
413 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r,
414 "[%s] The destination file can not be created.", GetErrorMessage(r));
416 _FileImpl* pFileImpl = _FileImpl::GetInstance(*pFile);
417 SysTryReturn(NID_CNT, pFileImpl != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
418 "[E_OUT_OF_MEMORY] The memory is insufficient.");
420 // Exception : E_SUCCESS, E_INVALID_ARG, E_ILLEGAL_ACCESS, E_STORAGE_FULL, E_IO
421 r = pFileImpl->Write(byteBuffer);
422 SysTryReturn(NID_CNT, !(IsFailed(r)), UuId::GetInvalidUuId(), r,
423 "[%s] The data can not be written in the destination file.", GetErrorMessage(r));
425 // for release file pointer
426 delete pFile.release();
430 ContentInfo::_ContentData contentData;
431 ContentInfo::_ContentData* pContentData = null;
432 media_info_h tempMediaInfo = null;
433 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
434 unique_ptr<char[]> pStr(null);
436 if (pContentInfo != null)
438 pContentData = (const_cast <ContentInfo*>(pContentInfo))->GetContentData();
439 SysTryCatch(NID_CNT, pContentData != null, , E_INVALID_ARG, "[E_INVALID_ARG] GetContentData failed.");
441 SysTryCatch(NID_CNT, pContentData->contentId == UuId::GetInvalidUuId(), , E_INVALID_ARG,
442 "[E_INVALID_ARG] The content already exists in database.");
444 // Compare the type of input parameter and system
445 // CheckContentType() need actual file. so it should be checked after creating the file.
446 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
447 ContentType inputType = pContentData->contentType;
451 if (inputType != sysType)
453 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
455 SysLogException(NID_CNT, E_INVALID_ARG,
456 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
461 // Sets the content path
462 (pContentData->contentPath).Clear();
463 pContentData->contentPath = destinationPath;
467 // Set the content path
468 contentData.contentPath = destinationPath;
470 pContentData = &contentData;
473 // Register the content to database directly.
474 pStr.reset(_StringConverter::CopyToCharArrayN(destinationPath));
475 SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
477 val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
478 SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
479 "media_info_insert_to_db failed[%d].", val);
481 pMediaInfo.reset(tempMediaInfo);
483 // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
484 contentId = SaveDataToDatabase(pMediaInfo.get(), pContentData);
486 SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
487 "[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
492 result saveResult = GetLastResult();
494 // If the destination file is made by this method, it should be deleted when error occurs.
495 r = _FileImpl::Remove(destinationPath);
496 SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
498 if (pMediaInfo != null)
500 val = media_info_delete_from_db(pStr.get());
501 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
504 SetLastResult(saveResult);
505 return UuId::GetInvalidUuId();
513 // E_FILE_ALREADY_EXIST
520 // E_PRIVILEGE_DENIED(in public)
523 _ContentManagerImpl::CreateContent(const String& sourcePath, const String& destinationPath, bool deleteSource,
524 const ContentInfo* pContentInfo)
526 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
530 // Check parameters(for type)
531 SysTryReturn(NID_CNT, _FileImpl::GetFileExtension(sourcePath) == _FileImpl::GetFileExtension(destinationPath),
532 UuId::GetInvalidUuId(), E_INVALID_ARG, "[E_INVALID_ARG] There is a mismatch between the type of source and dest path.");
534 // Check parameters(for path compatibility)
535 SysTryReturn(NID_CNT, VerifyHomeFilePathCompatibility(sourcePath), UuId::GetInvalidUuId(), E_INVALID_ARG,
536 "[E_INVALID_ARG] %ls is not compatible.", sourcePath.GetPointer());
537 SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(destinationPath, false), UuId::GetInvalidUuId(),
538 E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", destinationPath.GetPointer());
540 result r = E_SUCCESS;
543 if (deleteSource) // move
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::Move(sourcePath, destinationPath);
547 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Moving the file failed.", GetErrorMessage(r));
551 // 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
552 r = _FileImpl::Copy(sourcePath, destinationPath, true);
553 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Copying the file failed.", GetErrorMessage(r));
560 ContentInfo::_ContentData contentData;
561 ContentInfo::_ContentData* pContentData = null;
562 media_info_h tempMediaInfo = null;
563 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
564 unique_ptr<char[]> pStr(null);
566 if (pContentInfo != null)
568 pContentData = (const_cast <ContentInfo*>(pContentInfo))->GetContentData();
569 SysTryCatch(NID_CNT, pContentData != null, , E_INVALID_ARG, "[E_INVALID_ARG] GetContentData failed.");
571 SysTryCatch(NID_CNT, pContentData->contentId == UuId::GetInvalidUuId(), , E_INVALID_ARG,
572 "[E_INVALID_ARG] The content already exists in database.");
574 // Compare the type of input parameter and system
575 // CheckContentType() need actual file. so it should be checked after creating the file.
576 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
577 ContentType inputType = pContentData->contentType;
581 if (inputType != sysType)
583 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
585 SysLogException(NID_CNT, E_INVALID_ARG,
586 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
591 // Set the content path
592 (pContentData->contentPath).Clear();
593 pContentData->contentPath = destinationPath;
597 // Set the content path
598 contentData.contentPath = destinationPath;
600 pContentData = &contentData;
603 pStr.reset(_StringConverter::CopyToCharArrayN(destinationPath));
604 SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
606 val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
607 SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
608 "media_info_insert_to_db failed[%d].", val);
610 pMediaInfo.reset(tempMediaInfo);
612 contentId = SaveDataToDatabase(pMediaInfo.get(), pContentData);
614 SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
615 "[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
620 result saveResult = GetLastResult();
624 r = _FileImpl::Remove(destinationPath);
625 SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
629 r = _FileImpl::Move(destinationPath, sourcePath);
630 SysLog(NID_CNT, "Move[%s].", GetErrorMessage(r));
633 if (pMediaInfo != null)
635 val = media_info_delete_from_db(pStr.get());
636 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
639 SetLastResult(saveResult);
640 return UuId::GetInvalidUuId();
650 // E_PRIVILEGE_DENIED(in public)
653 _ContentManagerImpl::GetContentInfoN(const ContentId& contentId) const
655 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
659 SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), null, E_INVALID_ARG,
660 "[E_INVALID_ARG] The contentId is invalid.");
662 unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(contentId.ToString()));
663 SysTryReturn(NID_CNT, pStr != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
665 media_info_h tempMediaInfo = null;
666 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
667 int val = media_info_get_media_from_db(pStr.get(), &tempMediaInfo);
668 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
669 "media_info_get_media_from_db failed[%d].", val);
671 pMediaInfo.reset(tempMediaInfo);
673 media_content_type_e systemType = MEDIA_CONTENT_TYPE_IMAGE;
674 val = media_info_get_media_type(pMediaInfo.get(), &systemType);
675 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
676 "media_info_get_media_type failed[%d].", val);
678 char* __pFilePath = null;
679 val = media_info_get_file_path(pMediaInfo.get(), &__pFilePath);
680 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
681 "media_info_get_file_path failed[%d].", val);
683 unique_ptr<char, CharDeleter> pFilePath(__pFilePath);
685 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(String(pFilePath.get())), null, E_FILE_NOT_FOUND,
686 "[E_FILE_NOT_FOUND] The file corresponding to contentId could not be found.");
688 result r = E_SUCCESS;
690 if (systemType == SYSTEM_TYPE_IMAGE)
692 unique_ptr<ImageContentInfo> pImageContentInfo(new (nothrow) ImageContentInfo);
693 SysTryReturn(NID_CNT, pImageContentInfo != null, null, E_OUT_OF_MEMORY,
694 "[E_OUT_OF_MEMORY] The memory is insufficient.");
697 ContentInfo::_ContentData* pContentData = pImageContentInfo->GetContentData();
698 SysTryReturn(NID_CNT, pContentData != null, null, E_OUT_OF_MEMORY,
699 "[E_OUT_OF_MEMORY] The memory is insufficient.");
701 // Get image metadata
702 ImageContentInfo::_ImageContentData* pImageContentData = pImageContentInfo->GetImageContentData();
703 SysTryReturn(NID_CNT, pImageContentData != null, null, E_OUT_OF_MEMORY,
704 "[E_OUT_OF_MEMORY] The memory is insufficient.");
707 // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
708 r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, pImageContentData);
709 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
711 return pImageContentInfo.release();
713 else if (systemType == SYSTEM_TYPE_SOUND || systemType == SYSTEM_TYPE_MUSIC)
715 unique_ptr<AudioContentInfo> pAudioContentInfo(new (nothrow) AudioContentInfo);
716 SysTryReturn(NID_CNT, pAudioContentInfo != null, null, E_OUT_OF_MEMORY,
717 "[E_OUT_OF_MEMORY] The memory is insufficient.");
719 ContentInfo::_ContentData* pContentData = pAudioContentInfo->GetContentData();
720 SysTryReturn(NID_CNT, pContentData != null, null, E_OUT_OF_MEMORY,
721 "[E_OUT_OF_MEMORY] The memory is insufficient.");
723 AudioContentInfo::_AudioContentData* pAudioContentData = pAudioContentInfo->GetAudioContentData();
724 SysTryReturn(NID_CNT, pAudioContentData != null, null, E_OUT_OF_MEMORY,
725 "[E_OUT_OF_MEMORY] The memory is insufficient.");
727 r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, pAudioContentData);
728 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
730 return pAudioContentInfo.release();
732 else if (systemType == SYSTEM_TYPE_VIDEO)
734 unique_ptr<VideoContentInfo> pVideoContentInfo(new (nothrow) VideoContentInfo);
735 SysTryReturn(NID_CNT, pVideoContentInfo != null, null, E_OUT_OF_MEMORY,
736 "[E_OUT_OF_MEMORY] The memory is insufficient.");
738 ContentInfo::_ContentData* pContentData = pVideoContentInfo->GetContentData();
739 SysTryReturn(NID_CNT, pContentData != null, null, E_OUT_OF_MEMORY,
740 "[E_OUT_OF_MEMORY] The memory is insufficient.");
742 VideoContentInfo::_VideoContentData* pVideoContentData = pVideoContentInfo->GetVideoContentData();
743 SysTryReturn(NID_CNT, pVideoContentData != null, null, E_OUT_OF_MEMORY,
744 "[E_OUT_OF_MEMORY] The memory is insufficient.");
746 r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, pVideoContentData);
747 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
749 return pVideoContentInfo.release();
751 else if (systemType == SYSTEM_TYPE_OTHER)
753 unique_ptr<OtherContentInfo> pOtherContentInfo(new (nothrow) OtherContentInfo);
754 SysTryReturn(NID_CNT, pOtherContentInfo != null, null, E_OUT_OF_MEMORY,
755 "[E_OUT_OF_MEMORY] The memory is insufficient.");
757 ContentInfo::_ContentData* pContentData = pOtherContentInfo->GetContentData();
758 SysTryReturn(NID_CNT, pContentData != null, null, E_OUT_OF_MEMORY,
759 "[E_OUT_OF_MEMORY] The memory is insufficient.");
761 r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, null);
762 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
764 return pOtherContentInfo.release();
768 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] Unsupported type");
780 // E_PRIVILEGE_DENIED(in public)
783 _ContentManagerImpl::UpdateContent(const ContentInfo& contentInfo)
785 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
789 ContentId contentId = contentInfo.GetContentId();
790 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, "The content id is invalid.");
791 SysTryReturnResult(NID_CNT, _FileImpl::IsFileExist(contentInfo.GetContentPath()), E_FILE_NOT_FOUND,
792 "The file corresponding to contentInfo could not be found.");
794 // Get common data from ContentInfo class
795 ContentInfo::_ContentData* pContentData = (const_cast <ContentInfo*>(&contentInfo))->GetContentData();
796 SysTryReturnResult(NID_CNT, pContentData != null, E_INVALID_ARG, "pContentData is null.");
798 // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SYSTEM, E_SERVICE_BUSY
799 result r = this->UpdateDataToDatabase(pContentData);
800 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "UpdateDataToDatabase failed.");
812 // E_PRIVILEGE_DENIED(in public)
813 // - E_ILLEGAL_ACCESS
816 _ContentManagerImpl::DeleteContent(const ContentId& contentId)
818 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
822 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, "The contentId is invalid.");
824 unique_ptr<char[]> pContentId(_StringConverter::CopyToCharArrayN(contentId.ToString()));
825 SysTryReturnResult(NID_CNT, pContentId != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
827 result r = E_SUCCESS;
829 media_info_h tempMediaInfo = null;
830 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
832 val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
833 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
834 "media_info_get_media_from_db failed[%d].", val);
836 pMediaInfo.reset(tempMediaInfo);
838 char* __pContentPath = null;
840 val = media_info_get_file_path(pMediaInfo.get(), &__pContentPath);
841 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
842 "media_info_get_file_path failed[%d].", val);
844 unique_ptr<char, CharDeleter> pContentPath(__pContentPath);
846 String contentPath = String(pContentPath.get());
847 SysTryReturnResult(NID_CNT, _FileImpl::IsFileExist(contentPath), E_FILE_NOT_FOUND,
848 "The file corresponding to contentId could not be found.");
850 val = media_info_delete_from_db(pContentId.get());
851 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
852 "media_info_delete_From_db failed[%d].", val);
854 r = _FileImpl::Remove(contentPath);
855 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The file is not deleted.");
862 // E_OBJ_ALREADY_EXIST
866 _ContentManagerImpl::AddContentUpdateEventListener(IContentUpdateEventListener& listener)
870 SysTryReturnResult(NID_CNT, GetListener() == null, E_OBJ_ALREADY_EXIST, "IContentUpdateEventListener is already set.");
872 SetListener(&listener);
874 int val = media_content_set_db_updated_cb(OnContentUpdateCompleted, this);
875 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "media_content_set_db_updated_cb failed[%d].", val);
886 _ContentManagerImpl::RemoveContentUpdateEventListener(IContentUpdateEventListener& listener)
890 SysTryReturnResult(NID_CNT, GetListener() == &listener, E_OBJ_NOT_FOUND, "The input listener is not equal to the registered listener.");
892 int val = media_content_unset_db_updated_cb();
893 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "media_content_unset_db_updated_cb failed[%d].", val);
905 // E_PRIVILEGE_DENIED(in public)
908 _ContentManagerImpl::ScanFile(const Tizen::Base::String& contentPath)
912 SysSecureLog(NID_CNT, "The scan path is [%ls].", contentPath.GetPointer());
914 unique_ptr<char[]> pContentPath(_StringConverter::CopyToCharArrayN(contentPath));
915 SysTryReturnResult(NID_CNT, pContentPath, E_SYSTEM, "pContentPath is NULL.");
917 int val = media_content_connect();
918 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The connection failed[%d].", val);
920 val = media_content_scan_file(pContentPath.get());
921 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val), "media_content_scan_file failed[%d].", val);
923 val = media_content_disconnect();
924 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The disconnection failed[%d].", val);
934 // E_PRIVILEGE_DENIED(in public)
937 _ContentManagerImpl::ScanDirectory(const Tizen::Base::String& directoryPath, bool recursive, IContentScanListener* pListener, RequestId& reqId)
941 SysLog(NID_CNT, "The scan path is [%ls].", directoryPath.GetPointer());
943 unique_ptr<char[]> pDirPath(_StringConverter::CopyToCharArrayN(directoryPath));
944 SysTryReturnResult(NID_CNT, pDirPath, E_SYSTEM, "pDirPath is NULL.");
946 int val = media_content_connect();
947 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The connection failed[%d].", val);
949 unique_ptr< ScanResult > pScanResult(new (nothrow) ScanResult);
950 SysTryReturnResult(NID_CNT, pScanResult != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
954 pScanResult->scanPath = directoryPath;
955 pScanResult->pScanListener = pListener;
956 pScanResult->requestId = reqId;
958 val = media_content_scan_folder(pDirPath.get(), recursive, OnScanCompleted, pScanResult.release());
959 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val), "media_content_scan_folder failed[%d].", val);
972 _ContentManagerImpl::UpdateDataToDatabase(const ContentInfo::_ContentData* pContentData) const
976 SysTryReturnResult(NID_CNT, pContentData != null, E_INVALID_ARG, "pContentData is null.");
978 media_info_h tempMediaInfo = null;
979 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
980 unique_ptr<char[]> pContentId(_StringConverter::CopyToCharArrayN((pContentData->contentId).ToString()));
981 SysTryReturnResult(NID_CNT, pContentId != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
983 int val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
984 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
985 "media_info_get_media_from_db failed[%d].", val);
987 pMediaInfo.reset(tempMediaInfo);
989 result r = E_SUCCESS;
990 unique_ptr<char[]> pValue(null);
992 if (pContentData->pAuthor != null)
994 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pAuthor)));
995 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
997 val = media_info_set_author(pMediaInfo.get(), pValue.get());
998 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
999 "media_info_set_author failed[%d].", val);
1001 if (pContentData->pCategory != null)
1003 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pCategory)));
1004 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1006 val = media_info_set_category(pMediaInfo.get(), pValue.get());
1007 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1008 "media_info_set_category failed[%d].", val);
1010 if (pContentData->pContentName != null)
1012 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pContentName)));
1013 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1015 val = media_info_set_content_name(pMediaInfo.get(), pValue.get());
1016 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1017 "media_info_set_content_name failed[%d].", val);
1019 if (pContentData->pDescription != null)
1021 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pDescription)));
1022 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1024 val = media_info_set_description(pMediaInfo.get(), pValue.get());
1025 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1026 "media_info_set_description failed[%d].", val);
1028 if (pContentData->pKeyword != null)
1030 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pKeyword)));
1031 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1033 val = media_info_set_keyword(pMediaInfo.get(), pValue.get());
1034 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1035 "media_info_set_keyword failed[%d].", val);
1037 if (pContentData->pLocationTag != null)
1039 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pLocationTag)));
1040 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1042 val = media_info_set_location_tag(pMediaInfo.get(), pValue.get());
1043 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1044 "media_info_set_location_tag failed[%d].", val);
1046 if (pContentData->pProvider != null)
1048 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pProvider)));
1049 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1051 val = media_info_set_provider(pMediaInfo.get(), pValue.get());
1052 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1053 "media_info_set_provider failed[%d].", val);
1055 if (pContentData->pRating != null)
1057 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pRating)));
1058 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1060 val = media_info_set_age_rating(pMediaInfo.get(), pValue.get());
1061 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1062 "media_info_set_age_rating failed[%d].", val);
1064 if (Double::Compare(pContentData->latitude, DEFAULT_COORDINATE) != 0 &&
1065 Double::Compare(pContentData->longitude, DEFAULT_COORDINATE) != 0)
1067 val = media_info_set_latitude(pMediaInfo.get(), pContentData->latitude);
1068 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1069 "media_info_set_latitude failed[%d].", val);
1071 val = media_info_set_longitude(pMediaInfo.get(), pContentData->longitude);
1072 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1073 "media_info_set_longitude failed[%d].", val);
1075 if (Double::Compare(pContentData->altitude, DEFAULT_COORDINATE) != 0)
1077 val = media_info_set_altitude(pMediaInfo.get(), pContentData->altitude);
1078 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1079 "media_info_set_altitude failed[%d].", val);
1083 val = media_info_update_to_db(pMediaInfo.get());
1084 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1085 "media_info_update_to_db failed[%d].", val);
1098 _ContentManagerImpl::SaveDataToDatabase(const media_info_h pMediaInfo,
1099 ContentInfo::_ContentData* pContentData) const
1103 SysTryReturn(NID_CNT, pContentData != null, UuId::GetInvalidUuId(), E_INVALID_ARG,
1104 "[E_INVALID_ARG] pContentData is null.");
1106 String mimeType(L"");
1107 String extension = _FileImpl::GetFileExtension(pContentData->contentPath);
1108 result r = GetLastResult();
1113 SysLog(NID_CNT, "[%s] Failed to perform GetFileExtension operation.", GetErrorMessage(r));
1115 unique_ptr<char[]> pTempPath(_StringConverter::CopyToCharArrayN(pContentData->contentPath));
1116 SysTryReturn(NID_CNT, pTempPath != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1117 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1119 char tempType[255] = {0, };
1120 int ret = aul_get_mime_from_file(pTempPath.get(), tempType, sizeof(tempType));
1121 SysTryReturn(NID_CNT, ret == AUL_R_OK, UuId::GetInvalidUuId(), E_INVALID_ARG,
1122 "[E_INVALID_ARG] Failed to perform aul_get_mime_from_file operation.");
1124 r = mimeType.Append(tempType);
1125 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1126 "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
1130 // If the content format is JPG and it has GPS data, it will be saved in database automatically.
1131 if (extension == L"jpg" || extension == L"jpeg" || extension == L"JPG" || extension == L"JPEG" || mimeType.Contains(L"jpeg"))
1133 SysLog(NID_CNT, "The format of content is jpg.");
1135 ImageMetadata* pImageMetadata = _ContentManagerUtilImpl::GetImageMetaN(pContentData->contentPath, true);
1136 if (pImageMetadata != null)
1138 pContentData->latitude = pImageMetadata->GetLatitude();
1139 pContentData->longitude = pImageMetadata->GetLongitude();
1141 delete pImageMetadata;
1148 unique_ptr<char[]> pStr(null);
1150 if (pContentData->pAuthor != null)
1152 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pAuthor)));
1153 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1154 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1156 val = media_info_set_author(pMediaInfo, pStr.get());
1157 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1158 "media_info_set_author failed[%d].", val);
1160 if (pContentData->pCategory != null)
1162 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pCategory)));
1163 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1164 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1166 val = media_info_set_category(pMediaInfo, pStr.get());
1167 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1168 "media_info_set_category failed[%d].", val);
1170 if (pContentData->pContentName != null)
1172 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pContentName)));
1173 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1174 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1176 val = media_info_set_content_name(pMediaInfo, pStr.get());
1177 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1178 "media_info_set_content_name failed[%d].", val);
1180 if (pContentData->pDescription != null)
1182 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pDescription)));
1183 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1184 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1186 val = media_info_set_description(pMediaInfo, pStr.get());
1187 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1188 "media_info_set_description failed[%d].", val);
1190 if (pContentData->pKeyword != null)
1192 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pKeyword)));
1193 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1194 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1196 val = media_info_set_keyword(pMediaInfo, pStr.get());
1197 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1198 "media_info_set_keyword failed[%d].", val);
1200 if (pContentData->pLocationTag != null)
1202 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pLocationTag)));
1203 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1204 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1206 val = media_info_set_location_tag(pMediaInfo, pStr.get());
1207 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1208 "media_info_set_location_tag failed[%d].", val);
1210 if (pContentData->pProvider != null)
1212 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pProvider)));
1213 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1214 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1216 val = media_info_set_provider(pMediaInfo, pStr.get());
1217 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1218 "media_info_set_provider failed[%d].", val);
1220 if (pContentData->pRating != null)
1222 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pRating)));
1223 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1224 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1226 val = media_info_set_age_rating(pMediaInfo, pStr.get());
1227 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1228 "media_info_set_age_rating failed[%d].", val);
1230 if (Double::Compare(pContentData->latitude, DEFAULT_COORDINATE) != 0 &&
1231 Double::Compare(pContentData->longitude, DEFAULT_COORDINATE) != 0)
1233 val = media_info_set_latitude(pMediaInfo, pContentData->latitude);
1234 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1235 "media_info_set_latitude failed[%d].", val);
1237 val = media_info_set_longitude(pMediaInfo, pContentData->longitude);
1238 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1239 "media_info_set_longitude failed[%d].", val);
1241 if (Double::Compare(pContentData->altitude, DEFAULT_COORDINATE) != 0)
1243 val = media_info_set_altitude(pMediaInfo, pContentData->altitude);
1244 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1245 "media_info_set_altitude failed[%d].", val);
1249 val = media_info_update_to_db(pMediaInfo);
1250 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1251 "media_info_update_to_db failed[%d].", val);
1253 char* __pMediaId = null;
1254 unique_ptr<char, CharDeleter> pMediaId(null);
1256 val = media_info_get_media_id(pMediaInfo, &__pMediaId);
1257 if (__pMediaId != null)
1259 pMediaId.reset(__pMediaId);
1263 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1264 "media_info_get_media_id failed[%d].", val);
1267 String contentId(pMediaId.get());
1269 r = UuId::Parse(contentId, pContentData->contentId);
1270 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_INVALID_ARG,
1271 "[E_INVALID_ARG] UuId::Parse failed.");
1273 return pContentData->contentId;
1284 _ContentManagerImpl::MakeContentInfo(const media_info_h pMediaInfo, ContentInfo::_ContentData* pContentData,
1285 int systemType, void* pMetadata) const
1289 if (systemType != SYSTEM_TYPE_OTHER)
1291 SysTryReturnResult(NID_CNT, pMediaInfo != null && pContentData != null && pMetadata != null, E_INVALID_ARG,
1292 "The specified parameter is invalid.");
1294 else // There is no metadata in Other type
1296 SysTryReturnResult(NID_CNT, pMediaInfo != null && pContentData != null, E_INVALID_ARG,
1297 "The specified parameter is invalid.");
1300 result r = E_SUCCESS;
1301 char* __pStrValue = null;
1302 unique_ptr<char, CharDeleter> pStrValue(null);
1305 int val = media_info_get_media_id(pMediaInfo, &__pStrValue);
1306 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1307 "media_info_get_media_id failed[%d].", val);
1309 if (__pStrValue != null)
1311 pStrValue.reset(__pStrValue);
1313 String strContentId(pStrValue.get());
1315 r = UuId::Parse(strContentId, pContentData->contentId);
1316 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The content id can not be parsed.");
1318 SysLog(NID_CNT, "INFO: contentId[%ls]", strContentId.GetPointer());
1322 val = media_info_get_file_path(pMediaInfo, &__pStrValue);
1323 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1324 "media_info_get_file_path failed[%d].", val);
1326 if (__pStrValue != null)
1328 pStrValue.reset(__pStrValue);
1330 String strFilePath(pStrValue.get());
1332 // If the api version is 2.0, the content path has to be changed.
1333 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
1335 if (strFilePath.StartsWith(Environment::GetMediaPath(), 0))
1337 r = strFilePath.Replace(Environment::GetMediaPath(), OSP_MEDIA_PHONE);
1338 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The content path is not changed.");
1340 else if (strFilePath.StartsWith(Environment::GetExternalStoragePath(), 0))
1342 r = strFilePath.Replace(Environment::GetExternalStoragePath(), OSP_MEDIA_MMC);
1343 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Replace failed.");
1347 SysLogException(NID_CNT, E_INVALID_ARG,
1348 "[E_INVALID_ARG] The content path is not supported.");
1349 return E_INVALID_ARG;
1353 pContentData->contentPath = strFilePath;
1355 SysSecureLog(NID_CNT, "INFO: contentPath[%ls]", strFilePath.GetPointer());
1359 val = media_info_get_mime_type(pMediaInfo, &__pStrValue);
1360 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1361 "media_info_get_mime_type failed[%d].", val);
1363 if (__pStrValue != null)
1365 pStrValue.reset(__pStrValue);
1367 pContentData->mimeType = pStrValue.get();
1369 SysLog(NID_CNT, "INFO: mimeType[%ls]", (pContentData->mimeType).GetPointer());
1373 unsigned long long longlongValue = 0;
1374 val = media_info_get_size(pMediaInfo, &longlongValue);
1375 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1376 "media_info_get_size failed[%d].", val);
1377 pContentData->contentSize = longlongValue;
1378 SysLog(NID_CNT, "INFO: contentSize[%llu]", longlongValue);
1381 media_content_storage_e storageType;
1382 val = media_info_get_storage_type(pMediaInfo, &storageType);
1383 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1384 "media_info_get_storage_type failed[%d].", val);
1385 pContentData->storageType = storageType;
1386 SysLog(NID_CNT, "INFO: storageType[%d]", storageType);
1389 val = media_info_is_drm(pMediaInfo, &(pContentData->isDrm));
1390 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1391 "media_info_is_drm failed[%d].", val);
1392 SysLog(NID_CNT, "INFO: isDrm[%d]", pContentData->isDrm);
1396 val = media_info_get_added_time(pMediaInfo, &time);
1397 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1398 "media_info_get_added_time failed[%d].", val);
1399 r = (pContentData->dateTime).SetValue(1970, 1, 1);
1400 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "SetValue failed.");
1401 r = (pContentData->dateTime).AddSeconds(time);
1402 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "AddSeconds failed.");
1403 SysLog(NID_CNT, "INFO: dateTime[%ls]", ((pContentData->dateTime).ToString()).GetPointer());
1406 val = media_info_get_thumbnail_path(pMediaInfo, &__pStrValue);
1407 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1408 "media_info_get_thumbnail_path failed[%d].", val);
1410 if (__pStrValue != null)
1412 pStrValue.reset(__pStrValue);
1414 pContentData->pThumbnailPath = new (nothrow) String(pStrValue.get());
1416 SysLog(NID_CNT, "INFO: thumbnailPath[%ls]", (*pContentData->pThumbnailPath).GetPointer());
1420 val = media_info_get_author(pMediaInfo, &__pStrValue);
1421 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1422 "media_info_get_author failed[%d].", val);
1424 if (__pStrValue != null)
1426 pStrValue.reset(__pStrValue);
1428 pContentData->pAuthor = new (nothrow) String(pStrValue.get());
1430 SysLog(NID_CNT, "INFO: author[%ls]", (*pContentData->pAuthor).GetPointer());
1434 val = media_info_get_category(pMediaInfo, &__pStrValue);
1435 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1436 "media_info_get_category failed[%d].", val);
1438 if (__pStrValue != null)
1440 pStrValue.reset(__pStrValue);
1442 pContentData->pCategory = new (nothrow) String(pStrValue.get());
1444 SysLog(NID_CNT, "INFO: category[%ls]", (*pContentData->pCategory).GetPointer());
1448 val = media_info_get_content_name(pMediaInfo, &__pStrValue);
1449 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1450 "media_info_get_content_name failed[%d].", val);
1452 if (__pStrValue != null)
1454 pStrValue.reset(__pStrValue);
1456 pContentData->pContentName = new (nothrow) String(pStrValue.get());
1458 SysSecureLog(NID_CNT, "INFO: contentName[%ls]", (*pContentData->pContentName).GetPointer());
1462 val = media_info_get_description(pMediaInfo, &__pStrValue);
1463 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1464 "media_info_get_description failed[%d].", val);
1466 if (__pStrValue != null)
1468 pStrValue.reset(__pStrValue);
1470 pContentData->pDescription = new (nothrow) String(pStrValue.get());
1472 SysLog(NID_CNT, "INFO: description[%ls]", (*pContentData->pDescription).GetPointer());
1476 val = media_info_get_keyword(pMediaInfo, &__pStrValue);
1477 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1478 "media_info_get_keyword failed[%d].", val);
1480 if (__pStrValue != null)
1482 pStrValue.reset(__pStrValue);
1484 pContentData->pKeyword = new (nothrow) String(pStrValue.get());
1486 SysLog(NID_CNT, "INFO: keyword[%ls]", (*pContentData->pKeyword).GetPointer());
1490 val = media_info_get_location_tag(pMediaInfo, &__pStrValue);
1491 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1492 "media_info_get_location_tag failed[%d].", val);
1494 if (__pStrValue != null)
1496 pStrValue.reset(__pStrValue);
1498 pContentData->pLocationTag = new (nothrow) String(pStrValue.get());
1500 SysSecureLog(NID_CNT, "INFO: locationTag[%ls]", (*pContentData->pLocationTag).GetPointer());
1504 val = media_info_get_provider(pMediaInfo, &__pStrValue);
1505 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1506 "media_info_get_provider failed[%d].", val);
1508 if (__pStrValue != null)
1510 pStrValue.reset(__pStrValue);
1512 pContentData->pProvider = new (nothrow) String(pStrValue.get());
1514 SysLog(NID_CNT, "INFO: provider[%ls]", (*pContentData->pProvider).GetPointer());
1518 val = media_info_get_age_rating(pMediaInfo, &__pStrValue);
1519 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1520 "media_info_get_age_rating failed[%d].", val);
1522 if (__pStrValue != null)
1524 pStrValue.reset(__pStrValue);
1526 pContentData->pRating = new (nothrow) String(pStrValue.get());
1528 SysLog(NID_CNT, "INFO: rating[%ls]", (*pContentData->pRating).GetPointer());
1532 double doubleValue = 0;
1533 val = media_info_get_latitude(pMediaInfo, &doubleValue);
1534 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1535 "media_info_get_latitude failed[%d].", val);
1537 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1539 pContentData->latitude = doubleValue;
1541 SysSecureLog(NID_CNT, "INFO: latitude[%f]", pContentData->latitude);
1543 val = media_info_get_longitude(pMediaInfo, &doubleValue);
1544 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1545 "media_info_get_longitude failed[%d].", val);
1547 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1549 pContentData->longitude = doubleValue;
1551 SysSecureLog(NID_CNT, "INFO: longitude[%f]", pContentData->longitude);
1553 val = media_info_get_altitude(pMediaInfo, &doubleValue);
1554 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1555 "media_info_get_altitude failed[%d].", val);
1557 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1559 pContentData->altitude = doubleValue;
1561 SysLog(NID_CNT, "INFO: altitude[%f]", pContentData->altitude);
1565 // contentType and metadata
1566 if (systemType == SYSTEM_TYPE_IMAGE)
1568 image_meta_h __pImageMeta = null;
1569 unique_ptr<image_meta_h, ImageMetaDeleter> pImageMeta(null);
1571 pContentData->contentType = CONTENT_TYPE_IMAGE;
1572 SysLog(NID_CNT, "META: ContentType[%d]", pContentData->contentType);
1574 val = media_info_get_image(pMediaInfo, &__pImageMeta);
1575 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1576 "media_info_get_image failed[%d].", val);
1578 pImageMeta.reset(&__pImageMeta);
1581 val = image_meta_get_width(*(pImageMeta.get()), &intValue);
1582 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1583 "image_meta_get_width failed[%d].", val);
1585 (static_cast<ImageContentInfo::_ImageContentData*>(pMetadata))->width = intValue;
1586 SysLog(NID_CNT, "META: width[%d]", intValue);
1589 val = image_meta_get_height(*(pImageMeta.get()), &intValue);
1590 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1591 "image_meta_get_height failed[%d].", val);
1593 (static_cast<ImageContentInfo::_ImageContentData*>(pMetadata))->height = intValue;
1594 SysLog(NID_CNT, "META: height[%d]", intValue);
1597 media_content_orientation_e orientation;
1598 val = image_meta_get_orientation(*(pImageMeta.get()), &orientation);
1599 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1600 "image_meta_get_orientation failed[%d].", val);
1602 (static_cast<ImageContentInfo::_ImageContentData*>(pMetadata))->orientationType =
1603 static_cast<ImageOrientationType>(orientation);
1604 SysLog(NID_CNT, "META: orientation[%d]", orientation);
1607 val = media_info_get_display_name(pMediaInfo, &__pStrValue);
1608 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1609 "media_info_get_display_name failed[%d].", val);
1611 if (__pStrValue != null)
1613 pStrValue.reset(__pStrValue);
1617 String strTitle(pStrValue.get());
1619 r = strTitle.LastIndexOf(L'.', strTitle.GetLength() - 1, pos);
1622 r = strTitle.SubString(0, pos, fileName);
1623 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The title is invalid.");
1627 // Without extension
1629 fileName = strTitle;
1632 (static_cast<ImageContentInfo::_ImageContentData*>(pMetadata))->title = fileName;
1634 SysLog(NID_CNT, "META: title[%ls]", fileName.GetPointer());
1637 else if (systemType == SYSTEM_TYPE_SOUND || systemType == SYSTEM_TYPE_MUSIC)
1639 audio_meta_h __pAudioMeta = null;
1640 unique_ptr<audio_meta_h, AudioMetaDeleter> pAudioMeta(null);
1642 pContentData->contentType = CONTENT_TYPE_AUDIO;
1643 SysLog(NID_CNT, "META: ContentType[%d]", pContentData->contentType);
1645 val = media_info_get_audio(pMediaInfo, &__pAudioMeta);
1646 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1647 "media_info_get_audio failed[%d].", val);
1649 pAudioMeta.reset(&__pAudioMeta);
1652 val = audio_meta_get_bit_rate(*(pAudioMeta.get()), &intValue);
1653 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1654 "audio_meta_get_bit_rate failed[%d].", val);
1656 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->bitrate = intValue;
1657 SysLog(NID_CNT, "META: bitrate[%d]", intValue);
1660 val = audio_meta_get_year(*(pAudioMeta.get()), &__pStrValue);
1661 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1662 "audio_meta_get_year failed[%d].", val);
1664 if (__pStrValue != null)
1666 pStrValue.reset(__pStrValue);
1668 String strYear(pStrValue.get());
1670 if (strYear.CompareTo(L"Unknown") != 0)
1672 r = Integer::Parse(strYear, intValue);
1675 // It is one of the metadata. If error occurs, skip it for other metadata.
1678 SysLog(NID_CNT, "META: releaseYear - invalid data[%ls]", strYear.GetPointer());
1681 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->releaseYear = intValue;
1682 SysLog(NID_CNT, "META: releaseYear[%d]", intValue);
1687 val = audio_meta_get_title(*(pAudioMeta.get()), &__pStrValue);
1688 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1689 "audio_meta_get_title failed[%d].", val);
1691 if (__pStrValue != null)
1693 pStrValue.reset(__pStrValue);
1695 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pTitle =
1696 new (nothrow) String(pStrValue.get());
1698 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
1702 val = audio_meta_get_album(*(pAudioMeta.get()), &__pStrValue);
1703 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1704 "audio_meta_get_album failed[%d].", val);
1706 if (__pStrValue != null)
1708 pStrValue.reset(__pStrValue);
1710 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pAlbumName =
1711 new (nothrow) String(pStrValue.get());
1713 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
1717 val = audio_meta_get_artist(*(pAudioMeta.get()), &__pStrValue);
1718 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1719 "audio_meta_get_artist failed[%d].", val);
1721 if (__pStrValue != null)
1723 pStrValue.reset(__pStrValue);
1725 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pArtist =
1726 new (nothrow) String(pStrValue.get());
1728 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
1732 val = audio_meta_get_composer(*(pAudioMeta.get()), &__pStrValue);
1733 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1734 "audio_meta_get_composer failed[%d].", val);
1736 if (__pStrValue != null)
1738 pStrValue.reset(__pStrValue);
1740 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pComposer =
1741 new (nothrow) String(pStrValue.get());
1743 SysLog(NID_CNT, "META: composer[%ls]", (String(pStrValue.get())).GetPointer());
1747 val = audio_meta_get_genre(*(pAudioMeta.get()), &__pStrValue);
1748 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1749 "audio_meta_get_genre failed[%d].", val);
1751 if (__pStrValue != null)
1753 pStrValue.reset(__pStrValue);
1755 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pGenre =
1756 new (nothrow) String(pStrValue.get());
1758 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
1762 val = audio_meta_get_copyright(*(pAudioMeta.get()), &__pStrValue);
1763 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1764 "audio_meta_get_copyright failed[%d].", val);
1766 if (__pStrValue != null)
1768 pStrValue.reset(__pStrValue);
1770 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pCopyright =
1771 new (nothrow) String(pStrValue.get());
1773 SysLog(NID_CNT, "META: copyright[%ls]", (String(pStrValue.get())).GetPointer());
1777 val = audio_meta_get_track_num(*(pAudioMeta.get()), &__pStrValue);
1778 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1779 "audio_meta_get_track_num failed[%d].", val);
1781 if (__pStrValue != null)
1783 pStrValue.reset(__pStrValue);
1785 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pTrackInfo
1786 = new (nothrow) String(pStrValue.get());
1788 SysLog(NID_CNT, "META: trackInfo[%ls]", (String(pStrValue.get())).GetPointer());
1792 val = audio_meta_get_duration(*(pAudioMeta.get()), &intValue);
1793 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1794 "audio_meta_get_duration failed[%d].", val);
1796 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->duration = intValue;
1797 SysLog(NID_CNT, "META: duration[%d]", intValue);
1800 else if (systemType == MEDIA_CONTENT_TYPE_VIDEO)
1802 video_meta_h __pVideoMeta = null;
1803 unique_ptr<video_meta_h, VideoMetaDeleter> pVideoMeta(null);
1805 pContentData->contentType = CONTENT_TYPE_VIDEO;
1806 SysLog(NID_CNT, "META: ContentType[%d]", pContentData->contentType);
1808 val = media_info_get_video(pMediaInfo, &__pVideoMeta);
1809 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1810 "media_info_get_video failed[%d].", val);
1812 pVideoMeta.reset(&__pVideoMeta);
1815 val = video_meta_get_width(*(pVideoMeta.get()), &intValue);
1816 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1817 "video_meta_get_width failed[%d].", val);
1819 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->width = intValue;
1820 SysLog(NID_CNT, "META: width[%d]", intValue);
1823 val = video_meta_get_height(*(pVideoMeta.get()), &intValue);
1824 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1825 "video_meta_get_height failed[%d].", val);
1827 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->height = intValue;
1828 SysLog(NID_CNT, "META: height[%d]", intValue);
1830 // Get from metadata extractor (framerate, audio bitrate, video bitrate)
1833 val = video_meta_get_artist(*(pVideoMeta.get()), &__pStrValue);
1834 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1835 "video_meta_get_artist failed[%d].", val);
1837 if (__pStrValue != null)
1839 pStrValue.reset(__pStrValue);
1841 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->pArtist
1842 = new (nothrow) String(pStrValue.get());
1844 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
1848 val = video_meta_get_genre(*(pVideoMeta.get()), &__pStrValue);
1849 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1850 "video_meta_get_genre failed[%d].", val);
1852 if (__pStrValue != null)
1854 pStrValue.reset(__pStrValue);
1856 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->pGenre
1857 = new (nothrow) String(pStrValue.get());
1859 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
1863 val = video_meta_get_title(*(pVideoMeta.get()), &__pStrValue);
1864 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1865 "video_meta_get_title failed[%d].", val);
1867 if (__pStrValue != null)
1869 pStrValue.reset(__pStrValue);
1871 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->pTitle
1872 = new (nothrow) String(pStrValue.get());
1874 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
1878 val = video_meta_get_album(*(pVideoMeta.get()), &__pStrValue);
1879 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1880 "video_meta_get_album failed[%d].", val);
1882 if (__pStrValue != null)
1884 pStrValue.reset(__pStrValue);
1886 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->pAlbumName
1887 = new (nothrow) String(pStrValue.get());
1889 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
1893 val = video_meta_get_duration(*(pVideoMeta.get()), &intValue);
1894 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1895 "video_meta_get_duration failed[%d].", val);
1897 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->duration = intValue;
1898 SysLog(NID_CNT, "META: duration[%d]", intValue);
1900 else if (systemType == SYSTEM_TYPE_OTHER)
1902 pContentData->contentType = CONTENT_TYPE_OTHER;
1903 SysLog(NID_CNT, "META: ContentType[%d]", pContentData->contentType);
1910 _ContentManagerImpl::VerifyHomeFilePathCompatibility(const String& contentPath) const
1912 if (!_AppInfo::IsOspCompat())
1914 if (contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0))
1916 SysLogException(NID_CNT, E_INVALID_ARG,
1917 "[E_INVALID_ARG] /Home/ or /HomeExt/ is not supported from Tizen 2.0.");
1920 if (!(contentPath.StartsWith(App::App::GetInstance()->GetAppRootPath(), 0) ||
1921 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
1923 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] The path is not supported.");
1929 SysTryReturn(NID_CNT, contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0),
1930 false, E_INVALID_ARG, "[E_INVALID_ARG] The path should start with /Home or /HomeExt.");
1937 _ContentManagerImpl::VerifyMediaFilePathCompatibility(const String& contentPath, bool checkVersion) const
1941 result r = E_SUCCESS;
1943 if (!_AppInfo::IsOspCompat())
1945 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0) || contentPath.StartsWith(OSP_MEDIA_MMC, 0))
1947 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] /Media or /Storagecard/Media is not supported.");
1950 if (!(contentPath.StartsWith(Environment::GetMediaPath(), 0) ||
1951 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
1953 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] This path is not supported.");
1960 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0))
1962 r = (const_cast<String*>(&contentPath))->Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
1963 SysTryReturn(NID_CNT, !IsFailed(r), false, E_INVALID_ARG, "[E_INVALID_ARG] Replace failed.");
1965 else if (contentPath.StartsWith(OSP_MEDIA_MMC, 0))
1967 r = (const_cast<String*>(&contentPath))->Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
1968 SysTryReturn(NID_CNT, !IsFailed(r), false, E_INVALID_ARG, "[E_INVALID_ARG] Replace failed.");
1972 // CreateContent(const ByteBuffer&, ...) and CreateContent (const Sring&, ...) can receive old path like /Media/.
1973 // but CreateContent(const ContentInfo&) always receive new path like /opt/media/ because ContentInfo class convert the path from /Media/ to /opt/media.
1976 SysLogException(NID_CNT, E_INVALID_ARG,
1977 "[E_INVALID_ARG] The path should start with /Home, /Media, or /Storagecard/Media.");
1987 _ContentManagerImpl::SetListener(IContentUpdateEventListener* pListener)
1989 __pListener = pListener;
1992 IContentUpdateEventListener*
1993 _ContentManagerImpl::GetListener(void) const