Changes to stop DecodeUrl activity when Image object is deleted.
authormamata pattanaik <mamata.p@samsung.com>
Sat, 16 Mar 2013 09:35:21 +0000 (15:05 +0530)
committermamata pattanaik <mamata.p@samsung.com>
Sat, 16 Mar 2013 09:35:21 +0000 (15:05 +0530)
Change-Id: If7b53051aae6f5c8daddadfb8fd1a7393dc16aca
Signed-off-by: mamata pattanaik <mamata.p@samsung.com>
src/FMedia_ImageImpl.cpp
src/FMedia_ImageUriDataFactory.cpp
src/FMedia_ImageUriDataFactory.h
src/inc/FMedia_ImageImpl.h

index a89f3ff..28a1ba3 100644 (file)
@@ -56,10 +56,37 @@ static const int _MAX_ENCODE_RESIZE_LOOP = 2;
 
 _ImageImpl::_ImageImpl(void)
 {
+       __pUrlReqIDList.reset(null);
 }
 
 _ImageImpl::~_ImageImpl(void)
 {
+       _ImageUriDataFactory *pFactory = null;
+
+       pFactory = _ImageUriDataFactory::GetInstance();
+       SysTryReturn(NID_MEDIA, pFactory != null, , GetLastResult(), "[%s] Failed to get Factory instance.",
+               GetErrorMessage(GetLastResult()));
+
+       if (__pUrlReqIDList.get() != null)
+       {
+               int num = 0;
+               Object* pObj = null;
+
+               // free the memory
+               num = __pUrlReqIDList->GetCount();
+               for (int i = 0; i < num; i++)
+               {
+                       pObj = __pUrlReqIDList->GetAt(i);
+                       if (pObj != null)
+                       {
+                               Integer *pValue = dynamic_cast<Integer*>(pObj);
+                               RequestId reqId = (RequestId)(pValue->ToInt());
+
+                               pFactory->Remove(reqId);
+                       }
+               }
+               __pUrlReqIDList->RemoveAll(true);
+       }
 }
 
 _ImageImpl*
@@ -350,6 +377,14 @@ _ImageImpl::DecodeUrl(const Tizen::Base::Utility::Uri& srcImageUrl,
        r = pFactory->DecodeUrl(srcImageUrl, colorFormat, destWidth,destHeight, reqId, listener, timeout);
        SysTryCatch(NID_MEDIA, r == E_SUCCESS , , r,"[%s] Propagated.", GetErrorMessage(r));
 
+       if (__pUrlReqIDList.get() == null)
+       {
+               __pUrlReqIDList.reset(new (std::nothrow)Collection::LinkedList());
+               SysTryCatch(NID_MEDIA, __pUrlReqIDList.get() != null, r = E_OUT_OF_MEMORY, r,
+                       "[E_OUT_OF_MEMORY] Propagated. Failed to allocate a LinkedList.", GetErrorMessage(r));
+       }
+       __pUrlReqIDList->Add(new (std::nothrow) Integer(reqId));
+
        return r;
 
 CATCH:
index 730415f..e7b9605 100644 (file)
@@ -309,6 +309,69 @@ _ImageUriDataFactory::OnMediaSessionEnded(RequestId requestId)
        Watchout();
 }
 
+void
+_ImageUriDataFactory::Remove(RequestId reqId)
+{
+       Object* pObj = null;
+       int num = 0;
+       bool deleted = false;
+       result r = E_SUCCESS;
+
+       // Remove ImageUriData for this request id from the working list.
+       num = __pImageUriDataWorkingList->GetCount();
+       for (int i = 0; i < num; i++)
+       {
+               pObj = __pImageUriDataWorkingList->GetAt(i);
+               if (pObj != null)
+               {
+                       _ImageUriData* pImageUriData = dynamic_cast<_ImageUriData*>(pObj);
+                       if (pImageUriData != null)
+                       {
+                               if (reqId == pImageUriData->GetRequestId())
+                               {
+                                       pImageUriData->Cancel(reqId, r);
+                                       __pImageUriDataWorkingList->RemoveAt(i, true);
+                                       deleted = true;
+                                       break;
+                               }
+                       }
+               }
+       }
+
+       // If ImageUriData for this request id is not present in working list,
+       // remove it from the holder queue.
+       if (deleted != true)
+       {
+               num = __pImageUriDataHolderQueue->GetCount();
+               for (int i = 0; i < num; i++)
+               {
+                       // Dequeue elements one by one to check for reqId.
+                       pObj = __pImageUriDataHolderQueue->Dequeue();
+                       if (pObj != null)
+                       {
+                               _ImageUriData* pImageUriData = dynamic_cast<_ImageUriData*>(pObj);
+                               if (pImageUriData != null)
+                               {
+                                       if (reqId == pImageUriData->GetRequestId())
+                                       {
+                                               pImageUriData->Cancel(reqId, r);
+                                               delete pImageUriData;
+                                               deleted = true;
+                                               break;
+                                       }
+                                       // if Dequeued data does not have the same reqId, Enqueue is again.
+                                       __pImageUriDataHolderQueue->Enqueue(*pObj);
+                               }
+                       }
+               }
+       }
+
+       if(deleted != true)
+       {
+               SysLog(NID_MEDIA, "Could not find ReqId %ld in both queues!!", reqId);
+       }
+}
+
 int
 _ImageUriDataFactory::GetHolderCount(void)
 {
index cd7df71..ee9bfc3 100644 (file)
@@ -47,6 +47,7 @@ public:
 
        int GetHolderCount(void);
        int GetWorkerCount(void);
+       void Remove(RequestId reqId);
 
        void OnMediaSessionEnded(RequestId requestId);
 
index 48ce65c..b61894d 100644 (file)
@@ -245,6 +245,7 @@ private:
 //                                                                                     Tizen::Graphics::Dimension& destDim);
 //
 
+       std::unique_ptr<Tizen::Base::Collection::LinkedList> __pUrlReqIDList;
        _ImageImpl(const _ImageImpl& impl);
        _ImageImpl& operator =(const _ImageImpl& impl);