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.
18 * @file FApp_MapDataControlImpl.cpp
19 * @brief This is the implementation for the %_MapDataControlImpl class.
23 #include <unique_ptr.h>
25 #include <appsvc/appsvc.h>
27 #include <FBaseInteger.h>
28 #include <FBaseString.h>
29 #include <FBaseRtIEventArg.h>
31 #include <FAppMapDataControl.h>
32 #include <FAppIMapDataControlResponseListener.h>
34 #include <FBaseSysLog.h>
36 #include "FApp_AppControlManager.h"
37 #include "FApp_MapDataControlImpl.h"
38 #include "FApp_AppArg.h"
39 #include "FApp_DataControlManager.h"
43 using namespace Tizen::Base;
44 using namespace Tizen::Base::Collection;
45 using namespace Tizen::Base::Runtime;
46 using namespace Tizen::App;
47 using namespace Tizen::Io;
49 namespace Tizen { namespace App
52 static const int MAX_REQUEST_COUNT = 128;
53 static const int REQUEST_THRESHOLD = 100;
54 static const int _MAX_ARGUMENT_SIZE = 16384; // 16KB
56 class _MapDataControlEventArg
60 _MapDataControlEventArg(_DataControlRequestType requestType, RequestId reqId, String providerId, String dataId,
61 IList* pResultValueList, bool providerResult, String* pErrorMsg)
62 : __requestType(requestType)
64 , __providerId(providerId)
66 , __pResultValueList(pResultValueList)
67 , __providerResult(providerResult)
68 , __pErrorMsg(pErrorMsg)
71 ~_MapDataControlEventArg(void)
73 if (__pResultValueList)
75 __pResultValueList->RemoveAll(true);
76 delete __pResultValueList;
81 _DataControlRequestType __requestType;
85 IList* __pResultValueList;
86 bool __providerResult;
90 class _MapDataControlEvent
94 virtual void FireImpl(IEventListener& listener, const IEventArg& arg);
98 _MapDataControlEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
100 const _MapDataControlEventArg* pArg = dynamic_cast<const _MapDataControlEventArg*>(&arg);
103 IMapDataControlResponseListener* pListener = dynamic_cast<IMapDataControlResponseListener*> (&listener);
104 if (pListener != null)
106 switch (pArg->__requestType)
108 case _DATACONTROL_REQUEST_TYPE_MAP_QUERY:
109 pListener->OnMapDataControlGetValueResponseReceived(pArg->__reqId, pArg->__providerId, pArg->__dataId,
110 *(pArg->__pResultValueList), pArg->__providerResult, pArg->__pErrorMsg);
112 case _DATACONTROL_REQUEST_TYPE_MAP_INSERT:
113 pListener->OnMapDataControlAddValueResponseReceived(pArg->__reqId, pArg->__providerId, pArg->__dataId,
114 pArg->__providerResult, pArg->__pErrorMsg);
116 case _DATACONTROL_REQUEST_TYPE_MAP_UPDATE:
117 pListener->OnMapDataControlSetValueResponseReceived(pArg->__reqId, pArg->__providerId, pArg->__dataId,
118 pArg->__providerResult, pArg->__pErrorMsg);
120 case _DATACONTROL_REQUEST_TYPE_MAP_DELETE:
121 pListener->OnMapDataControlRemoveValueResponseReceived(pArg->__reqId, pArg->__providerId, pArg->__dataId,
122 pArg->__providerResult, pArg->__pErrorMsg);
132 _MapDataControlImpl::_MapDataControlImpl(void)
133 : __access(_DATACONTROL_ACCESS_UNDEFINED)
134 , __pPreviousListener(null)
135 , __pMapDataControlEvent(null)
139 _MapDataControlImpl::~_MapDataControlImpl(void)
141 delete __pMapDataControlEvent;
145 _MapDataControlImpl::GetInstance(MapDataControl& dc)
147 return dc.__pMapDataControlImpl;
150 const _MapDataControlImpl*
151 _MapDataControlImpl::GetInstance(const MapDataControl& dc)
153 return dc.__pMapDataControlImpl;
157 _MapDataControlImpl::StartMapDataControl(int type, const IList* pDataList, int* pReq)
159 Integer* pReqId = null;
160 _DataControlRequestInfo* pReqInfo = null;
161 result r = E_SUCCESS;
164 _DataControlManager* pDcMgr = _DataControlManager::GetInstance();
166 // Check the request count of DataControl operation
167 int count = pDcMgr->GetRequestCount();
168 SysLog(NID_APP, "Current launch request count: %d", count);
170 if (count > REQUEST_THRESHOLD)
172 _AppManagerImpl* pImpl = _AppManagerImpl::GetInstance();
174 // Clear the request queue if the provider is terminated
175 if (!pImpl->IsRunning(__appId))
177 SysLog(NID_APP, "The request queue is cleared due to the invalid provider.");
179 pDcMgr->RemoveAllRequests();
183 SysTryReturnResult(NID_APP, count < MAX_REQUEST_COUNT, E_MAX_EXCEEDED, "The number of requests has exceeded the maximum limit.");
185 _AppArg* pArg = new(std::nothrow) _AppArg; // XXX: pArg will be released in _AppManagerImpl::LaunchApp().
186 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
188 pArg->Construct(*this, static_cast <_DataControlRequestType>(type), pDataList);
190 _AppControlManager* pAppManagerImpl = _AppControlManager::GetInstance();
192 if (__pMapDataControlEvent)
194 // reqId is system-wide id because the bundle is system-wide.
196 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pAppManagerImpl, pArg, MapDataControlCallback, __pMapDataControlEvent, -1);
197 req = reqObj.GetRequestNumber();
199 _DataControlManager* pDcMgr = _DataControlManager::GetInstance();
200 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pAppManagerImpl, pArg, MapDataControlCallback, pDcMgr, -1);
201 req = reqObj.GetRequestNumber();
203 pReqId = new (std::nothrow) Integer(req);
204 SysTryCatch(NID_APP, pReqId != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
205 "[E_OUT_OF_MEMORY] The memory is insufficient");
207 pReqInfo = new (std::nothrow) _DataControlRequestInfo(__pMapDataControlEvent);
208 SysTryCatch(NID_APP, pReqId != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
209 "[E_OUT_OF_MEMORY] The memory is insufficient");
211 r = pDcMgr->AddRequestInfo(pReqId, pReqInfo);
212 SysTryCatch(NID_APP, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[%s] Failed to add request info", GetErrorMessage(r));
214 r = pAppManagerImpl->LaunchApp(__appId, pArg, req);
217 SysPropagate(NID_APP, r);
219 pDcMgr->RemoveRequestInfo(*pReqId);
230 r = pAppManagerImpl->LaunchApp(__appId, pArg);
231 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
245 _MapDataControlImpl::GetValue(const String& dataId, const String& key,
246 RequestId& reqId, int pageNo, int countPerPage)
248 SysTryReturnResult(NID_APP, pageNo > 0, E_INVALID_ARG, "The specified pageNo parameter is less than 1");
249 SysTryReturnResult(NID_APP, countPerPage > 0, E_INVALID_ARG, "The specified countPerPage parameter is less than 1");
250 SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_READ) > 0, E_ILLEGAL_ACCESS,
251 "The GetValue query is not permitted by DataControl provider.");
253 String* pPageNo = null;
254 String* pCountPerPage = null;
256 result r = E_SUCCESS;
258 ArrayList* pArgList = new ArrayList();
259 pArgList->Construct();
261 pArgList->Add(*(new String(dataId)));
262 pArgList->Add(*(new String(key)));
263 long long argSize = dataId.GetLength() * sizeof(wchar_t);
264 argSize += key.GetLength() * sizeof(wchar_t);
265 SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
266 "[E_MAX_EXCEEDED] The size of sending argument (%lld) exceeds the maximum limit.", argSize);
268 pPageNo = new (std::nothrow) String();
269 pPageNo->Append(pageNo);
270 pArgList->Add(*pPageNo);
272 pCountPerPage = new (std::nothrow) String();
273 pCountPerPage->Append(countPerPage);
274 pArgList->Add(*pCountPerPage);
276 r = StartMapDataControl(_DATACONTROL_REQUEST_TYPE_MAP_QUERY, pArgList, &id);
277 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
279 reqId = static_cast< RequestId >(id);
281 SysLog(NID_APP, "[DC_CALLER_SEND] data: %ls, key: %ls, req: %d, pageNo: %d, countPerPage: %d",
282 dataId.GetPointer(), key.GetPointer(), reqId, pageNo, countPerPage);
286 pArgList->RemoveAll(true);
293 _MapDataControlImpl::MapDataControlCallback(void* data, _AppArg* pArg, _AppArg* pResArg, service_result_e res, int prop, int option)
295 ArrayList* pResultList = null;
297 String* pResult = null;
298 String* pProviderId = null;
299 String* pDataId = null;
300 String* pErrorMessage = null;
301 String* pErrorMsg = null;
302 String* pResultCount = null;
303 String* pPath = null;
304 ArrayList* pResultValueList = null;
310 bool providerResult = true;
311 //bundle* origBundle = null;
312 bundle* resBundle = null;
313 _MapDataControlEventArg* pEventArg = null;
314 const char* p = null;
315 result r = E_SUCCESS;
317 SysTryReturnResult(NID_APP, pResArg != null, E_INVALID_ARG, "Empty result callback.");
318 SysLog(NID_APP, "appsvc result value: %d", res);
320 resBundle = pResArg->GetBundle();
323 p = appsvc_get_data(resBundle, OSP_K_REQUEST_ID);
324 SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
328 _DataControlManager* pDcMgr = static_cast< _DataControlManager* >(data);
329 _DataControlRequestInfo* pReqInfo = pDcMgr->GetRequestInfo(key);
330 if (pReqInfo == null)
332 SysLog(NID_APP, "No request info of reqId %d", reqId);
336 _MapDataControlEvent* pMapDataControlEvent = dynamic_cast< _MapDataControlEvent* >(pReqInfo->GetEvent());
337 SysTryCatch(NID_APP, pMapDataControlEvent != null, r = E_SYSTEM, E_SYSTEM,
338 "[E_SYSTEM] invalid request info");
340 // Remove the request from the queue
341 SysLog(NID_APP, "Remove the request, req: %d", reqId);
343 pDcMgr->RemoveRequestInfo(key);
345 if (pMapDataControlEvent != null && typeid(pMapDataControlEvent) == typeid(_MapDataControlEvent*))
349 pResultList = _AppArg::GetListN(resBundle, OSP_K_ARG);
350 SysTryCatch(NID_APP, pResultList, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result");
352 pResult = dynamic_cast <String*>(pResultList->GetAt(0)); // result list[0]
353 SysTryCatch(NID_APP, pResult, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result");
354 Integer::Parse(*pResult, providerRes);
355 providerResult = static_cast< bool >(providerRes);
357 pErrorMessage = dynamic_cast< String* >(pResultList->GetAt(1)); // result list[1]
358 SysTryCatch(NID_APP, pErrorMessage, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result");
359 pErrorMsg = new (std::nothrow) String(*pErrorMessage);
360 SysTryCatch(NID_APP, pErrorMsg, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
361 "[E_OUT_OF_MEMORY] The memory is insufficient.");
364 //origBundle = pArg->GetBundle();
366 p = appsvc_get_data(resBundle, OSP_K_DATACONTROL_REQUEST_TYPE);
367 SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
368 requestType = atoi(p);
370 p = appsvc_get_data(resBundle, OSP_K_DATACONTROL_PROVIDER);
371 SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
372 pProviderId = new (std::nothrow) String(p);
373 SysTryCatch(NID_APP, pProviderId, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
374 "[E_OUT_OF_MEMORY] The memory is insufficient.");
376 p = appsvc_get_data(resBundle, OSP_K_DATACONTROL_DATA);
377 SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
378 pDataId = new (std::nothrow) String(p);
379 SysTryCatch(NID_APP, pDataId, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
380 "[E_OUT_OF_MEMORY] The memory is insufficient.");
382 version = pResArg->GetValue(OSP_K_DATACONTROL_PROTOCOL_VERSION);
384 SysSecureLog(NID_APP, "[DC_CALLER_RECV] version: %ls, provider result: %ld, requestType: %d, req: %d, provider: %ls, data: %ls, errorMsg: %ls",
385 version.GetPointer(), providerRes, requestType, reqId, pProviderId->GetPointer(), pDataId->GetPointer(), pErrorMsg->GetPointer());
387 switch (static_cast< _DataControlRequestType >(requestType))
389 case _DATACONTROL_REQUEST_TYPE_MAP_QUERY:
391 pResultValueList = new (std::nothrow) ArrayList(SingleObjectDeleter);
392 SysTryCatch(NID_APP, pResultValueList, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
393 "[E_OUT_OF_MEMORY] The memory is insufficient.");
395 if (providerResult == true)
397 pResultCount = dynamic_cast< String* >(pResultList->GetAt(2)); // result list[2]
398 SysTryCatch(NID_APP, pResultCount, delete pResultValueList, E_SYSTEM, "[E_SYSTEM] invalid result");
399 Integer::Parse(*pResultCount, resultCount);
400 SysLog(NID_APP, "[DC_CALLER_RECV] result count: %d", resultCount);
404 if (version == L"ver_2.1.0.1" || version == L"ver_2.1.0.2" || version == L"ver_2.1.0.3")
406 pPath = dynamic_cast< String* >(pResultList->GetAt(3)); // result list[3]
407 SysTryCatch(NID_APP, pPath, delete pResultValueList, E_SYSTEM, "[E_SYSTEM] invalid result");
408 SysLog(NID_APP, "[DC_CALLER_RECV] path: %ls", pPath->GetPointer());
410 unique_ptr< File > pFile(new (std::nothrow) File());
411 SysTryCatch(NID_APP, pFile, delete pResultValueList, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
413 r = pFile->Construct(*pPath, "r");
414 SysTryCatch(NID_APP, !IsFailed(r), delete pResultValueList, r, "[%s] Failed to open result set (%ls)",
415 GetErrorMessage(r), pPath->GetPointer());
420 int ret = pFile->Read(&length, sizeof(int));
421 SysTryCatch(NID_APP, ret, delete pResultValueList, E_SYSTEM,
422 "[E_SYSTEM] Failed to read data from the result set of data control provider.");
424 char* pValue = new (std::nothrow) char[length + 1];
425 SysTryCatch(NID_APP, pValue, delete pResultValueList, E_OUT_OF_MEMORY,
426 "[E_OUT_OF_MEMORY] The memory is insufficient.");
428 ret = pFile->Read(pValue, length);
431 SysLogException(NID_APP, E_SYSTEM,
432 "[E_SYSTEM] Failed to read data from the result set of data control provider.");
433 delete pResultValueList;
437 pValue[length] = '\0';
439 pResultValueList->Add(new (std::nothrow) String(pValue));
449 String* pValue = dynamic_cast< String* >(pResultList->GetAt(index)); // result list[3] ~
450 SysTryCatch(NID_APP, pValue, delete pResultValueList, E_SYSTEM, "[E_SYSTEM] invalid result");
452 pResultValueList->Add((new (std::nothrow) String(*pValue)));
461 r = File::Remove(*pPath);
462 SysTryLog(NID_APP, !IsFailed(r), "Failed to remove result: %ls", pPath->GetPointer());
466 pEventArg = new (std::nothrow) _MapDataControlEventArg(_DATACONTROL_REQUEST_TYPE_MAP_QUERY, static_cast <RequestId>(reqId),
467 *pProviderId, *pDataId, pResultValueList, providerResult, pErrorMsg);
468 SysTryCatch(NID_APP, pEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
469 pMapDataControlEvent->Fire(*pEventArg);
473 case _DATACONTROL_REQUEST_TYPE_MAP_INSERT:
475 pEventArg = new (std::nothrow) _MapDataControlEventArg(_DATACONTROL_REQUEST_TYPE_MAP_INSERT, static_cast <RequestId>(reqId),
476 *pProviderId, *pDataId, null, providerResult, pErrorMsg);
477 SysTryCatch(NID_APP, pEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
478 pMapDataControlEvent->Fire(*pEventArg);
481 case _DATACONTROL_REQUEST_TYPE_MAP_UPDATE:
483 pEventArg = new (std::nothrow) _MapDataControlEventArg(_DATACONTROL_REQUEST_TYPE_MAP_UPDATE, static_cast <RequestId>(reqId),
484 *pProviderId, *pDataId, null, providerResult, pErrorMsg);
485 SysTryCatch(NID_APP, pEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
486 pMapDataControlEvent->Fire(*pEventArg);
489 case _DATACONTROL_REQUEST_TYPE_MAP_DELETE:
491 pEventArg = new (std::nothrow) _MapDataControlEventArg(_DATACONTROL_REQUEST_TYPE_MAP_DELETE, static_cast <RequestId>(reqId),
492 *pProviderId, *pDataId, null, providerResult, pErrorMsg);
493 SysTryCatch(NID_APP, pEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
494 pMapDataControlEvent->Fire(*pEventArg);
501 pResultList->RemoveAll(true);
507 p = appsvc_get_data(pArg->GetBundle(), OSP_K_REQUEST_ID);
508 SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
509 launchReqId = atoi(p);
516 pResultList->RemoveAll(true);
525 _MapDataControlImpl::AddValue(const String& dataId, const String& key,
526 const String& value, RequestId& reqId)
528 SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_WRITE) > 0, E_ILLEGAL_ACCESS,
529 "The AddValue query is not permitted by DataControl provider.");
532 result r = E_SUCCESS;
534 ArrayList* pArgList = null;
535 pArgList = new ArrayList();
536 pArgList->Construct();
538 pArgList->Add(*(new String(dataId)));
539 pArgList->Add(*(new String(key)));
540 pArgList->Add(*(new String(value)));
541 long long argSize = dataId.GetLength() * sizeof(wchar_t);
542 argSize += key.GetLength() * sizeof(wchar_t);
543 argSize += value.GetLength() * sizeof(wchar_t);
544 SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
545 "[E_MAX_EXCEEDED] The size of sending argument (%lld) exceeds the maximum limit.", argSize);
547 r = StartMapDataControl(_DATACONTROL_REQUEST_TYPE_MAP_INSERT, pArgList, &id);
548 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
550 reqId = static_cast< RequestId >(id);
552 SysLog(NID_APP, "[DC_CALLER_SEND] data: %ls, key: %ls, value: %ls, req: %d",
553 dataId.GetPointer(), key.GetPointer(), value.GetPointer(), reqId);
557 pArgList->RemoveAll(true);
564 _MapDataControlImpl::SetValue(const String& dataId, const String& key,
565 const String& oldValue, const String& newValue, RequestId& reqId)
567 SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_WRITE) > 0, E_ILLEGAL_ACCESS,
568 "The SetValue query is not permitted by DataControl provider.");
571 result r = E_SUCCESS;
573 ArrayList* pArgList = null;
574 pArgList = new ArrayList();
575 pArgList->Construct();
577 pArgList->Add(*(new String(dataId)));
578 pArgList->Add(*(new String(key)));
579 pArgList->Add(*(new String(oldValue)));
580 pArgList->Add(*(new String(newValue)));
581 long long argSize = dataId.GetLength() * sizeof(wchar_t);
582 argSize += key.GetLength() * sizeof(wchar_t);
583 argSize += oldValue.GetLength() * sizeof(wchar_t);
584 argSize += newValue.GetLength() * sizeof(wchar_t);
585 SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
586 "[E_MAX_EXCEEDED] The size of sending argument (%lld) exceeds the maximum limit.", argSize);
588 r = StartMapDataControl(_DATACONTROL_REQUEST_TYPE_MAP_UPDATE, pArgList, &id);
589 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
591 reqId = static_cast< RequestId >(id);
593 SysLog(NID_APP, "[DC_CALLER_SEND] data: %ls, key: %ls, oldValue: %ls, newValue: %ls, req: %d",
594 dataId.GetPointer(), key.GetPointer(), oldValue.GetPointer(), newValue.GetPointer(), reqId);
598 pArgList->RemoveAll(true);
605 _MapDataControlImpl::RemoveValue(const String& dataId, const String& key,
606 const String& value, RequestId& reqId)
608 SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_WRITE) > 0, E_ILLEGAL_ACCESS,
609 "The RemoveValue query is not permitted by DataControl provider.");
612 result r = E_SUCCESS;
614 ArrayList* pArgList = null;
615 pArgList = new ArrayList();
616 pArgList->Construct();
618 pArgList->Add(*(new String(dataId)));
619 pArgList->Add(*(new String(key)));
620 pArgList->Add(*(new String(value)));
621 long long argSize = dataId.GetLength() * sizeof(wchar_t);
622 argSize += key.GetLength() * sizeof(wchar_t);
623 argSize += value.GetLength() * sizeof(wchar_t);
624 SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
625 "[E_MAX_EXCEEDED] The size of sending argument (%lld) exceeds the maximum limit.", argSize);
627 r = StartMapDataControl(_DATACONTROL_REQUEST_TYPE_MAP_DELETE, pArgList, &id);
628 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
630 reqId = static_cast< RequestId >(id);
632 SysLog(NID_APP, "[DC_CALLER_SEND] data: %ls, key: %ls, value: %ls, req: %d",
633 dataId.GetPointer(), key.GetPointer(), value.GetPointer(), reqId);
637 pArgList->RemoveAll(true);
644 _MapDataControlImpl::SetMapDataControlResponseListener(IMapDataControlResponseListener* pListener)
646 result r = E_SUCCESS;
648 if (__pPreviousListener != null)
650 r = __pMapDataControlEvent->RemoveListener(*__pPreviousListener);
651 SysTryReturnResult(NID_APP, !IsFailed(r), E_SYSTEM, "Remove listener failed.");
652 __pPreviousListener = null;
655 if (pListener != null)
657 r = __pMapDataControlEvent->AddListener(*pListener);
662 case E_OBJ_ALREADY_EXIST:
664 case E_INVALID_OPERATION:
665 SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] The thread setting the listener is worker thread.");
668 SysLogException(NID_APP, r, "[%s] Propagating to caller...", GetErrorMessage(r));
674 __pPreviousListener = pListener;
681 _MapDataControlImpl::CreateMapDataControl(const AppId& appId, const String& providerId, const String& access)
683 unique_ptr<MapDataControl> pDc(new (std::nothrow) MapDataControl);
684 SysTryReturn(NID_APP, pDc != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient");
686 _MapDataControlImpl* pDcImpl = _MapDataControlImpl::GetInstance(*pDc);
687 unique_ptr<_MapDataControlEvent> pMapDataControlEvent(new (std::nothrow) _MapDataControlEvent);
688 SysTryReturn(NID_IO, pMapDataControlEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
690 pDcImpl->__pMapDataControlEvent = pMapDataControlEvent.release();
691 pDcImpl->__appId = appId;
692 pDcImpl->__providerId = providerId;
694 if (access == L"readonly")
696 pDcImpl->__access = _DATACONTROL_ACCESS_READ;
698 else if (access == L"writeonly")
700 pDcImpl->__access = _DATACONTROL_ACCESS_WRITE;
702 else if (access == L"readwrite")
704 pDcImpl->__access = _DATACONTROL_ACCESS_READWRITE;
708 pDcImpl->__access = _DATACONTROL_ACCESS_UNDEFINED;
709 SysLog(NID_IO, "The accessibility of DataControl provider is invalid.");
712 return pDc.release();