Add logic for prevent duplicated form id using on Form based Scene registrations...
authorSeungWon Lee <lsw2000.lee@samsung.com>
Thu, 28 Mar 2013 13:42:44 +0000 (22:42 +0900)
committerSeungWon Lee <lsw2000.lee@samsung.com>
Thu, 28 Mar 2013 13:42:44 +0000 (22:42 +0900)
Change-Id: Id003e9c69889a823601b781af84205add7dcb0e2
Signed-off-by: SeungWon Lee <lsw2000.lee@samsung.com>
src/ui/scenes/FUiScenes_SceneManagerImpl.cpp
src/ui/scenes/FUiScenes_SceneManagerImpl.h

index c580305..801d9f6 100644 (file)
@@ -169,6 +169,8 @@ _SceneManagerImpl::Construct(void)
        SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
        r = __transitionMap.Construct(0, 0, sceneHashCodeProvider, strComparer);
        SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
+       r = __formIdMap.Construct(0, 0, sceneHashCodeProvider, strComparer);
+       SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
 
        r = __sceneControlEvent.Construct();
        SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
@@ -221,6 +223,24 @@ _SceneManagerImpl::RegisterScene(const SceneId& sceneId, const String& formId, c
        SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
        SysTryReturnResult(NID_UI_SCENES, !isContains, E_OBJ_ALREADY_EXIST, "Specified sceneId already exist.");
 
+       __formIdMap.ContainsKey(formId, isContains);
+       if (panelId.IsEmpty())
+       {
+               SysTryReturnResult(NID_UI_SCENES, !isContains, E_INVALID_ARG, "Specified formId already exist. Only 'PanelScene' can share a formId for use as base form.");
+       }
+
+       if (!isContains)
+       {
+               __formIdMap.Add(formId, 1);
+       }
+       else
+       {
+               int refCount = 0;
+               __formIdMap.GetValue(formId, refCount);
+               ++refCount;
+               __formIdMap.SetValue(formId, refCount);
+       }
+
        pSceneDescription = new (std::nothrow) _SceneDescription(formId, panelId);
        SysTryReturnResult(NID_UI_SCENES, pSceneDescription != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
 
@@ -344,6 +364,27 @@ _SceneManagerImpl::UnregisterScene(const SceneId& sceneId)
        r = __sceneMap.GetValue(sceneId, pSceneDescription);
        SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
 
+       // Remove FormId from __formIdMap
+       if (pSceneDescription)
+       {
+               bool isContains = false;
+               __formIdMap.ContainsKey(pSceneDescription->formId, isContains);
+               if (isContains)
+               {
+                       int refCount = 0;
+                       __formIdMap.GetValue(pSceneDescription->formId, refCount);
+                       --refCount;
+                       if (refCount <= 0)
+                       {
+                               __formIdMap.Remove(pSceneDescription->formId);
+                       }
+                       else
+                       {
+                               __formIdMap.SetValue(pSceneDescription->formId, refCount);
+                       }
+               }
+       }
+
        r = __sceneMap.Remove(sceneId);
        SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
 
@@ -459,13 +500,11 @@ _SceneManagerImpl::GoForward(const ForwardSceneTransition& sceneTransition, cons
        SysTryReturnResult(NID_UI_SCENES, !__sceneTransitionProgressing, E_IN_PROGRESS, "Previous operation in progressing");
 
        result r = __sceneTransitionMutex.TryToAcquire();
-       SysLog(NID_UI_SCENES, "TryToAcquire result= %s", GetErrorMessage(r));
        SysTryReturnResult(NID_UI_SCENES, r != E_OBJECT_LOCKED, E_IN_PROGRESS, "Previous operation in progressing");
        SysTryReturnResult(NID_UI_SCENES, r != E_SYSTEM, E_SYSTEM, "A system error has been occurred.");
        r = __sceneTransitionMutex.Acquire();
        SysTryReturnResult(NID_UI_SCENES, !IsFailed(r), E_SYSTEM, "A system error has been occurred. Mutex acquire failed.");
        __sceneTransitionProgressing = true;    //## Temporary
-       SysLog(NID_UI_SCENES, "##### Mutex acquired.");
 
        SceneId sceneId;
        _SceneTransitionImpl forwardSceneTransition;
@@ -525,7 +564,6 @@ CATCH:
        __sceneTransitionProgressing = false;   //## Temporary
        SysTryReturnResult(NID_UI_SCENES, !IsFailed(__sceneTransitionMutex.Release()), E_SYSTEM,
                                           "A system error has been occurred. Mutext release failed.");
-       SysLog(NID_UI_SCENES, "##### Mutex released.");
        return r;
 }
 
@@ -535,7 +573,7 @@ _SceneManagerImpl::GoForward(const SceneTransitionId& transitionId, const Tizen:
        ForwardSceneTransition forwardTransition;
 
        result r = GetSceneTransition(transitionId, forwardTransition);
-       SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
+       SysTryReturnResult(NID_UI_SCENES, !IsFailed(r), E_INVALID_ARG, "Cannot get transition from Id.");
 
        return GoForward(forwardTransition, pArgs);
 }
@@ -802,13 +840,12 @@ _SceneManagerImpl::AddToSceneHistory(const SceneId& sceneId)
 IListT<SceneId>*
 _SceneManagerImpl::GetSceneHistoryN(void) const
 {
-       IListT<String>* pSceneList = null;
-       pSceneList = new (std::nothrow) ArrayListT<String>;
+       std::unique_ptr<IListT<String> > pSceneList(new (std::nothrow) ArrayListT<String>);
        SysTryReturn(NID_UI_SCENES, pSceneList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
                                 GetErrorMessage(E_OUT_OF_MEMORY));
 
        pSceneList->AddItems(__sceneHistory);
-       return pSceneList;
+       return pSceneList.release();
 }
 
 _SceneManagerImpl*
index 7013398..c2acc9d 100644 (file)
@@ -202,6 +202,7 @@ private:
        };
        Tizen::Base::Collection::HashMapT <Tizen::Base::String, _SceneDescription*> __sceneMap;
        Tizen::Base::Collection::HashMapT <Tizen::Base::String, SceneTransition*> __transitionMap;
+       Tizen::Base::Collection::HashMapT <Tizen::Base::String, int> __formIdMap;
 
        _SceneControlEvent      __sceneControlEvent;
        SceneId __destroyReservedScene;