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 char* pTempMediaId = null;
355 unique_ptr<char, CharDeleter> pMediaId(null);
356 val = media_info_get_media_id(pMediaInfo.get(), &pTempMediaId);
357 if (pTempMediaId != null)
359 pMediaId.reset(pTempMediaId);
363 SysLog(NID_CNT, "Failed to perform media_info_get_media_id operation.");
364 return UuId::GetInvalidUuId();
367 val = media_info_delete_from_db(pMediaId.get());
368 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
370 return UuId::GetInvalidUuId();
374 _ContentManagerImpl::CreateContent(const ByteBuffer& byteBuffer, const String& destinationPath,
375 const ContentInfo* pContentInfo)
379 // Check parameters(for length)
380 SysTryReturn(NID_CNT, byteBuffer.GetRemaining() > 0, UuId::GetInvalidUuId(), E_INVALID_ARG,
381 "[E_INVALID_ARG] byteBuffer is invalid.");
383 // Check parameters(for path compatibility)
384 SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(destinationPath), UuId::GetInvalidUuId(),
385 E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", destinationPath.GetPointer());
386 SysTryReturn(NID_CNT, !_FileImpl::IsFileExist(destinationPath), UuId::GetInvalidUuId(), E_FILE_ALREADY_EXIST,
387 "[E_FILE_ALREADY_EXIST] The specified file already exists.");
389 // Create a file with bytebuffer
390 unique_ptr<File> pFile(new (nothrow) File);
391 SysTryReturn(NID_CNT, pFile != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
392 "[E_OUT_OF_MEMORY] The memory is insufficient.");
394 result r = pFile->Construct(destinationPath, L"w+");
395 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r,
396 "[%s] The destination file can not be created.", GetErrorMessage(r));
398 _FileImpl* pFileImpl = _FileImpl::GetInstance(*pFile);
399 SysTryReturn(NID_CNT, pFileImpl != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
400 "[E_OUT_OF_MEMORY] The memory is insufficient.");
402 r = pFileImpl->Write(byteBuffer);
403 SysTryReturn(NID_CNT, !(IsFailed(r)), UuId::GetInvalidUuId(), r,
404 "[%s] The data can not be written in the destination file.", GetErrorMessage(r));
406 // for release file pointer
411 _ContentInfoImpl* pInfoImpl = null;
412 _ImageContentInfoImpl imageContentInfoImpl;
413 _AudioContentInfoImpl audioContentInfoImpl;
414 _VideoContentInfoImpl videoContentInfoImpl;
415 _OtherContentInfoImpl otherContentInfoImpl;
416 media_info_h tempMediaInfo = null;
417 unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
418 unique_ptr<char[]> pStr(null);
419 String destPath(L"");
421 r = ChangeCompatPathToTizen(destinationPath, destPath);
422 SysTryCatch(NID_CNT, !IsFailed(r), , r, "[%s] Failed to perform ChangedCompatPathToTizen.", GetErrorMessage(r));
424 if (pContentInfo != null)
426 pInfoImpl = const_cast< _ContentInfoImpl* >(_ContentInfoImpl::GetInstance(*pContentInfo));
427 SysTryCatch(NID_CNT, pInfoImpl != null, , E_INVALID_ARG,
428 "[E_INVALID_ARG] Invalid argument is used. ContentInfo is invalid.");
430 SysTryCatch(NID_CNT, pInfoImpl->GetContentId() == UuId::GetInvalidUuId(), , E_INVALID_ARG,
431 "[E_INVALID_ARG] The content already exists in database.");
433 // Compare the type of input parameter and system
434 // CheckContentType() need actual file. so it should be checked after creating the file.
435 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
436 ContentType inputType = pInfoImpl->GetContentType();
440 if (inputType != sysType)
442 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
444 SysLogException(NID_CNT, E_INVALID_ARG,
445 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
450 // Sets the content path
451 pInfoImpl->SetContentPath(destPath);
455 ContentType contentType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
459 // Set the content path
460 if (contentType == CONTENT_TYPE_IMAGE)
462 r = imageContentInfoImpl.Construct(&destinationPath);
463 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
464 "[E_OUT_OF_MEMORY] Failed to perform Construct for ImageContentInfoImpl.");
466 imageContentInfoImpl.SetContentPath(destPath);
467 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&imageContentInfoImpl);
469 else if (contentType == CONTENT_TYPE_AUDIO)
471 r = audioContentInfoImpl.Construct(&destinationPath);
472 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
473 "[E_OUT_OF_MEMORY] Failed to perform Construct for AudioContentInfoImpl.");
475 audioContentInfoImpl.SetContentPath(destPath);
476 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&audioContentInfoImpl);
478 else if (contentType == CONTENT_TYPE_VIDEO)
480 r = videoContentInfoImpl.Construct(&destinationPath);
481 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
482 "[E_OUT_OF_MEMORY] Failed to perform Construct for VideoContentInfoImpl.");
484 videoContentInfoImpl.SetContentPath(destPath);
485 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&videoContentInfoImpl);
489 r = otherContentInfoImpl.Construct(&destinationPath);
490 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
491 "[E_OUT_OF_MEMORY] Failed to perform Construct for OtherContentInfoImpl.");
493 otherContentInfoImpl.SetContentPath(destPath);
494 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&otherContentInfoImpl);
498 // Register the content to database directly.
499 pStr.reset(_StringConverter::CopyToCharArrayN(destPath));
500 SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
502 val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
503 SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
504 "media_info_insert_to_db failed[%d].", val);
506 pMediaInfo.reset(tempMediaInfo);
508 contentId = SaveDataToDatabase(pMediaInfo.get(), pInfoImpl);
510 SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
511 "[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
516 result saveResult = GetLastResult();
518 // If the destination file is made by this method, it should be deleted when error occurs.
519 r = _FileImpl::Remove(destinationPath);
520 SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
522 if (pMediaInfo != null)
524 char* pTempMediaId = null;
525 unique_ptr<char, CharDeleter> pMediaId(null);
526 val = media_info_get_media_id(pMediaInfo.get(), &pTempMediaId);
527 if (pTempMediaId != null)
529 pMediaId.reset(pTempMediaId);
533 SysLog(NID_CNT, "Failed to perform media_info_get_media_id operation.");
534 return UuId::GetInvalidUuId();
537 val = media_info_delete_from_db(pMediaId.get());
538 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
541 SetLastResult(saveResult);
542 return UuId::GetInvalidUuId();
546 _ContentManagerImpl::CreateContent(const String& sourcePath, const String& destinationPath, bool deleteSource,
547 const ContentInfo* pContentInfo)
551 // Check parameters(for type)
552 SysTryReturn(NID_CNT, _FileImpl::GetFileExtension(sourcePath) == _FileImpl::GetFileExtension(destinationPath),
553 UuId::GetInvalidUuId(), E_INVALID_ARG, "[E_INVALID_ARG] There is a mismatch between the type of source and dest path.");
555 // Check parameters(for path compatibility)
556 SysTryReturn(NID_CNT, VerifyHomeFilePathCompatibility(sourcePath), UuId::GetInvalidUuId(), E_INVALID_ARG,
557 "[E_INVALID_ARG] %ls is not compatible.", sourcePath.GetPointer());
558 SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(destinationPath), UuId::GetInvalidUuId(),
559 E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", destinationPath.GetPointer());
561 result r = _FileImpl::Copy(sourcePath, destinationPath, true);
562 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Copying the file failed.", GetErrorMessage(r));
566 _ContentInfoImpl* pInfoImpl = null;
567 _ImageContentInfoImpl imageContentInfoImpl;
568 _AudioContentInfoImpl audioContentInfoImpl;
569 _VideoContentInfoImpl videoContentInfoImpl;
570 _OtherContentInfoImpl otherContentInfoImpl;
571 media_info_h tempMediaInfo = null;
572 unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
573 unique_ptr<char[]> pStr(null);
574 String destPath(L"");
576 r = ChangeCompatPathToTizen(destinationPath, destPath);
577 SysTryCatch(NID_CNT, !IsFailed(r), , r, "[%s] Failed to perform ChangedCompatPathToTizen.", GetErrorMessage(r));
579 if (pContentInfo != null)
581 pInfoImpl = const_cast< _ContentInfoImpl* >(_ContentInfoImpl::GetInstance(*pContentInfo));
582 SysTryCatch(NID_CNT, pInfoImpl != null, , E_INVALID_ARG,
583 "[E_INVALID_ARG] Invalid argument is used. ContentInfo is invalid.");
585 SysTryCatch(NID_CNT, pInfoImpl->GetContentId() == UuId::GetInvalidUuId(), , E_INVALID_ARG,
586 "[E_INVALID_ARG] The content already exists in database.");
588 // Compare the type of input parameter and system
589 // CheckContentType() need actual file. so it should be checked after creating the file.
590 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
591 ContentType inputType = pInfoImpl->GetContentType();
595 if (inputType != sysType)
597 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
599 SysLogException(NID_CNT, E_INVALID_ARG,
600 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
605 // Set the content path
606 pInfoImpl->SetContentPath(destPath);
610 ContentType contentType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
614 // Set the content path
615 if (contentType == CONTENT_TYPE_IMAGE)
617 r = imageContentInfoImpl.Construct(&destinationPath);
618 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
619 "[E_OUT_OF_MEMORY] Failed to perform Construct for ImageContentInfoImpl.");
621 imageContentInfoImpl.SetContentPath(destPath);
622 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&imageContentInfoImpl);
624 else if (contentType == CONTENT_TYPE_AUDIO)
626 r = audioContentInfoImpl.Construct(&destinationPath);
627 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
628 "[E_OUT_OF_MEMORY] Failed to perform Construct for AudioContentInfoImpl.");
630 audioContentInfoImpl.SetContentPath(destPath);
631 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&audioContentInfoImpl);
633 else if (contentType == CONTENT_TYPE_VIDEO)
635 r = videoContentInfoImpl.Construct(&destinationPath);
636 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
637 "[E_OUT_OF_MEMORY] Failed to perform Construct for VideoContentInfoImpl.");
639 videoContentInfoImpl.SetContentPath(destPath);
640 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&videoContentInfoImpl);
644 r = otherContentInfoImpl.Construct(&destinationPath);
645 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
646 "[E_OUT_OF_MEMORY] Failed to perform Construct for OtherContentInfoImpl.");
648 otherContentInfoImpl.SetContentPath(destPath);
649 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&otherContentInfoImpl);
653 pStr.reset(_StringConverter::CopyToCharArrayN(destPath));
654 SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
656 val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
657 SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
658 "media_info_insert_to_db failed[%d].", val);
660 pMediaInfo.reset(tempMediaInfo);
662 contentId = SaveDataToDatabase(pMediaInfo.get(), pInfoImpl);
664 SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
665 "[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
669 unique_ptr<char[]> pContentPath(_StringConverter::CopyToCharArrayN(sourcePath));
670 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY, "[%s] pContentPath is null.", GetErrorMessage(E_OUT_OF_MEMORY));
672 r = _FileImpl::Remove(sourcePath);
673 SysTryCatch(NID_CNT, !IsFailed(r), , r, "[%s] Failed to perform Remove operation.", GetErrorMessage(r));
675 val = media_content_scan_file(pContentPath.get());
676 SysTryLog(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, "Failed to perform media_content_scan_file[%d].", val);
682 result saveResult = GetLastResult();
684 r = _FileImpl::Remove(destinationPath);
685 SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
687 if (pMediaInfo != null)
689 char* pTempMediaId = null;
690 unique_ptr<char, CharDeleter> pMediaId(null);
691 val = media_info_get_media_id(pMediaInfo.get(), &pTempMediaId);
692 if (pTempMediaId != null)
694 pMediaId.reset(pTempMediaId);
698 SysLog(NID_CNT, "Failed to perform media_info_get_media_id operation.");
699 return UuId::GetInvalidUuId();
702 val = media_info_delete_from_db(pMediaId.get());
703 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
706 SetLastResult(saveResult);
707 return UuId::GetInvalidUuId();
711 _ContentManagerImpl::GetContentInfoN(const ContentId& contentId) const
715 SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), null, E_INVALID_ARG,
716 "[E_INVALID_ARG] The contentId is invalid.");
718 unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(contentId.ToString()));
719 SysTryReturn(NID_CNT, pStr != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
721 media_info_h tempMediaInfo = null;
722 unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
723 int val = media_info_get_media_from_db(pStr.get(), &tempMediaInfo);
724 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
725 "media_info_get_media_from_db failed[%d].", val);
727 pMediaInfo.reset(tempMediaInfo);
729 media_content_type_e systemType = MEDIA_CONTENT_TYPE_IMAGE;
730 val = media_info_get_media_type(pMediaInfo.get(), &systemType);
731 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
732 "media_info_get_media_type failed[%d].", val);
734 char* pTempFilePath = null;
735 val = media_info_get_file_path(pMediaInfo.get(), &pTempFilePath);
736 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
737 "media_info_get_file_path failed[%d].", val);
739 unique_ptr<char, CharDeleter> pFilePath(pTempFilePath);
740 String contentPath(pFilePath.get());
741 String changedPath(L"");
743 result r = E_SUCCESS;
745 r = ChangeTizenPathToCompat(contentPath, changedPath);
746 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] Failed to perform ChangeTizenPathToCompat.", GetErrorMessage(r));
748 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(changedPath), null, E_FILE_NOT_FOUND,
749 "[E_FILE_NOT_FOUND] The file corresponding to contentId could not be found.");
751 if (systemType == SYSTEM_TYPE_IMAGE)
753 unique_ptr< ImageContentInfo > pImageContentInfo(new (nothrow) ImageContentInfo);
754 SysTryReturn(NID_CNT, pImageContentInfo != null, null, E_OUT_OF_MEMORY,
755 "[E_OUT_OF_MEMORY] The memory is insufficient.");
757 r = pImageContentInfo->Construct(&changedPath);
758 r = ConvertErrorToResult(r);
759 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
760 "[%s] Failed to perform Construct operation to ImageContentInfo.", GetErrorMessage(r));
762 _ImageContentInfoImpl* pImageContentInfoImpl = _ImageContentInfoImpl::GetInstance(*(pImageContentInfo.get()));
763 SysTryReturn(NID_CNT, pImageContentInfoImpl != null, null, E_OUT_OF_MEMORY,
764 "[E_OUT_OF_MEMORY] The memory is insufficient.");
766 r = MakeContentInfo(pMediaInfo.get(), systemType, pImageContentInfoImpl);
767 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
769 return pImageContentInfo.release();
771 else if (systemType == SYSTEM_TYPE_SOUND || systemType == SYSTEM_TYPE_MUSIC)
773 unique_ptr< AudioContentInfo > pAudioContentInfo(new (nothrow) AudioContentInfo);
774 SysTryReturn(NID_CNT, pAudioContentInfo != null, null, E_OUT_OF_MEMORY,
775 "[E_OUT_OF_MEMORY] The memory is insufficient.");
777 r = pAudioContentInfo->Construct(&changedPath);
778 r = ConvertErrorToResult(r);
779 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
780 "[%s] Failed to perform Construct operation to AudioContentInfo.", GetErrorMessage(r));
782 _AudioContentInfoImpl* pAudioContentInfoImpl = _AudioContentInfoImpl::GetInstance(*(pAudioContentInfo.get()));
783 SysTryReturn(NID_CNT, pAudioContentInfoImpl != null, null, E_OUT_OF_MEMORY,
784 "[E_OUT_OF_MEMORY] The memory is insufficient.");
786 r = MakeContentInfo(pMediaInfo.get(), systemType, pAudioContentInfoImpl);
787 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
789 return pAudioContentInfo.release();
791 else if (systemType == SYSTEM_TYPE_VIDEO)
793 unique_ptr< VideoContentInfo > pVideoContentInfo(new (nothrow) VideoContentInfo);
794 SysTryReturn(NID_CNT, pVideoContentInfo != null, null, E_OUT_OF_MEMORY,
795 "[E_OUT_OF_MEMORY] The memory is insufficient.");
797 r = pVideoContentInfo->Construct(&changedPath);
798 r = ConvertErrorToResult(r);
799 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
800 "[%s] Failed to perform Construct operation to VideoContentInfo.", GetErrorMessage(r));
802 _VideoContentInfoImpl* pVideoContentInfoImpl = _VideoContentInfoImpl::GetInstance(*(pVideoContentInfo.get()));
803 SysTryReturn(NID_CNT, pVideoContentInfoImpl != null, null, E_OUT_OF_MEMORY,
804 "[E_OUT_OF_MEMORY] The memory is insufficient.");
806 r = MakeContentInfo(pMediaInfo.get(), systemType, pVideoContentInfoImpl);
807 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
809 return pVideoContentInfo.release();
811 else if (systemType == SYSTEM_TYPE_OTHER)
813 unique_ptr< OtherContentInfo > pOtherContentInfo(new (nothrow) OtherContentInfo);
814 SysTryReturn(NID_CNT, pOtherContentInfo != null, null, E_OUT_OF_MEMORY,
815 "[E_OUT_OF_MEMORY] The memory is insufficient.");
817 r = pOtherContentInfo->Construct(&changedPath);
818 r = ConvertErrorToResult(r);
819 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
820 "[%s] Failed to perform Construct operation to OtherContentInfo.", GetErrorMessage(r));
822 _OtherContentInfoImpl* pOtherContentInfoImpl = _OtherContentInfoImpl::GetInstance(*(pOtherContentInfo.get()));
823 SysTryReturn(NID_CNT, pOtherContentInfoImpl != null, null, E_OUT_OF_MEMORY,
824 "[E_OUT_OF_MEMORY] The memory is insufficient.");
826 r = MakeContentInfo(pMediaInfo.get(), systemType, pOtherContentInfoImpl);
827 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
829 return pOtherContentInfo.release();
833 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] Unsupported type");
839 _ContentManagerImpl::UpdateContent(const ContentInfo& contentInfo)
841 const _ContentInfoImpl* pInfoImpl = _ContentInfoImpl::GetInstance(contentInfo);
842 SysTryReturnResult(NID_CNT, pInfoImpl != null, E_INVALID_ARG, "Invalid argument is used. ContentInfo is invalid.");
844 ContentId contentId = pInfoImpl->GetContentId();
845 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, "The content id is invalid.");
846 SysTryReturnResult(NID_CNT, _FileImpl::IsFileExist(pInfoImpl->GetContentPath()), E_FILE_NOT_FOUND,
847 "The file corresponding to contentInfo could not be found.");
849 result r = UpdateDataToDatabase(pInfoImpl);
850 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "UpdateDataToDatabase failed.");
856 _ContentManagerImpl::DeleteContent(const ContentId& contentId)
858 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, "The contentId is invalid.");
860 unique_ptr<char[]> pContentId(_StringConverter::CopyToCharArrayN(contentId.ToString()));
861 SysTryReturnResult(NID_CNT, pContentId != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
863 result r = E_SUCCESS;
865 media_info_h tempMediaInfo = null;
866 unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
868 val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
869 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
870 "media_info_get_media_from_db failed[%d].", val);
872 pMediaInfo.reset(tempMediaInfo);
874 char* pTempPath = null;
876 val = media_info_get_file_path(pMediaInfo.get(), &pTempPath);
877 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
878 "media_info_get_file_path failed[%d].", val);
880 unique_ptr<char, CharDeleter> pContentPath(pTempPath);
881 String contentPath(pContentPath.get());
882 String changedPath(L"");
884 r = ChangeTizenPathToCompat(contentPath, changedPath);
885 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "[%s] Failed to perform ChangeTizenPathToCompat.", GetErrorMessage(r));
887 SysTryReturnResult(NID_CNT, _FileImpl::IsFileExist(changedPath), E_FILE_NOT_FOUND,
888 "The file corresponding to contentId could not be found.");
890 val = media_info_delete_from_db(pContentId.get());
891 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
892 "media_info_delete_From_db failed[%d].", val);
894 r = _FileImpl::Remove(changedPath);
895 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The file is not deleted.");
901 _ContentManagerImpl::AddContentUpdateEventListener(IContentUpdateEventListener& listener)
903 SysTryReturnResult(NID_CNT, GetListener() == null, E_OBJ_ALREADY_EXIST, "IContentUpdateEventListener is already set.");
905 SetListener(&listener);
907 int val = media_content_set_db_updated_cb(OnContentUpdateCompleted, this);
908 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "media_content_set_db_updated_cb failed[%d].", val);
914 _ContentManagerImpl::RemoveContentUpdateEventListener(IContentUpdateEventListener& listener)
916 SysTryReturnResult(NID_CNT, GetListener() == &listener, E_OBJ_NOT_FOUND, "The input listener is not equal to the registered listener.");
918 int val = media_content_unset_db_updated_cb();
919 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "media_content_unset_db_updated_cb failed[%d].", val);
927 _ContentManagerImpl::ScanFile(const Tizen::Base::String& contentPath)
929 SysSecureLog(NID_CNT, "The scan path is [%ls].", contentPath.GetPointer());
931 unique_ptr<char[]> pContentPath(_StringConverter::CopyToCharArrayN(contentPath));
932 SysTryReturnResult(NID_CNT, pContentPath, E_SYSTEM, "pContentPath is NULL.");
934 int val = media_content_connect();
935 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The connection failed[%d].", val);
937 val = media_content_scan_file(pContentPath.get());
938 result r = ConvertError(val);
939 SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , r, "[%s] media_content_scan_file failed[%d].", GetErrorMessage(r), val);
941 val = media_content_disconnect();
942 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The disconnection failed[%d].", val);
947 val = media_content_disconnect();
948 SysTryLog(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, "The disconnection failed[%d].", val);
954 _ContentManagerImpl::ScanDirectory(const Tizen::Base::String& directoryPath, bool recursive, IContentScanListener* pListener, RequestId& reqId)
956 static RequestId requestId = 0;
958 SysLog(NID_CNT, "The scan path is [%ls].", directoryPath.GetPointer());
960 unique_ptr<char[]> pDirPath(_StringConverter::CopyToCharArrayN(directoryPath));
961 SysTryReturnResult(NID_CNT, pDirPath, E_SYSTEM, "pDirPath is NULL.");
963 int val = media_content_connect();
964 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The connection failed[%d].", val);
966 unique_ptr< _ScanResult > pScanResult(new (nothrow) _ScanResult);
967 SysTryReturnResult(NID_CNT, pScanResult != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
971 pScanResult->scanPath = directoryPath;
972 pScanResult->pScanListener = pListener;
973 pScanResult->requestId = reqId;
975 val = media_content_scan_folder(pDirPath.get(), recursive, OnScanCompleted, pScanResult.release());
976 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val), "media_content_scan_folder failed[%d].", val);
982 _ContentManagerImpl::UpdateDataToDatabase(const _ContentInfoImpl* pContentInfoImpl) const
984 SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_INVALID_ARG, "pContentInfoImpl is null.");
986 media_info_h tempMediaInfo = null;
987 unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
988 unique_ptr<char[]> pContentId(_StringConverter::CopyToCharArrayN((pContentInfoImpl->GetContentId()).ToString()));
989 SysTryReturnResult(NID_CNT, pContentId != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
991 int val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
992 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
993 "media_info_get_media_from_db failed[%d].", val);
995 pMediaInfo.reset(tempMediaInfo);
997 result r = E_SUCCESS;
998 unique_ptr<char[]> pValue(null);
1001 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetAuthor()));
1002 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1004 val = media_info_set_author(pMediaInfo.get(), pValue.get());
1005 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1006 "media_info_set_author failed[%d].", val);
1009 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetCategory()));
1010 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1012 val = media_info_set_category(pMediaInfo.get(), pValue.get());
1013 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1014 "media_info_set_category failed[%d].", val);
1017 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetContentName()));
1018 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1020 val = media_info_set_content_name(pMediaInfo.get(), pValue.get());
1021 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1022 "media_info_set_content_name failed[%d].", val);
1025 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetDescription()));
1026 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1028 val = media_info_set_description(pMediaInfo.get(), pValue.get());
1029 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1030 "media_info_set_description failed[%d].", val);
1033 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetKeyword()));
1034 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1036 val = media_info_set_keyword(pMediaInfo.get(), pValue.get());
1037 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1038 "media_info_set_keyword failed[%d].", val);
1041 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetLocationTag()));
1042 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1044 val = media_info_set_location_tag(pMediaInfo.get(), pValue.get());
1045 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1046 "media_info_set_location_tag failed[%d].", val);
1049 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetProvider()));
1050 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1052 val = media_info_set_provider(pMediaInfo.get(), pValue.get());
1053 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1054 "media_info_set_provider failed[%d].", val);
1057 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetRating()));
1058 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1060 val = media_info_set_age_rating(pMediaInfo.get(), pValue.get());
1061 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1062 "media_info_set_age_rating failed[%d].", val);
1064 // latitude, longitude, altitude
1065 if (Double::Compare(pContentInfoImpl->GetLatitude(), DEFAULT_COORDINATE) != 0 &&
1066 Double::Compare(pContentInfoImpl->GetLongitude(), DEFAULT_COORDINATE) != 0)
1068 val = media_info_set_latitude(pMediaInfo.get(), pContentInfoImpl->GetLatitude());
1069 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1070 "media_info_set_latitude failed[%d].", val);
1072 val = media_info_set_longitude(pMediaInfo.get(), pContentInfoImpl->GetLongitude());
1073 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1074 "media_info_set_longitude failed[%d].", val);
1076 if (Double::Compare(pContentInfoImpl->GetAltitude(), DEFAULT_COORDINATE) != 0)
1078 val = media_info_set_altitude(pMediaInfo.get(), pContentInfoImpl->GetAltitude());
1079 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1080 "media_info_set_altitude failed[%d].", val);
1084 val = media_info_update_to_db(pMediaInfo.get());
1085 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1086 "media_info_update_to_db failed[%d].", val);
1092 _ContentManagerImpl::SaveDataToDatabase(const media_info_h pMediaInfo,
1093 _ContentInfoImpl* pContentInfoImpl) const
1096 result r = E_SUCCESS;
1098 SysTryReturn(NID_CNT, pContentInfoImpl != null, UuId::GetInvalidUuId(), E_INVALID_ARG,
1099 "[E_INVALID_ARG] Invalid argument is used. ContentInfo is invalid.");
1101 String contentPath(pContentInfoImpl->GetPhysicalContentPath());
1102 String changedPath(L"");
1104 r = ChangeTizenPathToCompat(contentPath, changedPath);
1105 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r,
1106 "[%s] Failed to perform ChangeTizenPathToCompat.", GetErrorMessage(r));
1108 String mimeType(L"");
1109 String extension = _FileImpl::GetFileExtension(changedPath);
1110 r = GetLastResult();
1115 SysLog(NID_CNT, "[%s] Failed to perform GetFileExtension operation.", GetErrorMessage(r));
1117 unique_ptr<char[]> pTempPath(_StringConverter::CopyToCharArrayN(contentPath));
1118 SysTryReturn(NID_CNT, pTempPath != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1119 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1121 char tempType[255] = {0, };
1122 int ret = aul_get_mime_from_file(pTempPath.get(), tempType, sizeof(tempType));
1123 SysTryReturn(NID_CNT, ret == AUL_R_OK, UuId::GetInvalidUuId(), E_INVALID_ARG,
1124 "[E_INVALID_ARG] Failed to perform aul_get_mime_from_file operation.");
1126 r = mimeType.Append(tempType);
1127 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1128 "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
1132 // If the content format is JPG and it has GPS data, it will be saved in database automatically.
1133 if (extension == L"jpg" || extension == L"jpeg" || extension == L"JPG" || extension == L"JPEG" || mimeType.Contains(L"jpeg"))
1135 SysLog(NID_CNT, "The format of content is jpg.");
1137 ImageMetadata* pImageMetadata = _ContentManagerUtilImpl::GetImageMetaN(changedPath, true);
1138 if (pImageMetadata != null)
1140 pContentInfoImpl->SetLatitude(pImageMetadata->GetLatitude());
1141 pContentInfoImpl->SetLongitude(pImageMetadata->GetLongitude());
1143 delete pImageMetadata;
1150 unique_ptr<char[]> pStr(null);
1153 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetAuthor()));
1154 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1155 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1157 val = media_info_set_author(pMediaInfo, pStr.get());
1158 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1159 "media_info_set_author failed[%d].", val);
1162 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetCategory()));
1163 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1164 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1166 val = media_info_set_category(pMediaInfo, pStr.get());
1167 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1168 "media_info_set_category failed[%d].", val);
1171 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetContentName()));
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_content_name(pMediaInfo, pStr.get());
1176 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1177 "media_info_set_content_name failed[%d].", val);
1180 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetDescription()));
1181 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1182 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1184 val = media_info_set_description(pMediaInfo, pStr.get());
1185 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1186 "media_info_set_description failed[%d].", val);
1189 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetKeyword()));
1190 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1191 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1193 val = media_info_set_keyword(pMediaInfo, pStr.get());
1194 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1195 "media_info_set_keyword failed[%d].", val);
1198 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetLocationTag()));
1199 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1200 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1202 val = media_info_set_location_tag(pMediaInfo, pStr.get());
1203 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1204 "media_info_set_location_tag failed[%d].", val);
1207 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetProvider()));
1208 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1209 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1211 val = media_info_set_provider(pMediaInfo, pStr.get());
1212 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1213 "media_info_set_provider failed[%d].", val);
1216 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetRating()));
1217 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1218 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1220 val = media_info_set_age_rating(pMediaInfo, pStr.get());
1221 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1222 "media_info_set_age_rating failed[%d].", val);
1224 // latitude, longitude, altitude
1225 if (Double::Compare(pContentInfoImpl->GetLatitude(), DEFAULT_COORDINATE) != 0 &&
1226 Double::Compare(pContentInfoImpl->GetLongitude(), DEFAULT_COORDINATE) != 0)
1228 val = media_info_set_latitude(pMediaInfo, pContentInfoImpl->GetLatitude());
1229 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1230 "media_info_set_latitude failed[%d].", val);
1232 val = media_info_set_longitude(pMediaInfo, pContentInfoImpl->GetLongitude());
1233 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1234 "media_info_set_longitude failed[%d].", val);
1236 if (Double::Compare(pContentInfoImpl->GetAltitude(), DEFAULT_COORDINATE) != 0)
1238 val = media_info_set_altitude(pMediaInfo, pContentInfoImpl->GetAltitude());
1239 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1240 "media_info_set_altitude failed[%d].", val);
1244 val = media_info_update_to_db(pMediaInfo);
1245 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1246 "media_info_update_to_db failed[%d].", val);
1248 char* pTempMediaId = null;
1249 unique_ptr<char, CharDeleter> pMediaId(null);
1251 val = media_info_get_media_id(pMediaInfo, &pTempMediaId);
1252 if (pTempMediaId != null)
1254 pMediaId.reset(pTempMediaId);
1258 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1259 "media_info_get_media_id failed[%d].", val);
1262 String tempContentId(pMediaId.get());
1263 ContentId contentId;
1265 r = UuId::Parse(tempContentId, contentId);
1266 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_INVALID_ARG,
1267 "[E_INVALID_ARG] UuId::Parse failed.");
1273 _ContentManagerImpl::MakeContentInfo(const media_info_h pMediaInfo, int systemType, void* pInfoImpl) const
1275 SysTryReturnResult(NID_CNT, pMediaInfo != null && pInfoImpl != null, E_INVALID_ARG,
1276 "The specified parameter is invalid.");
1278 _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1280 result r = E_SUCCESS;
1281 char* pTempValue = null;
1282 unique_ptr<char, CharDeleter> pStrValue(null);
1285 int val = media_info_get_media_id(pMediaInfo, &pTempValue);
1286 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1287 "media_info_get_media_id failed[%d].", val);
1289 if (pTempValue != null)
1291 pStrValue.reset(pTempValue);
1293 String strContentId(pStrValue.get());
1294 ContentId contentId;
1296 r = UuId::Parse(strContentId, contentId);
1297 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The content id can not be parsed.");
1299 pContentInfoImpl->SetContentId(contentId);
1301 SysLog(NID_CNT, "INFO: contentId[%ls]", strContentId.GetPointer());
1305 val = media_info_get_file_path(pMediaInfo, &pTempValue);
1306 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1307 "media_info_get_file_path failed[%d].", val);
1309 if (pTempValue != null)
1311 pStrValue.reset(pTempValue);
1313 String strFilePath(pStrValue.get());
1315 pContentInfoImpl->SetContentPath(strFilePath);
1316 SysSecureLog(NID_CNT, "INFO: contentPath[%ls]", (pContentInfoImpl->GetContentPath()).GetPointer());
1320 val = media_info_get_mime_type(pMediaInfo, &pTempValue);
1321 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1322 "media_info_get_mime_type failed[%d].", val);
1324 if (pTempValue != null)
1326 pStrValue.reset(pTempValue);
1328 pContentInfoImpl->SetMimeType(pStrValue.get());
1330 SysLog(NID_CNT, "INFO: mimeType[%ls]", (pContentInfoImpl->GetMimeType()).GetPointer());
1334 unsigned long long longlongValue = 0;
1335 val = media_info_get_size(pMediaInfo, &longlongValue);
1336 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1337 "media_info_get_size failed[%d].", val);
1338 pContentInfoImpl->SetContentSize(longlongValue);
1339 SysLog(NID_CNT, "INFO: contentSize[%llu]", longlongValue);
1342 media_content_storage_e storageType;
1343 val = media_info_get_storage_type(pMediaInfo, &storageType);
1344 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1345 "media_info_get_storage_type failed[%d].", val);
1346 pContentInfoImpl->SetStorageType(storageType);
1347 SysLog(NID_CNT, "INFO: storageType[%d]", storageType);
1350 bool tempDrm = false;
1352 val = media_info_is_drm(pMediaInfo, &tempDrm);
1353 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1354 "media_info_is_drm failed[%d].", val);
1356 pContentInfoImpl->SetDrmProtected(tempDrm);
1358 SysLog(NID_CNT, "INFO: isDrm[%d]", pContentInfoImpl->IsDrmProtected());
1361 time_t addedTime = 0;
1362 val = media_info_get_added_time(pMediaInfo, &addedTime);
1363 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1364 "media_info_get_added_time failed[%d].", val);
1367 r = dt.SetValue(1970, 1, 1);
1368 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.SetValue operation.");
1369 r = dt.AddSeconds(addedTime);// need to check addedTime is secs/millisec
1370 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.AddSeconds operation.");
1372 pContentInfoImpl->SetDateTime(dt);
1373 SysLog(NID_CNT, "INFO: dateTime[%ls]", ((pContentInfoImpl->GetDateTime()).ToString()).GetPointer());
1376 time_t modifiedTime = 0;
1377 val = media_info_get_modified_time(pMediaInfo, &modifiedTime);
1378 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1379 "media_info_get_modified_time failed[%d].", val);
1381 r = dt.SetValue(1970, 1, 1);
1382 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.SetValue operation.");
1383 r = dt.AddSeconds(modifiedTime);
1384 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.AddSeconds operation.");
1386 pContentInfoImpl->SetModifiedTime(dt);
1387 SysLog(NID_CNT, "INFO: modifiedTime[%ls]", ((pContentInfoImpl->GetModifiedTime()).ToString()).GetPointer());
1390 val = media_info_get_thumbnail_path(pMediaInfo, &pTempValue);
1391 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1392 "media_info_get_thumbnail_path failed[%d].", val);
1394 if (pTempValue != null)
1396 pStrValue.reset(pTempValue);
1397 String thumbnailPath(pStrValue.get());
1399 pContentInfoImpl->SetThumbnailPath(thumbnailPath);
1400 SysLog(NID_CNT, "INFO: thumbnailPath[%ls]", (pContentInfoImpl->GetThumbnailPath()).GetPointer());
1404 val = media_info_get_author(pMediaInfo, &pTempValue);
1405 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1406 "media_info_get_author failed[%d].", val);
1408 if (pTempValue != null)
1410 pStrValue.reset(pTempValue);
1412 pContentInfoImpl->SetAuthor(String(pStrValue.get()));
1414 SysLog(NID_CNT, "INFO: author[%ls]", (pContentInfoImpl->GetAuthor()).GetPointer());
1418 val = media_info_get_category(pMediaInfo, &pTempValue);
1419 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1420 "media_info_get_category failed[%d].", val);
1422 if (pTempValue != null)
1424 pStrValue.reset(pTempValue);
1426 pContentInfoImpl->SetCategory(String(pStrValue.get()));
1428 SysLog(NID_CNT, "INFO: category[%ls]", (pContentInfoImpl->GetCategory()).GetPointer());
1432 val = media_info_get_content_name(pMediaInfo, &pTempValue);
1433 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1434 "media_info_get_content_name failed[%d].", val);
1436 if (pTempValue != null)
1438 pStrValue.reset(pTempValue);
1440 pContentInfoImpl->SetContentName(String(pStrValue.get()));
1442 SysSecureLog(NID_CNT, "INFO: contentName[%ls]", (pContentInfoImpl->GetContentName()).GetPointer());
1446 val = media_info_get_description(pMediaInfo, &pTempValue);
1447 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1448 "media_info_get_description failed[%d].", val);
1450 if (pTempValue != null)
1452 pStrValue.reset(pTempValue);
1454 pContentInfoImpl->SetDescription(String(pStrValue.get()));
1456 SysLog(NID_CNT, "INFO: description[%ls]", (pContentInfoImpl->GetDescription()).GetPointer());
1460 val = media_info_get_keyword(pMediaInfo, &pTempValue);
1461 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1462 "media_info_get_keyword failed[%d].", val);
1464 if (pTempValue != null)
1466 pStrValue.reset(pTempValue);
1468 pContentInfoImpl->SetKeyword(String(pStrValue.get()));
1470 SysLog(NID_CNT, "INFO: keyword[%ls]", (pContentInfoImpl->GetKeyword()).GetPointer());
1474 val = media_info_get_location_tag(pMediaInfo, &pTempValue);
1475 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1476 "media_info_get_location_tag failed[%d].", val);
1478 if (pTempValue != null)
1480 pStrValue.reset(pTempValue);
1482 pContentInfoImpl->SetLocationTag(String(pStrValue.get()));
1484 SysSecureLog(NID_CNT, "INFO: locationTag[%ls]", (pContentInfoImpl->GetLocationTag()).GetPointer());
1488 val = media_info_get_provider(pMediaInfo, &pTempValue);
1489 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1490 "media_info_get_provider failed[%d].", val);
1492 if (pTempValue != null)
1494 pStrValue.reset(pTempValue);
1496 pContentInfoImpl->SetProvider(String(pStrValue.get()));
1498 SysLog(NID_CNT, "INFO: provider[%ls]", (pContentInfoImpl->GetProvider()).GetPointer());
1502 val = media_info_get_age_rating(pMediaInfo, &pTempValue);
1503 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1504 "media_info_get_age_rating failed[%d].", val);
1506 if (pTempValue != null)
1508 pStrValue.reset(pTempValue);
1510 pContentInfoImpl->SetRating(String(pStrValue.get()));
1512 SysLog(NID_CNT, "INFO: rating[%ls]", (pContentInfoImpl->GetRating()).GetPointer());
1516 Coordinates coordinates;
1517 double doubleValue = 0;
1518 val = media_info_get_latitude(pMediaInfo, &doubleValue);
1519 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1520 "media_info_get_latitude failed[%d].", val);
1522 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1524 pContentInfoImpl->SetLatitude(doubleValue);
1525 coordinates.SetLatitude(doubleValue);
1527 SysSecureLog(NID_CNT, "INFO: latitude[%f]", pContentInfoImpl->GetLatitude());
1529 val = media_info_get_longitude(pMediaInfo, &doubleValue);
1530 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1531 "media_info_get_longitude failed[%d].", val);
1533 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1535 pContentInfoImpl->SetLongitude(doubleValue);
1536 coordinates.SetLongitude(doubleValue);
1538 SysSecureLog(NID_CNT, "INFO: longitude[%f]", pContentInfoImpl->GetLongitude());
1540 val = media_info_get_altitude(pMediaInfo, &doubleValue);
1541 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1542 "media_info_get_altitude failed[%d].", val);
1544 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1546 pContentInfoImpl->SetAltitude(doubleValue);
1547 coordinates.SetAltitude(doubleValue);
1549 SysLog(NID_CNT, "INFO: altitude[%f]", pContentInfoImpl->GetAltitude());
1551 pContentInfoImpl->SetCoordinates(coordinates);
1553 // contentType and metadata
1554 if (systemType == SYSTEM_TYPE_IMAGE)
1556 r = MakeImageContentInfo(pMediaInfo, pInfoImpl);
1557 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform MakeImageContentInfo operation.");
1559 else if (systemType == SYSTEM_TYPE_SOUND || systemType == SYSTEM_TYPE_MUSIC)
1561 r = MakeAudioContentInfo(pMediaInfo, pInfoImpl);
1562 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform MakeAudioContentInfo operation.");
1564 else if (systemType == MEDIA_CONTENT_TYPE_VIDEO)
1566 r = MakeVideoContentInfo(pMediaInfo, pInfoImpl);
1567 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform MakeVideoContentInfo operation.");
1569 else if (systemType == SYSTEM_TYPE_OTHER)
1571 pContentInfoImpl->SetContentType(CONTENT_TYPE_OTHER);
1572 SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1579 _ContentManagerImpl::MakeImageContentInfo(const media_info_h pMediaInfo, void* pInfoImpl) const
1581 result r = E_SUCCESS;
1583 bool boolValue = false;
1584 image_meta_h pTempMeta = null;
1585 unique_ptr<image_meta_h, _ImageMetaDeleter> pImageMeta(null);
1587 SysTryReturnResult(NID_CNT, pInfoImpl != null, E_OUT_OF_MEMORY, "pInfoImpl is null.");
1589 _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1590 SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ContentInfoImpl.");
1592 pContentInfoImpl->SetContentType(CONTENT_TYPE_IMAGE);
1593 SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1595 int val = media_info_get_image(pMediaInfo, &pTempMeta);
1596 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1597 "media_info_get_image failed[%d].", val);
1599 pImageMeta.reset(&pTempMeta);
1601 _ImageContentInfoImpl* pImageContentInfoImpl = static_cast< _ImageContentInfoImpl* >(pInfoImpl);
1602 SysTryReturnResult(NID_CNT, pImageContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ImageContentInfoImpl.");
1605 val = image_meta_get_width(*(pImageMeta.get()), &intValue);
1606 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1607 "image_meta_get_width failed[%d].", val);
1609 pImageContentInfoImpl->SetWidth(intValue);
1610 SysLog(NID_CNT, "META: width[%d]", intValue);
1613 val = image_meta_get_height(*(pImageMeta.get()), &intValue);
1614 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1615 "image_meta_get_height failed[%d].", val);
1617 pImageContentInfoImpl->SetHeight(intValue);
1618 SysLog(NID_CNT, "META: height[%d]", intValue);
1621 media_content_orientation_e orientation;
1622 val = image_meta_get_orientation(*(pImageMeta.get()), &orientation);
1623 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1624 "image_meta_get_orientation failed[%d].", val);
1626 pImageContentInfoImpl->SetOrientation(static_cast< ImageOrientationType >(orientation));
1627 SysLog(NID_CNT, "META: orientation[%d]", orientation);
1629 char* pTempValue = null;
1630 unique_ptr<char, CharDeleter> pStrValue(null);
1633 val = media_info_get_display_name(pMediaInfo, &pTempValue);
1634 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1635 "media_info_get_display_name failed[%d].", val);
1637 if (pTempValue != null)
1639 pStrValue.reset(pTempValue);
1643 String strTitle(pStrValue.get());
1645 result r = strTitle.LastIndexOf(L'.', strTitle.GetLength() - 1, pos);
1648 r = strTitle.SubString(0, pos, fileName);
1649 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The title is invalid.");
1653 // Without extension
1655 fileName = strTitle;
1658 pImageContentInfoImpl->SetTitle(fileName);
1660 SysLog(NID_CNT, "META: title[%ls]", fileName.GetPointer());
1664 val = image_meta_get_date_taken(*(pImageMeta.get()), &pTempValue);
1665 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1666 "image_meta_get_date_taken failed[%d].", val);
1670 if (pTempValue != null)
1672 pStrValue.reset(pTempValue);
1673 String dateTaken(pStrValue.get());
1674 String newDateTaken(L"");
1676 // detour the unexpected datetaken format
1677 String tempDelim(L"+-Z");
1680 StringTokenizer tempStrTok(dateTaken, tempDelim);
1682 r = tempStrTok.GetNextToken(token);
1683 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1687 String delim(L": ");
1690 StringTokenizer strTok(dateTaken, delim);
1692 r = strTok.SetDelimiters(delim);
1693 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform SetDelimiters operation.");
1695 r = strTok.GetNextToken(token);
1696 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1701 r = strTok.GetNextToken(token);
1702 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1704 r = newDateTaken.Append(token);
1705 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1707 r = newDateTaken.Append(L"/");
1708 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1711 r = strTok.GetNextToken(token);
1712 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1714 r = newDateTaken.Append(token);
1715 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1717 r = newDateTaken.Append(L"/");
1718 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1721 r = newDateTaken.Append(year);
1722 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1724 r = newDateTaken.Append(L" ");
1725 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1727 String newDelim(L" ");
1729 r = strTok.SetDelimiters(newDelim);
1730 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform SetDelimiters operation.");
1732 r = strTok.GetNextToken(token);
1733 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1735 r = newDateTaken.Append(token);
1736 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1738 r = DateTime::Parse(newDateTaken, dt);
1739 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform Parse operation for DateTime.");
1743 dt = DateTime::GetMinValue();
1746 pImageContentInfoImpl->SetImageTakenDate(dt);
1747 SysLog(NID_CNT, "META: dateTaken[%ls]", dt.ToString().GetPointer());
1750 val = image_meta_is_burst_shot(*(pImageMeta.get()), &boolValue);
1751 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1752 "image_meta_is_burst_shot failed[%d].", val);
1754 pImageContentInfoImpl->SetBurstShot(boolValue);
1755 SysLog(NID_CNT, "META: isBurstShot[%d]", boolValue);
1758 val = image_meta_get_burst_id(*(pImageMeta.get()), &pTempValue);
1759 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1760 "image_meta_get_burst_id failed[%d].", val);
1762 if (pTempValue != null)
1764 pStrValue.reset(pTempValue);
1765 String burstShotId(pStrValue.get());
1767 pImageContentInfoImpl->SetBurstShotId(burstShotId);
1768 SysLog(NID_CNT, "META: burstShotId[%ls]", burstShotId.GetPointer());
1775 _ContentManagerImpl::MakeAudioContentInfo(const media_info_h pMediaInfo, void* pInfoImpl) const
1778 audio_meta_h pTempMeta = null;
1779 unique_ptr<audio_meta_h, _AudioMetaDeleter> pAudioMeta(null);
1781 SysTryReturnResult(NID_CNT, pInfoImpl != null, E_OUT_OF_MEMORY, "pInfoImpl is null.");
1783 _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1784 SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ContentInfoImpl.");
1786 pContentInfoImpl->SetContentType(CONTENT_TYPE_AUDIO);
1787 SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1789 int val = media_info_get_audio(pMediaInfo, &pTempMeta);
1790 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1791 "media_info_get_audio failed[%d].", val);
1793 pAudioMeta.reset(&pTempMeta);
1795 _AudioContentInfoImpl* pAudioContentInfoImpl = static_cast< _AudioContentInfoImpl* >(pInfoImpl);
1796 SysTryReturnResult(NID_CNT, pAudioContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _AudioContentInfoImpl.");
1799 val = audio_meta_get_bit_rate(*(pAudioMeta.get()), &intValue);
1800 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1801 "audio_meta_get_bit_rate failed[%d].", val);
1803 pAudioContentInfoImpl->SetBitrate(intValue);
1804 SysLog(NID_CNT, "META: bitrate[%d]", intValue);
1806 char* pTempValue = null;
1807 unique_ptr<char, CharDeleter> pStrValue(null);
1810 val = audio_meta_get_year(*(pAudioMeta.get()), &pTempValue);
1811 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1812 "audio_meta_get_year failed[%d].", val);
1814 if (pTempValue != null)
1816 pStrValue.reset(pTempValue);
1818 String strYear(pStrValue.get());
1820 if (strYear.CompareTo(L"Unknown") != 0)
1822 result r = Integer::Parse(strYear, intValue);
1825 // It is one of the metadata. If error occurs, skip it for other metadata.
1828 SysLog(NID_CNT, "META: releaseYear - invalid data[%ls]", strYear.GetPointer());
1831 pAudioContentInfoImpl->SetReleaseYear(intValue);
1832 SysLog(NID_CNT, "META: releaseYear[%d]", intValue);
1837 val = audio_meta_get_title(*(pAudioMeta.get()), &pTempValue);
1838 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1839 "audio_meta_get_title failed[%d].", val);
1841 if (pTempValue != null)
1843 pStrValue.reset(pTempValue);
1845 pAudioContentInfoImpl->SetTitle(String(pStrValue.get()));
1847 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
1851 val = audio_meta_get_album(*(pAudioMeta.get()), &pTempValue);
1852 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1853 "audio_meta_get_album failed[%d].", val);
1855 if (pTempValue != null)
1857 pStrValue.reset(pTempValue);
1859 pAudioContentInfoImpl->SetAlbumName(String(pStrValue.get()));
1861 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
1865 val = audio_meta_get_artist(*(pAudioMeta.get()), &pTempValue);
1866 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1867 "audio_meta_get_artist failed[%d].", val);
1869 if (pTempValue != null)
1871 pStrValue.reset(pTempValue);
1873 pAudioContentInfoImpl->SetArtist(String(pStrValue.get()));
1875 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
1879 val = audio_meta_get_composer(*(pAudioMeta.get()), &pTempValue);
1880 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1881 "audio_meta_get_composer failed[%d].", val);
1883 if (pTempValue != null)
1885 pStrValue.reset(pTempValue);
1887 pAudioContentInfoImpl->SetComposer(String(pStrValue.get()));
1889 SysLog(NID_CNT, "META: composer[%ls]", (String(pStrValue.get())).GetPointer());
1893 val = audio_meta_get_genre(*(pAudioMeta.get()), &pTempValue);
1894 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1895 "audio_meta_get_genre failed[%d].", val);
1897 if (pTempValue != null)
1899 pStrValue.reset(pTempValue);
1901 pAudioContentInfoImpl->SetGenre(String(pStrValue.get()));
1903 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
1907 val = audio_meta_get_copyright(*(pAudioMeta.get()), &pTempValue);
1908 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1909 "audio_meta_get_copyright failed[%d].", val);
1911 if (pTempValue != null)
1913 pStrValue.reset(pTempValue);
1915 pAudioContentInfoImpl->SetCopyright(String(pStrValue.get()));
1917 SysLog(NID_CNT, "META: copyright[%ls]", (String(pStrValue.get())).GetPointer());
1921 val = audio_meta_get_track_num(*(pAudioMeta.get()), &pTempValue);
1922 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1923 "audio_meta_get_track_num failed[%d].", val);
1925 if (pTempValue != null)
1927 pStrValue.reset(pTempValue);
1929 pAudioContentInfoImpl->SetTrackInfo(String(pStrValue.get()));
1931 SysLog(NID_CNT, "META: trackInfo[%ls]", (String(pStrValue.get())).GetPointer());
1935 val = audio_meta_get_duration(*(pAudioMeta.get()), &intValue);
1936 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1937 "audio_meta_get_duration failed[%d].", val);
1939 pAudioContentInfoImpl->SetDuration(intValue);
1940 SysLog(NID_CNT, "META: duration[%d]", intValue);
1946 _ContentManagerImpl::MakeVideoContentInfo(const media_info_h pMediaInfo, void* pInfoImpl) const
1949 video_meta_h pTempMeta = null;
1950 unique_ptr<video_meta_h, _VideoMetaDeleter> pVideoMeta(null);
1952 SysTryReturnResult(NID_CNT, pInfoImpl != null, E_OUT_OF_MEMORY, "pInfoImpl is null.");
1954 _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1955 SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ContentInfoImpl.");
1957 pContentInfoImpl->SetContentType(CONTENT_TYPE_VIDEO);
1958 SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1960 int val = media_info_get_video(pMediaInfo, &pTempMeta);
1961 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1962 "media_info_get_video failed[%d].", val);
1964 pVideoMeta.reset(&pTempMeta);
1966 _VideoContentInfoImpl* pVideoContentInfoImpl = static_cast< _VideoContentInfoImpl* >(pInfoImpl);
1967 SysTryReturnResult(NID_CNT, pVideoContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _VideoContentInfoImpl.");
1970 val = video_meta_get_width(*(pVideoMeta.get()), &intValue);
1971 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1972 "video_meta_get_width failed[%d].", val);
1974 pVideoContentInfoImpl->SetWidth(intValue);
1975 SysLog(NID_CNT, "META: width[%d]", intValue);
1978 val = video_meta_get_height(*(pVideoMeta.get()), &intValue);
1979 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1980 "video_meta_get_height failed[%d].", val);
1982 pVideoContentInfoImpl->SetHeight(intValue);
1983 SysLog(NID_CNT, "META: height[%d]", intValue);
1985 char* pTempValue = null;
1986 unique_ptr<char, CharDeleter> pStrValue(null);
1989 val = video_meta_get_artist(*(pVideoMeta.get()), &pTempValue);
1990 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1991 "video_meta_get_artist failed[%d].", val);
1993 if (pTempValue != null)
1995 pStrValue.reset(pTempValue);
1997 pVideoContentInfoImpl->SetArtist(String(pStrValue.get()));
1999 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
2003 val = video_meta_get_genre(*(pVideoMeta.get()), &pTempValue);
2004 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
2005 "video_meta_get_genre failed[%d].", val);
2007 if (pTempValue != null)
2009 pStrValue.reset(pTempValue);
2011 pVideoContentInfoImpl->SetGenre(String(pStrValue.get()));
2013 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
2017 val = video_meta_get_title(*(pVideoMeta.get()), &pTempValue);
2018 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
2019 "video_meta_get_title failed[%d].", val);
2021 if (pTempValue != null)
2023 pStrValue.reset(pTempValue);
2025 pVideoContentInfoImpl->SetTitle(String(pStrValue.get()));
2027 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
2031 val = video_meta_get_album(*(pVideoMeta.get()), &pTempValue);
2032 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
2033 "video_meta_get_album failed[%d].", val);
2035 if (pTempValue != null)
2037 pStrValue.reset(pTempValue);
2039 pVideoContentInfoImpl->SetAlbumName(String(pStrValue.get()));
2041 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
2045 val = video_meta_get_duration(*(pVideoMeta.get()), &intValue);
2046 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
2047 "video_meta_get_duration failed[%d].", val);
2049 pVideoContentInfoImpl->SetDuration(intValue);
2050 SysLog(NID_CNT, "META: duration[%d]", intValue);
2052 // Get some information from metadata extractor when calling VideoContentInfo (framerate, audio bitrate, video bitrate)
2058 _ContentManagerImpl::VerifyHomeFilePathCompatibility(const String& contentPath) const
2060 if (!_AppInfo::IsOspCompat())
2062 if (contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0))
2064 SysLogException(NID_CNT, E_INVALID_ARG,
2065 "[E_INVALID_ARG] /Home/ or /HomeExt/ is not supported from Tizen 2.0.");
2068 if (!(contentPath.StartsWith(App::App::GetInstance()->GetAppRootPath(), 0) ||
2069 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
2071 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] The path is not supported.");
2077 SysTryReturn(NID_CNT, contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0),
2078 false, E_INVALID_ARG, "[E_INVALID_ARG] The path should start with /Home or /HomeExt.");
2085 _ContentManagerImpl::VerifyMediaFilePathCompatibility(const String& contentPath) const
2089 if (!_AppInfo::IsOspCompat())
2091 if (!(contentPath.StartsWith(Environment::GetMediaPath(), 0) ||
2092 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
2094 SysLogException(NID_CNT, E_INVALID_ARG, "[%s] This path is not supported.", GetErrorMessage(E_INVALID_ARG));
2101 if (!(contentPath.StartsWith(OSP_MEDIA_PHONE, 0)) ||
2102 (contentPath.StartsWith(OSP_MEDIA_MMC, 0)))
2104 SysLogException(NID_CNT, E_INVALID_ARG, "[%s] The path should start with /Media, or /Storagecard/Media.", GetErrorMessage(E_INVALID_ARG));
2113 _ContentManagerImpl::ChangeTizenPathToCompat(const String& contentPath, String& changedPath) const
2115 result r = E_SUCCESS;
2116 changedPath = contentPath;
2118 // If the api version is 2.0, the content path has to be changed.
2119 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
2121 r = _FileImpl::ConvertPhysicalToVirtualPath(contentPath, changedPath);
2122 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG,
2123 "[%s] Failed to convert physical path to virtual path.", GetErrorMessage(E_INVALID_ARG));
2130 _ContentManagerImpl::ChangeCompatPathToTizen(const String& contentPath, String& changedPath) const
2132 result r = E_SUCCESS;
2133 changedPath = contentPath;
2135 // If the api version is 2.0, the content path has to be changed.
2136 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
2138 r = _FileImpl::ConvertVirtualToPhysicalPath(contentPath, changedPath);
2139 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG,
2140 "[%s] Failed to convert virtual path to physical path.", GetErrorMessage(E_INVALID_ARG));
2147 _ContentManagerImpl::SetListener(IContentUpdateEventListener* pListener)
2149 __pListener = pListener;
2152 IContentUpdateEventListener*
2153 _ContentManagerImpl::GetListener(void) const
2159 _ContentManagerImpl::ConvertErrorToResult(result res) const
2161 result r = E_SUCCESS;