proper headers
[platform/framework/native/appfw.git] / src / app / FApp_MapDataControlImpl.cpp
index b03b54a..7ee27e4 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <FBaseInteger.h>
 #include <FBaseString.h>
+#include <FBaseColLinkedList.h>
 #include <FBaseRtIEventArg.h>
 #include <FIoFile.h>
 #include <FAppMapDataControl.h>
@@ -91,7 +92,7 @@ class _MapDataControlEvent
        : public Event
 {
 protected:
-               virtual void FireImpl(IEventListener& listener, const IEventArg& arg);
+       virtual void FireImpl(IEventListener& listener, const IEventArg& arg);
 };
 
 void
@@ -139,6 +140,19 @@ _MapDataControlImpl::_MapDataControlImpl(void)
 _MapDataControlImpl::~_MapDataControlImpl(void)
 {
        delete __pMapDataControlEvent;
+
+       _DataControlManager* pDcMgr = _DataControlManager::GetInstance();
+
+       IEnumerator* pEnum = __pRequestList->GetEnumeratorN();
+       while (pEnum->MoveNext() == E_SUCCESS)
+       {
+               Integer* pReqId = dynamic_cast< Integer* >(pEnum->GetCurrent());
+               if (pReqId != null)
+               {
+                       pDcMgr->RemoveRequestInfo(*pReqId);
+               }
+       }
+       delete __pRequestList;
 }
 
 _MapDataControlImpl*
@@ -205,8 +219,9 @@ _MapDataControlImpl::StartMapDataControl(int type, const IList* pDataList, int*
                                "[E_OUT_OF_MEMORY] The memory is insufficient");
 
                pReqInfo = new (std::nothrow) _DataControlRequestInfo(__pMapDataControlEvent);
-               SysTryCatch(NID_APP, pReqId != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+               SysTryCatch(NID_APP, pReqInfo != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
                                "[E_OUT_OF_MEMORY] The memory is insufficient");
+               pReqInfo->SetMapDataControlImpl(this);
 
                r = pDcMgr->AddRequestInfo(pReqId, pReqInfo);
                SysTryCatch(NID_APP, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[%s] Failed to add request info", GetErrorMessage(r));
@@ -220,6 +235,8 @@ _MapDataControlImpl::StartMapDataControl(int type, const IList* pDataList, int*
                        return r;
                }
 
+               __pRequestList->Add(new (std::nothrow) Integer(req));
+
                if (pReq)
                {
                        *pReq = req;
@@ -334,14 +351,17 @@ _MapDataControlImpl::MapDataControlCallback(void* data, _AppArg* pArg, _AppArg*
                }
 
                _MapDataControlEvent* pMapDataControlEvent = dynamic_cast< _MapDataControlEvent* >(pReqInfo->GetEvent());
-               SysTryCatch(NID_APP, pMapDataControlEvent != null, r = E_SYSTEM, E_SYSTEM,
-                               "[E_SYSTEM] invalid request info");
+               SysTryCatch(NID_APP, pMapDataControlEvent != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request info");
+
+               pDcMgr->RemoveRequestInfo(key);
+
+               _MapDataControlImpl* pDcImpl = pReqInfo->GetMapDataControlImpl();
+               SysTryCatch(NID_APP, pDcImpl != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request info");
+               pDcImpl->__pRequestList->Remove(key);
 
                // Remove the request from the queue
                SysLog(NID_APP, "Remove the request, req: %d", reqId);
 
-               pDcMgr->RemoveRequestInfo(key);
-
                if (pMapDataControlEvent != null && typeid(pMapDataControlEvent) == typeid(_MapDataControlEvent*))
                {
 
@@ -684,12 +704,15 @@ _MapDataControlImpl::CreateMapDataControl(const AppId& appId, const String& prov
        SysTryReturn(NID_APP, pDc != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient");
 
        _MapDataControlImpl* pDcImpl = _MapDataControlImpl::GetInstance(*pDc);
+       pDcImpl->__appId = appId;
+       pDcImpl->__providerId = providerId;
        unique_ptr<_MapDataControlEvent> pMapDataControlEvent(new (std::nothrow) _MapDataControlEvent);
        SysTryReturn(NID_IO, pMapDataControlEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
+       pDcImpl->__pRequestList = new (std::nothrow) LinkedList(SingleObjectDeleter);
+       SysTryReturn(NID_IO, pDcImpl->__pRequestList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
        pDcImpl->__pMapDataControlEvent = pMapDataControlEvent.release();
-       pDcImpl->__appId = appId;
-       pDcImpl->__providerId = providerId;
 
        if (access == L"readonly")
        {