2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 * @file FCnt_ContentManagerImpl.cpp
18 * @brief This is the implementation file for the %_ContentManagerImpl class.
20 * This file contains implementation of the %_ContentManagerImpl class.
24 #include <FBaseSysLog.h>
26 #include <FBaseInteger.h>
27 #include <FBaseByteBuffer.h>
28 #include <FCntContentManager.h>
29 #include <FCntImageContentInfo.h>
30 #include <FCntAudioContentInfo.h>
31 #include <FCntVideoContentInfo.h>
32 #include <FCntOtherContentInfo.h>
33 #include <FCntImageMetadata.h>
34 #include <FCntAudioMetadata.h>
35 #include <FCntVideoMetadata.h>
36 #include <FCntIContentScanListener.h>
37 #include <FCntIContentUpdateEventListener.h>
38 #include <FIoDirectory.h>
39 #include <FSysEnvironment.h>
40 #include <FCnt_ContentManagerImpl.h>
41 #include <FCnt_ContentManagerUtilImpl.h>
42 #include <FBase_StringConverter.h>
43 #include <FIo_FileImpl.h>
44 #include <FApp_AppInfo.h>
46 using namespace Tizen::Base;
47 using namespace Tizen::Base::Collection;
48 using namespace Tizen::Io;
49 using namespace Tizen::App;
50 using namespace Tizen::System;
53 namespace Tizen { namespace Content
56 static RequestId requestId = 0;
58 static const int SYSTEM_TYPE_IMAGE = 0;
59 static const int SYSTEM_TYPE_VIDEO = 1;
60 static const int SYSTEM_TYPE_SOUND = 2;
61 static const int SYSTEM_TYPE_MUSIC = 3;
62 static const int SYSTEM_TYPE_OTHER = 4;
63 static const double DEFAULT_COORDINATE = -200.0;
65 // For extern declaration in FCntTypes.h
66 const wchar_t OSP_HOME[] = L"/Home/";
67 const wchar_t OSP_HOME_EXT[] = L"/HomeExt/";
68 const wchar_t OSP_MEDIA_PHONE[] = L"/Media/";
69 const wchar_t OSP_MEDIA_MMC[] = L"/Storagecard/Media/";
72 ConvertError(int error)
78 case MEDIA_CONTENT_ERROR_NONE:
82 case MEDIA_CONTENT_ERROR_INVALID_PARAMETER:
86 case MEDIA_CONTENT_ERROR_OUT_OF_MEMORY:
90 case MEDIA_CONTENT_ERROR_DB_BUSY:
94 case MEDIA_CONTENT_ERROR_DB_FAILED:
107 OnScanCompleted(media_content_error_e error, void* user_data)
109 SysLog(NID_CNT, "OnScanCompleted callback method is called.");
112 result r = E_SUCCESS;
113 String scanPath(L"");
114 IContentScanListener* pListener = null;
116 unique_ptr< ScanResult > pScanResult;
118 SysTryLogCatch(NID_CNT, user_data != null, , "OnScanCompleted failed.");
120 pScanResult = unique_ptr< ScanResult >(static_cast< ScanResult* >(user_data));
122 SysTryLogCatch(NID_CNT, pScanResult != null, , "OnScanCompleted failed.");
123 SysTryLogCatch(NID_CNT, pScanResult->pScanListener != null, , "Listener is null. OnScanCompleted succeeded.");
125 scanPath = pScanResult->scanPath;
126 pListener = pScanResult->pScanListener;
127 reqId = pScanResult->requestId;
129 r = ConvertError(error);
131 pListener->OnContentScanCompleted(reqId, scanPath, r);
132 SysLog(NID_CNT, "OnContentScanCompleted fired.");
135 int val = media_content_disconnect();
136 SysTryLog(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, "The disconnection failed[%d].", val);
140 OnContentUpdateCompleted(media_content_error_e error, int pid, media_content_db_update_item_type_e update_item,
141 media_content_db_update_type_e update_type, media_content_type_e media_type, char* uuid, char* path, char* mime_type, void* user_data)
143 SysLog(NID_CNT, "OnContentUpdateCompleted callback method is called.");
145 result r = E_SUCCESS;
147 SysTryLogReturn(NID_CNT, user_data != null, , "OnContentUpdateCompleted failed.");
149 _ContentManagerImpl* pTempManagerImpl = static_cast< _ContentManagerImpl* >(user_data);
151 IContentUpdateEventListener* pListener = pTempManagerImpl->GetListener();
152 SysTryLogReturn(NID_CNT, pListener != null, , "IContentUpdateEventListener is null.");
154 if (error != MEDIA_CONTENT_ERROR_NONE)
161 case MEDIA_ITEM_FILE:
163 ContentType contentType = CONTENT_TYPE_UNKNOWN;
167 case MEDIA_CONTENT_TYPE_IMAGE:
168 contentType = CONTENT_TYPE_IMAGE;
171 case MEDIA_CONTENT_TYPE_VIDEO:
172 contentType = CONTENT_TYPE_VIDEO;
175 case MEDIA_CONTENT_TYPE_SOUND:
177 case MEDIA_CONTENT_TYPE_MUSIC:
178 contentType = CONTENT_TYPE_AUDIO;
181 case MEDIA_CONTENT_TYPE_OTHERS:
182 contentType = CONTENT_TYPE_OTHER;
187 SysLog(NID_CNT, "media_type is invalid.");
194 result res = UuId::Parse(str, contentId);
195 SysTryLogReturn(NID_CNT, !IsFailed(res), , "Failed to parse to the content ID.");
199 case MEDIA_CONTENT_INSERT:
200 pListener->OnContentFileCreated(contentId, contentType, r);
203 case MEDIA_CONTENT_DELETE:
204 pListener->OnContentFileDeleted(contentId, contentType, r);
207 case MEDIA_CONTENT_UPDATE:
208 pListener->OnContentFileUpdated(contentId, contentType, r);
212 SysLog(NID_CNT, "update_type is invalid.");
217 case MEDIA_ITEM_DIRECTORY:
219 String directoryPath(path);
221 pListener->OnContentDirectoryScanCompleted(directoryPath, r);
226 SysLog(NID_CNT, "update_item is invalid.");
230 SysLog(NID_CNT, "Fire the OnContentUpdateCompleted method.");
233 _ContentManagerImpl::_ContentManagerImpl(void)
235 , __isConnected(false)
241 _ContentManagerImpl::~_ContentManagerImpl(void)
243 int val = media_content_disconnect();
244 SysLog(NID_CNT, "media_content_disconnect result[%d].", val);
246 __isConnected = false;
250 _ContentManagerImpl::GetInstance(ContentManager& contentManager)
252 return contentManager.__pImpl;
255 const _ContentManagerImpl*
256 _ContentManagerImpl::GetInstance(const ContentManager& contentManager)
258 return contentManager.__pImpl;
264 // E_OUT_OF_MEMORY(in public)
267 _ContentManagerImpl::Construct(void)
269 SysAssertf(!__isConnected,
270 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
274 int val = media_content_connect();
275 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM,
276 "The connection failed[%d].", val);
278 SysLog(NID_CNT, "media_content_connect result[%d].", val);
280 __isConnected = true;
292 // E_PRIVILEGE_DENIED(in public)
296 _ContentManagerImpl::CreateContent(const ContentInfo& contentInfo)
298 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
302 // Get common data from ContentInfo class
303 ContentInfo::_ContentData* pContentData = (const_cast <ContentInfo*>(&contentInfo))->GetContentData();
304 SysTryReturn(NID_CNT, pContentData != null, UuId::GetInvalidUuId(), E_INVALID_ARG,
305 "[E_INVALID_ARG] pContentData is null.");
307 SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(pContentData->contentPath, true), UuId::GetInvalidUuId(),
308 E_INVALID_ARG, "[E_INVALID_ARG] The contentPath is not compatible.");
309 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(pContentData->contentPath), UuId::GetInvalidUuId(), E_FILE_NOT_FOUND,
310 "[E_FILE_NOT_FOUND] The file corresponding to contentInfo could not be found.");
311 SysTryReturn(NID_CNT, pContentData->contentId == UuId::GetInvalidUuId(), UuId::GetInvalidUuId(),
312 E_INVALID_ARG, "[E_INVALID_ARG] The contentId is not empty.");
314 // Compare the type of input parameter and system
315 ContentType inputType = pContentData->contentType;
316 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(pContentData->contentPath, true);
318 if (inputType != sysType)
320 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
322 SysLogException(NID_CNT, E_INVALID_ARG,
323 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
324 return UuId::GetInvalidUuId();
328 // Save data to database with contentPath.
329 unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(pContentData->contentPath));
330 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
331 "[E_OUT_OF_MEMORY] The memory is insufficient.");
333 media_info_h tempMediaInfo = null;
334 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
336 // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
337 int val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
338 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
339 "The registration to database failed[%d].", val);
341 pMediaInfo.reset(tempMediaInfo);
343 // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
344 ContentId contentId = SaveDataToDatabase(pMediaInfo.get(), pContentData);
345 result r = GetLastResult();
346 SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
347 "[%s] The registration to database failed.", GetErrorMessage(r));
352 // There are two steps(insert and update) for content registration.
353 // If the update failed after inserting, the inserted data SHOULD be deleted from here.
354 val = media_info_delete_from_db(pStr.get());
355 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
357 return UuId::GetInvalidUuId();
364 // E_FILE_ALREADY_EXIST
371 // E_PRIVILEGE_DENIED(in public)
374 _ContentManagerImpl::CreateContent(const ByteBuffer& byteBuffer, const String& destinationPath,
375 const ContentInfo* pContentInfo)
377 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
381 // Check parameters(for length)
382 SysTryReturn(NID_CNT, byteBuffer.GetRemaining() > 0, UuId::GetInvalidUuId(), E_INVALID_ARG,
383 "[E_INVALID_ARG] byteBuffer is invalid.");
385 // Check parameters(for path compatibility)
386 SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(destinationPath, false), UuId::GetInvalidUuId(),
387 E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", destinationPath.GetPointer());
388 SysTryReturn(NID_CNT, !_FileImpl::IsFileExist(destinationPath), UuId::GetInvalidUuId(), E_FILE_ALREADY_EXIST,
389 "[E_FILE_ALREADY_EXIST] The specified file already exists.");
391 // Create a file with bytebuffer
392 unique_ptr<File> pFile(new (nothrow) File);
393 SysTryReturn(NID_CNT, pFile != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
394 "[E_OUT_OF_MEMORY] The memory is insufficient.");
396 // 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
397 result r = pFile->Construct(destinationPath, L"w+");
398 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r,
399 "[%s] The destination file can not be created.", GetErrorMessage(r));
401 _FileImpl* pFileImpl = _FileImpl::GetInstance(*pFile);
402 SysTryReturn(NID_CNT, pFileImpl != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
403 "[E_OUT_OF_MEMORY] The memory is insufficient.");
405 // Exception : E_SUCCESS, E_INVALID_ARG, E_ILLEGAL_ACCESS, E_STORAGE_FULL, E_IO
406 r = pFileImpl->Write(byteBuffer);
407 SysTryReturn(NID_CNT, !(IsFailed(r)), UuId::GetInvalidUuId(), r,
408 "[%s] The data can not be written in the destination file.", GetErrorMessage(r));
410 // for release file pointer
411 delete pFile.release();
415 ContentInfo::_ContentData contentData;
416 ContentInfo::_ContentData* pContentData = null;
417 media_info_h tempMediaInfo = null;
418 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
419 unique_ptr<char[]> pStr(null);
421 if (pContentInfo != null)
423 pContentData = (const_cast <ContentInfo*>(pContentInfo))->GetContentData();
424 SysTryCatch(NID_CNT, pContentData != null, , E_INVALID_ARG, "[E_INVALID_ARG] GetContentData failed.");
426 SysTryCatch(NID_CNT, pContentData->contentId == UuId::GetInvalidUuId(), , E_INVALID_ARG,
427 "[E_INVALID_ARG] The content already exists in database.");
429 // Compare the type of input parameter and system
430 // CheckContentType() need actual file. so it should be checked after creating the file.
431 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
432 ContentType inputType = pContentData->contentType;
434 if (inputType != sysType)
436 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
438 SysLogException(NID_CNT, E_INVALID_ARG,
439 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
444 // Sets the content path
445 (pContentData->contentPath).Clear();
446 pContentData->contentPath = destinationPath;
450 // Set the content path
451 contentData.contentPath = destinationPath;
453 pContentData = &contentData;
456 // Register the content to database directly.
457 pStr.reset(_StringConverter::CopyToCharArrayN(destinationPath));
458 SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
460 val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
461 SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
462 "media_info_insert_to_db failed[%d].", val);
464 pMediaInfo.reset(tempMediaInfo);
466 // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
467 contentId = SaveDataToDatabase(pMediaInfo.get(), pContentData);
469 SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
470 "[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
475 result saveResult = GetLastResult();
477 // If the destination file is made by this method, it should be deleted when error occurs.
478 r = _FileImpl::Remove(destinationPath);
479 SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
481 if (pMediaInfo != null)
483 val = media_info_delete_from_db(pStr.get());
484 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
487 SetLastResult(saveResult);
488 return UuId::GetInvalidUuId();
496 // E_FILE_ALREADY_EXIST
503 // E_PRIVILEGE_DENIED(in public)
506 _ContentManagerImpl::CreateContent(const String& sourcePath, const String& destinationPath, bool deleteSource,
507 const ContentInfo* pContentInfo)
509 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
513 // Check parameters(for type)
514 SysTryReturn(NID_CNT, _FileImpl::GetFileExtension(sourcePath) == _FileImpl::GetFileExtension(destinationPath),
515 UuId::GetInvalidUuId(), E_INVALID_ARG, "[E_INVALID_ARG] There is a mismatch between the type of source and dest path.");
517 // Check parameters(for path compatibility)
518 SysTryReturn(NID_CNT, VerifyHomeFilePathCompatibility(sourcePath), UuId::GetInvalidUuId(), E_INVALID_ARG,
519 "[E_INVALID_ARG] %ls is not compatible.", sourcePath.GetPointer());
520 SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(destinationPath, false), UuId::GetInvalidUuId(),
521 E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", destinationPath.GetPointer());
523 result r = E_SUCCESS;
525 if (deleteSource) // move
527 // 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
528 r = _FileImpl::Move(sourcePath, destinationPath);
529 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Moving the file failed.", GetErrorMessage(r));
533 // 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
534 r = _FileImpl::Copy(sourcePath, destinationPath, true);
535 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Copying the file failed.", GetErrorMessage(r));
540 ContentInfo::_ContentData contentData;
541 ContentInfo::_ContentData* pContentData = null;
542 media_info_h tempMediaInfo = null;
543 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
544 unique_ptr<char[]> pStr(null);
546 if (pContentInfo != null)
548 pContentData = (const_cast <ContentInfo*>(pContentInfo))->GetContentData();
549 SysTryCatch(NID_CNT, pContentData != null, , E_INVALID_ARG, "[E_INVALID_ARG] GetContentData failed.");
551 SysTryCatch(NID_CNT, pContentData->contentId == UuId::GetInvalidUuId(), , E_INVALID_ARG,
552 "[E_INVALID_ARG] The content already exists in database.");
554 // Compare the type of input parameter and system
555 // CheckContentType() need actual file. so it should be checked after creating the file.
556 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
557 ContentType inputType = pContentData->contentType;
559 if (inputType != sysType)
561 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
563 SysLogException(NID_CNT, E_INVALID_ARG,
564 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
569 // Set the content path
570 (pContentData->contentPath).Clear();
571 pContentData->contentPath = destinationPath;
575 // Set the content path
576 contentData.contentPath = destinationPath;
578 pContentData = &contentData;
581 pStr.reset(_StringConverter::CopyToCharArrayN(destinationPath));
582 SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
584 val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
585 SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
586 "media_info_insert_to_db failed[%d].", val);
588 pMediaInfo.reset(tempMediaInfo);
590 contentId = SaveDataToDatabase(pMediaInfo.get(), pContentData);
592 SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
593 "[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
598 result saveResult = GetLastResult();
600 // If the destination file is made by this method, it should be deleted when error occurs.
601 r = _FileImpl::Remove(destinationPath);
602 SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
604 if (pMediaInfo != null)
606 val = media_info_delete_from_db(pStr.get());
607 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
610 SetLastResult(saveResult);
611 return UuId::GetInvalidUuId();
621 // E_PRIVILEGE_DENIED(in public)
624 _ContentManagerImpl::GetContentInfoN(const ContentId& contentId) const
626 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
630 SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), null, E_INVALID_ARG,
631 "[E_INVALID_ARG] The contentId is invalid.");
633 unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(contentId.ToString()));
634 SysTryReturn(NID_CNT, pStr != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
636 media_info_h tempMediaInfo = null;
637 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
638 int val = media_info_get_media_from_db(pStr.get(), &tempMediaInfo);
639 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
640 "media_info_get_media_from_db failed[%d].", val);
642 pMediaInfo.reset(tempMediaInfo);
644 media_content_type_e systemType = MEDIA_CONTENT_TYPE_IMAGE;
645 val = media_info_get_media_type(pMediaInfo.get(), &systemType);
646 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
647 "media_info_get_media_type failed[%d].", val);
649 char* __pFilePath = null;
650 val = media_info_get_file_path(pMediaInfo.get(), &__pFilePath);
651 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
652 "media_info_get_file_path failed[%d].", val);
654 unique_ptr<char, CharDeleter> pFilePath(__pFilePath);
656 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(String(pFilePath.get())), null, E_FILE_NOT_FOUND,
657 "[E_FILE_NOT_FOUND] The file corresponding to contentId could not be found.");
659 result r = E_SUCCESS;
661 if (systemType == SYSTEM_TYPE_IMAGE)
663 unique_ptr<ImageContentInfo> pImageContentInfo(new (nothrow) ImageContentInfo);
664 SysTryReturn(NID_CNT, pImageContentInfo != null, null, E_OUT_OF_MEMORY,
665 "[E_OUT_OF_MEMORY] The memory is insufficient.");
668 ContentInfo::_ContentData* pContentData = pImageContentInfo->GetContentData();
669 SysTryReturn(NID_CNT, pContentData != null, null, E_OUT_OF_MEMORY,
670 "[E_OUT_OF_MEMORY] The memory is insufficient.");
672 // Get image metadata
673 ImageContentInfo::_ImageContentData* pImageContentData = pImageContentInfo->GetImageContentData();
674 SysTryReturn(NID_CNT, pImageContentData != null, null, E_OUT_OF_MEMORY,
675 "[E_OUT_OF_MEMORY] The memory is insufficient.");
678 // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
679 r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, pImageContentData);
680 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
682 return pImageContentInfo.release();
684 else if (systemType == SYSTEM_TYPE_SOUND || systemType == SYSTEM_TYPE_MUSIC)
686 unique_ptr<AudioContentInfo> pAudioContentInfo(new (nothrow) AudioContentInfo);
687 SysTryReturn(NID_CNT, pAudioContentInfo != null, null, E_OUT_OF_MEMORY,
688 "[E_OUT_OF_MEMORY] The memory is insufficient.");
690 ContentInfo::_ContentData* pContentData = pAudioContentInfo->GetContentData();
691 SysTryReturn(NID_CNT, pContentData != null, null, E_OUT_OF_MEMORY,
692 "[E_OUT_OF_MEMORY] The memory is insufficient.");
694 AudioContentInfo::_AudioContentData* pAudioContentData = pAudioContentInfo->GetAudioContentData();
695 SysTryReturn(NID_CNT, pAudioContentData != null, null, E_OUT_OF_MEMORY,
696 "[E_OUT_OF_MEMORY] The memory is insufficient.");
698 r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, pAudioContentData);
699 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
701 return pAudioContentInfo.release();
703 else if (systemType == SYSTEM_TYPE_VIDEO)
705 unique_ptr<VideoContentInfo> pVideoContentInfo(new (nothrow) VideoContentInfo);
706 SysTryReturn(NID_CNT, pVideoContentInfo != null, null, E_OUT_OF_MEMORY,
707 "[E_OUT_OF_MEMORY] The memory is insufficient.");
709 ContentInfo::_ContentData* pContentData = pVideoContentInfo->GetContentData();
710 SysTryReturn(NID_CNT, pContentData != null, null, E_OUT_OF_MEMORY,
711 "[E_OUT_OF_MEMORY] The memory is insufficient.");
713 VideoContentInfo::_VideoContentData* pVideoContentData = pVideoContentInfo->GetVideoContentData();
714 SysTryReturn(NID_CNT, pVideoContentData != null, null, E_OUT_OF_MEMORY,
715 "[E_OUT_OF_MEMORY] The memory is insufficient.");
717 r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, pVideoContentData);
718 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
720 return pVideoContentInfo.release();
722 else if (systemType == SYSTEM_TYPE_OTHER)
724 unique_ptr<OtherContentInfo> pOtherContentInfo(new (nothrow) OtherContentInfo);
725 SysTryReturn(NID_CNT, pOtherContentInfo != null, null, E_OUT_OF_MEMORY,
726 "[E_OUT_OF_MEMORY] The memory is insufficient.");
728 ContentInfo::_ContentData* pContentData = pOtherContentInfo->GetContentData();
729 SysTryReturn(NID_CNT, pContentData != null, null, E_OUT_OF_MEMORY,
730 "[E_OUT_OF_MEMORY] The memory is insufficient.");
732 r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, null);
733 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
735 return pOtherContentInfo.release();
739 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] Unsupported type");
751 // E_PRIVILEGE_DENIED(in public)
754 _ContentManagerImpl::UpdateContent(const ContentInfo& contentInfo)
756 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
760 ContentId contentId = contentInfo.GetContentId();
761 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, "The content id is invalid.");
762 SysTryReturnResult(NID_CNT, _FileImpl::IsFileExist(contentInfo.GetContentPath()), E_FILE_NOT_FOUND,
763 "The file corresponding to contentInfo could not be found.");
765 // Get common data from ContentInfo class
766 ContentInfo::_ContentData* pContentData = (const_cast <ContentInfo*>(&contentInfo))->GetContentData();
767 SysTryReturnResult(NID_CNT, pContentData != null, E_INVALID_ARG, "pContentData is null.");
769 // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SYSTEM, E_SERVICE_BUSY
770 result r = this->UpdateDataToDatabase(pContentData);
771 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "UpdateDataToDatabase failed.");
783 // E_PRIVILEGE_DENIED(in public)
784 // - E_ILLEGAL_ACCESS
787 _ContentManagerImpl::DeleteContent(const ContentId& contentId)
789 SysAssertf(__isConnected, "Not yet constructed. Construct() should be called before use.");
793 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, "The contentId is invalid.");
795 unique_ptr<char[]> pContentId(_StringConverter::CopyToCharArrayN(contentId.ToString()));
796 SysTryReturnResult(NID_CNT, pContentId != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
798 result r = E_SUCCESS;
800 media_info_h tempMediaInfo = null;
801 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
803 val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
804 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
805 "media_info_get_media_from_db failed[%d].", val);
807 pMediaInfo.reset(tempMediaInfo);
809 char* __pContentPath = null;
811 val = media_info_get_file_path(pMediaInfo.get(), &__pContentPath);
812 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
813 "media_info_get_file_path failed[%d].", val);
815 unique_ptr<char, CharDeleter> pContentPath(__pContentPath);
817 String contentPath = String(pContentPath.get());
818 SysTryReturnResult(NID_CNT, _FileImpl::IsFileExist(contentPath), E_FILE_NOT_FOUND,
819 "The file corresponding to contentId could not be found.");
821 val = media_info_delete_from_db(pContentId.get());
822 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
823 "media_info_delete_From_db failed[%d].", val);
825 r = _FileImpl::Remove(contentPath);
826 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The file is not deleted.");
833 // E_OBJ_ALREADY_EXIST
837 _ContentManagerImpl::AddContentUpdateEventListener(IContentUpdateEventListener& listener)
841 SysTryReturnResult(NID_CNT, GetListener() == null, E_OBJ_ALREADY_EXIST, "IContentUpdateEventListener is already set.");
843 SetListener(&listener);
845 int val = media_content_set_db_updated_cb(OnContentUpdateCompleted, this);
846 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "media_content_set_db_updated_cb failed[%d].", val);
857 _ContentManagerImpl::RemoveContentUpdateEventListener(IContentUpdateEventListener& listener)
861 SysTryReturnResult(NID_CNT, GetListener() == &listener, E_OBJ_NOT_FOUND, "The input listener is not equal to the registered listener.");
863 int val = media_content_unset_db_updated_cb();
864 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "media_content_unset_db_updated_cb failed[%d].", val);
876 // E_PRIVILEGE_DENIED(in public)
879 _ContentManagerImpl::ScanFile(const Tizen::Base::String& contentPath)
883 SysSecureLog(NID_CNT, "The scan path is [%ls].", contentPath.GetPointer());
885 unique_ptr<char[]> pContentPath(_StringConverter::CopyToCharArrayN(contentPath));
886 SysTryReturnResult(NID_CNT, pContentPath, E_SYSTEM, "pContentPath is NULL.");
888 int val = media_content_connect();
889 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The connection failed[%d].", val);
891 val = media_content_scan_file(pContentPath.get());
892 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val), "media_content_scan_file failed[%d].", val);
894 val = media_content_disconnect();
895 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The disconnection failed[%d].", val);
905 // E_PRIVILEGE_DENIED(in public)
908 _ContentManagerImpl::ScanDirectory(const Tizen::Base::String& directoryPath, bool recursive, IContentScanListener* pListener, RequestId& reqId)
912 SysLog(NID_CNT, "The scan path is [%ls].", directoryPath.GetPointer());
914 unique_ptr<char[]> pDirPath(_StringConverter::CopyToCharArrayN(directoryPath));
915 SysTryReturnResult(NID_CNT, pDirPath, E_SYSTEM, "pDirPath is NULL.");
917 int val = media_content_connect();
918 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The connection failed[%d].", val);
920 unique_ptr< ScanResult > pScanResult(new (nothrow) ScanResult);
921 SysTryReturnResult(NID_CNT, pScanResult != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
925 pScanResult->scanPath = directoryPath;
926 pScanResult->pScanListener = pListener;
927 pScanResult->requestId = reqId;
929 val = media_content_scan_folder(pDirPath.get(), recursive, OnScanCompleted, pScanResult.release());
930 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val), "media_content_scan_folder failed[%d].", val);
943 _ContentManagerImpl::UpdateDataToDatabase(const ContentInfo::_ContentData* pContentData) const
947 SysTryReturnResult(NID_CNT, pContentData != null, E_INVALID_ARG, "pContentData is null.");
949 media_info_h tempMediaInfo = null;
950 unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
951 unique_ptr<char[]> pContentId(_StringConverter::CopyToCharArrayN((pContentData->contentId).ToString()));
952 SysTryReturnResult(NID_CNT, pContentId != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
954 int val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
955 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
956 "media_info_get_media_from_db failed[%d].", val);
958 pMediaInfo.reset(tempMediaInfo);
960 result r = E_SUCCESS;
961 unique_ptr<char[]> pValue(null);
963 if (pContentData->pAuthor != null)
965 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pAuthor)));
966 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
968 val = media_info_set_author(pMediaInfo.get(), pValue.get());
969 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
970 "media_info_set_author failed[%d].", val);
972 if (pContentData->pCategory != null)
974 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pCategory)));
975 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
977 val = media_info_set_category(pMediaInfo.get(), pValue.get());
978 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
979 "media_info_set_category failed[%d].", val);
981 if (pContentData->pContentName != null)
983 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pContentName)));
984 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
986 val = media_info_set_content_name(pMediaInfo.get(), pValue.get());
987 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
988 "media_info_set_content_name failed[%d].", val);
990 if (pContentData->pDescription != null)
992 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pDescription)));
993 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
995 val = media_info_set_description(pMediaInfo.get(), pValue.get());
996 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
997 "media_info_set_description failed[%d].", val);
999 if (pContentData->pKeyword != null)
1001 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pKeyword)));
1002 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1004 val = media_info_set_keyword(pMediaInfo.get(), pValue.get());
1005 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1006 "media_info_set_keyword failed[%d].", val);
1008 if (pContentData->pLocationTag != null)
1010 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pLocationTag)));
1011 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1013 val = media_info_set_location_tag(pMediaInfo.get(), pValue.get());
1014 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1015 "media_info_set_location_tag failed[%d].", val);
1017 if (pContentData->pProvider != null)
1019 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pProvider)));
1020 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1022 val = media_info_set_provider(pMediaInfo.get(), pValue.get());
1023 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1024 "media_info_set_provider failed[%d].", val);
1026 if (pContentData->pRating != null)
1028 pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pRating)));
1029 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1031 val = media_info_set_age_rating(pMediaInfo.get(), pValue.get());
1032 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1033 "media_info_set_age_rating failed[%d].", val);
1035 if (Double::Compare(pContentData->latitude, DEFAULT_COORDINATE) != 0 &&
1036 Double::Compare(pContentData->longitude, DEFAULT_COORDINATE) != 0)
1038 val = media_info_set_latitude(pMediaInfo.get(), pContentData->latitude);
1039 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1040 "media_info_set_latitude failed[%d].", val);
1042 val = media_info_set_longitude(pMediaInfo.get(), pContentData->longitude);
1043 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1044 "media_info_set_longitude failed[%d].", val);
1046 if (Double::Compare(pContentData->altitude, DEFAULT_COORDINATE) != 0)
1048 val = media_info_set_altitude(pMediaInfo.get(), pContentData->altitude);
1049 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1050 "media_info_set_altitude failed[%d].", val);
1054 val = media_info_update_to_db(pMediaInfo.get());
1055 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1056 "media_info_update_to_db failed[%d].", val);
1069 _ContentManagerImpl::SaveDataToDatabase(const media_info_h pMediaInfo,
1070 ContentInfo::_ContentData* pContentData) const
1074 SysTryReturn(NID_CNT, pContentData != null, UuId::GetInvalidUuId(), E_INVALID_ARG,
1075 "[E_INVALID_ARG] pContentData is null.");
1077 // Exception : E_SUCCESS, E_INVALID_ARG
1078 String extension = _FileImpl::GetFileExtension(pContentData->contentPath);
1079 result r = GetLastResult();
1080 SysTryReturn(NID_CNT, !(IsFailed(r)), UuId::GetInvalidUuId(), r, "[%s] Propagating.", GetErrorMessage(r));
1082 // If the content format is JPG and it has GPS data, it will be saved in database automatically.
1083 if (extension == L"jpg" || extension == L"jpeg" || extension == L"JPG" || extension == L"JPEG")
1085 SysLog(NID_CNT, "The format of content is jpg.");
1087 ImageMetadata* pImageMetadata = _ContentManagerUtilImpl::GetImageMetaN(pContentData->contentPath, true);
1088 if (pImageMetadata != null)
1090 pContentData->latitude = pImageMetadata->GetLatitude();
1091 pContentData->longitude = pImageMetadata->GetLongitude();
1093 delete pImageMetadata;
1094 pImageMetadata = null;
1099 unique_ptr<char[]> pStr(null);
1101 if (pContentData->pAuthor != null)
1103 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pAuthor)));
1104 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1105 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1107 val = media_info_set_author(pMediaInfo, pStr.get());
1108 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1109 "media_info_set_author failed[%d].", val);
1111 if (pContentData->pCategory != null)
1113 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pCategory)));
1114 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1115 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1117 val = media_info_set_category(pMediaInfo, pStr.get());
1118 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1119 "media_info_set_category failed[%d].", val);
1121 if (pContentData->pContentName != null)
1123 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pContentName)));
1124 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1125 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1127 val = media_info_set_content_name(pMediaInfo, pStr.get());
1128 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1129 "media_info_set_content_name failed[%d].", val);
1131 if (pContentData->pDescription != null)
1133 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pDescription)));
1134 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1135 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1137 val = media_info_set_description(pMediaInfo, pStr.get());
1138 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1139 "media_info_set_description failed[%d].", val);
1141 if (pContentData->pKeyword != null)
1143 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pKeyword)));
1144 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1145 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1147 val = media_info_set_keyword(pMediaInfo, pStr.get());
1148 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1149 "media_info_set_keyword failed[%d].", val);
1151 if (pContentData->pLocationTag != null)
1153 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pLocationTag)));
1154 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1155 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1157 val = media_info_set_location_tag(pMediaInfo, pStr.get());
1158 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1159 "media_info_set_location_tag failed[%d].", val);
1161 if (pContentData->pProvider != null)
1163 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pProvider)));
1164 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1165 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1167 val = media_info_set_provider(pMediaInfo, pStr.get());
1168 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1169 "media_info_set_provider failed[%d].", val);
1171 if (pContentData->pRating != null)
1173 pStr.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pRating)));
1174 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1175 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1177 val = media_info_set_age_rating(pMediaInfo, pStr.get());
1178 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1179 "media_info_set_age_rating failed[%d].", val);
1181 if (Double::Compare(pContentData->latitude, DEFAULT_COORDINATE) != 0 &&
1182 Double::Compare(pContentData->longitude, DEFAULT_COORDINATE) != 0)
1184 val = media_info_set_latitude(pMediaInfo, pContentData->latitude);
1185 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1186 "media_info_set_latitude failed[%d].", val);
1188 val = media_info_set_longitude(pMediaInfo, pContentData->longitude);
1189 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1190 "media_info_set_longitude failed[%d].", val);
1192 if (Double::Compare(pContentData->altitude, DEFAULT_COORDINATE) != 0)
1194 val = media_info_set_altitude(pMediaInfo, pContentData->altitude);
1195 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1196 "media_info_set_altitude failed[%d].", val);
1200 val = media_info_update_to_db(pMediaInfo);
1201 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1202 "media_info_update_to_db failed[%d].", val);
1204 char* __pMediaId = null;
1205 unique_ptr<char, CharDeleter> pMediaId(null);
1207 val = media_info_get_media_id(pMediaInfo, &__pMediaId);
1208 if (__pMediaId != null)
1210 pMediaId.reset(__pMediaId);
1214 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1215 "media_info_get_media_id failed[%d].", val);
1218 String contentId(pMediaId.get());
1220 r = UuId::Parse(contentId, pContentData->contentId);
1221 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_INVALID_ARG,
1222 "[E_INVALID_ARG] UuId::Parse failed.");
1224 return pContentData->contentId;
1235 _ContentManagerImpl::MakeContentInfo(const media_info_h pMediaInfo, ContentInfo::_ContentData* pContentData,
1236 int systemType, void* pMetadata) const
1240 if (systemType != SYSTEM_TYPE_OTHER)
1242 SysTryReturnResult(NID_CNT, pMediaInfo != null && pContentData != null && pMetadata != null, E_INVALID_ARG,
1243 "The specified parameter is invalid.");
1245 else // There is no metadata in Other type
1247 SysTryReturnResult(NID_CNT, pMediaInfo != null && pContentData != null, E_INVALID_ARG,
1248 "The specified parameter is invalid.");
1251 result r = E_SUCCESS;
1252 char* __pStrValue = null;
1253 unique_ptr<char, CharDeleter> pStrValue(null);
1256 int val = media_info_get_media_id(pMediaInfo, &__pStrValue);
1257 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1258 "media_info_get_media_id failed[%d].", val);
1260 if (__pStrValue != null)
1262 pStrValue.reset(__pStrValue);
1264 String strContentId(pStrValue.get());
1266 r = UuId::Parse(strContentId, pContentData->contentId);
1267 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The content id can not be parsed.");
1269 SysLog(NID_CNT, "INFO: contentId[%ls]", strContentId.GetPointer());
1273 val = media_info_get_file_path(pMediaInfo, &__pStrValue);
1274 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1275 "media_info_get_file_path failed[%d].", val);
1277 if (__pStrValue != null)
1279 pStrValue.reset(__pStrValue);
1281 String strFilePath(pStrValue.get());
1283 // If the api version is 2.0, the content path has to be changed.
1284 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
1286 if (strFilePath.StartsWith(Environment::GetMediaPath(), 0))
1288 r = strFilePath.Replace(Environment::GetMediaPath(), OSP_MEDIA_PHONE);
1289 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The content path is not changed.");
1291 else if (strFilePath.StartsWith(Environment::GetExternalStoragePath(), 0))
1293 r = strFilePath.Replace(Environment::GetExternalStoragePath(), OSP_MEDIA_MMC);
1294 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Replace failed.");
1298 SysLogException(NID_CNT, E_INVALID_ARG,
1299 "[E_INVALID_ARG] The content path is not supported.");
1300 return E_INVALID_ARG;
1304 pContentData->contentPath = strFilePath;
1306 SysSecureLog(NID_CNT, "INFO: contentPath[%ls]", strFilePath.GetPointer());
1310 val = media_info_get_mime_type(pMediaInfo, &__pStrValue);
1311 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1312 "media_info_get_mime_type failed[%d].", val);
1314 if (__pStrValue != null)
1316 pStrValue.reset(__pStrValue);
1318 pContentData->mimeType = pStrValue.get();
1320 SysLog(NID_CNT, "INFO: mimeType[%ls]", (pContentData->mimeType).GetPointer());
1324 unsigned long long longlongValue = 0;
1325 val = media_info_get_size(pMediaInfo, &longlongValue);
1326 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1327 "media_info_get_size failed[%d].", val);
1328 pContentData->contentSize = longlongValue;
1329 SysLog(NID_CNT, "INFO: contentSize[%llu]", longlongValue);
1332 media_content_storage_e storageType;
1333 val = media_info_get_storage_type(pMediaInfo, &storageType);
1334 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1335 "media_info_get_storage_type failed[%d].", val);
1336 pContentData->storageType = storageType;
1337 SysLog(NID_CNT, "INFO: storageType[%d]", storageType);
1340 val = media_info_is_drm(pMediaInfo, &(pContentData->isDrm));
1341 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1342 "media_info_is_drm failed[%d].", val);
1343 SysLog(NID_CNT, "INFO: isDrm[%d]", pContentData->isDrm);
1347 val = media_info_get_added_time(pMediaInfo, &time);
1348 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1349 "media_info_get_added_time failed[%d].", val);
1350 r = (pContentData->dateTime).SetValue(1970, 1, 1);
1351 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "SetValue failed.");
1352 r = (pContentData->dateTime).AddSeconds(time);
1353 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "AddSeconds failed.");
1354 SysLog(NID_CNT, "INFO: dateTime[%ls]", ((pContentData->dateTime).ToString()).GetPointer());
1357 val = media_info_get_thumbnail_path(pMediaInfo, &__pStrValue);
1358 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1359 "media_info_get_thumbnail_path failed[%d].", val);
1361 if (__pStrValue != null)
1363 pStrValue.reset(__pStrValue);
1365 pContentData->pThumbnailPath = new (nothrow) String(pStrValue.get());
1367 SysLog(NID_CNT, "INFO: thumbnailPath[%ls]", (*pContentData->pThumbnailPath).GetPointer());
1371 val = media_info_get_author(pMediaInfo, &__pStrValue);
1372 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1373 "media_info_get_author failed[%d].", val);
1375 if (__pStrValue != null)
1377 pStrValue.reset(__pStrValue);
1379 pContentData->pAuthor = new (nothrow) String(pStrValue.get());
1381 SysLog(NID_CNT, "INFO: author[%ls]", (*pContentData->pAuthor).GetPointer());
1385 val = media_info_get_category(pMediaInfo, &__pStrValue);
1386 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1387 "media_info_get_category failed[%d].", val);
1389 if (__pStrValue != null)
1391 pStrValue.reset(__pStrValue);
1393 pContentData->pCategory = new (nothrow) String(pStrValue.get());
1395 SysLog(NID_CNT, "INFO: category[%ls]", (*pContentData->pCategory).GetPointer());
1399 val = media_info_get_content_name(pMediaInfo, &__pStrValue);
1400 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1401 "media_info_get_content_name failed[%d].", val);
1403 if (__pStrValue != null)
1405 pStrValue.reset(__pStrValue);
1407 pContentData->pContentName = new (nothrow) String(pStrValue.get());
1409 SysSecureLog(NID_CNT, "INFO: contentName[%ls]", (*pContentData->pContentName).GetPointer());
1413 val = media_info_get_description(pMediaInfo, &__pStrValue);
1414 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1415 "media_info_get_description failed[%d].", val);
1417 if (__pStrValue != null)
1419 pStrValue.reset(__pStrValue);
1421 pContentData->pDescription = new (nothrow) String(pStrValue.get());
1423 SysLog(NID_CNT, "INFO: description[%ls]", (*pContentData->pDescription).GetPointer());
1427 val = media_info_get_keyword(pMediaInfo, &__pStrValue);
1428 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1429 "media_info_get_keyword failed[%d].", val);
1431 if (__pStrValue != null)
1433 pStrValue.reset(__pStrValue);
1435 pContentData->pKeyword = new (nothrow) String(pStrValue.get());
1437 SysLog(NID_CNT, "INFO: keyword[%ls]", (*pContentData->pKeyword).GetPointer());
1441 val = media_info_get_location_tag(pMediaInfo, &__pStrValue);
1442 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1443 "media_info_get_location_tag failed[%d].", val);
1445 if (__pStrValue != null)
1447 pStrValue.reset(__pStrValue);
1449 pContentData->pLocationTag = new (nothrow) String(pStrValue.get());
1451 SysSecureLog(NID_CNT, "INFO: locationTag[%ls]", (*pContentData->pLocationTag).GetPointer());
1455 val = media_info_get_provider(pMediaInfo, &__pStrValue);
1456 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1457 "media_info_get_provider failed[%d].", val);
1459 if (__pStrValue != null)
1461 pStrValue.reset(__pStrValue);
1463 pContentData->pProvider = new (nothrow) String(pStrValue.get());
1465 SysLog(NID_CNT, "INFO: provider[%ls]", (*pContentData->pProvider).GetPointer());
1469 val = media_info_get_age_rating(pMediaInfo, &__pStrValue);
1470 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1471 "media_info_get_age_rating failed[%d].", val);
1473 if (__pStrValue != null)
1475 pStrValue.reset(__pStrValue);
1477 pContentData->pRating = new (nothrow) String(pStrValue.get());
1479 SysLog(NID_CNT, "INFO: rating[%ls]", (*pContentData->pRating).GetPointer());
1483 double doubleValue = 0;
1484 val = media_info_get_latitude(pMediaInfo, &doubleValue);
1485 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1486 "media_info_get_latitude failed[%d].", val);
1488 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1490 pContentData->latitude = doubleValue;
1492 SysSecureLog(NID_CNT, "INFO: latitude[%f]", pContentData->latitude);
1494 val = media_info_get_longitude(pMediaInfo, &doubleValue);
1495 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1496 "media_info_get_longitude failed[%d].", val);
1498 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1500 pContentData->longitude = doubleValue;
1502 SysSecureLog(NID_CNT, "INFO: longitude[%f]", pContentData->longitude);
1504 val = media_info_get_altitude(pMediaInfo, &doubleValue);
1505 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1506 "media_info_get_altitude failed[%d].", val);
1508 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1510 pContentData->altitude = doubleValue;
1512 SysLog(NID_CNT, "INFO: altitude[%f]", pContentData->altitude);
1516 // contentType and metadata
1517 if (systemType == SYSTEM_TYPE_IMAGE)
1519 image_meta_h __pImageMeta = null;
1520 unique_ptr<image_meta_h, ImageMetaDeleter> pImageMeta(null);
1522 pContentData->contentType = CONTENT_TYPE_IMAGE;
1523 SysLog(NID_CNT, "META: ContentType[%d]", pContentData->contentType);
1525 val = media_info_get_image(pMediaInfo, &__pImageMeta);
1526 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1527 "media_info_get_image failed[%d].", val);
1529 pImageMeta.reset(&__pImageMeta);
1532 val = image_meta_get_width(*(pImageMeta.get()), &intValue);
1533 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1534 "image_meta_get_width failed[%d].", val);
1536 (static_cast<ImageContentInfo::_ImageContentData*>(pMetadata))->width = intValue;
1537 SysLog(NID_CNT, "META: width[%d]", intValue);
1540 val = image_meta_get_height(*(pImageMeta.get()), &intValue);
1541 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1542 "image_meta_get_height failed[%d].", val);
1544 (static_cast<ImageContentInfo::_ImageContentData*>(pMetadata))->height = intValue;
1545 SysLog(NID_CNT, "META: height[%d]", intValue);
1548 media_content_orientation_e orientation;
1549 val = image_meta_get_orientation(*(pImageMeta.get()), &orientation);
1550 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1551 "image_meta_get_orientation failed[%d].", val);
1553 (static_cast<ImageContentInfo::_ImageContentData*>(pMetadata))->orientationType =
1554 static_cast<ImageOrientationType>(orientation);
1555 SysLog(NID_CNT, "META: orientation[%d]", orientation);
1558 val = media_info_get_display_name(pMediaInfo, &__pStrValue);
1559 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1560 "media_info_get_display_name failed[%d].", val);
1562 if (__pStrValue != null)
1564 pStrValue.reset(__pStrValue);
1568 String strTitle(pStrValue.get());
1570 r = strTitle.LastIndexOf(L'.', strTitle.GetLength() - 1, pos);
1573 r = strTitle.SubString(0, pos, fileName);
1574 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The title is invalid.");
1578 // Without extension
1580 fileName = strTitle;
1583 (static_cast<ImageContentInfo::_ImageContentData*>(pMetadata))->title = fileName;
1585 SysLog(NID_CNT, "META: title[%ls]", fileName.GetPointer());
1588 else if (systemType == SYSTEM_TYPE_SOUND || systemType == SYSTEM_TYPE_MUSIC)
1590 audio_meta_h __pAudioMeta = null;
1591 unique_ptr<audio_meta_h, AudioMetaDeleter> pAudioMeta(null);
1593 pContentData->contentType = CONTENT_TYPE_AUDIO;
1594 SysLog(NID_CNT, "META: ContentType[%d]", pContentData->contentType);
1596 val = media_info_get_audio(pMediaInfo, &__pAudioMeta);
1597 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1598 "media_info_get_audio failed[%d].", val);
1600 pAudioMeta.reset(&__pAudioMeta);
1603 val = audio_meta_get_bit_rate(*(pAudioMeta.get()), &intValue);
1604 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1605 "audio_meta_get_bit_rate failed[%d].", val);
1607 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->bitrate = intValue;
1608 SysLog(NID_CNT, "META: bitrate[%d]", intValue);
1611 val = audio_meta_get_year(*(pAudioMeta.get()), &__pStrValue);
1612 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1613 "audio_meta_get_year failed[%d].", val);
1615 if (__pStrValue != null)
1617 pStrValue.reset(__pStrValue);
1619 String strYear(pStrValue.get());
1621 if (strYear.CompareTo(L"Unknown") != 0)
1623 r = Integer::Parse(strYear, intValue);
1626 // It is one of the metadata. If error occurs, skip it for other metadata.
1629 SysLog(NID_CNT, "META: releaseYear - invalid data[%ls]", strYear.GetPointer());
1632 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->releaseYear = intValue;
1633 SysLog(NID_CNT, "META: releaseYear[%d]", intValue);
1638 val = audio_meta_get_title(*(pAudioMeta.get()), &__pStrValue);
1639 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1640 "audio_meta_get_title failed[%d].", val);
1642 if (__pStrValue != null)
1644 pStrValue.reset(__pStrValue);
1646 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pTitle =
1647 new (nothrow) String(pStrValue.get());
1649 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
1653 val = audio_meta_get_album(*(pAudioMeta.get()), &__pStrValue);
1654 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1655 "audio_meta_get_album failed[%d].", val);
1657 if (__pStrValue != null)
1659 pStrValue.reset(__pStrValue);
1661 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pAlbumName =
1662 new (nothrow) String(pStrValue.get());
1664 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
1668 val = audio_meta_get_artist(*(pAudioMeta.get()), &__pStrValue);
1669 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1670 "audio_meta_get_artist failed[%d].", val);
1672 if (__pStrValue != null)
1674 pStrValue.reset(__pStrValue);
1676 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pArtist =
1677 new (nothrow) String(pStrValue.get());
1679 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
1683 val = audio_meta_get_composer(*(pAudioMeta.get()), &__pStrValue);
1684 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1685 "audio_meta_get_composer failed[%d].", val);
1687 if (__pStrValue != null)
1689 pStrValue.reset(__pStrValue);
1691 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pComposer =
1692 new (nothrow) String(pStrValue.get());
1694 SysLog(NID_CNT, "META: composer[%ls]", (String(pStrValue.get())).GetPointer());
1698 val = audio_meta_get_genre(*(pAudioMeta.get()), &__pStrValue);
1699 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1700 "audio_meta_get_genre failed[%d].", val);
1702 if (__pStrValue != null)
1704 pStrValue.reset(__pStrValue);
1706 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pGenre =
1707 new (nothrow) String(pStrValue.get());
1709 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
1713 val = audio_meta_get_copyright(*(pAudioMeta.get()), &__pStrValue);
1714 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1715 "audio_meta_get_copyright failed[%d].", val);
1717 if (__pStrValue != null)
1719 pStrValue.reset(__pStrValue);
1721 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pCopyright =
1722 new (nothrow) String(pStrValue.get());
1724 SysLog(NID_CNT, "META: copyright[%ls]", (String(pStrValue.get())).GetPointer());
1728 val = audio_meta_get_track_num(*(pAudioMeta.get()), &__pStrValue);
1729 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1730 "audio_meta_get_track_num failed[%d].", val);
1732 if (__pStrValue != null)
1734 pStrValue.reset(__pStrValue);
1736 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->pTrackInfo
1737 = new (nothrow) String(pStrValue.get());
1739 SysLog(NID_CNT, "META: trackInfo[%ls]", (String(pStrValue.get())).GetPointer());
1743 val = audio_meta_get_duration(*(pAudioMeta.get()), &intValue);
1744 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1745 "audio_meta_get_duration failed[%d].", val);
1747 (static_cast<AudioContentInfo::_AudioContentData*>(pMetadata))->duration = intValue;
1748 SysLog(NID_CNT, "META: duration[%d]", intValue);
1751 else if (systemType == MEDIA_CONTENT_TYPE_VIDEO)
1753 video_meta_h __pVideoMeta = null;
1754 unique_ptr<video_meta_h, VideoMetaDeleter> pVideoMeta(null);
1756 pContentData->contentType = CONTENT_TYPE_VIDEO;
1757 SysLog(NID_CNT, "META: ContentType[%d]", pContentData->contentType);
1759 val = media_info_get_video(pMediaInfo, &__pVideoMeta);
1760 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1761 "media_info_get_video failed[%d].", val);
1763 pVideoMeta.reset(&__pVideoMeta);
1766 val = video_meta_get_width(*(pVideoMeta.get()), &intValue);
1767 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1768 "video_meta_get_width failed[%d].", val);
1770 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->width = intValue;
1771 SysLog(NID_CNT, "META: width[%d]", intValue);
1774 val = video_meta_get_height(*(pVideoMeta.get()), &intValue);
1775 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1776 "video_meta_get_height failed[%d].", val);
1778 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->height = intValue;
1779 SysLog(NID_CNT, "META: height[%d]", intValue);
1781 // Get from metadata extractor (framerate, audio bitrate, video bitrate)
1784 val = video_meta_get_artist(*(pVideoMeta.get()), &__pStrValue);
1785 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1786 "video_meta_get_artist failed[%d].", val);
1788 if (__pStrValue != null)
1790 pStrValue.reset(__pStrValue);
1792 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->pArtist
1793 = new (nothrow) String(pStrValue.get());
1795 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
1799 val = video_meta_get_genre(*(pVideoMeta.get()), &__pStrValue);
1800 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1801 "video_meta_get_genre failed[%d].", val);
1803 if (__pStrValue != null)
1805 pStrValue.reset(__pStrValue);
1807 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->pGenre
1808 = new (nothrow) String(pStrValue.get());
1810 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
1814 val = video_meta_get_title(*(pVideoMeta.get()), &__pStrValue);
1815 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1816 "video_meta_get_title failed[%d].", val);
1818 if (__pStrValue != null)
1820 pStrValue.reset(__pStrValue);
1822 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->pTitle
1823 = new (nothrow) String(pStrValue.get());
1825 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
1829 val = video_meta_get_album(*(pVideoMeta.get()), &__pStrValue);
1830 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1831 "video_meta_get_album failed[%d].", val);
1833 if (__pStrValue != null)
1835 pStrValue.reset(__pStrValue);
1837 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->pAlbumName
1838 = new (nothrow) String(pStrValue.get());
1840 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
1844 val = video_meta_get_duration(*(pVideoMeta.get()), &intValue);
1845 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1846 "video_meta_get_duration failed[%d].", val);
1848 (static_cast<VideoContentInfo::_VideoContentData*>(pMetadata))->duration = intValue;
1849 SysLog(NID_CNT, "META: duration[%d]", intValue);
1851 else if (systemType == SYSTEM_TYPE_OTHER)
1853 pContentData->contentType = CONTENT_TYPE_OTHER;
1854 SysLog(NID_CNT, "META: ContentType[%d]", pContentData->contentType);
1861 _ContentManagerImpl::VerifyHomeFilePathCompatibility(const String& contentPath) const
1863 if (!_AppInfo::IsOspCompat())
1865 if (contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0))
1867 SysLogException(NID_CNT, E_INVALID_ARG,
1868 "[E_INVALID_ARG] /Home/ or /HomeExt/ is not supported from Tizen 2.0.");
1871 if (!(contentPath.StartsWith(App::App::GetInstance()->GetAppRootPath(), 0) ||
1872 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
1874 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] The path is not supported.");
1880 SysTryReturn(NID_CNT, contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0),
1881 false, E_INVALID_ARG, "[E_INVALID_ARG] The path should start with /Home or /HomeExt.");
1888 _ContentManagerImpl::VerifyMediaFilePathCompatibility(const String& contentPath, bool checkVersion) const
1892 result r = E_SUCCESS;
1894 if (!_AppInfo::IsOspCompat())
1896 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0) || contentPath.StartsWith(OSP_MEDIA_MMC, 0))
1898 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] /Media or /Storagecard/Media is not supported.");
1901 if (!(contentPath.StartsWith(Environment::GetMediaPath(), 0) ||
1902 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
1904 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] %ls is not supported.", contentPath.GetPointer());
1911 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0))
1913 r = (const_cast<String*>(&contentPath))->Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
1914 SysTryReturn(NID_CNT, !IsFailed(r), false, E_INVALID_ARG, "[E_INVALID_ARG] Replace failed.");
1916 else if (contentPath.StartsWith(OSP_MEDIA_MMC, 0))
1918 r = (const_cast<String*>(&contentPath))->Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
1919 SysTryReturn(NID_CNT, !IsFailed(r), false, E_INVALID_ARG, "[E_INVALID_ARG] Replace failed.");
1923 // CreateContent(const ByteBuffer&, ...) and CreateContent (const Sring&, ...) can receive old path like /Media/.
1924 // but CreateContent(const ContentInfo&) always receive new path like /opt/media/ because ContentInfo class convert the path from /Media/ to /opt/media.
1927 SysLogException(NID_CNT, E_INVALID_ARG,
1928 "[E_INVALID_ARG] The path should start with /Home, /Media, or /Storagecard/Media.");
1938 _ContentManagerImpl::SetListener(IContentUpdateEventListener* pListener)
1940 __pListener = pListener;
1943 IContentUpdateEventListener*
1944 _ContentManagerImpl::GetListener(void) const