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;
539 if (deleteSource) // move
541 // 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
542 r = _FileImpl::Move(sourcePath, destinationPath);
543 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Moving the file failed.", GetErrorMessage(r));
547 // 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
548 r = _FileImpl::Copy(sourcePath, destinationPath, true);
549 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Copying the file failed.", GetErrorMessage(r));
556 ContentInfo::_ContentData contentData;
557 ContentInfo::_ContentData* pContentData = null;
558 media_info_h tempMediaInfo = null;
559 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
560 unique_ptr<char[]> pStr(null);
562 if (pContentInfo != null)
564 pContentData = (const_cast <ContentInfo*>(pContentInfo))->GetContentData();
565 SysTryCatch(NID_CNT, pContentData != null, , E_INVALID_ARG, "[E_INVALID_ARG] GetContentData failed.");
567 SysTryCatch(NID_CNT, pContentData->contentId == UuId::GetInvalidUuId(), , E_INVALID_ARG,
568 "[E_INVALID_ARG] The content already exists in database.");
570 // Compare the type of input parameter and system
571 // CheckContentType() need actual file. so it should be checked after creating the file.
572 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
573 ContentType inputType = pContentData->contentType;
575 if (inputType != sysType)
577 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
579 SysLogException(NID_CNT, E_INVALID_ARG,
580 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
585 // Set the content path
586 (pContentData->contentPath).Clear();
587 pContentData->contentPath = destinationPath;
591 // Set the content path
592 contentData.contentPath = destinationPath;
594 pContentData = &contentData;
597 pStr.reset(_StringConverter::CopyToCharArrayN(destinationPath));
598 SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
600 val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
601 SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
602 "media_info_insert_to_db failed[%d].", val);
604 pMediaInfo.reset(tempMediaInfo);
606 contentId = SaveDataToDatabase(pMediaInfo.get(), pContentData);
608 SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
609 "[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
614 result saveResult = GetLastResult();
618 r = _FileImpl::Remove(destinationPath);
619 SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
623 r = _FileImpl::Move(destinationPath, sourcePath);
624 SysLog(NID_CNT, "Move[%s].", GetErrorMessage(r));
627 if (pMediaInfo != null)
629 val = media_info_delete_from_db(pStr.get());
630 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
633 SetLastResult(saveResult);
634 return UuId::GetInvalidUuId();
644 // E_PRIVILEGE_DENIED(in public)
647 _ContentManagerImpl::GetContentInfoN(const ContentId& contentId) const
649 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
653 SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), null, E_INVALID_ARG,
654 "[E_INVALID_ARG] The contentId is invalid.");
656 unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(contentId.ToString()));
657 SysTryReturn(NID_CNT, pStr != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
659 media_info_h tempMediaInfo = null;
660 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
661 int val = media_info_get_media_from_db(pStr.get(), &tempMediaInfo);
662 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
663 "media_info_get_media_from_db failed[%d].", val);
665 pMediaInfo.reset(tempMediaInfo);
667 media_content_type_e systemType = MEDIA_CONTENT_TYPE_IMAGE;
668 val = media_info_get_media_type(pMediaInfo.get(), &systemType);
669 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
670 "media_info_get_media_type failed[%d].", val);
672 char* __pFilePath = null;
673 val = media_info_get_file_path(pMediaInfo.get(), &__pFilePath);
674 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
675 "media_info_get_file_path failed[%d].", val);
677 unique_ptr<char, CharDeleter> pFilePath(__pFilePath);
679 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(String(pFilePath.get())), null, E_FILE_NOT_FOUND,
680 "[E_FILE_NOT_FOUND] The file corresponding to contentId could not be found.");
682 result r = E_SUCCESS;
684 if (systemType == SYSTEM_TYPE_IMAGE)
686 unique_ptr<ImageContentInfo> pImageContentInfo(new (nothrow) ImageContentInfo);
687 SysTryReturn(NID_CNT, pImageContentInfo != null, null, E_OUT_OF_MEMORY,
688 "[E_OUT_OF_MEMORY] The memory is insufficient.");
691 ContentInfo::_ContentData* pContentData = pImageContentInfo->GetContentData();
692 SysTryReturn(NID_CNT, pContentData != null, null, E_OUT_OF_MEMORY,
693 "[E_OUT_OF_MEMORY] The memory is insufficient.");
695 // Get image metadata
696 ImageContentInfo::_ImageContentData* pImageContentData = pImageContentInfo->GetImageContentData();
697 SysTryReturn(NID_CNT, pImageContentData != null, null, E_OUT_OF_MEMORY,
698 "[E_OUT_OF_MEMORY] The memory is insufficient.");
701 // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
702 r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, pImageContentData);
703 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
705 return pImageContentInfo.release();
707 else if (systemType == SYSTEM_TYPE_SOUND || systemType == SYSTEM_TYPE_MUSIC)
709 unique_ptr<AudioContentInfo> pAudioContentInfo(new (nothrow) AudioContentInfo);
710 SysTryReturn(NID_CNT, pAudioContentInfo != null, null, E_OUT_OF_MEMORY,
711 "[E_OUT_OF_MEMORY] The memory is insufficient.");
713 ContentInfo::_ContentData* pContentData = pAudioContentInfo->GetContentData();
714 SysTryReturn(NID_CNT, pContentData != null, null, E_OUT_OF_MEMORY,
715 "[E_OUT_OF_MEMORY] The memory is insufficient.");
717 AudioContentInfo::_AudioContentData* pAudioContentData = pAudioContentInfo->GetAudioContentData();
718 SysTryReturn(NID_CNT, pAudioContentData != null, null, E_OUT_OF_MEMORY,
719 "[E_OUT_OF_MEMORY] The memory is insufficient.");
721 r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, pAudioContentData);
722 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
724 return pAudioContentInfo.release();
726 else if (systemType == SYSTEM_TYPE_VIDEO)
728 unique_ptr<VideoContentInfo> pVideoContentInfo(new (nothrow) VideoContentInfo);
729 SysTryReturn(NID_CNT, pVideoContentInfo != null, null, E_OUT_OF_MEMORY,
730 "[E_OUT_OF_MEMORY] The memory is insufficient.");
732 ContentInfo::_ContentData* pContentData = pVideoContentInfo->GetContentData();
733 SysTryReturn(NID_CNT, pContentData != null, null, E_OUT_OF_MEMORY,
734 "[E_OUT_OF_MEMORY] The memory is insufficient.");
736 VideoContentInfo::_VideoContentData* pVideoContentData = pVideoContentInfo->GetVideoContentData();
737 SysTryReturn(NID_CNT, pVideoContentData != null, null, E_OUT_OF_MEMORY,
738 "[E_OUT_OF_MEMORY] The memory is insufficient.");
740 r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, pVideoContentData);
741 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
743 return pVideoContentInfo.release();
745 else if (systemType == SYSTEM_TYPE_OTHER)
747 unique_ptr<OtherContentInfo> pOtherContentInfo(new (nothrow) OtherContentInfo);
748 SysTryReturn(NID_CNT, pOtherContentInfo != null, null, E_OUT_OF_MEMORY,
749 "[E_OUT_OF_MEMORY] The memory is insufficient.");
751 ContentInfo::_ContentData* pContentData = pOtherContentInfo->GetContentData();
752 SysTryReturn(NID_CNT, pContentData != null, null, E_OUT_OF_MEMORY,
753 "[E_OUT_OF_MEMORY] The memory is insufficient.");
755 r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, null);
756 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
758 return pOtherContentInfo.release();
762 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] Unsupported type");
774 // E_PRIVILEGE_DENIED(in public)
777 _ContentManagerImpl::UpdateContent(const ContentInfo& contentInfo)
779 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
783 ContentId contentId = contentInfo.GetContentId();
784 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, "The content id is invalid.");
785 SysTryReturnResult(NID_CNT, _FileImpl::IsFileExist(contentInfo.GetContentPath()), E_FILE_NOT_FOUND,
786 "The file corresponding to contentInfo could not be found.");
788 // Get common data from ContentInfo class
789 ContentInfo::_ContentData* pContentData = (const_cast <ContentInfo*>(&contentInfo))->GetContentData();
790 SysTryReturnResult(NID_CNT, pContentData != null, E_INVALID_ARG, "pContentData is null.");
792 // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SYSTEM, E_SERVICE_BUSY
793 result r = this->UpdateDataToDatabase(pContentData);
794 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "UpdateDataToDatabase failed.");
806 // E_PRIVILEGE_DENIED(in public)
807 // - E_ILLEGAL_ACCESS
810 _ContentManagerImpl::DeleteContent(const ContentId& contentId)
812 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
816 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, "The contentId is invalid.");
818 unique_ptr<char[]> pContentId(_StringConverter::CopyToCharArrayN(contentId.ToString()));
819 SysTryReturnResult(NID_CNT, pContentId != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
821 result r = E_SUCCESS;
823 media_info_h tempMediaInfo = null;
824 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
826 val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
827 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
828 "media_info_get_media_from_db failed[%d].", val);
830 pMediaInfo.reset(tempMediaInfo);
832 char* __pContentPath = null;
834 val = media_info_get_file_path(pMediaInfo.get(), &__pContentPath);
835 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
836 "media_info_get_file_path failed[%d].", val);
838 unique_ptr<char, CharDeleter> pContentPath(__pContentPath);
840 String contentPath = String(pContentPath.get());
841 SysTryReturnResult(NID_CNT, _FileImpl::IsFileExist(contentPath), E_FILE_NOT_FOUND,
842 "The file corresponding to contentId could not be found.");
844 val = media_info_delete_from_db(pContentId.get());
845 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
846 "media_info_delete_From_db failed[%d].", val);
848 r = _FileImpl::Remove(contentPath);
849 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The file is not deleted.");
856 // E_OBJ_ALREADY_EXIST
860 _ContentManagerImpl::AddContentUpdateEventListener(IContentUpdateEventListener& listener)
864 SysTryReturnResult(NID_CNT, GetListener() == null, E_OBJ_ALREADY_EXIST, "IContentUpdateEventListener is already set.");
866 SetListener(&listener);
868 int val = media_content_set_db_updated_cb(OnContentUpdateCompleted, this);
869 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "media_content_set_db_updated_cb failed[%d].", val);
880 _ContentManagerImpl::RemoveContentUpdateEventListener(IContentUpdateEventListener& listener)
884 SysTryReturnResult(NID_CNT, GetListener() == &listener, E_OBJ_NOT_FOUND, "The input listener is not equal to the registered listener.");
886 int val = media_content_unset_db_updated_cb();
887 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "media_content_unset_db_updated_cb failed[%d].", val);
899 // E_PRIVILEGE_DENIED(in public)
902 _ContentManagerImpl::ScanFile(const Tizen::Base::String& contentPath)
906 SysSecureLog(NID_CNT, "The scan path is [%ls].", contentPath.GetPointer());
908 unique_ptr<char[]> pContentPath(_StringConverter::CopyToCharArrayN(contentPath));
909 SysTryReturnResult(NID_CNT, pContentPath, E_SYSTEM, "pContentPath is NULL.");
911 int val = media_content_connect();
912 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The connection failed[%d].", val);
914 val = media_content_scan_file(pContentPath.get());
915 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val), "media_content_scan_file failed[%d].", val);
917 val = media_content_disconnect();
918 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The disconnection failed[%d].", val);
928 // E_PRIVILEGE_DENIED(in public)
931 _ContentManagerImpl::ScanDirectory(const Tizen::Base::String& directoryPath, bool recursive, IContentScanListener* pListener, RequestId& reqId)
935 SysLog(NID_CNT, "The scan path is [%ls].", directoryPath.GetPointer());
937 unique_ptr<char[]> pDirPath(_StringConverter::CopyToCharArrayN(directoryPath));
938 SysTryReturnResult(NID_CNT, pDirPath, E_SYSTEM, "pDirPath is NULL.");
940 int val = media_content_connect();
941 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The connection failed[%d].", val);
943 unique_ptr< ScanResult > pScanResult(new (nothrow) ScanResult);
944 SysTryReturnResult(NID_CNT, pScanResult != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
948 pScanResult->scanPath = directoryPath;
949 pScanResult->pScanListener = pListener;
950 pScanResult->requestId = reqId;
952 val = media_content_scan_folder(pDirPath.get(), recursive, OnScanCompleted, pScanResult.release());
953 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val), "media_content_scan_folder failed[%d].", val);
966 _ContentManagerImpl::UpdateDataToDatabase(const ContentInfo::_ContentData* pContentData) const
970 SysTryReturnResult(NID_CNT, pContentData != null, E_INVALID_ARG, "pContentData is null.");
972 media_info_h tempMediaInfo = null;
973 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
974 unique_ptr<char[]> pContentId(_StringConverter::CopyToCharArrayN((pContentData->contentId).ToString()));
975 SysTryReturnResult(NID_CNT, pContentId != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
977 int val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
978 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
979 "media_info_get_media_from_db failed[%d].", val);
981 pMediaInfo.reset(tempMediaInfo);
983 result r = E_SUCCESS;
984 unique_ptr<char[]> pValue(null);
986 if (pContentData->pAuthor != null)
988 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pAuthor)));
989 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
991 val = media_info_set_author(pMediaInfo.get(), pValue.get());
992 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
993 "media_info_set_author failed[%d].", val);
995 if (pContentData->pCategory != null)
997 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pCategory)));
998 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1000 val = media_info_set_category(pMediaInfo.get(), pValue.get());
1001 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1002 "media_info_set_category failed[%d].", val);
1004 if (pContentData->pContentName != null)
1006 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pContentName)));
1007 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1009 val = media_info_set_content_name(pMediaInfo.get(), pValue.get());
1010 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1011 "media_info_set_content_name failed[%d].", val);
1013 if (pContentData->pDescription != null)
1015 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pDescription)));
1016 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1018 val = media_info_set_description(pMediaInfo.get(), pValue.get());
1019 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1020 "media_info_set_description failed[%d].", val);
1022 if (pContentData->pKeyword != null)
1024 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pKeyword)));
1025 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1027 val = media_info_set_keyword(pMediaInfo.get(), pValue.get());
1028 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1029 "media_info_set_keyword failed[%d].", val);
1031 if (pContentData->pLocationTag != null)
1033 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pLocationTag)));
1034 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1036 val = media_info_set_location_tag(pMediaInfo.get(), pValue.get());
1037 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1038 "media_info_set_location_tag failed[%d].", val);
1040 if (pContentData->pProvider != null)
1042 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pProvider)));
1043 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1045 val = media_info_set_provider(pMediaInfo.get(), pValue.get());
1046 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1047 "media_info_set_provider failed[%d].", val);
1049 if (pContentData->pRating != null)
1051 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pRating)));
1052 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1054 val = media_info_set_age_rating(pMediaInfo.get(), pValue.get());
1055 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1056 "media_info_set_age_rating failed[%d].", val);
1058 if (Double::Compare(pContentData->latitude, DEFAULT_COORDINATE) != 0 &&
1059 Double::Compare(pContentData->longitude, DEFAULT_COORDINATE) != 0)
1061 val = media_info_set_latitude(pMediaInfo.get(), pContentData->latitude);
1062 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1063 "media_info_set_latitude failed[%d].", val);
1065 val = media_info_set_longitude(pMediaInfo.get(), pContentData->longitude);
1066 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1067 "media_info_set_longitude failed[%d].", val);
1069 if (Double::Compare(pContentData->altitude, DEFAULT_COORDINATE) != 0)
1071 val = media_info_set_altitude(pMediaInfo.get(), pContentData->altitude);
1072 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1073 "media_info_set_altitude failed[%d].", val);
1077 val = media_info_update_to_db(pMediaInfo.get());
1078 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1079 "media_info_update_to_db failed[%d].", val);
1092 _ContentManagerImpl::SaveDataToDatabase(const media_info_h pMediaInfo,
1093 ContentInfo::_ContentData* pContentData) const
1097 SysTryReturn(NID_CNT, pContentData != null, UuId::GetInvalidUuId(), E_INVALID_ARG,
1098 "[E_INVALID_ARG] pContentData is null.");
1100 String mimeType(L"");
1101 String extension = _FileImpl::GetFileExtension(pContentData->contentPath);
1102 result r = GetLastResult();
1105 SysLog(NID_CNT, "[%s] Failed to perform GetFileExtension operation.", GetErrorMessage(r));
1107 unique_ptr<char[]> pTempPath(_StringConverter::CopyToCharArrayN(pContentData->contentPath));
1108 SysTryReturn(NID_CNT, pTempPath != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1109 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1111 char tempType[255] = {0, };
1112 int ret = aul_get_mime_from_file(pTempPath.get(), tempType, sizeof(tempType));
1113 SysTryReturn(NID_CNT, ret == AUL_R_OK, UuId::GetInvalidUuId(), E_INVALID_ARG,
1114 "[E_INVALID_ARG] Failed to perform aul_get_mime_from_file operation.");
1116 r = mimeType.Append(tempType);
1117 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1118 "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
1121 // If the content format is JPG and it has GPS data, it will be saved in database automatically.
1122 if (extension == L"jpg" || extension == L"jpeg" || extension == L"JPG" || extension == L"JPEG" || mimeType.Contains(L"jpeg"))
1124 SysLog(NID_CNT, "The format of content is jpg.");
1126 ImageMetadata* pImageMetadata = _ContentManagerUtilImpl::GetImageMetaN(pContentData->contentPath, true);
1127 if (pImageMetadata != null)
1129 pContentData->latitude = pImageMetadata->GetLatitude();
1130 pContentData->longitude = pImageMetadata->GetLongitude();
1132 delete pImageMetadata;
1137 unique_ptr<char[]> pStr(null);
1139 if (pContentData->pAuthor != null)
1141 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pAuthor)));
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_author(pMediaInfo, pStr.get());
1146 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1147 "media_info_set_author failed[%d].", val);
1149 if (pContentData->pCategory != null)
1151 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pCategory)));
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_category(pMediaInfo, pStr.get());
1156 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1157 "media_info_set_category failed[%d].", val);
1159 if (pContentData->pContentName != null)
1161 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pContentName)));
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_content_name(pMediaInfo, pStr.get());
1166 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1167 "media_info_set_content_name failed[%d].", val);
1169 if (pContentData->pDescription != null)
1171 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pDescription)));
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_description(pMediaInfo, pStr.get());
1176 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1177 "media_info_set_description failed[%d].", val);
1179 if (pContentData->pKeyword != null)
1181 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pKeyword)));
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_keyword(pMediaInfo, pStr.get());
1186 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1187 "media_info_set_keyword failed[%d].", val);
1189 if (pContentData->pLocationTag != null)
1191 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pLocationTag)));
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_location_tag(pMediaInfo, pStr.get());
1196 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1197 "media_info_set_location_tag failed[%d].", val);
1199 if (pContentData->pProvider != null)
1201 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pProvider)));
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_provider(pMediaInfo, pStr.get());
1206 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1207 "media_info_set_provider failed[%d].", val);
1209 if (pContentData->pRating != null)
1211 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pRating)));
1212 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1213 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1215 val = media_info_set_age_rating(pMediaInfo, pStr.get());
1216 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1217 "media_info_set_age_rating failed[%d].", val);
1219 if (Double::Compare(pContentData->latitude, DEFAULT_COORDINATE) != 0 &&
1220 Double::Compare(pContentData->longitude, DEFAULT_COORDINATE) != 0)
1222 val = media_info_set_latitude(pMediaInfo, pContentData->latitude);
1223 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1224 "media_info_set_latitude failed[%d].", val);
1226 val = media_info_set_longitude(pMediaInfo, pContentData->longitude);
1227 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1228 "media_info_set_longitude failed[%d].", val);
1230 if (Double::Compare(pContentData->altitude, DEFAULT_COORDINATE) != 0)
1232 val = media_info_set_altitude(pMediaInfo, pContentData->altitude);
1233 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1234 "media_info_set_altitude failed[%d].", val);
1238 val = media_info_update_to_db(pMediaInfo);
1239 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1240 "media_info_update_to_db failed[%d].", val);
1242 char* __pMediaId = null;
1243 unique_ptr<char, CharDeleter> pMediaId(null);
1245 val = media_info_get_media_id(pMediaInfo, &__pMediaId);
1246 if (__pMediaId != null)
1248 pMediaId.reset(__pMediaId);
1252 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1253 "media_info_get_media_id failed[%d].", val);
1256 String contentId(pMediaId.get());
1258 r = UuId::Parse(contentId, pContentData->contentId);
1259 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_INVALID_ARG,
1260 "[E_INVALID_ARG] UuId::Parse failed.");
1262 return pContentData->contentId;
1273 _ContentManagerImpl::MakeContentInfo(const media_info_h pMediaInfo, ContentInfo::_ContentData* pContentData,
1274 int systemType, void* pMetadata) const
1278 if (systemType != SYSTEM_TYPE_OTHER)
1280 SysTryReturnResult(NID_CNT, pMediaInfo != null && pContentData != null && pMetadata != null, E_INVALID_ARG,
1281 "The specified parameter is invalid.");
1283 else // There is no metadata in Other type
1285 SysTryReturnResult(NID_CNT, pMediaInfo != null && pContentData != null, E_INVALID_ARG,
1286 "The specified parameter is invalid.");
1289 result r = E_SUCCESS;
1290 char* __pStrValue = null;
1291 unique_ptr<char, CharDeleter> pStrValue(null);
1294 int val = media_info_get_media_id(pMediaInfo, &__pStrValue);
1295 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1296 "media_info_get_media_id failed[%d].", val);
1298 if (__pStrValue != null)
1300 pStrValue.reset(__pStrValue);
1302 String strContentId(pStrValue.get());
1304 r = UuId::Parse(strContentId, pContentData->contentId);
1305 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The content id can not be parsed.");
1307 SysLog(NID_CNT, "INFO: contentId[%ls]", strContentId.GetPointer());
1311 val = media_info_get_file_path(pMediaInfo, &__pStrValue);
1312 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1313 "media_info_get_file_path failed[%d].", val);
1315 if (__pStrValue != null)
1317 pStrValue.reset(__pStrValue);
1319 String strFilePath(pStrValue.get());
1321 // If the api version is 2.0, the content path has to be changed.
1322 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
1324 if (strFilePath.StartsWith(Environment::GetMediaPath(), 0))
1326 r = strFilePath.Replace(Environment::GetMediaPath(), OSP_MEDIA_PHONE);
1327 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The content path is not changed.");
1329 else if (strFilePath.StartsWith(Environment::GetExternalStoragePath(), 0))
1331 r = strFilePath.Replace(Environment::GetExternalStoragePath(), OSP_MEDIA_MMC);
1332 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Replace failed.");
1336 SysLogException(NID_CNT, E_INVALID_ARG,
1337 "[E_INVALID_ARG] The content path is not supported.");
1338 return E_INVALID_ARG;
1342 pContentData->contentPath = strFilePath;
1344 SysSecureLog(NID_CNT, "INFO: contentPath[%ls]", strFilePath.GetPointer());
1348 val = media_info_get_mime_type(pMediaInfo, &__pStrValue);
1349 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1350 "media_info_get_mime_type failed[%d].", val);
1352 if (__pStrValue != null)
1354 pStrValue.reset(__pStrValue);
1356 pContentData->mimeType = pStrValue.get();
1358 SysLog(NID_CNT, "INFO: mimeType[%ls]", (pContentData->mimeType).GetPointer());
1362 unsigned long long longlongValue = 0;
1363 val = media_info_get_size(pMediaInfo, &longlongValue);
1364 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1365 "media_info_get_size failed[%d].", val);
1366 pContentData->contentSize = longlongValue;
1367 SysLog(NID_CNT, "INFO: contentSize[%llu]", longlongValue);
1370 media_content_storage_e storageType;
1371 val = media_info_get_storage_type(pMediaInfo, &storageType);
1372 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1373 "media_info_get_storage_type failed[%d].", val);
1374 pContentData->storageType = storageType;
1375 SysLog(NID_CNT, "INFO: storageType[%d]", storageType);
1378 val = media_info_is_drm(pMediaInfo, &(pContentData->isDrm));
1379 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1380 "media_info_is_drm failed[%d].", val);
1381 SysLog(NID_CNT, "INFO: isDrm[%d]", pContentData->isDrm);
1385 val = media_info_get_added_time(pMediaInfo, &time);
1386 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1387 "media_info_get_added_time failed[%d].", val);
1388 r = (pContentData->dateTime).SetValue(1970, 1, 1);
1389 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "SetValue failed.");
1390 r = (pContentData->dateTime).AddSeconds(time);
1391 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "AddSeconds failed.");
1392 SysLog(NID_CNT, "INFO: dateTime[%ls]", ((pContentData->dateTime).ToString()).GetPointer());
1395 val = media_info_get_thumbnail_path(pMediaInfo, &__pStrValue);
1396 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1397 "media_info_get_thumbnail_path failed[%d].", val);
1399 if (__pStrValue != null)
1401 pStrValue.reset(__pStrValue);
1403 pContentData->pThumbnailPath = new (nothrow) String(pStrValue.get());
1405 SysLog(NID_CNT, "INFO: thumbnailPath[%ls]", (*pContentData->pThumbnailPath).GetPointer());
1409 val = media_info_get_author(pMediaInfo, &__pStrValue);
1410 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1411 "media_info_get_author failed[%d].", val);
1413 if (__pStrValue != null)
1415 pStrValue.reset(__pStrValue);
1417 pContentData->pAuthor = new (nothrow) String(pStrValue.get());
1419 SysLog(NID_CNT, "INFO: author[%ls]", (*pContentData->pAuthor).GetPointer());
1423 val = media_info_get_category(pMediaInfo, &__pStrValue);
1424 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1425 "media_info_get_category failed[%d].", val);
1427 if (__pStrValue != null)
1429 pStrValue.reset(__pStrValue);
1431 pContentData->pCategory = new (nothrow) String(pStrValue.get());
1433 SysLog(NID_CNT, "INFO: category[%ls]", (*pContentData->pCategory).GetPointer());
1437 val = media_info_get_content_name(pMediaInfo, &__pStrValue);
1438 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1439 "media_info_get_content_name failed[%d].", val);
1441 if (__pStrValue != null)
1443 pStrValue.reset(__pStrValue);
1445 pContentData->pContentName = new (nothrow) String(pStrValue.get());
1447 SysSecureLog(NID_CNT, "INFO: contentName[%ls]", (*pContentData->pContentName).GetPointer());
1451 val = media_info_get_description(pMediaInfo, &__pStrValue);
1452 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1453 "media_info_get_description failed[%d].", val);
1455 if (__pStrValue != null)
1457 pStrValue.reset(__pStrValue);
1459 pContentData->pDescription = new (nothrow) String(pStrValue.get());
1461 SysLog(NID_CNT, "INFO: description[%ls]", (*pContentData->pDescription).GetPointer());
1465 val = media_info_get_keyword(pMediaInfo, &__pStrValue);
1466 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1467 "media_info_get_keyword failed[%d].", val);
1469 if (__pStrValue != null)
1471 pStrValue.reset(__pStrValue);
1473 pContentData->pKeyword = new (nothrow) String(pStrValue.get());
1475 SysLog(NID_CNT, "INFO: keyword[%ls]", (*pContentData->pKeyword).GetPointer());
1479 val = media_info_get_location_tag(pMediaInfo, &__pStrValue);
1480 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1481 "media_info_get_location_tag failed[%d].", val);
1483 if (__pStrValue != null)
1485 pStrValue.reset(__pStrValue);
1487 pContentData->pLocationTag = new (nothrow) String(pStrValue.get());
1489 SysSecureLog(NID_CNT, "INFO: locationTag[%ls]", (*pContentData->pLocationTag).GetPointer());
1493 val = media_info_get_provider(pMediaInfo, &__pStrValue);
1494 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1495 "media_info_get_provider failed[%d].", val);
1497 if (__pStrValue != null)
1499 pStrValue.reset(__pStrValue);
1501 pContentData->pProvider = new (nothrow) String(pStrValue.get());
1503 SysLog(NID_CNT, "INFO: provider[%ls]", (*pContentData->pProvider).GetPointer());
1507 val = media_info_get_age_rating(pMediaInfo, &__pStrValue);
1508 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1509 "media_info_get_age_rating failed[%d].", val);
1511 if (__pStrValue != null)
1513 pStrValue.reset(__pStrValue);
1515 pContentData->pRating = new (nothrow) String(pStrValue.get());
1517 SysLog(NID_CNT, "INFO: rating[%ls]", (*pContentData->pRating).GetPointer());
1521 double doubleValue = 0;
1522 val = media_info_get_latitude(pMediaInfo, &doubleValue);
1523 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1524 "media_info_get_latitude failed[%d].", val);
1526 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1528 pContentData->latitude = doubleValue;
1530 SysSecureLog(NID_CNT, "INFO: latitude[%f]", pContentData->latitude);
1532 val = media_info_get_longitude(pMediaInfo, &doubleValue);
1533 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1534 "media_info_get_longitude failed[%d].", val);
1536 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1538 pContentData->longitude = doubleValue;
1540 SysSecureLog(NID_CNT, "INFO: longitude[%f]", pContentData->longitude);
1542 val = media_info_get_altitude(pMediaInfo, &doubleValue);
1543 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1544 "media_info_get_altitude failed[%d].", val);
1546 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1548 pContentData->altitude = doubleValue;
1550 SysLog(NID_CNT, "INFO: altitude[%f]", pContentData->altitude);
1554 // contentType and metadata
1555 if (systemType == SYSTEM_TYPE_IMAGE)
1557 image_meta_h __pImageMeta = null;
1558 unique_ptr<image_meta_h, ImageMetaDeleter> pImageMeta(null);
1560 pContentData->contentType = CONTENT_TYPE_IMAGE;
1561 SysLog(NID_CNT, "META: ContentType[%d]", pContentData->contentType);
1563 val = media_info_get_image(pMediaInfo, &__pImageMeta);
1564 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1565 "media_info_get_image failed[%d].", val);
1567 pImageMeta.reset(&__pImageMeta);
1570 val = image_meta_get_width(*(pImageMeta.get()), &intValue);
1571 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1572 "image_meta_get_width failed[%d].", val);
1574 (static_cast<ImageContentInfo::_ImageContentData*>(pMetadata))->width = intValue;
1575 SysLog(NID_CNT, "META: width[%d]", intValue);
1578 val = image_meta_get_height(*(pImageMeta.get()), &intValue);
1579 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1580 "image_meta_get_height failed[%d].", val);
1582 (static_cast<ImageContentInfo::_ImageContentData*>(pMetadata))->height = intValue;
1583 SysLog(NID_CNT, "META: height[%d]", intValue);
1586 media_content_orientation_e orientation;
1587 val = image_meta_get_orientation(*(pImageMeta.get()), &orientation);
1588 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1589 "image_meta_get_orientation failed[%d].", val);
1591 (static_cast<ImageContentInfo::_ImageContentData*>(pMetadata))->orientationType =
1592 static_cast<ImageOrientationType>(orientation);
1593 SysLog(NID_CNT, "META: orientation[%d]", orientation);
1596 val = media_info_get_display_name(pMediaInfo, &__pStrValue);
1597 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1598 "media_info_get_display_name failed[%d].", val);
1600 if (__pStrValue != null)
1602 pStrValue.reset(__pStrValue);
1606 String strTitle(pStrValue.get());
1608 r = strTitle.LastIndexOf(L'.', strTitle.GetLength() - 1, pos);
1611 r = strTitle.SubString(0, pos, fileName);
1612 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The title is invalid.");
1616 // Without extension
1618 fileName = strTitle;
1621 (static_cast<ImageContentInfo::_ImageContentData*>(pMetadata))->title = fileName;
1623 SysLog(NID_CNT, "META: title[%ls]", fileName.GetPointer());
1626 else if (systemType == SYSTEM_TYPE_SOUND || systemType == SYSTEM_TYPE_MUSIC)
1628 audio_meta_h __pAudioMeta = null;
1629 unique_ptr<audio_meta_h, AudioMetaDeleter> pAudioMeta(null);
1631 pContentData->contentType = CONTENT_TYPE_AUDIO;
1632 SysLog(NID_CNT, "META: ContentType[%d]", pContentData->contentType);
1634 val = media_info_get_audio(pMediaInfo, &__pAudioMeta);
1635 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1636 "media_info_get_audio failed[%d].", val);
1638 pAudioMeta.reset(&__pAudioMeta);
1641 val = audio_meta_get_bit_rate(*(pAudioMeta.get()), &intValue);
1642 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1643 "audio_meta_get_bit_rate failed[%d].", val);
1645 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->bitrate = intValue;
1646 SysLog(NID_CNT, "META: bitrate[%d]", intValue);
1649 val = audio_meta_get_year(*(pAudioMeta.get()), &__pStrValue);
1650 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1651 "audio_meta_get_year failed[%d].", val);
1653 if (__pStrValue != null)
1655 pStrValue.reset(__pStrValue);
1657 String strYear(pStrValue.get());
1659 if (strYear.CompareTo(L"Unknown") != 0)
1661 r = Integer::Parse(strYear, intValue);
1664 // It is one of the metadata. If error occurs, skip it for other metadata.
1667 SysLog(NID_CNT, "META: releaseYear - invalid data[%ls]", strYear.GetPointer());
1670 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->releaseYear = intValue;
1671 SysLog(NID_CNT, "META: releaseYear[%d]", intValue);
1676 val = audio_meta_get_title(*(pAudioMeta.get()), &__pStrValue);
1677 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1678 "audio_meta_get_title failed[%d].", val);
1680 if (__pStrValue != null)
1682 pStrValue.reset(__pStrValue);
1684 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pTitle =
1685 new (nothrow) String(pStrValue.get());
1687 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
1691 val = audio_meta_get_album(*(pAudioMeta.get()), &__pStrValue);
1692 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1693 "audio_meta_get_album failed[%d].", val);
1695 if (__pStrValue != null)
1697 pStrValue.reset(__pStrValue);
1699 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pAlbumName =
1700 new (nothrow) String(pStrValue.get());
1702 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
1706 val = audio_meta_get_artist(*(pAudioMeta.get()), &__pStrValue);
1707 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1708 "audio_meta_get_artist failed[%d].", val);
1710 if (__pStrValue != null)
1712 pStrValue.reset(__pStrValue);
1714 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pArtist =
1715 new (nothrow) String(pStrValue.get());
1717 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
1721 val = audio_meta_get_composer(*(pAudioMeta.get()), &__pStrValue);
1722 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1723 "audio_meta_get_composer failed[%d].", val);
1725 if (__pStrValue != null)
1727 pStrValue.reset(__pStrValue);
1729 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pComposer =
1730 new (nothrow) String(pStrValue.get());
1732 SysLog(NID_CNT, "META: composer[%ls]", (String(pStrValue.get())).GetPointer());
1736 val = audio_meta_get_genre(*(pAudioMeta.get()), &__pStrValue);
1737 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1738 "audio_meta_get_genre failed[%d].", val);
1740 if (__pStrValue != null)
1742 pStrValue.reset(__pStrValue);
1744 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pGenre =
1745 new (nothrow) String(pStrValue.get());
1747 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
1751 val = audio_meta_get_copyright(*(pAudioMeta.get()), &__pStrValue);
1752 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1753 "audio_meta_get_copyright failed[%d].", val);
1755 if (__pStrValue != null)
1757 pStrValue.reset(__pStrValue);
1759 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pCopyright =
1760 new (nothrow) String(pStrValue.get());
1762 SysLog(NID_CNT, "META: copyright[%ls]", (String(pStrValue.get())).GetPointer());
1766 val = audio_meta_get_track_num(*(pAudioMeta.get()), &__pStrValue);
1767 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1768 "audio_meta_get_track_num failed[%d].", val);
1770 if (__pStrValue != null)
1772 pStrValue.reset(__pStrValue);
1774 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pTrackInfo
1775 = new (nothrow) String(pStrValue.get());
1777 SysLog(NID_CNT, "META: trackInfo[%ls]", (String(pStrValue.get())).GetPointer());
1781 val = audio_meta_get_duration(*(pAudioMeta.get()), &intValue);
1782 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1783 "audio_meta_get_duration failed[%d].", val);
1785 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->duration = intValue;
1786 SysLog(NID_CNT, "META: duration[%d]", intValue);
1789 else if (systemType == MEDIA_CONTENT_TYPE_VIDEO)
1791 video_meta_h __pVideoMeta = null;
1792 unique_ptr<video_meta_h, VideoMetaDeleter> pVideoMeta(null);
1794 pContentData->contentType = CONTENT_TYPE_VIDEO;
1795 SysLog(NID_CNT, "META: ContentType[%d]", pContentData->contentType);
1797 val = media_info_get_video(pMediaInfo, &__pVideoMeta);
1798 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1799 "media_info_get_video failed[%d].", val);
1801 pVideoMeta.reset(&__pVideoMeta);
1804 val = video_meta_get_width(*(pVideoMeta.get()), &intValue);
1805 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1806 "video_meta_get_width failed[%d].", val);
1808 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->width = intValue;
1809 SysLog(NID_CNT, "META: width[%d]", intValue);
1812 val = video_meta_get_height(*(pVideoMeta.get()), &intValue);
1813 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1814 "video_meta_get_height failed[%d].", val);
1816 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->height = intValue;
1817 SysLog(NID_CNT, "META: height[%d]", intValue);
1819 // Get from metadata extractor (framerate, audio bitrate, video bitrate)
1822 val = video_meta_get_artist(*(pVideoMeta.get()), &__pStrValue);
1823 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1824 "video_meta_get_artist failed[%d].", val);
1826 if (__pStrValue != null)
1828 pStrValue.reset(__pStrValue);
1830 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->pArtist
1831 = new (nothrow) String(pStrValue.get());
1833 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
1837 val = video_meta_get_genre(*(pVideoMeta.get()), &__pStrValue);
1838 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1839 "video_meta_get_genre failed[%d].", val);
1841 if (__pStrValue != null)
1843 pStrValue.reset(__pStrValue);
1845 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->pGenre
1846 = new (nothrow) String(pStrValue.get());
1848 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
1852 val = video_meta_get_title(*(pVideoMeta.get()), &__pStrValue);
1853 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1854 "video_meta_get_title failed[%d].", val);
1856 if (__pStrValue != null)
1858 pStrValue.reset(__pStrValue);
1860 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->pTitle
1861 = new (nothrow) String(pStrValue.get());
1863 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
1867 val = video_meta_get_album(*(pVideoMeta.get()), &__pStrValue);
1868 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1869 "video_meta_get_album failed[%d].", val);
1871 if (__pStrValue != null)
1873 pStrValue.reset(__pStrValue);
1875 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->pAlbumName
1876 = new (nothrow) String(pStrValue.get());
1878 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
1882 val = video_meta_get_duration(*(pVideoMeta.get()), &intValue);
1883 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1884 "video_meta_get_duration failed[%d].", val);
1886 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->duration = intValue;
1887 SysLog(NID_CNT, "META: duration[%d]", intValue);
1889 else if (systemType == SYSTEM_TYPE_OTHER)
1891 pContentData->contentType = CONTENT_TYPE_OTHER;
1892 SysLog(NID_CNT, "META: ContentType[%d]", pContentData->contentType);
1899 _ContentManagerImpl::VerifyHomeFilePathCompatibility(const String& contentPath) const
1901 if (!_AppInfo::IsOspCompat())
1903 if (contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0))
1905 SysLogException(NID_CNT, E_INVALID_ARG,
1906 "[E_INVALID_ARG] /Home/ or /HomeExt/ is not supported from Tizen 2.0.");
1909 if (!(contentPath.StartsWith(App::App::GetInstance()->GetAppRootPath(), 0) ||
1910 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
1912 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] The path is not supported.");
1918 SysTryReturn(NID_CNT, contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0),
1919 false, E_INVALID_ARG, "[E_INVALID_ARG] The path should start with /Home or /HomeExt.");
1926 _ContentManagerImpl::VerifyMediaFilePathCompatibility(const String& contentPath, bool checkVersion) const
1930 result r = E_SUCCESS;
1932 if (!_AppInfo::IsOspCompat())
1934 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0) || contentPath.StartsWith(OSP_MEDIA_MMC, 0))
1936 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] /Media or /Storagecard/Media is not supported.");
1939 if (!(contentPath.StartsWith(Environment::GetMediaPath(), 0) ||
1940 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
1942 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] This path is not supported.");
1949 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0))
1951 r = (const_cast<String*>(&contentPath))->Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
1952 SysTryReturn(NID_CNT, !IsFailed(r), false, E_INVALID_ARG, "[E_INVALID_ARG] Replace failed.");
1954 else if (contentPath.StartsWith(OSP_MEDIA_MMC, 0))
1956 r = (const_cast<String*>(&contentPath))->Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
1957 SysTryReturn(NID_CNT, !IsFailed(r), false, E_INVALID_ARG, "[E_INVALID_ARG] Replace failed.");
1961 // CreateContent(const ByteBuffer&, ...) and CreateContent (const Sring&, ...) can receive old path like /Media/.
1962 // but CreateContent(const ContentInfo&) always receive new path like /opt/media/ because ContentInfo class convert the path from /Media/ to /opt/media.
1965 SysLogException(NID_CNT, E_INVALID_ARG,
1966 "[E_INVALID_ARG] The path should start with /Home, /Media, or /Storagecard/Media.");
1976 _ContentManagerImpl::SetListener(IContentUpdateEventListener* pListener)
1978 __pListener = pListener;
1981 IContentUpdateEventListener*
1982 _ContentManagerImpl::GetListener(void) const