[Gallery] Code refactoring 99/135499/1
authorIgor Nazarov <i.nazarov@samsung.com>
Thu, 22 Jun 2017 17:27:47 +0000 (20:27 +0300)
committerIgor Nazarov <i.nazarov@samsung.com>
Thu, 22 Jun 2017 17:32:51 +0000 (20:32 +0300)
- ucl::RefCountAware::m_rc made private. Added public functions instead;
- Widget casting functions renamed in "ucl/gui/helpers.h";
- Fixed type mismatch for getUseCount() method;
- Other changes.

Change-Id: I9253860d333bfc111a8de0d4c0f28227593c1c9e

23 files changed:
inc/gallery/presenters/Dialog.h
inc/gallery/presenters/Dialog.hpp
inc/gallery/presenters/Page.h
inc/gallery/presenters/ProcessingPresenter.h
src/presenters/Dialog.cpp
src/presenters/Page.cpp
src/presenters/ProcessingPresenter.cpp
ucl/inc/ucl/gui/Genlist.h
ucl/inc/ucl/gui/Genlist.hpp
ucl/inc/ucl/gui/Widget.h
ucl/inc/ucl/gui/helpers.h
ucl/inc/ucl/gui/types.h
ucl/inc/ucl/misc/RefCountAware.h
ucl/inc/ucl/misc/RefCountAware.hpp
ucl/inc/ucl/util/memory/BaseRef.h
ucl/inc/ucl/util/memory/BaseRef.hpp
ucl/inc/ucl/util/memory/IRefCountObj.h
ucl/inc/ucl/util/memory/RefCountObj.h
ucl/inc/ucl/util/memory/RefCountObj.hpp
ucl/src/gui/ElmWidget.cpp
ucl/src/gui/NaviItem.cpp
ucl/src/gui/Widget.cpp
ucl/src/mvp/GuiPresenter.cpp

index f820c07c6e30a52fdedf0182fea8d75034681f34..7c26010320a3fee50f08617422391e65fb927971 100644 (file)
@@ -60,6 +60,8 @@ namespace gallery {
 
        protected:
                ucl::StyledWidgetSRef m_popup;
+       private:
+               DialogSRef m_selfRef;
                bool m_isDismissed;
        };
 }
index ed2c8f76e2a01c508ff284b3c23263c58b7657fa..5bd8ecb16c41233f4cafed3c02cbdec82766690a 100644 (file)
@@ -30,7 +30,7 @@ namespace gallery {
 
                UCL_FAIL_RETURN(onPrepare(), "onPrepare() failed!");
 
-               m_rc->ref();
+               m_selfRef = asShared(*this);
 
                return ucl::RES_OK;
        }
index d8132dca436138a005609cb04b1065ae6488f709..b98569cd67919cda05ae0ae362d108f36a55b8a3 100644 (file)
@@ -80,6 +80,7 @@ namespace gallery {
                const ucl::NaviframeSRef m_navi;
                const ExitRequestHandler m_onExitRequest;
                ucl::NaviItem m_item;
+               PageSRef m_selfRef;
        };
 
        // Non-member functions //
