Fix the block issue in DataControl
[platform/framework/native/appfw.git] / src / app / FApp_MapDataControlImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file        FApp_MapDataControlImpl.cpp
20  * @brief       This is the implementation for the %_MapDataControlImpl class.
21  */
22
23 #include <typeinfo>
24 #include <new>
25 #include <unique_ptr.h>
26
27 #include <appsvc/appsvc.h>
28
29 #include <FBaseInteger.h>
30 #include <FBaseString.h>
31 #include <FBaseRtIEventArg.h>
32 #include <FAppMapDataControl.h>
33 #include <FAppIMapDataControlResponseListener.h>
34
35 #include <FBaseSysLog.h>
36 #include <FBaseRtWaitingLoop.h>
37
38 #include "FApp_AppControlManager.h"
39 #include "FApp_MapDataControlImpl.h"
40 #include "FApp_AppArg.h"
41
42 using namespace std;
43
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;
49
50 namespace Tizen { namespace App
51 {
52
53 class _MapDataControlEventArg
54         : public IEventArg
55 {
56 public:
57                 _MapDataControlEventArg(_DataControlRequestType requestType, RequestId reqId, String providerId, String dataId,
58                                 IList* pResultValueList, bool providerResult, String* pErrorMsg)
59                         : __requestType(requestType)
60                         , __reqId(reqId)
61                         , __providerId(providerId)
62                         , __dataId(dataId)
63                         , __pResultValueList(pResultValueList)
64                         , __providerResult(providerResult)
65                         , __pErrorMsg(pErrorMsg)
66                 {
67                 }
68                 ~_MapDataControlEventArg(void)
69                 {
70                         if (__pResultValueList)
71                         {
72                                 __pResultValueList->RemoveAll(true);
73                                 delete __pResultValueList;
74                         }
75                         delete __pErrorMsg;
76                 }
77
78                 _DataControlRequestType __requestType;
79                 RequestId __reqId;
80                 String __providerId;
81                 String __dataId;
82                 IList* __pResultValueList;
83                 bool __providerResult;
84                 String* __pErrorMsg;
85 };
86
87 class _MapDataControlEvent
88         : public Event
89 {
90 protected:
91                 virtual void FireImpl(IEventListener& listener, const IEventArg& arg);
92 };
93
94 void
95 _MapDataControlEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
96 {
97         const _MapDataControlEventArg* pArg = dynamic_cast<const _MapDataControlEventArg*>(&arg);
98         if (pArg != null)
99         {
100                 IMapDataControlResponseListener* pListener = dynamic_cast<IMapDataControlResponseListener*> (&listener);
101                 if (pListener != null)
102                 {
103                         switch (pArg->__requestType)
104                         {
105                         case _DATACONTROL_REQUEST_TYPE_MAP_QUERY:
106                                 pListener->OnMapDataControlGetValueResponseReceived(pArg->__reqId, pArg->__providerId, pArg->__dataId,
107                                                 *(pArg->__pResultValueList), pArg->__providerResult, pArg->__pErrorMsg);
108                                 break;
109                         case _DATACONTROL_REQUEST_TYPE_MAP_INSERT:
110                                 pListener->OnMapDataControlAddValueResponseReceived(pArg->__reqId, pArg->__providerId, pArg->__dataId,
111                                                  pArg->__providerResult, pArg->__pErrorMsg);
112                                 break;
113                         case _DATACONTROL_REQUEST_TYPE_MAP_UPDATE:
114                                 pListener->OnMapDataControlSetValueResponseReceived(pArg->__reqId, pArg->__providerId, pArg->__dataId,
115                                                 pArg->__providerResult, pArg->__pErrorMsg);
116                                 break;
117                         case _DATACONTROL_REQUEST_TYPE_MAP_DELETE:
118                                 pListener->OnMapDataControlRemoveValueResponseReceived(pArg->__reqId, pArg->__providerId, pArg->__dataId,
119                                                 pArg->__providerResult, pArg->__pErrorMsg);
120                                 break;
121                         default:
122                                 break;
123                         }
124                 }
125         }
126 }
127
128 // private
129 _MapDataControlImpl::_MapDataControlImpl(void)
130         : __appId(L"")
131         , __providerId(L"")
132         , __access(_DATACONTROL_ACCESS_UNDEFINED)
133         , __pPreviousListener(null)
134         , __pMapDataControlEvent(null)
135 {
136 }
137
138 _MapDataControlImpl::~_MapDataControlImpl(void)
139 {
140         delete __pMapDataControlEvent;
141 }
142
143 _MapDataControlImpl*
144 _MapDataControlImpl::GetInstance(MapDataControl& dc)
145 {
146         return dc.__pMapDataControlImpl;
147 }
148
149 const _MapDataControlImpl*
150 _MapDataControlImpl::GetInstance(const MapDataControl& dc)
151 {
152         return dc.__pMapDataControlImpl;
153 }
154
155 result
156 _MapDataControlImpl::StartMapDataControl(int type, const IList* pDataList, int* pReq)
157 {
158         result r = E_SUCCESS;
159
160         _AppArg* pArg = new(std::nothrow) _AppArg; // XXX: pArg will be released in _AppManagerImpl::LaunchApp().
161         SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
162
163         pArg->Construct(*this, static_cast <_DataControlRequestType>(type), pDataList);
164
165         _AppControlManager* pAppManagerImpl = _AppControlManager::GetInstance();
166         int req = -1;
167
168         // Proceeds the previous request
169         WaitingLoop* pLoop = WaitingLoop::GetInstance();
170         pLoop->Wait(30);
171
172         if (__pMapDataControlEvent)
173         {
174                 // reqId is system-wide id because the bundle is system-wide.
175                 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pAppManagerImpl, pArg, MapDataControlCallback, __pMapDataControlEvent, -1);
176                 req = reqObj.GetRequestNumber();
177
178                 r = pAppManagerImpl->LaunchApp(__appId, pArg, req);
179                 SysTryCatch(NID_APP, r == E_SUCCESS, reqObj.Invalidate(), r, "[%s] Propgated.", GetErrorMessage(r));
180
181                 if (pReq)
182                 {
183                         *pReq = req;
184                 }
185         }
186         else
187         {
188                 r = pAppManagerImpl->LaunchApp(__appId, pArg);
189                 delete pArg;
190         }
191
192 CATCH:
193         return r;
194 }
195
196 result
197 _MapDataControlImpl::GetValue(const String& dataId, const String& key,
198                 RequestId& reqId, int pageNo, int countPerPage)
199 {
200         SysTryReturnResult(NID_APP, pageNo > 0, E_INVALID_ARG, "The specified pageNo parameter is less than 1");
201         SysTryReturnResult(NID_APP, countPerPage > 0, E_INVALID_ARG, "The specified countPerPage parameter is less than 1");
202         SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_READ) > 0, E_ILLEGAL_ACCESS,
203                         "The GetValue query is not permitted by DataControl provider.");
204
205         int id = 0;
206         result r = E_SUCCESS;
207
208         ArrayList* pArgList = null;
209         pArgList = new ArrayList();
210         pArgList->Construct();
211
212         pArgList->Add(*(new String(dataId)));
213         pArgList->Add(*(new String(key)));
214
215         String* pPageNo = new String();
216         pPageNo->Append(pageNo);
217         pArgList->Add(*pPageNo);
218
219         String* pCountPerPage = new String();
220         pCountPerPage->Append(countPerPage);
221         pArgList->Add(*pCountPerPage);
222
223         r = StartMapDataControl(_DATACONTROL_REQUEST_TYPE_MAP_QUERY, pArgList, &id);
224         SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
225
226         reqId = static_cast< RequestId >(id);
227
228         SysLog(NID_APP, "dataId: %ls, key: %ls, reqId: %d, pageNo: %d, countPerPage: %d",
229                         dataId.GetPointer(), key.GetPointer(), reqId, pageNo, countPerPage);
230
231         // fall through
232 CATCH:
233         pArgList->RemoveAll(true);
234         delete pArgList;
235
236         return r;
237 }
238
239 result
240 _MapDataControlImpl::MapDataControlCallback(void* data, _AppArg* pArg, _AppArg* pResArg, service_result_e res, int prop)
241 {
242         ArrayList* pResultList = null;
243         ArrayList* pOrigList = null;
244         String* pRequestType = null;
245         String* pResult = null;
246         String* pReqId = null;
247         String* pProviderId = null;
248         String* pDataId = null;
249         String* pErrorMessage = null;
250         String* pErrorMsg = null;
251         String* pResultCount = null;
252         String* pValue = null;
253         ArrayList* pResultValueList = null;
254         int resultCount = 0;
255         int requestType = 0;
256         int reqId = 0;
257         int providerRes = 0;
258         bool providerResult = true;
259         bundle* origBundle = null;
260         bundle* resBundle = null;
261         _MapDataControlEventArg* pEventArg = null;
262         result r = E_SUCCESS;
263
264         SysTryReturnResult(NID_APP, pResArg != null, E_INVALID_ARG, "Empty result callback.");
265         SysLog(NID_APP, "appsvc result value: %d", res);
266
267         resBundle = pResArg->GetBundle();
268         if (resBundle)
269         {
270                 _MapDataControlEvent* pMapDataControlEvent = static_cast< _MapDataControlEvent* >(data);
271
272                 if (pMapDataControlEvent != null && typeid(pMapDataControlEvent) == typeid(_MapDataControlEvent*))
273                 {
274                         const char* p = null;
275
276                         // result list
277                         pResultList = _AppArg::GetListN(resBundle, OSP_K_ARG);
278                         SysTryCatch(NID_APP, pResultList, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result");
279
280                         pResult = dynamic_cast <String*>(pResultList->GetAt(0));
281                         SysTryCatch(NID_APP, pResult, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result");
282                         Integer::Parse(*pResult, providerRes);
283                         providerResult = static_cast< bool >(providerRes);
284
285                         pErrorMessage = dynamic_cast< String* >(pResultList->GetAt(1));
286                         SysTryCatch(NID_APP, pErrorMessage, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result");
287                         pErrorMsg = new (std::nothrow) String(*pErrorMessage);
288                         SysTryCatch(NID_APP, pErrorMsg, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
289                                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
290
291                         // request info
292                         origBundle = pArg->GetBundle();
293
294                         p = appsvc_get_data(origBundle, OSP_K_DATACONTROL_REQUEST_TYPE);
295                         SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
296                         pRequestType = new (std::nothrow) String(p);
297                         SysTryCatch(NID_APP, pRequestType, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
298                                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
299                         Integer::Parse(*pRequestType, requestType);
300
301                         p = appsvc_get_data(origBundle, OSP_K_REQUEST_ID);
302                         SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
303                         pReqId = new (std::nothrow) String(p);
304                         SysTryCatch(NID_APP, pReqId, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
305                                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
306                         Integer::Parse(*pReqId, reqId);
307
308                         p = appsvc_get_data(origBundle, OSP_K_DATACONTROL_PROVIDER);
309                         SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
310                         pProviderId = new (std::nothrow) String(p);
311                         SysTryCatch(NID_APP, pProviderId, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
312                                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
313
314                         pOrigList = _AppArg::GetListN(origBundle, OSP_K_ARG);
315                         SysTryCatch(NID_APP, pOrigList, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
316                         pDataId = dynamic_cast <String*>(pOrigList->GetAt(0));
317                         SysTryCatch(NID_APP, pDataId, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
318
319                         SysLog(NID_APP, "result: %ld, requestType: %d, reqId: %d, providerId: %ls, dataId: %ls, errorMsg: %ls ",
320                                         providerRes, requestType, reqId, pProviderId->GetPointer(), pDataId->GetPointer(), pErrorMsg->GetPointer());
321
322                         switch (static_cast< _DataControlRequestType >(requestType))
323                         {
324                         case _DATACONTROL_REQUEST_TYPE_MAP_QUERY:
325                         {
326                                 pResultValueList = new (std::nothrow) ArrayList();
327                                 SysTryCatch(NID_APP, pResultValueList, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
328                                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
329
330                                 if (providerResult == true)
331                                 {
332                                         pResultCount = dynamic_cast< String* >(pResultList->GetAt(2));
333                                         if (pResultCount == null)
334                                         {
335                                                 SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] invalid result");
336                                                 pResultValueList->RemoveAll(true);
337                                                 delete pResultValueList;
338                                                 goto CATCH;
339                                         }
340                                         Integer::Parse(*pResultCount, resultCount);
341
342                                         int index = 3;
343                                         while (resultCount)
344                                         {
345                                                 pValue = dynamic_cast< String* >(pResultList->GetAt(index));
346                                                 if (pValue == null)
347                                                 {
348                                                         SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] invalid result");
349                                                         pResultValueList->RemoveAll(true);
350                                                         delete pResultValueList;
351                                                         goto CATCH;
352                                                 }
353
354                                                 pResultValueList->Add(*(new (std::nothrow) String(*pValue)));
355                                                 resultCount--;
356                                                 index++;
357                                         }
358                                 }
359
360                                 pEventArg = new (std::nothrow) _MapDataControlEventArg(_DATACONTROL_REQUEST_TYPE_MAP_QUERY, static_cast <RequestId>(reqId),
361                                                 *pProviderId, *pDataId, pResultValueList, providerResult, pErrorMsg);
362                                 SysTryCatch(NID_APP, pEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
363                                 pMapDataControlEvent->Fire(*pEventArg);
364
365                                 break;
366                         }
367                         case _DATACONTROL_REQUEST_TYPE_MAP_INSERT:
368                         {
369                                 pEventArg = new (std::nothrow) _MapDataControlEventArg(_DATACONTROL_REQUEST_TYPE_MAP_INSERT, static_cast <RequestId>(reqId),
370                                                 *pProviderId, *pDataId, null, providerResult, pErrorMsg);
371                                 SysTryCatch(NID_APP, pEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
372                                 pMapDataControlEvent->Fire(*pEventArg);
373                                 break;
374                         }
375                         case _DATACONTROL_REQUEST_TYPE_MAP_UPDATE:
376                         {
377                                 pEventArg = new (std::nothrow) _MapDataControlEventArg(_DATACONTROL_REQUEST_TYPE_MAP_UPDATE, static_cast <RequestId>(reqId),
378                                                 *pProviderId, *pDataId, null, providerResult, pErrorMsg);
379                                 SysTryCatch(NID_APP, pEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
380                                 pMapDataControlEvent->Fire(*pEventArg);
381                                 break;
382                         }
383                         case _DATACONTROL_REQUEST_TYPE_MAP_DELETE:
384                         {
385                                 pEventArg = new (std::nothrow) _MapDataControlEventArg(_DATACONTROL_REQUEST_TYPE_MAP_DELETE, static_cast <RequestId>(reqId),
386                                                 *pProviderId, *pDataId, null, providerResult, pErrorMsg);
387                                 SysTryCatch(NID_APP, pEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
388                                 pMapDataControlEvent->Fire(*pEventArg);
389                                 break;
390                         }
391                         default:
392                                 break;
393                         }
394
395                         pResultList->RemoveAll(true);
396                         delete pResultList;
397
398                         pOrigList->RemoveAll(true);
399                         delete pOrigList;
400
401                         delete pRequestType;
402                         delete pReqId;
403                         delete pProviderId;
404                 }
405         }
406
407         return E_SUCCESS;
408
409 CATCH:
410         if (pResultList)
411         {
412                 pResultList->RemoveAll(true);
413                 delete pResultList;
414         }
415
416         if (pOrigList)
417         {
418                 pOrigList->RemoveAll(true);
419                 delete pOrigList;
420         }
421
422         delete pRequestType;
423         delete pReqId;
424         delete pProviderId;
425
426         return r;
427 }
428
429 result
430 _MapDataControlImpl::AddValue(const String& dataId, const String& key,
431                 const String& value, RequestId& reqId)
432 {
433         SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_WRITE) > 0, E_ILLEGAL_ACCESS,
434                         "The AddValue query is not permitted by DataControl provider.");
435
436         int id = 0;
437         result r = E_SUCCESS;
438
439         ArrayList* pArgList = null;
440         pArgList = new ArrayList();
441         pArgList->Construct();
442
443         pArgList->Add(*(new String(dataId)));
444         pArgList->Add(*(new String(key)));
445         pArgList->Add(*(new String(value)));
446
447         r = StartMapDataControl(_DATACONTROL_REQUEST_TYPE_MAP_INSERT, pArgList, &id);
448         SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
449
450         reqId = static_cast< RequestId >(id);
451
452         SysLog(NID_APP, "dataId: %ls, key: %ls, value: %ls, reqId: %d",
453                         dataId.GetPointer(), key.GetPointer(), value.GetPointer(), reqId);
454
455         // fall through
456 CATCH:
457         pArgList->RemoveAll(true);
458         delete pArgList;
459
460         return r;
461 }
462
463 result
464 _MapDataControlImpl::SetValue(const String& dataId, const String& key,
465                 const String& oldValue, const String& newValue, RequestId& reqId)
466 {
467         SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_WRITE) > 0, E_ILLEGAL_ACCESS,
468                         "The SetValue query is not permitted by DataControl provider.");
469
470         int id = 0;
471         result r = E_SUCCESS;
472
473         ArrayList* pArgList = null;
474         pArgList = new ArrayList();
475         pArgList->Construct();
476
477         pArgList->Add(*(new String(dataId)));
478         pArgList->Add(*(new String(key)));
479         pArgList->Add(*(new String(oldValue)));
480         pArgList->Add(*(new String(newValue)));
481
482         r = StartMapDataControl(_DATACONTROL_REQUEST_TYPE_MAP_UPDATE, pArgList, &id);
483         SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
484
485         reqId = static_cast< RequestId >(id);
486
487         SysLog(NID_APP, "dataId: %ls, key: %ls, oldValue: %ls, newValue: %ls, reqId: %d",
488                         dataId.GetPointer(), key.GetPointer(), oldValue.GetPointer(), newValue.GetPointer(), reqId);
489
490         // fall through
491 CATCH:
492         pArgList->RemoveAll(true);
493         delete pArgList;
494
495         return r;
496 }
497
498 result
499 _MapDataControlImpl::RemoveValue(const String& dataId, const String& key,
500                 const String& value, RequestId& reqId)
501 {
502         SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_WRITE) > 0, E_ILLEGAL_ACCESS,
503                         "The RemoveValue query is not permitted by DataControl provider.");
504
505         int id = 0;
506         result r = E_SUCCESS;
507
508         ArrayList* pArgList = null;
509         pArgList = new ArrayList();
510         pArgList->Construct();
511
512         pArgList->Add(*(new String(dataId)));
513         pArgList->Add(*(new String(key)));
514         pArgList->Add(*(new String(value)));
515
516         r = StartMapDataControl(_DATACONTROL_REQUEST_TYPE_MAP_DELETE, pArgList, &id);
517         SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
518
519         reqId = static_cast< RequestId >(id);
520
521         SysLog(NID_APP, "dataId: %ls, key: %ls, value: %ls, reqId: %d",
522                         dataId.GetPointer(), key.GetPointer(), value.GetPointer(), reqId);
523
524         // fall through
525 CATCH:
526         pArgList->RemoveAll(true);
527         delete pArgList;
528
529         return r;
530 }
531
532 result
533 _MapDataControlImpl::SetMapDataControlResponseListener(IMapDataControlResponseListener* pListener)
534 {
535         result r = E_SUCCESS;
536
537         if (__pPreviousListener != null)
538         {
539                 r =  __pMapDataControlEvent->RemoveListener(*__pPreviousListener);
540                 SysTryReturnResult(NID_APP, !IsFailed(r), E_SYSTEM, "Remove listener failed.");
541                  __pPreviousListener = null;
542         }
543
544         if (pListener != null)
545         {
546                 r =  __pMapDataControlEvent->AddListener(*pListener);
547                 if (IsFailed(r))
548                 {
549                         switch (r)
550                         {
551                         case E_OBJ_ALREADY_EXIST:
552                                 return E_SUCCESS;
553                         case E_INVALID_OPERATION:
554                                 SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] The thread setting the listener is worker thread.");
555                                 return E_SYSTEM;
556                         default:
557                                 SysLogException(NID_APP, r, "[%s] Propagating to caller...", GetErrorMessage(r));
558                                 return r;
559                         }
560                 }
561         }
562
563         __pPreviousListener = pListener;
564
565         return E_SUCCESS;
566 }
567
568 // private
569 MapDataControl*
570 _MapDataControlImpl::CreateMapDataControl(const AppId& appId, const String& providerId, const String& access)
571 {
572         unique_ptr<MapDataControl> pDc(new (std::nothrow) MapDataControl);
573         SysTryReturn(NID_APP, pDc != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient");
574
575         _MapDataControlImpl* pDcImpl = _MapDataControlImpl::GetInstance(*pDc);
576         unique_ptr<_MapDataControlEvent> pMapDataControlEvent(new (std::nothrow) _MapDataControlEvent);
577         SysTryReturn(NID_IO, pMapDataControlEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
578
579         pDcImpl->__pMapDataControlEvent = pMapDataControlEvent.release();
580         pDcImpl->__appId = appId;
581         pDcImpl->__providerId = providerId;
582
583         if (access == L"readonly")
584         {
585                 pDcImpl->__access = _DATACONTROL_ACCESS_READ;
586         }
587         else if (access == L"writeonly")
588         {
589                 pDcImpl->__access = _DATACONTROL_ACCESS_WRITE;
590         }
591         else if (access == L"readwrite")
592         {
593                 pDcImpl->__access = _DATACONTROL_ACCESS_READWRITE;
594         }
595         else
596         {
597                 pDcImpl->__access = _DATACONTROL_ACCESS_UNDEFINED;
598                 SysLog(NID_IO, "The accessibility of DataControl provider is invalid.");
599         }
600
601         return pDc.release();
602 }
603
604 }} // Tizen::App
605