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);
970 if (!pContentInfoImpl->GetAuthor().IsEmpty())
972 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetAuthor()));
973 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
975 val = media_info_set_author(pMediaInfo.get(), pValue.get());
976 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
977 "media_info_set_author failed[%d].", val);
979 if (!pContentInfoImpl->GetCategory().IsEmpty())
981 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetCategory()));
982 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
984 val = media_info_set_category(pMediaInfo.get(), pValue.get());
985 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
986 "media_info_set_category failed[%d].", val);
988 if (!pContentInfoImpl->GetContentName().IsEmpty())
990 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetContentName()));
991 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
993 val = media_info_set_content_name(pMediaInfo.get(), pValue.get());
994 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
995 "media_info_set_content_name failed[%d].", val);
997 if (!pContentInfoImpl->GetDescription().IsEmpty())
999 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetDescription()));
1000 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1002 val = media_info_set_description(pMediaInfo.get(), pValue.get());
1003 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1004 "media_info_set_description failed[%d].", val);
1006 if (!pContentInfoImpl->GetKeyword().IsEmpty())
1008 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetKeyword()));
1009 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1011 val = media_info_set_keyword(pMediaInfo.get(), pValue.get());
1012 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1013 "media_info_set_keyword failed[%d].", val);
1015 if (!pContentInfoImpl->GetLocationTag().IsEmpty())
1017 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetLocationTag()));
1018 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1020 val = media_info_set_location_tag(pMediaInfo.get(), pValue.get());
1021 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1022 "media_info_set_location_tag failed[%d].", val);
1024 if (!pContentInfoImpl->GetProvider().IsEmpty())
1026 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetProvider()));
1027 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1029 val = media_info_set_provider(pMediaInfo.get(), pValue.get());
1030 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1031 "media_info_set_provider failed[%d].", val);
1033 if (!pContentInfoImpl->GetRating().IsEmpty())
1035 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetRating()));
1036 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1038 val = media_info_set_age_rating(pMediaInfo.get(), pValue.get());
1039 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1040 "media_info_set_age_rating failed[%d].", val);
1042 if (Double::Compare(pContentInfoImpl->GetLatitude(), DEFAULT_COORDINATE) != 0 &&
1043 Double::Compare(pContentInfoImpl->GetLongitude(), DEFAULT_COORDINATE) != 0)
1045 val = media_info_set_latitude(pMediaInfo.get(), pContentInfoImpl->GetLatitude());
1046 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1047 "media_info_set_latitude failed[%d].", val);
1049 val = media_info_set_longitude(pMediaInfo.get(), pContentInfoImpl->GetLongitude());
1050 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1051 "media_info_set_longitude failed[%d].", val);
1053 if (Double::Compare(pContentInfoImpl->GetAltitude(), DEFAULT_COORDINATE) != 0)
1055 val = media_info_set_altitude(pMediaInfo.get(), pContentInfoImpl->GetAltitude());
1056 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1057 "media_info_set_altitude failed[%d].", val);
1061 val = media_info_update_to_db(pMediaInfo.get());
1062 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1063 "media_info_update_to_db failed[%d].", val);
1069 _ContentManagerImpl::SaveDataToDatabase(const media_info_h pMediaInfo,
1070 _ContentInfoImpl* pContentInfoImpl) const
1073 result r = E_SUCCESS;
1075 SysTryReturn(NID_CNT, pContentInfoImpl != null, UuId::GetInvalidUuId(), E_INVALID_ARG,
1076 "[E_INVALID_ARG] Invalid argument is used. ContentInfo is invalid.");
1078 String contentPath(pContentInfoImpl->GetPhysicalContentPath());
1079 String changedPath(L"");
1081 r = ChangeTizenPathToCompat(contentPath, changedPath);
1082 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r,
1083 "[%s] Failed to perform ChangeTizenPathToCompat.", GetErrorMessage(r));
1085 String mimeType(L"");
1086 String extension = _FileImpl::GetFileExtension(changedPath);
1087 r = GetLastResult();
1092 SysLog(NID_CNT, "[%s] Failed to perform GetFileExtension operation.", GetErrorMessage(r));
1094 unique_ptr<char[]> pTempPath(_StringConverter::CopyToCharArrayN(contentPath));
1095 SysTryReturn(NID_CNT, pTempPath != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1096 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1098 char tempType[255] = {0, };
1099 int ret = aul_get_mime_from_file(pTempPath.get(), tempType, sizeof(tempType));
1100 SysTryReturn(NID_CNT, ret == AUL_R_OK, UuId::GetInvalidUuId(), E_INVALID_ARG,
1101 "[E_INVALID_ARG] Failed to perform aul_get_mime_from_file operation.");
1103 r = mimeType.Append(tempType);
1104 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1105 "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
1109 // If the content format is JPG and it has GPS data, it will be saved in database automatically.
1110 if (extension == L"jpg" || extension == L"jpeg" || extension == L"JPG" || extension == L"JPEG" || mimeType.Contains(L"jpeg"))
1112 SysLog(NID_CNT, "The format of content is jpg.");
1114 ImageMetadata* pImageMetadata = _ContentManagerUtilImpl::GetImageMetaN(changedPath, true);
1115 if (pImageMetadata != null)
1117 pContentInfoImpl->SetLatitude(pImageMetadata->GetLatitude());
1118 pContentInfoImpl->SetLongitude(pImageMetadata->GetLongitude());
1120 delete pImageMetadata;
1127 unique_ptr<char[]> pStr(null);
1129 if (pContentInfoImpl->GetAuthor() != null)
1131 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetAuthor()));
1132 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1133 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1135 val = media_info_set_author(pMediaInfo, pStr.get());
1136 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1137 "media_info_set_author failed[%d].", val);
1139 if (pContentInfoImpl->GetCategory() != null)
1141 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetCategory()));
1142 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1143 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1145 val = media_info_set_category(pMediaInfo, pStr.get());
1146 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1147 "media_info_set_category failed[%d].", val);
1149 if (pContentInfoImpl->GetContentName() != null)
1151 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetContentName()));
1152 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1153 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1155 val = media_info_set_content_name(pMediaInfo, pStr.get());
1156 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1157 "media_info_set_content_name failed[%d].", val);
1159 if (pContentInfoImpl->GetDescription() != null)
1161 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetDescription()));
1162 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1163 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1165 val = media_info_set_description(pMediaInfo, pStr.get());
1166 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1167 "media_info_set_description failed[%d].", val);
1169 if (pContentInfoImpl->GetKeyword() != null)
1171 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetKeyword()));
1172 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1173 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1175 val = media_info_set_keyword(pMediaInfo, pStr.get());
1176 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1177 "media_info_set_keyword failed[%d].", val);
1179 if (pContentInfoImpl->GetLocationTag() != null)
1181 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetLocationTag()));
1182 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1183 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1185 val = media_info_set_location_tag(pMediaInfo, pStr.get());
1186 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1187 "media_info_set_location_tag failed[%d].", val);
1189 if (pContentInfoImpl->GetProvider() != null)
1191 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetProvider()));
1192 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1193 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1195 val = media_info_set_provider(pMediaInfo, pStr.get());
1196 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1197 "media_info_set_provider failed[%d].", val);
1199 if (pContentInfoImpl->GetRating() != null)
1201 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetRating()));
1202 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1203 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1205 val = media_info_set_age_rating(pMediaInfo, pStr.get());
1206 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1207 "media_info_set_age_rating failed[%d].", val);
1209 if (Double::Compare(pContentInfoImpl->GetLatitude(), DEFAULT_COORDINATE) != 0 &&
1210 Double::Compare(pContentInfoImpl->GetLongitude(), DEFAULT_COORDINATE) != 0)
1212 val = media_info_set_latitude(pMediaInfo, pContentInfoImpl->GetLatitude());
1213 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1214 "media_info_set_latitude failed[%d].", val);
1216 val = media_info_set_longitude(pMediaInfo, pContentInfoImpl->GetLongitude());
1217 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1218 "media_info_set_longitude failed[%d].", val);
1220 if (Double::Compare(pContentInfoImpl->GetAltitude(), DEFAULT_COORDINATE) != 0)
1222 val = media_info_set_altitude(pMediaInfo, pContentInfoImpl->GetAltitude());
1223 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1224 "media_info_set_altitude failed[%d].", val);
1228 val = media_info_update_to_db(pMediaInfo);
1229 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1230 "media_info_update_to_db failed[%d].", val);
1232 char* pTempMediaId = null;
1233 unique_ptr<char, CharDeleter> pMediaId(null);
1235 val = media_info_get_media_id(pMediaInfo, &pTempMediaId);
1236 if (pTempMediaId != null)
1238 pMediaId.reset(pTempMediaId);
1242 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1243 "media_info_get_media_id failed[%d].", val);
1246 String tempContentId(pMediaId.get());
1247 ContentId contentId;
1249 r = UuId::Parse(tempContentId, contentId);
1250 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_INVALID_ARG,
1251 "[E_INVALID_ARG] UuId::Parse failed.");
1257 _ContentManagerImpl::MakeContentInfo(const media_info_h pMediaInfo, int systemType, void* pInfoImpl) const
1259 SysTryReturnResult(NID_CNT, pMediaInfo != null && pInfoImpl != null, E_INVALID_ARG,
1260 "The specified parameter is invalid.");
1262 _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1264 result r = E_SUCCESS;
1265 char* pTempValue = null;
1266 unique_ptr<char, CharDeleter> pStrValue(null);
1269 int val = media_info_get_media_id(pMediaInfo, &pTempValue);
1270 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1271 "media_info_get_media_id failed[%d].", val);
1273 if (pTempValue != null)
1275 pStrValue.reset(pTempValue);
1277 String strContentId(pStrValue.get());
1278 ContentId contentId;
1280 r = UuId::Parse(strContentId, contentId);
1281 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The content id can not be parsed.");
1283 pContentInfoImpl->SetContentId(contentId);
1285 SysLog(NID_CNT, "INFO: contentId[%ls]", strContentId.GetPointer());
1289 val = media_info_get_file_path(pMediaInfo, &pTempValue);
1290 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1291 "media_info_get_file_path failed[%d].", val);
1293 if (pTempValue != null)
1295 pStrValue.reset(pTempValue);
1297 String strFilePath(pStrValue.get());
1299 pContentInfoImpl->SetContentPath(strFilePath);
1300 SysSecureLog(NID_CNT, "INFO: contentPath[%ls]", (pContentInfoImpl->GetContentPath()).GetPointer());
1304 val = media_info_get_mime_type(pMediaInfo, &pTempValue);
1305 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1306 "media_info_get_mime_type failed[%d].", val);
1308 if (pTempValue != null)
1310 pStrValue.reset(pTempValue);
1312 pContentInfoImpl->SetMimeType(pStrValue.get());
1314 SysLog(NID_CNT, "INFO: mimeType[%ls]", (pContentInfoImpl->GetMimeType()).GetPointer());
1318 unsigned long long longlongValue = 0;
1319 val = media_info_get_size(pMediaInfo, &longlongValue);
1320 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1321 "media_info_get_size failed[%d].", val);
1322 pContentInfoImpl->SetContentSize(longlongValue);
1323 SysLog(NID_CNT, "INFO: contentSize[%llu]", longlongValue);
1326 media_content_storage_e storageType;
1327 val = media_info_get_storage_type(pMediaInfo, &storageType);
1328 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1329 "media_info_get_storage_type failed[%d].", val);
1330 pContentInfoImpl->SetStorageType(storageType);
1331 SysLog(NID_CNT, "INFO: storageType[%d]", storageType);
1334 bool tempDrm = false;
1336 val = media_info_is_drm(pMediaInfo, &tempDrm);
1337 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1338 "media_info_is_drm failed[%d].", val);
1340 pContentInfoImpl->SetDrmProtected(tempDrm);
1342 SysLog(NID_CNT, "INFO: isDrm[%d]", pContentInfoImpl->IsDrmProtected());
1345 time_t addedTime = 0;
1346 val = media_info_get_added_time(pMediaInfo, &addedTime);
1347 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1348 "media_info_get_added_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(addedTime);// need to check addedTime is secs/millisec
1354 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.AddSeconds operation.");
1356 pContentInfoImpl->SetDateTime(dt);
1357 SysLog(NID_CNT, "INFO: dateTime[%ls]", ((pContentInfoImpl->GetDateTime()).ToString()).GetPointer());
1360 time_t modifiedTime = 0;
1361 val = media_info_get_modified_time(pMediaInfo, &modifiedTime);
1362 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1363 "media_info_get_modified_time failed[%d].", val);
1365 r = dt.SetValue(1970, 1, 1);
1366 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.SetValue operation.");
1367 r = dt.AddSeconds(modifiedTime);
1368 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.AddSeconds operation.");
1370 pContentInfoImpl->SetModifiedTime(dt);
1371 SysLog(NID_CNT, "INFO: modifiedTime[%ls]", ((pContentInfoImpl->GetModifiedTime()).ToString()).GetPointer());
1374 val = media_info_get_thumbnail_path(pMediaInfo, &pTempValue);
1375 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1376 "media_info_get_thumbnail_path failed[%d].", val);
1378 if (pTempValue != null)
1380 pStrValue.reset(pTempValue);
1381 String thumbnailPath(pStrValue.get());
1383 pContentInfoImpl->SetThumbnailPath(thumbnailPath);
1384 SysLog(NID_CNT, "INFO: thumbnailPath[%ls]", (pContentInfoImpl->GetThumbnailPath()).GetPointer());
1388 val = media_info_get_author(pMediaInfo, &pTempValue);
1389 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1390 "media_info_get_author failed[%d].", val);
1392 if (pTempValue != null)
1394 pStrValue.reset(pTempValue);
1396 pContentInfoImpl->SetAuthor(String(pStrValue.get()));
1398 SysLog(NID_CNT, "INFO: author[%ls]", (pContentInfoImpl->GetAuthor()).GetPointer());
1402 val = media_info_get_category(pMediaInfo, &pTempValue);
1403 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1404 "media_info_get_category failed[%d].", val);
1406 if (pTempValue != null)
1408 pStrValue.reset(pTempValue);
1410 pContentInfoImpl->SetCategory(String(pStrValue.get()));
1412 SysLog(NID_CNT, "INFO: category[%ls]", (pContentInfoImpl->GetCategory()).GetPointer());
1416 val = media_info_get_content_name(pMediaInfo, &pTempValue);
1417 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1418 "media_info_get_content_name failed[%d].", val);
1420 if (pTempValue != null)
1422 pStrValue.reset(pTempValue);
1424 pContentInfoImpl->SetContentName(String(pStrValue.get()));
1426 SysSecureLog(NID_CNT, "INFO: contentName[%ls]", (pContentInfoImpl->GetContentName()).GetPointer());
1430 val = media_info_get_description(pMediaInfo, &pTempValue);
1431 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1432 "media_info_get_description failed[%d].", val);
1434 if (pTempValue != null)
1436 pStrValue.reset(pTempValue);
1438 pContentInfoImpl->SetDescription(String(pStrValue.get()));
1440 SysLog(NID_CNT, "INFO: description[%ls]", (pContentInfoImpl->GetDescription()).GetPointer());
1444 val = media_info_get_keyword(pMediaInfo, &pTempValue);
1445 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1446 "media_info_get_keyword failed[%d].", val);
1448 if (pTempValue != null)
1450 pStrValue.reset(pTempValue);
1452 pContentInfoImpl->SetKeyword(String(pStrValue.get()));
1454 SysLog(NID_CNT, "INFO: keyword[%ls]", (pContentInfoImpl->GetKeyword()).GetPointer());
1458 val = media_info_get_location_tag(pMediaInfo, &pTempValue);
1459 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1460 "media_info_get_location_tag failed[%d].", val);
1462 if (pTempValue != null)
1464 pStrValue.reset(pTempValue);
1466 pContentInfoImpl->SetLocationTag(String(pStrValue.get()));
1468 SysSecureLog(NID_CNT, "INFO: locationTag[%ls]", (pContentInfoImpl->GetLocationTag()).GetPointer());
1472 val = media_info_get_provider(pMediaInfo, &pTempValue);
1473 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1474 "media_info_get_provider failed[%d].", val);
1476 if (pTempValue != null)
1478 pStrValue.reset(pTempValue);
1480 pContentInfoImpl->SetProvider(String(pStrValue.get()));
1482 SysLog(NID_CNT, "INFO: provider[%ls]", (pContentInfoImpl->GetProvider()).GetPointer());
1486 val = media_info_get_age_rating(pMediaInfo, &pTempValue);
1487 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1488 "media_info_get_age_rating failed[%d].", val);
1490 if (pTempValue != null)
1492 pStrValue.reset(pTempValue);
1494 pContentInfoImpl->SetRating(String(pStrValue.get()));
1496 SysLog(NID_CNT, "INFO: rating[%ls]", (pContentInfoImpl->GetRating()).GetPointer());
1500 Coordinates coordinates;
1501 double doubleValue = 0;
1502 val = media_info_get_latitude(pMediaInfo, &doubleValue);
1503 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1504 "media_info_get_latitude failed[%d].", val);
1506 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1508 pContentInfoImpl->SetLatitude(doubleValue);
1509 coordinates.SetLatitude(doubleValue);
1511 SysSecureLog(NID_CNT, "INFO: latitude[%f]", pContentInfoImpl->GetLatitude());
1513 val = media_info_get_longitude(pMediaInfo, &doubleValue);
1514 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1515 "media_info_get_longitude failed[%d].", val);
1517 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1519 pContentInfoImpl->SetLongitude(doubleValue);
1520 coordinates.SetLongitude(doubleValue);
1522 SysSecureLog(NID_CNT, "INFO: longitude[%f]", pContentInfoImpl->GetLongitude());
1524 val = media_info_get_altitude(pMediaInfo, &doubleValue);
1525 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1526 "media_info_get_altitude failed[%d].", val);
1528 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1530 pContentInfoImpl->SetAltitude(doubleValue);
1531 coordinates.SetAltitude(doubleValue);
1533 SysLog(NID_CNT, "INFO: altitude[%f]", pContentInfoImpl->GetAltitude());
1535 pContentInfoImpl->SetCoordinates(coordinates);
1537 // contentType and metadata
1538 if (systemType == SYSTEM_TYPE_IMAGE)
1540 r = MakeImageContentInfo(pMediaInfo, pInfoImpl);
1541 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform MakeImageContentInfo operation.");
1543 else if (systemType == SYSTEM_TYPE_SOUND || systemType == SYSTEM_TYPE_MUSIC)
1545 r = MakeAudioContentInfo(pMediaInfo, pInfoImpl);
1546 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform MakeAudioContentInfo operation.");
1548 else if (systemType == MEDIA_CONTENT_TYPE_VIDEO)
1550 r = MakeVideoContentInfo(pMediaInfo, pInfoImpl);
1551 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform MakeVideoContentInfo operation.");
1553 else if (systemType == SYSTEM_TYPE_OTHER)
1555 pContentInfoImpl->SetContentType(CONTENT_TYPE_OTHER);
1556 SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1563 _ContentManagerImpl::MakeImageContentInfo(const media_info_h pMediaInfo, void* pInfoImpl) const
1565 result r = E_SUCCESS;
1567 bool boolValue = false;
1568 image_meta_h pTempMeta = null;
1569 unique_ptr<image_meta_h, _ImageMetaDeleter> pImageMeta(null);
1571 SysTryReturnResult(NID_CNT, pInfoImpl != null, E_OUT_OF_MEMORY, "pInfoImpl is null.");
1573 _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1574 SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ContentInfoImpl.");
1576 pContentInfoImpl->SetContentType(CONTENT_TYPE_IMAGE);
1577 SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1579 int val = media_info_get_image(pMediaInfo, &pTempMeta);
1580 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1581 "media_info_get_image failed[%d].", val);
1583 pImageMeta.reset(&pTempMeta);
1585 _ImageContentInfoImpl* pImageContentInfoImpl = static_cast< _ImageContentInfoImpl* >(pInfoImpl);
1586 SysTryReturnResult(NID_CNT, pImageContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ImageContentInfoImpl.");
1589 val = image_meta_get_width(*(pImageMeta.get()), &intValue);
1590 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1591 "image_meta_get_width failed[%d].", val);
1593 pImageContentInfoImpl->SetWidth(intValue);
1594 SysLog(NID_CNT, "META: width[%d]", intValue);
1597 val = image_meta_get_height(*(pImageMeta.get()), &intValue);
1598 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1599 "image_meta_get_height failed[%d].", val);
1601 pImageContentInfoImpl->SetHeight(intValue);
1602 SysLog(NID_CNT, "META: height[%d]", intValue);
1605 media_content_orientation_e orientation;
1606 val = image_meta_get_orientation(*(pImageMeta.get()), &orientation);
1607 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1608 "image_meta_get_orientation failed[%d].", val);
1610 pImageContentInfoImpl->SetOrientation(static_cast< ImageOrientationType >(orientation));
1611 SysLog(NID_CNT, "META: orientation[%d]", orientation);
1613 char* pTempValue = null;
1614 unique_ptr<char, CharDeleter> pStrValue(null);
1617 val = media_info_get_display_name(pMediaInfo, &pTempValue);
1618 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1619 "media_info_get_display_name failed[%d].", val);
1621 if (pTempValue != null)
1623 pStrValue.reset(pTempValue);
1627 String strTitle(pStrValue.get());
1629 result r = strTitle.LastIndexOf(L'.', strTitle.GetLength() - 1, pos);
1632 r = strTitle.SubString(0, pos, fileName);
1633 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The title is invalid.");
1637 // Without extension
1639 fileName = strTitle;
1642 pImageContentInfoImpl->SetTitle(fileName);
1644 SysLog(NID_CNT, "META: title[%ls]", fileName.GetPointer());
1648 val = image_meta_get_date_taken(*(pImageMeta.get()), &pTempValue);
1649 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1650 "image_meta_get_date_taken failed[%d].", val);
1654 if (pTempValue != null)
1656 pStrValue.reset(pTempValue);
1657 String dateTaken(pStrValue.get());
1658 String newDateTaken(L"");
1660 // detour the unexpected datetaken format
1661 String tempDelim(L"+-Z");
1664 StringTokenizer tempStrTok(dateTaken, tempDelim);
1666 r = tempStrTok.GetNextToken(token);
1667 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1671 String delim(L": ");
1674 StringTokenizer strTok(dateTaken, delim);
1676 r = strTok.SetDelimiters(delim);
1677 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform SetDelimiters operation.");
1679 r = strTok.GetNextToken(token);
1680 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1685 r = strTok.GetNextToken(token);
1686 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1688 r = newDateTaken.Append(token);
1689 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1691 r = newDateTaken.Append(L"/");
1692 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1695 r = strTok.GetNextToken(token);
1696 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1698 r = newDateTaken.Append(token);
1699 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1701 r = newDateTaken.Append(L"/");
1702 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1705 r = newDateTaken.Append(year);
1706 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1708 r = newDateTaken.Append(L" ");
1709 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1711 String newDelim(L" ");
1713 r = strTok.SetDelimiters(newDelim);
1714 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform SetDelimiters operation.");
1716 r = strTok.GetNextToken(token);
1717 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1719 r = newDateTaken.Append(token);
1720 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1722 r = DateTime::Parse(newDateTaken, dt);
1723 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform Parse operation for DateTime.");
1727 dt = DateTime::GetMinValue();
1730 pImageContentInfoImpl->SetImageTakenDate(dt);
1731 SysLog(NID_CNT, "META: dateTaken[%ls]", dt.ToString().GetPointer());
1734 val = image_meta_is_burst_shot(*(pImageMeta.get()), &boolValue);
1735 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1736 "image_meta_is_burst_shot failed[%d].", val);
1738 pImageContentInfoImpl->SetBurstShot(boolValue);
1739 SysLog(NID_CNT, "META: isBurstShot[%d]", boolValue);
1742 val = image_meta_get_burst_id(*(pImageMeta.get()), &pTempValue);
1743 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1744 "image_meta_get_burst_id failed[%d].", val);
1746 if (pTempValue != null)
1748 pStrValue.reset(pTempValue);
1749 String burstShotId(pStrValue.get());
1751 pImageContentInfoImpl->SetBurstShotId(burstShotId);
1752 SysLog(NID_CNT, "META: burstShotId[%ls]", burstShotId.GetPointer());
1759 _ContentManagerImpl::MakeAudioContentInfo(const media_info_h pMediaInfo, void* pInfoImpl) const
1762 audio_meta_h pTempMeta = null;
1763 unique_ptr<audio_meta_h, _AudioMetaDeleter> pAudioMeta(null);
1765 SysTryReturnResult(NID_CNT, pInfoImpl != null, E_OUT_OF_MEMORY, "pInfoImpl is null.");
1767 _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1768 SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ContentInfoImpl.");
1770 pContentInfoImpl->SetContentType(CONTENT_TYPE_AUDIO);
1771 SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1773 int val = media_info_get_audio(pMediaInfo, &pTempMeta);
1774 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1775 "media_info_get_audio failed[%d].", val);
1777 pAudioMeta.reset(&pTempMeta);
1779 _AudioContentInfoImpl* pAudioContentInfoImpl = static_cast< _AudioContentInfoImpl* >(pInfoImpl);
1780 SysTryReturnResult(NID_CNT, pAudioContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _AudioContentInfoImpl.");
1783 val = audio_meta_get_bit_rate(*(pAudioMeta.get()), &intValue);
1784 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1785 "audio_meta_get_bit_rate failed[%d].", val);
1787 pAudioContentInfoImpl->SetBitrate(intValue);
1788 SysLog(NID_CNT, "META: bitrate[%d]", intValue);
1790 char* pTempValue = null;
1791 unique_ptr<char, CharDeleter> pStrValue(null);
1794 val = audio_meta_get_year(*(pAudioMeta.get()), &pTempValue);
1795 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1796 "audio_meta_get_year failed[%d].", val);
1798 if (pTempValue != null)
1800 pStrValue.reset(pTempValue);
1802 String strYear(pStrValue.get());
1804 if (strYear.CompareTo(L"Unknown") != 0)
1806 result r = Integer::Parse(strYear, intValue);
1809 // It is one of the metadata. If error occurs, skip it for other metadata.
1812 SysLog(NID_CNT, "META: releaseYear - invalid data[%ls]", strYear.GetPointer());
1815 pAudioContentInfoImpl->SetReleaseYear(intValue);
1816 SysLog(NID_CNT, "META: releaseYear[%d]", intValue);
1821 val = audio_meta_get_title(*(pAudioMeta.get()), &pTempValue);
1822 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1823 "audio_meta_get_title failed[%d].", val);
1825 if (pTempValue != null)
1827 pStrValue.reset(pTempValue);
1829 pAudioContentInfoImpl->SetTitle(String(pStrValue.get()));
1831 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
1835 val = audio_meta_get_album(*(pAudioMeta.get()), &pTempValue);
1836 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1837 "audio_meta_get_album failed[%d].", val);
1839 if (pTempValue != null)
1841 pStrValue.reset(pTempValue);
1843 pAudioContentInfoImpl->SetAlbumName(String(pStrValue.get()));
1845 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
1849 val = audio_meta_get_artist(*(pAudioMeta.get()), &pTempValue);
1850 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1851 "audio_meta_get_artist failed[%d].", val);
1853 if (pTempValue != null)
1855 pStrValue.reset(pTempValue);
1857 pAudioContentInfoImpl->SetArtist(String(pStrValue.get()));
1859 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
1863 val = audio_meta_get_composer(*(pAudioMeta.get()), &pTempValue);
1864 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1865 "audio_meta_get_composer failed[%d].", val);
1867 if (pTempValue != null)
1869 pStrValue.reset(pTempValue);
1871 pAudioContentInfoImpl->SetComposer(String(pStrValue.get()));
1873 SysLog(NID_CNT, "META: composer[%ls]", (String(pStrValue.get())).GetPointer());
1877 val = audio_meta_get_genre(*(pAudioMeta.get()), &pTempValue);
1878 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1879 "audio_meta_get_genre failed[%d].", val);
1881 if (pTempValue != null)
1883 pStrValue.reset(pTempValue);
1885 pAudioContentInfoImpl->SetGenre(String(pStrValue.get()));
1887 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
1891 val = audio_meta_get_copyright(*(pAudioMeta.get()), &pTempValue);
1892 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1893 "audio_meta_get_copyright failed[%d].", val);
1895 if (pTempValue != null)
1897 pStrValue.reset(pTempValue);
1899 pAudioContentInfoImpl->SetCopyright(String(pStrValue.get()));
1901 SysLog(NID_CNT, "META: copyright[%ls]", (String(pStrValue.get())).GetPointer());
1905 val = audio_meta_get_track_num(*(pAudioMeta.get()), &pTempValue);
1906 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1907 "audio_meta_get_track_num failed[%d].", val);
1909 if (pTempValue != null)
1911 pStrValue.reset(pTempValue);
1913 pAudioContentInfoImpl->SetTrackInfo(String(pStrValue.get()));
1915 SysLog(NID_CNT, "META: trackInfo[%ls]", (String(pStrValue.get())).GetPointer());
1919 val = audio_meta_get_duration(*(pAudioMeta.get()), &intValue);
1920 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1921 "audio_meta_get_duration failed[%d].", val);
1923 pAudioContentInfoImpl->SetDuration(intValue);
1924 SysLog(NID_CNT, "META: duration[%d]", intValue);
1930 _ContentManagerImpl::MakeVideoContentInfo(const media_info_h pMediaInfo, void* pInfoImpl) const
1933 video_meta_h pTempMeta = null;
1934 unique_ptr<video_meta_h, _VideoMetaDeleter> pVideoMeta(null);
1936 SysTryReturnResult(NID_CNT, pInfoImpl != null, E_OUT_OF_MEMORY, "pInfoImpl is null.");
1938 _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1939 SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ContentInfoImpl.");
1941 pContentInfoImpl->SetContentType(CONTENT_TYPE_VIDEO);
1942 SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1944 int val = media_info_get_video(pMediaInfo, &pTempMeta);
1945 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1946 "media_info_get_video failed[%d].", val);
1948 pVideoMeta.reset(&pTempMeta);
1950 _VideoContentInfoImpl* pVideoContentInfoImpl = static_cast< _VideoContentInfoImpl* >(pInfoImpl);
1951 SysTryReturnResult(NID_CNT, pVideoContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _VideoContentInfoImpl.");
1954 val = video_meta_get_width(*(pVideoMeta.get()), &intValue);
1955 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1956 "video_meta_get_width failed[%d].", val);
1958 pVideoContentInfoImpl->SetWidth(intValue);
1959 SysLog(NID_CNT, "META: width[%d]", intValue);
1962 val = video_meta_get_height(*(pVideoMeta.get()), &intValue);
1963 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1964 "video_meta_get_height failed[%d].", val);
1966 pVideoContentInfoImpl->SetHeight(intValue);
1967 SysLog(NID_CNT, "META: height[%d]", intValue);
1969 char* pTempValue = null;
1970 unique_ptr<char, CharDeleter> pStrValue(null);
1973 val = video_meta_get_artist(*(pVideoMeta.get()), &pTempValue);
1974 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1975 "video_meta_get_artist failed[%d].", val);
1977 if (pTempValue != null)
1979 pStrValue.reset(pTempValue);
1981 pVideoContentInfoImpl->SetArtist(String(pStrValue.get()));
1983 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
1987 val = video_meta_get_genre(*(pVideoMeta.get()), &pTempValue);
1988 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1989 "video_meta_get_genre failed[%d].", val);
1991 if (pTempValue != null)
1993 pStrValue.reset(pTempValue);
1995 pVideoContentInfoImpl->SetGenre(String(pStrValue.get()));
1997 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
2001 val = video_meta_get_title(*(pVideoMeta.get()), &pTempValue);
2002 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
2003 "video_meta_get_title failed[%d].", val);
2005 if (pTempValue != null)
2007 pStrValue.reset(pTempValue);
2009 pVideoContentInfoImpl->SetTitle(String(pStrValue.get()));
2011 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
2015 val = video_meta_get_album(*(pVideoMeta.get()), &pTempValue);
2016 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
2017 "video_meta_get_album failed[%d].", val);
2019 if (pTempValue != null)
2021 pStrValue.reset(pTempValue);
2023 pVideoContentInfoImpl->SetAlbumName(String(pStrValue.get()));
2025 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
2029 val = video_meta_get_duration(*(pVideoMeta.get()), &intValue);
2030 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
2031 "video_meta_get_duration failed[%d].", val);
2033 pVideoContentInfoImpl->SetDuration(intValue);
2034 SysLog(NID_CNT, "META: duration[%d]", intValue);
2036 // Get from metadata extractor (framerate, audio bitrate, video bitrate)
2037 VideoMetadata* pVideoMetadata = ContentManagerUtil::GetVideoMetaN(pVideoContentInfoImpl->GetContentPath());
2038 result r = GetLastResult();
2039 SysTryReturnResult(NID_CNT, pVideoMetadata != null, r, "GetVideoMetadata() failed.");
2041 pVideoContentInfoImpl->SetFramerate(pVideoMetadata->GetFramerate());
2042 pVideoContentInfoImpl->SetAudioBitrate(pVideoMetadata->GetAudioBitrate());
2043 pVideoContentInfoImpl->SetVideoBitrate(pVideoMetadata->GetVideoBitrate());
2049 _ContentManagerImpl::VerifyHomeFilePathCompatibility(const String& contentPath) const
2051 if (!_AppInfo::IsOspCompat())
2053 if (contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0))
2055 SysLogException(NID_CNT, E_INVALID_ARG,
2056 "[E_INVALID_ARG] /Home/ or /HomeExt/ is not supported from Tizen 2.0.");
2059 if (!(contentPath.StartsWith(App::App::GetInstance()->GetAppRootPath(), 0) ||
2060 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
2062 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] The path is not supported.");
2068 SysTryReturn(NID_CNT, contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0),
2069 false, E_INVALID_ARG, "[E_INVALID_ARG] The path should start with /Home or /HomeExt.");
2076 _ContentManagerImpl::VerifyMediaFilePathCompatibility(const String& contentPath) const
2080 if (!_AppInfo::IsOspCompat())
2082 if (!(contentPath.StartsWith(Environment::GetMediaPath(), 0) ||
2083 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
2085 SysLogException(NID_CNT, E_INVALID_ARG, "[%s] This path is not supported.", GetErrorMessage(E_INVALID_ARG));
2092 if (!(contentPath.StartsWith(OSP_MEDIA_PHONE, 0)) ||
2093 (contentPath.StartsWith(OSP_MEDIA_MMC, 0)))
2095 SysLogException(NID_CNT, E_INVALID_ARG, "[%s] The path should start with /Media, or /Storagecard/Media.", GetErrorMessage(E_INVALID_ARG));
2104 _ContentManagerImpl::ChangeTizenPathToCompat(const String& contentPath, String& changedPath) const
2106 result r = E_SUCCESS;
2107 changedPath = contentPath;
2109 // If the api version is 2.0, the content path has to be changed.
2110 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
2112 r = _FileImpl::ConvertPhysicalToVirtualPath(contentPath, changedPath);
2113 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG,
2114 "[%s] Failed to convert physical path to virtual path.", GetErrorMessage(E_INVALID_ARG));
2121 _ContentManagerImpl::ChangeCompatPathToTizen(const String& contentPath, String& changedPath) const
2123 result r = E_SUCCESS;
2124 changedPath = contentPath;
2126 // If the api version is 2.0, the content path has to be changed.
2127 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
2129 r = _FileImpl::ConvertVirtualToPhysicalPath(contentPath, changedPath);
2130 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG,
2131 "[%s] Failed to convert virtual path to physical path.", GetErrorMessage(E_INVALID_ARG));
2138 _ContentManagerImpl::SetListener(IContentUpdateEventListener* pListener)
2140 __pListener = pListener;
2143 IContentUpdateEventListener*
2144 _ContentManagerImpl::GetListener(void) const
2150 _ContentManagerImpl::ConvertErrorToResult(result res) const
2152 result r = E_SUCCESS;