index 12760931b82fffc7588e6c9109fdc0085fe45c0f..ff0477a4d21a463061e6eacfcbd80f5c5e43ee89 100644 (file)
@@ -100,6 +100,7 @@ namespace gallery {
                DismissHandler m_dismissHandler;
                Ecore_Timer *m_timer;
                State m_state;
+               ProcessingPresenterSRef m_selfRef;
                bool m_mayComplete;
                bool m_isComplete;
                bool m_isDismissed;
index 826b9fabd01cfd7914c801762cab349fe001e087..33d415c9f9cb4a9605470dcbbc6955950d5b70d0 100644 (file)
@@ -70,7 +70,7 @@ namespace gallery {
 
                        deactivateBy(m_popup.get());
                        m_popup.reset();
-                       m_rc->unref();
+                       m_selfRef.reset();
 
                        broadcastActivate();
                }
index ae3f71e1d5b3de9a0f022efbf8ff5c0148e50af2..de4b8ebf169c3455034dcd9b2ddf2533f0dc0f34 100644 (file)
@@ -73,7 +73,7 @@ namespace gallery {
                m_item.setData(this);
                m_item.setDelCallback(CALLBACK_A(Page::onItemDel));
 
-               m_rc->ref();
+               m_selfRef = asShared(*this);
 
                if (!m_navi->isInTransition() && isAtTop()) {
                        dispatchTopPageChanged();
@@ -95,7 +95,7 @@ namespace gallery {
        void Page::onItemDel(Evas_Object *obj, void *eventInfo)
        {
                m_item = nullptr;
-               m_rc->unref();
+               m_selfRef.reset();
        }
 
        void Page::exit()
index 7238837d953f725661c204886707dc665839470a..d3c71e5e923d4eb88dea43a82fb8c3fde9499823 100644 (file)
@@ -276,9 +276,7 @@ namespace gallery {
                        deactivateBy(m_popup.get());
                        broadcastActivate();
                        m_popup.reset();
-                       if (m_isComplete) {
-                               m_rc->unref();
-                       }
+                       m_selfRef.reset();
                }
        }
 
@@ -354,7 +352,7 @@ namespace gallery {
                        FAIL_LOG(createIcon(), "createIcon() failed!");
                }
 
-               m_rc->ref();
+               m_selfRef = asShared(*this);
 
                tryShowPopup();
        }
index ea2e6600d1720975fcb5406c8f7bc43741f98241..ebbb43e6d0664b35e6c3f1e71b0efa5ba46f4304 100644 (file)
@@ -65,25 +65,25 @@ namespace ucl {
 
                GenlistItem append(const Elm_Genlist_Item_Class *itc,
                                const void *data, SmartCbHandler onSelect = nullptr,
-                               GenlistItem parent = nullptr,
-                               GenlistItem::Type type = GenlistItem::Type::SIMPLE);
+                               GenlistItem::Type type = GenlistItem::Type::SIMPLE,
+                               GenlistItem parent = nullptr);
 
                GenlistItem prepend(const Elm_Genlist_Item_Class *itc,
                                const void *data, SmartCbHandler onSelect = nullptr,
-                               GenlistItem parent = nullptr,
-                               GenlistItem::Type type = GenlistItem::Type::SIMPLE);
+                               GenlistItem::Type type = GenlistItem::Type::SIMPLE,
+                               GenlistItem parent = nullptr);
 
                GenlistItem insertAfter(GenlistItem after,
                                const Elm_Genlist_Item_Class *itc, const void *data,
                                SmartCbHandler onSelect = nullptr,
-                               GenlistItem parent = nullptr,
-                               GenlistItem::Type type = GenlistItem::Type::SIMPLE);
+                               GenlistItem::Type type = GenlistItem::Type::SIMPLE,
+                               GenlistItem parent = nullptr);
 
                GenlistItem insertBefore(GenlistItem before,
                                const Elm_Genlist_Item_Class *itc, const void *data,
                                SmartCbHandler onSelect = nullptr,
-                               GenlistItem parent = nullptr,
-                               GenlistItem::Type type = GenlistItem::Type::SIMPLE);
+                               GenlistItem::Type type = GenlistItem::Type::SIMPLE,
+                               GenlistItem parent = nullptr);
        };
 }
 
