From c544020ce3223383d6ed33e74640d89e80399fc7 Mon Sep 17 00:00:00 2001 From: Seokpil Park Date: Thu, 6 Jun 2013 10:15:52 +0900 Subject: [PATCH] [content] Use _LocalizedNumParser::ToDouble() because locale Change-Id: I6d8ffd505d57acd4970c6dbcb821b7d74022ca24 Signed-off-by: Seokpil Park --- src/FCnt_ContentManagerUtilImpl.cpp | 288 ++++++++++++++-------------------- src/FCnt_ContentSearchImpl.cpp | 8 +- src/inc/FCnt_ContentManagerUtilImpl.h | 1 - 3 files changed, 121 insertions(+), 176 deletions(-) diff --git a/src/FCnt_ContentManagerUtilImpl.cpp b/src/FCnt_ContentManagerUtilImpl.cpp index 0b6b2b9..665461a 100755 --- a/src/FCnt_ContentManagerUtilImpl.cpp +++ b/src/FCnt_ContentManagerUtilImpl.cpp @@ -20,52 +20,52 @@ * This file contains implementation of the %_ContentManagerUtilImpl class. */ +#include #include #include -#include -#include -#include #include -#include -#include -#include -#include +#include +#include +#include #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include -#include #include +#include #include #include -#include +#include "FCnt_AudioMetadataImpl.h" +#include "FCnt_ContentManagerUtilImpl.h" +#include "FCnt_ImageMetadataImpl.h" +#include "FCnt_VideoMetadataImpl.h" + +using namespace std; +using namespace Tizen::App; using namespace Tizen::Base; +using namespace Tizen::Base::Utility; +using namespace Tizen::Graphics; using namespace Tizen::Io; using namespace Tizen::Media; -using namespace Tizen::Graphics; -using namespace Tizen::App; using namespace Tizen::System; -using namespace std; namespace Tizen { namespace Content { // Types of content, format supported and default values -static const int IMAGE_BUFF_LENGTH = 100; -static const int THUMBNAIL_IMAGE_WIDTH = 80; -static const int THUMBNAIL_IMAGE_HEIGHT = 60; -static const int MINUTES = 60; -static const int SECONDS = 3600; +static const int _IMAGE_BUFF_LENGTH = 100; +static const int _THUMBNAIL_IMAGE_WIDTH = 80; +static const int _THUMBNAIL_IMAGE_HEIGHT = 60; +static const int _MINUTES = 60; +static const int _SECONDS = 3600; -// -// E_SUCCESS -// E_INVALID_ARG -// E_OUT_OF_MEMORY -// ImageMetadata* _ContentManagerUtilImpl::GetImageMetaN(const String& contentPath, bool internal) { @@ -117,9 +117,9 @@ _ContentManagerUtilImpl::GetImageMetaN(const String& contentPath, bool internal) ExifByteOrder byteOrder; ExifEntry** pEntries = null; const char* pData = null; - char buf[IMAGE_BUFF_LENGTH] = {0, }; - char mmBuff[IMAGE_BUFF_LENGTH] = {0, }; // to store minutes value of GPS data - char ssBuff[IMAGE_BUFF_LENGTH] = {0, }; // to store seconds value of GPS data + char buf[_IMAGE_BUFF_LENGTH] = {0, }; + char mmBuff[_IMAGE_BUFF_LENGTH] = {0, }; // to store minutes value of GPS data + char ssBuff[_IMAGE_BUFF_LENGTH] = {0, }; // to store seconds value of GPS data ExifContent* pExifcont[EXIF_IFD_COUNT]; int index = 0; char latitudeRef = 0; // to store latitude reference (quadrasphere designation 'N', 'S', 'W' or 'E') @@ -182,47 +182,31 @@ _ContentManagerUtilImpl::GetImageMetaN(const String& contentPath, bool internal) } else if (tag == EXIF_TAG_GPS_LATITUDE) { - ParseBuffer(buf, index); // to extract the minutes value of GPS data, if present - for (int l = 0; l < IMAGE_BUFF_LENGTH-1; l++) - { - mmBuff[l] = buf[l + index + 1]; //add 1 to skip the ',' - } - index = 0; //re-assign index value as this is new buffer - ParseBuffer(mmBuff, index); // to extract the seconds value of GPS data, if present - for (int l = 0; l < IMAGE_BUFF_LENGTH-1; l++) - { - ssBuff[l] = mmBuff[l + index + 1]; //add 1 to skip the ',' - } + String tempLatitude(buf); + String delim(L","); - char *pLocal; - std::unique_ptr pCurrentLocal(null); - pLocal = setlocale (LC_ALL, 0); // Get the name of the current locale. - if( pLocal == null ) - { - SysLog(NID_CNT, "setlocale failed. (get current locale)"); - continue; - } - pCurrentLocal.reset(strdup (pLocal)); + StringTokenizer strTok(tempLatitude, delim); + String token[3] = {L"", }; - pLocal = setlocale(LC_ALL, "C"); - if( pLocal == null ) + int count = 0; + while (strTok.HasMoreTokens()) { - SysLog(NID_CNT, "setlocale failed. (set POSIX C locale)"); - continue; + strTok.GetNextToken(token[count++]); } - double ddVal = atof(buf); // degree value - double mmVal = atof(mmBuff); // minutesvalue - double ssVal = atof(ssBuff); // seconds value + double ddVal = _LocalizedNumParser::ToDouble(token[0], "C"); // degree value + r = GetLastResult(); + SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to perform ToDouble operation."); - pLocal = setlocale (LC_ALL, pCurrentLocal.get()); // restore the locale. - if( pLocal == null ) - { - SysLog(NID_CNT, "setlocale failed. (set current locale)"); - continue; - } + double mmVal = _LocalizedNumParser::ToDouble(token[1], "C"); // minutes value + r = GetLastResult(); + SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to perform ToDouble operation."); - pMetadata->latitude = ddVal + (mmVal/MINUTES) + (ssVal/SECONDS); + double ssVal = _LocalizedNumParser::ToDouble(token[2], "C"); // seconds value + r = GetLastResult(); + SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to perform ToDouble operation."); + + pMetadata->latitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS); // if latitude designation is Southern (SOUTH) then latitude degree will be negative DD if (latitudeRef == 'S') @@ -236,48 +220,31 @@ _ContentManagerUtilImpl::GetImageMetaN(const String& contentPath, bool internal) } else if (tag == EXIF_TAG_GPS_LONGITUDE) { - index = 0; //re-assign index value as this is new buffer - ParseBuffer(buf, index); // to extract the minutes value of GPS data, if present - for (int l = 0; l < IMAGE_BUFF_LENGTH-1; l++) - { - mmBuff[l] = buf[l + index + 1]; //add 1 to skip the ',' - } - index = 0; //re-assign index value as this is new buffer - ParseBuffer(mmBuff, index); // to extract the seconds value of GPS data, if present - for (int l = 0; l < IMAGE_BUFF_LENGTH-1; l++) - { - ssBuff[l] = mmBuff[l + index + 1]; //add 1 to skip the ',' - } + String tempLongitude(buf); + String delim(L","); - char *pLocal; - std::unique_ptr pCurrentLocal(null); - pLocal = setlocale (LC_ALL, 0); // Get the name of the current locale. - if( pLocal == null ) - { - SysLog(NID_CNT, "setlocale failed. (get current locale)"); - continue; - } - pCurrentLocal.reset(strdup (pLocal)); + StringTokenizer strTok(tempLongitude, delim); + String token[3] = {L"", }; - pLocal = setlocale(LC_ALL, "C"); - if( pLocal == null ) + int count = 0; + while (strTok.HasMoreTokens()) { - SysLog(NID_CNT, "setlocale failed. (set POSIX C locale)"); - continue; + strTok.GetNextToken(token[count++]); } - double ddVal = atof(buf); // degree value - double mmVal = atof(mmBuff); // minutesvalue - double ssVal = atof(ssBuff); // seconds value + double ddVal = _LocalizedNumParser::ToDouble(token[0], "C"); // degree value + r = GetLastResult(); + SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation."); - pLocal = setlocale (LC_ALL, pCurrentLocal.get()); // restore the locale. - if( pLocal == null ) - { - SysLog(NID_CNT, "setlocale failed. (set current locale)"); - continue; - } + double mmVal = _LocalizedNumParser::ToDouble(token[1], "C"); // minutes value + r = GetLastResult(); + SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation."); + + double ssVal = _LocalizedNumParser::ToDouble(token[2], "C"); // seconds value + r = GetLastResult(); + SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation."); - pMetadata->longitude = ddVal + (mmVal/MINUTES) + (ssVal/SECONDS); + pMetadata->longitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS); // if longitude designation is Western (WEST) then longitude degree will be negative DD if (longitudeRef == 'W') @@ -299,20 +266,6 @@ _ContentManagerUtilImpl::GetImageMetaN(const String& contentPath, bool internal) return pImageMetadata.release(); } -void -_ContentManagerUtilImpl::ParseBuffer(char* pBuffer, int& count) -{ - if ((*pBuffer != ',') && (*pBuffer != '\0')) // parse the buffer till ',' or '\0' and return the index - { - ParseBuffer(++pBuffer, ++count); - } -} - -// -// E_SUCCESS -// E_INVALID_ARG -// E_OUT_OF_MEMORY -// AudioMetadata* _ContentManagerUtilImpl::GetAudioMetaN(const String& contentPath) { @@ -629,7 +582,7 @@ _ContentManagerUtilImpl::GetAudioMetaN(const String& contentPath) { format = img.GetImageFormat(buffer); pMetadata->pThumbnail = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888, - THUMBNAIL_IMAGE_WIDTH, THUMBNAIL_IMAGE_HEIGHT); + _THUMBNAIL_IMAGE_WIDTH, _THUMBNAIL_IMAGE_HEIGHT); if (pMetadata->pThumbnail == null) { // Because Thumbnail is one of the metadata, it is not exception in this function. @@ -655,11 +608,6 @@ _ContentManagerUtilImpl::GetAudioMetaN(const String& contentPath) return pAudioMetadata.release(); } -// -// E_SUCCESS -// E_INVALID_ARG -// E_OUT_OF_MEMORY -// VideoMetadata* _ContentManagerUtilImpl::GetVideoMetaN(const String& contentPath) { @@ -934,9 +882,9 @@ _ContentManagerUtilImpl::GetImageMetaN(const ByteBuffer& byteBuffer) ExifByteOrder byteOrder; ExifEntry** pEntries = null; const char* pData = null; - char buf[IMAGE_BUFF_LENGTH] = {0, }; - char mmBuff[IMAGE_BUFF_LENGTH] = {0, }; // to store minutes value of GPS data - char ssBuff[IMAGE_BUFF_LENGTH] = {0, }; // to store seconds value of GPS data + char buf[_IMAGE_BUFF_LENGTH] = {0, }; + char mmBuff[_IMAGE_BUFF_LENGTH] = {0, }; // to store minutes value of GPS data + char ssBuff[_IMAGE_BUFF_LENGTH] = {0, }; // to store seconds value of GPS data ExifContent* pExifcont[EXIF_IFD_COUNT]; int index = 0; char latitudeRef = 0; // to store latitude reference (quadrasphere designation 'N', 'S', 'W' or 'E') @@ -999,21 +947,31 @@ _ContentManagerUtilImpl::GetImageMetaN(const ByteBuffer& byteBuffer) } else if (tag == EXIF_TAG_GPS_LATITUDE) { - ParseBuffer(buf, index); // to extract the minutes value of GPS data, if present - for (int l = 0; l < IMAGE_BUFF_LENGTH-1; l++) - { - mmBuff[l] = buf[l + index + 1]; //add 1 to skip the ',' - } - index = 0; //re-assign index value as this is new buffer - ParseBuffer(mmBuff, index); // to extract the seconds value of GPS data, if present - for (int l = 0; l < IMAGE_BUFF_LENGTH-1; l++) + String tempLatitude(buf); + String delim(L","); + + StringTokenizer strTok(tempLatitude, delim); + String token[3] = {L"", }; + + int count = 0; + while (strTok.HasMoreTokens()) { - ssBuff[l] = mmBuff[l + index + 1]; //add 1 to skip the ',' + strTok.GetNextToken(token[count++]); } - double ddVal = atof(buf); // degree value - double mmVal = atof(mmBuff); // minutesvalue - double ssVal = atof(ssBuff); // seconds value - pMetadata->latitude = ddVal + (mmVal/MINUTES) + (ssVal/SECONDS); + + double ddVal = _LocalizedNumParser::ToDouble(token[0], "C"); // degree value + r = GetLastResult(); + SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation."); + + double mmVal = _LocalizedNumParser::ToDouble(token[1], "C"); // minutes value + r = GetLastResult(); + SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation."); + + double ssVal = _LocalizedNumParser::ToDouble(token[2], "C"); // seconds value + r = GetLastResult(); + SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation."); + + pMetadata->latitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS); // if latitude designation is Southern (SOUTH) then latitude degree will be negative DD if (latitudeRef == 'S') @@ -1027,22 +985,31 @@ _ContentManagerUtilImpl::GetImageMetaN(const ByteBuffer& byteBuffer) } else if (tag == EXIF_TAG_GPS_LONGITUDE) { - index = 0; //re-assign index value as this is new buffer - ParseBuffer(buf, index); // to extract the minutes value of GPS data, if present - for (int l = 0; l < IMAGE_BUFF_LENGTH-1; l++) - { - mmBuff[l] = buf[l + index + 1]; //add 1 to skip the ',' - } - index = 0; //re-assign index value as this is new buffer - ParseBuffer(mmBuff, index); // to extract the seconds value of GPS data, if present - for (int l = 0; l < IMAGE_BUFF_LENGTH-1; l++) + String tempLongitude(buf); + String delim(L","); + + StringTokenizer strTok(tempLongitude, delim); + String token[3] = {L"", }; + + int count = 0; + while (strTok.HasMoreTokens()) { - ssBuff[l] = mmBuff[l + index + 1]; //add 1 to skip the ',' + strTok.GetNextToken(token[count++]); } - double ddVal = atof(buf); // degree value - double mmVal = atof(mmBuff); // minutesvalue - double ssVal = atof(ssBuff); // seconds value - pMetadata->longitude = ddVal + (mmVal/MINUTES) + (ssVal/SECONDS); + + double ddVal = _LocalizedNumParser::ToDouble(token[0], "C"); // degree value + r = GetLastResult(); + SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation."); + + double mmVal = _LocalizedNumParser::ToDouble(token[1], "C"); // minutes value + r = GetLastResult(); + SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation."); + + double ssVal = _LocalizedNumParser::ToDouble(token[2], "C"); // seconds value + r = GetLastResult(); + SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation."); + + pMetadata->longitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS); // if longitude designation is Western (WEST) then longitude degree will be negative DD if (longitudeRef == 'W') @@ -1064,11 +1031,6 @@ _ContentManagerUtilImpl::GetImageMetaN(const ByteBuffer& byteBuffer) return pImageMetadata.release(); } -// -// E_SUCCESS -// E_INVALID_ARG -// E_OUT_OF_MEMORY -// AudioMetadata* _ContentManagerUtilImpl::GetAudioMetaN(const ByteBuffer& byteBuffer) { @@ -1378,7 +1340,7 @@ _ContentManagerUtilImpl::GetAudioMetaN(const ByteBuffer& byteBuffer) { format = img.GetImageFormat(buffer); pMetadata->pThumbnail = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888, - THUMBNAIL_IMAGE_WIDTH, THUMBNAIL_IMAGE_HEIGHT); + _THUMBNAIL_IMAGE_WIDTH, _THUMBNAIL_IMAGE_HEIGHT); if (pMetadata->pThumbnail == null) { // Because Thumbnail is one of the metadata, it is not exception in this function. @@ -1404,11 +1366,6 @@ _ContentManagerUtilImpl::GetAudioMetaN(const ByteBuffer& byteBuffer) return pAudioMetadata.release(); } -// -// E_SUCCESS -// E_INVALID_ARG -// E_OUT_OF_MEMORY -// VideoMetadata* _ContentManagerUtilImpl::GetVideoMetaN(const ByteBuffer& byteBuffer) { @@ -1632,13 +1589,6 @@ _ContentManagerUtilImpl::GetVideoMetaN(const ByteBuffer& byteBuffer) return pVideoMetadata.release(); } -// -// E_SUCCESS -// E_INVALID_ARG -// E_OUT_OF_MEMORY -// E_FILE_NOT_FOUND -// E_UNSUPPORTED_FORMAT -// ContentType _ContentManagerUtilImpl::CheckContentType(const String& contentPath, bool internal) { @@ -1851,9 +1801,6 @@ _ContentManagerUtilImpl::ErrorMapToRetVal(int retVal) return r; } -/** - * deprecation - */ result _ContentManagerUtilImpl::CopyToMediaDirectory(const String& srcContentPath, const String& destContentPath) { @@ -1877,9 +1824,6 @@ _ContentManagerUtilImpl::CopyToMediaDirectory(const String& srcContentPath, cons return r; } -/** - * deprecation - */ result _ContentManagerUtilImpl::MoveToMediaDirectory(const String& srcContentPath, const String& destContentPath) { diff --git a/src/FCnt_ContentSearchImpl.cpp b/src/FCnt_ContentSearchImpl.cpp index 4788b7e..a640f99 100644 --- a/src/FCnt_ContentSearchImpl.cpp +++ b/src/FCnt_ContentSearchImpl.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -1445,9 +1446,10 @@ _ContentSearchImpl::ExecuteAndFillGetValueListN(media_group_e groupIndex, int co //fall through case 13://"Altitude", "MEDIA_ALTITUDE" if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty())) - { - res = Double::Parse(strColVal, dVal); - SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] double parse failed.", GetErrorMessage(res)); + { + dVal = _LocalizedNumParser::ToDouble(strColVal, "C"); + r = GetLastResult(); + SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform ToDouble operation."); } pValue.reset(new (std::nothrow) Double(dVal)); break; diff --git a/src/inc/FCnt_ContentManagerUtilImpl.h b/src/inc/FCnt_ContentManagerUtilImpl.h index cdf3c25..4e4ad62 100644 --- a/src/inc/FCnt_ContentManagerUtilImpl.h +++ b/src/inc/FCnt_ContentManagerUtilImpl.h @@ -121,7 +121,6 @@ private: _ContentManagerUtilImpl(void); _ContentManagerUtilImpl(const _ContentManagerUtilImpl& rhs); virtual ~_ContentManagerUtilImpl(void); - static void ParseBuffer(char* pBuffer, int& count); static bool VerifyFilePathCompatibility(const Tizen::Base::String& contentPath); _ContentManagerUtilImpl& operator =(const _ContentManagerUtilImpl& rhs); static result ErrorMapToRetVal(int retVal); -- 2.7.4