proper headers
[platform/framework/native/appfw.git] / src / app / FApp_MapDataControlImpl.cpp
index 1b86d02..7ee27e4 100644 (file)
@@ -1,5 +1,4 @@
 //
-// Open Service Platform
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the License);
  */
 
 #include <typeinfo>
-#include <new>
 #include <unique_ptr.h>
 
 #include <appsvc/appsvc.h>
 
 #include <FBaseInteger.h>
 #include <FBaseString.h>
+#include <FBaseColLinkedList.h>
 #include <FBaseRtIEventArg.h>
+#include <FIoFile.h>
 #include <FAppMapDataControl.h>
 #include <FAppIMapDataControlResponseListener.h>
 
@@ -37,6 +37,7 @@
 #include "FApp_AppControlManager.h"
 #include "FApp_MapDataControlImpl.h"
 #include "FApp_AppArg.h"
+#include "FApp_DataControlManager.h"
 
 using namespace std;
 
@@ -49,6 +50,10 @@ using namespace Tizen::Io;
 namespace Tizen { namespace App
 {
 
+static const int MAX_REQUEST_COUNT = 128;
+static const int REQUEST_THRESHOLD = 100;
+static const int _MAX_ARGUMENT_SIZE = 16384; // 16KB
+
 class _MapDataControlEventArg
        : public IEventArg
 {
@@ -87,7 +92,7 @@ class _MapDataControlEvent
        : public Event
 {
 protected:
-               virtual void FireImpl(IEventListener& listener, const IEventArg& arg);
+       virtual void FireImpl(IEventListener& listener, const IEventArg& arg);
 };
 
 void
@@ -126,9 +131,7 @@ _MapDataControlEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
 
 // private
 _MapDataControlImpl::_MapDataControlImpl(void)
-       : __appId(L"")
-       , __providerId(L"")
-       , __access(_DATACONTROL_ACCESS_UNDEFINED)
+       : __access(_DATACONTROL_ACCESS_UNDEFINED)
        , __pPreviousListener(null)
        , __pMapDataControlEvent(null)
 {
@@ -137,6 +140,19 @@ _MapDataControlImpl::_MapDataControlImpl(void)
 _MapDataControlImpl::~_MapDataControlImpl(void)
 {
        delete __pMapDataControlEvent;
+
+       _DataControlManager* pDcMgr = _DataControlManager::GetInstance();
+
+       IEnumerator* pEnum = __pRequestList->GetEnumeratorN();
+       while (pEnum->MoveNext() == E_SUCCESS)
+       {
+               Integer* pReqId = dynamic_cast< Integer* >(pEnum->GetCurrent());
+               if (pReqId != null)
+               {
+                       pDcMgr->RemoveRequestInfo(*pReqId);
+               }
+       }
+       delete __pRequestList;
 }
 
 _MapDataControlImpl*
@@ -154,24 +170,72 @@ _MapDataControlImpl::GetInstance(const MapDataControl& dc)
 result
 _MapDataControlImpl::StartMapDataControl(int type, const IList* pDataList, int* pReq)
 {
+       Integer* pReqId = null;
+       _DataControlRequestInfo* pReqInfo = null;
        result r = E_SUCCESS;
 
+       int req = -1;
+       _DataControlManager* pDcMgr = _DataControlManager::GetInstance();
+
+       // Check the request count of DataControl operation
+       int count = pDcMgr->GetRequestCount();
+       SysLog(NID_APP, "Current launch request count: %d", count);
+
+       if (count > REQUEST_THRESHOLD)
+       {
+               _AppManagerImpl* pImpl = _AppManagerImpl::GetInstance();
+
+               // Clear the request queue if the provider is terminated
+               if (!pImpl->IsRunning(__appId))
+               {
+                       SysLog(NID_APP, "The request queue is cleared due to the invalid provider.");
+
+                       pDcMgr->RemoveAllRequests();
+               }
+       }
+
+       SysTryReturnResult(NID_APP, count < MAX_REQUEST_COUNT, E_MAX_EXCEEDED, "The number of requests has exceeded the maximum limit.");
+
        _AppArg* pArg = new(std::nothrow) _AppArg; // XXX: pArg will be released in _AppManagerImpl::LaunchApp().
        SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
 
        pArg->Construct(*this, static_cast <_DataControlRequestType>(type), pDataList);
 
        _AppControlManager* pAppManagerImpl = _AppControlManager::GetInstance();
-       int req = -1;
 
        if (__pMapDataControlEvent)
        {
                // reqId is system-wide id because the bundle is system-wide.
+#if 0
                _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pAppManagerImpl, pArg, MapDataControlCallback, __pMapDataControlEvent, -1);
                req = reqObj.GetRequestNumber();
+#else
+               _DataControlManager* pDcMgr = _DataControlManager::GetInstance();
+               _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pAppManagerImpl, pArg, MapDataControlCallback, pDcMgr, -1);
+               req = reqObj.GetRequestNumber();
+#endif
+               pReqId = new (std::nothrow) Integer(req);
+               SysTryCatch(NID_APP, pReqId != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+                               "[E_OUT_OF_MEMORY] The memory is insufficient");
+
+               pReqInfo = new (std::nothrow) _DataControlRequestInfo(__pMapDataControlEvent);
+               SysTryCatch(NID_APP, pReqInfo != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+                               "[E_OUT_OF_MEMORY] The memory is insufficient");
+               pReqInfo->SetMapDataControlImpl(this);
+
+               r = pDcMgr->AddRequestInfo(pReqId, pReqInfo);
+               SysTryCatch(NID_APP, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[%s] Failed to add request info", GetErrorMessage(r));
 
                r = pAppManagerImpl->LaunchApp(__appId, pArg, req);
-               SysTryCatch(NID_APP, r == E_SUCCESS, reqObj.Invalidate(), r, "[%s] Propgated.", GetErrorMessage(r));
+               if (IsFailed(r))
+               {
+                       SysPropagate(NID_APP, r);
+                       reqObj.Invalidate();
+                       pDcMgr->RemoveRequestInfo(*pReqId);
+                       return r;
+               }
+
+               __pRequestList->Add(new (std::nothrow) Integer(req));
 
                if (pReq)
                {
@@ -181,10 +245,16 @@ _MapDataControlImpl::StartMapDataControl(int type, const IList* pDataList, int*
        else
        {
                r = pAppManagerImpl->LaunchApp(__appId, pArg);
+               SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
                delete pArg;
        }
 
+       return E_SUCCESS;
+
 CATCH:
+       delete pArg;
+       delete pReqId;
+       delete pReqInfo;
        return r;
 }
 
@@ -197,21 +267,26 @@ _MapDataControlImpl::GetValue(const String& dataId, const String& key,
        SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_READ) > 0, E_ILLEGAL_ACCESS,
                        "The GetValue query is not permitted by DataControl provider.");
 
+       String* pPageNo = null;
+       String* pCountPerPage = null;
        int id = 0;
        result r = E_SUCCESS;
 
-       ArrayList* pArgList = null;
-       pArgList = new ArrayList();
+       ArrayList* pArgList = new ArrayList();
        pArgList->Construct();
 
        pArgList->Add(*(new String(dataId)));
        pArgList->Add(*(new String(key)));
+       long long argSize = dataId.GetLength() * sizeof(wchar_t);
+       argSize += key.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 (%lld) exceeds the maximum limit.", argSize);
 
-       String* pPageNo = new String();
+       pPageNo = new (std::nothrow) String();
        pPageNo->Append(pageNo);
        pArgList->Add(*pPageNo);
 
-       String* pCountPerPage = new String();
+       pCountPerPage = new (std::nothrow) String();
        pCountPerPage->Append(countPerPage);
        pArgList->Add(*pCountPerPage);
 
@@ -220,7 +295,7 @@ _MapDataControlImpl::GetValue(const String& dataId, const String& key,
 
        reqId = static_cast< RequestId >(id);
 
-       SysLog(NID_APP, "dataId: %ls, key: %ls, reqId: %d, pageNo: %d, countPerPage: %d",
+       SysLog(NID_APP, "[DC_CALLER_SEND] data: %ls, key: %ls, req: %d, pageNo: %d, countPerPage: %d",
                        dataId.GetPointer(), key.GetPointer(), reqId, pageNo, countPerPage);
 
        // fall through
@@ -232,28 +307,28 @@ CATCH:
 }
 
 result
-_MapDataControlImpl::MapDataControlCallback(void* data, _AppArg* pArg, _AppArg* pResArg, service_result_e res, int prop)
+_MapDataControlImpl::MapDataControlCallback(void* data, _AppArg* pArg, _AppArg* pResArg, service_result_e res, int prop, int option)
 {
        ArrayList* pResultList = null;
-       ArrayList* pOrigList = null;
-       String* pRequestType = null;
+       String version;
        String* pResult = null;
-       String* pReqId = 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;
        int reqId = 0;
+       int launchReqId = 0;
        int providerRes = 0;
        bool providerResult = true;
-       bundle* origBundle = null;
+       //bundle* origBundle = null;
        bundle* resBundle = null;
        _MapDataControlEventArg* pEventArg = null;
+       const char* p = null;
        result r = E_SUCCESS;
 
        SysTryReturnResult(NID_APP, pResArg != null, E_INVALID_ARG, "Empty result callback.");
@@ -262,93 +337,149 @@ _MapDataControlImpl::MapDataControlCallback(void* data, _AppArg* pArg, _AppArg*
        resBundle = pResArg->GetBundle();
        if (resBundle)
        {
-               _MapDataControlEvent* pMapDataControlEvent = static_cast< _MapDataControlEvent* >(data);
+               p = appsvc_get_data(resBundle, OSP_K_REQUEST_ID);
+               SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
+               reqId = atoi(p);
+               Integer key(reqId);
+
+               _DataControlManager* pDcMgr = static_cast< _DataControlManager* >(data);
+               _DataControlRequestInfo* pReqInfo = pDcMgr->GetRequestInfo(key);
+               if (pReqInfo == null)
+               {
+                       SysLog(NID_APP, "No request info of reqId %d", reqId);
+                       return E_SUCCESS;
+               }
+
+               _MapDataControlEvent* pMapDataControlEvent = dynamic_cast< _MapDataControlEvent* >(pReqInfo->GetEvent());
+               SysTryCatch(NID_APP, pMapDataControlEvent != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request info");
+
+               pDcMgr->RemoveRequestInfo(key);
+
+               _MapDataControlImpl* pDcImpl = pReqInfo->GetMapDataControlImpl();
+               SysTryCatch(NID_APP, pDcImpl != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request info");
+               pDcImpl->__pRequestList->Remove(key);
+
+               // Remove the request from the queue
+               SysLog(NID_APP, "Remove the request, req: %d", reqId);
 
                if (pMapDataControlEvent != null && typeid(pMapDataControlEvent) == typeid(_MapDataControlEvent*))
                {
-                       const char* p = null;
 
                        // result list
                        pResultList = _AppArg::GetListN(resBundle, OSP_K_ARG);
                        SysTryCatch(NID_APP, pResultList, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result");
 
-                       pResult = dynamic_cast <String*>(pResultList->GetAt(0));
+                       pResult = dynamic_cast <String*>(pResultList->GetAt(0)); // result list[0]
                        SysTryCatch(NID_APP, pResult, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result");
                        Integer::Parse(*pResult, providerRes);
                        providerResult = static_cast< bool >(providerRes);
 
-                       pErrorMessage = dynamic_cast< String* >(pResultList->GetAt(1));
+                       pErrorMessage = dynamic_cast< String* >(pResultList->GetAt(1)); // result list[1]
                        SysTryCatch(NID_APP, pErrorMessage, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result");
                        pErrorMsg = new (std::nothrow) String(*pErrorMessage);
                        SysTryCatch(NID_APP, pErrorMsg, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
                                        "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
                        // request info
-                       origBundle = pArg->GetBundle();
+                       //origBundle = pArg->GetBundle();
 
-                       p = appsvc_get_data(origBundle, OSP_K_DATACONTROL_REQUEST_TYPE);
+                       p = appsvc_get_data(resBundle, OSP_K_DATACONTROL_REQUEST_TYPE);
                        SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
-                       pRequestType = new (std::nothrow) String(p);
-                       SysTryCatch(NID_APP, pRequestType, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
-                                       "[E_OUT_OF_MEMORY] The memory is insufficient.");
-                       Integer::Parse(*pRequestType, requestType);
+                       requestType = atoi(p);
 
-                       p = appsvc_get_data(origBundle, OSP_K_REQUEST_ID);
+                       p = appsvc_get_data(resBundle, OSP_K_DATACONTROL_PROVIDER);
                        SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
-                       pReqId = new (std::nothrow) String(p);
-                       SysTryCatch(NID_APP, pReqId, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+                       pProviderId = new (std::nothrow) String(p);
+                       SysTryCatch(NID_APP, pProviderId, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
                                        "[E_OUT_OF_MEMORY] The memory is insufficient.");
-                       Integer::Parse(*pReqId, reqId);
 
-                       p = appsvc_get_data(origBundle, OSP_K_DATACONTROL_PROVIDER);
+                       p = appsvc_get_data(resBundle, OSP_K_DATACONTROL_DATA);
                        SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
-                       pProviderId = new (std::nothrow) String(p);
-                       SysTryCatch(NID_APP, pProviderId, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+                       pDataId = new (std::nothrow) String(p);
+                       SysTryCatch(NID_APP, pDataId, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
                                        "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
-                       pOrigList = _AppArg::GetListN(origBundle, OSP_K_ARG);
-                       SysTryCatch(NID_APP, pOrigList, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
-                       pDataId = dynamic_cast <String*>(pOrigList->GetAt(0));
-                       SysTryCatch(NID_APP, pDataId, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
+                       version = pResArg->GetValue(OSP_K_DATACONTROL_PROTOCOL_VERSION);
 
-                       SysLog(NID_APP, "result: %ld, requestType: %d, reqId: %d, providerId: %ls, dataId: %ls, errorMsg: %ls ",
-                                       providerRes, requestType, reqId, pProviderId->GetPointer(), pDataId->GetPointer(), pErrorMsg->GetPointer());
+                       SysSecureLog(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));
-                                       if (pResultCount == null)
-                                       {
-                                               SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] invalid result");
-                                               pResultValueList->RemoveAll(true);
-                                               delete pResultValueList;
-                                               goto CATCH;
-                                       }
+                                       pResultCount = dynamic_cast< String* >(pResultList->GetAt(2)); // result list[2]
+                                       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" || version == L"ver_2.1.0.2" || version == L"ver_2.1.0.3")
+                                               {
+                                                       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
                                                {
-                                                       SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] invalid result");
-                                                       pResultValueList->RemoveAll(true);
-                                                       delete pResultValueList;
-                                                       goto CATCH;
+                                                       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());
                                        }
                                }
 
@@ -389,16 +520,14 @@ _MapDataControlImpl::MapDataControlCallback(void* data, _AppArg* pArg, _AppArg*
 
                        pResultList->RemoveAll(true);
                        delete pResultList;
-
-                       pOrigList->RemoveAll(true);
-                       delete pOrigList;
-
-                       delete pRequestType;
-                       delete pReqId;
                        delete pProviderId;
                }
        }
 
+       p = appsvc_get_data(pArg->GetBundle(), OSP_K_REQUEST_ID);
+       SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
+       launchReqId = atoi(p);
+
        return E_SUCCESS;
 
 CATCH:
@@ -407,15 +536,6 @@ CATCH:
                pResultList->RemoveAll(true);
                delete pResultList;
        }
-
-       if (pOrigList)
-       {
-               pOrigList->RemoveAll(true);
-               delete pOrigList;
-       }
-
-       delete pRequestType;
-       delete pReqId;
        delete pProviderId;
 
        return r;
@@ -438,13 +558,18 @@ _MapDataControlImpl::AddValue(const String& dataId, const String& key,
        pArgList->Add(*(new String(dataId)));
        pArgList->Add(*(new String(key)));
        pArgList->Add(*(new String(value)));
+       long long argSize = dataId.GetLength() * sizeof(wchar_t);
+       argSize += key.GetLength() * sizeof(wchar_t);
+       argSize += value.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 (%lld) exceeds the maximum limit.", argSize);
 
        r = StartMapDataControl(_DATACONTROL_REQUEST_TYPE_MAP_INSERT, pArgList, &id);
        SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
 
        reqId = static_cast< RequestId >(id);
 
-       SysLog(NID_APP, "dataId: %ls, key: %ls, value: %ls, reqId: %d",
+       SysLog(NID_APP, "[DC_CALLER_SEND] data: %ls, key: %ls, value: %ls, req: %d",
                        dataId.GetPointer(), key.GetPointer(), value.GetPointer(), reqId);
 
        // fall through
@@ -473,13 +598,19 @@ _MapDataControlImpl::SetValue(const String& dataId, const String& key,
        pArgList->Add(*(new String(key)));
        pArgList->Add(*(new String(oldValue)));
        pArgList->Add(*(new String(newValue)));
+       long long argSize = dataId.GetLength() * sizeof(wchar_t);
+       argSize += key.GetLength() * sizeof(wchar_t);
+       argSize += oldValue.GetLength() * sizeof(wchar_t);
+       argSize += newValue.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 (%lld) exceeds the maximum limit.", argSize);
 
        r = StartMapDataControl(_DATACONTROL_REQUEST_TYPE_MAP_UPDATE, pArgList, &id);
        SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
 
        reqId = static_cast< RequestId >(id);
 
-       SysLog(NID_APP, "dataId: %ls, key: %ls, oldValue: %ls, newValue: %ls, reqId: %d",
+       SysLog(NID_APP, "[DC_CALLER_SEND] data: %ls, key: %ls, oldValue: %ls, newValue: %ls, req: %d",
                        dataId.GetPointer(), key.GetPointer(), oldValue.GetPointer(), newValue.GetPointer(), reqId);
 
        // fall through
@@ -507,13 +638,18 @@ _MapDataControlImpl::RemoveValue(const String& dataId, const String& key,
        pArgList->Add(*(new String(dataId)));
        pArgList->Add(*(new String(key)));
        pArgList->Add(*(new String(value)));
+       long long argSize = dataId.GetLength() * sizeof(wchar_t);
+       argSize += key.GetLength() * sizeof(wchar_t);
+       argSize += value.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 (%lld) exceeds the maximum limit.", argSize);
 
        r = StartMapDataControl(_DATACONTROL_REQUEST_TYPE_MAP_DELETE, pArgList, &id);
        SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
 
        reqId = static_cast< RequestId >(id);
 
-       SysLog(NID_APP, "dataId: %ls, key: %ls, value: %ls, reqId: %d",
+       SysLog(NID_APP, "[DC_CALLER_SEND] data: %ls, key: %ls, value: %ls, req: %d",
                        dataId.GetPointer(), key.GetPointer(), value.GetPointer(), reqId);
 
        // fall through
@@ -568,12 +704,15 @@ _MapDataControlImpl::CreateMapDataControl(const AppId& appId, const String& prov
        SysTryReturn(NID_APP, pDc != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient");
 
        _MapDataControlImpl* pDcImpl = _MapDataControlImpl::GetInstance(*pDc);
+       pDcImpl->__appId = appId;
+       pDcImpl->__providerId = providerId;
        unique_ptr<_MapDataControlEvent> pMapDataControlEvent(new (std::nothrow) _MapDataControlEvent);
        SysTryReturn(NID_IO, pMapDataControlEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
+       pDcImpl->__pRequestList = new (std::nothrow) LinkedList(SingleObjectDeleter);
+       SysTryReturn(NID_IO, pDcImpl->__pRequestList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
        pDcImpl->__pMapDataControlEvent = pMapDataControlEvent.release();
-       pDcImpl->__appId = appId;
-       pDcImpl->__providerId = providerId;
 
        if (access == L"readonly")
        {