index 83eed72e9e03d5fdf2db39d3b891d1cd7e1550d7..d3cfed046efe40c5e534de01109e0387e87192f9 100644 (file)
@@ -90,7 +90,7 @@ namespace ucl {
 
        inline GenlistItem Genlist::append(const Elm_Genlist_Item_Class *const itc,
                        const void *const data, const SmartCbHandler onSelect,
-                       const GenlistItem parent, const GenlistItem::Type type)
+                       const GenlistItem::Type type, const GenlistItem parent)
        {
                return GenlistItem(elm_genlist_item_append(
                                getEo(), itc, data, parent,
@@ -100,7 +100,7 @@ namespace ucl {
 
        inline GenlistItem Genlist::prepend(const Elm_Genlist_Item_Class *const itc,
                        const void *const data, SmartCbHandler onSelect,
-                       const GenlistItem parent, const GenlistItem::Type type)
+                       const GenlistItem::Type type, const GenlistItem parent)
        {
                return GenlistItem(elm_genlist_item_prepend(
                                getEo(), itc, data, parent,
@@ -110,8 +110,8 @@ namespace ucl {
 
        inline GenlistItem Genlist::insertAfter(const GenlistItem after,
                        const Elm_Genlist_Item_Class *const itc, const void *const data,
-                       const SmartCbHandler onSelect, const GenlistItem parent,
-                       const GenlistItem::Type type)
+                       const SmartCbHandler onSelect, const GenlistItem::Type type,
+                       const GenlistItem parent)
        {
                return GenlistItem(elm_genlist_item_insert_after(
                                getEo(), itc, data, parent, after,
@@ -121,8 +121,8 @@ namespace ucl {
 
        inline GenlistItem Genlist::insertBefore(const GenlistItem before,
                        const Elm_Genlist_Item_Class *itc, const void *data,
-                       const SmartCbHandler onSelect, const GenlistItem parent,
-                       const GenlistItem::Type type)
+                       const SmartCbHandler onSelect, const GenlistItem::Type type,
+                       const GenlistItem parent)
        {
                return GenlistItem(elm_genlist_item_insert_before(
                                getEo(), itc, data, parent, before,
index 2048a7d6521e5087667d325604808bdf8586205b..e60c5ec74451012407751e35bdaa677338d27535 100644 (file)
@@ -135,11 +135,11 @@ namespace ucl {
        private:
                Evas_Object *m_eo;
                EventProxies m_eventProxies;
-               bool m_isOwner: 1;
-               bool m_isBoundToEo: 1;
-               bool m_isEoRefKept: 1;
-               bool m_isSelfRefKept: 1;
-               bool m_isSelfRefUnique: 1;
+               WidgetSRef m_selfRef;
+               bool m_isOwner;
+               bool m_isBoundToEo;
+               bool m_isEoRefKept;
+               bool m_isSelfRefUnique;
        };
 
        // Non-member functions //
index f598c17ff19c6c7f9eabb8dcc9b28100c998a248..d42eccb613d1d77a0da3dc28920123c486755276 100644 (file)
@@ -29,59 +29,59 @@ namespace ucl {
        // Widget casting functions from Evas_Object //
 
        template <class WIDGET_TYPE>
-       inline auto staticCast(Evas_Object *eo) ->
+       inline auto staticWidgetCast(Evas_Object *eo) ->
                        decltype(static_cast<WIDGET_TYPE *>(asWidget(eo)))
        {
                return static_cast<WIDGET_TYPE *>(asWidget(eo));
        }
 
        template <class WIDGET_TYPE>
-       inline auto staticCast(const Evas_Object *eo) ->
+       inline auto staticWidgetCast(const Evas_Object *eo) ->
                        decltype(static_cast<WIDGET_TYPE *>(asWidget(eo)))
        {
                return static_cast<WIDGET_TYPE *>(asWidget(eo));
        }
 
        template <class WIDGET_TYPE>
-       inline auto dynamicCast(Evas_Object *eo) ->
+       inline auto dynamicWidgetCast(Evas_Object *eo) ->
                        decltype(dynamic_cast<WIDGET_TYPE *>(asWidget(eo)))
        {
                return dynamic_cast<WIDGET_TYPE *>(asWidget(eo));
        }
 
        template <class WIDGET_TYPE>
-       inline auto dynamicCast(const Evas_Object *eo) ->
+       inline auto dynamicWidgetCast(const Evas_Object *eo) ->
                        decltype(dynamic_cast<WIDGET_TYPE *>(asWidget(eo)))
        {
                return dynamic_cast<WIDGET_TYPE *>(asWidget(eo));
        }
 
        template <class WIDGET_TYPE>
-       inline auto staticRefCast(Evas_Object *eo) ->
-                       decltype(asShared(staticCast<WIDGET_TYPE>(eo)))
+       inline auto staticWidgetRefCast(Evas_Object *eo) ->
+                       decltype(asShared(staticWidgetCast<WIDGET_TYPE>(eo)))
        {
-               return asShared(staticCast<WIDGET_TYPE>(eo));
+               return asShared(staticWidgetCast<WIDGET_TYPE>(eo));
        }
 
        template <class WIDGET_TYPE>
-       inline auto staticRefCast(const Evas_Object *eo) ->
-                       decltype(asShared(staticCast<WIDGET_TYPE>(eo)))
+       inline auto staticWidgetRefCast(const Evas_Object *eo) ->
+                       decltype(asShared(staticWidgetCast<WIDGET_TYPE>(eo)))
        {
-               return asShared(staticCast<WIDGET_TYPE>(eo));
+               return asShared(staticWidgetCast<WIDGET_TYPE>(eo));
        }
 
        template <class WIDGET_TYPE>
-       inline auto dynamicRefCast(Evas_Object *eo) ->
-                       decltype(asShared(dynamicCast<WIDGET_TYPE>(eo)))
+       inline auto dynamicWidgetRefCast(Evas_Object *eo) ->
+                       decltype(asShared(dynamicWidgetCast<WIDGET_TYPE>(eo)))
        {
-               return asShared(dynamicCast<WIDGET_TYPE>(eo));
+               return asShared(dynamicWidgetCast<WIDGET_TYPE>(eo));
        }
 
        template <class WIDGET_TYPE>
-       inline auto dynamicRefCast(const Evas_Object *eo) ->
-                       decltype(asShared(dynamicCast<WIDGET_TYPE>(eo)))
+       inline auto dynamicWidgetRefCast(const Evas_Object *eo) ->
+                       decltype(asShared(dynamicWidgetCast<WIDGET_TYPE>(eo)))
        {
-               return asShared(dynamicCast<WIDGET_TYPE>(eo));
+               return asShared(dynamicWidgetCast<WIDGET_TYPE>(eo));
        }
 }
 
index 4063b330bb87cff69b12576a274639ebb71c925e..6d43d766b9039ca6b267603c34073b061e52c531 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "ucl/misc/Aspect.h"
 #include "ucl/misc/TString.h"
+#include "ucl/misc/ConstCString.h"
 #include "ucl/misc/Variant.h"
 
 namespace ucl {
index e75ecb9e384978bd39dbdef27687fbf8f773b72c..6ea5ee9cbf72e90c28f0e1729fdf0760a972f380 100644 (file)
@@ -27,6 +27,8 @@ namespace ucl {
        class RefCountAware : public Polymorphic {
        public:
                bool isShared() const;
+               UInt getUseCount() const;
+               const void *getObjPtr() const;
 
                template <class T>
                SharedRef<T> asSharedThis(T *thisAlias) const;
@@ -43,7 +45,7 @@ namespace ucl {
                // Signal to RefCountObj<T, C> to pass IRefCountObj to constructor
                enum { _IS_REF_COUNT_AWARE };
 
-       protected:
+       private:
                IRefCountObj *const m_rc;
        };
 
index 3906d0eba6e42a5d4922dc80917d7fce477a76bc..8fb38122d82e58ae5a8ae320478c5169825c5dc5 100644 (file)
@@ -28,6 +28,24 @@ namespace ucl {
                return !!m_rc;
        }
 
+       inline UInt RefCountAware::getUseCount() const
+       {
+               if (!isShared()) {
+                       UCL_ELOG("NOT SHARED: %s", typeid(*this).name());
+                       return 0;
+               }
+               return m_rc->getUseCount();
+       }
+
+       inline const void *RefCountAware::getObjPtr() const
+       {
+               if (!isShared()) {
+                       UCL_ELOG("NOT SHARED: %s", typeid(*this).name());
+                       return nullptr;
+               }
+               return m_rc->getObjPtr();
+       }
+
        template <class T>
        inline SharedRef<T> RefCountAware::asSharedThis(T *const thisAlias) const
        {
index f82a2c918dc7ef9c730b8c789a6e432c0bcaf2d8..8146eae89db30cbd0f7e6d3cae3bffe70319f234 100644 (file)
@@ -34,7 +34,7 @@ namespace ucl {
                friend class WeakRef;
 
        public:
-               int getUseCount() const noexcept;
+               UInt getUseCount() const noexcept;
 
        protected:
                constexpr BaseRef() noexcept;
index adde1c9a8afc2306be405b013d85e3d05c2d6b72..312c38ed0de68479a2ed943cdde5084f66c178a9 100644 (file)
@@ -51,7 +51,7 @@ namespace ucl {
        }
 
        template <class T>
-       inline int BaseRef<T>::getUseCount() const noexcept
+       inline UInt BaseRef<T>::getUseCount() const noexcept
        {
                return (m_rc ? m_rc->getUseCount() : 0);
        }
index c2397d44a9a0ce7547dd107018f58630df9d45f0..69d6a1c6f66ca002817a2b46de1f8a90ee6997ce 100644 (file)
@@ -28,7 +28,7 @@ namespace ucl {
                virtual bool refNz() noexcept = 0;
                virtual void refWeak() noexcept = 0;
                virtual void unrefWeak() noexcept = 0;
-               virtual unsigned getUseCount() const noexcept = 0;
+               virtual UInt getUseCount() const noexcept = 0;
                virtual const void *getObjPtr() const noexcept = 0;
        protected:
                virtual ~IRefCountObj() = default;
index 9832ff6797419ffc363468ff18ea6911b9a3b7bb..7237aa48beb67b2b6744cc2d55fb2cefe7d990e2 100644 (file)
@@ -37,7 +37,7 @@ namespace ucl {
                virtual bool refNz() noexcept final override;
                virtual void refWeak() noexcept final override;
                virtual void unrefWeak() noexcept final override;
-               virtual unsigned getUseCount() const noexcept final override;
+               virtual UInt getUseCount() const noexcept final override;
                virtual const void *getObjPtr() const noexcept final override;
 
        private:
index d3b4e97eb2253ddee01668c268904f144037f2b2..8a2c065d5513ba19d2b78a44cd9a36de14329cf6 100644 (file)
@@ -79,7 +79,7 @@ namespace ucl {
        }
 
        template <class T, class C>
-       inline unsigned RefCountObj<T, C>::getUseCount() const noexcept
+       inline UInt RefCountObj<T, C>::getUseCount() const noexcept
        {
                return m_useCounter.get();
        }
index 7c39f813db65f58685e6300b5edf95e376a7f146..b7d227ef0d570118b62b8d238841e523b4c15934 100644 (file)
@@ -70,6 +70,6 @@ namespace ucl {
 
        Window *ElmWidget::getWindow() const
        {
-               return dynamicCast<Window>(getTopWidget());
+               return dynamicWidgetCast<Window>(getTopWidget());
        }
 }
index dd212bfa9add22473914a287485f9c349d5b1641..02f5da2deeb2961363390e470ce95d6ac309b9b0 100644 (file)
@@ -23,7 +23,7 @@ namespace ucl {
 
        void NaviItem::popTo() const
        {
-               const auto navi = dynamicCast<Naviframe>(getWidget());
+               const auto navi = dynamicWidgetCast<Naviframe>(getWidget());
                const bool needStartTransition =
                                (navi && (navi->getTopItem() != *this));
 
@@ -36,7 +36,7 @@ namespace ucl {
 
        void NaviItem::promote() const
        {
-               const auto navi = dynamicCast<Naviframe>(getWidget());
+               const auto navi = dynamicWidgetCast<Naviframe>(getWidget());
                const bool needStartTransition =
                                (navi && (navi->getTopItem() != *this));
 
index d2c0dd65a3e9eeb4ade1d7a2294dc018fb49ebf0..096c6e1b7c1bbeadfec36552341100290cfaca86 100644 (file)
@@ -117,12 +117,11 @@ namespace ucl {
                m_isOwner(isOwner),
                m_isBoundToEo(false),
                m_isEoRefKept(false),
-               m_isSelfRefKept(false),
                m_isSelfRefUnique(false)
        {
                UCL_ASSERT(m_eo, "m_eo is NULL!");
 
-               if (m_rc) {
+               if (isShared()) {
                        evas_object_event_callback_priority_add(m_eo, EVAS_CALLBACK_DEL,
                                        EO_CALLBACK_PRIORITY_AFTER,
                                        CALLBACK_A(Widget::onEoDel), this);
@@ -139,7 +138,7 @@ namespace ucl {
                        unbindFromEo();
                }
 
-               if (m_rc) {
+               if (isShared()) {
                        evas_object_event_callback_del_full(m_eo, EVAS_CALLBACK_DEL,
                                        CALLBACK_A(Widget::onEoDel), this);
                }
@@ -177,7 +176,7 @@ namespace ucl {
        {
                updateEoRef();
 
-               if (m_rc) {
+               if (isShared()) {
                        updateSelfRef();
                }
        }
@@ -202,14 +201,10 @@ namespace ucl {
 
        void Widget::updateSelfRef()
        {
-               if (needKeepSelfRef()) {
-                       if (!m_isSelfRefKept) {
-                               m_isSelfRefKept = true;
-                               m_rc->ref();
-                       }
-               } else if (m_isSelfRefKept) {
-                       m_isSelfRefKept = false;
-                       m_rc->unref();
+               if (!needKeepSelfRef()) {
+                       m_selfRef.reset();
+               } else if (!m_selfRef) {
+                       m_selfRef = asShared(*this);
                }
        }
 
@@ -228,8 +223,8 @@ namespace ucl {
 
        void Widget::onEoDel(Evas *e, Evas_Object *obj, void *event_info)
        {
-               if (!m_isSelfRefKept) {
-                       FLOG("UNEXPECTED! m_isSelfRefKept: %d;", m_isSelfRefKept);
+               if (!m_selfRef) {
+                       FLOG("UNEXPECTED! m_selfRef is NULL!");
                        m_eo = nullptr;
                        return;
                }
@@ -239,8 +234,7 @@ namespace ucl {
                                        m_isOwner, m_isEoRefKept, m_isSelfRefUnique);
                        m_eo = nullptr;
                }
-               m_isSelfRefKept = false;
-               m_rc->unref();
+               m_selfRef.reset();
        }
 
        void Widget::onUniqueChanged(bool isUnique)
index e7d7bd963cb204c8934d7e8d3a0288d7279f3753..e23bc0208257a084dc6c66cff5ba201a07c3753e 100644 (file)
@@ -60,7 +60,7 @@ namespace ucl {
                }
 
                if (flags & PF_ADD_SELF_EXCEPT) {
-                       addDeactivatorException(m_rc->getObjPtr());
+                       addDeactivatorException(getObjPtr());
                }
 
                m_isPrepared = true;
@@ -89,7 +89,7 @@ namespace ucl {
                }
 
                if (flags & PF_ADD_SELF_EXCEPT) {
-                       addDeactivatorException(m_rc->getObjPtr());
+                       addDeactivatorException(getObjPtr());
                }
 
                m_window = parent.m_window;
@@ -125,22 +125,22 @@ namespace ucl {
 
        void GuiPresenter::sendActivate(Widget &sender)
        {
-               sendDeactivator(sender, impl::ACTIVATE_BY, m_rc->getObjPtr());
+               sendDeactivator(sender, impl::ACTIVATE_BY, getObjPtr());
        }
 
        void GuiPresenter::sendDeactivate(Widget &sender)
        {
-               sendDeactivator(sender, impl::DEACTIVATE_BY, m_rc->getObjPtr());
+               sendDeactivator(sender, impl::DEACTIVATE_BY, getObjPtr());
        }
 
        void GuiPresenter::broadcastActivate()
        {
-               broadcastDeactivator(impl::ACTIVATE_BY, m_rc->getObjPtr());
+               broadcastDeactivator(impl::ACTIVATE_BY, getObjPtr());
        }
 
        void GuiPresenter::broadcastDeactivate()
        {
-               broadcastDeactivator(impl::DEACTIVATE_BY, m_rc->getObjPtr());
+               broadcastDeactivator(impl::DEACTIVATE_BY, getObjPtr());
        }
 
        void GuiPresenter::sendDeactivator(Widget &sender,