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.
27 #include <FBaseSysLog.h>
28 #include <FBaseDateTime.h>
29 #include <FBaseInteger.h>
30 #include <FBaseByteBuffer.h>
31 #include <FBaseUtilStringTokenizer.h>
32 #include <FCntContentManager.h>
33 #include <FCntContentManagerUtil.h>
34 #include <FCntImageContentInfo.h>
35 #include <FCntAudioContentInfo.h>
36 #include <FCntVideoContentInfo.h>
37 #include <FCntOtherContentInfo.h>
38 #include <FCntImageMetadata.h>
39 #include <FCntAudioMetadata.h>
40 #include <FCntVideoMetadata.h>
41 #include <FCntIContentScanListener.h>
42 #include <FCntIContentUpdateEventListener.h>
43 #include <FIoDirectory.h>
44 #include <FSysEnvironment.h>
45 #include <FApp_AppInfo.h>
46 #include <FBase_StringConverter.h>
47 #include <FIo_FileImpl.h>
48 #include "FCnt_ContentManagerImpl.h"
49 #include "FCnt_ContentManagerUtilImpl.h"
50 #include "FCnt_ContentInfoImpl.h"
51 #include "FCnt_ImageContentInfoImpl.h"
52 #include "FCnt_AudioContentInfoImpl.h"
53 #include "FCnt_VideoContentInfoImpl.h"
54 #include "FCnt_OtherContentInfoImpl.h"
55 #include "FCnt_ContentInfoHelper.h"
58 using namespace Tizen::App;
59 using namespace Tizen::Base;
60 using namespace Tizen::Base::Collection;
61 using namespace Tizen::Base::Utility;
62 using namespace Tizen::Io;
63 using namespace Tizen::Locations;
64 using namespace Tizen::System;
66 namespace Tizen { namespace Content
69 static const int SYSTEM_TYPE_IMAGE = 0;
70 static const int SYSTEM_TYPE_VIDEO = 1;
71 static const int SYSTEM_TYPE_SOUND = 2;
72 static const int SYSTEM_TYPE_MUSIC = 3;
73 static const int SYSTEM_TYPE_OTHER = 4;
74 static const double DEFAULT_COORDINATE = -200.0;
76 // For extern declaration in FCntTypes.h
77 const wchar_t OSP_HOME[] = L"/Home/";
78 const wchar_t OSP_HOME_EXT[] = L"/HomeExt/";
79 const wchar_t OSP_MEDIA_PHONE[] = L"/Media/";
80 const wchar_t OSP_MEDIA_MMC[] = L"/Storagecard/Media/";
83 ConvertError(int error)
89 case MEDIA_CONTENT_ERROR_NONE:
93 case MEDIA_CONTENT_ERROR_INVALID_PARAMETER:
97 case MEDIA_CONTENT_ERROR_OUT_OF_MEMORY:
101 case MEDIA_CONTENT_ERROR_DB_BUSY:
105 case MEDIA_CONTENT_ERROR_DB_FAILED:
118 OnScanCompleted(media_content_error_e error, void* user_data)
120 SysLog(NID_CNT, "OnScanCompleted callback method is called.");
123 result r = E_SUCCESS;
124 String scanPath(L"");
125 IContentScanListener* pListener = null;
127 unique_ptr< _ScanResult > pScanResult;
129 SysTryLogCatch(NID_CNT, user_data != null, , "OnScanCompleted failed.");
131 pScanResult = unique_ptr< _ScanResult >(static_cast< _ScanResult* >(user_data));
133 SysTryLogCatch(NID_CNT, pScanResult != null, , "OnScanCompleted failed.");
134 SysTryLogCatch(NID_CNT, pScanResult->pScanListener != null, , "Listener is null. OnScanCompleted succeeded.");
136 scanPath = pScanResult->scanPath;
137 pListener = pScanResult->pScanListener;
138 reqId = pScanResult->requestId;
140 r = ConvertError(error);
142 pListener->OnContentScanCompleted(reqId, scanPath, r);
143 SysLog(NID_CNT, "OnContentScanCompleted fired.");
146 int val = media_content_disconnect();
147 SysTryLog(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, "The disconnection failed[%d].", val);
151 OnContentUpdateCompleted(media_content_error_e error, int pid, media_content_db_update_item_type_e update_item,
152 media_content_db_update_type_e update_type, media_content_type_e media_type, char* uuid, char* path, char* mime_type, void* user_data)
154 SysLog(NID_CNT, "OnContentUpdateCompleted callback method is called.");
156 result r = E_SUCCESS;
158 SysTryLogReturn(NID_CNT, user_data != null, , "OnContentUpdateCompleted failed.");
160 _ContentManagerImpl* pTempManagerImpl = static_cast< _ContentManagerImpl* >(user_data);
161 SysTryLogReturn(NID_CNT, pTempManagerImpl != null, , "pTempManagerImpl is null.");
163 IContentUpdateEventListener* pListener = pTempManagerImpl->GetListener();
164 SysTryLogReturn(NID_CNT, pListener != null, , "IContentUpdateEventListener is null.");
166 if (error != MEDIA_CONTENT_ERROR_NONE)
173 case MEDIA_ITEM_FILE:
175 ContentType contentType = CONTENT_TYPE_UNKNOWN;
179 case MEDIA_CONTENT_TYPE_IMAGE:
180 contentType = CONTENT_TYPE_IMAGE;
183 case MEDIA_CONTENT_TYPE_VIDEO:
184 contentType = CONTENT_TYPE_VIDEO;
187 case MEDIA_CONTENT_TYPE_SOUND:
189 case MEDIA_CONTENT_TYPE_MUSIC:
190 contentType = CONTENT_TYPE_AUDIO;
193 case MEDIA_CONTENT_TYPE_OTHERS:
194 contentType = CONTENT_TYPE_OTHER;
199 SysLog(NID_CNT, "media_type is invalid.");
206 result res = UuId::Parse(str, contentId);
207 SysTryLogReturn(NID_CNT, !IsFailed(res), , "Failed to parse to the content ID.");
211 case MEDIA_CONTENT_INSERT:
212 pListener->OnContentFileCreated(contentId, contentType, r);
215 case MEDIA_CONTENT_DELETE:
216 pListener->OnContentFileDeleted(contentId, contentType, r);
219 case MEDIA_CONTENT_UPDATE:
220 pListener->OnContentFileUpdated(contentId, contentType, r);
224 SysLog(NID_CNT, "update_type is invalid.");
230 case MEDIA_ITEM_DIRECTORY:
232 String directoryPath(path);
234 pListener->OnContentDirectoryScanCompleted(directoryPath, r);
239 SysLog(NID_CNT, "update_item is invalid.");
243 SysLog(NID_CNT, "Fire the OnContentUpdateCompleted method.");
246 _ContentManagerImpl::_ContentManagerImpl(void)
247 : __isConnected(false)
253 _ContentManagerImpl::~_ContentManagerImpl(void)
259 val = media_content_unset_db_updated_cb();
260 SysLog(NID_CNT, "media_content_unset_db_updated_cb result[%d].", val);
263 val = media_content_disconnect();
264 SysLog(NID_CNT, "media_content_disconnect result[%d].", val);
268 _ContentManagerImpl::GetInstance(ContentManager& contentManager)
270 return contentManager.__pContentManagerImpl;
273 const _ContentManagerImpl*
274 _ContentManagerImpl::GetInstance(const ContentManager& contentManager)
276 return contentManager.__pContentManagerImpl;
280 _ContentManagerImpl::Construct(void)
282 int val = media_content_connect();
283 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM,
284 "The connection failed[%d].", val);
286 SysLog(NID_CNT, "media_content_connect result[%d].", val);
288 __isConnected = true;
294 _ContentManagerImpl::CreateContent(const ContentInfo& contentInfo)
298 _ContentInfoImpl* pInfoImpl = const_cast< _ContentInfoImpl* >(_ContentInfoImpl::GetInstance(contentInfo));
299 SysTryReturn(NID_CNT, pInfoImpl != null, UuId::GetInvalidUuId(), E_INVALID_ARG,
300 "[E_INVALID_ARG] Invalid argument is used. ContentInfo is invalid.");
302 String contentPath(pInfoImpl->GetPhysicalContentPath());
303 String changedPath(L"");
305 result r = ChangeTizenPathToCompat(contentPath, changedPath);
306 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] Failed to perform ChangeTizenPathToCompat.", GetErrorMessage(r));
308 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(changedPath), UuId::GetInvalidUuId(), E_FILE_NOT_FOUND,
309 "[%s] The file cound not be found.", GetErrorMessage(E_FILE_NOT_FOUND));
311 SysTryReturn(NID_CNT, pInfoImpl->GetContentId() == 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 = pInfoImpl->GetContentType();
316 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(contentPath, true);
320 if (inputType != sysType)
322 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
324 SysLogException(NID_CNT, E_INVALID_ARG,
325 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
326 return UuId::GetInvalidUuId();
330 // Save data to database with contentPath.
331 unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(contentPath));
332 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
333 "[E_OUT_OF_MEMORY] The memory is insufficient.");
335 media_info_h tempMediaInfo = null;
336 unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
338 int val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
339 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
340 "The registration to database failed[%d].", val);
342 pMediaInfo.reset(tempMediaInfo);
344 ContentId contentId = SaveDataToDatabase(pMediaInfo.get(), pInfoImpl);
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();
361 _ContentManagerImpl::CreateContent(const ByteBuffer& byteBuffer, const String& destinationPath,
362 const ContentInfo* pContentInfo)
366 // Check parameters(for length)
367 SysTryReturn(NID_CNT, byteBuffer.GetRemaining() > 0, UuId::GetInvalidUuId(), E_INVALID_ARG,
368 "[E_INVALID_ARG] byteBuffer is invalid.");
370 // Check parameters(for path compatibility)
371 SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(destinationPath), UuId::GetInvalidUuId(),
372 E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", destinationPath.GetPointer());
373 SysTryReturn(NID_CNT, !_FileImpl::IsFileExist(destinationPath), UuId::GetInvalidUuId(), E_FILE_ALREADY_EXIST,
374 "[E_FILE_ALREADY_EXIST] The specified file already exists.");
376 // Create a file with bytebuffer
377 unique_ptr<File> pFile(new (nothrow) File);
378 SysTryReturn(NID_CNT, pFile != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
379 "[E_OUT_OF_MEMORY] The memory is insufficient.");
381 result r = pFile->Construct(destinationPath, L"w+");
382 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r,
383 "[%s] The destination file can not be created.", GetErrorMessage(r));
385 _FileImpl* pFileImpl = _FileImpl::GetInstance(*pFile);
386 SysTryReturn(NID_CNT, pFileImpl != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
387 "[E_OUT_OF_MEMORY] The memory is insufficient.");
389 r = pFileImpl->Write(byteBuffer);
390 SysTryReturn(NID_CNT, !(IsFailed(r)), UuId::GetInvalidUuId(), r,
391 "[%s] The data can not be written in the destination file.", GetErrorMessage(r));
393 // for release file pointer
398 _ContentInfoImpl* pInfoImpl = null;
399 _ImageContentInfoImpl imageContentInfoImpl;
400 _AudioContentInfoImpl audioContentInfoImpl;
401 _VideoContentInfoImpl videoContentInfoImpl;
402 _OtherContentInfoImpl otherContentInfoImpl;
403 media_info_h tempMediaInfo = null;
404 unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
405 unique_ptr<char[]> pStr(null);
406 String destPath(L"");
408 r = ChangeCompatPathToTizen(destinationPath, destPath);
409 SysTryCatch(NID_CNT, !IsFailed(r), , r, "[%s] Failed to perform ChangedCompatPathToTizen.", GetErrorMessage(r));
411 if (pContentInfo != null)
413 pInfoImpl = const_cast< _ContentInfoImpl* >(_ContentInfoImpl::GetInstance(*pContentInfo));
414 SysTryCatch(NID_CNT, pInfoImpl != null, , E_INVALID_ARG,
415 "[E_INVALID_ARG] Invalid argument is used. ContentInfo is invalid.");
417 SysTryCatch(NID_CNT, pInfoImpl->GetContentId() == UuId::GetInvalidUuId(), , E_INVALID_ARG,
418 "[E_INVALID_ARG] The content already exists in database.");
420 // Compare the type of input parameter and system
421 // CheckContentType() need actual file. so it should be checked after creating the file.
422 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
423 ContentType inputType = pInfoImpl->GetContentType();
427 if (inputType != sysType)
429 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
431 SysLogException(NID_CNT, E_INVALID_ARG,
432 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
437 // Sets the content path
438 pInfoImpl->SetContentPath(destPath);
442 ContentType contentType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
446 // Set the content path
447 if (contentType == CONTENT_TYPE_IMAGE)
449 r = imageContentInfoImpl.Construct(&destinationPath);
450 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
451 "[E_OUT_OF_MEMORY] Failed to perform Construct for ImageContentInfoImpl.");
453 imageContentInfoImpl.SetContentPath(destPath);
454 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&imageContentInfoImpl);
456 else if (contentType == CONTENT_TYPE_AUDIO)
458 r = audioContentInfoImpl.Construct(&destinationPath);
459 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
460 "[E_OUT_OF_MEMORY] Failed to perform Construct for AudioContentInfoImpl.");
462 audioContentInfoImpl.SetContentPath(destPath);
463 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&audioContentInfoImpl);
465 else if (contentType == CONTENT_TYPE_VIDEO)
467 r = videoContentInfoImpl.Construct(&destinationPath);
468 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
469 "[E_OUT_OF_MEMORY] Failed to perform Construct for VideoContentInfoImpl.");
471 videoContentInfoImpl.SetContentPath(destPath);
472 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&videoContentInfoImpl);
476 r = otherContentInfoImpl.Construct(&destinationPath);
477 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
478 "[E_OUT_OF_MEMORY] Failed to perform Construct for OtherContentInfoImpl.");
480 otherContentInfoImpl.SetContentPath(destPath);
481 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&otherContentInfoImpl);
485 // Register the content to database directly.
486 pStr.reset(_StringConverter::CopyToCharArrayN(destPath));
487 SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
489 val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
490 SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
491 "media_info_insert_to_db failed[%d].", val);
493 pMediaInfo.reset(tempMediaInfo);
495 contentId = SaveDataToDatabase(pMediaInfo.get(), pInfoImpl);
497 SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
498 "[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
503 result saveResult = GetLastResult();
505 // If the destination file is made by this method, it should be deleted when error occurs.
506 r = _FileImpl::Remove(destinationPath);
507 SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
509 if (pMediaInfo != null)
511 val = media_info_delete_from_db(pStr.get());
512 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
515 SetLastResult(saveResult);
516 return UuId::GetInvalidUuId();
520 _ContentManagerImpl::CreateContent(const String& sourcePath, const String& destinationPath, bool deleteSource,
521 const ContentInfo* pContentInfo)
525 // Check parameters(for type)
526 SysTryReturn(NID_CNT, _FileImpl::GetFileExtension(sourcePath) == _FileImpl::GetFileExtension(destinationPath),
527 UuId::GetInvalidUuId(), E_INVALID_ARG, "[E_INVALID_ARG] There is a mismatch between the type of source and dest path.");
529 // Check parameters(for path compatibility)
530 SysTryReturn(NID_CNT, VerifyHomeFilePathCompatibility(sourcePath), UuId::GetInvalidUuId(), E_INVALID_ARG,
531 "[E_INVALID_ARG] %ls is not compatible.", sourcePath.GetPointer());
532 SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(destinationPath), UuId::GetInvalidUuId(),
533 E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", destinationPath.GetPointer());
535 result r = E_SUCCESS;
538 if (deleteSource) // move
540 r = _FileImpl::Move(sourcePath, destinationPath);
541 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Moving the file failed.", GetErrorMessage(r));
545 r = _FileImpl::Copy(sourcePath, destinationPath, true);
546 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Copying the file failed.", GetErrorMessage(r));
553 _ContentInfoImpl* pInfoImpl = null;
554 _ImageContentInfoImpl imageContentInfoImpl;
555 _AudioContentInfoImpl audioContentInfoImpl;
556 _VideoContentInfoImpl videoContentInfoImpl;
557 _OtherContentInfoImpl otherContentInfoImpl;
558 media_info_h tempMediaInfo = null;
559 unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
560 unique_ptr<char[]> pStr(null);
561 String destPath(L"");
563 r = ChangeCompatPathToTizen(destinationPath, destPath);
564 SysTryCatch(NID_CNT, !IsFailed(r), , r, "[%s] Failed to perform ChangedCompatPathToTizen.", GetErrorMessage(r));
566 if (pContentInfo != null)
568 pInfoImpl = const_cast< _ContentInfoImpl* >(_ContentInfoImpl::GetInstance(*pContentInfo));
569 SysTryCatch(NID_CNT, pInfoImpl != null, , E_INVALID_ARG,
570 "[E_INVALID_ARG] Invalid argument is used. ContentInfo is invalid.");
572 SysTryCatch(NID_CNT, pInfoImpl->GetContentId() == UuId::GetInvalidUuId(), , E_INVALID_ARG,
573 "[E_INVALID_ARG] The content already exists in database.");
575 // Compare the type of input parameter and system
576 // CheckContentType() need actual file. so it should be checked after creating the file.
577 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
578 ContentType inputType = pInfoImpl->GetContentType();
582 if (inputType != sysType)
584 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
586 SysLogException(NID_CNT, E_INVALID_ARG,
587 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
592 // Set the content path
593 pInfoImpl->SetContentPath(destPath);
597 ContentType contentType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
601 // Set the content path
602 if (contentType == CONTENT_TYPE_IMAGE)
604 r = imageContentInfoImpl.Construct(&destinationPath);
605 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
606 "[E_OUT_OF_MEMORY] Failed to perform Construct for ImageContentInfoImpl.");
608 imageContentInfoImpl.SetContentPath(destPath);
609 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&imageContentInfoImpl);
611 else if (contentType == CONTENT_TYPE_AUDIO)
613 r = audioContentInfoImpl.Construct(&destinationPath);
614 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
615 "[E_OUT_OF_MEMORY] Failed to perform Construct for AudioContentInfoImpl.");
617 audioContentInfoImpl.SetContentPath(destPath);
618 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&audioContentInfoImpl);
620 else if (contentType == CONTENT_TYPE_VIDEO)
622 r = videoContentInfoImpl.Construct(&destinationPath);
623 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
624 "[E_OUT_OF_MEMORY] Failed to perform Construct for VideoContentInfoImpl.");
626 videoContentInfoImpl.SetContentPath(destPath);
627 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&videoContentInfoImpl);
631 r = otherContentInfoImpl.Construct(&destinationPath);
632 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
633 "[E_OUT_OF_MEMORY] Failed to perform Construct for OtherContentInfoImpl.");
635 otherContentInfoImpl.SetContentPath(destPath);
636 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&otherContentInfoImpl);
640 pStr.reset(_StringConverter::CopyToCharArrayN(destPath));
641 SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
643 val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
644 SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
645 "media_info_insert_to_db failed[%d].", val);
647 pMediaInfo.reset(tempMediaInfo);
649 contentId = SaveDataToDatabase(pMediaInfo.get(), pInfoImpl);
651 SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
652 "[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
657 result saveResult = GetLastResult();
661 r = _FileImpl::Remove(destinationPath);
662 SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
666 r = _FileImpl::Move(destinationPath, sourcePath);
667 SysLog(NID_CNT, "Move[%s].", GetErrorMessage(r));
670 if (pMediaInfo != null)
672 val = media_info_delete_from_db(pStr.get());
673 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
676 SetLastResult(saveResult);
677 return UuId::GetInvalidUuId();
681 _ContentManagerImpl::GetContentInfoN(const ContentId& contentId) const
685 SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), null, E_INVALID_ARG,
686 "[E_INVALID_ARG] The contentId is invalid.");
688 unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(contentId.ToString()));
689 SysTryReturn(NID_CNT, pStr != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
691 media_info_h tempMediaInfo = null;
692 unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
693 int val = media_info_get_media_from_db(pStr.get(), &tempMediaInfo);
694 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
695 "media_info_get_media_from_db failed[%d].", val);
697 pMediaInfo.reset(tempMediaInfo);
699 media_content_type_e systemType = MEDIA_CONTENT_TYPE_IMAGE;
700 val = media_info_get_media_type(pMediaInfo.get(), &systemType);
701 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
702 "media_info_get_media_type failed[%d].", val);
704 char* pTempFilePath = null;
705 val = media_info_get_file_path(pMediaInfo.get(), &pTempFilePath);
706 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
707 "media_info_get_file_path failed[%d].", val);
709 unique_ptr<char, CharDeleter> pFilePath(pTempFilePath);
710 String contentPath(pFilePath.get());
711 String changedPath(L"");
713 result r = E_SUCCESS;
715 r = ChangeTizenPathToCompat(contentPath, changedPath);
716 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] Failed to perform ChangeTizenPathToCompat.", GetErrorMessage(r));
718 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(changedPath), null, E_FILE_NOT_FOUND,
719 "[E_FILE_NOT_FOUND] The file corresponding to contentId could not be found.");
721 if (systemType == SYSTEM_TYPE_IMAGE)
723 unique_ptr< ImageContentInfo > pImageContentInfo(new (nothrow) ImageContentInfo);
724 SysTryReturn(NID_CNT, pImageContentInfo != null, null, E_OUT_OF_MEMORY,
725 "[E_OUT_OF_MEMORY] The memory is insufficient.");
727 r = pImageContentInfo->Construct(&changedPath);
728 r = ConvertErrorToResult(r);
729 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
730 "[%s] Failed to perform Construct operation to ImageContentInfo.", GetErrorMessage(r));
732 _ImageContentInfoImpl* pImageContentInfoImpl = _ImageContentInfoImpl::GetInstance(*(pImageContentInfo.get()));
733 SysTryReturn(NID_CNT, pImageContentInfoImpl != null, null, E_OUT_OF_MEMORY,
734 "[E_OUT_OF_MEMORY] The memory is insufficient.");
736 r = MakeContentInfo(pMediaInfo.get(), systemType, pImageContentInfoImpl);
737 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
739 return pImageContentInfo.release();
741 else if (systemType == SYSTEM_TYPE_SOUND || systemType == SYSTEM_TYPE_MUSIC)
743 unique_ptr< AudioContentInfo > pAudioContentInfo(new (nothrow) AudioContentInfo);
744 SysTryReturn(NID_CNT, pAudioContentInfo != null, null, E_OUT_OF_MEMORY,
745 "[E_OUT_OF_MEMORY] The memory is insufficient.");
747 r = pAudioContentInfo->Construct(&changedPath);
748 r = ConvertErrorToResult(r);
749 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
750 "[%s] Failed to perform Construct operation to AudioContentInfo.", GetErrorMessage(r));
752 _AudioContentInfoImpl* pAudioContentInfoImpl = _AudioContentInfoImpl::GetInstance(*(pAudioContentInfo.get()));
753 SysTryReturn(NID_CNT, pAudioContentInfoImpl != null, null, E_OUT_OF_MEMORY,
754 "[E_OUT_OF_MEMORY] The memory is insufficient.");
756 r = MakeContentInfo(pMediaInfo.get(), systemType, pAudioContentInfoImpl);
757 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
759 return pAudioContentInfo.release();
761 else if (systemType == SYSTEM_TYPE_VIDEO)
763 unique_ptr< VideoContentInfo > pVideoContentInfo(new (nothrow) VideoContentInfo);
764 SysTryReturn(NID_CNT, pVideoContentInfo != null, null, E_OUT_OF_MEMORY,
765 "[E_OUT_OF_MEMORY] The memory is insufficient.");
767 r = pVideoContentInfo->Construct(&changedPath);
768 r = ConvertErrorToResult(r);
769 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
770 "[%s] Failed to perform Construct operation to VideoContentInfo.", GetErrorMessage(r));
772 _VideoContentInfoImpl* pVideoContentInfoImpl = _VideoContentInfoImpl::GetInstance(*(pVideoContentInfo.get()));
773 SysTryReturn(NID_CNT, pVideoContentInfoImpl != null, null, E_OUT_OF_MEMORY,
774 "[E_OUT_OF_MEMORY] The memory is insufficient.");
776 r = MakeContentInfo(pMediaInfo.get(), systemType, pVideoContentInfoImpl);
777 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
779 return pVideoContentInfo.release();
781 else if (systemType == SYSTEM_TYPE_OTHER)
783 unique_ptr< OtherContentInfo > pOtherContentInfo(new (nothrow) OtherContentInfo);
784 SysTryReturn(NID_CNT, pOtherContentInfo != null, null, E_OUT_OF_MEMORY,
785 "[E_OUT_OF_MEMORY] The memory is insufficient.");
787 r = pOtherContentInfo->Construct(&changedPath);
788 r = ConvertErrorToResult(r);
789 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
790 "[%s] Failed to perform Construct operation to OtherContentInfo.", GetErrorMessage(r));
792 _OtherContentInfoImpl* pOtherContentInfoImpl = _OtherContentInfoImpl::GetInstance(*(pOtherContentInfo.get()));
793 SysTryReturn(NID_CNT, pOtherContentInfoImpl != null, null, E_OUT_OF_MEMORY,
794 "[E_OUT_OF_MEMORY] The memory is insufficient.");
796 r = MakeContentInfo(pMediaInfo.get(), systemType, pOtherContentInfoImpl);
797 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
799 return pOtherContentInfo.release();
803 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] Unsupported type");
809 _ContentManagerImpl::UpdateContent(const ContentInfo& contentInfo)
811 const _ContentInfoImpl* pInfoImpl = _ContentInfoImpl::GetInstance(contentInfo);
812 SysTryReturnResult(NID_CNT, pInfoImpl != null, E_INVALID_ARG, "Invalid argument is used. ContentInfo is invalid.");
814 ContentId contentId = pInfoImpl->GetContentId();
815 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, "The content id is invalid.");
816 SysTryReturnResult(NID_CNT, _FileImpl::IsFileExist(pInfoImpl->GetContentPath()), E_FILE_NOT_FOUND,
817 "The file corresponding to contentInfo could not be found.");
819 result r = UpdateDataToDatabase(pInfoImpl);
820 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "UpdateDataToDatabase failed.");
826 _ContentManagerImpl::DeleteContent(const ContentId& contentId)
828 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, "The contentId is invalid.");
830 unique_ptr<char[]> pContentId(_StringConverter::CopyToCharArrayN(contentId.ToString()));
831 SysTryReturnResult(NID_CNT, pContentId != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
833 result r = E_SUCCESS;
835 media_info_h tempMediaInfo = null;
836 unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
838 val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
839 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
840 "media_info_get_media_from_db failed[%d].", val);
842 pMediaInfo.reset(tempMediaInfo);
844 char* pTempPath = null;
846 val = media_info_get_file_path(pMediaInfo.get(), &pTempPath);
847 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
848 "media_info_get_file_path failed[%d].", val);
850 unique_ptr<char, CharDeleter> pContentPath(pTempPath);
851 String contentPath(pContentPath.get());
852 String changedPath(L"");
854 r = ChangeTizenPathToCompat(contentPath, changedPath);
855 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "[%s] Failed to perform ChangeTizenPathToCompat.", GetErrorMessage(r));
857 SysTryReturnResult(NID_CNT, _FileImpl::IsFileExist(changedPath), E_FILE_NOT_FOUND,
858 "The file corresponding to contentId could not be found.");
860 val = media_info_delete_from_db(pContentId.get());
861 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
862 "media_info_delete_From_db failed[%d].", val);
864 r = _FileImpl::Remove(changedPath);
865 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The file is not deleted.");
871 _ContentManagerImpl::AddContentUpdateEventListener(IContentUpdateEventListener& listener)
873 SysTryReturnResult(NID_CNT, GetListener() == null, E_OBJ_ALREADY_EXIST, "IContentUpdateEventListener is already set.");
875 SetListener(&listener);
877 int val = media_content_set_db_updated_cb(OnContentUpdateCompleted, this);
878 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "media_content_set_db_updated_cb failed[%d].", val);
884 _ContentManagerImpl::RemoveContentUpdateEventListener(IContentUpdateEventListener& listener)
886 SysTryReturnResult(NID_CNT, GetListener() == &listener, E_OBJ_NOT_FOUND, "The input listener is not equal to the registered listener.");
888 int val = media_content_unset_db_updated_cb();
889 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "media_content_unset_db_updated_cb failed[%d].", val);
897 _ContentManagerImpl::ScanFile(const Tizen::Base::String& contentPath)
899 SysSecureLog(NID_CNT, "The scan path is [%ls].", contentPath.GetPointer());
901 unique_ptr<char[]> pContentPath(_StringConverter::CopyToCharArrayN(contentPath));
902 SysTryReturnResult(NID_CNT, pContentPath, E_SYSTEM, "pContentPath is NULL.");
904 int val = media_content_connect();
905 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The connection failed[%d].", val);
907 val = media_content_scan_file(pContentPath.get());
908 result r = ConvertError(val);
909 SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , r, "[%s] media_content_scan_file failed[%d].", GetErrorMessage(r), val);
911 val = media_content_disconnect();
912 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The disconnection failed[%d].", val);
917 val = media_content_disconnect();
918 SysTryLog(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, "The disconnection failed[%d].", val);
924 _ContentManagerImpl::ScanDirectory(const Tizen::Base::String& directoryPath, bool recursive, IContentScanListener* pListener, RequestId& reqId)
926 static RequestId requestId = 0;
928 SysLog(NID_CNT, "The scan path is [%ls].", directoryPath.GetPointer());
930 unique_ptr<char[]> pDirPath(_StringConverter::CopyToCharArrayN(directoryPath));
931 SysTryReturnResult(NID_CNT, pDirPath, E_SYSTEM, "pDirPath is NULL.");
933 int val = media_content_connect();
934 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The connection failed[%d].", val);
936 unique_ptr< _ScanResult > pScanResult(new (nothrow) _ScanResult);
937 SysTryReturnResult(NID_CNT, pScanResult != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
941 pScanResult->scanPath = directoryPath;
942 pScanResult->pScanListener = pListener;
943 pScanResult->requestId = reqId;
945 val = media_content_scan_folder(pDirPath.get(), recursive, OnScanCompleted, pScanResult.release());
946 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val), "media_content_scan_folder failed[%d].", val);
952 _ContentManagerImpl::UpdateDataToDatabase(const _ContentInfoImpl* pContentInfoImpl) const
954 SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_INVALID_ARG, "pContentInfoImpl is null.");
956 media_info_h tempMediaInfo = null;
957 unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
958 unique_ptr<char[]> pContentId(_StringConverter::CopyToCharArrayN((pContentInfoImpl->GetContentId()).ToString()));
959 SysTryReturnResult(NID_CNT, pContentId != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
961 int val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
962 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
963 "media_info_get_media_from_db failed[%d].", val);
965 pMediaInfo.reset(tempMediaInfo);
967 result r = E_SUCCESS;
968 unique_ptr<char[]> pValue(null);
971 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetAuthor()));
972 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
974 val = media_info_set_author(pMediaInfo.get(), pValue.get());
975 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
976 "media_info_set_author failed[%d].", val);
979 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetCategory()));
980 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
982 val = media_info_set_category(pMediaInfo.get(), pValue.get());
983 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
984 "media_info_set_category failed[%d].", val);
987 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetContentName()));
988 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
990 val = media_info_set_content_name(pMediaInfo.get(), pValue.get());
991 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
992 "media_info_set_content_name failed[%d].", val);
995 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetDescription()));
996 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
998 val = media_info_set_description(pMediaInfo.get(), pValue.get());
999 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1000 "media_info_set_description failed[%d].", val);
1003 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetKeyword()));
1004 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1006 val = media_info_set_keyword(pMediaInfo.get(), pValue.get());
1007 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1008 "media_info_set_keyword failed[%d].", val);
1011 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetLocationTag()));
1012 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1014 val = media_info_set_location_tag(pMediaInfo.get(), pValue.get());
1015 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1016 "media_info_set_location_tag failed[%d].", val);
1019 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetProvider()));
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);
1027 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetRating()));
1028 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1030 val = media_info_set_age_rating(pMediaInfo.get(), pValue.get());
1031 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1032 "media_info_set_age_rating failed[%d].", val);
1034 // latitude, longitude, altitude
1035 if (Double::Compare(pContentInfoImpl->GetLatitude(), DEFAULT_COORDINATE) != 0 &&
1036 Double::Compare(pContentInfoImpl->GetLongitude(), DEFAULT_COORDINATE) != 0)
1038 val = media_info_set_latitude(pMediaInfo.get(), pContentInfoImpl->GetLatitude());
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(), pContentInfoImpl->GetLongitude());
1043 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1044 "media_info_set_longitude failed[%d].", val);
1046 if (Double::Compare(pContentInfoImpl->GetAltitude(), DEFAULT_COORDINATE) != 0)
1048 val = media_info_set_altitude(pMediaInfo.get(), pContentInfoImpl->GetAltitude());
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);
1062 _ContentManagerImpl::SaveDataToDatabase(const media_info_h pMediaInfo,
1063 _ContentInfoImpl* pContentInfoImpl) const
1066 result r = E_SUCCESS;
1068 SysTryReturn(NID_CNT, pContentInfoImpl != null, UuId::GetInvalidUuId(), E_INVALID_ARG,
1069 "[E_INVALID_ARG] Invalid argument is used. ContentInfo is invalid.");
1071 String contentPath(pContentInfoImpl->GetPhysicalContentPath());
1072 String changedPath(L"");
1074 r = ChangeTizenPathToCompat(contentPath, changedPath);
1075 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r,
1076 "[%s] Failed to perform ChangeTizenPathToCompat.", GetErrorMessage(r));
1078 String mimeType(L"");
1079 String extension = _FileImpl::GetFileExtension(changedPath);
1080 r = GetLastResult();
1085 SysLog(NID_CNT, "[%s] Failed to perform GetFileExtension operation.", GetErrorMessage(r));
1087 unique_ptr<char[]> pTempPath(_StringConverter::CopyToCharArrayN(contentPath));
1088 SysTryReturn(NID_CNT, pTempPath != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1089 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1091 char tempType[255] = {0, };
1092 int ret = aul_get_mime_from_file(pTempPath.get(), tempType, sizeof(tempType));
1093 SysTryReturn(NID_CNT, ret == AUL_R_OK, UuId::GetInvalidUuId(), E_INVALID_ARG,
1094 "[E_INVALID_ARG] Failed to perform aul_get_mime_from_file operation.");
1096 r = mimeType.Append(tempType);
1097 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1098 "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
1102 // If the content format is JPG and it has GPS data, it will be saved in database automatically.
1103 if (extension == L"jpg" || extension == L"jpeg" || extension == L"JPG" || extension == L"JPEG" || mimeType.Contains(L"jpeg"))
1105 SysLog(NID_CNT, "The format of content is jpg.");
1107 ImageMetadata* pImageMetadata = _ContentManagerUtilImpl::GetImageMetaN(changedPath, true);
1108 if (pImageMetadata != null)
1110 pContentInfoImpl->SetLatitude(pImageMetadata->GetLatitude());
1111 pContentInfoImpl->SetLongitude(pImageMetadata->GetLongitude());
1113 delete pImageMetadata;
1120 unique_ptr<char[]> pStr(null);
1123 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetAuthor()));
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_author(pMediaInfo, pStr.get());
1128 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1129 "media_info_set_author failed[%d].", val);
1132 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetCategory()));
1133 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1134 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1136 val = media_info_set_category(pMediaInfo, pStr.get());
1137 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1138 "media_info_set_category failed[%d].", val);
1141 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetContentName()));
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_content_name(pMediaInfo, pStr.get());
1146 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1147 "media_info_set_content_name failed[%d].", val);
1150 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetDescription()));
1151 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1152 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1154 val = media_info_set_description(pMediaInfo, pStr.get());
1155 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1156 "media_info_set_description failed[%d].", val);
1159 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetKeyword()));
1160 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1161 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1163 val = media_info_set_keyword(pMediaInfo, pStr.get());
1164 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1165 "media_info_set_keyword failed[%d].", val);
1168 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetLocationTag()));
1169 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1170 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1172 val = media_info_set_location_tag(pMediaInfo, pStr.get());
1173 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1174 "media_info_set_location_tag failed[%d].", val);
1177 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetProvider()));
1178 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1179 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1181 val = media_info_set_provider(pMediaInfo, pStr.get());
1182 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1183 "media_info_set_provider failed[%d].", val);
1186 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetRating()));
1187 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1188 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1190 val = media_info_set_age_rating(pMediaInfo, pStr.get());
1191 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1192 "media_info_set_age_rating failed[%d].", val);
1194 // latitude, longitude, altitude
1195 if (Double::Compare(pContentInfoImpl->GetLatitude(), DEFAULT_COORDINATE) != 0 &&
1196 Double::Compare(pContentInfoImpl->GetLongitude(), DEFAULT_COORDINATE) != 0)
1198 val = media_info_set_latitude(pMediaInfo, pContentInfoImpl->GetLatitude());
1199 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1200 "media_info_set_latitude failed[%d].", val);
1202 val = media_info_set_longitude(pMediaInfo, pContentInfoImpl->GetLongitude());
1203 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1204 "media_info_set_longitude failed[%d].", val);
1206 if (Double::Compare(pContentInfoImpl->GetAltitude(), DEFAULT_COORDINATE) != 0)
1208 val = media_info_set_altitude(pMediaInfo, pContentInfoImpl->GetAltitude());
1209 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1210 "media_info_set_altitude failed[%d].", val);
1214 val = media_info_update_to_db(pMediaInfo);
1215 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1216 "media_info_update_to_db failed[%d].", val);
1218 char* pTempMediaId = null;
1219 unique_ptr<char, CharDeleter> pMediaId(null);
1221 val = media_info_get_media_id(pMediaInfo, &pTempMediaId);
1222 if (pTempMediaId != null)
1224 pMediaId.reset(pTempMediaId);
1228 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1229 "media_info_get_media_id failed[%d].", val);
1232 String tempContentId(pMediaId.get());
1233 ContentId contentId;
1235 r = UuId::Parse(tempContentId, contentId);
1236 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_INVALID_ARG,
1237 "[E_INVALID_ARG] UuId::Parse failed.");
1243 _ContentManagerImpl::MakeContentInfo(const media_info_h pMediaInfo, int systemType, void* pInfoImpl) const
1245 SysTryReturnResult(NID_CNT, pMediaInfo != null && pInfoImpl != null, E_INVALID_ARG,
1246 "The specified parameter is invalid.");
1248 _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1250 result r = E_SUCCESS;
1251 char* pTempValue = null;
1252 unique_ptr<char, CharDeleter> pStrValue(null);
1255 int val = media_info_get_media_id(pMediaInfo, &pTempValue);
1256 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1257 "media_info_get_media_id failed[%d].", val);
1259 if (pTempValue != null)
1261 pStrValue.reset(pTempValue);
1263 String strContentId(pStrValue.get());
1264 ContentId contentId;
1266 r = UuId::Parse(strContentId, contentId);
1267 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The content id can not be parsed.");
1269 pContentInfoImpl->SetContentId(contentId);
1271 SysLog(NID_CNT, "INFO: contentId[%ls]", strContentId.GetPointer());
1275 val = media_info_get_file_path(pMediaInfo, &pTempValue);
1276 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1277 "media_info_get_file_path failed[%d].", val);
1279 if (pTempValue != null)
1281 pStrValue.reset(pTempValue);
1283 String strFilePath(pStrValue.get());
1285 pContentInfoImpl->SetContentPath(strFilePath);
1286 SysSecureLog(NID_CNT, "INFO: contentPath[%ls]", (pContentInfoImpl->GetContentPath()).GetPointer());
1290 val = media_info_get_mime_type(pMediaInfo, &pTempValue);
1291 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1292 "media_info_get_mime_type failed[%d].", val);
1294 if (pTempValue != null)
1296 pStrValue.reset(pTempValue);
1298 pContentInfoImpl->SetMimeType(pStrValue.get());
1300 SysLog(NID_CNT, "INFO: mimeType[%ls]", (pContentInfoImpl->GetMimeType()).GetPointer());
1304 unsigned long long longlongValue = 0;
1305 val = media_info_get_size(pMediaInfo, &longlongValue);
1306 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1307 "media_info_get_size failed[%d].", val);
1308 pContentInfoImpl->SetContentSize(longlongValue);
1309 SysLog(NID_CNT, "INFO: contentSize[%llu]", longlongValue);
1312 media_content_storage_e storageType;
1313 val = media_info_get_storage_type(pMediaInfo, &storageType);
1314 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1315 "media_info_get_storage_type failed[%d].", val);
1316 pContentInfoImpl->SetStorageType(storageType);
1317 SysLog(NID_CNT, "INFO: storageType[%d]", storageType);
1320 bool tempDrm = false;
1322 val = media_info_is_drm(pMediaInfo, &tempDrm);
1323 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1324 "media_info_is_drm failed[%d].", val);
1326 pContentInfoImpl->SetDrmProtected(tempDrm);
1328 SysLog(NID_CNT, "INFO: isDrm[%d]", pContentInfoImpl->IsDrmProtected());
1331 time_t addedTime = 0;
1332 val = media_info_get_added_time(pMediaInfo, &addedTime);
1333 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1334 "media_info_get_added_time failed[%d].", val);
1337 r = dt.SetValue(1970, 1, 1);
1338 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.SetValue operation.");
1339 r = dt.AddSeconds(addedTime);// need to check addedTime is secs/millisec
1340 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.AddSeconds operation.");
1342 pContentInfoImpl->SetDateTime(dt);
1343 SysLog(NID_CNT, "INFO: dateTime[%ls]", ((pContentInfoImpl->GetDateTime()).ToString()).GetPointer());
1346 time_t modifiedTime = 0;
1347 val = media_info_get_modified_time(pMediaInfo, &modifiedTime);
1348 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1349 "media_info_get_modified_time failed[%d].", val);
1351 r = dt.SetValue(1970, 1, 1);
1352 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.SetValue operation.");
1353 r = dt.AddSeconds(modifiedTime);
1354 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.AddSeconds operation.");
1356 pContentInfoImpl->SetModifiedTime(dt);
1357 SysLog(NID_CNT, "INFO: modifiedTime[%ls]", ((pContentInfoImpl->GetModifiedTime()).ToString()).GetPointer());
1360 val = media_info_get_thumbnail_path(pMediaInfo, &pTempValue);
1361 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1362 "media_info_get_thumbnail_path failed[%d].", val);
1364 if (pTempValue != null)
1366 pStrValue.reset(pTempValue);
1367 String thumbnailPath(pStrValue.get());
1369 pContentInfoImpl->SetThumbnailPath(thumbnailPath);
1370 SysLog(NID_CNT, "INFO: thumbnailPath[%ls]", (pContentInfoImpl->GetThumbnailPath()).GetPointer());
1374 val = media_info_get_author(pMediaInfo, &pTempValue);
1375 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1376 "media_info_get_author failed[%d].", val);
1378 if (pTempValue != null)
1380 pStrValue.reset(pTempValue);
1382 pContentInfoImpl->SetAuthor(String(pStrValue.get()));
1384 SysLog(NID_CNT, "INFO: author[%ls]", (pContentInfoImpl->GetAuthor()).GetPointer());
1388 val = media_info_get_category(pMediaInfo, &pTempValue);
1389 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1390 "media_info_get_category failed[%d].", val);
1392 if (pTempValue != null)
1394 pStrValue.reset(pTempValue);
1396 pContentInfoImpl->SetCategory(String(pStrValue.get()));
1398 SysLog(NID_CNT, "INFO: category[%ls]", (pContentInfoImpl->GetCategory()).GetPointer());
1402 val = media_info_get_content_name(pMediaInfo, &pTempValue);
1403 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1404 "media_info_get_content_name failed[%d].", val);
1406 if (pTempValue != null)
1408 pStrValue.reset(pTempValue);
1410 pContentInfoImpl->SetContentName(String(pStrValue.get()));
1412 SysSecureLog(NID_CNT, "INFO: contentName[%ls]", (pContentInfoImpl->GetContentName()).GetPointer());
1416 val = media_info_get_description(pMediaInfo, &pTempValue);
1417 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1418 "media_info_get_description failed[%d].", val);
1420 if (pTempValue != null)
1422 pStrValue.reset(pTempValue);
1424 pContentInfoImpl->SetDescription(String(pStrValue.get()));
1426 SysLog(NID_CNT, "INFO: description[%ls]", (pContentInfoImpl->GetDescription()).GetPointer());
1430 val = media_info_get_keyword(pMediaInfo, &pTempValue);
1431 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1432 "media_info_get_keyword failed[%d].", val);
1434 if (pTempValue != null)
1436 pStrValue.reset(pTempValue);
1438 pContentInfoImpl->SetKeyword(String(pStrValue.get()));
1440 SysLog(NID_CNT, "INFO: keyword[%ls]", (pContentInfoImpl->GetKeyword()).GetPointer());
1444 val = media_info_get_location_tag(pMediaInfo, &pTempValue);
1445 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1446 "media_info_get_location_tag failed[%d].", val);
1448 if (pTempValue != null)
1450 pStrValue.reset(pTempValue);
1452 pContentInfoImpl->SetLocationTag(String(pStrValue.get()));
1454 SysSecureLog(NID_CNT, "INFO: locationTag[%ls]", (pContentInfoImpl->GetLocationTag()).GetPointer());
1458 val = media_info_get_provider(pMediaInfo, &pTempValue);
1459 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1460 "media_info_get_provider failed[%d].", val);
1462 if (pTempValue != null)
1464 pStrValue.reset(pTempValue);
1466 pContentInfoImpl->SetProvider(String(pStrValue.get()));
1468 SysLog(NID_CNT, "INFO: provider[%ls]", (pContentInfoImpl->GetProvider()).GetPointer());
1472 val = media_info_get_age_rating(pMediaInfo, &pTempValue);
1473 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1474 "media_info_get_age_rating failed[%d].", val);
1476 if (pTempValue != null)
1478 pStrValue.reset(pTempValue);
1480 pContentInfoImpl->SetRating(String(pStrValue.get()));
1482 SysLog(NID_CNT, "INFO: rating[%ls]", (pContentInfoImpl->GetRating()).GetPointer());
1486 Coordinates coordinates;
1487 double doubleValue = 0;
1488 val = media_info_get_latitude(pMediaInfo, &doubleValue);
1489 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1490 "media_info_get_latitude failed[%d].", val);
1492 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1494 pContentInfoImpl->SetLatitude(doubleValue);
1495 coordinates.SetLatitude(doubleValue);
1497 SysSecureLog(NID_CNT, "INFO: latitude[%f]", pContentInfoImpl->GetLatitude());
1499 val = media_info_get_longitude(pMediaInfo, &doubleValue);
1500 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1501 "media_info_get_longitude failed[%d].", val);
1503 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1505 pContentInfoImpl->SetLongitude(doubleValue);
1506 coordinates.SetLongitude(doubleValue);
1508 SysSecureLog(NID_CNT, "INFO: longitude[%f]", pContentInfoImpl->GetLongitude());
1510 val = media_info_get_altitude(pMediaInfo, &doubleValue);
1511 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1512 "media_info_get_altitude failed[%d].", val);
1514 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1516 pContentInfoImpl->SetAltitude(doubleValue);
1517 coordinates.SetAltitude(doubleValue);
1519 SysLog(NID_CNT, "INFO: altitude[%f]", pContentInfoImpl->GetAltitude());
1521 pContentInfoImpl->SetCoordinates(coordinates);
1523 // contentType and metadata
1524 if (systemType == SYSTEM_TYPE_IMAGE)
1526 r = MakeImageContentInfo(pMediaInfo, pInfoImpl);
1527 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform MakeImageContentInfo operation.");
1529 else if (systemType == SYSTEM_TYPE_SOUND || systemType == SYSTEM_TYPE_MUSIC)
1531 r = MakeAudioContentInfo(pMediaInfo, pInfoImpl);
1532 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform MakeAudioContentInfo operation.");
1534 else if (systemType == MEDIA_CONTENT_TYPE_VIDEO)
1536 r = MakeVideoContentInfo(pMediaInfo, pInfoImpl);
1537 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform MakeVideoContentInfo operation.");
1539 else if (systemType == SYSTEM_TYPE_OTHER)
1541 pContentInfoImpl->SetContentType(CONTENT_TYPE_OTHER);
1542 SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1549 _ContentManagerImpl::MakeImageContentInfo(const media_info_h pMediaInfo, void* pInfoImpl) const
1551 result r = E_SUCCESS;
1553 bool boolValue = false;
1554 image_meta_h pTempMeta = null;
1555 unique_ptr<image_meta_h, _ImageMetaDeleter> pImageMeta(null);
1557 SysTryReturnResult(NID_CNT, pInfoImpl != null, E_OUT_OF_MEMORY, "pInfoImpl is null.");
1559 _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1560 SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ContentInfoImpl.");
1562 pContentInfoImpl->SetContentType(CONTENT_TYPE_IMAGE);
1563 SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1565 int val = media_info_get_image(pMediaInfo, &pTempMeta);
1566 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1567 "media_info_get_image failed[%d].", val);
1569 pImageMeta.reset(&pTempMeta);
1571 _ImageContentInfoImpl* pImageContentInfoImpl = static_cast< _ImageContentInfoImpl* >(pInfoImpl);
1572 SysTryReturnResult(NID_CNT, pImageContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ImageContentInfoImpl.");
1575 val = image_meta_get_width(*(pImageMeta.get()), &intValue);
1576 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1577 "image_meta_get_width failed[%d].", val);
1579 pImageContentInfoImpl->SetWidth(intValue);
1580 SysLog(NID_CNT, "META: width[%d]", intValue);
1583 val = image_meta_get_height(*(pImageMeta.get()), &intValue);
1584 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1585 "image_meta_get_height failed[%d].", val);
1587 pImageContentInfoImpl->SetHeight(intValue);
1588 SysLog(NID_CNT, "META: height[%d]", intValue);
1591 media_content_orientation_e orientation;
1592 val = image_meta_get_orientation(*(pImageMeta.get()), &orientation);
1593 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1594 "image_meta_get_orientation failed[%d].", val);
1596 pImageContentInfoImpl->SetOrientation(static_cast< ImageOrientationType >(orientation));
1597 SysLog(NID_CNT, "META: orientation[%d]", orientation);
1599 char* pTempValue = null;
1600 unique_ptr<char, CharDeleter> pStrValue(null);
1603 val = media_info_get_display_name(pMediaInfo, &pTempValue);
1604 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1605 "media_info_get_display_name failed[%d].", val);
1607 if (pTempValue != null)
1609 pStrValue.reset(pTempValue);
1613 String strTitle(pStrValue.get());
1615 result r = strTitle.LastIndexOf(L'.', strTitle.GetLength() - 1, pos);
1618 r = strTitle.SubString(0, pos, fileName);
1619 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The title is invalid.");
1623 // Without extension
1625 fileName = strTitle;
1628 pImageContentInfoImpl->SetTitle(fileName);
1630 SysLog(NID_CNT, "META: title[%ls]", fileName.GetPointer());
1634 val = image_meta_get_date_taken(*(pImageMeta.get()), &pTempValue);
1635 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1636 "image_meta_get_date_taken failed[%d].", val);
1640 if (pTempValue != null)
1642 pStrValue.reset(pTempValue);
1643 String dateTaken(pStrValue.get());
1644 String newDateTaken(L"");
1646 // detour the unexpected datetaken format
1647 String tempDelim(L"+-Z");
1650 StringTokenizer tempStrTok(dateTaken, tempDelim);
1652 r = tempStrTok.GetNextToken(token);
1653 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1657 String delim(L": ");
1660 StringTokenizer strTok(dateTaken, delim);
1662 r = strTok.SetDelimiters(delim);
1663 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform SetDelimiters operation.");
1665 r = strTok.GetNextToken(token);
1666 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1671 r = strTok.GetNextToken(token);
1672 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1674 r = newDateTaken.Append(token);
1675 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1677 r = newDateTaken.Append(L"/");
1678 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1681 r = strTok.GetNextToken(token);
1682 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1684 r = newDateTaken.Append(token);
1685 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1687 r = newDateTaken.Append(L"/");
1688 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1691 r = newDateTaken.Append(year);
1692 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1694 r = newDateTaken.Append(L" ");
1695 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1697 String newDelim(L" ");
1699 r = strTok.SetDelimiters(newDelim);
1700 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform SetDelimiters operation.");
1702 r = strTok.GetNextToken(token);
1703 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1705 r = newDateTaken.Append(token);
1706 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1708 r = DateTime::Parse(newDateTaken, dt);
1709 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform Parse operation for DateTime.");
1713 dt = DateTime::GetMinValue();
1716 pImageContentInfoImpl->SetImageTakenDate(dt);
1717 SysLog(NID_CNT, "META: dateTaken[%ls]", dt.ToString().GetPointer());
1720 val = image_meta_is_burst_shot(*(pImageMeta.get()), &boolValue);
1721 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1722 "image_meta_is_burst_shot failed[%d].", val);
1724 pImageContentInfoImpl->SetBurstShot(boolValue);
1725 SysLog(NID_CNT, "META: isBurstShot[%d]", boolValue);
1728 val = image_meta_get_burst_id(*(pImageMeta.get()), &pTempValue);
1729 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1730 "image_meta_get_burst_id failed[%d].", val);
1732 if (pTempValue != null)
1734 pStrValue.reset(pTempValue);
1735 String burstShotId(pStrValue.get());
1737 pImageContentInfoImpl->SetBurstShotId(burstShotId);
1738 SysLog(NID_CNT, "META: burstShotId[%ls]", burstShotId.GetPointer());
1745 _ContentManagerImpl::MakeAudioContentInfo(const media_info_h pMediaInfo, void* pInfoImpl) const
1748 audio_meta_h pTempMeta = null;
1749 unique_ptr<audio_meta_h, _AudioMetaDeleter> pAudioMeta(null);
1751 SysTryReturnResult(NID_CNT, pInfoImpl != null, E_OUT_OF_MEMORY, "pInfoImpl is null.");
1753 _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1754 SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ContentInfoImpl.");
1756 pContentInfoImpl->SetContentType(CONTENT_TYPE_AUDIO);
1757 SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1759 int val = media_info_get_audio(pMediaInfo, &pTempMeta);
1760 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1761 "media_info_get_audio failed[%d].", val);
1763 pAudioMeta.reset(&pTempMeta);
1765 _AudioContentInfoImpl* pAudioContentInfoImpl = static_cast< _AudioContentInfoImpl* >(pInfoImpl);
1766 SysTryReturnResult(NID_CNT, pAudioContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _AudioContentInfoImpl.");
1769 val = audio_meta_get_bit_rate(*(pAudioMeta.get()), &intValue);
1770 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1771 "audio_meta_get_bit_rate failed[%d].", val);
1773 pAudioContentInfoImpl->SetBitrate(intValue);
1774 SysLog(NID_CNT, "META: bitrate[%d]", intValue);
1776 char* pTempValue = null;
1777 unique_ptr<char, CharDeleter> pStrValue(null);
1780 val = audio_meta_get_year(*(pAudioMeta.get()), &pTempValue);
1781 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1782 "audio_meta_get_year failed[%d].", val);
1784 if (pTempValue != null)
1786 pStrValue.reset(pTempValue);
1788 String strYear(pStrValue.get());
1790 if (strYear.CompareTo(L"Unknown") != 0)
1792 result r = Integer::Parse(strYear, intValue);
1795 // It is one of the metadata. If error occurs, skip it for other metadata.
1798 SysLog(NID_CNT, "META: releaseYear - invalid data[%ls]", strYear.GetPointer());
1801 pAudioContentInfoImpl->SetReleaseYear(intValue);
1802 SysLog(NID_CNT, "META: releaseYear[%d]", intValue);
1807 val = audio_meta_get_title(*(pAudioMeta.get()), &pTempValue);
1808 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1809 "audio_meta_get_title failed[%d].", val);
1811 if (pTempValue != null)
1813 pStrValue.reset(pTempValue);
1815 pAudioContentInfoImpl->SetTitle(String(pStrValue.get()));
1817 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
1821 val = audio_meta_get_album(*(pAudioMeta.get()), &pTempValue);
1822 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1823 "audio_meta_get_album failed[%d].", val);
1825 if (pTempValue != null)
1827 pStrValue.reset(pTempValue);
1829 pAudioContentInfoImpl->SetAlbumName(String(pStrValue.get()));
1831 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
1835 val = audio_meta_get_artist(*(pAudioMeta.get()), &pTempValue);
1836 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1837 "audio_meta_get_artist failed[%d].", val);
1839 if (pTempValue != null)
1841 pStrValue.reset(pTempValue);
1843 pAudioContentInfoImpl->SetArtist(String(pStrValue.get()));
1845 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
1849 val = audio_meta_get_composer(*(pAudioMeta.get()), &pTempValue);
1850 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1851 "audio_meta_get_composer failed[%d].", val);
1853 if (pTempValue != null)
1855 pStrValue.reset(pTempValue);
1857 pAudioContentInfoImpl->SetComposer(String(pStrValue.get()));
1859 SysLog(NID_CNT, "META: composer[%ls]", (String(pStrValue.get())).GetPointer());
1863 val = audio_meta_get_genre(*(pAudioMeta.get()), &pTempValue);
1864 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1865 "audio_meta_get_genre failed[%d].", val);
1867 if (pTempValue != null)
1869 pStrValue.reset(pTempValue);
1871 pAudioContentInfoImpl->SetGenre(String(pStrValue.get()));
1873 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
1877 val = audio_meta_get_copyright(*(pAudioMeta.get()), &pTempValue);
1878 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1879 "audio_meta_get_copyright failed[%d].", val);
1881 if (pTempValue != null)
1883 pStrValue.reset(pTempValue);
1885 pAudioContentInfoImpl->SetCopyright(String(pStrValue.get()));
1887 SysLog(NID_CNT, "META: copyright[%ls]", (String(pStrValue.get())).GetPointer());
1891 val = audio_meta_get_track_num(*(pAudioMeta.get()), &pTempValue);
1892 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1893 "audio_meta_get_track_num failed[%d].", val);
1895 if (pTempValue != null)
1897 pStrValue.reset(pTempValue);
1899 pAudioContentInfoImpl->SetTrackInfo(String(pStrValue.get()));
1901 SysLog(NID_CNT, "META: trackInfo[%ls]", (String(pStrValue.get())).GetPointer());
1905 val = audio_meta_get_duration(*(pAudioMeta.get()), &intValue);
1906 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1907 "audio_meta_get_duration failed[%d].", val);
1909 pAudioContentInfoImpl->SetDuration(intValue);
1910 SysLog(NID_CNT, "META: duration[%d]", intValue);
1916 _ContentManagerImpl::MakeVideoContentInfo(const media_info_h pMediaInfo, void* pInfoImpl) const
1919 video_meta_h pTempMeta = null;
1920 unique_ptr<video_meta_h, _VideoMetaDeleter> pVideoMeta(null);
1922 SysTryReturnResult(NID_CNT, pInfoImpl != null, E_OUT_OF_MEMORY, "pInfoImpl is null.");
1924 _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1925 SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ContentInfoImpl.");
1927 pContentInfoImpl->SetContentType(CONTENT_TYPE_VIDEO);
1928 SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1930 int val = media_info_get_video(pMediaInfo, &pTempMeta);
1931 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1932 "media_info_get_video failed[%d].", val);
1934 pVideoMeta.reset(&pTempMeta);
1936 _VideoContentInfoImpl* pVideoContentInfoImpl = static_cast< _VideoContentInfoImpl* >(pInfoImpl);
1937 SysTryReturnResult(NID_CNT, pVideoContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _VideoContentInfoImpl.");
1940 val = video_meta_get_width(*(pVideoMeta.get()), &intValue);
1941 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1942 "video_meta_get_width failed[%d].", val);
1944 pVideoContentInfoImpl->SetWidth(intValue);
1945 SysLog(NID_CNT, "META: width[%d]", intValue);
1948 val = video_meta_get_height(*(pVideoMeta.get()), &intValue);
1949 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1950 "video_meta_get_height failed[%d].", val);
1952 pVideoContentInfoImpl->SetHeight(intValue);
1953 SysLog(NID_CNT, "META: height[%d]", intValue);
1955 char* pTempValue = null;
1956 unique_ptr<char, CharDeleter> pStrValue(null);
1959 val = video_meta_get_artist(*(pVideoMeta.get()), &pTempValue);
1960 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1961 "video_meta_get_artist failed[%d].", val);
1963 if (pTempValue != null)
1965 pStrValue.reset(pTempValue);
1967 pVideoContentInfoImpl->SetArtist(String(pStrValue.get()));
1969 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
1973 val = video_meta_get_genre(*(pVideoMeta.get()), &pTempValue);
1974 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1975 "video_meta_get_genre failed[%d].", val);
1977 if (pTempValue != null)
1979 pStrValue.reset(pTempValue);
1981 pVideoContentInfoImpl->SetGenre(String(pStrValue.get()));
1983 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
1987 val = video_meta_get_title(*(pVideoMeta.get()), &pTempValue);
1988 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1989 "video_meta_get_title failed[%d].", val);
1991 if (pTempValue != null)
1993 pStrValue.reset(pTempValue);
1995 pVideoContentInfoImpl->SetTitle(String(pStrValue.get()));
1997 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
2001 val = video_meta_get_album(*(pVideoMeta.get()), &pTempValue);
2002 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
2003 "video_meta_get_album failed[%d].", val);
2005 if (pTempValue != null)
2007 pStrValue.reset(pTempValue);
2009 pVideoContentInfoImpl->SetAlbumName(String(pStrValue.get()));
2011 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
2015 val = video_meta_get_duration(*(pVideoMeta.get()), &intValue);
2016 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
2017 "video_meta_get_duration failed[%d].", val);
2019 pVideoContentInfoImpl->SetDuration(intValue);
2020 SysLog(NID_CNT, "META: duration[%d]", intValue);
2022 // Get from metadata extractor (framerate, audio bitrate, video bitrate)
2023 VideoMetadata* pVideoMetadata = ContentManagerUtil::GetVideoMetaN(pVideoContentInfoImpl->GetContentPath());
2024 result r = GetLastResult();
2025 SysTryReturnResult(NID_CNT, pVideoMetadata != null, r, "GetVideoMetadata() failed.");
2027 pVideoContentInfoImpl->SetFramerate(pVideoMetadata->GetFramerate());
2028 pVideoContentInfoImpl->SetAudioBitrate(pVideoMetadata->GetAudioBitrate());
2029 pVideoContentInfoImpl->SetVideoBitrate(pVideoMetadata->GetVideoBitrate());
2035 _ContentManagerImpl::VerifyHomeFilePathCompatibility(const String& contentPath) const
2037 if (!_AppInfo::IsOspCompat())
2039 if (contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0))
2041 SysLogException(NID_CNT, E_INVALID_ARG,
2042 "[E_INVALID_ARG] /Home/ or /HomeExt/ is not supported from Tizen 2.0.");
2045 if (!(contentPath.StartsWith(App::App::GetInstance()->GetAppRootPath(), 0) ||
2046 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
2048 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] The path is not supported.");
2054 SysTryReturn(NID_CNT, contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0),
2055 false, E_INVALID_ARG, "[E_INVALID_ARG] The path should start with /Home or /HomeExt.");
2062 _ContentManagerImpl::VerifyMediaFilePathCompatibility(const String& contentPath) const
2066 if (!_AppInfo::IsOspCompat())
2068 if (!(contentPath.StartsWith(Environment::GetMediaPath(), 0) ||
2069 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
2071 SysLogException(NID_CNT, E_INVALID_ARG, "[%s] This path is not supported.", GetErrorMessage(E_INVALID_ARG));
2078 if (!(contentPath.StartsWith(OSP_MEDIA_PHONE, 0)) ||
2079 (contentPath.StartsWith(OSP_MEDIA_MMC, 0)))
2081 SysLogException(NID_CNT, E_INVALID_ARG, "[%s] The path should start with /Media, or /Storagecard/Media.", GetErrorMessage(E_INVALID_ARG));
2090 _ContentManagerImpl::ChangeTizenPathToCompat(const String& contentPath, String& changedPath) const
2092 result r = E_SUCCESS;
2093 changedPath = contentPath;
2095 // If the api version is 2.0, the content path has to be changed.
2096 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
2098 r = _FileImpl::ConvertPhysicalToVirtualPath(contentPath, changedPath);
2099 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG,
2100 "[%s] Failed to convert physical path to virtual path.", GetErrorMessage(E_INVALID_ARG));
2107 _ContentManagerImpl::ChangeCompatPathToTizen(const String& contentPath, String& changedPath) const
2109 result r = E_SUCCESS;
2110 changedPath = contentPath;
2112 // If the api version is 2.0, the content path has to be changed.
2113 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
2115 r = _FileImpl::ConvertVirtualToPhysicalPath(contentPath, changedPath);
2116 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG,
2117 "[%s] Failed to convert virtual path to physical path.", GetErrorMessage(E_INVALID_ARG));
2124 _ContentManagerImpl::SetListener(IContentUpdateEventListener* pListener)
2126 __pListener = pListener;
2129 IContentUpdateEventListener*
2130 _ContentManagerImpl::GetListener(void) const
2136 _ContentManagerImpl::ConvertErrorToResult(result res) const
2138 result r = E_SUCCESS;