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 <FBaseInteger.h>
29 #include <FBaseByteBuffer.h>
30 #include <FCntContentManager.h>
31 #include <FCntContentManagerUtil.h>
32 #include <FCntImageContentInfo.h>
33 #include <FCntAudioContentInfo.h>
34 #include <FCntVideoContentInfo.h>
35 #include <FCntOtherContentInfo.h>
36 #include <FCntImageMetadata.h>
37 #include <FCntAudioMetadata.h>
38 #include <FCntVideoMetadata.h>
39 #include <FCntIContentScanListener.h>
40 #include <FCntIContentUpdateEventListener.h>
41 #include <FIoDirectory.h>
42 #include <FSysEnvironment.h>
43 #include <FApp_AppInfo.h>
44 #include <FBase_StringConverter.h>
45 #include <FIo_FileImpl.h>
46 #include "FCnt_ContentManagerImpl.h"
47 #include "FCnt_ContentManagerUtilImpl.h"
48 #include "FCnt_ContentInfoImpl.h"
49 #include "FCnt_ImageContentInfoImpl.h"
50 #include "FCnt_AudioContentInfoImpl.h"
51 #include "FCnt_VideoContentInfoImpl.h"
52 #include "FCnt_OtherContentInfoImpl.h"
53 #include "FCnt_ContentInfoHelper.h"
56 using namespace Tizen::App;
57 using namespace Tizen::Base;
58 using namespace Tizen::Base::Collection;
59 using namespace Tizen::Io;
60 using namespace Tizen::Locations;
61 using namespace Tizen::System;
63 namespace Tizen { namespace Content
66 static const int SYSTEM_TYPE_IMAGE = 0;
67 static const int SYSTEM_TYPE_VIDEO = 1;
68 static const int SYSTEM_TYPE_SOUND = 2;
69 static const int SYSTEM_TYPE_MUSIC = 3;
70 static const int SYSTEM_TYPE_OTHER = 4;
71 static const double DEFAULT_COORDINATE = -200.0;
73 // For extern declaration in FCntTypes.h
74 const wchar_t OSP_HOME[] = L"/Home/";
75 const wchar_t OSP_HOME_EXT[] = L"/HomeExt/";
76 const wchar_t OSP_MEDIA_PHONE[] = L"/Media/";
77 const wchar_t OSP_MEDIA_MMC[] = L"/Storagecard/Media/";
80 ConvertError(int error)
86 case MEDIA_CONTENT_ERROR_NONE:
90 case MEDIA_CONTENT_ERROR_INVALID_PARAMETER:
94 case MEDIA_CONTENT_ERROR_OUT_OF_MEMORY:
98 case MEDIA_CONTENT_ERROR_DB_BUSY:
102 case MEDIA_CONTENT_ERROR_DB_FAILED:
115 OnScanCompleted(media_content_error_e error, void* user_data)
117 SysLog(NID_CNT, "OnScanCompleted callback method is called.");
120 result r = E_SUCCESS;
121 String scanPath(L"");
122 IContentScanListener* pListener = null;
124 unique_ptr< _ScanResult > pScanResult;
126 SysTryLogCatch(NID_CNT, user_data != null, , "OnScanCompleted failed.");
128 pScanResult = unique_ptr< _ScanResult >(static_cast< _ScanResult* >(user_data));
130 SysTryLogCatch(NID_CNT, pScanResult != null, , "OnScanCompleted failed.");
131 SysTryLogCatch(NID_CNT, pScanResult->pScanListener != null, , "Listener is null. OnScanCompleted succeeded.");
133 scanPath = pScanResult->scanPath;
134 pListener = pScanResult->pScanListener;
135 reqId = pScanResult->requestId;
137 r = ConvertError(error);
139 pListener->OnContentScanCompleted(reqId, scanPath, r);
140 SysLog(NID_CNT, "OnContentScanCompleted fired.");
143 int val = media_content_disconnect();
144 SysTryLog(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, "The disconnection failed[%d].", val);
148 OnContentUpdateCompleted(media_content_error_e error, int pid, media_content_db_update_item_type_e update_item,
149 media_content_db_update_type_e update_type, media_content_type_e media_type, char* uuid, char* path, char* mime_type, void* user_data)
151 SysLog(NID_CNT, "OnContentUpdateCompleted callback method is called.");
153 result r = E_SUCCESS;
155 SysTryLogReturn(NID_CNT, user_data != null, , "OnContentUpdateCompleted failed.");
157 _ContentManagerImpl* pTempManagerImpl = static_cast< _ContentManagerImpl* >(user_data);
158 SysTryLogReturn(NID_CNT, pTempManagerImpl != null, , "pTempManagerImpl is null.");
160 IContentUpdateEventListener* pListener = pTempManagerImpl->GetListener();
161 SysTryLogReturn(NID_CNT, pListener != null, , "IContentUpdateEventListener is null.");
163 if (error != MEDIA_CONTENT_ERROR_NONE)
170 case MEDIA_ITEM_FILE:
172 ContentType contentType = CONTENT_TYPE_UNKNOWN;
176 case MEDIA_CONTENT_TYPE_IMAGE:
177 contentType = CONTENT_TYPE_IMAGE;
180 case MEDIA_CONTENT_TYPE_VIDEO:
181 contentType = CONTENT_TYPE_VIDEO;
184 case MEDIA_CONTENT_TYPE_SOUND:
186 case MEDIA_CONTENT_TYPE_MUSIC:
187 contentType = CONTENT_TYPE_AUDIO;
190 case MEDIA_CONTENT_TYPE_OTHERS:
191 contentType = CONTENT_TYPE_OTHER;
196 SysLog(NID_CNT, "media_type is invalid.");
203 result res = UuId::Parse(str, contentId);
204 SysTryLogReturn(NID_CNT, !IsFailed(res), , "Failed to parse to the content ID.");
208 case MEDIA_CONTENT_INSERT:
209 pListener->OnContentFileCreated(contentId, contentType, r);
212 case MEDIA_CONTENT_DELETE:
213 pListener->OnContentFileDeleted(contentId, contentType, r);
216 case MEDIA_CONTENT_UPDATE:
217 pListener->OnContentFileUpdated(contentId, contentType, r);
221 SysLog(NID_CNT, "update_type is invalid.");
227 case MEDIA_ITEM_DIRECTORY:
229 String directoryPath(path);
231 pListener->OnContentDirectoryScanCompleted(directoryPath, r);
236 SysLog(NID_CNT, "update_item is invalid.");
240 SysLog(NID_CNT, "Fire the OnContentUpdateCompleted method.");
243 _ContentManagerImpl::_ContentManagerImpl(void)
244 : __isConnected(false)
250 _ContentManagerImpl::~_ContentManagerImpl(void)
256 val = media_content_unset_db_updated_cb();
257 SysLog(NID_CNT, "media_content_unset_db_updated_cb result[%d].", val);
260 val = media_content_disconnect();
261 SysLog(NID_CNT, "media_content_disconnect result[%d].", val);
265 _ContentManagerImpl::GetInstance(ContentManager& contentManager)
267 return contentManager.__pContentManagerImpl;
270 const _ContentManagerImpl*
271 _ContentManagerImpl::GetInstance(const ContentManager& contentManager)
273 return contentManager.__pContentManagerImpl;
277 _ContentManagerImpl::Construct(void)
279 int val = media_content_connect();
280 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM,
281 "The connection failed[%d].", val);
283 SysLog(NID_CNT, "media_content_connect result[%d].", val);
285 __isConnected = true;
291 _ContentManagerImpl::CreateContent(const ContentInfo& contentInfo)
295 _ContentInfoImpl* pInfoImpl = const_cast< _ContentInfoImpl* >(_ContentInfoImpl::GetInstance(contentInfo));
296 SysTryReturn(NID_CNT, pInfoImpl != null, UuId::GetInvalidUuId(), E_INVALID_ARG,
297 "[E_INVALID_ARG] Invalid argument is used. ContentInfo is invalid.");
299 SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(pInfoImpl->GetContentPath(), true), UuId::GetInvalidUuId(),
300 E_INVALID_ARG, "[E_INVALID_ARG] The contentPath is not compatible.");
301 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(pInfoImpl->GetContentPath()), UuId::GetInvalidUuId(), E_FILE_NOT_FOUND,
302 "[E_FILE_NOT_FOUND] The file corresponding to contentInfo could not be found.");
303 SysTryReturn(NID_CNT, pInfoImpl->GetContentId() == UuId::GetInvalidUuId(), UuId::GetInvalidUuId(),
304 E_INVALID_ARG, "[E_INVALID_ARG] The contentId is not empty.");
306 // Compare the type of input parameter and system
307 ContentType inputType = pInfoImpl->GetContentType();
308 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(pInfoImpl->GetContentPath(), true);
312 if (inputType != sysType)
314 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
316 SysLogException(NID_CNT, E_INVALID_ARG,
317 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
318 return UuId::GetInvalidUuId();
322 // Save data to database with contentPath.
323 unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(contentInfo.GetContentPath()));
324 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
325 "[E_OUT_OF_MEMORY] The memory is insufficient.");
327 media_info_h tempMediaInfo = null;
328 unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
330 int val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
331 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
332 "The registration to database failed[%d].", val);
334 pMediaInfo.reset(tempMediaInfo);
336 ContentId contentId = SaveDataToDatabase(pMediaInfo.get(), pInfoImpl);
337 result r = GetLastResult();
338 SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
339 "[%s] The registration to database failed.", GetErrorMessage(r));
344 // There are two steps(insert and update) for content registration.
345 // If the update failed after inserting, the inserted data SHOULD be deleted from here.
346 val = media_info_delete_from_db(pStr.get());
347 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
349 return UuId::GetInvalidUuId();
353 _ContentManagerImpl::CreateContent(const ByteBuffer& byteBuffer, const String& destinationPath,
354 const ContentInfo* pContentInfo)
358 // Check parameters(for length)
359 SysTryReturn(NID_CNT, byteBuffer.GetRemaining() > 0, UuId::GetInvalidUuId(), E_INVALID_ARG,
360 "[E_INVALID_ARG] byteBuffer is invalid.");
362 // Check parameters(for path compatibility)
363 SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(destinationPath, false), UuId::GetInvalidUuId(),
364 E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", destinationPath.GetPointer());
365 SysTryReturn(NID_CNT, !_FileImpl::IsFileExist(destinationPath), UuId::GetInvalidUuId(), E_FILE_ALREADY_EXIST,
366 "[E_FILE_ALREADY_EXIST] The specified file already exists.");
368 // Create a file with bytebuffer
369 unique_ptr<File> pFile(new (nothrow) File);
370 SysTryReturn(NID_CNT, pFile != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
371 "[E_OUT_OF_MEMORY] The memory is insufficient.");
373 result r = pFile->Construct(destinationPath, L"w+");
374 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r,
375 "[%s] The destination file can not be created.", GetErrorMessage(r));
377 _FileImpl* pFileImpl = _FileImpl::GetInstance(*pFile);
378 SysTryReturn(NID_CNT, pFileImpl != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
379 "[E_OUT_OF_MEMORY] The memory is insufficient.");
381 r = pFileImpl->Write(byteBuffer);
382 SysTryReturn(NID_CNT, !(IsFailed(r)), UuId::GetInvalidUuId(), r,
383 "[%s] The data can not be written in the destination file.", GetErrorMessage(r));
385 // for release file pointer
390 _ContentInfoImpl* pInfoImpl = null;
391 _ImageContentInfoImpl imageContentInfoImpl;
392 _AudioContentInfoImpl audioContentInfoImpl;
393 _VideoContentInfoImpl videoContentInfoImpl;
394 _OtherContentInfoImpl otherContentInfoImpl;
395 media_info_h tempMediaInfo = null;
396 unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
397 unique_ptr<char[]> pStr(null);
399 if (pContentInfo != null)
401 pInfoImpl = const_cast< _ContentInfoImpl* >(_ContentInfoImpl::GetInstance(*pContentInfo));
402 SysTryCatch(NID_CNT, pInfoImpl != null, , E_INVALID_ARG,
403 "[E_INVALID_ARG] Invalid argument is used. ContentInfo is invalid.");
405 SysTryCatch(NID_CNT, pInfoImpl->GetContentId() == UuId::GetInvalidUuId(), , E_INVALID_ARG,
406 "[E_INVALID_ARG] The content already exists in database.");
408 // Compare the type of input parameter and system
409 // CheckContentType() need actual file. so it should be checked after creating the file.
410 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
411 ContentType inputType = pInfoImpl->GetContentType();
415 if (inputType != sysType)
417 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
419 SysLogException(NID_CNT, E_INVALID_ARG,
420 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
425 // Sets the content path
426 pInfoImpl->SetContentPath(destinationPath);
430 ContentType contentType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
434 // Set the content path
435 if (contentType == CONTENT_TYPE_IMAGE)
437 r = imageContentInfoImpl.Construct(&destinationPath);
438 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
439 "[E_OUT_OF_MEMORY] Failed to perform Construct for ImageContentInfoImpl.");
441 imageContentInfoImpl.SetContentPath(destinationPath);
442 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&imageContentInfoImpl);
444 else if (contentType == CONTENT_TYPE_AUDIO)
446 r = audioContentInfoImpl.Construct(&destinationPath);
447 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
448 "[E_OUT_OF_MEMORY] Failed to perform Construct for AudioContentInfoImpl.");
450 audioContentInfoImpl.SetContentPath(destinationPath);
451 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&audioContentInfoImpl);
453 else if (contentType == CONTENT_TYPE_VIDEO)
455 r = videoContentInfoImpl.Construct(&destinationPath);
456 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
457 "[E_OUT_OF_MEMORY] Failed to perform Construct for VideoContentInfoImpl.");
459 videoContentInfoImpl.SetContentPath(destinationPath);
460 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&videoContentInfoImpl);
464 r = otherContentInfoImpl.Construct(&destinationPath);
465 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
466 "[E_OUT_OF_MEMORY] Failed to perform Construct for OtherContentInfoImpl.");
468 otherContentInfoImpl.SetContentPath(destinationPath);
469 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&otherContentInfoImpl);
473 // Register the content to database directly.
474 pStr.reset(_StringConverter::CopyToCharArrayN(destinationPath));
475 SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
477 val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
478 SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
479 "media_info_insert_to_db failed[%d].", val);
481 pMediaInfo.reset(tempMediaInfo);
483 contentId = SaveDataToDatabase(pMediaInfo.get(), pInfoImpl);
485 SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
486 "[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
491 result saveResult = GetLastResult();
493 // If the destination file is made by this method, it should be deleted when error occurs.
494 r = _FileImpl::Remove(destinationPath);
495 SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
497 if (pMediaInfo != null)
499 val = media_info_delete_from_db(pStr.get());
500 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
503 SetLastResult(saveResult);
504 return UuId::GetInvalidUuId();
508 _ContentManagerImpl::CreateContent(const String& sourcePath, const String& destinationPath, bool deleteSource,
509 const ContentInfo* pContentInfo)
513 // Check parameters(for type)
514 SysTryReturn(NID_CNT, _FileImpl::GetFileExtension(sourcePath) == _FileImpl::GetFileExtension(destinationPath),
515 UuId::GetInvalidUuId(), E_INVALID_ARG, "[E_INVALID_ARG] There is a mismatch between the type of source and dest path.");
517 // Check parameters(for path compatibility)
518 SysTryReturn(NID_CNT, VerifyHomeFilePathCompatibility(sourcePath), UuId::GetInvalidUuId(), E_INVALID_ARG,
519 "[E_INVALID_ARG] %ls is not compatible.", sourcePath.GetPointer());
520 SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(destinationPath, false), UuId::GetInvalidUuId(),
521 E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", destinationPath.GetPointer());
523 result r = E_SUCCESS;
526 if (deleteSource) // move
528 r = _FileImpl::Move(sourcePath, destinationPath);
529 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Moving the file failed.", GetErrorMessage(r));
533 r = _FileImpl::Copy(sourcePath, destinationPath, true);
534 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Copying the file failed.", GetErrorMessage(r));
541 _ContentInfoImpl* pInfoImpl = null;
542 _ImageContentInfoImpl imageContentInfoImpl;
543 _AudioContentInfoImpl audioContentInfoImpl;
544 _VideoContentInfoImpl videoContentInfoImpl;
545 _OtherContentInfoImpl otherContentInfoImpl;
546 media_info_h tempMediaInfo = null;
547 unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
548 unique_ptr<char[]> pStr(null);
550 if (pContentInfo != null)
552 pInfoImpl = const_cast< _ContentInfoImpl* >(_ContentInfoImpl::GetInstance(*pContentInfo));
553 SysTryCatch(NID_CNT, pInfoImpl != null, , E_INVALID_ARG,
554 "[E_INVALID_ARG] Invalid argument is used. ContentInfo is invalid.");
556 SysTryCatch(NID_CNT, pInfoImpl->GetContentId() == UuId::GetInvalidUuId(), , E_INVALID_ARG,
557 "[E_INVALID_ARG] The content already exists in database.");
559 // Compare the type of input parameter and system
560 // CheckContentType() need actual file. so it should be checked after creating the file.
561 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
562 ContentType inputType = pInfoImpl->GetContentType();
566 if (inputType != sysType)
568 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
570 SysLogException(NID_CNT, E_INVALID_ARG,
571 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
576 // Set the content path
577 pInfoImpl->SetContentPath(destinationPath);
581 ContentType contentType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
585 // Set the content path
586 if (contentType == CONTENT_TYPE_IMAGE)
588 r = imageContentInfoImpl.Construct(&destinationPath);
589 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
590 "[E_OUT_OF_MEMORY] Failed to perform Construct for ImageContentInfoImpl.");
592 imageContentInfoImpl.SetContentPath(destinationPath);
593 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&imageContentInfoImpl);
595 else if (contentType == CONTENT_TYPE_AUDIO)
597 r = audioContentInfoImpl.Construct(&destinationPath);
598 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
599 "[E_OUT_OF_MEMORY] Failed to perform Construct for AudioContentInfoImpl.");
601 audioContentInfoImpl.SetContentPath(destinationPath);
602 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&audioContentInfoImpl);
604 else if (contentType == CONTENT_TYPE_VIDEO)
606 r = videoContentInfoImpl.Construct(&destinationPath);
607 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
608 "[E_OUT_OF_MEMORY] Failed to perform Construct for VideoContentInfoImpl.");
610 videoContentInfoImpl.SetContentPath(destinationPath);
611 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&videoContentInfoImpl);
615 r = otherContentInfoImpl.Construct(&destinationPath);
616 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
617 "[E_OUT_OF_MEMORY] Failed to perform Construct for OtherContentInfoImpl.");
619 otherContentInfoImpl.SetContentPath(destinationPath);
620 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&otherContentInfoImpl);
624 pStr.reset(_StringConverter::CopyToCharArrayN(destinationPath));
625 SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
627 val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
628 SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
629 "media_info_insert_to_db failed[%d].", val);
631 pMediaInfo.reset(tempMediaInfo);
633 contentId = SaveDataToDatabase(pMediaInfo.get(), pInfoImpl);
635 SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
636 "[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
641 result saveResult = GetLastResult();
645 r = _FileImpl::Remove(destinationPath);
646 SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
650 r = _FileImpl::Move(destinationPath, sourcePath);
651 SysLog(NID_CNT, "Move[%s].", GetErrorMessage(r));
654 if (pMediaInfo != null)
656 val = media_info_delete_from_db(pStr.get());
657 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
660 SetLastResult(saveResult);
661 return UuId::GetInvalidUuId();
665 _ContentManagerImpl::GetContentInfoN(const ContentId& contentId) const
669 SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), null, E_INVALID_ARG,
670 "[E_INVALID_ARG] The contentId is invalid.");
672 unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(contentId.ToString()));
673 SysTryReturn(NID_CNT, pStr != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
675 media_info_h tempMediaInfo = null;
676 unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
677 int val = media_info_get_media_from_db(pStr.get(), &tempMediaInfo);
678 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
679 "media_info_get_media_from_db failed[%d].", val);
681 pMediaInfo.reset(tempMediaInfo);
683 media_content_type_e systemType = MEDIA_CONTENT_TYPE_IMAGE;
684 val = media_info_get_media_type(pMediaInfo.get(), &systemType);
685 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
686 "media_info_get_media_type failed[%d].", val);
688 char* pTempFilePath = null;
689 val = media_info_get_file_path(pMediaInfo.get(), &pTempFilePath);
690 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
691 "media_info_get_file_path failed[%d].", val);
693 unique_ptr<char, CharDeleter> pFilePath(pTempFilePath);
694 String contentPath(pFilePath.get());
696 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), null, E_FILE_NOT_FOUND,
697 "[E_FILE_NOT_FOUND] The file corresponding to contentId could not be found.");
699 result r = E_SUCCESS;
701 if (systemType == SYSTEM_TYPE_IMAGE)
703 unique_ptr< ImageContentInfo > pImageContentInfo(new (nothrow) ImageContentInfo);
704 SysTryReturn(NID_CNT, pImageContentInfo != null, null, E_OUT_OF_MEMORY,
705 "[E_OUT_OF_MEMORY] The memory is insufficient.");
707 r = pImageContentInfo->Construct(&contentPath);
708 r = ConvertErrorToResult(r);
709 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
710 "[%s] Failed to perform Construct operation to ImageContentInfo.", GetErrorMessage(r));
712 _ImageContentInfoImpl* pImageContentInfoImpl = _ImageContentInfoImpl::GetInstance(*(pImageContentInfo.get()));
713 SysTryReturn(NID_CNT, pImageContentInfoImpl != null, null, E_OUT_OF_MEMORY,
714 "[E_OUT_OF_MEMORY] The memory is insufficient.");
716 r = MakeContentInfo(pMediaInfo.get(), systemType, pImageContentInfoImpl);
717 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
719 return pImageContentInfo.release();
721 else if (systemType == SYSTEM_TYPE_SOUND || systemType == SYSTEM_TYPE_MUSIC)
723 unique_ptr< AudioContentInfo > pAudioContentInfo(new (nothrow) AudioContentInfo);
724 SysTryReturn(NID_CNT, pAudioContentInfo != null, null, E_OUT_OF_MEMORY,
725 "[E_OUT_OF_MEMORY] The memory is insufficient.");
727 r = pAudioContentInfo->Construct(&contentPath);
728 r = ConvertErrorToResult(r);
729 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
730 "[%s] Failed to perform Construct operation to AudioContentInfo.", GetErrorMessage(r));
732 _AudioContentInfoImpl* pAudioContentInfoImpl = _AudioContentInfoImpl::GetInstance(*(pAudioContentInfo.get()));
733 SysTryReturn(NID_CNT, pAudioContentInfoImpl != null, null, E_OUT_OF_MEMORY,
734 "[E_OUT_OF_MEMORY] The memory is insufficient.");
736 r = MakeContentInfo(pMediaInfo.get(), systemType, pAudioContentInfoImpl);
737 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
739 return pAudioContentInfo.release();
741 else if (systemType == SYSTEM_TYPE_VIDEO)
743 unique_ptr< VideoContentInfo > pVideoContentInfo(new (nothrow) VideoContentInfo);
744 SysTryReturn(NID_CNT, pVideoContentInfo != null, null, E_OUT_OF_MEMORY,
745 "[E_OUT_OF_MEMORY] The memory is insufficient.");
747 r = pVideoContentInfo->Construct(&contentPath);
748 r = ConvertErrorToResult(r);
749 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
750 "[%s] Failed to perform Construct operation to VideoContentInfo.", GetErrorMessage(r));
752 _VideoContentInfoImpl* pVideoContentInfoImpl = _VideoContentInfoImpl::GetInstance(*(pVideoContentInfo.get()));
753 SysTryReturn(NID_CNT, pVideoContentInfoImpl != null, null, E_OUT_OF_MEMORY,
754 "[E_OUT_OF_MEMORY] The memory is insufficient.");
756 r = MakeContentInfo(pMediaInfo.get(), systemType, pVideoContentInfoImpl);
757 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
759 return pVideoContentInfo.release();
761 else if (systemType == SYSTEM_TYPE_OTHER)
763 unique_ptr< OtherContentInfo > pOtherContentInfo(new (nothrow) OtherContentInfo);
764 SysTryReturn(NID_CNT, pOtherContentInfo != null, null, E_OUT_OF_MEMORY,
765 "[E_OUT_OF_MEMORY] The memory is insufficient.");
767 r = pOtherContentInfo->Construct(&contentPath);
768 r = ConvertErrorToResult(r);
769 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
770 "[%s] Failed to perform Construct operation to OtherContentInfo.", GetErrorMessage(r));
772 _OtherContentInfoImpl* pOtherContentInfoImpl = _OtherContentInfoImpl::GetInstance(*(pOtherContentInfo.get()));
773 SysTryReturn(NID_CNT, pOtherContentInfoImpl != null, null, E_OUT_OF_MEMORY,
774 "[E_OUT_OF_MEMORY] The memory is insufficient.");
776 r = MakeContentInfo(pMediaInfo.get(), systemType, pOtherContentInfoImpl);
777 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
779 return pOtherContentInfo.release();
783 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] Unsupported type");
789 _ContentManagerImpl::UpdateContent(const ContentInfo& contentInfo)
791 ContentId contentId = contentInfo.GetContentId();
792 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, "The content id is invalid.");
793 SysTryReturnResult(NID_CNT, _FileImpl::IsFileExist(contentInfo.GetContentPath()), E_FILE_NOT_FOUND,
794 "The file corresponding to contentInfo could not be found.");
796 const _ContentInfoImpl* pInfoImpl = _ContentInfoImpl::GetInstance(contentInfo);
797 SysTryReturnResult(NID_CNT, pInfoImpl != null, E_INVALID_ARG, "Invalid argument is used. ContentInfo is invalid.");
799 result r = UpdateDataToDatabase(pInfoImpl);
800 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "UpdateDataToDatabase failed.");
806 _ContentManagerImpl::DeleteContent(const ContentId& contentId)
808 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, "The contentId is invalid.");
810 unique_ptr<char[]> pContentId(_StringConverter::CopyToCharArrayN(contentId.ToString()));
811 SysTryReturnResult(NID_CNT, pContentId != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
813 result r = E_SUCCESS;
815 media_info_h tempMediaInfo = null;
816 unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
818 val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
819 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
820 "media_info_get_media_from_db failed[%d].", val);
822 pMediaInfo.reset(tempMediaInfo);
824 char* pTempPath = null;
826 val = media_info_get_file_path(pMediaInfo.get(), &pTempPath);
827 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
828 "media_info_get_file_path failed[%d].", val);
830 unique_ptr<char, CharDeleter> pContentPath(pTempPath);
832 String contentPath = String(pContentPath.get());
833 SysTryReturnResult(NID_CNT, _FileImpl::IsFileExist(contentPath), E_FILE_NOT_FOUND,
834 "The file corresponding to contentId could not be found.");
836 val = media_info_delete_from_db(pContentId.get());
837 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
838 "media_info_delete_From_db failed[%d].", val);
840 r = _FileImpl::Remove(contentPath);
841 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The file is not deleted.");
847 _ContentManagerImpl::AddContentUpdateEventListener(IContentUpdateEventListener& listener)
849 SysTryReturnResult(NID_CNT, GetListener() == null, E_OBJ_ALREADY_EXIST, "IContentUpdateEventListener is already set.");
851 SetListener(&listener);
853 int val = media_content_set_db_updated_cb(OnContentUpdateCompleted, this);
854 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "media_content_set_db_updated_cb failed[%d].", val);
860 _ContentManagerImpl::RemoveContentUpdateEventListener(IContentUpdateEventListener& listener)
862 SysTryReturnResult(NID_CNT, GetListener() == &listener, E_OBJ_NOT_FOUND, "The input listener is not equal to the registered listener.");
864 int val = media_content_unset_db_updated_cb();
865 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "media_content_unset_db_updated_cb failed[%d].", val);
873 _ContentManagerImpl::ScanFile(const Tizen::Base::String& contentPath)
875 SysSecureLog(NID_CNT, "The scan path is [%ls].", contentPath.GetPointer());
877 unique_ptr<char[]> pContentPath(_StringConverter::CopyToCharArrayN(contentPath));
878 SysTryReturnResult(NID_CNT, pContentPath, E_SYSTEM, "pContentPath is NULL.");
880 int val = media_content_connect();
881 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The connection failed[%d].", val);
883 val = media_content_scan_file(pContentPath.get());
884 result r = ConvertError(val);
885 SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , r, "[%s] media_content_scan_file failed[%d].", GetErrorMessage(r), val);
887 val = media_content_disconnect();
888 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The disconnection failed[%d].", val);
893 val = media_content_disconnect();
894 SysTryLog(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, "The disconnection failed[%d].", val);
900 _ContentManagerImpl::ScanDirectory(const Tizen::Base::String& directoryPath, bool recursive, IContentScanListener* pListener, RequestId& reqId)
902 static RequestId requestId = 0;
904 SysLog(NID_CNT, "The scan path is [%ls].", directoryPath.GetPointer());
906 unique_ptr<char[]> pDirPath(_StringConverter::CopyToCharArrayN(directoryPath));
907 SysTryReturnResult(NID_CNT, pDirPath, E_SYSTEM, "pDirPath is NULL.");
909 int val = media_content_connect();
910 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The connection failed[%d].", val);
912 unique_ptr< _ScanResult > pScanResult(new (nothrow) _ScanResult);
913 SysTryReturnResult(NID_CNT, pScanResult != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
917 pScanResult->scanPath = directoryPath;
918 pScanResult->pScanListener = pListener;
919 pScanResult->requestId = reqId;
921 val = media_content_scan_folder(pDirPath.get(), recursive, OnScanCompleted, pScanResult.release());
922 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val), "media_content_scan_folder failed[%d].", val);
928 _ContentManagerImpl::UpdateDataToDatabase(const _ContentInfoImpl* pContentInfoImpl) const
930 SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_INVALID_ARG, "pContentInfoImpl is null.");
932 media_info_h tempMediaInfo = null;
933 unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
934 unique_ptr<char[]> pContentId(_StringConverter::CopyToCharArrayN((pContentInfoImpl->GetContentId()).ToString()));
935 SysTryReturnResult(NID_CNT, pContentId != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
937 int val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
938 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
939 "media_info_get_media_from_db failed[%d].", val);
941 pMediaInfo.reset(tempMediaInfo);
943 result r = E_SUCCESS;
944 unique_ptr<char[]> pValue(null);
946 if (!pContentInfoImpl->GetAuthor().IsEmpty())
948 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetAuthor()));
949 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
951 val = media_info_set_author(pMediaInfo.get(), pValue.get());
952 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
953 "media_info_set_author failed[%d].", val);
955 if (!pContentInfoImpl->GetCategory().IsEmpty())
957 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetCategory()));
958 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
960 val = media_info_set_category(pMediaInfo.get(), pValue.get());
961 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
962 "media_info_set_category failed[%d].", val);
964 if (!pContentInfoImpl->GetContentName().IsEmpty())
966 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetContentName()));
967 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
969 val = media_info_set_content_name(pMediaInfo.get(), pValue.get());
970 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
971 "media_info_set_content_name failed[%d].", val);
973 if (!pContentInfoImpl->GetDescription().IsEmpty())
975 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetDescription()));
976 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
978 val = media_info_set_description(pMediaInfo.get(), pValue.get());
979 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
980 "media_info_set_description failed[%d].", val);
982 if (!pContentInfoImpl->GetKeyword().IsEmpty())
984 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetKeyword()));
985 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
987 val = media_info_set_keyword(pMediaInfo.get(), pValue.get());
988 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
989 "media_info_set_keyword failed[%d].", val);
991 if (!pContentInfoImpl->GetLocationTag().IsEmpty())
993 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetLocationTag()));
994 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
996 val = media_info_set_location_tag(pMediaInfo.get(), pValue.get());
997 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
998 "media_info_set_location_tag failed[%d].", val);
1000 if (!pContentInfoImpl->GetProvider().IsEmpty())
1002 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetProvider()));
1003 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1005 val = media_info_set_provider(pMediaInfo.get(), pValue.get());
1006 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1007 "media_info_set_provider failed[%d].", val);
1009 if (!pContentInfoImpl->GetRating().IsEmpty())
1011 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetRating()));
1012 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1014 val = media_info_set_age_rating(pMediaInfo.get(), pValue.get());
1015 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1016 "media_info_set_age_rating failed[%d].", val);
1018 if (Double::Compare(pContentInfoImpl->GetLatitude(), DEFAULT_COORDINATE) != 0 &&
1019 Double::Compare(pContentInfoImpl->GetLongitude(), DEFAULT_COORDINATE) != 0)
1021 val = media_info_set_latitude(pMediaInfo.get(), pContentInfoImpl->GetLatitude());
1022 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1023 "media_info_set_latitude failed[%d].", val);
1025 val = media_info_set_longitude(pMediaInfo.get(), pContentInfoImpl->GetLongitude());
1026 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1027 "media_info_set_longitude failed[%d].", val);
1029 if (Double::Compare(pContentInfoImpl->GetAltitude(), DEFAULT_COORDINATE) != 0)
1031 val = media_info_set_altitude(pMediaInfo.get(), pContentInfoImpl->GetAltitude());
1032 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1033 "media_info_set_altitude failed[%d].", val);
1037 val = media_info_update_to_db(pMediaInfo.get());
1038 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1039 "media_info_update_to_db failed[%d].", val);
1045 _ContentManagerImpl::SaveDataToDatabase(const media_info_h pMediaInfo,
1046 _ContentInfoImpl* pContentInfoImpl) const
1050 SysTryReturn(NID_CNT, pContentInfoImpl != null, UuId::GetInvalidUuId(), E_INVALID_ARG,
1051 "[E_INVALID_ARG] Invalid argument is used. ContentInfo is invalid.");
1053 String mimeType(L"");
1054 String extension = _FileImpl::GetFileExtension(pContentInfoImpl->GetContentPath());
1055 result r = GetLastResult();
1060 SysLog(NID_CNT, "[%s] Failed to perform GetFileExtension operation.", GetErrorMessage(r));
1062 unique_ptr<char[]> pTempPath(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetContentPath()));
1063 SysTryReturn(NID_CNT, pTempPath != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1064 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1066 char tempType[255] = {0, };
1067 int ret = aul_get_mime_from_file(pTempPath.get(), tempType, sizeof(tempType));
1068 SysTryReturn(NID_CNT, ret == AUL_R_OK, UuId::GetInvalidUuId(), E_INVALID_ARG,
1069 "[E_INVALID_ARG] Failed to perform aul_get_mime_from_file operation.");
1071 r = mimeType.Append(tempType);
1072 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1073 "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
1077 // If the content format is JPG and it has GPS data, it will be saved in database automatically.
1078 if (extension == L"jpg" || extension == L"jpeg" || extension == L"JPG" || extension == L"JPEG" || mimeType.Contains(L"jpeg"))
1080 SysLog(NID_CNT, "The format of content is jpg.");
1082 ImageMetadata* pImageMetadata = _ContentManagerUtilImpl::GetImageMetaN(pContentInfoImpl->GetContentPath(), true);
1083 if (pImageMetadata != null)
1085 pContentInfoImpl->SetLatitude(pImageMetadata->GetLatitude());
1086 pContentInfoImpl->SetLongitude(pImageMetadata->GetLongitude());
1088 delete pImageMetadata;
1095 unique_ptr<char[]> pStr(null);
1097 if (pContentInfoImpl->GetAuthor() != null)
1099 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetAuthor()));
1100 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1101 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1103 val = media_info_set_author(pMediaInfo, pStr.get());
1104 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1105 "media_info_set_author failed[%d].", val);
1107 if (pContentInfoImpl->GetCategory() != null)
1109 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetCategory()));
1110 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1111 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1113 val = media_info_set_category(pMediaInfo, pStr.get());
1114 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1115 "media_info_set_category failed[%d].", val);
1117 if (pContentInfoImpl->GetContentName() != null)
1119 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetContentName()));
1120 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1121 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1123 val = media_info_set_content_name(pMediaInfo, pStr.get());
1124 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1125 "media_info_set_content_name failed[%d].", val);
1127 if (pContentInfoImpl->GetDescription() != null)
1129 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetDescription()));
1130 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1131 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1133 val = media_info_set_description(pMediaInfo, pStr.get());
1134 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1135 "media_info_set_description failed[%d].", val);
1137 if (pContentInfoImpl->GetKeyword() != null)
1139 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetKeyword()));
1140 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1141 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1143 val = media_info_set_keyword(pMediaInfo, pStr.get());
1144 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1145 "media_info_set_keyword failed[%d].", val);
1147 if (pContentInfoImpl->GetLocationTag() != null)
1149 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetLocationTag()));
1150 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1151 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1153 val = media_info_set_location_tag(pMediaInfo, pStr.get());
1154 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1155 "media_info_set_location_tag failed[%d].", val);
1157 if (pContentInfoImpl->GetProvider() != null)
1159 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetProvider()));
1160 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1161 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1163 val = media_info_set_provider(pMediaInfo, pStr.get());
1164 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1165 "media_info_set_provider failed[%d].", val);
1167 if (pContentInfoImpl->GetRating() != null)
1169 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetRating()));
1170 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1171 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1173 val = media_info_set_age_rating(pMediaInfo, pStr.get());
1174 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1175 "media_info_set_age_rating failed[%d].", val);
1177 if (Double::Compare(pContentInfoImpl->GetLatitude(), DEFAULT_COORDINATE) != 0 &&
1178 Double::Compare(pContentInfoImpl->GetLongitude(), DEFAULT_COORDINATE) != 0)
1180 val = media_info_set_latitude(pMediaInfo, pContentInfoImpl->GetLatitude());
1181 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1182 "media_info_set_latitude failed[%d].", val);
1184 val = media_info_set_longitude(pMediaInfo, pContentInfoImpl->GetLongitude());
1185 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1186 "media_info_set_longitude failed[%d].", val);
1188 if (Double::Compare(pContentInfoImpl->GetAltitude(), DEFAULT_COORDINATE) != 0)
1190 val = media_info_set_altitude(pMediaInfo, pContentInfoImpl->GetAltitude());
1191 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1192 "media_info_set_altitude failed[%d].", val);
1196 val = media_info_update_to_db(pMediaInfo);
1197 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1198 "media_info_update_to_db failed[%d].", val);
1200 char* pTempMediaId = null;
1201 unique_ptr<char, CharDeleter> pMediaId(null);
1203 val = media_info_get_media_id(pMediaInfo, &pTempMediaId);
1204 if (pTempMediaId != null)
1206 pMediaId.reset(pTempMediaId);
1210 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1211 "media_info_get_media_id failed[%d].", val);
1214 String tempContentId(pMediaId.get());
1215 ContentId contentId;
1217 r = UuId::Parse(tempContentId, contentId);
1218 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_INVALID_ARG,
1219 "[E_INVALID_ARG] UuId::Parse failed.");
1225 _ContentManagerImpl::MakeContentInfo(const media_info_h pMediaInfo, int systemType, void* pInfoImpl) const
1227 SysTryReturnResult(NID_CNT, pMediaInfo != null && pInfoImpl != null, E_INVALID_ARG,
1228 "The specified parameter is invalid.");
1230 _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1232 result r = E_SUCCESS;
1233 char* pTempValue = null;
1234 unique_ptr<char, CharDeleter> pStrValue(null);
1237 int val = media_info_get_media_id(pMediaInfo, &pTempValue);
1238 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1239 "media_info_get_media_id failed[%d].", val);
1241 if (pTempValue != null)
1243 pStrValue.reset(pTempValue);
1245 String strContentId(pStrValue.get());
1246 ContentId contentId;
1248 r = UuId::Parse(strContentId, contentId);
1249 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The content id can not be parsed.");
1251 pContentInfoImpl->SetContentId(contentId);
1253 SysLog(NID_CNT, "INFO: contentId[%ls]", strContentId.GetPointer());
1257 val = media_info_get_file_path(pMediaInfo, &pTempValue);
1258 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1259 "media_info_get_file_path failed[%d].", val);
1261 if (pTempValue != null)
1263 pStrValue.reset(pTempValue);
1265 String strFilePath(pStrValue.get());
1267 // If the api version is 2.0, the content path has to be changed.
1268 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
1270 if (strFilePath.StartsWith(Environment::GetMediaPath(), 0))
1272 r = strFilePath.Replace(Environment::GetMediaPath(), OSP_MEDIA_PHONE);
1273 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The content path is not changed.");
1275 else if (strFilePath.StartsWith(Environment::GetExternalStoragePath(), 0))
1277 r = strFilePath.Replace(Environment::GetExternalStoragePath(), OSP_MEDIA_MMC);
1278 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Replace failed.");
1282 SysLogException(NID_CNT, E_INVALID_ARG,
1283 "[E_INVALID_ARG] The content path is not supported.");
1284 return E_INVALID_ARG;
1288 pContentInfoImpl->SetContentPath(strFilePath);
1290 SysSecureLog(NID_CNT, "INFO: contentPath[%ls]", strFilePath.GetPointer());
1294 val = media_info_get_mime_type(pMediaInfo, &pTempValue);
1295 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1296 "media_info_get_mime_type failed[%d].", val);
1298 if (pTempValue != null)
1300 pStrValue.reset(pTempValue);
1302 pContentInfoImpl->SetMimeType(pStrValue.get());
1304 SysLog(NID_CNT, "INFO: mimeType[%ls]", (pContentInfoImpl->GetMimeType()).GetPointer());
1308 unsigned long long longlongValue = 0;
1309 val = media_info_get_size(pMediaInfo, &longlongValue);
1310 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1311 "media_info_get_size failed[%d].", val);
1312 pContentInfoImpl->SetContentSize(longlongValue);
1313 SysLog(NID_CNT, "INFO: contentSize[%llu]", longlongValue);
1316 media_content_storage_e storageType;
1317 val = media_info_get_storage_type(pMediaInfo, &storageType);
1318 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1319 "media_info_get_storage_type failed[%d].", val);
1320 pContentInfoImpl->SetStorageType(storageType);
1321 SysLog(NID_CNT, "INFO: storageType[%d]", storageType);
1324 bool tempDrm = false;
1326 val = media_info_is_drm(pMediaInfo, &tempDrm);
1327 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1328 "media_info_is_drm failed[%d].", val);
1330 pContentInfoImpl->SetDrmProtected(tempDrm);
1332 SysLog(NID_CNT, "INFO: isDrm[%d]", pContentInfoImpl->IsDrmProtected());
1335 time_t addedTime = 0;
1336 val = media_info_get_added_time(pMediaInfo, &addedTime);
1337 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1338 "media_info_get_added_time failed[%d].", val);
1341 r = dt.SetValue(1970, 1, 1);
1342 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.SetValue operation.");
1343 r = dt.AddSeconds(addedTime);// need to check addedTime is secs/millisec
1344 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.AddSeconds operation.");
1346 pContentInfoImpl->SetDateTime(dt);
1347 SysLog(NID_CNT, "INFO: dateTime[%ls]", ((pContentInfoImpl->GetDateTime()).ToString()).GetPointer());
1350 val = media_info_get_thumbnail_path(pMediaInfo, &pTempValue);
1351 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1352 "media_info_get_thumbnail_path failed[%d].", val);
1354 if (pTempValue != null)
1356 pStrValue.reset(pTempValue);
1357 String thumbnailPath(pStrValue.get());
1359 pContentInfoImpl->SetThumbnailPath(thumbnailPath);
1361 SysLog(NID_CNT, "INFO: thumbnailPath[%ls]", (pContentInfoImpl->GetThumbnailPath()).GetPointer());
1365 val = media_info_get_author(pMediaInfo, &pTempValue);
1366 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1367 "media_info_get_author failed[%d].", val);
1369 if (pTempValue != null)
1371 pStrValue.reset(pTempValue);
1373 pContentInfoImpl->SetAuthor(String(pStrValue.get()));
1375 SysLog(NID_CNT, "INFO: author[%ls]", (pContentInfoImpl->GetAuthor()).GetPointer());
1379 val = media_info_get_category(pMediaInfo, &pTempValue);
1380 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1381 "media_info_get_category failed[%d].", val);
1383 if (pTempValue != null)
1385 pStrValue.reset(pTempValue);
1387 pContentInfoImpl->SetCategory(String(pStrValue.get()));
1389 SysLog(NID_CNT, "INFO: category[%ls]", (pContentInfoImpl->GetCategory()).GetPointer());
1393 val = media_info_get_content_name(pMediaInfo, &pTempValue);
1394 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1395 "media_info_get_content_name failed[%d].", val);
1397 if (pTempValue != null)
1399 pStrValue.reset(pTempValue);
1401 pContentInfoImpl->SetContentName(String(pStrValue.get()));
1403 SysSecureLog(NID_CNT, "INFO: contentName[%ls]", (pContentInfoImpl->GetContentName()).GetPointer());
1407 val = media_info_get_description(pMediaInfo, &pTempValue);
1408 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1409 "media_info_get_description failed[%d].", val);
1411 if (pTempValue != null)
1413 pStrValue.reset(pTempValue);
1415 pContentInfoImpl->SetDescription(String(pStrValue.get()));
1417 SysLog(NID_CNT, "INFO: description[%ls]", (pContentInfoImpl->GetDescription()).GetPointer());
1421 val = media_info_get_keyword(pMediaInfo, &pTempValue);
1422 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1423 "media_info_get_keyword failed[%d].", val);
1425 if (pTempValue != null)
1427 pStrValue.reset(pTempValue);
1429 pContentInfoImpl->SetKeyword(String(pStrValue.get()));
1431 SysLog(NID_CNT, "INFO: keyword[%ls]", (pContentInfoImpl->GetKeyword()).GetPointer());
1435 val = media_info_get_location_tag(pMediaInfo, &pTempValue);
1436 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1437 "media_info_get_location_tag failed[%d].", val);
1439 if (pTempValue != null)
1441 pStrValue.reset(pTempValue);
1443 pContentInfoImpl->SetLocationTag(String(pStrValue.get()));
1445 SysSecureLog(NID_CNT, "INFO: locationTag[%ls]", (pContentInfoImpl->GetLocationTag()).GetPointer());
1449 val = media_info_get_provider(pMediaInfo, &pTempValue);
1450 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1451 "media_info_get_provider failed[%d].", val);
1453 if (pTempValue != null)
1455 pStrValue.reset(pTempValue);
1457 pContentInfoImpl->SetProvider(String(pStrValue.get()));
1459 SysLog(NID_CNT, "INFO: provider[%ls]", (pContentInfoImpl->GetProvider()).GetPointer());
1463 val = media_info_get_age_rating(pMediaInfo, &pTempValue);
1464 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1465 "media_info_get_age_rating failed[%d].", val);
1467 if (pTempValue != null)
1469 pStrValue.reset(pTempValue);
1471 pContentInfoImpl->SetRating(String(pStrValue.get()));
1473 SysLog(NID_CNT, "INFO: rating[%ls]", (pContentInfoImpl->GetRating()).GetPointer());
1477 Coordinates coordinates;
1478 double doubleValue = 0;
1479 val = media_info_get_latitude(pMediaInfo, &doubleValue);
1480 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1481 "media_info_get_latitude failed[%d].", val);
1483 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1485 pContentInfoImpl->SetLatitude(doubleValue);
1486 coordinates.SetLatitude(doubleValue);
1488 SysSecureLog(NID_CNT, "INFO: latitude[%f]", pContentInfoImpl->GetLatitude());
1490 val = media_info_get_longitude(pMediaInfo, &doubleValue);
1491 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1492 "media_info_get_longitude failed[%d].", val);
1494 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1496 pContentInfoImpl->SetLongitude(doubleValue);
1497 coordinates.SetLongitude(doubleValue);
1499 SysSecureLog(NID_CNT, "INFO: longitude[%f]", pContentInfoImpl->GetLongitude());
1501 val = media_info_get_altitude(pMediaInfo, &doubleValue);
1502 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1503 "media_info_get_altitude failed[%d].", val);
1505 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1507 pContentInfoImpl->SetAltitude(doubleValue);
1508 coordinates.SetAltitude(doubleValue);
1510 SysLog(NID_CNT, "INFO: altitude[%f]", pContentInfoImpl->GetAltitude());
1512 pContentInfoImpl->SetCoordinates(coordinates);
1514 // contentType and metadata
1515 if (systemType == SYSTEM_TYPE_IMAGE)
1517 r = MakeImageContentInfo(pMediaInfo, pInfoImpl);
1518 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform MakeImageContentInfo operation.");
1520 else if (systemType == SYSTEM_TYPE_SOUND || systemType == SYSTEM_TYPE_MUSIC)
1522 r = MakeAudioContentInfo(pMediaInfo, pInfoImpl);
1523 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform MakeAudioContentInfo operation.");
1525 else if (systemType == MEDIA_CONTENT_TYPE_VIDEO)
1527 r = MakeVideoContentInfo(pMediaInfo, pInfoImpl);
1528 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform MakeVideoContentInfo operation.");
1530 else if (systemType == SYSTEM_TYPE_OTHER)
1532 pContentInfoImpl->SetContentType(CONTENT_TYPE_OTHER);
1533 SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1540 _ContentManagerImpl::MakeImageContentInfo(const media_info_h pMediaInfo, void* pInfoImpl) const
1543 image_meta_h pTempMeta = null;
1544 unique_ptr<image_meta_h, _ImageMetaDeleter> pImageMeta(null);
1546 SysTryReturnResult(NID_CNT, pInfoImpl != null, E_OUT_OF_MEMORY, "pInfoImpl is null.");
1548 _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1549 SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ContentInfoImpl.");
1551 pContentInfoImpl->SetContentType(CONTENT_TYPE_IMAGE);
1552 SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1554 int val = media_info_get_image(pMediaInfo, &pTempMeta);
1555 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1556 "media_info_get_image failed[%d].", val);
1558 pImageMeta.reset(&pTempMeta);
1560 _ImageContentInfoImpl* pImageContentInfoImpl = static_cast< _ImageContentInfoImpl* >(pInfoImpl);
1561 SysTryReturnResult(NID_CNT, pImageContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ImageContentInfoImpl.");
1564 val = image_meta_get_width(*(pImageMeta.get()), &intValue);
1565 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1566 "image_meta_get_width failed[%d].", val);
1568 pImageContentInfoImpl->SetWidth(intValue);
1569 SysLog(NID_CNT, "META: width[%d]", intValue);
1572 val = image_meta_get_height(*(pImageMeta.get()), &intValue);
1573 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1574 "image_meta_get_height failed[%d].", val);
1576 pImageContentInfoImpl->SetHeight(intValue);
1577 SysLog(NID_CNT, "META: height[%d]", intValue);
1580 media_content_orientation_e orientation;
1581 val = image_meta_get_orientation(*(pImageMeta.get()), &orientation);
1582 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1583 "image_meta_get_orientation failed[%d].", val);
1585 pImageContentInfoImpl->SetOrientation(static_cast< ImageOrientationType >(orientation));
1586 SysLog(NID_CNT, "META: orientation[%d]", orientation);
1588 char* pTempValue = null;
1589 unique_ptr<char, CharDeleter> pStrValue(null);
1592 val = media_info_get_display_name(pMediaInfo, &pTempValue);
1593 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1594 "media_info_get_display_name failed[%d].", val);
1596 if (pTempValue != null)
1598 pStrValue.reset(pTempValue);
1602 String strTitle(pStrValue.get());
1604 result r = strTitle.LastIndexOf(L'.', strTitle.GetLength() - 1, pos);
1607 r = strTitle.SubString(0, pos, fileName);
1608 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The title is invalid.");
1612 // Without extension
1614 fileName = strTitle;
1617 pImageContentInfoImpl->SetTitle(fileName);
1619 SysLog(NID_CNT, "META: title[%ls]", fileName.GetPointer());
1626 _ContentManagerImpl::MakeAudioContentInfo(const media_info_h pMediaInfo, void* pInfoImpl) const
1629 audio_meta_h pTempMeta = null;
1630 unique_ptr<audio_meta_h, _AudioMetaDeleter> pAudioMeta(null);
1632 SysTryReturnResult(NID_CNT, pInfoImpl != null, E_OUT_OF_MEMORY, "pInfoImpl is null.");
1634 _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1635 SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ContentInfoImpl.");
1637 pContentInfoImpl->SetContentType(CONTENT_TYPE_AUDIO);
1638 SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1640 int val = media_info_get_audio(pMediaInfo, &pTempMeta);
1641 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1642 "media_info_get_audio failed[%d].", val);
1644 pAudioMeta.reset(&pTempMeta);
1646 _AudioContentInfoImpl* pAudioContentInfoImpl = static_cast< _AudioContentInfoImpl* >(pInfoImpl);
1647 SysTryReturnResult(NID_CNT, pAudioContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _AudioContentInfoImpl.");
1650 val = audio_meta_get_bit_rate(*(pAudioMeta.get()), &intValue);
1651 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1652 "audio_meta_get_bit_rate failed[%d].", val);
1654 pAudioContentInfoImpl->SetBitrate(intValue);
1655 SysLog(NID_CNT, "META: bitrate[%d]", intValue);
1657 char* pTempValue = null;
1658 unique_ptr<char, CharDeleter> pStrValue(null);
1661 val = audio_meta_get_year(*(pAudioMeta.get()), &pTempValue);
1662 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1663 "audio_meta_get_year failed[%d].", val);
1665 if (pTempValue != null)
1667 pStrValue.reset(pTempValue);
1669 String strYear(pStrValue.get());
1671 if (strYear.CompareTo(L"Unknown") != 0)
1673 result r = Integer::Parse(strYear, intValue);
1676 // It is one of the metadata. If error occurs, skip it for other metadata.
1679 SysLog(NID_CNT, "META: releaseYear - invalid data[%ls]", strYear.GetPointer());
1682 pAudioContentInfoImpl->SetReleaseYear(intValue);
1683 SysLog(NID_CNT, "META: releaseYear[%d]", intValue);
1688 val = audio_meta_get_title(*(pAudioMeta.get()), &pTempValue);
1689 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1690 "audio_meta_get_title failed[%d].", val);
1692 if (pTempValue != null)
1694 pStrValue.reset(pTempValue);
1696 pAudioContentInfoImpl->SetTitle(String(pStrValue.get()));
1698 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
1702 val = audio_meta_get_album(*(pAudioMeta.get()), &pTempValue);
1703 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1704 "audio_meta_get_album failed[%d].", val);
1706 if (pTempValue != null)
1708 pStrValue.reset(pTempValue);
1710 pAudioContentInfoImpl->SetAlbumName(String(pStrValue.get()));
1712 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
1716 val = audio_meta_get_artist(*(pAudioMeta.get()), &pTempValue);
1717 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1718 "audio_meta_get_artist failed[%d].", val);
1720 if (pTempValue != null)
1722 pStrValue.reset(pTempValue);
1724 pAudioContentInfoImpl->SetArtist(String(pStrValue.get()));
1726 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
1730 val = audio_meta_get_composer(*(pAudioMeta.get()), &pTempValue);
1731 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1732 "audio_meta_get_composer failed[%d].", val);
1734 if (pTempValue != null)
1736 pStrValue.reset(pTempValue);
1738 pAudioContentInfoImpl->SetComposer(String(pStrValue.get()));
1740 SysLog(NID_CNT, "META: composer[%ls]", (String(pStrValue.get())).GetPointer());
1744 val = audio_meta_get_genre(*(pAudioMeta.get()), &pTempValue);
1745 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1746 "audio_meta_get_genre failed[%d].", val);
1748 if (pTempValue != null)
1750 pStrValue.reset(pTempValue);
1752 pAudioContentInfoImpl->SetGenre(String(pStrValue.get()));
1754 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
1758 val = audio_meta_get_copyright(*(pAudioMeta.get()), &pTempValue);
1759 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1760 "audio_meta_get_copyright failed[%d].", val);
1762 if (pTempValue != null)
1764 pStrValue.reset(pTempValue);
1766 pAudioContentInfoImpl->SetCopyright(String(pStrValue.get()));
1768 SysLog(NID_CNT, "META: copyright[%ls]", (String(pStrValue.get())).GetPointer());
1772 val = audio_meta_get_track_num(*(pAudioMeta.get()), &pTempValue);
1773 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1774 "audio_meta_get_track_num failed[%d].", val);
1776 if (pTempValue != null)
1778 pStrValue.reset(pTempValue);
1780 pAudioContentInfoImpl->SetTrackInfo(String(pStrValue.get()));
1782 SysLog(NID_CNT, "META: trackInfo[%ls]", (String(pStrValue.get())).GetPointer());
1786 val = audio_meta_get_duration(*(pAudioMeta.get()), &intValue);
1787 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1788 "audio_meta_get_duration failed[%d].", val);
1790 pAudioContentInfoImpl->SetDuration(intValue);
1791 SysLog(NID_CNT, "META: duration[%d]", intValue);
1797 _ContentManagerImpl::MakeVideoContentInfo(const media_info_h pMediaInfo, void* pInfoImpl) const
1800 video_meta_h pTempMeta = null;
1801 unique_ptr<video_meta_h, _VideoMetaDeleter> pVideoMeta(null);
1803 SysTryReturnResult(NID_CNT, pInfoImpl != null, E_OUT_OF_MEMORY, "pInfoImpl is null.");
1805 _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1806 SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ContentInfoImpl.");
1808 pContentInfoImpl->SetContentType(CONTENT_TYPE_VIDEO);
1809 SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1811 int val = media_info_get_video(pMediaInfo, &pTempMeta);
1812 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1813 "media_info_get_video failed[%d].", val);
1815 pVideoMeta.reset(&pTempMeta);
1817 _VideoContentInfoImpl* pVideoContentInfoImpl = static_cast< _VideoContentInfoImpl* >(pInfoImpl);
1818 SysTryReturnResult(NID_CNT, pVideoContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _VideoContentInfoImpl.");
1821 val = video_meta_get_width(*(pVideoMeta.get()), &intValue);
1822 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1823 "video_meta_get_width failed[%d].", val);
1825 pVideoContentInfoImpl->SetWidth(intValue);
1826 SysLog(NID_CNT, "META: width[%d]", intValue);
1829 val = video_meta_get_height(*(pVideoMeta.get()), &intValue);
1830 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1831 "video_meta_get_height failed[%d].", val);
1833 pVideoContentInfoImpl->SetHeight(intValue);
1834 SysLog(NID_CNT, "META: height[%d]", intValue);
1836 char* pTempValue = null;
1837 unique_ptr<char, CharDeleter> pStrValue(null);
1840 val = video_meta_get_artist(*(pVideoMeta.get()), &pTempValue);
1841 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1842 "video_meta_get_artist failed[%d].", val);
1844 if (pTempValue != null)
1846 pStrValue.reset(pTempValue);
1848 pVideoContentInfoImpl->SetArtist(String(pStrValue.get()));
1850 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
1854 val = video_meta_get_genre(*(pVideoMeta.get()), &pTempValue);
1855 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1856 "video_meta_get_genre failed[%d].", val);
1858 if (pTempValue != null)
1860 pStrValue.reset(pTempValue);
1862 pVideoContentInfoImpl->SetGenre(String(pStrValue.get()));
1864 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
1868 val = video_meta_get_title(*(pVideoMeta.get()), &pTempValue);
1869 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1870 "video_meta_get_title failed[%d].", val);
1872 if (pTempValue != null)
1874 pStrValue.reset(pTempValue);
1876 pVideoContentInfoImpl->SetTitle(String(pStrValue.get()));
1878 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
1882 val = video_meta_get_album(*(pVideoMeta.get()), &pTempValue);
1883 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1884 "video_meta_get_album failed[%d].", val);
1886 if (pTempValue != null)
1888 pStrValue.reset(pTempValue);
1890 pVideoContentInfoImpl->SetAlbumName(String(pStrValue.get()));
1892 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
1896 val = video_meta_get_duration(*(pVideoMeta.get()), &intValue);
1897 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1898 "video_meta_get_duration failed[%d].", val);
1900 pVideoContentInfoImpl->SetDuration(intValue);
1901 SysLog(NID_CNT, "META: duration[%d]", intValue);
1903 // Get from metadata extractor (framerate, audio bitrate, video bitrate)
1904 VideoMetadata* pVideoMetadata = ContentManagerUtil::GetVideoMetaN(pVideoContentInfoImpl->GetContentPath());
1905 result r = GetLastResult();
1906 SysTryReturnResult(NID_CNT, pVideoMetadata != null, r, "GetVideoMetadata() failed.");
1908 pVideoContentInfoImpl->SetFramerate(pVideoMetadata->GetFramerate());
1909 pVideoContentInfoImpl->SetAudioBitrate(pVideoMetadata->GetAudioBitrate());
1910 pVideoContentInfoImpl->SetVideoBitrate(pVideoMetadata->GetVideoBitrate());
1916 _ContentManagerImpl::VerifyHomeFilePathCompatibility(const String& contentPath) const
1918 if (!_AppInfo::IsOspCompat())
1920 if (contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0))
1922 SysLogException(NID_CNT, E_INVALID_ARG,
1923 "[E_INVALID_ARG] /Home/ or /HomeExt/ is not supported from Tizen 2.0.");
1926 if (!(contentPath.StartsWith(App::App::GetInstance()->GetAppRootPath(), 0) ||
1927 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
1929 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] The path is not supported.");
1935 SysTryReturn(NID_CNT, contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0),
1936 false, E_INVALID_ARG, "[E_INVALID_ARG] The path should start with /Home or /HomeExt.");
1943 _ContentManagerImpl::VerifyMediaFilePathCompatibility(const String& contentPath, bool checkVersion) const
1947 result r = E_SUCCESS;
1949 if (!_AppInfo::IsOspCompat())
1951 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0) || contentPath.StartsWith(OSP_MEDIA_MMC, 0))
1953 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] /Media or /Storagecard/Media is not supported.");
1956 if (!(contentPath.StartsWith(Environment::GetMediaPath(), 0) ||
1957 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
1959 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] This path is not supported.");
1965 String tempPath(contentPath);
1968 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0))
1970 r = tempPath.Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
1971 SysTryReturn(NID_CNT, !IsFailed(r), false, E_INVALID_ARG, "[E_INVALID_ARG] Replace failed.");
1973 else if (contentPath.StartsWith(OSP_MEDIA_MMC, 0))
1975 r = tempPath.Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
1976 SysTryReturn(NID_CNT, !IsFailed(r), false, E_INVALID_ARG, "[E_INVALID_ARG] Replace failed.");
1980 // CreateContent(const ByteBuffer&, ...) and CreateContent (const Sring&, ...) can receive old path like /Media/.
1981 // but CreateContent(const ContentInfo&) always receive new path like /opt/media/ because ContentInfo class convert the path from /Media/ to /opt/media.
1984 SysLogException(NID_CNT, E_INVALID_ARG,
1985 "[E_INVALID_ARG] The path should start with /Home, /Media, or /Storagecard/Media.");
1995 _ContentManagerImpl::SetListener(IContentUpdateEventListener* pListener)
1997 __pListener = pListener;
2000 IContentUpdateEventListener*
2001 _ContentManagerImpl::GetListener(void) const
2007 _ContentManagerImpl::ConvertErrorToResult(result res) const
2009 result r = E_SUCCESS;