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