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 <FBaseColLinkedList.h>
30 #include <FBaseColArrayList.h>
31 #include <FBaseRtIEventArg.h>
33 #include <FAppMapDataControl.h>
34 #include <FAppIMapDataControlResponseListener.h>
35 #include <FBaseSysLog.h>
37 #include "FApp_AppControlManager.h"
38 #include "FApp_MapDataControlImpl.h"
39 #include "FApp_AppArg.h"
40 #include "FApp_DataControlManager.h"
44 using namespace Tizen::Base;
45 using namespace Tizen::Base::Collection;
46 using namespace Tizen::Base::Runtime;
47 using namespace Tizen::App;
48 using namespace Tizen::Io;
50 namespace Tizen { namespace App
53 static const int MAX_REQUEST_COUNT = 128;
54 static const int REQUEST_THRESHOLD = 100;
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)
134 : __access(_DATACONTROL_ACCESS_UNDEFINED)
135 , __pPreviousListener(null)
136 , __pMapDataControlEvent(null)
140 _MapDataControlImpl::~_MapDataControlImpl(void)
142 delete __pMapDataControlEvent;
144 _DataControlManager* pDcMgr = _DataControlManager::GetInstance();
146 IEnumerator* pEnum = __pRequestList->GetEnumeratorN();
147 while (pEnum->MoveNext() == E_SUCCESS)
149 Integer* pReqId = dynamic_cast< Integer* >(pEnum->GetCurrent());
152 pDcMgr->RemoveRequestInfo(*pReqId);
155 delete __pRequestList;
159 _MapDataControlImpl::GetInstance(MapDataControl& dc)
161 return dc.__pMapDataControlImpl;
164 const _MapDataControlImpl*
165 _MapDataControlImpl::GetInstance(const MapDataControl& dc)
167 return dc.__pMapDataControlImpl;
171 _MapDataControlImpl::StartMapDataControl(int type, const IList* pDataList, int* pReq)
173 Integer* pReqId = null;
174 _DataControlRequestInfo* pReqInfo = null;
175 result r = E_SUCCESS;
178 _DataControlManager* pDcMgr = _DataControlManager::GetInstance();
180 // Check the request count of DataControl operation
181 int count = pDcMgr->GetRequestCount();
182 SysLog(NID_APP, "Current launch request count: %d", count);
184 if (count > REQUEST_THRESHOLD)
186 _AppManagerImpl* pImpl = _AppManagerImpl::GetInstance();
188 // Clear the request queue if the provider is terminated
189 if (!pImpl->IsRunning(__appId))
191 SysLog(NID_APP, "The request queue is cleared due to the invalid provider.");
193 pDcMgr->RemoveAllRequests();
197 SysTryReturnResult(NID_APP, count < MAX_REQUEST_COUNT, E_MAX_EXCEEDED, "The number of requests has exceeded the maximum limit.");
199 _AppArg* pArg = new(std::nothrow) _AppArg; // XXX: pArg will be released in _AppManagerImpl::LaunchApp().
200 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
202 pArg->Construct(*this, static_cast <_DataControlRequestType>(type), pDataList);
204 _AppControlManager* pAppManagerImpl = _AppControlManager::GetInstance();
206 if (__pMapDataControlEvent)
208 // reqId is system-wide id because the bundle is system-wide.
210 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pAppManagerImpl, pArg, MapDataControlCallback, __pMapDataControlEvent, -1);
211 req = reqObj.GetRequestNumber();
213 _DataControlManager* pDcMgr = _DataControlManager::GetInstance();
214 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pAppManagerImpl, pArg, MapDataControlCallback, pDcMgr, -1);
215 req = reqObj.GetRequestNumber();
217 pReqId = new (std::nothrow) Integer(req);
218 SysTryCatch(NID_APP, pReqId != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
219 "[E_OUT_OF_MEMORY] The memory is insufficient");
221 pReqInfo = new (std::nothrow) _DataControlRequestInfo(__pMapDataControlEvent);
222 SysTryCatch(NID_APP, pReqInfo != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
223 "[E_OUT_OF_MEMORY] The memory is insufficient");
224 pReqInfo->SetMapDataControlImpl(this);
226 r = pDcMgr->AddRequestInfo(pReqId, pReqInfo);
227 SysTryCatch(NID_APP, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[%s] Failed to add request info", GetErrorMessage(r));
229 r = pAppManagerImpl->LaunchApp(__appId, pArg, req);
232 SysPropagate(NID_APP, r);
234 pDcMgr->RemoveRequestInfo(*pReqId);
238 __pRequestList->Add(new (std::nothrow) Integer(req));
247 r = pAppManagerImpl->LaunchApp(__appId, pArg);
248 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
262 _MapDataControlImpl::GetValue(const String& dataId, const String& key,
263 RequestId& reqId, int pageNo, int countPerPage)
265 SysTryReturnResult(NID_APP, pageNo > 0, E_INVALID_ARG, "The specified pageNo parameter is less than 1");
266 SysTryReturnResult(NID_APP, countPerPage > 0, E_INVALID_ARG, "The specified countPerPage parameter is less than 1");
267 SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_READ) > 0, E_ILLEGAL_ACCESS,
268 "The GetValue query is not permitted by DataControl provider.");
270 String* pPageNo = null;
271 String* pCountPerPage = null;
273 result r = E_SUCCESS;
275 ArrayList* pArgList = new ArrayList();
276 pArgList->Construct();
278 pArgList->Add(*(new String(dataId)));
279 pArgList->Add(*(new String(key)));
280 long long argSize = dataId.GetLength() * sizeof(wchar_t);
281 argSize += key.GetLength() * sizeof(wchar_t);
282 SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
283 "[E_MAX_EXCEEDED] The size of sending argument (%lld) exceeds the maximum limit.", argSize);
285 pPageNo = new (std::nothrow) String();
286 pPageNo->Append(pageNo);
287 pArgList->Add(*pPageNo);
289 pCountPerPage = new (std::nothrow) String();
290 pCountPerPage->Append(countPerPage);
291 pArgList->Add(*pCountPerPage);
293 r = StartMapDataControl(_DATACONTROL_REQUEST_TYPE_MAP_QUERY, pArgList, &id);
294 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
296 reqId = static_cast< RequestId >(id);
298 SysLog(NID_APP, "[DC_CALLER_SEND] data: %ls, key: %ls, req: %d, pageNo: %d, countPerPage: %d",
299 dataId.GetPointer(), key.GetPointer(), reqId, pageNo, countPerPage);
303 pArgList->RemoveAll(true);
310 _MapDataControlImpl::MapDataControlCallback(void* data, _AppArg* pArg, _AppArg* pResArg, service_result_e res, int prop, int option)
312 ArrayList* pResultList = null;
314 String* pResult = null;
315 String* pProviderId = null;
316 String* pDataId = null;
317 String* pErrorMessage = null;
318 String* pErrorMsg = null;
319 String* pResultCount = null;
320 String* pPath = null;
321 ArrayList* pResultValueList = null;
327 bool providerResult = true;
328 //bundle* origBundle = null;
329 bundle* resBundle = null;
330 _MapDataControlEventArg* pEventArg = null;
331 const char* p = null;
332 result r = E_SUCCESS;
334 SysTryReturnResult(NID_APP, pResArg != null, E_INVALID_ARG, "Empty result callback.");
335 SysLog(NID_APP, "appsvc result value: %d", res);
337 resBundle = pResArg->GetBundle();
340 p = appsvc_get_data(resBundle, OSP_K_REQUEST_ID);
341 SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
345 _DataControlManager* pDcMgr = static_cast< _DataControlManager* >(data);
346 _DataControlRequestInfo* pReqInfo = pDcMgr->GetRequestInfo(key);
347 if (pReqInfo == null)
349 SysLog(NID_APP, "No request info of reqId %d", reqId);
353 _MapDataControlEvent* pMapDataControlEvent = dynamic_cast< _MapDataControlEvent* >(pReqInfo->GetEvent());
354 SysTryCatch(NID_APP, pMapDataControlEvent != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request info");
356 pDcMgr->RemoveRequestInfo(key);
358 _MapDataControlImpl* pDcImpl = pReqInfo->GetMapDataControlImpl();
359 SysTryCatch(NID_APP, pDcImpl != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request info");
360 pDcImpl->__pRequestList->Remove(key);
362 // Remove the request from the queue
363 SysLog(NID_APP, "Remove the request, req: %d", reqId);
365 if (pMapDataControlEvent != null && typeid(pMapDataControlEvent) == typeid(_MapDataControlEvent*))
369 pResultList = _AppArg::GetListN(resBundle, OSP_K_ARG);
370 SysTryCatch(NID_APP, pResultList, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result");
372 pResult = dynamic_cast <String*>(pResultList->GetAt(0)); // result list[0]
373 SysTryCatch(NID_APP, pResult, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result");
374 Integer::Parse(*pResult, providerRes);
375 providerResult = static_cast< bool >(providerRes);
377 pErrorMessage = dynamic_cast< String* >(pResultList->GetAt(1)); // result list[1]
378 SysTryCatch(NID_APP, pErrorMessage, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result");
379 pErrorMsg = new (std::nothrow) String(*pErrorMessage);
380 SysTryCatch(NID_APP, pErrorMsg, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
381 "[E_OUT_OF_MEMORY] The memory is insufficient.");
384 //origBundle = pArg->GetBundle();
386 p = appsvc_get_data(resBundle, OSP_K_DATACONTROL_REQUEST_TYPE);
387 SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
388 requestType = atoi(p);
390 p = appsvc_get_data(resBundle, OSP_K_DATACONTROL_PROVIDER);
391 SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
392 pProviderId = new (std::nothrow) String(p);
393 SysTryCatch(NID_APP, pProviderId, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
394 "[E_OUT_OF_MEMORY] The memory is insufficient.");
396 p = appsvc_get_data(resBundle, OSP_K_DATACONTROL_DATA);
397 SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
398 pDataId = new (std::nothrow) String(p);
399 SysTryCatch(NID_APP, pDataId, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
400 "[E_OUT_OF_MEMORY] The memory is insufficient.");
402 version = pResArg->GetValue(OSP_K_DATACONTROL_PROTOCOL_VERSION);
404 SysSecureLog(NID_APP, "[DC_CALLER_RECV] version: %ls, provider result: %ld, requestType: %d, req: %d, provider: %ls, data: %ls, errorMsg: %ls",
405 version.GetPointer(), providerRes, requestType, reqId, pProviderId->GetPointer(), pDataId->GetPointer(), pErrorMsg->GetPointer());
407 switch (static_cast< _DataControlRequestType >(requestType))
409 case _DATACONTROL_REQUEST_TYPE_MAP_QUERY:
411 pResultValueList = new (std::nothrow) ArrayList(SingleObjectDeleter);
412 SysTryCatch(NID_APP, pResultValueList, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
413 "[E_OUT_OF_MEMORY] The memory is insufficient.");
415 if (providerResult == true)
417 pResultCount = dynamic_cast< String* >(pResultList->GetAt(2)); // result list[2]
418 SysTryCatch(NID_APP, pResultCount, delete pResultValueList, E_SYSTEM, "[E_SYSTEM] invalid result");
419 Integer::Parse(*pResultCount, resultCount);
420 SysLog(NID_APP, "[DC_CALLER_RECV] result count: %d", resultCount);
424 if (version == L"ver_2.1.0.1" || version == L"ver_2.1.0.2" || version == L"ver_2.1.0.3")
426 pPath = dynamic_cast< String* >(pResultList->GetAt(3)); // result list[3]
427 SysTryCatch(NID_APP, pPath, delete pResultValueList, E_SYSTEM, "[E_SYSTEM] invalid result");
428 SysLog(NID_APP, "[DC_CALLER_RECV] path: %ls", pPath->GetPointer());
430 unique_ptr< File > pFile(new (std::nothrow) File());
431 SysTryCatch(NID_APP, pFile, delete pResultValueList, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
433 r = pFile->Construct(*pPath, "r");
434 SysTryCatch(NID_APP, !IsFailed(r), delete pResultValueList, r, "[%s] Failed to open result set (%ls)",
435 GetErrorMessage(r), pPath->GetPointer());
440 int ret = pFile->Read(&length, sizeof(int));
441 SysTryCatch(NID_APP, ret, delete pResultValueList, E_SYSTEM,
442 "[E_SYSTEM] Failed to read data from the result set of data control provider.");
444 char* pValue = new (std::nothrow) char[length + 1];
445 SysTryCatch(NID_APP, pValue, delete pResultValueList, E_OUT_OF_MEMORY,
446 "[E_OUT_OF_MEMORY] The memory is insufficient.");
448 ret = pFile->Read(pValue, length);
451 SysLogException(NID_APP, E_SYSTEM,
452 "[E_SYSTEM] Failed to read data from the result set of data control provider.");
453 delete pResultValueList;
457 pValue[length] = '\0';
459 pResultValueList->Add(new (std::nothrow) String(pValue));
469 String* pValue = dynamic_cast< String* >(pResultList->GetAt(index)); // result list[3] ~
470 SysTryCatch(NID_APP, pValue, delete pResultValueList, E_SYSTEM, "[E_SYSTEM] invalid result");
472 pResultValueList->Add((new (std::nothrow) String(*pValue)));
481 r = File::Remove(*pPath);
482 SysTryLog(NID_APP, !IsFailed(r), "Failed to remove result: %ls", pPath->GetPointer());
486 pEventArg = new (std::nothrow) _MapDataControlEventArg(_DATACONTROL_REQUEST_TYPE_MAP_QUERY, static_cast <RequestId>(reqId),
487 *pProviderId, *pDataId, pResultValueList, providerResult, pErrorMsg);
488 SysTryCatch(NID_APP, pEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
489 pMapDataControlEvent->Fire(*pEventArg);
493 case _DATACONTROL_REQUEST_TYPE_MAP_INSERT:
495 pEventArg = new (std::nothrow) _MapDataControlEventArg(_DATACONTROL_REQUEST_TYPE_MAP_INSERT, static_cast <RequestId>(reqId),
496 *pProviderId, *pDataId, null, providerResult, pErrorMsg);
497 SysTryCatch(NID_APP, pEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
498 pMapDataControlEvent->Fire(*pEventArg);
501 case _DATACONTROL_REQUEST_TYPE_MAP_UPDATE:
503 pEventArg = new (std::nothrow) _MapDataControlEventArg(_DATACONTROL_REQUEST_TYPE_MAP_UPDATE, static_cast <RequestId>(reqId),
504 *pProviderId, *pDataId, null, providerResult, pErrorMsg);
505 SysTryCatch(NID_APP, pEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
506 pMapDataControlEvent->Fire(*pEventArg);
509 case _DATACONTROL_REQUEST_TYPE_MAP_DELETE:
511 pEventArg = new (std::nothrow) _MapDataControlEventArg(_DATACONTROL_REQUEST_TYPE_MAP_DELETE, static_cast <RequestId>(reqId),
512 *pProviderId, *pDataId, null, providerResult, pErrorMsg);
513 SysTryCatch(NID_APP, pEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
514 pMapDataControlEvent->Fire(*pEventArg);
521 pResultList->RemoveAll(true);
527 p = appsvc_get_data(pArg->GetBundle(), OSP_K_REQUEST_ID);
528 SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
529 launchReqId = atoi(p);
536 pResultList->RemoveAll(true);
545 _MapDataControlImpl::AddValue(const String& dataId, const String& key,
546 const String& value, RequestId& reqId)
548 SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_WRITE) > 0, E_ILLEGAL_ACCESS,
549 "The AddValue query is not permitted by DataControl provider.");
552 result r = E_SUCCESS;
554 ArrayList* pArgList = null;
555 pArgList = new ArrayList();
556 pArgList->Construct();
558 pArgList->Add(*(new String(dataId)));
559 pArgList->Add(*(new String(key)));
560 pArgList->Add(*(new String(value)));
561 long long argSize = dataId.GetLength() * sizeof(wchar_t);
562 argSize += key.GetLength() * sizeof(wchar_t);
563 argSize += value.GetLength() * sizeof(wchar_t);
564 SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
565 "[E_MAX_EXCEEDED] The size of sending argument (%lld) exceeds the maximum limit.", argSize);
567 r = StartMapDataControl(_DATACONTROL_REQUEST_TYPE_MAP_INSERT, pArgList, &id);
568 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
570 reqId = static_cast< RequestId >(id);
572 SysLog(NID_APP, "[DC_CALLER_SEND] data: %ls, key: %ls, value: %ls, req: %d",
573 dataId.GetPointer(), key.GetPointer(), value.GetPointer(), reqId);
577 pArgList->RemoveAll(true);
584 _MapDataControlImpl::SetValue(const String& dataId, const String& key,
585 const String& oldValue, const String& newValue, RequestId& reqId)
587 SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_WRITE) > 0, E_ILLEGAL_ACCESS,
588 "The SetValue query is not permitted by DataControl provider.");
591 result r = E_SUCCESS;
593 ArrayList* pArgList = null;
594 pArgList = new ArrayList();
595 pArgList->Construct();
597 pArgList->Add(*(new String(dataId)));
598 pArgList->Add(*(new String(key)));
599 pArgList->Add(*(new String(oldValue)));
600 pArgList->Add(*(new String(newValue)));
601 long long argSize = dataId.GetLength() * sizeof(wchar_t);
602 argSize += key.GetLength() * sizeof(wchar_t);
603 argSize += oldValue.GetLength() * sizeof(wchar_t);
604 argSize += newValue.GetLength() * sizeof(wchar_t);
605 SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
606 "[E_MAX_EXCEEDED] The size of sending argument (%lld) exceeds the maximum limit.", argSize);
608 r = StartMapDataControl(_DATACONTROL_REQUEST_TYPE_MAP_UPDATE, pArgList, &id);
609 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
611 reqId = static_cast< RequestId >(id);
613 SysLog(NID_APP, "[DC_CALLER_SEND] data: %ls, key: %ls, oldValue: %ls, newValue: %ls, req: %d",
614 dataId.GetPointer(), key.GetPointer(), oldValue.GetPointer(), newValue.GetPointer(), reqId);
618 pArgList->RemoveAll(true);
625 _MapDataControlImpl::RemoveValue(const String& dataId, const String& key,
626 const String& value, RequestId& reqId)
628 SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_WRITE) > 0, E_ILLEGAL_ACCESS,
629 "The RemoveValue query is not permitted by DataControl provider.");
632 result r = E_SUCCESS;
634 ArrayList* pArgList = null;
635 pArgList = new ArrayList();
636 pArgList->Construct();
638 pArgList->Add(*(new String(dataId)));
639 pArgList->Add(*(new String(key)));
640 pArgList->Add(*(new String(value)));
641 long long argSize = dataId.GetLength() * sizeof(wchar_t);
642 argSize += key.GetLength() * sizeof(wchar_t);
643 argSize += value.GetLength() * sizeof(wchar_t);
644 SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
645 "[E_MAX_EXCEEDED] The size of sending argument (%lld) exceeds the maximum limit.", argSize);
647 r = StartMapDataControl(_DATACONTROL_REQUEST_TYPE_MAP_DELETE, pArgList, &id);
648 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
650 reqId = static_cast< RequestId >(id);
652 SysLog(NID_APP, "[DC_CALLER_SEND] data: %ls, key: %ls, value: %ls, req: %d",
653 dataId.GetPointer(), key.GetPointer(), value.GetPointer(), reqId);
657 pArgList->RemoveAll(true);
664 _MapDataControlImpl::SetMapDataControlResponseListener(IMapDataControlResponseListener* pListener)
666 result r = E_SUCCESS;
668 if (__pPreviousListener != null)
670 r = __pMapDataControlEvent->RemoveListener(*__pPreviousListener);
671 SysTryReturnResult(NID_APP, !IsFailed(r), E_SYSTEM, "Remove listener failed.");
672 __pPreviousListener = null;
675 if (pListener != null)
677 r = __pMapDataControlEvent->AddListener(*pListener);
682 case E_OBJ_ALREADY_EXIST:
684 case E_INVALID_OPERATION:
685 SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] The thread setting the listener is worker thread.");
688 SysLogException(NID_APP, r, "[%s] Propagating to caller...", GetErrorMessage(r));
694 __pPreviousListener = pListener;
701 _MapDataControlImpl::CreateMapDataControl(const AppId& appId, const String& providerId, const String& access)
703 unique_ptr<MapDataControl> pDc(new (std::nothrow) MapDataControl);
704 SysTryReturn(NID_APP, pDc != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient");
706 _MapDataControlImpl* pDcImpl = _MapDataControlImpl::GetInstance(*pDc);
707 pDcImpl->__appId = appId;
708 pDcImpl->__providerId = providerId;
709 unique_ptr<_MapDataControlEvent> pMapDataControlEvent(new (std::nothrow) _MapDataControlEvent);
710 SysTryReturn(NID_IO, pMapDataControlEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
712 pDcImpl->__pRequestList = new (std::nothrow) LinkedList(SingleObjectDeleter);
713 SysTryReturn(NID_IO, pDcImpl->__pRequestList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
715 pDcImpl->__pMapDataControlEvent = pMapDataControlEvent.release();
717 if (access == L"readonly")
719 pDcImpl->__access = _DATACONTROL_ACCESS_READ;
721 else if (access == L"writeonly")
723 pDcImpl->__access = _DATACONTROL_ACCESS_WRITE;
725 else if (access == L"readwrite")
727 pDcImpl->__access = _DATACONTROL_ACCESS_READWRITE;
731 pDcImpl->__access = _DATACONTROL_ACCESS_UNDEFINED;
732 SysLog(NID_IO, "The accessibility of DataControl provider is invalid.");
735 return pDc.release();