//
-// Open Service Platform
// Copyright (c) 2012 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the License);
*/
#include <stdlib.h>
+#include <aul/aul.h>
#include <FBaseSysLog.h>
#include <FAppApp.h>
#include <FBaseInteger.h>
pScanResult = unique_ptr< ScanResult >(static_cast< ScanResult* >(user_data));
- SysTryLogCatch(NID_CNT, pScanResult != null && pScanResult->pScanPath != null, , "OnScanCompleted failed.");
+ SysTryLogCatch(NID_CNT, pScanResult != null, , "OnScanCompleted failed.");
SysTryLogCatch(NID_CNT, pScanResult->pScanListener != null, , "Listener is null. OnScanCompleted succeeded.");
- scanPath = pScanResult->pScanPath;
+ scanPath = pScanResult->scanPath;
pListener = pScanResult->pScanListener;
reqId = pScanResult->requestId;
SysTryLogReturn(NID_CNT, user_data != null, , "OnContentUpdateCompleted failed.");
_ContentManagerImpl* pTempManagerImpl = static_cast< _ContentManagerImpl* >(user_data);
+ SysTryLogReturn(NID_CNT, pTempManagerImpl != null, , "pTempManagerImpl is null.");
IContentUpdateEventListener* pListener = pTempManagerImpl->GetListener();
SysTryLogReturn(NID_CNT, pListener != null, , "IContentUpdateEventListener is null.");
SysLog(NID_CNT, "update_type is invalid.");
break;
}
+ break;
}
case MEDIA_ITEM_DIRECTORY:
_ContentManagerImpl::~_ContentManagerImpl(void)
{
- int val = media_content_disconnect();
+ int val;
+
+ if (GetListener())
+ {
+ val = media_content_unset_db_updated_cb();
+ SysLog(NID_CNT, "media_content_unset_db_updated_cb result[%d].", val);
+
+ SetListener(null);
+ }
+
+ val = media_content_disconnect();
SysLog(NID_CNT, "media_content_disconnect result[%d].", val);
__isConnected = false;
SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
"[E_OUT_OF_MEMORY] The memory is insufficient.");
- media_info_h __pMediaInfo = null;
- unique_ptr<media_info_h, MediaInfoDeleter> pMediaInfo(null);
+ media_info_h tempMediaInfo = null;
+ unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
// Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
- int val = media_info_insert_to_db(pStr.get(), &__pMediaInfo);
+ int val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
"The registration to database failed[%d].", val);
- pMediaInfo.reset(&__pMediaInfo);
+ pMediaInfo.reset(tempMediaInfo);
// Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
- ContentId contentId = SaveDataToDatabase(*(pMediaInfo.get()), pContentData);
+ ContentId contentId = SaveDataToDatabase(pMediaInfo.get(), pContentData);
result r = GetLastResult();
SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
"[%s] The registration to database failed.", GetErrorMessage(r));
ContentId contentId;
ContentInfo::_ContentData contentData;
ContentInfo::_ContentData* pContentData = null;
- media_info_h __pMediaInfo = null;
- unique_ptr<media_info_h, MediaInfoDeleter> pMediaInfo(null);
+ media_info_h tempMediaInfo = null;
+ unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
unique_ptr<char[]> pStr(null);
if (pContentInfo != null)
pStr.reset(_StringConverter::CopyToCharArrayN(destinationPath));
SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
- val = media_info_insert_to_db(pStr.get(), &__pMediaInfo);
+ val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
"media_info_insert_to_db failed[%d].", val);
- pMediaInfo.reset(&__pMediaInfo);
+ pMediaInfo.reset(tempMediaInfo);
// Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
- contentId = SaveDataToDatabase(*(pMediaInfo.get()), pContentData);
+ contentId = SaveDataToDatabase(pMediaInfo.get(), pContentData);
r = GetLastResult();
SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
"[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", destinationPath.GetPointer());
result r = E_SUCCESS;
+ bool isCopy = false;
if (deleteSource) // move
{
// Exception : E_SUCCESS, E_INVALID_ARG, E_ILLEGAL_ACCESS, E_FILE_NOT_FOUND, E_FILE_ALREADY_EXIST, E_MAX_EXCEEDED, E_STORAGE_FULL, E_IO
r = _FileImpl::Copy(sourcePath, destinationPath, true);
SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Copying the file failed.", GetErrorMessage(r));
+
+ isCopy = true;
}
int val = 0;
ContentId contentId;
ContentInfo::_ContentData contentData;
ContentInfo::_ContentData* pContentData = null;
- media_info_h __pMediaInfo = null;
- unique_ptr<media_info_h, MediaInfoDeleter> pMediaInfo(null);
+ media_info_h tempMediaInfo = null;
+ unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
unique_ptr<char[]> pStr(null);
if (pContentInfo != null)
pStr.reset(_StringConverter::CopyToCharArrayN(destinationPath));
SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
- val = media_info_insert_to_db(pStr.get(), &__pMediaInfo);
+ val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
"media_info_insert_to_db failed[%d].", val);
- pMediaInfo.reset(&__pMediaInfo);
+ pMediaInfo.reset(tempMediaInfo);
- contentId = SaveDataToDatabase(*(pMediaInfo.get()), pContentData);
+ contentId = SaveDataToDatabase(pMediaInfo.get(), pContentData);
r = GetLastResult();
SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
"[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
CATCH:
result saveResult = GetLastResult();
- // If the destination file is made by this method, it should be deleted when error occurs.
- r = _FileImpl::Remove(destinationPath);
- SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
+ if (isCopy)
+ {
+ r = _FileImpl::Remove(destinationPath);
+ SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
+ }
+ else
+ {
+ r = _FileImpl::Move(destinationPath, sourcePath);
+ SysLog(NID_CNT, "Move[%s].", GetErrorMessage(r));
+ }
if (pMediaInfo != null)
{
unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(contentId.ToString()));
SysTryReturn(NID_CNT, pStr != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
- media_info_h __pMediaInfo = null;
- unique_ptr<media_info_h, MediaInfoDeleter> pMediaInfo(null);
- int val = media_info_get_media_from_db(pStr.get(), &__pMediaInfo);
+ media_info_h tempMediaInfo = null;
+ unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
+ int val = media_info_get_media_from_db(pStr.get(), &tempMediaInfo);
SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
"media_info_get_media_from_db failed[%d].", val);
- pMediaInfo.reset(&__pMediaInfo);
+ pMediaInfo.reset(tempMediaInfo);
media_content_type_e systemType = MEDIA_CONTENT_TYPE_IMAGE;
- val = media_info_get_media_type(*(pMediaInfo.get()), &systemType);
+ val = media_info_get_media_type(pMediaInfo.get(), &systemType);
SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
"media_info_get_media_type failed[%d].", val);
char* __pFilePath = null;
- val = media_info_get_file_path(*(pMediaInfo.get()), &__pFilePath);
+ val = media_info_get_file_path(pMediaInfo.get(), &__pFilePath);
SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
"media_info_get_file_path failed[%d].", val);
// Set data
// Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
- r = MakeContentInfo(*(pMediaInfo.get()), pContentData, systemType, pImageContentData);
+ r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, pImageContentData);
SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
return pImageContentInfo.release();
SysTryReturn(NID_CNT, pAudioContentData != null, null, E_OUT_OF_MEMORY,
"[E_OUT_OF_MEMORY] The memory is insufficient.");
- r = MakeContentInfo(*(pMediaInfo.get()), pContentData, systemType, pAudioContentData);
+ r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, pAudioContentData);
SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
return pAudioContentInfo.release();
SysTryReturn(NID_CNT, pVideoContentData != null, null, E_OUT_OF_MEMORY,
"[E_OUT_OF_MEMORY] The memory is insufficient.");
- r = MakeContentInfo(*(pMediaInfo.get()), pContentData, systemType, pVideoContentData);
+ r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, pVideoContentData);
SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
return pVideoContentInfo.release();
SysTryReturn(NID_CNT, pContentData != null, null, E_OUT_OF_MEMORY,
"[E_OUT_OF_MEMORY] The memory is insufficient.");
- r = MakeContentInfo(*(pMediaInfo.get()), pContentData, systemType, null);
+ r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, null);
SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
return pOtherContentInfo.release();
result r = E_SUCCESS;
int val = 0;
- media_info_h __pMediaInfo = null;
- unique_ptr<media_info_h, MediaInfoDeleter> pMediaInfo(null);
+ media_info_h tempMediaInfo = null;
+ unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
- val = media_info_get_media_from_db(pContentId.get(), &__pMediaInfo);
+ val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
"media_info_get_media_from_db failed[%d].", val);
- pMediaInfo.reset(&__pMediaInfo);
+ pMediaInfo.reset(tempMediaInfo);
char* __pContentPath = null;
- val = media_info_get_file_path(*(pMediaInfo.get()), &__pContentPath);
+ val = media_info_get_file_path(pMediaInfo.get(), &__pContentPath);
SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
"media_info_get_file_path failed[%d].", val);
reqId = requestId++;
- pScanResult->pScanPath = pDirPath.get();
+ pScanResult->scanPath = directoryPath;
pScanResult->pScanListener = pListener;
pScanResult->requestId = reqId;
- val = media_content_scan_folder(pDirPath.release(), recursive, OnScanCompleted, pScanResult.release());
+ val = media_content_scan_folder(pDirPath.get(), recursive, OnScanCompleted, pScanResult.release());
SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val), "media_content_scan_folder failed[%d].", val);
return E_SUCCESS;
SysTryReturnResult(NID_CNT, pContentData != null, E_INVALID_ARG, "pContentData is null.");
- media_info_h __pMediaInfo = null;
- unique_ptr<media_info_h, MediaInfoDeleter> pMediaInfo(null);
+ media_info_h tempMediaInfo = null;
+ unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
unique_ptr<char[]> pContentId(_StringConverter::CopyToCharArrayN((pContentData->contentId).ToString()));
SysTryReturnResult(NID_CNT, pContentId != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
- int val = media_info_get_media_from_db(pContentId.get(), &__pMediaInfo);
+ int val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
"media_info_get_media_from_db failed[%d].", val);
- pMediaInfo.reset(&__pMediaInfo);
+ pMediaInfo.reset(tempMediaInfo);
result r = E_SUCCESS;
unique_ptr<char[]> pValue(null);
pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pAuthor)));
SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
- val = media_info_set_author(*(pMediaInfo.get()), pValue.get());
+ val = media_info_set_author(pMediaInfo.get(), pValue.get());
SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
"media_info_set_author failed[%d].", val);
}
pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pCategory)));
SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
- val = media_info_set_category(*(pMediaInfo.get()), pValue.get());
+ val = media_info_set_category(pMediaInfo.get(), pValue.get());
SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
"media_info_set_category failed[%d].", val);
}
pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pContentName)));
SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
- val = media_info_set_content_name(*(pMediaInfo.get()), pValue.get());
+ val = media_info_set_content_name(pMediaInfo.get(), pValue.get());
SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
"media_info_set_content_name failed[%d].", val);
}
pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pDescription)));
SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
- val = media_info_set_description(*(pMediaInfo.get()), pValue.get());
+ val = media_info_set_description(pMediaInfo.get(), pValue.get());
SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
"media_info_set_description failed[%d].", val);
}
pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pKeyword)));
SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
- val = media_info_set_keyword(*(pMediaInfo.get()), pValue.get());
+ val = media_info_set_keyword(pMediaInfo.get(), pValue.get());
SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
"media_info_set_keyword failed[%d].", val);
}
pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pLocationTag)));
SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
- val = media_info_set_location_tag(*(pMediaInfo.get()), pValue.get());
+ val = media_info_set_location_tag(pMediaInfo.get(), pValue.get());
SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
"media_info_set_location_tag failed[%d].", val);
}
pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pProvider)));
SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
- val = media_info_set_provider(*(pMediaInfo.get()), pValue.get());
+ val = media_info_set_provider(pMediaInfo.get(), pValue.get());
SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
"media_info_set_provider failed[%d].", val);
}
pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pRating)));
SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
- val = media_info_set_age_rating(*(pMediaInfo.get()), pValue.get());
+ val = media_info_set_age_rating(pMediaInfo.get(), pValue.get());
SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
"media_info_set_age_rating failed[%d].", val);
}
if (Double::Compare(pContentData->latitude, DEFAULT_COORDINATE) != 0 &&
Double::Compare(pContentData->longitude, DEFAULT_COORDINATE) != 0)
{
- val = media_info_set_latitude(*(pMediaInfo.get()), pContentData->latitude);
+ val = media_info_set_latitude(pMediaInfo.get(), pContentData->latitude);
SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
"media_info_set_latitude failed[%d].", val);
- val = media_info_set_longitude(*(pMediaInfo.get()), pContentData->longitude);
+ val = media_info_set_longitude(pMediaInfo.get(), pContentData->longitude);
SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
"media_info_set_longitude failed[%d].", val);
if (Double::Compare(pContentData->altitude, DEFAULT_COORDINATE) != 0)
{
- val = media_info_set_altitude(*(pMediaInfo.get()), pContentData->altitude);
+ val = media_info_set_altitude(pMediaInfo.get(), pContentData->altitude);
SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
"media_info_set_altitude failed[%d].", val);
}
}
- val = media_info_update_to_db(*(pMediaInfo.get()));
+ val = media_info_update_to_db(pMediaInfo.get());
SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
"media_info_update_to_db failed[%d].", val);
SysTryReturn(NID_CNT, pContentData != null, UuId::GetInvalidUuId(), E_INVALID_ARG,
"[E_INVALID_ARG] pContentData is null.");
- // Exception : E_SUCCESS, E_INVALID_ARG
+ String mimeType(L"");
String extension = _FileImpl::GetFileExtension(pContentData->contentPath);
result r = GetLastResult();
- SysTryReturn(NID_CNT, !(IsFailed(r)), UuId::GetInvalidUuId(), r, "[%s] Propagating.", GetErrorMessage(r));
+ if (IsFailed(r))
+ {
+ ClearLastResult();
+
+ SysLog(NID_CNT, "[%s] Failed to perform GetFileExtension operation.", GetErrorMessage(r));
+
+ unique_ptr<char[]> pTempPath(_StringConverter::CopyToCharArrayN(pContentData->contentPath));
+ SysTryReturn(NID_CNT, pTempPath != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
+ "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
+ char tempType[255] = {0, };
+ int ret = aul_get_mime_from_file(pTempPath.get(), tempType, sizeof(tempType));
+ SysTryReturn(NID_CNT, ret == AUL_R_OK, UuId::GetInvalidUuId(), E_INVALID_ARG,
+ "[E_INVALID_ARG] Failed to perform aul_get_mime_from_file operation.");
+
+ r = mimeType.Append(tempType);
+ SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
+ "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
+
+ }
// If the content format is JPG and it has GPS data, it will be saved in database automatically.
- if (extension == L"jpg" || extension == L"jpeg" || extension == L"JPG" || extension == L"JPEG")
+ if (extension == L"jpg" || extension == L"jpeg" || extension == L"JPG" || extension == L"JPEG" || mimeType.Contains(L"jpeg"))
{
SysLog(NID_CNT, "The format of content is jpg.");
pContentData->longitude = pImageMetadata->GetLongitude();
delete pImageMetadata;
- pImageMetadata = null;
}
}
if (!(contentPath.StartsWith(Environment::GetMediaPath(), 0) ||
contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
{
- SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] %ls is not supported.", contentPath.GetPointer());
+ SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] This path is not supported.");
return false;
}
}