2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FApp_MapDataControlImpl.cpp
20 * @brief This is the implementation for the %_MapDataControlImpl class.
25 #include <unique_ptr.h>
27 #include <appsvc/appsvc.h>
29 #include <FBaseInteger.h>
30 #include <FBaseString.h>
31 #include <FBaseRtIEventArg.h>
33 #include <FAppMapDataControl.h>
34 #include <FAppIMapDataControlResponseListener.h>
36 #include <FBaseSysLog.h>
38 #include "FApp_AppControlManager.h"
39 #include "FApp_MapDataControlImpl.h"
40 #include "FApp_AppArg.h"
41 #include "FApp_DataControlManager.h"
45 using namespace Tizen::Base;
46 using namespace Tizen::Base::Collection;
47 using namespace Tizen::Base::Runtime;
48 using namespace Tizen::App;
49 using namespace Tizen::Io;
51 namespace Tizen { namespace App
54 static const int MAX_REQUEST_COUNT = 128;
55 static const int _MAX_ARGUMENT_SIZE = 16384; // 16KB
57 class _MapDataControlEventArg
61 _MapDataControlEventArg(_DataControlRequestType requestType, RequestId reqId, String providerId, String dataId,
62 IList* pResultValueList, bool providerResult, String* pErrorMsg)
63 : __requestType(requestType)
65 , __providerId(providerId)
67 , __pResultValueList(pResultValueList)
68 , __providerResult(providerResult)
69 , __pErrorMsg(pErrorMsg)
72 ~_MapDataControlEventArg(void)
74 if (__pResultValueList)
76 __pResultValueList->RemoveAll(true);
77 delete __pResultValueList;
82 _DataControlRequestType __requestType;
86 IList* __pResultValueList;
87 bool __providerResult;
91 class _MapDataControlEvent
95 virtual void FireImpl(IEventListener& listener, const IEventArg& arg);
99 _MapDataControlEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
101 const _MapDataControlEventArg* pArg = dynamic_cast<const _MapDataControlEventArg*>(&arg);
104 IMapDataControlResponseListener* pListener = dynamic_cast<IMapDataControlResponseListener*> (&listener);
105 if (pListener != null)
107 switch (pArg->__requestType)
109 case _DATACONTROL_REQUEST_TYPE_MAP_QUERY:
110 pListener->OnMapDataControlGetValueResponseReceived(pArg->__reqId, pArg->__providerId, pArg->__dataId,
111 *(pArg->__pResultValueList), pArg->__providerResult, pArg->__pErrorMsg);
113 case _DATACONTROL_REQUEST_TYPE_MAP_INSERT:
114 pListener->OnMapDataControlAddValueResponseReceived(pArg->__reqId, pArg->__providerId, pArg->__dataId,
115 pArg->__providerResult, pArg->__pErrorMsg);
117 case _DATACONTROL_REQUEST_TYPE_MAP_UPDATE:
118 pListener->OnMapDataControlSetValueResponseReceived(pArg->__reqId, pArg->__providerId, pArg->__dataId,
119 pArg->__providerResult, pArg->__pErrorMsg);
121 case _DATACONTROL_REQUEST_TYPE_MAP_DELETE:
122 pListener->OnMapDataControlRemoveValueResponseReceived(pArg->__reqId, pArg->__providerId, pArg->__dataId,
123 pArg->__providerResult, pArg->__pErrorMsg);
133 _MapDataControlImpl::_MapDataControlImpl(void)
136 , __access(_DATACONTROL_ACCESS_UNDEFINED)
137 , __pPreviousListener(null)
138 , __pMapDataControlEvent(null)
142 _MapDataControlImpl::~_MapDataControlImpl(void)
144 delete __pMapDataControlEvent;
148 _MapDataControlImpl::GetInstance(MapDataControl& dc)
150 return dc.__pMapDataControlImpl;
153 const _MapDataControlImpl*
154 _MapDataControlImpl::GetInstance(const MapDataControl& dc)
156 return dc.__pMapDataControlImpl;
160 _MapDataControlImpl::StartMapDataControl(int type, const IList* pDataList, int* pReq)
162 Integer* pReqId = null;
163 _DataControlRequestInfo* pReqInfo = null;
164 result r = E_SUCCESS;
167 _AppControlManager* pAppManagerImpl = _AppControlManager::GetInstance();
169 // Check the request count of DataControl operation
170 int count = pAppManagerImpl->GetLaunchRequestCount();
171 SysLog(NID_APP, "Current launch request count: %d", count);
173 SysTryReturnResult(NID_APP, count < MAX_REQUEST_COUNT, E_MAX_EXCEEDED, "The number of requests has exceeded the maximum limit.");
175 _AppArg* pArg = new(std::nothrow) _AppArg; // XXX: pArg will be released in _AppManagerImpl::LaunchApp().
176 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
178 pArg->Construct(*this, static_cast <_DataControlRequestType>(type), pDataList);
180 if (__pMapDataControlEvent)
182 // reqId is system-wide id because the bundle is system-wide.
184 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pAppManagerImpl, pArg, MapDataControlCallback, __pMapDataControlEvent, -1);
185 req = reqObj.GetRequestNumber();
187 _DataControlManager* pDcMgr = _DataControlManager::GetInstance();
188 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pAppManagerImpl, pArg, MapDataControlCallback, pDcMgr, -1);
189 req = reqObj.GetRequestNumber();
191 pReqId = new (std::nothrow) Integer(req);
192 SysTryCatch(NID_APP, pReqId != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
193 "[E_OUT_OF_MEMORY] The memory is insufficient");
195 pReqInfo = new (std::nothrow) _DataControlRequestInfo(__pMapDataControlEvent);
196 SysTryCatch(NID_APP, pReqId != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
197 "[E_OUT_OF_MEMORY] The memory is insufficient");
199 r = pDcMgr->AddRequestInfo(pReqId, pReqInfo);
200 SysTryCatch(NID_APP, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[%s] Failed to add request info", GetErrorMessage(r));
202 r = pAppManagerImpl->LaunchApp(__appId, pArg, req);
205 SysPropagate(NID_APP, r);
207 pDcMgr->RemoveRequestInfo(*pReqId);
219 r = pAppManagerImpl->LaunchApp(__appId, pArg);
220 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
234 _MapDataControlImpl::GetValue(const String& dataId, const String& key,
235 RequestId& reqId, int pageNo, int countPerPage)
237 SysTryReturnResult(NID_APP, pageNo > 0, E_INVALID_ARG, "The specified pageNo parameter is less than 1");
238 SysTryReturnResult(NID_APP, countPerPage > 0, E_INVALID_ARG, "The specified countPerPage parameter is less than 1");
239 SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_READ) > 0, E_ILLEGAL_ACCESS,
240 "The GetValue query is not permitted by DataControl provider.");
242 String* pPageNo = null;
243 String* pCountPerPage = null;
245 result r = E_SUCCESS;
247 ArrayList* pArgList = new ArrayList();
248 pArgList->Construct();
250 pArgList->Add(*(new String(dataId)));
251 pArgList->Add(*(new String(key)));
252 long long argSize = dataId.GetLength() * sizeof(wchar_t);
253 argSize += key.GetLength() * sizeof(wchar_t);
254 SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
255 "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
257 pPageNo = new (std::nothrow) String();
258 pPageNo->Append(pageNo);
259 pArgList->Add(*pPageNo);
261 pCountPerPage = new (std::nothrow) String();
262 pCountPerPage->Append(countPerPage);
263 pArgList->Add(*pCountPerPage);
265 r = StartMapDataControl(_DATACONTROL_REQUEST_TYPE_MAP_QUERY, pArgList, &id);
266 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
268 reqId = static_cast< RequestId >(id);
270 SysLog(NID_APP, "[DC_CALLER_SEND] data: %ls, key: %ls, req: %d, pageNo: %d, countPerPage: %d",
271 dataId.GetPointer(), key.GetPointer(), reqId, pageNo, countPerPage);
275 pArgList->RemoveAll(true);
282 _MapDataControlImpl::MapDataControlCallback(void* data, _AppArg* pArg, _AppArg* pResArg, service_result_e res, int prop, int option)
284 ArrayList* pResultList = null;
286 String* pResult = null;
287 String* pProviderId = null;
288 String* pDataId = null;
289 String* pErrorMessage = null;
290 String* pErrorMsg = null;
291 String* pResultCount = null;
292 String* pPath = null;
293 ArrayList* pResultValueList = null;
299 bool providerResult = true;
300 //bundle* origBundle = null;
301 bundle* resBundle = null;
302 _MapDataControlEventArg* pEventArg = null;
303 const char* p = null;
304 result r = E_SUCCESS;
306 SysTryReturnResult(NID_APP, pResArg != null, E_INVALID_ARG, "Empty result callback.");
307 SysLog(NID_APP, "appsvc result value: %d", res);
309 resBundle = pResArg->GetBundle();
312 p = appsvc_get_data(resBundle, OSP_K_REQUEST_ID);
313 SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
317 _DataControlManager* pDcMgr = static_cast< _DataControlManager* >(data);
318 _DataControlRequestInfo* pReqInfo = pDcMgr->GetRequestInfo(key);
319 SysTryCatch(NID_APP, pReqInfo != null, r = E_SYSTEM, E_SYSTEM,
320 "[E_SYSTEM] Failed to get request info");
322 _MapDataControlEvent* pMapDataControlEvent = dynamic_cast< _MapDataControlEvent* >(pReqInfo->GetEvent());
323 SysTryCatch(NID_APP, pMapDataControlEvent != null, r = E_SYSTEM, E_SYSTEM,
324 "[E_SYSTEM] invalid request info");
326 pDcMgr->RemoveRequestInfo(key);
328 if (pMapDataControlEvent != null && typeid(pMapDataControlEvent) == typeid(_MapDataControlEvent*))
332 pResultList = _AppArg::GetListN(resBundle, OSP_K_ARG);
333 SysTryCatch(NID_APP, pResultList, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result");
335 pResult = dynamic_cast <String*>(pResultList->GetAt(0)); // result list[0]
336 SysTryCatch(NID_APP, pResult, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result");
337 Integer::Parse(*pResult, providerRes);
338 providerResult = static_cast< bool >(providerRes);
340 pErrorMessage = dynamic_cast< String* >(pResultList->GetAt(1)); // result list[1]
341 SysTryCatch(NID_APP, pErrorMessage, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result");
342 pErrorMsg = new (std::nothrow) String(*pErrorMessage);
343 SysTryCatch(NID_APP, pErrorMsg, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
344 "[E_OUT_OF_MEMORY] The memory is insufficient.");
347 //origBundle = pArg->GetBundle();
349 p = appsvc_get_data(resBundle, OSP_K_DATACONTROL_REQUEST_TYPE);
350 SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
351 requestType = atoi(p);
353 p = appsvc_get_data(resBundle, OSP_K_DATACONTROL_PROVIDER);
354 SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
355 pProviderId = new (std::nothrow) String(p);
356 SysTryCatch(NID_APP, pProviderId, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
357 "[E_OUT_OF_MEMORY] The memory is insufficient.");
359 p = appsvc_get_data(resBundle, OSP_K_DATACONTROL_DATA);
360 SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
361 pDataId = new (std::nothrow) String(p);
362 SysTryCatch(NID_APP, pDataId, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
363 "[E_OUT_OF_MEMORY] The memory is insufficient.");
365 version = pResArg->GetValue(OSP_K_DATACONTROL_PROTOCOL_VERSION);
367 SysLog(NID_APP, "[DC_CALLER_RECV] version: %ls, provider result: %ld, requestType: %d, req: %d, provider: %ls, data: %ls, errorMsg: %ls",
368 version.GetPointer(), providerRes, requestType, reqId, pProviderId->GetPointer(), pDataId->GetPointer(), pErrorMsg->GetPointer());
370 switch (static_cast< _DataControlRequestType >(requestType))
372 case _DATACONTROL_REQUEST_TYPE_MAP_QUERY:
374 pResultValueList = new (std::nothrow) ArrayList(SingleObjectDeleter);
375 SysTryCatch(NID_APP, pResultValueList, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
376 "[E_OUT_OF_MEMORY] The memory is insufficient.");
378 if (providerResult == true)
380 pResultCount = dynamic_cast< String* >(pResultList->GetAt(2)); // result list[2]
381 SysTryCatch(NID_APP, pResultCount, delete pResultValueList, E_SYSTEM, "[E_SYSTEM] invalid result");
382 Integer::Parse(*pResultCount, resultCount);
383 SysLog(NID_APP, "[DC_CALLER_RECV] result count: %d", resultCount);
387 if (version == L"ver_2.1.0.1")
389 pPath = dynamic_cast< String* >(pResultList->GetAt(3)); // result list[3]
390 SysTryCatch(NID_APP, pPath, delete pResultValueList, E_SYSTEM, "[E_SYSTEM] invalid result");
391 SysLog(NID_APP, "[DC_CALLER_RECV] path: %ls", pPath->GetPointer());
393 unique_ptr< File > pFile(new (std::nothrow) File());
394 SysTryCatch(NID_APP, pFile, delete pResultValueList, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
396 r = pFile->Construct(*pPath, "r");
397 SysTryCatch(NID_APP, !IsFailed(r), delete pResultValueList, r, "[%s] Failed to open result set (%ls)",
398 GetErrorMessage(r), pPath->GetPointer());
403 int ret = pFile->Read(&length, sizeof(int));
404 SysTryCatch(NID_APP, ret, delete pResultValueList, E_SYSTEM,
405 "[E_SYSTEM] Failed to read data from the result set of data control provider.");
407 char* pValue = new (std::nothrow) char[length + 1];
408 SysTryCatch(NID_APP, pValue, delete pResultValueList, E_OUT_OF_MEMORY,
409 "[E_OUT_OF_MEMORY] The memory is insufficient.");
411 ret = pFile->Read(pValue, length);
414 SysLogException(NID_APP, E_SYSTEM,
415 "[E_SYSTEM] Failed to read data from the result set of data control provider.");
416 delete pResultValueList;
420 pValue[length] = '\0';
422 pResultValueList->Add(new (std::nothrow) String(pValue));
432 String* pValue = dynamic_cast< String* >(pResultList->GetAt(index)); // result list[3] ~
433 SysTryCatch(NID_APP, pValue, delete pResultValueList, E_SYSTEM, "[E_SYSTEM] invalid result");
435 pResultValueList->Add((new (std::nothrow) String(*pValue)));
444 r = File::Remove(*pPath);
445 SysTryLog(NID_APP, !IsFailed(r), "Failed to remove result: %ls", pPath->GetPointer());
449 pEventArg = new (std::nothrow) _MapDataControlEventArg(_DATACONTROL_REQUEST_TYPE_MAP_QUERY, static_cast <RequestId>(reqId),
450 *pProviderId, *pDataId, pResultValueList, providerResult, pErrorMsg);
451 SysTryCatch(NID_APP, pEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
452 pMapDataControlEvent->Fire(*pEventArg);
456 case _DATACONTROL_REQUEST_TYPE_MAP_INSERT:
458 pEventArg = new (std::nothrow) _MapDataControlEventArg(_DATACONTROL_REQUEST_TYPE_MAP_INSERT, static_cast <RequestId>(reqId),
459 *pProviderId, *pDataId, null, providerResult, pErrorMsg);
460 SysTryCatch(NID_APP, pEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
461 pMapDataControlEvent->Fire(*pEventArg);
464 case _DATACONTROL_REQUEST_TYPE_MAP_UPDATE:
466 pEventArg = new (std::nothrow) _MapDataControlEventArg(_DATACONTROL_REQUEST_TYPE_MAP_UPDATE, static_cast <RequestId>(reqId),
467 *pProviderId, *pDataId, null, 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);
472 case _DATACONTROL_REQUEST_TYPE_MAP_DELETE:
474 pEventArg = new (std::nothrow) _MapDataControlEventArg(_DATACONTROL_REQUEST_TYPE_MAP_DELETE, static_cast <RequestId>(reqId),
475 *pProviderId, *pDataId, null, providerResult, pErrorMsg);
476 SysTryCatch(NID_APP, pEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
477 pMapDataControlEvent->Fire(*pEventArg);
484 pResultList->RemoveAll(true);
490 p = appsvc_get_data(pArg->GetBundle(), OSP_K_REQUEST_ID);
491 SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
492 launchReqId = atoi(p);
494 // Remove the request count
495 SysLog(NID_APP, "Remove a launch request: req: %d", launchReqId);
496 _AppControlManager::GetInstance()->RemoveLaunchRequest(launchReqId);
503 pResultList->RemoveAll(true);
512 _MapDataControlImpl::AddValue(const String& dataId, const String& key,
513 const String& value, RequestId& reqId)
515 SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_WRITE) > 0, E_ILLEGAL_ACCESS,
516 "The AddValue query is not permitted by DataControl provider.");
519 result r = E_SUCCESS;
521 ArrayList* pArgList = null;
522 pArgList = new ArrayList();
523 pArgList->Construct();
525 pArgList->Add(*(new String(dataId)));
526 pArgList->Add(*(new String(key)));
527 pArgList->Add(*(new String(value)));
528 long long argSize = dataId.GetLength() * sizeof(wchar_t);
529 argSize += key.GetLength() * sizeof(wchar_t);
530 argSize += value.GetLength() * sizeof(wchar_t);
531 SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
532 "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
534 r = StartMapDataControl(_DATACONTROL_REQUEST_TYPE_MAP_INSERT, pArgList, &id);
535 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
537 reqId = static_cast< RequestId >(id);
539 SysLog(NID_APP, "[DC_CALLER_SEND] data: %ls, key: %ls, value: %ls, req: %d",
540 dataId.GetPointer(), key.GetPointer(), value.GetPointer(), reqId);
544 pArgList->RemoveAll(true);
551 _MapDataControlImpl::SetValue(const String& dataId, const String& key,
552 const String& oldValue, const String& newValue, RequestId& reqId)
554 SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_WRITE) > 0, E_ILLEGAL_ACCESS,
555 "The SetValue query is not permitted by DataControl provider.");
558 result r = E_SUCCESS;
560 ArrayList* pArgList = null;
561 pArgList = new ArrayList();
562 pArgList->Construct();
564 pArgList->Add(*(new String(dataId)));
565 pArgList->Add(*(new String(key)));
566 pArgList->Add(*(new String(oldValue)));
567 pArgList->Add(*(new String(newValue)));
568 long long argSize = dataId.GetLength() * sizeof(wchar_t);
569 argSize += key.GetLength() * sizeof(wchar_t);
570 argSize += oldValue.GetLength() * sizeof(wchar_t);
571 argSize += newValue.GetLength() * sizeof(wchar_t);
572 SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
573 "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
575 r = StartMapDataControl(_DATACONTROL_REQUEST_TYPE_MAP_UPDATE, pArgList, &id);
576 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
578 reqId = static_cast< RequestId >(id);
580 SysLog(NID_APP, "[DC_CALLER_SEND] data: %ls, key: %ls, oldValue: %ls, newValue: %ls, req: %d",
581 dataId.GetPointer(), key.GetPointer(), oldValue.GetPointer(), newValue.GetPointer(), reqId);
585 pArgList->RemoveAll(true);
592 _MapDataControlImpl::RemoveValue(const String& dataId, const String& key,
593 const String& value, RequestId& reqId)
595 SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_WRITE) > 0, E_ILLEGAL_ACCESS,
596 "The RemoveValue query is not permitted by DataControl provider.");
599 result r = E_SUCCESS;
601 ArrayList* pArgList = null;
602 pArgList = new ArrayList();
603 pArgList->Construct();
605 pArgList->Add(*(new String(dataId)));
606 pArgList->Add(*(new String(key)));
607 pArgList->Add(*(new String(value)));
608 long long argSize = dataId.GetLength() * sizeof(wchar_t);
609 argSize += key.GetLength() * sizeof(wchar_t);
610 argSize += value.GetLength() * sizeof(wchar_t);
611 SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
612 "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
614 r = StartMapDataControl(_DATACONTROL_REQUEST_TYPE_MAP_DELETE, pArgList, &id);
615 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
617 reqId = static_cast< RequestId >(id);
619 SysLog(NID_APP, "[DC_CALLER_SEND] data: %ls, key: %ls, value: %ls, req: %d",
620 dataId.GetPointer(), key.GetPointer(), value.GetPointer(), reqId);
624 pArgList->RemoveAll(true);
631 _MapDataControlImpl::SetMapDataControlResponseListener(IMapDataControlResponseListener* pListener)
633 result r = E_SUCCESS;
635 if (__pPreviousListener != null)
637 r = __pMapDataControlEvent->RemoveListener(*__pPreviousListener);
638 SysTryReturnResult(NID_APP, !IsFailed(r), E_SYSTEM, "Remove listener failed.");
639 __pPreviousListener = null;
642 if (pListener != null)
644 r = __pMapDataControlEvent->AddListener(*pListener);
649 case E_OBJ_ALREADY_EXIST:
651 case E_INVALID_OPERATION:
652 SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] The thread setting the listener is worker thread.");
655 SysLogException(NID_APP, r, "[%s] Propagating to caller...", GetErrorMessage(r));
661 __pPreviousListener = pListener;
668 _MapDataControlImpl::CreateMapDataControl(const AppId& appId, const String& providerId, const String& access)
670 unique_ptr<MapDataControl> pDc(new (std::nothrow) MapDataControl);
671 SysTryReturn(NID_APP, pDc != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient");
673 _MapDataControlImpl* pDcImpl = _MapDataControlImpl::GetInstance(*pDc);
674 unique_ptr<_MapDataControlEvent> pMapDataControlEvent(new (std::nothrow) _MapDataControlEvent);
675 SysTryReturn(NID_IO, pMapDataControlEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
677 pDcImpl->__pMapDataControlEvent = pMapDataControlEvent.release();
678 pDcImpl->__appId = appId;
679 pDcImpl->__providerId = providerId;
681 if (access == L"readonly")
683 pDcImpl->__access = _DATACONTROL_ACCESS_READ;
685 else if (access == L"writeonly")
687 pDcImpl->__access = _DATACONTROL_ACCESS_WRITE;
689 else if (access == L"readwrite")
691 pDcImpl->__access = _DATACONTROL_ACCESS_READWRITE;
695 pDcImpl->__access = _DATACONTROL_ACCESS_UNDEFINED;
696 SysLog(NID_IO, "The accessibility of DataControl provider is invalid.");
699 return pDc.release();