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 SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(pInfoImpl->GetContentPath(), true), UuId::GetInvalidUuId(),
303 E_INVALID_ARG, "[E_INVALID_ARG] The contentPath is not compatible.");
304 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(pInfoImpl->GetContentPath()), UuId::GetInvalidUuId(), E_FILE_NOT_FOUND,
305 "[E_FILE_NOT_FOUND] The file corresponding to contentInfo could not be found.");
306 SysTryReturn(NID_CNT, pInfoImpl->GetContentId() == UuId::GetInvalidUuId(), UuId::GetInvalidUuId(),
307 E_INVALID_ARG, "[E_INVALID_ARG] The contentId is not empty.");
309 // Compare the type of input parameter and system
310 ContentType inputType = pInfoImpl->GetContentType();
311 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(pInfoImpl->GetContentPath(), true);
315 if (inputType != sysType)
317 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
319 SysLogException(NID_CNT, E_INVALID_ARG,
320 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
321 return UuId::GetInvalidUuId();
325 // Save data to database with contentPath.
326 unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(contentInfo.GetContentPath()));
327 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
328 "[E_OUT_OF_MEMORY] The memory is insufficient.");
330 media_info_h tempMediaInfo = null;
331 unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
333 int val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
334 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
335 "The registration to database failed[%d].", val);
337 pMediaInfo.reset(tempMediaInfo);
339 ContentId contentId = SaveDataToDatabase(pMediaInfo.get(), pInfoImpl);
340 result r = GetLastResult();
341 SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
342 "[%s] The registration to database failed.", GetErrorMessage(r));
347 // There are two steps(insert and update) for content registration.
348 // If the update failed after inserting, the inserted data SHOULD be deleted from here.
349 val = media_info_delete_from_db(pStr.get());
350 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
352 return UuId::GetInvalidUuId();
356 _ContentManagerImpl::CreateContent(const ByteBuffer& byteBuffer, const String& destinationPath,
357 const ContentInfo* pContentInfo)
361 // Check parameters(for length)
362 SysTryReturn(NID_CNT, byteBuffer.GetRemaining() > 0, UuId::GetInvalidUuId(), E_INVALID_ARG,
363 "[E_INVALID_ARG] byteBuffer is invalid.");
365 // Check parameters(for path compatibility)
366 SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(destinationPath, false), UuId::GetInvalidUuId(),
367 E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", destinationPath.GetPointer());
368 SysTryReturn(NID_CNT, !_FileImpl::IsFileExist(destinationPath), UuId::GetInvalidUuId(), E_FILE_ALREADY_EXIST,
369 "[E_FILE_ALREADY_EXIST] The specified file already exists.");
371 // Create a file with bytebuffer
372 unique_ptr<File> pFile(new (nothrow) File);
373 SysTryReturn(NID_CNT, pFile != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
374 "[E_OUT_OF_MEMORY] The memory is insufficient.");
376 result r = pFile->Construct(destinationPath, L"w+");
377 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r,
378 "[%s] The destination file can not be created.", GetErrorMessage(r));
380 _FileImpl* pFileImpl = _FileImpl::GetInstance(*pFile);
381 SysTryReturn(NID_CNT, pFileImpl != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
382 "[E_OUT_OF_MEMORY] The memory is insufficient.");
384 r = pFileImpl->Write(byteBuffer);
385 SysTryReturn(NID_CNT, !(IsFailed(r)), UuId::GetInvalidUuId(), r,
386 "[%s] The data can not be written in the destination file.", GetErrorMessage(r));
388 // for release file pointer
393 _ContentInfoImpl* pInfoImpl = null;
394 _ImageContentInfoImpl imageContentInfoImpl;
395 _AudioContentInfoImpl audioContentInfoImpl;
396 _VideoContentInfoImpl videoContentInfoImpl;
397 _OtherContentInfoImpl otherContentInfoImpl;
398 media_info_h tempMediaInfo = null;
399 unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
400 unique_ptr<char[]> pStr(null);
402 if (pContentInfo != null)
404 pInfoImpl = const_cast< _ContentInfoImpl* >(_ContentInfoImpl::GetInstance(*pContentInfo));
405 SysTryCatch(NID_CNT, pInfoImpl != null, , E_INVALID_ARG,
406 "[E_INVALID_ARG] Invalid argument is used. ContentInfo is invalid.");
408 SysTryCatch(NID_CNT, pInfoImpl->GetContentId() == UuId::GetInvalidUuId(), , E_INVALID_ARG,
409 "[E_INVALID_ARG] The content already exists in database.");
411 // Compare the type of input parameter and system
412 // CheckContentType() need actual file. so it should be checked after creating the file.
413 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
414 ContentType inputType = pInfoImpl->GetContentType();
418 if (inputType != sysType)
420 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
422 SysLogException(NID_CNT, E_INVALID_ARG,
423 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
428 // Sets the content path
429 pInfoImpl->SetContentPath(destinationPath);
433 ContentType contentType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
437 // Set the content path
438 if (contentType == CONTENT_TYPE_IMAGE)
440 r = imageContentInfoImpl.Construct(&destinationPath);
441 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
442 "[E_OUT_OF_MEMORY] Failed to perform Construct for ImageContentInfoImpl.");
444 imageContentInfoImpl.SetContentPath(destinationPath);
445 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&imageContentInfoImpl);
447 else if (contentType == CONTENT_TYPE_AUDIO)
449 r = audioContentInfoImpl.Construct(&destinationPath);
450 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
451 "[E_OUT_OF_MEMORY] Failed to perform Construct for AudioContentInfoImpl.");
453 audioContentInfoImpl.SetContentPath(destinationPath);
454 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&audioContentInfoImpl);
456 else if (contentType == CONTENT_TYPE_VIDEO)
458 r = videoContentInfoImpl.Construct(&destinationPath);
459 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
460 "[E_OUT_OF_MEMORY] Failed to perform Construct for VideoContentInfoImpl.");
462 videoContentInfoImpl.SetContentPath(destinationPath);
463 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&videoContentInfoImpl);
467 r = otherContentInfoImpl.Construct(&destinationPath);
468 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
469 "[E_OUT_OF_MEMORY] Failed to perform Construct for OtherContentInfoImpl.");
471 otherContentInfoImpl.SetContentPath(destinationPath);
472 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&otherContentInfoImpl);
476 // Register the content to database directly.
477 pStr.reset(_StringConverter::CopyToCharArrayN(destinationPath));
478 SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
480 val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
481 SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
482 "media_info_insert_to_db failed[%d].", val);
484 pMediaInfo.reset(tempMediaInfo);
486 contentId = SaveDataToDatabase(pMediaInfo.get(), pInfoImpl);
488 SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
489 "[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
494 result saveResult = GetLastResult();
496 // If the destination file is made by this method, it should be deleted when error occurs.
497 r = _FileImpl::Remove(destinationPath);
498 SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
500 if (pMediaInfo != null)
502 val = media_info_delete_from_db(pStr.get());
503 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
506 SetLastResult(saveResult);
507 return UuId::GetInvalidUuId();
511 _ContentManagerImpl::CreateContent(const String& sourcePath, const String& destinationPath, bool deleteSource,
512 const ContentInfo* pContentInfo)
516 // Check parameters(for type)
517 SysTryReturn(NID_CNT, _FileImpl::GetFileExtension(sourcePath) == _FileImpl::GetFileExtension(destinationPath),
518 UuId::GetInvalidUuId(), E_INVALID_ARG, "[E_INVALID_ARG] There is a mismatch between the type of source and dest path.");
520 // Check parameters(for path compatibility)
521 SysTryReturn(NID_CNT, VerifyHomeFilePathCompatibility(sourcePath), UuId::GetInvalidUuId(), E_INVALID_ARG,
522 "[E_INVALID_ARG] %ls is not compatible.", sourcePath.GetPointer());
523 SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(destinationPath, false), UuId::GetInvalidUuId(),
524 E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", destinationPath.GetPointer());
526 result r = E_SUCCESS;
529 if (deleteSource) // move
531 r = _FileImpl::Move(sourcePath, destinationPath);
532 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Moving the file failed.", GetErrorMessage(r));
536 r = _FileImpl::Copy(sourcePath, destinationPath, true);
537 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Copying the file failed.", GetErrorMessage(r));
544 _ContentInfoImpl* pInfoImpl = null;
545 _ImageContentInfoImpl imageContentInfoImpl;
546 _AudioContentInfoImpl audioContentInfoImpl;
547 _VideoContentInfoImpl videoContentInfoImpl;
548 _OtherContentInfoImpl otherContentInfoImpl;
549 media_info_h tempMediaInfo = null;
550 unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
551 unique_ptr<char[]> pStr(null);
553 if (pContentInfo != null)
555 pInfoImpl = const_cast< _ContentInfoImpl* >(_ContentInfoImpl::GetInstance(*pContentInfo));
556 SysTryCatch(NID_CNT, pInfoImpl != null, , E_INVALID_ARG,
557 "[E_INVALID_ARG] Invalid argument is used. ContentInfo is invalid.");
559 SysTryCatch(NID_CNT, pInfoImpl->GetContentId() == UuId::GetInvalidUuId(), , E_INVALID_ARG,
560 "[E_INVALID_ARG] The content already exists in database.");
562 // Compare the type of input parameter and system
563 // CheckContentType() need actual file. so it should be checked after creating the file.
564 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
565 ContentType inputType = pInfoImpl->GetContentType();
569 if (inputType != sysType)
571 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
573 SysLogException(NID_CNT, E_INVALID_ARG,
574 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
579 // Set the content path
580 pInfoImpl->SetContentPath(destinationPath);
584 ContentType contentType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
588 // Set the content path
589 if (contentType == CONTENT_TYPE_IMAGE)
591 r = imageContentInfoImpl.Construct(&destinationPath);
592 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
593 "[E_OUT_OF_MEMORY] Failed to perform Construct for ImageContentInfoImpl.");
595 imageContentInfoImpl.SetContentPath(destinationPath);
596 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&imageContentInfoImpl);
598 else if (contentType == CONTENT_TYPE_AUDIO)
600 r = audioContentInfoImpl.Construct(&destinationPath);
601 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
602 "[E_OUT_OF_MEMORY] Failed to perform Construct for AudioContentInfoImpl.");
604 audioContentInfoImpl.SetContentPath(destinationPath);
605 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&audioContentInfoImpl);
607 else if (contentType == CONTENT_TYPE_VIDEO)
609 r = videoContentInfoImpl.Construct(&destinationPath);
610 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
611 "[E_OUT_OF_MEMORY] Failed to perform Construct for VideoContentInfoImpl.");
613 videoContentInfoImpl.SetContentPath(destinationPath);
614 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&videoContentInfoImpl);
618 r = otherContentInfoImpl.Construct(&destinationPath);
619 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
620 "[E_OUT_OF_MEMORY] Failed to perform Construct for OtherContentInfoImpl.");
622 otherContentInfoImpl.SetContentPath(destinationPath);
623 pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&otherContentInfoImpl);
627 pStr.reset(_StringConverter::CopyToCharArrayN(destinationPath));
628 SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
630 val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
631 SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
632 "media_info_insert_to_db failed[%d].", val);
634 pMediaInfo.reset(tempMediaInfo);
636 contentId = SaveDataToDatabase(pMediaInfo.get(), pInfoImpl);
638 SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
639 "[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
644 result saveResult = GetLastResult();
648 r = _FileImpl::Remove(destinationPath);
649 SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
653 r = _FileImpl::Move(destinationPath, sourcePath);
654 SysLog(NID_CNT, "Move[%s].", GetErrorMessage(r));
657 if (pMediaInfo != null)
659 val = media_info_delete_from_db(pStr.get());
660 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
663 SetLastResult(saveResult);
664 return UuId::GetInvalidUuId();
668 _ContentManagerImpl::GetContentInfoN(const ContentId& contentId) const
672 SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), null, E_INVALID_ARG,
673 "[E_INVALID_ARG] The contentId is invalid.");
675 unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(contentId.ToString()));
676 SysTryReturn(NID_CNT, pStr != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
678 media_info_h tempMediaInfo = null;
679 unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
680 int val = media_info_get_media_from_db(pStr.get(), &tempMediaInfo);
681 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
682 "media_info_get_media_from_db failed[%d].", val);
684 pMediaInfo.reset(tempMediaInfo);
686 media_content_type_e systemType = MEDIA_CONTENT_TYPE_IMAGE;
687 val = media_info_get_media_type(pMediaInfo.get(), &systemType);
688 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
689 "media_info_get_media_type failed[%d].", val);
691 char* pTempFilePath = null;
692 val = media_info_get_file_path(pMediaInfo.get(), &pTempFilePath);
693 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
694 "media_info_get_file_path failed[%d].", val);
696 unique_ptr<char, CharDeleter> pFilePath(pTempFilePath);
697 String contentPath(pFilePath.get());
699 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), null, E_FILE_NOT_FOUND,
700 "[E_FILE_NOT_FOUND] The file corresponding to contentId could not be found.");
702 result r = E_SUCCESS;
704 if (systemType == SYSTEM_TYPE_IMAGE)
706 unique_ptr< ImageContentInfo > pImageContentInfo(new (nothrow) ImageContentInfo);
707 SysTryReturn(NID_CNT, pImageContentInfo != null, null, E_OUT_OF_MEMORY,
708 "[E_OUT_OF_MEMORY] The memory is insufficient.");
710 r = pImageContentInfo->Construct(&contentPath);
711 r = ConvertErrorToResult(r);
712 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
713 "[%s] Failed to perform Construct operation to ImageContentInfo.", GetErrorMessage(r));
715 _ImageContentInfoImpl* pImageContentInfoImpl = _ImageContentInfoImpl::GetInstance(*(pImageContentInfo.get()));
716 SysTryReturn(NID_CNT, pImageContentInfoImpl != null, null, E_OUT_OF_MEMORY,
717 "[E_OUT_OF_MEMORY] The memory is insufficient.");
719 r = MakeContentInfo(pMediaInfo.get(), systemType, pImageContentInfoImpl);
720 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
722 return pImageContentInfo.release();
724 else if (systemType == SYSTEM_TYPE_SOUND || systemType == SYSTEM_TYPE_MUSIC)
726 unique_ptr< AudioContentInfo > pAudioContentInfo(new (nothrow) AudioContentInfo);
727 SysTryReturn(NID_CNT, pAudioContentInfo != null, null, E_OUT_OF_MEMORY,
728 "[E_OUT_OF_MEMORY] The memory is insufficient.");
730 r = pAudioContentInfo->Construct(&contentPath);
731 r = ConvertErrorToResult(r);
732 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
733 "[%s] Failed to perform Construct operation to AudioContentInfo.", GetErrorMessage(r));
735 _AudioContentInfoImpl* pAudioContentInfoImpl = _AudioContentInfoImpl::GetInstance(*(pAudioContentInfo.get()));
736 SysTryReturn(NID_CNT, pAudioContentInfoImpl != null, null, E_OUT_OF_MEMORY,
737 "[E_OUT_OF_MEMORY] The memory is insufficient.");
739 r = MakeContentInfo(pMediaInfo.get(), systemType, pAudioContentInfoImpl);
740 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
742 return pAudioContentInfo.release();
744 else if (systemType == SYSTEM_TYPE_VIDEO)
746 unique_ptr< VideoContentInfo > pVideoContentInfo(new (nothrow) VideoContentInfo);
747 SysTryReturn(NID_CNT, pVideoContentInfo != null, null, E_OUT_OF_MEMORY,
748 "[E_OUT_OF_MEMORY] The memory is insufficient.");
750 r = pVideoContentInfo->Construct(&contentPath);
751 r = ConvertErrorToResult(r);
752 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
753 "[%s] Failed to perform Construct operation to VideoContentInfo.", GetErrorMessage(r));
755 _VideoContentInfoImpl* pVideoContentInfoImpl = _VideoContentInfoImpl::GetInstance(*(pVideoContentInfo.get()));
756 SysTryReturn(NID_CNT, pVideoContentInfoImpl != null, null, E_OUT_OF_MEMORY,
757 "[E_OUT_OF_MEMORY] The memory is insufficient.");
759 r = MakeContentInfo(pMediaInfo.get(), systemType, pVideoContentInfoImpl);
760 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
762 return pVideoContentInfo.release();
764 else if (systemType == SYSTEM_TYPE_OTHER)
766 unique_ptr< OtherContentInfo > pOtherContentInfo(new (nothrow) OtherContentInfo);
767 SysTryReturn(NID_CNT, pOtherContentInfo != null, null, E_OUT_OF_MEMORY,
768 "[E_OUT_OF_MEMORY] The memory is insufficient.");
770 r = pOtherContentInfo->Construct(&contentPath);
771 r = ConvertErrorToResult(r);
772 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
773 "[%s] Failed to perform Construct operation to OtherContentInfo.", GetErrorMessage(r));
775 _OtherContentInfoImpl* pOtherContentInfoImpl = _OtherContentInfoImpl::GetInstance(*(pOtherContentInfo.get()));
776 SysTryReturn(NID_CNT, pOtherContentInfoImpl != null, null, E_OUT_OF_MEMORY,
777 "[E_OUT_OF_MEMORY] The memory is insufficient.");
779 r = MakeContentInfo(pMediaInfo.get(), systemType, pOtherContentInfoImpl);
780 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
782 return pOtherContentInfo.release();
786 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] Unsupported type");
792 _ContentManagerImpl::UpdateContent(const ContentInfo& contentInfo)
794 ContentId contentId = contentInfo.GetContentId();
795 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, "The content id is invalid.");
796 SysTryReturnResult(NID_CNT, _FileImpl::IsFileExist(contentInfo.GetContentPath()), E_FILE_NOT_FOUND,
797 "The file corresponding to contentInfo could not be found.");
799 const _ContentInfoImpl* pInfoImpl = _ContentInfoImpl::GetInstance(contentInfo);
800 SysTryReturnResult(NID_CNT, pInfoImpl != null, E_INVALID_ARG, "Invalid argument is used. ContentInfo is invalid.");
802 result r = UpdateDataToDatabase(pInfoImpl);
803 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "UpdateDataToDatabase failed.");
809 _ContentManagerImpl::DeleteContent(const ContentId& contentId)
811 SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, "The contentId is invalid.");
813 unique_ptr<char[]> pContentId(_StringConverter::CopyToCharArrayN(contentId.ToString()));
814 SysTryReturnResult(NID_CNT, pContentId != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
816 result r = E_SUCCESS;
818 media_info_h tempMediaInfo = null;
819 unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
821 val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
822 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
823 "media_info_get_media_from_db failed[%d].", val);
825 pMediaInfo.reset(tempMediaInfo);
827 char* pTempPath = null;
829 val = media_info_get_file_path(pMediaInfo.get(), &pTempPath);
830 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
831 "media_info_get_file_path failed[%d].", val);
833 unique_ptr<char, CharDeleter> pContentPath(pTempPath);
835 String contentPath = String(pContentPath.get());
836 SysTryReturnResult(NID_CNT, _FileImpl::IsFileExist(contentPath), E_FILE_NOT_FOUND,
837 "The file corresponding to contentId could not be found.");
839 val = media_info_delete_from_db(pContentId.get());
840 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
841 "media_info_delete_From_db failed[%d].", val);
843 r = _FileImpl::Remove(contentPath);
844 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The file is not deleted.");
850 _ContentManagerImpl::AddContentUpdateEventListener(IContentUpdateEventListener& listener)
852 SysTryReturnResult(NID_CNT, GetListener() == null, E_OBJ_ALREADY_EXIST, "IContentUpdateEventListener is already set.");
854 SetListener(&listener);
856 int val = media_content_set_db_updated_cb(OnContentUpdateCompleted, this);
857 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "media_content_set_db_updated_cb failed[%d].", val);
863 _ContentManagerImpl::RemoveContentUpdateEventListener(IContentUpdateEventListener& listener)
865 SysTryReturnResult(NID_CNT, GetListener() == &listener, E_OBJ_NOT_FOUND, "The input listener is not equal to the registered listener.");
867 int val = media_content_unset_db_updated_cb();
868 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "media_content_unset_db_updated_cb failed[%d].", val);
876 _ContentManagerImpl::ScanFile(const Tizen::Base::String& contentPath)
878 SysSecureLog(NID_CNT, "The scan path is [%ls].", contentPath.GetPointer());
880 unique_ptr<char[]> pContentPath(_StringConverter::CopyToCharArrayN(contentPath));
881 SysTryReturnResult(NID_CNT, pContentPath, E_SYSTEM, "pContentPath is NULL.");
883 int val = media_content_connect();
884 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The connection failed[%d].", val);
886 val = media_content_scan_file(pContentPath.get());
887 result r = ConvertError(val);
888 SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , r, "[%s] media_content_scan_file failed[%d].", GetErrorMessage(r), val);
890 val = media_content_disconnect();
891 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The disconnection failed[%d].", val);
896 val = media_content_disconnect();
897 SysTryLog(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, "The disconnection failed[%d].", val);
903 _ContentManagerImpl::ScanDirectory(const Tizen::Base::String& directoryPath, bool recursive, IContentScanListener* pListener, RequestId& reqId)
905 static RequestId requestId = 0;
907 SysLog(NID_CNT, "The scan path is [%ls].", directoryPath.GetPointer());
909 unique_ptr<char[]> pDirPath(_StringConverter::CopyToCharArrayN(directoryPath));
910 SysTryReturnResult(NID_CNT, pDirPath, E_SYSTEM, "pDirPath is NULL.");
912 int val = media_content_connect();
913 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The connection failed[%d].", val);
915 unique_ptr< _ScanResult > pScanResult(new (nothrow) _ScanResult);
916 SysTryReturnResult(NID_CNT, pScanResult != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
920 pScanResult->scanPath = directoryPath;
921 pScanResult->pScanListener = pListener;
922 pScanResult->requestId = reqId;
924 val = media_content_scan_folder(pDirPath.get(), recursive, OnScanCompleted, pScanResult.release());
925 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val), "media_content_scan_folder failed[%d].", val);
931 _ContentManagerImpl::UpdateDataToDatabase(const _ContentInfoImpl* pContentInfoImpl) const
933 SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_INVALID_ARG, "pContentInfoImpl is null.");
935 media_info_h tempMediaInfo = null;
936 unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
937 unique_ptr<char[]> pContentId(_StringConverter::CopyToCharArrayN((pContentInfoImpl->GetContentId()).ToString()));
938 SysTryReturnResult(NID_CNT, pContentId != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
940 int val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
941 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
942 "media_info_get_media_from_db failed[%d].", val);
944 pMediaInfo.reset(tempMediaInfo);
946 result r = E_SUCCESS;
947 unique_ptr<char[]> pValue(null);
949 if (!pContentInfoImpl->GetAuthor().IsEmpty())
951 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetAuthor()));
952 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
954 val = media_info_set_author(pMediaInfo.get(), pValue.get());
955 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
956 "media_info_set_author failed[%d].", val);
958 if (!pContentInfoImpl->GetCategory().IsEmpty())
960 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetCategory()));
961 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
963 val = media_info_set_category(pMediaInfo.get(), pValue.get());
964 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
965 "media_info_set_category failed[%d].", val);
967 if (!pContentInfoImpl->GetContentName().IsEmpty())
969 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetContentName()));
970 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
972 val = media_info_set_content_name(pMediaInfo.get(), pValue.get());
973 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
974 "media_info_set_content_name failed[%d].", val);
976 if (!pContentInfoImpl->GetDescription().IsEmpty())
978 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetDescription()));
979 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
981 val = media_info_set_description(pMediaInfo.get(), pValue.get());
982 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
983 "media_info_set_description failed[%d].", val);
985 if (!pContentInfoImpl->GetKeyword().IsEmpty())
987 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetKeyword()));
988 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
990 val = media_info_set_keyword(pMediaInfo.get(), pValue.get());
991 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
992 "media_info_set_keyword failed[%d].", val);
994 if (!pContentInfoImpl->GetLocationTag().IsEmpty())
996 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetLocationTag()));
997 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
999 val = media_info_set_location_tag(pMediaInfo.get(), pValue.get());
1000 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1001 "media_info_set_location_tag failed[%d].", val);
1003 if (!pContentInfoImpl->GetProvider().IsEmpty())
1005 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetProvider()));
1006 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1008 val = media_info_set_provider(pMediaInfo.get(), pValue.get());
1009 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1010 "media_info_set_provider failed[%d].", val);
1012 if (!pContentInfoImpl->GetRating().IsEmpty())
1014 pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetRating()));
1015 SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1017 val = media_info_set_age_rating(pMediaInfo.get(), pValue.get());
1018 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1019 "media_info_set_age_rating failed[%d].", val);
1021 if (Double::Compare(pContentInfoImpl->GetLatitude(), DEFAULT_COORDINATE) != 0 &&
1022 Double::Compare(pContentInfoImpl->GetLongitude(), DEFAULT_COORDINATE) != 0)
1024 val = media_info_set_latitude(pMediaInfo.get(), pContentInfoImpl->GetLatitude());
1025 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1026 "media_info_set_latitude failed[%d].", val);
1028 val = media_info_set_longitude(pMediaInfo.get(), pContentInfoImpl->GetLongitude());
1029 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1030 "media_info_set_longitude failed[%d].", val);
1032 if (Double::Compare(pContentInfoImpl->GetAltitude(), DEFAULT_COORDINATE) != 0)
1034 val = media_info_set_altitude(pMediaInfo.get(), pContentInfoImpl->GetAltitude());
1035 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1036 "media_info_set_altitude failed[%d].", val);
1040 val = media_info_update_to_db(pMediaInfo.get());
1041 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1042 "media_info_update_to_db failed[%d].", val);
1048 _ContentManagerImpl::SaveDataToDatabase(const media_info_h pMediaInfo,
1049 _ContentInfoImpl* pContentInfoImpl) const
1053 SysTryReturn(NID_CNT, pContentInfoImpl != null, UuId::GetInvalidUuId(), E_INVALID_ARG,
1054 "[E_INVALID_ARG] Invalid argument is used. ContentInfo is invalid.");
1056 String mimeType(L"");
1057 String extension = _FileImpl::GetFileExtension(pContentInfoImpl->GetContentPath());
1058 result r = GetLastResult();
1063 SysLog(NID_CNT, "[%s] Failed to perform GetFileExtension operation.", GetErrorMessage(r));
1065 unique_ptr<char[]> pTempPath(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetContentPath()));
1066 SysTryReturn(NID_CNT, pTempPath != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1067 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1069 char tempType[255] = {0, };
1070 int ret = aul_get_mime_from_file(pTempPath.get(), tempType, sizeof(tempType));
1071 SysTryReturn(NID_CNT, ret == AUL_R_OK, UuId::GetInvalidUuId(), E_INVALID_ARG,
1072 "[E_INVALID_ARG] Failed to perform aul_get_mime_from_file operation.");
1074 r = mimeType.Append(tempType);
1075 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1076 "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
1080 // If the content format is JPG and it has GPS data, it will be saved in database automatically.
1081 if (extension == L"jpg" || extension == L"jpeg" || extension == L"JPG" || extension == L"JPEG" || mimeType.Contains(L"jpeg"))
1083 SysLog(NID_CNT, "The format of content is jpg.");
1085 ImageMetadata* pImageMetadata = _ContentManagerUtilImpl::GetImageMetaN(pContentInfoImpl->GetContentPath(), true);
1086 if (pImageMetadata != null)
1088 pContentInfoImpl->SetLatitude(pImageMetadata->GetLatitude());
1089 pContentInfoImpl->SetLongitude(pImageMetadata->GetLongitude());
1091 delete pImageMetadata;
1098 unique_ptr<char[]> pStr(null);
1100 if (pContentInfoImpl->GetAuthor() != null)
1102 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetAuthor()));
1103 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1104 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1106 val = media_info_set_author(pMediaInfo, pStr.get());
1107 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1108 "media_info_set_author failed[%d].", val);
1110 if (pContentInfoImpl->GetCategory() != null)
1112 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetCategory()));
1113 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1114 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1116 val = media_info_set_category(pMediaInfo, pStr.get());
1117 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1118 "media_info_set_category failed[%d].", val);
1120 if (pContentInfoImpl->GetContentName() != null)
1122 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetContentName()));
1123 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1124 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1126 val = media_info_set_content_name(pMediaInfo, pStr.get());
1127 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1128 "media_info_set_content_name failed[%d].", val);
1130 if (pContentInfoImpl->GetDescription() != null)
1132 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetDescription()));
1133 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1134 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1136 val = media_info_set_description(pMediaInfo, pStr.get());
1137 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1138 "media_info_set_description failed[%d].", val);
1140 if (pContentInfoImpl->GetKeyword() != null)
1142 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetKeyword()));
1143 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1144 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1146 val = media_info_set_keyword(pMediaInfo, pStr.get());
1147 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1148 "media_info_set_keyword failed[%d].", val);
1150 if (pContentInfoImpl->GetLocationTag() != null)
1152 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetLocationTag()));
1153 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1154 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1156 val = media_info_set_location_tag(pMediaInfo, pStr.get());
1157 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1158 "media_info_set_location_tag failed[%d].", val);
1160 if (pContentInfoImpl->GetProvider() != null)
1162 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetProvider()));
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_provider(pMediaInfo, pStr.get());
1167 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1168 "media_info_set_provider failed[%d].", val);
1170 if (pContentInfoImpl->GetRating() != null)
1172 pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetRating()));
1173 SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1174 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1176 val = media_info_set_age_rating(pMediaInfo, pStr.get());
1177 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1178 "media_info_set_age_rating failed[%d].", val);
1180 if (Double::Compare(pContentInfoImpl->GetLatitude(), DEFAULT_COORDINATE) != 0 &&
1181 Double::Compare(pContentInfoImpl->GetLongitude(), DEFAULT_COORDINATE) != 0)
1183 val = media_info_set_latitude(pMediaInfo, pContentInfoImpl->GetLatitude());
1184 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1185 "media_info_set_latitude failed[%d].", val);
1187 val = media_info_set_longitude(pMediaInfo, pContentInfoImpl->GetLongitude());
1188 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1189 "media_info_set_longitude failed[%d].", val);
1191 if (Double::Compare(pContentInfoImpl->GetAltitude(), DEFAULT_COORDINATE) != 0)
1193 val = media_info_set_altitude(pMediaInfo, pContentInfoImpl->GetAltitude());
1194 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1195 "media_info_set_altitude failed[%d].", val);
1199 val = media_info_update_to_db(pMediaInfo);
1200 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1201 "media_info_update_to_db failed[%d].", val);
1203 char* pTempMediaId = null;
1204 unique_ptr<char, CharDeleter> pMediaId(null);
1206 val = media_info_get_media_id(pMediaInfo, &pTempMediaId);
1207 if (pTempMediaId != null)
1209 pMediaId.reset(pTempMediaId);
1213 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1214 "media_info_get_media_id failed[%d].", val);
1217 String tempContentId(pMediaId.get());
1218 ContentId contentId;
1220 r = UuId::Parse(tempContentId, contentId);
1221 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_INVALID_ARG,
1222 "[E_INVALID_ARG] UuId::Parse failed.");
1228 _ContentManagerImpl::MakeContentInfo(const media_info_h pMediaInfo, int systemType, void* pInfoImpl) const
1230 SysTryReturnResult(NID_CNT, pMediaInfo != null && pInfoImpl != null, E_INVALID_ARG,
1231 "The specified parameter is invalid.");
1233 _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1235 result r = E_SUCCESS;
1236 char* pTempValue = null;
1237 unique_ptr<char, CharDeleter> pStrValue(null);
1240 int val = media_info_get_media_id(pMediaInfo, &pTempValue);
1241 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1242 "media_info_get_media_id failed[%d].", val);
1244 if (pTempValue != null)
1246 pStrValue.reset(pTempValue);
1248 String strContentId(pStrValue.get());
1249 ContentId contentId;
1251 r = UuId::Parse(strContentId, contentId);
1252 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The content id can not be parsed.");
1254 pContentInfoImpl->SetContentId(contentId);
1256 SysLog(NID_CNT, "INFO: contentId[%ls]", strContentId.GetPointer());
1260 val = media_info_get_file_path(pMediaInfo, &pTempValue);
1261 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1262 "media_info_get_file_path failed[%d].", val);
1264 if (pTempValue != null)
1266 pStrValue.reset(pTempValue);
1268 String strFilePath(pStrValue.get());
1270 // If the api version is 2.0, the content path has to be changed.
1271 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
1273 if (strFilePath.StartsWith(Environment::GetMediaPath(), 0))
1275 r = strFilePath.Replace(Environment::GetMediaPath(), OSP_MEDIA_PHONE);
1276 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The content path is not changed.");
1278 else if (strFilePath.StartsWith(Environment::GetExternalStoragePath(), 0))
1280 r = strFilePath.Replace(Environment::GetExternalStoragePath(), OSP_MEDIA_MMC);
1281 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Replace failed.");
1285 SysLogException(NID_CNT, E_INVALID_ARG,
1286 "[E_INVALID_ARG] The content path is not supported.");
1287 return E_INVALID_ARG;
1291 pContentInfoImpl->SetContentPath(strFilePath);
1293 SysSecureLog(NID_CNT, "INFO: contentPath[%ls]", strFilePath.GetPointer());
1297 val = media_info_get_mime_type(pMediaInfo, &pTempValue);
1298 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1299 "media_info_get_mime_type failed[%d].", val);
1301 if (pTempValue != null)
1303 pStrValue.reset(pTempValue);
1305 pContentInfoImpl->SetMimeType(pStrValue.get());
1307 SysLog(NID_CNT, "INFO: mimeType[%ls]", (pContentInfoImpl->GetMimeType()).GetPointer());
1311 unsigned long long longlongValue = 0;
1312 val = media_info_get_size(pMediaInfo, &longlongValue);
1313 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1314 "media_info_get_size failed[%d].", val);
1315 pContentInfoImpl->SetContentSize(longlongValue);
1316 SysLog(NID_CNT, "INFO: contentSize[%llu]", longlongValue);
1319 media_content_storage_e storageType;
1320 val = media_info_get_storage_type(pMediaInfo, &storageType);
1321 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1322 "media_info_get_storage_type failed[%d].", val);
1323 pContentInfoImpl->SetStorageType(storageType);
1324 SysLog(NID_CNT, "INFO: storageType[%d]", storageType);
1327 bool tempDrm = false;
1329 val = media_info_is_drm(pMediaInfo, &tempDrm);
1330 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1331 "media_info_is_drm failed[%d].", val);
1333 pContentInfoImpl->SetDrmProtected(tempDrm);
1335 SysLog(NID_CNT, "INFO: isDrm[%d]", pContentInfoImpl->IsDrmProtected());
1338 time_t addedTime = 0;
1339 val = media_info_get_added_time(pMediaInfo, &addedTime);
1340 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1341 "media_info_get_added_time failed[%d].", val);
1344 r = dt.SetValue(1970, 1, 1);
1345 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.SetValue operation.");
1346 r = dt.AddSeconds(addedTime);// need to check addedTime is secs/millisec
1347 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.AddSeconds operation.");
1349 pContentInfoImpl->SetDateTime(dt);
1350 SysLog(NID_CNT, "INFO: dateTime[%ls]", ((pContentInfoImpl->GetDateTime()).ToString()).GetPointer());
1353 time_t modifiedTime = 0;
1354 val = media_info_get_modified_time(pMediaInfo, &modifiedTime);
1355 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1356 "media_info_get_modified_time failed[%d].", val);
1358 r = dt.SetValue(1970, 1, 1);
1359 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.SetValue operation.");
1360 r = dt.AddSeconds(modifiedTime);
1361 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.AddSeconds operation.");
1363 pContentInfoImpl->SetModifiedTime(dt);
1364 SysLog(NID_CNT, "INFO: modifiedTime[%ls]", ((pContentInfoImpl->GetModifiedTime()).ToString()).GetPointer());
1367 val = media_info_get_thumbnail_path(pMediaInfo, &pTempValue);
1368 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1369 "media_info_get_thumbnail_path failed[%d].", val);
1371 if (pTempValue != null)
1373 pStrValue.reset(pTempValue);
1374 String thumbnailPath(pStrValue.get());
1376 pContentInfoImpl->SetThumbnailPath(thumbnailPath);
1378 SysLog(NID_CNT, "INFO: thumbnailPath[%ls]", (pContentInfoImpl->GetThumbnailPath()).GetPointer());
1382 val = media_info_get_author(pMediaInfo, &pTempValue);
1383 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1384 "media_info_get_author failed[%d].", val);
1386 if (pTempValue != null)
1388 pStrValue.reset(pTempValue);
1390 pContentInfoImpl->SetAuthor(String(pStrValue.get()));
1392 SysLog(NID_CNT, "INFO: author[%ls]", (pContentInfoImpl->GetAuthor()).GetPointer());
1396 val = media_info_get_category(pMediaInfo, &pTempValue);
1397 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1398 "media_info_get_category failed[%d].", val);
1400 if (pTempValue != null)
1402 pStrValue.reset(pTempValue);
1404 pContentInfoImpl->SetCategory(String(pStrValue.get()));
1406 SysLog(NID_CNT, "INFO: category[%ls]", (pContentInfoImpl->GetCategory()).GetPointer());
1410 val = media_info_get_content_name(pMediaInfo, &pTempValue);
1411 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1412 "media_info_get_content_name failed[%d].", val);
1414 if (pTempValue != null)
1416 pStrValue.reset(pTempValue);
1418 pContentInfoImpl->SetContentName(String(pStrValue.get()));
1420 SysSecureLog(NID_CNT, "INFO: contentName[%ls]", (pContentInfoImpl->GetContentName()).GetPointer());
1424 val = media_info_get_description(pMediaInfo, &pTempValue);
1425 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1426 "media_info_get_description failed[%d].", val);
1428 if (pTempValue != null)
1430 pStrValue.reset(pTempValue);
1432 pContentInfoImpl->SetDescription(String(pStrValue.get()));
1434 SysLog(NID_CNT, "INFO: description[%ls]", (pContentInfoImpl->GetDescription()).GetPointer());
1438 val = media_info_get_keyword(pMediaInfo, &pTempValue);
1439 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1440 "media_info_get_keyword failed[%d].", val);
1442 if (pTempValue != null)
1444 pStrValue.reset(pTempValue);
1446 pContentInfoImpl->SetKeyword(String(pStrValue.get()));
1448 SysLog(NID_CNT, "INFO: keyword[%ls]", (pContentInfoImpl->GetKeyword()).GetPointer());
1452 val = media_info_get_location_tag(pMediaInfo, &pTempValue);
1453 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1454 "media_info_get_location_tag failed[%d].", val);
1456 if (pTempValue != null)
1458 pStrValue.reset(pTempValue);
1460 pContentInfoImpl->SetLocationTag(String(pStrValue.get()));
1462 SysSecureLog(NID_CNT, "INFO: locationTag[%ls]", (pContentInfoImpl->GetLocationTag()).GetPointer());
1466 val = media_info_get_provider(pMediaInfo, &pTempValue);
1467 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1468 "media_info_get_provider failed[%d].", val);
1470 if (pTempValue != null)
1472 pStrValue.reset(pTempValue);
1474 pContentInfoImpl->SetProvider(String(pStrValue.get()));
1476 SysLog(NID_CNT, "INFO: provider[%ls]", (pContentInfoImpl->GetProvider()).GetPointer());
1480 val = media_info_get_age_rating(pMediaInfo, &pTempValue);
1481 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1482 "media_info_get_age_rating failed[%d].", val);
1484 if (pTempValue != null)
1486 pStrValue.reset(pTempValue);
1488 pContentInfoImpl->SetRating(String(pStrValue.get()));
1490 SysLog(NID_CNT, "INFO: rating[%ls]", (pContentInfoImpl->GetRating()).GetPointer());
1494 Coordinates coordinates;
1495 double doubleValue = 0;
1496 val = media_info_get_latitude(pMediaInfo, &doubleValue);
1497 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1498 "media_info_get_latitude failed[%d].", val);
1500 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1502 pContentInfoImpl->SetLatitude(doubleValue);
1503 coordinates.SetLatitude(doubleValue);
1505 SysSecureLog(NID_CNT, "INFO: latitude[%f]", pContentInfoImpl->GetLatitude());
1507 val = media_info_get_longitude(pMediaInfo, &doubleValue);
1508 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1509 "media_info_get_longitude failed[%d].", val);
1511 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1513 pContentInfoImpl->SetLongitude(doubleValue);
1514 coordinates.SetLongitude(doubleValue);
1516 SysSecureLog(NID_CNT, "INFO: longitude[%f]", pContentInfoImpl->GetLongitude());
1518 val = media_info_get_altitude(pMediaInfo, &doubleValue);
1519 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1520 "media_info_get_altitude failed[%d].", val);
1522 if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1524 pContentInfoImpl->SetAltitude(doubleValue);
1525 coordinates.SetAltitude(doubleValue);
1527 SysLog(NID_CNT, "INFO: altitude[%f]", pContentInfoImpl->GetAltitude());
1529 pContentInfoImpl->SetCoordinates(coordinates);
1531 // contentType and metadata
1532 if (systemType == SYSTEM_TYPE_IMAGE)
1534 r = MakeImageContentInfo(pMediaInfo, pInfoImpl);
1535 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform MakeImageContentInfo operation.");
1537 else if (systemType == SYSTEM_TYPE_SOUND || systemType == SYSTEM_TYPE_MUSIC)
1539 r = MakeAudioContentInfo(pMediaInfo, pInfoImpl);
1540 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform MakeAudioContentInfo operation.");
1542 else if (systemType == MEDIA_CONTENT_TYPE_VIDEO)
1544 r = MakeVideoContentInfo(pMediaInfo, pInfoImpl);
1545 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform MakeVideoContentInfo operation.");
1547 else if (systemType == SYSTEM_TYPE_OTHER)
1549 pContentInfoImpl->SetContentType(CONTENT_TYPE_OTHER);
1550 SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1557 _ContentManagerImpl::MakeImageContentInfo(const media_info_h pMediaInfo, void* pInfoImpl) const
1559 result r = E_SUCCESS;
1561 bool boolValue = false;
1562 image_meta_h pTempMeta = null;
1563 unique_ptr<image_meta_h, _ImageMetaDeleter> pImageMeta(null);
1565 SysTryReturnResult(NID_CNT, pInfoImpl != null, E_OUT_OF_MEMORY, "pInfoImpl is null.");
1567 _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1568 SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ContentInfoImpl.");
1570 pContentInfoImpl->SetContentType(CONTENT_TYPE_IMAGE);
1571 SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1573 int val = media_info_get_image(pMediaInfo, &pTempMeta);
1574 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1575 "media_info_get_image failed[%d].", val);
1577 pImageMeta.reset(&pTempMeta);
1579 _ImageContentInfoImpl* pImageContentInfoImpl = static_cast< _ImageContentInfoImpl* >(pInfoImpl);
1580 SysTryReturnResult(NID_CNT, pImageContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ImageContentInfoImpl.");
1583 val = image_meta_get_width(*(pImageMeta.get()), &intValue);
1584 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1585 "image_meta_get_width failed[%d].", val);
1587 pImageContentInfoImpl->SetWidth(intValue);
1588 SysLog(NID_CNT, "META: width[%d]", intValue);
1591 val = image_meta_get_height(*(pImageMeta.get()), &intValue);
1592 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1593 "image_meta_get_height failed[%d].", val);
1595 pImageContentInfoImpl->SetHeight(intValue);
1596 SysLog(NID_CNT, "META: height[%d]", intValue);
1599 media_content_orientation_e orientation;
1600 val = image_meta_get_orientation(*(pImageMeta.get()), &orientation);
1601 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1602 "image_meta_get_orientation failed[%d].", val);
1604 pImageContentInfoImpl->SetOrientation(static_cast< ImageOrientationType >(orientation));
1605 SysLog(NID_CNT, "META: orientation[%d]", orientation);
1607 char* pTempValue = null;
1608 unique_ptr<char, CharDeleter> pStrValue(null);
1611 val = media_info_get_display_name(pMediaInfo, &pTempValue);
1612 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1613 "media_info_get_display_name failed[%d].", val);
1615 if (pTempValue != null)
1617 pStrValue.reset(pTempValue);
1621 String strTitle(pStrValue.get());
1623 result r = strTitle.LastIndexOf(L'.', strTitle.GetLength() - 1, pos);
1626 r = strTitle.SubString(0, pos, fileName);
1627 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The title is invalid.");
1631 // Without extension
1633 fileName = strTitle;
1636 pImageContentInfoImpl->SetTitle(fileName);
1638 SysLog(NID_CNT, "META: title[%ls]", fileName.GetPointer());
1642 val = image_meta_get_date_taken(*(pImageMeta.get()), &pTempValue);
1643 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1644 "image_meta_get_date_taken failed[%d].", val);
1648 if (pTempValue != null)
1650 pStrValue.reset(pTempValue);
1651 String dateTaken(pStrValue.get());
1652 String newDateTaken(L"");
1654 String delim(L": ");
1659 StringTokenizer strTok(dateTaken, delim);
1661 r = strTok.GetNextToken(token);
1662 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1667 r = strTok.GetNextToken(token);
1668 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1670 r = newDateTaken.Append(token);
1671 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1673 r = newDateTaken.Append(L"/");
1674 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1677 r = strTok.GetNextToken(token);
1678 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1680 r = newDateTaken.Append(token);
1681 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1683 r = newDateTaken.Append(L"/");
1684 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1687 r = newDateTaken.Append(year);
1688 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1690 r = newDateTaken.Append(L" ");
1691 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1693 String newDelim(L" ");
1695 r = strTok.SetDelimiters(newDelim);
1696 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform SetDelimiters operation.");
1698 r = strTok.GetNextToken(token);
1699 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1701 r = newDateTaken.Append(token);
1702 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1704 r = DateTime::Parse(newDateTaken, dt);
1705 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform Parse operation for DateTime.");
1709 dt = DateTime::GetMinValue();
1712 pImageContentInfoImpl->SetImageTakenDate(dt);
1713 SysLog(NID_CNT, "META: dateTaken[%ls]", dt.ToString().GetPointer());
1716 val = image_meta_is_burst_shot(*(pImageMeta.get()), &boolValue);
1717 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1718 "image_meta_is_burst_shot failed[%d].", val);
1720 pImageContentInfoImpl->SetBurstShot(boolValue);
1721 SysLog(NID_CNT, "META: isBurstShot[%d]", boolValue);
1724 val = image_meta_get_burst_id(*(pImageMeta.get()), &pTempValue);
1725 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1726 "image_meta_get_burst_id failed[%d].", val);
1728 if (pTempValue != null)
1730 pStrValue.reset(pTempValue);
1731 String burstShotId(pStrValue.get());
1733 pImageContentInfoImpl->SetBurstShotId(burstShotId);
1734 SysLog(NID_CNT, "META: burstShotId[%ls]", burstShotId.GetPointer());
1741 _ContentManagerImpl::MakeAudioContentInfo(const media_info_h pMediaInfo, void* pInfoImpl) const
1744 audio_meta_h pTempMeta = null;
1745 unique_ptr<audio_meta_h, _AudioMetaDeleter> pAudioMeta(null);
1747 SysTryReturnResult(NID_CNT, pInfoImpl != null, E_OUT_OF_MEMORY, "pInfoImpl is null.");
1749 _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1750 SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ContentInfoImpl.");
1752 pContentInfoImpl->SetContentType(CONTENT_TYPE_AUDIO);
1753 SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1755 int val = media_info_get_audio(pMediaInfo, &pTempMeta);
1756 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1757 "media_info_get_audio failed[%d].", val);
1759 pAudioMeta.reset(&pTempMeta);
1761 _AudioContentInfoImpl* pAudioContentInfoImpl = static_cast< _AudioContentInfoImpl* >(pInfoImpl);
1762 SysTryReturnResult(NID_CNT, pAudioContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _AudioContentInfoImpl.");
1765 val = audio_meta_get_bit_rate(*(pAudioMeta.get()), &intValue);
1766 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1767 "audio_meta_get_bit_rate failed[%d].", val);
1769 pAudioContentInfoImpl->SetBitrate(intValue);
1770 SysLog(NID_CNT, "META: bitrate[%d]", intValue);
1772 char* pTempValue = null;
1773 unique_ptr<char, CharDeleter> pStrValue(null);
1776 val = audio_meta_get_year(*(pAudioMeta.get()), &pTempValue);
1777 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1778 "audio_meta_get_year failed[%d].", val);
1780 if (pTempValue != null)
1782 pStrValue.reset(pTempValue);
1784 String strYear(pStrValue.get());
1786 if (strYear.CompareTo(L"Unknown") != 0)
1788 result r = Integer::Parse(strYear, intValue);
1791 // It is one of the metadata. If error occurs, skip it for other metadata.
1794 SysLog(NID_CNT, "META: releaseYear - invalid data[%ls]", strYear.GetPointer());
1797 pAudioContentInfoImpl->SetReleaseYear(intValue);
1798 SysLog(NID_CNT, "META: releaseYear[%d]", intValue);
1803 val = audio_meta_get_title(*(pAudioMeta.get()), &pTempValue);
1804 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1805 "audio_meta_get_title failed[%d].", val);
1807 if (pTempValue != null)
1809 pStrValue.reset(pTempValue);
1811 pAudioContentInfoImpl->SetTitle(String(pStrValue.get()));
1813 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
1817 val = audio_meta_get_album(*(pAudioMeta.get()), &pTempValue);
1818 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1819 "audio_meta_get_album failed[%d].", val);
1821 if (pTempValue != null)
1823 pStrValue.reset(pTempValue);
1825 pAudioContentInfoImpl->SetAlbumName(String(pStrValue.get()));
1827 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
1831 val = audio_meta_get_artist(*(pAudioMeta.get()), &pTempValue);
1832 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1833 "audio_meta_get_artist failed[%d].", val);
1835 if (pTempValue != null)
1837 pStrValue.reset(pTempValue);
1839 pAudioContentInfoImpl->SetArtist(String(pStrValue.get()));
1841 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
1845 val = audio_meta_get_composer(*(pAudioMeta.get()), &pTempValue);
1846 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1847 "audio_meta_get_composer failed[%d].", val);
1849 if (pTempValue != null)
1851 pStrValue.reset(pTempValue);
1853 pAudioContentInfoImpl->SetComposer(String(pStrValue.get()));
1855 SysLog(NID_CNT, "META: composer[%ls]", (String(pStrValue.get())).GetPointer());
1859 val = audio_meta_get_genre(*(pAudioMeta.get()), &pTempValue);
1860 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1861 "audio_meta_get_genre failed[%d].", val);
1863 if (pTempValue != null)
1865 pStrValue.reset(pTempValue);
1867 pAudioContentInfoImpl->SetGenre(String(pStrValue.get()));
1869 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
1873 val = audio_meta_get_copyright(*(pAudioMeta.get()), &pTempValue);
1874 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1875 "audio_meta_get_copyright failed[%d].", val);
1877 if (pTempValue != null)
1879 pStrValue.reset(pTempValue);
1881 pAudioContentInfoImpl->SetCopyright(String(pStrValue.get()));
1883 SysLog(NID_CNT, "META: copyright[%ls]", (String(pStrValue.get())).GetPointer());
1887 val = audio_meta_get_track_num(*(pAudioMeta.get()), &pTempValue);
1888 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1889 "audio_meta_get_track_num failed[%d].", val);
1891 if (pTempValue != null)
1893 pStrValue.reset(pTempValue);
1895 pAudioContentInfoImpl->SetTrackInfo(String(pStrValue.get()));
1897 SysLog(NID_CNT, "META: trackInfo[%ls]", (String(pStrValue.get())).GetPointer());
1901 val = audio_meta_get_duration(*(pAudioMeta.get()), &intValue);
1902 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1903 "audio_meta_get_duration failed[%d].", val);
1905 pAudioContentInfoImpl->SetDuration(intValue);
1906 SysLog(NID_CNT, "META: duration[%d]", intValue);
1912 _ContentManagerImpl::MakeVideoContentInfo(const media_info_h pMediaInfo, void* pInfoImpl) const
1915 video_meta_h pTempMeta = null;
1916 unique_ptr<video_meta_h, _VideoMetaDeleter> pVideoMeta(null);
1918 SysTryReturnResult(NID_CNT, pInfoImpl != null, E_OUT_OF_MEMORY, "pInfoImpl is null.");
1920 _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1921 SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ContentInfoImpl.");
1923 pContentInfoImpl->SetContentType(CONTENT_TYPE_VIDEO);
1924 SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1926 int val = media_info_get_video(pMediaInfo, &pTempMeta);
1927 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1928 "media_info_get_video failed[%d].", val);
1930 pVideoMeta.reset(&pTempMeta);
1932 _VideoContentInfoImpl* pVideoContentInfoImpl = static_cast< _VideoContentInfoImpl* >(pInfoImpl);
1933 SysTryReturnResult(NID_CNT, pVideoContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _VideoContentInfoImpl.");
1936 val = video_meta_get_width(*(pVideoMeta.get()), &intValue);
1937 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1938 "video_meta_get_width failed[%d].", val);
1940 pVideoContentInfoImpl->SetWidth(intValue);
1941 SysLog(NID_CNT, "META: width[%d]", intValue);
1944 val = video_meta_get_height(*(pVideoMeta.get()), &intValue);
1945 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1946 "video_meta_get_height failed[%d].", val);
1948 pVideoContentInfoImpl->SetHeight(intValue);
1949 SysLog(NID_CNT, "META: height[%d]", intValue);
1951 char* pTempValue = null;
1952 unique_ptr<char, CharDeleter> pStrValue(null);
1955 val = video_meta_get_artist(*(pVideoMeta.get()), &pTempValue);
1956 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1957 "video_meta_get_artist failed[%d].", val);
1959 if (pTempValue != null)
1961 pStrValue.reset(pTempValue);
1963 pVideoContentInfoImpl->SetArtist(String(pStrValue.get()));
1965 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
1969 val = video_meta_get_genre(*(pVideoMeta.get()), &pTempValue);
1970 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1971 "video_meta_get_genre failed[%d].", val);
1973 if (pTempValue != null)
1975 pStrValue.reset(pTempValue);
1977 pVideoContentInfoImpl->SetGenre(String(pStrValue.get()));
1979 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
1983 val = video_meta_get_title(*(pVideoMeta.get()), &pTempValue);
1984 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1985 "video_meta_get_title failed[%d].", val);
1987 if (pTempValue != null)
1989 pStrValue.reset(pTempValue);
1991 pVideoContentInfoImpl->SetTitle(String(pStrValue.get()));
1993 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
1997 val = video_meta_get_album(*(pVideoMeta.get()), &pTempValue);
1998 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1999 "video_meta_get_album failed[%d].", val);
2001 if (pTempValue != null)
2003 pStrValue.reset(pTempValue);
2005 pVideoContentInfoImpl->SetAlbumName(String(pStrValue.get()));
2007 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
2011 val = video_meta_get_duration(*(pVideoMeta.get()), &intValue);
2012 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
2013 "video_meta_get_duration failed[%d].", val);
2015 pVideoContentInfoImpl->SetDuration(intValue);
2016 SysLog(NID_CNT, "META: duration[%d]", intValue);
2018 // Get from metadata extractor (framerate, audio bitrate, video bitrate)
2019 VideoMetadata* pVideoMetadata = ContentManagerUtil::GetVideoMetaN(pVideoContentInfoImpl->GetContentPath());
2020 result r = GetLastResult();
2021 SysTryReturnResult(NID_CNT, pVideoMetadata != null, r, "GetVideoMetadata() failed.");
2023 pVideoContentInfoImpl->SetFramerate(pVideoMetadata->GetFramerate());
2024 pVideoContentInfoImpl->SetAudioBitrate(pVideoMetadata->GetAudioBitrate());
2025 pVideoContentInfoImpl->SetVideoBitrate(pVideoMetadata->GetVideoBitrate());
2031 _ContentManagerImpl::VerifyHomeFilePathCompatibility(const String& contentPath) const
2033 if (!_AppInfo::IsOspCompat())
2035 if (contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0))
2037 SysLogException(NID_CNT, E_INVALID_ARG,
2038 "[E_INVALID_ARG] /Home/ or /HomeExt/ is not supported from Tizen 2.0.");
2041 if (!(contentPath.StartsWith(App::App::GetInstance()->GetAppRootPath(), 0) ||
2042 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
2044 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] The path is not supported.");
2050 SysTryReturn(NID_CNT, contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0),
2051 false, E_INVALID_ARG, "[E_INVALID_ARG] The path should start with /Home or /HomeExt.");
2058 _ContentManagerImpl::VerifyMediaFilePathCompatibility(const String& contentPath, bool checkVersion) const
2062 result r = E_SUCCESS;
2064 if (!_AppInfo::IsOspCompat())
2066 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0) || contentPath.StartsWith(OSP_MEDIA_MMC, 0))
2068 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] /Media or /Storagecard/Media is not supported.");
2071 if (!(contentPath.StartsWith(Environment::GetMediaPath(), 0) ||
2072 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
2074 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] This path is not supported.");
2080 String tempPath(contentPath);
2083 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0))
2085 r = tempPath.Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
2086 SysTryReturn(NID_CNT, !IsFailed(r), false, E_INVALID_ARG, "[E_INVALID_ARG] Replace failed.");
2088 else if (contentPath.StartsWith(OSP_MEDIA_MMC, 0))
2090 r = tempPath.Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
2091 SysTryReturn(NID_CNT, !IsFailed(r), false, E_INVALID_ARG, "[E_INVALID_ARG] Replace failed.");
2095 // CreateContent(const ByteBuffer&, ...) and CreateContent (const Sring&, ...) can receive old path like /Media/.
2096 // but CreateContent(const ContentInfo&) always receive new path like /opt/media/ because ContentInfo class convert the path from /Media/ to /opt/media.
2099 SysLogException(NID_CNT, E_INVALID_ARG,
2100 "[E_INVALID_ARG] The path should start with /Home, /Media, or /Storagecard/Media.");
2110 _ContentManagerImpl::SetListener(IContentUpdateEventListener* pListener)
2112 __pListener = pListener;
2115 IContentUpdateEventListener*
2116 _ContentManagerImpl::GetListener(void) const
2122 _ContentManagerImpl::ConvertErrorToResult(result res) const
2124 result r = E_SUCCESS;