From: Hyunbin Lee Date: Thu, 18 Apr 2013 07:49:45 +0000 (+0900) Subject: Increase result set size of MapDataControl X-Git-Tag: accepted/tizen_2.1/20130425.034849~33 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=966d870ceabcad3c3e62493412f66e1f66945a69;p=platform%2Fframework%2Fnative%2Fappfw.git Increase result set size of MapDataControl Change-Id: Iabbb4ebb3036b544fb021de553156e6994b31d1e Signed-off-by: Hyunbin Lee --- diff --git a/src/app/FApp_AppArg.cpp b/src/app/FApp_AppArg.cpp index 6657a36..4e9f09a 100644 --- a/src/app/FApp_AppArg.cpp +++ b/src/app/FApp_AppArg.cpp @@ -71,6 +71,7 @@ static const char OSP_V_REQUEST_TYPE_MAP_QEURY[] = "map_query"; static const char OSP_V_REQUEST_TYPE_MAP_INSERT[] = "map_insert"; static const char OSP_V_REQUEST_TYPE_MAP_UPDATE[] = "map_update"; static const char OSP_V_REQUEST_TYPE_MAP_DELETE[] = "map_delete"; +static const char OSP_V_VERSION_2_1_0_1[] = "ver_2.1.0.1"; static const char BUNDLE_KEY_PREFIX_AUL[] = "__AUL_"; static const char BUNDLE_KEY_PREFIX_SERVICE[] = "__APP_SVC_"; static const char BUNDLE_KEY_PREFIX_OSP[] = "__OSP_"; @@ -1030,6 +1031,7 @@ _AppArg::CreateMapDataControlArg(bundle* b, const _MapDataControlImpl& dc, _Data char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, }; snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast < int >(requestType)); bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType); + bundle_add(b, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_V_VERSION_2_1_0_1); std::unique_ptr pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId)); if (pProvider) diff --git a/src/app/FApp_DataControlProviderManagerImpl.cpp b/src/app/FApp_DataControlProviderManagerImpl.cpp index 544c19c..97bfedd 100644 --- a/src/app/FApp_DataControlProviderManagerImpl.cpp +++ b/src/app/FApp_DataControlProviderManagerImpl.cpp @@ -20,6 +20,7 @@ * @brief This is the implementation for the %_DataControlProviderManagerImpl class. */ +#include #include #include @@ -28,13 +29,15 @@ #include #include #include +#include #include #include #include #include #include +#include -#include +#include #include #include "FApp_Aul.h" @@ -46,6 +49,7 @@ #include "FApp_MapDataControlImpl.h" #include "FApp_DataControlProviderManagerImpl.h" +using namespace std; using namespace Tizen::Base; using namespace Tizen::Base::Collection; using namespace Tizen::Io; @@ -80,7 +84,9 @@ _DataControlProviderManagerImpl::SendDataControlResult(RequestId reqId, _DataCon IDbEnumerator* pDbEnum, IList* pResultValueList, long long insertRowId, bool providerResult, const String* pErrorMsg) { ArrayList* pList = null; - String appId; + String callerAppId; + int callerPid = -1; + String version; String reqType; int type = 0; _DataControlRequestType requestType = _DATACONTROL_REQUEST_TYPE_UNDEFINED; @@ -128,7 +134,9 @@ _DataControlProviderManagerImpl::SendDataControlResult(RequestId reqId, _DataCon } } - appId = arg.GetCallerAppId(); + callerAppId = arg.GetCallerAppId(); + callerPid = arg.GetCallerPid(); + version = arg.GetValue(OSP_K_DATACONTROL_PROTOCOL_VERSION); callerReqId = arg.GetValue(OSP_K_REQUEST_ID); providerId = arg.GetValue(OSP_K_DATACONTROL_PROVIDER); @@ -139,8 +147,8 @@ _DataControlProviderManagerImpl::SendDataControlResult(RequestId reqId, _DataCon pDataId = dynamic_cast< String* >(pList->GetAt(0)); // request list[0] SysTryCatch(NID_APP, pDataId, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result object"); - SysLog(NID_APP, "[DC_PROV_SEND] > app: %ls, requestType: %d, callerReq: %ls, provider: %ls, data: %ls", - appId.GetPointer(), requestType, callerReqId.GetPointer(), providerId.GetPointer(), pDataId->GetPointer()); + SysLog(NID_APP, "[DC_PROV_SEND] > caller app: %ls, caller proc: %d, version: %ls requestType: %d, callerReq: %ls, provider: %ls, data: %ls", + callerAppId.GetPointer(), callerPid, version.GetPointer(), requestType, callerReqId.GetPointer(), providerId.GetPointer(), pDataId->GetPointer()); // Serializes result pResultArgList = new (std::nothrow) ArrayList(); @@ -174,7 +182,7 @@ _DataControlProviderManagerImpl::SendDataControlResult(RequestId reqId, _DataCon { if (pDbEnum) { - std::unique_ptr<_DataControlResultSetImpl> pResultSet(new (std::nothrow) _DataControlResultSetImpl(reqId)); + unique_ptr<_DataControlResultSetImpl> pResultSet(new (std::nothrow) _DataControlResultSetImpl(reqId)); SysTryCatch(NID_APP, pResultSet, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); @@ -183,7 +191,7 @@ _DataControlProviderManagerImpl::SendDataControlResult(RequestId reqId, _DataCon "[E_SYSTEM] The method cannot proceed due to a severe system error."); String tempFilePath(_DATACONTROL_RESULTSET_DIR); - tempFilePath.Append(appId); + tempFilePath.Append(callerAppId); tempFilePath.Append(callerReqId); pTempFilePath = new (std::nothrow) String(tempFilePath); } @@ -235,19 +243,63 @@ _DataControlProviderManagerImpl::SendDataControlResult(RequestId reqId, _DataCon SysTryCatch(NID_APP, pResultCount, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory was insufficient."); pResultArgList->Add(*pResultCount); // result list[2] + SysLog(NID_APP, "[DC_PROV_SEND] result count: %ls", resultCount.GetPointer()); long long argSize = 0; - for (int i = currentoffset; i < num; i++) + if (addItemCount > 0) { - String* pTempValue = dynamic_cast< String* >(pResultValueList->GetAt(i)); - SysTryCatch(NID_APP, pTempValue != null, r = E_INVALID_ARG, E_INVALID_ARG, - "[E_INVALID_ARG] The specified pResultValueList parameter should be String class."); - - pResultValue = new (std::nothrow) String(*pTempValue); - SysTryCatch(NID_APP, pResultValue, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, - "[E_OUT_OF_MEMORY] The memory was insufficient."); - pResultArgList->Add(*pResultValue); // list[3] ~ - argSize += pResultValue->GetLength() * sizeof(wchar_t); + if (version == L"ver_2.1.0.1") + { + String tempFilePath(_DATACONTROL_RESULTSET_DIR); + tempFilePath.Append(callerAppId); + tempFilePath.Append(callerReqId); + pTempFilePath = new (std::nothrow) String(tempFilePath); + pResultArgList->Add(*pTempFilePath); // result list[3] + SysLog(NID_APP, "[DC_PROV_SEND] protocol version: %ls, path: %ls", version.GetPointer(), pTempFilePath->GetPointer()); + + unique_ptr< File > pFile(new (std::nothrow) File()); + SysTryCatch(NID_APP, pFile != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); + + r = pFile->Construct(*pTempFilePath, L"w+", true); + SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Failed to create temp file (%ls) for result set.", + GetErrorMessage(r), pTempFilePath->GetPointer()); + + for (int i = currentoffset; i < num; ++i) + { + String* pValue = dynamic_cast< String* >(pResultValueList->GetAt(i)); + SysTryCatch(NID_APP, pValue != null, r = E_INVALID_ARG, E_INVALID_ARG, + "[E_INVALID_ARG] The specified pResultValueList parameter should be String class."); + + int length = pValue->GetLength(); + r = pFile->Write(&length, sizeof(int)); // data length + SysTryCatch(NID_APP, !IsFailed(r), , E_SYSTEM, "[%s] Failed to write result.", GetErrorMessage(r)); + + unique_ptr< char[] > pData(_StringConverter::CopyToCharArrayN(*pValue)); + SysTryCatch(NID_APP, pData != null, , GetLastResult(), "[%s] Invalid result value", + GetErrorMessage(GetLastResult())); + + r = pFile->Write(pData.get(), strlen(pData.get())); // data + SysTryCatch(NID_APP, !IsFailed(r), , E_SYSTEM, "[E_SYSTEM] Failed to write result.", GetErrorMessage(r)); + argSize += pValue->GetLength() * sizeof(wchar_t); + } + pFile->Flush(); + } + else + { + SysLog(NID_APP, "[DC_PROV_SEND] protocol version: none"); + for (int i = currentoffset; i < num; ++i) + { + String* pValue = dynamic_cast< String* >(pResultValueList->GetAt(i)); + SysTryCatch(NID_APP, pValue != null, r = E_INVALID_ARG, E_INVALID_ARG, + "[E_INVALID_ARG] The specified pResultValueList parameter should be String class."); + + pResultValue = new (std::nothrow) String(*pValue); + SysTryCatch(NID_APP, pResultValue, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] The memory was insufficient."); + pResultArgList->Add(*pResultValue); // list[3] ~ + argSize += pValue->GetLength() * sizeof(wchar_t); + } + } } SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED, "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize); @@ -275,6 +327,7 @@ _DataControlProviderManagerImpl::SendDataControlResult(RequestId reqId, _DataCon resultArg.UpdateKeyValue(OSP_K_DATACONTROL_REQUEST_TYPE, reqType); resultArg.UpdateKeyValue(OSP_K_DATACONTROL_PROVIDER, providerId); resultArg.UpdateKeyValue(OSP_K_DATACONTROL_DATA, *pDataId); + resultArg.UpdateKeyValue(OSP_K_DATACONTROL_PROTOCOL_VERSION, version); //resultArg.Print(); r = _Aul::SendResult(resultArg.GetBundle(), static_cast< appsvc_result_val >(0)); diff --git a/src/app/FApp_MapDataControlImpl.cpp b/src/app/FApp_MapDataControlImpl.cpp index 1e4746a..862fa0e 100755 --- a/src/app/FApp_MapDataControlImpl.cpp +++ b/src/app/FApp_MapDataControlImpl.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -281,13 +282,14 @@ result _MapDataControlImpl::MapDataControlCallback(void* data, _AppArg* pArg, _AppArg* pResArg, service_result_e res, int prop, int option) { ArrayList* pResultList = null; + String version; String* pResult = null; String* pProviderId = null; String* pDataId = null; String* pErrorMessage = null; String* pErrorMsg = null; String* pResultCount = null; - String* pValue = null; + String* pPath = null; ArrayList* pResultValueList = null; int resultCount = 0; int requestType = 0; @@ -360,44 +362,87 @@ _MapDataControlImpl::MapDataControlCallback(void* data, _AppArg* pArg, _AppArg* SysTryCatch(NID_APP, pDataId, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); - SysLog(NID_APP, "[DC_CALLER_RECV] provider result: %ld, requestType: %d, req: %d, provider: %ls, data: %ls, errorMsg: %ls ", - providerRes, requestType, reqId, pProviderId->GetPointer(), pDataId->GetPointer(), pErrorMsg->GetPointer()); + version = pResArg->GetValue(OSP_K_DATACONTROL_PROTOCOL_VERSION); + + SysLog(NID_APP, "[DC_CALLER_RECV] version: %ls, provider result: %ld, requestType: %d, req: %d, provider: %ls, data: %ls, errorMsg: %ls", + version.GetPointer(), providerRes, requestType, reqId, pProviderId->GetPointer(), pDataId->GetPointer(), pErrorMsg->GetPointer()); switch (static_cast< _DataControlRequestType >(requestType)) { case _DATACONTROL_REQUEST_TYPE_MAP_QUERY: { - pResultValueList = new (std::nothrow) ArrayList(); + pResultValueList = new (std::nothrow) ArrayList(SingleObjectDeleter); SysTryCatch(NID_APP, pResultValueList, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); if (providerResult == true) { pResultCount = dynamic_cast< String* >(pResultList->GetAt(2)); // result list[2] - if (pResultCount == null) - { - SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] invalid result"); - pResultValueList->RemoveAll(true); - delete pResultValueList; - goto CATCH; - } + SysTryCatch(NID_APP, pResultCount, delete pResultValueList, E_SYSTEM, "[E_SYSTEM] invalid result"); Integer::Parse(*pResultCount, resultCount); + SysLog(NID_APP, "[DC_CALLER_RECV] result count: %d", resultCount); - int index = 3; - while (resultCount) + if (resultCount > 0) { - pValue = dynamic_cast< String* >(pResultList->GetAt(index)); - if (pValue == null) + if (version == L"ver_2.1.0.1") { - SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] invalid result"); - pResultValueList->RemoveAll(true); - delete pResultValueList; - goto CATCH; + pPath = dynamic_cast< String* >(pResultList->GetAt(3)); // result list[3] + SysTryCatch(NID_APP, pPath, delete pResultValueList, E_SYSTEM, "[E_SYSTEM] invalid result"); + SysLog(NID_APP, "[DC_CALLER_RECV] path: %ls", pPath->GetPointer()); + + unique_ptr< File > pFile(new (std::nothrow) File()); + SysTryCatch(NID_APP, pFile, delete pResultValueList, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); + + r = pFile->Construct(*pPath, "r"); + SysTryCatch(NID_APP, !IsFailed(r), delete pResultValueList, r, "[%s] Failed to open result set (%ls)", + GetErrorMessage(r), pPath->GetPointer()); + + while (resultCount) + { + int length = 0; + int ret = pFile->Read(&length, sizeof(int)); + SysTryCatch(NID_APP, ret, delete pResultValueList, E_SYSTEM, + "[E_SYSTEM] Failed to read data from the result set of data control provider."); + + char* pValue = new (std::nothrow) char[length + 1]; + SysTryCatch(NID_APP, pValue, delete pResultValueList, E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] The memory is insufficient."); + + ret = pFile->Read(pValue, length); + if (ret == 0) + { + SysLogException(NID_APP, E_SYSTEM, + "[E_SYSTEM] Failed to read data from the result set of data control provider."); + delete pResultValueList; + delete[] pValue; + goto CATCH; + } + pValue[length] = '\0'; + + pResultValueList->Add(new (std::nothrow) String(pValue)); + delete[] pValue; + --resultCount; + } } + else + { + int index = 3; + while (resultCount) + { + String* pValue = dynamic_cast< String* >(pResultList->GetAt(index)); // result list[3] ~ + SysTryCatch(NID_APP, pValue, delete pResultValueList, E_SYSTEM, "[E_SYSTEM] invalid result"); + + pResultValueList->Add((new (std::nothrow) String(*pValue))); + --resultCount; + ++index; + } + } + } - pResultValueList->Add(*(new (std::nothrow) String(*pValue))); - resultCount--; - index++; + if (pPath) + { + r = File::Remove(*pPath); + SysTryLog(NID_APP, !IsFailed(r), "Failed to remove result: %ls", pPath->GetPointer()); } } diff --git a/src/app/inc/FApp_AppArg.h b/src/app/inc/FApp_AppArg.h index 32f59f0..1dee6ed 100644 --- a/src/app/inc/FApp_AppArg.h +++ b/src/app/inc/FApp_AppArg.h @@ -68,6 +68,7 @@ enum _DataControlRequestType #define OSP_K_DATACONTROL_PROVIDER "__OSP_DATACONTROL_PROVIDER__" #define OSP_K_DATACONTROL_DATA "__OSP_DATACONTROL_DATA__" #define OSP_K_DATACONTROL_REQUEST_TYPE "__OSP_DATACONTROL_REQUEST_TYPE__" +#define OSP_K_DATACONTROL_PROTOCOL_VERSION "__OSP_DATACONTROL_PROTOCOL_VERSION__" /** * @class _AppArg @@ -189,7 +190,7 @@ public: static result FillMapFromList(Tizen::Base::Collection::IMap* pMap, const Tizen::Base::Collection::IList* pList); static result FillLegacyAppControlResult(Tizen::Base::Collection::IList& list, int res, const Tizen::Base::Collection::IMap* pMap, const Tizen::Base::String& aId); - + static result SetArgMap(bundle* pBundle, Tizen::Base::Collection::HashMap* pMap); private: diff --git a/src/io/FIo_DataControlResultSetImpl.cpp b/src/io/FIo_DataControlResultSetImpl.cpp index 63c0a86..b4a71f7 100644 --- a/src/io/FIo_DataControlResultSetImpl.cpp +++ b/src/io/FIo_DataControlResultSetImpl.cpp @@ -187,7 +187,7 @@ _DataControlResultSetImpl::FillWith(IDbEnumerator* pDbEnum) SysTryReturnResult(NID_IO, pFile != null, E_OUT_OF_MEMORY, "The memory is insufficient."); - r = pFile->Construct(__tmpPath, "w+", true); + r = pFile->Construct(__tmpPath, L"w+", true); SysTryReturn(NID_IO, r == E_SUCCESS, r, r, "[%s] Failed to create temp file (%ls) for result set.", GetErrorMessage(r), __tmpPath.GetPointer());