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