Enhance fault tolerance for the deleted DataControl instance (N_SE-41877)
authorHyunbin Lee <hyunbin.lee@samsung.com>
Wed, 19 Jun 2013 02:02:15 +0000 (11:02 +0900)
committerHyunbin Lee <hyunbin.lee@samsung.com>
Wed, 19 Jun 2013 02:37:34 +0000 (11:37 +0900)
Change-Id: I2ed8f2bcf453468ba0a6885e4bcf891ca1d1dd3c
Signed-off-by: Hyunbin Lee <hyunbin.lee@samsung.com>
src/app/FApp_DataControlManager.h
src/app/FApp_MapDataControlImpl.cpp
src/app/FApp_MapDataControlImpl.h
src/app/FApp_SqlDataControlImpl.cpp
src/app/FApp_SqlDataControlImpl.h

index 494474b..ca29cb6 100644 (file)
 namespace Tizen { namespace App
 {
 
+class _SqlDataControlImpl;
+class _MapDataControlImpl;
+
 class _DataControlRequestInfo
        : public Tizen::Base::Object
 {
 public:
        _DataControlRequestInfo(Tizen::Base::Runtime::Event* pEvent)
+               : __pEvent(null)
+               , __pSqlDcImpl(null)
+               , __pMapDcImpl(null)
        {
                __pEvent = pEvent;
        }
@@ -48,13 +54,34 @@ public:
        {
                return __pEvent;
        }
-private:
-       _DataControlRequestInfo(void)
-               : __pEvent(null)
+
+       void SetSqlDataControlImpl(_SqlDataControlImpl* pSqlDcImpl)
        {
+               __pSqlDcImpl = pSqlDcImpl;
        }
+
+       void SetMapDataControlImpl(_MapDataControlImpl* pMapDcImpl)
+       {
+               __pMapDcImpl = pMapDcImpl;
+       }
+
+       _SqlDataControlImpl* GetSqlDataControlImpl(void)
+       {
+               return __pSqlDcImpl;
+       }
+
+       _MapDataControlImpl* GetMapDataControlImpl(void)
+       {
+               return __pMapDcImpl;
+       }
+
+private:
+       _DataControlRequestInfo(void);
+
 private:
        Tizen::Base::Runtime::Event* __pEvent;
+       _SqlDataControlImpl* __pSqlDcImpl;
+       _MapDataControlImpl* __pMapDcImpl;
 };
 
 class _DataControlManager
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")
        {
index 6b1bf3c..355acc0 100644 (file)
@@ -36,6 +36,7 @@ namespace Tizen { namespace Base
 {
 namespace Collection
 {
+class LinkedList;
 class IList;
 }
 }}
@@ -85,6 +86,7 @@ private:
        int __access;
        IMapDataControlResponseListener* __pPreviousListener;
        Tizen::Base::Runtime::Event* __pMapDataControlEvent;
+       Tizen::Base::Collection::LinkedList* __pRequestList;
 
        friend class MapDataControl;
        friend class _AppManagerImpl;
index 2b2abeb..193087b 100644 (file)
@@ -27,6 +27,7 @@
 #include <FBaseInteger.h>
 #include <FBaseString.h>
 #include <FBaseLongLong.h>
+#include <FBaseColLinkedList.h>
 #include <FBaseColIList.h>
 #include <FBaseColIMap.h>
 #include <FBaseColIMapEnumerator.h>
@@ -104,7 +105,7 @@ class _SqlDataControlEvent
        : public Event
 {
 protected:
-               virtual void FireImpl(IEventListener& listener, const IEventArg& arg);
+       virtual void FireImpl(IEventListener& listener, const IEventArg& arg);
 };
 
 void
@@ -152,6 +153,19 @@ _SqlDataControlImpl::_SqlDataControlImpl(void)
 _SqlDataControlImpl::~_SqlDataControlImpl(void)
 {
        delete __pSqlDataControlEvent;
+
+       _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;
 }
 
 _SqlDataControlImpl*
@@ -217,8 +231,9 @@ _SqlDataControlImpl::StartSqlDataControl(int type, const IList* pDataList, int*
                                "[E_OUT_OF_MEMORY] The memory is insufficient");
 
                pReqInfo = new (std::nothrow) _DataControlRequestInfo(__pSqlDataControlEvent);
-               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->SetSqlDataControlImpl(this);
 
                r = pDcMgr->AddRequestInfo(pReqId, pReqInfo);
                SysTryCatch(NID_APP, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[%s] Failed to add request info", GetErrorMessage(r));
@@ -232,6 +247,8 @@ _SqlDataControlImpl::StartSqlDataControl(int type, const IList* pDataList, int*
                        return r;
                }
 
+               __pRequestList->Add(new (std::nothrow) Integer(req));
+
                if (pReq)
                {
                        *pReq = req;
@@ -387,14 +404,17 @@ _SqlDataControlImpl::SqlDataControlCallback(void* data, _AppArg* pArg, _AppArg*
                }
 
                _SqlDataControlEvent* pSqlDataControlEvent = dynamic_cast< _SqlDataControlEvent* >(pReqInfo->GetEvent());
-               SysTryCatch(NID_APP, pSqlDataControlEvent != null, r = E_SYSTEM, E_SYSTEM,
-                               "[E_SYSTEM] invalid request info");
+               SysTryCatch(NID_APP, pSqlDataControlEvent != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request info");
+
+               pDcMgr->RemoveRequestInfo(key);
+
+               _SqlDataControlImpl* pDcImpl = pReqInfo->GetSqlDataControlImpl();
+               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 (pSqlDataControlEvent != null && typeid(pSqlDataControlEvent) == typeid(_SqlDataControlEvent*))
                {
                        // result list
@@ -916,6 +936,9 @@ _SqlDataControlImpl::CreateSqlDataControl(const String& appId, const String& pro
        unique_ptr<_SqlDataControlEvent> pSqlDataControlEvent(new (std::nothrow) _SqlDataControlEvent);
        SysTryReturn(NID_IO, pSqlDataControlEvent != 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->__pSqlDataControlEvent = pSqlDataControlEvent.release();
 
        if (access == L"readonly")
index 450ef1e..c8b3789 100644 (file)
@@ -35,6 +35,7 @@ namespace Tizen { namespace Base
 {
 namespace Collection
 {
+class LinkedList;
 class IList;
 class IMap;
 }
@@ -86,6 +87,7 @@ private:
        int __access;
        ISqlDataControlResponseListener* __pPreviousListener;
        Tizen::Base::Runtime::Event* __pSqlDataControlEvent;
+       Tizen::Base::Collection::LinkedList* __pRequestList;
 
        friend class SqlDataControl;
        friend class _AppManagerImpl;