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