From b65700d0f874f096696c12c9e9fdc96be995d9d0 Mon Sep 17 00:00:00 2001 From: Jehun Lim Date: Fri, 22 May 2015 14:37:29 +0900 Subject: [PATCH] convert DestroyMediaList to private method Change-Id: I335698cb243092eb2e9a1ca8d97e39566c2b121e Signed-off-by: Jehun Lim --- include/data/mediadata.h | 6 ++-- src/data/mediadata.cpp | 63 ++++++++++++--------------------- src/main.cpp | 2 +- src/view/gallery-view/gallery_view.cpp | 12 ++----- src/view/gallery-view/layout_all.cpp | 5 ++- src/view/gallery-view/layout_events.cpp | 7 ++-- src/view/gallery-view/layout_folder.cpp | 7 ++-- 7 files changed, 37 insertions(+), 65 deletions(-) diff --git a/include/data/mediadata.h b/include/data/mediadata.h index 3be2eec..2427982 100644 --- a/include/data/mediadata.h +++ b/include/data/mediadata.h @@ -21,7 +21,6 @@ class CMediadata : public CMediaContentListener { private: static CMediadata *instance; struct SMediadata *m; - static int g_ref_count; private: static bool sm_CbEachMediaInfo(media_info_h media_h, void *dt); @@ -40,6 +39,8 @@ private: void m_DeleteEventList(void); void m_DeleteMediaList(int type); + void m_DestroyMediaList(void); + bool m_CreateFilter(filter_h *filter, int type); bool m_DestroyFilter(filter_h filter); @@ -52,8 +53,7 @@ public: static CMediadata *GetInstance(void); - bool CreateMediaList(int source_type, int media); - void DestroyMediaList(void); + bool InitMediaList(int source_type, int media); CMediaInfo *FindMediaInfo(Eina_List *media_list, const char *path); Eina_List *CreateListforType(Eina_List *media_list, int type); diff --git a/src/data/mediadata.cpp b/src/data/mediadata.cpp index 1210ce7..1ed580b 100644 --- a/src/data/mediadata.cpp +++ b/src/data/mediadata.cpp @@ -30,7 +30,6 @@ #define MEDIA_CONDITION_VIDEO "(MEDIA_TYPE=1)" struct SMediadata { - filter_h filter; Eina_List *folderlist; Eina_List *folder_medialist; Eina_List *eventlist; @@ -54,7 +53,6 @@ enum { }; CMediadata *CMediadata::instance = NULL; -int CMediadata::g_ref_count = 0; void CMediadata::m_DeleteFolderList(void) { @@ -112,19 +110,12 @@ void CMediadata::m_DeleteMediaList(int type) m->folder_medialist = NULL; } -void CMediadata::DestroyMediaList(void) +void CMediadata::m_DestroyMediaList(void) { - if (m->folderlist) - m_DeleteFolderList(); - - if (m->eventlist) - m_DeleteEventList(); - - if (m->medialist) - m_DeleteMediaList(E_TYPE_MEDIA); - - if (m->folder_medialist) - m_DeleteMediaList(E_TYPE_FOLDER_MEDIA); + m_DeleteFolderList(); + m_DeleteEventList(); + m_DeleteMediaList(E_TYPE_MEDIA); + m_DeleteMediaList(E_TYPE_FOLDER_MEDIA); } bool CMediadata::m_CreateFilter(filter_h *filter, int type) @@ -463,19 +454,16 @@ error: m_DestroyFilter(filter); delete finfo; free(uuid); - DestroyMediaList(); + m_DestroyMediaList(); return false; } bool CMediadata::Initialize(void) { - int ret; + ASSERT(!instance); - if (g_ref_count > 0) { - g_ref_count++; - return false; - } + int ret; instance = new CMediadata; if (!instance) @@ -501,8 +489,6 @@ bool CMediadata::Initialize(void) goto err; } - g_ref_count++; - return true; err: @@ -513,24 +499,16 @@ err: void CMediadata::Finalize(void) { - if (!instance || !instance->m) - return; + ASSERT(instance); int ret; - if (g_ref_count <= 0) - return; - - g_ref_count--; - - if (g_ref_count == 0) { - instance->DestroyMediaList(); - instance->Destroy(); + instance->m_DestroyMediaList(); + instance->Destroy(); - ret = media_content_disconnect(); - if (ret != MEDIA_CONTENT_ERROR_NONE) - _ERR("Media Content Connect Failed"); - } + ret = media_content_disconnect(); + if (ret != MEDIA_CONTENT_ERROR_NONE) + _ERR("Media Content Connect Failed"); delete instance->m; @@ -543,27 +521,30 @@ CMediadata *CMediadata::GetInstance() return instance; } -bool CMediadata::CreateMediaList(int source_type, int media) +bool CMediadata::InitMediaList(int source_type, int media) { int ret; + filter_h filter; m->source_type = source_type; m->media = media; - m_CreateFilter(&m->filter, E_FILTER_TYPE_FOLDER); + m_DestroyMediaList(); - ret = media_folder_foreach_folder_from_db(m->filter, + m_CreateFilter(&filter, E_FILTER_TYPE_FOLDER); + + ret = media_folder_foreach_folder_from_db(filter, sm_CbEachFolderInfo, (void *)this); if (ret != MEDIA_CONTENT_ERROR_NONE) { _ERR("Failed to read from folders"); - m_DestroyFilter(m->filter); + m_DestroyFilter(filter); return false; } if (m->medialist) m_GetEventList(); - m_DestroyFilter(m->filter); + m_DestroyFilter(filter); return true; } diff --git a/src/main.cpp b/src/main.cpp index e89c5f4..cd49c4d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -294,7 +294,7 @@ bool CGalleryApp::m_CreatePhotoViewerView(void) return false; } - m->pMediadata->CreateMediaList(m->source, m->media_type); + m->pMediadata->InitMediaList(m->source, m->media_type); vd->minfo = m->pMediadata->FindMediaInfo(m->pMediadata->MediaList(), m->id); vd->media_list = m->pMediadata->CreateListforType( diff --git a/src/view/gallery-view/gallery_view.cpp b/src/view/gallery-view/gallery_view.cpp index 4c95170..88ed151 100644 --- a/src/view/gallery-view/gallery_view.cpp +++ b/src/view/gallery-view/gallery_view.cpp @@ -256,9 +256,7 @@ void CGalleryView::m_SortLayout(void) void CGalleryView::m_SourceChange(void) { - m->pMediadata->DestroyMediaList(); - - if (!m->pMediadata->CreateMediaList(m->source_type, m->arglist->media_type)) + if (!m->pMediadata->InitMediaList(m->source_type, m->arglist->media_type)) return; m_DrawContentArea(m->current_layout); @@ -361,7 +359,7 @@ bool CGalleryView::m_DrawLeftArea(void) elm_object_part_content_set(Base(), PART_LEFTSWALLOW, box); - m->pMediadata->CreateMediaList(m->source_type, m->arglist->media_type); + m->pMediadata->InitMediaList(m->source_type, m->arglist->media_type); /* Set focus directions and initial focus */ elm_object_focus_next_object_set(m->btn[MENUITEM_SIZE - 1], @@ -633,8 +631,6 @@ void CGalleryView::Destroy(void) if (CUsbListener::FlagCreate()) CUsbListener::Destroy(); - m->pMediadata->DestroyMediaList(); - m->pLayoutMgr->RemoveLayout(m->pAllLayout); m->pAllLayout->Destroy(); delete m->pAllLayout; @@ -885,9 +881,7 @@ void CGalleryView::OnDbUpdated(const SEntity *entity) m->pCtxPopup = NULL; } - m->pMediadata->DestroyMediaList(); - - if (!m->pMediadata->CreateMediaList( + if (!m->pMediadata->InitMediaList( m->source_type, m->arglist->media_type)) return; diff --git a/src/view/gallery-view/layout_all.cpp b/src/view/gallery-view/layout_all.cpp index 366ac55..a63de2c 100644 --- a/src/view/gallery-view/layout_all.cpp +++ b/src/view/gallery-view/layout_all.cpp @@ -683,13 +683,12 @@ void CAllLayout::Destroy(void) Disconnect(m->grid); - if (m->media_list) - eina_list_free(m->media_list); - evas_object_del(Layout()); CBaseLayout::Destroy(); + eina_list_free(m->media_list); + delete m; m = NULL; } diff --git a/src/view/gallery-view/layout_events.cpp b/src/view/gallery-view/layout_events.cpp index 543a9d6..b4b0a93 100644 --- a/src/view/gallery-view/layout_events.cpp +++ b/src/view/gallery-view/layout_events.cpp @@ -714,14 +714,13 @@ void CEventLayout::Destroy(void) Disconnect(m->grid); - if (m->media_list) - eina_list_free(m->media_list); - evas_object_del(Layout()); CBaseLayout::Destroy(); - free(m); + eina_list_free(m->event_list); + + delete m; m = NULL; } diff --git a/src/view/gallery-view/layout_folder.cpp b/src/view/gallery-view/layout_folder.cpp index eeb28d4..f4cd9e8 100644 --- a/src/view/gallery-view/layout_folder.cpp +++ b/src/view/gallery-view/layout_folder.cpp @@ -480,14 +480,13 @@ void CFolderLayout::Destroy(void) Disconnect(m->grid); - if (m->media_list) - eina_list_free(m->media_list); - evas_object_del(Layout()); CBaseLayout::Destroy(); - free(m); + eina_list_free(m->folder_list); + + delete m; m = NULL; } -- 2.7.4