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);
331 if (inputType != sysType)
333 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
335 SysLogException(NID_CNT, E_INVALID_ARG,
336 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
337 return UuId::GetInvalidUuId();
341 // Save data to database with contentPath.
342 unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(pContentData->contentPath));
343 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
344 "[E_OUT_OF_MEMORY] The memory is insufficient.");
346 media_info_h tempMediaInfo = null;
347 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
349 // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
350 int val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
351 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
352 "The registration to database failed[%d].", val);
354 pMediaInfo.reset(tempMediaInfo);
356 // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
357 ContentId contentId = SaveDataToDatabase(pMediaInfo.get(), pContentData);
358 result r = GetLastResult();
359 SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
360 "[%s] The registration to database failed.", GetErrorMessage(r));
365 // There are two steps(insert and update) for content registration.
366 // If the update failed after inserting, the inserted data SHOULD be deleted from here.
367 val = media_info_delete_from_db(pStr.get());
368 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
370 return UuId::GetInvalidUuId();
377 // E_FILE_ALREADY_EXIST
384 // E_PRIVILEGE_DENIED(in public)
387 _ContentManagerImpl::CreateContent(const ByteBuffer& byteBuffer, const String& destinationPath,
388 const ContentInfo* pContentInfo)
390 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
394 // Check parameters(for length)
395 SysTryReturn(NID_CNT, byteBuffer.GetRemaining() > 0, UuId::GetInvalidUuId(), E_INVALID_ARG,
396 "[E_INVALID_ARG] byteBuffer is invalid.");
398 // Check parameters(for path compatibility)
399 SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(destinationPath, false), UuId::GetInvalidUuId(),
400 E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", destinationPath.GetPointer());
401 SysTryReturn(NID_CNT, !_FileImpl::IsFileExist(destinationPath), UuId::GetInvalidUuId(), E_FILE_ALREADY_EXIST,
402 "[E_FILE_ALREADY_EXIST] The specified file already exists.");
404 // Create a file with bytebuffer
405 unique_ptr<File> pFile(new (nothrow) File);
406 SysTryReturn(NID_CNT, pFile != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
407 "[E_OUT_OF_MEMORY] The memory is insufficient.");
409 // 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
410 result r = pFile->Construct(destinationPath, L"w+");
411 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r,
412 "[%s] The destination file can not be created.", GetErrorMessage(r));
414 _FileImpl* pFileImpl = _FileImpl::GetInstance(*pFile);
415 SysTryReturn(NID_CNT, pFileImpl != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
416 "[E_OUT_OF_MEMORY] The memory is insufficient.");
418 // Exception : E_SUCCESS, E_INVALID_ARG, E_ILLEGAL_ACCESS, E_STORAGE_FULL, E_IO
419 r = pFileImpl->Write(byteBuffer);
420 SysTryReturn(NID_CNT, !(IsFailed(r)), UuId::GetInvalidUuId(), r,
421 "[%s] The data can not be written in the destination file.", GetErrorMessage(r));
423 // for release file pointer
424 delete pFile.release();
428 ContentInfo::_ContentData contentData;
429 ContentInfo::_ContentData* pContentData = null;
430 media_info_h tempMediaInfo = null;
431 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
432 unique_ptr<char[]> pStr(null);
434 if (pContentInfo != null)
436 pContentData = (const_cast <ContentInfo*>(pContentInfo))->GetContentData();
437 SysTryCatch(NID_CNT, pContentData != null, , E_INVALID_ARG, "[E_INVALID_ARG] GetContentData failed.");
439 SysTryCatch(NID_CNT, pContentData->contentId == UuId::GetInvalidUuId(), , E_INVALID_ARG,
440 "[E_INVALID_ARG] The content already exists in database.");
442 // Compare the type of input parameter and system
443 // CheckContentType() need actual file. so it should be checked after creating the file.
444 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
445 ContentType inputType = pContentData->contentType;
447 if (inputType != sysType)
449 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
451 SysLogException(NID_CNT, E_INVALID_ARG,
452 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
457 // Sets the content path
458 (pContentData->contentPath).Clear();
459 pContentData->contentPath = destinationPath;
463 // Set the content path
464 contentData.contentPath = destinationPath;
466 pContentData = &contentData;
469 // Register the content to database directly.
470 pStr.reset(_StringConverter::CopyToCharArrayN(destinationPath));
471 SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
473 val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
474 SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
475 "media_info_insert_to_db failed[%d].", val);
477 pMediaInfo.reset(tempMediaInfo);
479 // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
480 contentId = SaveDataToDatabase(pMediaInfo.get(), pContentData);
482 SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
483 "[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
488 result saveResult = GetLastResult();
490 // If the destination file is made by this method, it should be deleted when error occurs.
491 r = _FileImpl::Remove(destinationPath);
492 SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
494 if (pMediaInfo != null)
496 val = media_info_delete_from_db(pStr.get());
497 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
500 SetLastResult(saveResult);
501 return UuId::GetInvalidUuId();
509 // E_FILE_ALREADY_EXIST
516 // E_PRIVILEGE_DENIED(in public)
519 _ContentManagerImpl::CreateContent(const String& sourcePath, const String& destinationPath, bool deleteSource,
520 const ContentInfo* pContentInfo)
522 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
526 // Check parameters(for type)
527 SysTryReturn(NID_CNT, _FileImpl::GetFileExtension(sourcePath) == _FileImpl::GetFileExtension(destinationPath),
528 UuId::GetInvalidUuId(), E_INVALID_ARG, "[E_INVALID_ARG] There is a mismatch between the type of source and dest path.");
530 // Check parameters(for path compatibility)
531 SysTryReturn(NID_CNT, VerifyHomeFilePathCompatibility(sourcePath), UuId::GetInvalidUuId(), E_INVALID_ARG,
532 "[E_INVALID_ARG] %ls is not compatible.", sourcePath.GetPointer());
533 SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(destinationPath, false), UuId::GetInvalidUuId(),
534 E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", destinationPath.GetPointer());
536 result r = E_SUCCESS;
538 if (deleteSource) // move
540 // 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
541 r = _FileImpl::Move(sourcePath, destinationPath);
542 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Moving the file failed.", GetErrorMessage(r));
546 // 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
547 r = _FileImpl::Copy(sourcePath, destinationPath, true);
548 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Copying the file failed.", GetErrorMessage(r));
553 ContentInfo::_ContentData contentData;
554 ContentInfo::_ContentData* pContentData = null;
555 media_info_h tempMediaInfo = null;
556 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
557 unique_ptr<char[]> pStr(null);
559 if (pContentInfo != null)
561 pContentData = (const_cast <ContentInfo*>(pContentInfo))->GetContentData();
562 SysTryCatch(NID_CNT, pContentData != null, , E_INVALID_ARG, "[E_INVALID_ARG] GetContentData failed.");
564 SysTryCatch(NID_CNT, pContentData->contentId == UuId::GetInvalidUuId(), , E_INVALID_ARG,
565 "[E_INVALID_ARG] The content already exists in database.");
567 // Compare the type of input parameter and system
568 // CheckContentType() need actual file. so it should be checked after creating the file.
569 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
570 ContentType inputType = pContentData->contentType;
572 if (inputType != sysType)
574 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
576 SysLogException(NID_CNT, E_INVALID_ARG,
577 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
582 // Set the content path
583 (pContentData->contentPath).Clear();
584 pContentData->contentPath = destinationPath;
588 // Set the content path
589 contentData.contentPath = destinationPath;
591 pContentData = &contentData;
594 pStr.reset(_StringConverter::CopyToCharArrayN(destinationPath));
595 SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
597 val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
598 SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
599 "media_info_insert_to_db failed[%d].", val);
601 pMediaInfo.reset(tempMediaInfo);
603 contentId = SaveDataToDatabase(pMediaInfo.get(), pContentData);
605 SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
606 "[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
611 result saveResult = GetLastResult();
613 // If the destination file is made by this method, it should be deleted when error occurs.
614 r = _FileImpl::Remove(destinationPath);
615 SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
617 if (pMediaInfo != null)
619 val = media_info_delete_from_db(pStr.get());
620 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
623 SetLastResult(saveResult);
624 return UuId::GetInvalidUuId();
634 // E_PRIVILEGE_DENIED(in public)
637 _ContentManagerImpl::GetContentInfoN(const ContentId& contentId) const
639 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
643 SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), null, E_INVALID_ARG,
644 "[E_INVALID_ARG] The contentId is invalid.");
646 unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(contentId.ToString()));
647 SysTryReturn(NID_CNT, pStr != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
649 media_info_h tempMediaInfo = null;
650 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
651 int val = media_info_get_media_from_db(pStr.get(), &tempMediaInfo);
652 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
653 "media_info_get_media_from_db failed[%d].", val);
655 pMediaInfo.reset(tempMediaInfo);
657 media_content_type_e systemType = MEDIA_CONTENT_TYPE_IMAGE;
658 val = media_info_get_media_type(pMediaInfo.get(), &systemType);
659 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
660 "media_info_get_media_type failed[%d].", val);
662 char* __pFilePath = null;
663 val = media_info_get_file_path(pMediaInfo.get(), &__pFilePath);
664 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
665 "media_info_get_file_path failed[%d].", val);
667 unique_ptr<char, CharDeleter> pFilePath(__pFilePath);
669 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(String(pFilePath.get())), null, E_FILE_NOT_FOUND,
670 "[E_FILE_NOT_FOUND] The file corresponding to contentId could not be found.");
672 result r = E_SUCCESS;
674 if (systemType == SYSTEM_TYPE_IMAGE)
676 unique_ptr<ImageContentInfo> pImageContentInfo(new (nothrow) ImageContentInfo);
677 SysTryReturn(NID_CNT, pImageContentInfo != null, null, E_OUT_OF_MEMORY,
678 "[E_OUT_OF_MEMORY] The memory is insufficient.");
681 ContentInfo::_ContentData* pContentData = pImageContentInfo->GetContentData();
682 SysTryReturn(NID_CNT, pContentData != null, null, E_OUT_OF_MEMORY,
683 "[E_OUT_OF_MEMORY] The memory is insufficient.");
685 // Get image metadata
686 ImageContentInfo::_ImageContentData* pImageContentData = pImageContentInfo->GetImageContentData();
687 SysTryReturn(NID_CNT, pImageContentData != null, null, E_OUT_OF_MEMORY,
688 "[E_OUT_OF_MEMORY] The memory is insufficient.");
691 // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
692 r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, pImageContentData);
693 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
695 return pImageContentInfo.release();
697 else if (systemType == SYSTEM_TYPE_SOUND || systemType == SYSTEM_TYPE_MUSIC)
699 unique_ptr<AudioContentInfo> pAudioContentInfo(new (nothrow) AudioContentInfo);
700 SysTryReturn(NID_CNT, pAudioContentInfo != null, null, E_OUT_OF_MEMORY,
701 "[E_OUT_OF_MEMORY] The memory is insufficient.");
703 ContentInfo::_ContentData* pContentData = pAudioContentInfo->GetContentData();
704 SysTryReturn(NID_CNT, pContentData != null, null, E_OUT_OF_MEMORY,
705 "[E_OUT_OF_MEMORY] The memory is insufficient.");
707 AudioContentInfo::_AudioContentData* pAudioContentData = pAudioContentInfo->GetAudioContentData();
708 SysTryReturn(NID_CNT, pAudioContentData != null, null, E_OUT_OF_MEMORY,
709 "[E_OUT_OF_MEMORY] The memory is insufficient.");
711 r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, pAudioContentData);
712 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
714 return pAudioContentInfo.release();
716 else if (systemType == SYSTEM_TYPE_VIDEO)
718 unique_ptr<VideoContentInfo> pVideoContentInfo(new (nothrow) VideoContentInfo);
719 SysTryReturn(NID_CNT, pVideoContentInfo != null, null, E_OUT_OF_MEMORY,
720 "[E_OUT_OF_MEMORY] The memory is insufficient.");
722 ContentInfo::_ContentData* pContentData = pVideoContentInfo->GetContentData();
723 SysTryReturn(NID_CNT, pContentData != null, null, E_OUT_OF_MEMORY,
724 "[E_OUT_OF_MEMORY] The memory is insufficient.");
726 VideoContentInfo::_VideoContentData* pVideoContentData = pVideoContentInfo->GetVideoContentData();
727 SysTryReturn(NID_CNT, pVideoContentData != null, null, E_OUT_OF_MEMORY,
728 "[E_OUT_OF_MEMORY] The memory is insufficient.");
730 r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, pVideoContentData);
731 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
733 return pVideoContentInfo.release();
735 else if (systemType == SYSTEM_TYPE_OTHER)
737 unique_ptr<OtherContentInfo> pOtherContentInfo(new (nothrow) OtherContentInfo);
738 SysTryReturn(NID_CNT, pOtherContentInfo != null, null, E_OUT_OF_MEMORY,
739 "[E_OUT_OF_MEMORY] The memory is insufficient.");
741 ContentInfo::_ContentData* pContentData = pOtherContentInfo->GetContentData();
742 SysTryReturn(NID_CNT, pContentData != null, null, E_OUT_OF_MEMORY,
743 "[E_OUT_OF_MEMORY] The memory is insufficient.");
745 r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, null);
746 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
748 return pOtherContentInfo.release();
752 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] Unsupported type");
764 // E_PRIVILEGE_DENIED(in public)
767 _ContentManagerImpl::UpdateContent(const ContentInfo& contentInfo)
769 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
773 ContentId contentId = contentInfo.GetContentId();
774 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, "The content id is invalid.");
775 SysTryReturnResult(NID_CNT, _FileImpl::IsFileExist(contentInfo.GetContentPath()), E_FILE_NOT_FOUND,
776 "The file corresponding to contentInfo could not be found.");
778 // Get common data from ContentInfo class
779 ContentInfo::_ContentData* pContentData = (const_cast <ContentInfo*>(&contentInfo))->GetContentData();
780 SysTryReturnResult(NID_CNT, pContentData != null, E_INVALID_ARG, "pContentData is null.");
782 // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SYSTEM, E_SERVICE_BUSY
783 result r = this->UpdateDataToDatabase(pContentData);
784 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "UpdateDataToDatabase failed.");
796 // E_PRIVILEGE_DENIED(in public)
797 // - E_ILLEGAL_ACCESS
800 _ContentManagerImpl::DeleteContent(const ContentId& contentId)
802 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
806 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, "The contentId is invalid.");
808 unique_ptr<char[]> pContentId(_StringConverter::CopyToCharArrayN(contentId.ToString()));
809 SysTryReturnResult(NID_CNT, pContentId != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
811 result r = E_SUCCESS;
813 media_info_h tempMediaInfo = null;
814 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
816 val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
817 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
818 "media_info_get_media_from_db failed[%d].", val);
820 pMediaInfo.reset(tempMediaInfo);
822 char* __pContentPath = null;
824 val = media_info_get_file_path(pMediaInfo.get(), &__pContentPath);
825 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
826 "media_info_get_file_path failed[%d].", val);
828 unique_ptr<char, CharDeleter> pContentPath(__pContentPath);
830 String contentPath = String(pContentPath.get());
831 SysTryReturnResult(NID_CNT, _FileImpl::IsFileExist(contentPath), E_FILE_NOT_FOUND,
832 "The file corresponding to contentId could not be found.");
834 val = media_info_delete_from_db(pContentId.get());
835 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
836 "media_info_delete_From_db failed[%d].", val);
838 r = _FileImpl::Remove(contentPath);
839 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The file is not deleted.");
846 // E_OBJ_ALREADY_EXIST
850 _ContentManagerImpl::AddContentUpdateEventListener(IContentUpdateEventListener& listener)
854 SysTryReturnResult(NID_CNT, GetListener() == null, E_OBJ_ALREADY_EXIST, "IContentUpdateEventListener is already set.");
856 SetListener(&listener);
858 int val = media_content_set_db_updated_cb(OnContentUpdateCompleted, this);
859 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "media_content_set_db_updated_cb failed[%d].", val);
870 _ContentManagerImpl::RemoveContentUpdateEventListener(IContentUpdateEventListener& listener)
874 SysTryReturnResult(NID_CNT, GetListener() == &listener, E_OBJ_NOT_FOUND, "The input listener is not equal to the registered listener.");
876 int val = media_content_unset_db_updated_cb();
877 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "media_content_unset_db_updated_cb failed[%d].", val);
889 // E_PRIVILEGE_DENIED(in public)
892 _ContentManagerImpl::ScanFile(const Tizen::Base::String& contentPath)
896 SysSecureLog(NID_CNT, "The scan path is [%ls].", contentPath.GetPointer());
898 unique_ptr<char[]> pContentPath(_StringConverter::CopyToCharArrayN(contentPath));
899 SysTryReturnResult(NID_CNT, pContentPath, E_SYSTEM, "pContentPath is NULL.");
901 int val = media_content_connect();
902 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The connection failed[%d].", val);
904 val = media_content_scan_file(pContentPath.get());
905 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val), "media_content_scan_file failed[%d].", val);
907 val = media_content_disconnect();
908 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The disconnection failed[%d].", val);
918 // E_PRIVILEGE_DENIED(in public)
921 _ContentManagerImpl::ScanDirectory(const Tizen::Base::String& directoryPath, bool recursive, IContentScanListener* pListener, RequestId& reqId)
925 SysLog(NID_CNT, "The scan path is [%ls].", directoryPath.GetPointer());
927 unique_ptr<char[]> pDirPath(_StringConverter::CopyToCharArrayN(directoryPath));
928 SysTryReturnResult(NID_CNT, pDirPath, E_SYSTEM, "pDirPath is NULL.");
930 int val = media_content_connect();
931 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The connection failed[%d].", val);
933 unique_ptr< ScanResult > pScanResult(new (nothrow) ScanResult);
934 SysTryReturnResult(NID_CNT, pScanResult != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
938 pScanResult->scanPath = directoryPath;
939 pScanResult->pScanListener = pListener;
940 pScanResult->requestId = reqId;
942 val = media_content_scan_folder(pDirPath.get(), recursive, OnScanCompleted, pScanResult.release());
943 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val), "media_content_scan_folder failed[%d].", val);
956 _ContentManagerImpl::UpdateDataToDatabase(const ContentInfo::_ContentData* pContentData) const
960 SysTryReturnResult(NID_CNT, pContentData != null, E_INVALID_ARG, "pContentData is null.");
962 media_info_h tempMediaInfo = null;
963 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
964 unique_ptr<char[]> pContentId(_StringConverter::CopyToCharArrayN((pContentData->contentId).ToString()));
965 SysTryReturnResult(NID_CNT, pContentId != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
967 int val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
968 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
969 "media_info_get_media_from_db failed[%d].", val);
971 pMediaInfo.reset(tempMediaInfo);
973 result r = E_SUCCESS;
974 unique_ptr<char[]> pValue(null);
976 if (pContentData->pAuthor != null)
978 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pAuthor)));
979 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
981 val = media_info_set_author(pMediaInfo.get(), pValue.get());
982 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
983 "media_info_set_author failed[%d].", val);
985 if (pContentData->pCategory != null)
987 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pCategory)));
988 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
990 val = media_info_set_category(pMediaInfo.get(), pValue.get());
991 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
992 "media_info_set_category failed[%d].", val);
994 if (pContentData->pContentName != null)
996 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pContentName)));
997 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
999 val = media_info_set_content_name(pMediaInfo.get(), pValue.get());
1000 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1001 "media_info_set_content_name failed[%d].", val);
1003 if (pContentData->pDescription != null)
1005 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pDescription)));
1006 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1008 val = media_info_set_description(pMediaInfo.get(), pValue.get());
1009 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1010 "media_info_set_description failed[%d].", val);
1012 if (pContentData->pKeyword != null)
1014 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pKeyword)));
1015 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1017 val = media_info_set_keyword(pMediaInfo.get(), pValue.get());
1018 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1019 "media_info_set_keyword failed[%d].", val);
1021 if (pContentData->pLocationTag != null)
1023 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pLocationTag)));
1024 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1026 val = media_info_set_location_tag(pMediaInfo.get(), pValue.get());
1027 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1028 "media_info_set_location_tag failed[%d].", val);
1030 if (pContentData->pProvider != null)
1032 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pProvider)));
1033 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1035 val = media_info_set_provider(pMediaInfo.get(), pValue.get());
1036 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1037 "media_info_set_provider failed[%d].", val);
1039 if (pContentData->pRating != null)
1041 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pRating)));
1042 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1044 val = media_info_set_age_rating(pMediaInfo.get(), pValue.get());
1045 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1046 "media_info_set_age_rating failed[%d].", val);
1048 if (Double::Compare(pContentData->latitude, DEFAULT_COORDINATE) != 0 &&
1049 Double::Compare(pContentData->longitude, DEFAULT_COORDINATE) != 0)
1051 val = media_info_set_latitude(pMediaInfo.get(), pContentData->latitude);
1052 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1053 "media_info_set_latitude failed[%d].", val);
1055 val = media_info_set_longitude(pMediaInfo.get(), pContentData->longitude);
1056 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1057 "media_info_set_longitude failed[%d].", val);
1059 if (Double::Compare(pContentData->altitude, DEFAULT_COORDINATE) != 0)
1061 val = media_info_set_altitude(pMediaInfo.get(), pContentData->altitude);
1062 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1063 "media_info_set_altitude failed[%d].", val);
1067 val = media_info_update_to_db(pMediaInfo.get());
1068 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1069 "media_info_update_to_db failed[%d].", val);
1082 _ContentManagerImpl::SaveDataToDatabase(const media_info_h pMediaInfo,
1083 ContentInfo::_ContentData* pContentData) const
1087 SysTryReturn(NID_CNT, pContentData != null, UuId::GetInvalidUuId(), E_INVALID_ARG,
1088 "[E_INVALID_ARG] pContentData is null.");
1090 String mimeType(L"");
1091 String extension = _FileImpl::GetFileExtension(pContentData->contentPath);
1092 result r = GetLastResult();
1095 SysLog(NID_CNT, "[%s] Failed to perform GetFileExtension operation.", GetErrorMessage(r));
1097 unique_ptr<char[]> pTempPath(_StringConverter::CopyToCharArrayN(pContentData->contentPath));
1098 SysTryReturn(NID_CNT, pTempPath != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1099 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1101 char tempType[255] = {0, };
1102 int ret = aul_get_mime_from_file(pTempPath.get(), tempType, sizeof(tempType));
1103 SysTryReturn(NID_CNT, ret == AUL_R_OK, UuId::GetInvalidUuId(), E_INVALID_ARG,
1104 "[E_INVALID_ARG] Failed to perform aul_get_mime_from_file operation.");
1106 r = mimeType.Append(tempType);
1107 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1108 "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
1111 // If the content format is JPG and it has GPS data, it will be saved in database automatically.
1112 if (extension == L"jpg" || extension == L"jpeg" || extension == L"JPG" || extension == L"JPEG" || mimeType.Contains(L"jpeg"))
1114 SysLog(NID_CNT, "The format of content is jpg.");
1116 ImageMetadata* pImageMetadata = _ContentManagerUtilImpl::GetImageMetaN(pContentData->contentPath, true);
1117 if (pImageMetadata != null)
1119 pContentData->latitude = pImageMetadata->GetLatitude();
1120 pContentData->longitude = pImageMetadata->GetLongitude();
1122 delete pImageMetadata;
1127 unique_ptr<char[]> pStr(null);
1129 if (pContentData->pAuthor != null)
1131 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pAuthor)));
1132 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1133 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1135 val = media_info_set_author(pMediaInfo, pStr.get());
1136 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1137 "media_info_set_author failed[%d].", val);
1139 if (pContentData->pCategory != null)
1141 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pCategory)));
1142 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1143 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1145 val = media_info_set_category(pMediaInfo, pStr.get());
1146 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1147 "media_info_set_category failed[%d].", val);
1149 if (pContentData->pContentName != null)
1151 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pContentName)));
1152 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1153 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1155 val = media_info_set_content_name(pMediaInfo, pStr.get());
1156 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1157 "media_info_set_content_name failed[%d].", val);
1159 if (pContentData->pDescription != null)
1161 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pDescription)));
1162 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1163 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1165 val = media_info_set_description(pMediaInfo, pStr.get());
1166 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1167 "media_info_set_description failed[%d].", val);
1169 if (pContentData->pKeyword != null)
1171 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pKeyword)));
1172 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1173 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1175 val = media_info_set_keyword(pMediaInfo, pStr.get());
1176 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1177 "media_info_set_keyword failed[%d].", val);
1179 if (pContentData->pLocationTag != null)
1181 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pLocationTag)));
1182 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1183 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1185 val = media_info_set_location_tag(pMediaInfo, pStr.get());
1186 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1187 "media_info_set_location_tag failed[%d].", val);
1189 if (pContentData->pProvider != null)
1191 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pProvider)));
1192 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1193 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1195 val = media_info_set_provider(pMediaInfo, pStr.get());
1196 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1197 "media_info_set_provider failed[%d].", val);
1199 if (pContentData->pRating != null)
1201 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pRating)));
1202 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1203 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1205 val = media_info_set_age_rating(pMediaInfo, pStr.get());
1206 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1207 "media_info_set_age_rating failed[%d].", val);
1209 if (Double::Compare(pContentData->latitude, DEFAULT_COORDINATE) != 0 &&
1210 Double::Compare(pContentData->longitude, DEFAULT_COORDINATE) != 0)
1212 val = media_info_set_latitude(pMediaInfo, pContentData->latitude);
1213 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1214 "media_info_set_latitude failed[%d].", val);
1216 val = media_info_set_longitude(pMediaInfo, pContentData->longitude);
1217 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1218 "media_info_set_longitude failed[%d].", val);
1220 if (Double::Compare(pContentData->altitude, DEFAULT_COORDINATE) != 0)
1222 val = media_info_set_altitude(pMediaInfo, pContentData->altitude);
1223 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1224 "media_info_set_altitude failed[%d].", val);
1228 val = media_info_update_to_db(pMediaInfo);
1229 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1230 "media_info_update_to_db failed[%d].", val);
1232 char* __pMediaId = null;
1233 unique_ptr<char, CharDeleter> pMediaId(null);
1235 val = media_info_get_media_id(pMediaInfo, &__pMediaId);
1236 if (__pMediaId != null)
1238 pMediaId.reset(__pMediaId);
1242 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1243 "media_info_get_media_id failed[%d].", val);
1246 String contentId(pMediaId.get());
1248 r = UuId::Parse(contentId, pContentData->contentId);
1249 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_INVALID_ARG,
1250 "[E_INVALID_ARG] UuId::Parse failed.");
1252 return pContentData->contentId;
1263 _ContentManagerImpl::MakeContentInfo(const media_info_h pMediaInfo, ContentInfo::_ContentData* pContentData,
1264 int systemType, void* pMetadata) const
1268 if (systemType != SYSTEM_TYPE_OTHER)
1270 SysTryReturnResult(NID_CNT, pMediaInfo != null && pContentData != null && pMetadata != null, E_INVALID_ARG,
1271 "The specified parameter is invalid.");
1273 else // There is no metadata in Other type
1275 SysTryReturnResult(NID_CNT, pMediaInfo != null && pContentData != null, E_INVALID_ARG,
1276 "The specified parameter is invalid.");
1279 result r = E_SUCCESS;
1280 char* __pStrValue = null;
1281 unique_ptr<char, CharDeleter> pStrValue(null);
1284 int val = media_info_get_media_id(pMediaInfo, &__pStrValue);
1285 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1286 "media_info_get_media_id failed[%d].", val);
1288 if (__pStrValue != null)
1290 pStrValue.reset(__pStrValue);
1292 String strContentId(pStrValue.get());
1294 r = UuId::Parse(strContentId, pContentData->contentId);
1295 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The content id can not be parsed.");
1297 SysLog(NID_CNT, "INFO: contentId[%ls]", strContentId.GetPointer());
1301 val = media_info_get_file_path(pMediaInfo, &__pStrValue);
1302 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1303 "media_info_get_file_path failed[%d].", val);
1305 if (__pStrValue != null)
1307 pStrValue.reset(__pStrValue);
1309 String strFilePath(pStrValue.get());
1311 // If the api version is 2.0, the content path has to be changed.
1312 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
1314 if (strFilePath.StartsWith(Environment::GetMediaPath(), 0))
1316 r = strFilePath.Replace(Environment::GetMediaPath(), OSP_MEDIA_PHONE);
1317 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The content path is not changed.");
1319 else if (strFilePath.StartsWith(Environment::GetExternalStoragePath(), 0))
1321 r = strFilePath.Replace(Environment::GetExternalStoragePath(), OSP_MEDIA_MMC);
1322 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Replace failed.");
1326 SysLogException(NID_CNT, E_INVALID_ARG,
1327 "[E_INVALID_ARG] The content path is not supported.");
1328 return E_INVALID_ARG;
1332 pContentData->contentPath = strFilePath;
1334 SysSecureLog(NID_CNT, "INFO: contentPath[%ls]", strFilePath.GetPointer());
1338 val = media_info_get_mime_type(pMediaInfo, &__pStrValue);
1339 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1340 "media_info_get_mime_type failed[%d].", val);
1342 if (__pStrValue != null)
1344 pStrValue.reset(__pStrValue);
1346 pContentData->mimeType = pStrValue.get();
1348 SysLog(NID_CNT, "INFO: mimeType[%ls]", (pContentData->mimeType).GetPointer());
1352 unsigned long long longlongValue = 0;
1353 val = media_info_get_size(pMediaInfo, &longlongValue);
1354 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1355 "media_info_get_size failed[%d].", val);
1356 pContentData->contentSize = longlongValue;
1357 SysLog(NID_CNT, "INFO: contentSize[%llu]", longlongValue);
1360 media_content_storage_e storageType;
1361 val = media_info_get_storage_type(pMediaInfo, &storageType);
1362 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1363 "media_info_get_storage_type failed[%d].", val);
1364 pContentData->storageType = storageType;
1365 SysLog(NID_CNT, "INFO: storageType[%d]", storageType);
1368 val = media_info_is_drm(pMediaInfo, &(pContentData->isDrm));
1369 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1370 "media_info_is_drm failed[%d].", val);
1371 SysLog(NID_CNT, "INFO: isDrm[%d]", pContentData->isDrm);
1375 val = media_info_get_added_time(pMediaInfo, &time);
1376 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1377 "media_info_get_added_time failed[%d].", val);
1378 r = (pContentData->dateTime).SetValue(1970, 1, 1);
1379 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "SetValue failed.");
1380 r = (pContentData->dateTime).AddSeconds(time);
1381 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "AddSeconds failed.");
1382 SysLog(NID_CNT, "INFO: dateTime[%ls]", ((pContentData->dateTime).ToString()).GetPointer());
1385 val = media_info_get_thumbnail_path(pMediaInfo, &__pStrValue);
1386 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1387 "media_info_get_thumbnail_path failed[%d].", val);
1389 if (__pStrValue != null)
1391 pStrValue.reset(__pStrValue);
1393 pContentData->pThumbnailPath = new (nothrow) String(pStrValue.get());
1395 SysLog(NID_CNT, "INFO: thumbnailPath[%ls]", (*pContentData->pThumbnailPath).GetPointer());
1399 val = media_info_get_author(pMediaInfo, &__pStrValue);
1400 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1401 "media_info_get_author failed[%d].", val);
1403 if (__pStrValue != null)
1405 pStrValue.reset(__pStrValue);
1407 pContentData->pAuthor = new (nothrow) String(pStrValue.get());
1409 SysLog(NID_CNT, "INFO: author[%ls]", (*pContentData->pAuthor).GetPointer());
1413 val = media_info_get_category(pMediaInfo, &__pStrValue);
1414 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1415 "media_info_get_category failed[%d].", val);
1417 if (__pStrValue != null)
1419 pStrValue.reset(__pStrValue);
1421 pContentData->pCategory = new (nothrow) String(pStrValue.get());
1423 SysLog(NID_CNT, "INFO: category[%ls]", (*pContentData->pCategory).GetPointer());
1427 val = media_info_get_content_name(pMediaInfo, &__pStrValue);
1428 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1429 "media_info_get_content_name failed[%d].", val);
1431 if (__pStrValue != null)
1433 pStrValue.reset(__pStrValue);
1435 pContentData->pContentName = new (nothrow) String(pStrValue.get());
1437 SysSecureLog(NID_CNT, "INFO: contentName[%ls]", (*pContentData->pContentName).GetPointer());
1441 val = media_info_get_description(pMediaInfo, &__pStrValue);
1442 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1443 "media_info_get_description failed[%d].", val);
1445 if (__pStrValue != null)
1447 pStrValue.reset(__pStrValue);
1449 pContentData->pDescription = new (nothrow) String(pStrValue.get());
1451 SysLog(NID_CNT, "INFO: description[%ls]", (*pContentData->pDescription).GetPointer());
1455 val = media_info_get_keyword(pMediaInfo, &__pStrValue);
1456 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1457 "media_info_get_keyword failed[%d].", val);
1459 if (__pStrValue != null)
1461 pStrValue.reset(__pStrValue);
1463 pContentData->pKeyword = new (nothrow) String(pStrValue.get());
1465 SysLog(NID_CNT, "INFO: keyword[%ls]", (*pContentData->pKeyword).GetPointer());
1469 val = media_info_get_location_tag(pMediaInfo, &__pStrValue);
1470 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1471 "media_info_get_location_tag failed[%d].", val);
1473 if (__pStrValue != null)
1475 pStrValue.reset(__pStrValue);
1477 pContentData->pLocationTag = new (nothrow) String(pStrValue.get());
1479 SysSecureLog(NID_CNT, "INFO: locationTag[%ls]", (*pContentData->pLocationTag).GetPointer());
1483 val = media_info_get_provider(pMediaInfo, &__pStrValue);
1484 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1485 "media_info_get_provider failed[%d].", val);
1487 if (__pStrValue != null)
1489 pStrValue.reset(__pStrValue);
1491 pContentData->pProvider = new (nothrow) String(pStrValue.get());
1493 SysLog(NID_CNT, "INFO: provider[%ls]", (*pContentData->pProvider).GetPointer());
1497 val = media_info_get_age_rating(pMediaInfo, &__pStrValue);
1498 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1499 "media_info_get_age_rating failed[%d].", val);
1501 if (__pStrValue != null)
1503 pStrValue.reset(__pStrValue);
1505 pContentData->pRating = new (nothrow) String(pStrValue.get());
1507 SysLog(NID_CNT, "INFO: rating[%ls]", (*pContentData->pRating).GetPointer());
1511 double doubleValue = 0;
1512 val = media_info_get_latitude(pMediaInfo, &doubleValue);
1513 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1514 "media_info_get_latitude failed[%d].", val);
1516 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1518 pContentData->latitude = doubleValue;
1520 SysSecureLog(NID_CNT, "INFO: latitude[%f]", pContentData->latitude);
1522 val = media_info_get_longitude(pMediaInfo, &doubleValue);
1523 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1524 "media_info_get_longitude failed[%d].", val);
1526 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1528 pContentData->longitude = doubleValue;
1530 SysSecureLog(NID_CNT, "INFO: longitude[%f]", pContentData->longitude);
1532 val = media_info_get_altitude(pMediaInfo, &doubleValue);
1533 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1534 "media_info_get_altitude failed[%d].", val);
1536 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1538 pContentData->altitude = doubleValue;
1540 SysLog(NID_CNT, "INFO: altitude[%f]", pContentData->altitude);
1544 // contentType and metadata
1545 if (systemType == SYSTEM_TYPE_IMAGE)
1547 image_meta_h __pImageMeta = null;
1548 unique_ptr<image_meta_h, ImageMetaDeleter> pImageMeta(null);
1550 pContentData->contentType = CONTENT_TYPE_IMAGE;
1551 SysLog(NID_CNT, "META: ContentType[%d]", pContentData->contentType);
1553 val = media_info_get_image(pMediaInfo, &__pImageMeta);
1554 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1555 "media_info_get_image failed[%d].", val);
1557 pImageMeta.reset(&__pImageMeta);
1560 val = image_meta_get_width(*(pImageMeta.get()), &intValue);
1561 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1562 "image_meta_get_width failed[%d].", val);
1564 (static_cast<ImageContentInfo::_ImageContentData*>(pMetadata))->width = intValue;
1565 SysLog(NID_CNT, "META: width[%d]", intValue);
1568 val = image_meta_get_height(*(pImageMeta.get()), &intValue);
1569 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1570 "image_meta_get_height failed[%d].", val);
1572 (static_cast<ImageContentInfo::_ImageContentData*>(pMetadata))->height = intValue;
1573 SysLog(NID_CNT, "META: height[%d]", intValue);
1576 media_content_orientation_e orientation;
1577 val = image_meta_get_orientation(*(pImageMeta.get()), &orientation);
1578 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1579 "image_meta_get_orientation failed[%d].", val);
1581 (static_cast<ImageContentInfo::_ImageContentData*>(pMetadata))->orientationType =
1582 static_cast<ImageOrientationType>(orientation);
1583 SysLog(NID_CNT, "META: orientation[%d]", orientation);
1586 val = media_info_get_display_name(pMediaInfo, &__pStrValue);
1587 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1588 "media_info_get_display_name failed[%d].", val);
1590 if (__pStrValue != null)
1592 pStrValue.reset(__pStrValue);
1596 String strTitle(pStrValue.get());
1598 r = strTitle.LastIndexOf(L'.', strTitle.GetLength() - 1, pos);
1601 r = strTitle.SubString(0, pos, fileName);
1602 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The title is invalid.");
1606 // Without extension
1608 fileName = strTitle;
1611 (static_cast<ImageContentInfo::_ImageContentData*>(pMetadata))->title = fileName;
1613 SysLog(NID_CNT, "META: title[%ls]", fileName.GetPointer());
1616 else if (systemType == SYSTEM_TYPE_SOUND || systemType == SYSTEM_TYPE_MUSIC)
1618 audio_meta_h __pAudioMeta = null;
1619 unique_ptr<audio_meta_h, AudioMetaDeleter> pAudioMeta(null);
1621 pContentData->contentType = CONTENT_TYPE_AUDIO;
1622 SysLog(NID_CNT, "META: ContentType[%d]", pContentData->contentType);
1624 val = media_info_get_audio(pMediaInfo, &__pAudioMeta);
1625 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1626 "media_info_get_audio failed[%d].", val);
1628 pAudioMeta.reset(&__pAudioMeta);
1631 val = audio_meta_get_bit_rate(*(pAudioMeta.get()), &intValue);
1632 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1633 "audio_meta_get_bit_rate failed[%d].", val);
1635 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->bitrate = intValue;
1636 SysLog(NID_CNT, "META: bitrate[%d]", intValue);
1639 val = audio_meta_get_year(*(pAudioMeta.get()), &__pStrValue);
1640 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1641 "audio_meta_get_year failed[%d].", val);
1643 if (__pStrValue != null)
1645 pStrValue.reset(__pStrValue);
1647 String strYear(pStrValue.get());
1649 if (strYear.CompareTo(L"Unknown") != 0)
1651 r = Integer::Parse(strYear, intValue);
1654 // It is one of the metadata. If error occurs, skip it for other metadata.
1657 SysLog(NID_CNT, "META: releaseYear - invalid data[%ls]", strYear.GetPointer());
1660 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->releaseYear = intValue;
1661 SysLog(NID_CNT, "META: releaseYear[%d]", intValue);
1666 val = audio_meta_get_title(*(pAudioMeta.get()), &__pStrValue);
1667 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1668 "audio_meta_get_title failed[%d].", val);
1670 if (__pStrValue != null)
1672 pStrValue.reset(__pStrValue);
1674 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pTitle =
1675 new (nothrow) String(pStrValue.get());
1677 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
1681 val = audio_meta_get_album(*(pAudioMeta.get()), &__pStrValue);
1682 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1683 "audio_meta_get_album failed[%d].", val);
1685 if (__pStrValue != null)
1687 pStrValue.reset(__pStrValue);
1689 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pAlbumName =
1690 new (nothrow) String(pStrValue.get());
1692 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
1696 val = audio_meta_get_artist(*(pAudioMeta.get()), &__pStrValue);
1697 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1698 "audio_meta_get_artist failed[%d].", val);
1700 if (__pStrValue != null)
1702 pStrValue.reset(__pStrValue);
1704 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pArtist =
1705 new (nothrow) String(pStrValue.get());
1707 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
1711 val = audio_meta_get_composer(*(pAudioMeta.get()), &__pStrValue);
1712 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1713 "audio_meta_get_composer failed[%d].", val);
1715 if (__pStrValue != null)
1717 pStrValue.reset(__pStrValue);
1719 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pComposer =
1720 new (nothrow) String(pStrValue.get());
1722 SysLog(NID_CNT, "META: composer[%ls]", (String(pStrValue.get())).GetPointer());
1726 val = audio_meta_get_genre(*(pAudioMeta.get()), &__pStrValue);
1727 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1728 "audio_meta_get_genre failed[%d].", val);
1730 if (__pStrValue != null)
1732 pStrValue.reset(__pStrValue);
1734 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pGenre =
1735 new (nothrow) String(pStrValue.get());
1737 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
1741 val = audio_meta_get_copyright(*(pAudioMeta.get()), &__pStrValue);
1742 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1743 "audio_meta_get_copyright failed[%d].", val);
1745 if (__pStrValue != null)
1747 pStrValue.reset(__pStrValue);
1749 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pCopyright =
1750 new (nothrow) String(pStrValue.get());
1752 SysLog(NID_CNT, "META: copyright[%ls]", (String(pStrValue.get())).GetPointer());
1756 val = audio_meta_get_track_num(*(pAudioMeta.get()), &__pStrValue);
1757 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1758 "audio_meta_get_track_num failed[%d].", val);
1760 if (__pStrValue != null)
1762 pStrValue.reset(__pStrValue);
1764 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pTrackInfo
1765 = new (nothrow) String(pStrValue.get());
1767 SysLog(NID_CNT, "META: trackInfo[%ls]", (String(pStrValue.get())).GetPointer());
1771 val = audio_meta_get_duration(*(pAudioMeta.get()), &intValue);
1772 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1773 "audio_meta_get_duration failed[%d].", val);
1775 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->duration = intValue;
1776 SysLog(NID_CNT, "META: duration[%d]", intValue);
1779 else if (systemType == MEDIA_CONTENT_TYPE_VIDEO)
1781 video_meta_h __pVideoMeta = null;
1782 unique_ptr<video_meta_h, VideoMetaDeleter> pVideoMeta(null);
1784 pContentData->contentType = CONTENT_TYPE_VIDEO;
1785 SysLog(NID_CNT, "META: ContentType[%d]", pContentData->contentType);
1787 val = media_info_get_video(pMediaInfo, &__pVideoMeta);
1788 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1789 "media_info_get_video failed[%d].", val);
1791 pVideoMeta.reset(&__pVideoMeta);
1794 val = video_meta_get_width(*(pVideoMeta.get()), &intValue);
1795 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1796 "video_meta_get_width failed[%d].", val);
1798 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->width = intValue;
1799 SysLog(NID_CNT, "META: width[%d]", intValue);
1802 val = video_meta_get_height(*(pVideoMeta.get()), &intValue);
1803 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1804 "video_meta_get_height failed[%d].", val);
1806 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->height = intValue;
1807 SysLog(NID_CNT, "META: height[%d]", intValue);
1809 // Get from metadata extractor (framerate, audio bitrate, video bitrate)
1812 val = video_meta_get_artist(*(pVideoMeta.get()), &__pStrValue);
1813 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1814 "video_meta_get_artist failed[%d].", val);
1816 if (__pStrValue != null)
1818 pStrValue.reset(__pStrValue);
1820 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->pArtist
1821 = new (nothrow) String(pStrValue.get());
1823 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
1827 val = video_meta_get_genre(*(pVideoMeta.get()), &__pStrValue);
1828 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1829 "video_meta_get_genre failed[%d].", val);
1831 if (__pStrValue != null)
1833 pStrValue.reset(__pStrValue);
1835 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->pGenre
1836 = new (nothrow) String(pStrValue.get());
1838 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
1842 val = video_meta_get_title(*(pVideoMeta.get()), &__pStrValue);
1843 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1844 "video_meta_get_title failed[%d].", val);
1846 if (__pStrValue != null)
1848 pStrValue.reset(__pStrValue);
1850 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->pTitle
1851 = new (nothrow) String(pStrValue.get());
1853 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
1857 val = video_meta_get_album(*(pVideoMeta.get()), &__pStrValue);
1858 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1859 "video_meta_get_album failed[%d].", val);
1861 if (__pStrValue != null)
1863 pStrValue.reset(__pStrValue);
1865 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->pAlbumName
1866 = new (nothrow) String(pStrValue.get());
1868 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
1872 val = video_meta_get_duration(*(pVideoMeta.get()), &intValue);
1873 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1874 "video_meta_get_duration failed[%d].", val);
1876 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->duration = intValue;
1877 SysLog(NID_CNT, "META: duration[%d]", intValue);
1879 else if (systemType == SYSTEM_TYPE_OTHER)
1881 pContentData->contentType = CONTENT_TYPE_OTHER;
1882 SysLog(NID_CNT, "META: ContentType[%d]", pContentData->contentType);
1889 _ContentManagerImpl::VerifyHomeFilePathCompatibility(const String& contentPath) const
1891 if (!_AppInfo::IsOspCompat())
1893 if (contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0))
1895 SysLogException(NID_CNT, E_INVALID_ARG,
1896 "[E_INVALID_ARG] /Home/ or /HomeExt/ is not supported from Tizen 2.0.");
1899 if (!(contentPath.StartsWith(App::App::GetInstance()->GetAppRootPath(), 0) ||
1900 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
1902 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] The path is not supported.");
1908 SysTryReturn(NID_CNT, contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0),
1909 false, E_INVALID_ARG, "[E_INVALID_ARG] The path should start with /Home or /HomeExt.");
1916 _ContentManagerImpl::VerifyMediaFilePathCompatibility(const String& contentPath, bool checkVersion) const
1920 result r = E_SUCCESS;
1922 if (!_AppInfo::IsOspCompat())
1924 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0) || contentPath.StartsWith(OSP_MEDIA_MMC, 0))
1926 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] /Media or /Storagecard/Media is not supported.");
1929 if (!(contentPath.StartsWith(Environment::GetMediaPath(), 0) ||
1930 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
1932 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] This path is not supported.");
1939 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0))
1941 r = (const_cast<String*>(&contentPath))->Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
1942 SysTryReturn(NID_CNT, !IsFailed(r), false, E_INVALID_ARG, "[E_INVALID_ARG] Replace failed.");
1944 else if (contentPath.StartsWith(OSP_MEDIA_MMC, 0))
1946 r = (const_cast<String*>(&contentPath))->Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
1947 SysTryReturn(NID_CNT, !IsFailed(r), false, E_INVALID_ARG, "[E_INVALID_ARG] Replace failed.");
1951 // CreateContent(const ByteBuffer&, ...) and CreateContent (const Sring&, ...) can receive old path like /Media/.
1952 // but CreateContent(const ContentInfo&) always receive new path like /opt/media/ because ContentInfo class convert the path from /Media/ to /opt/media.
1955 SysLogException(NID_CNT, E_INVALID_ARG,
1956 "[E_INVALID_ARG] The path should start with /Home, /Media, or /Storagecard/Media.");
1966 _ContentManagerImpl::SetListener(IContentUpdateEventListener* pListener)
1968 __pListener = pListener;
1971 IContentUpdateEventListener*
1972 _ContentManagerImpl::GetListener(void) const