[gparted] Stop borrowing the constructor to load the LVM2_PV_Info cache (#750582)



commit 81f0b934bce9a8243735e2b8d05c6d70d1e109be
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Fri Jun 5 19:44:07 2015 +0100

    Stop borrowing the constructor to load the LVM2_PV_Info cache (#750582)
    
    An LVM2_PV_Info object contains no member variables as all the data is
    static (exists once in the program and accessed by all objects).  The
    constructor did nothing, except when passed true to load the cache.
    
    Provide a separate load_cache() member function and remove the
    constructors and destructor which do nothing.  The C++ compiler will
    provide a default constructor and destructor, which don't do anything as
    there are no member variables to initialise and finalise.
    
    This makes the interface a little easier to understand.  Mostly a step
    along the way of refactoring how the LVM2_PV_Info cache module works.
    
    Bug 750582 - Refactor the LVM2_PV_Info module object interface and
                 internal cache representation

 include/LVM2_PV_Info.h |    8 +++-----
 src/GParted_Core.cc    |    2 +-
 src/LVM2_PV_Info.cc    |   19 ++++---------------
 3 files changed, 8 insertions(+), 21 deletions(-)
---
diff --git a/include/LVM2_PV_Info.h b/include/LVM2_PV_Info.h
index afdbb6f..ac48913 100644
--- a/include/LVM2_PV_Info.h
+++ b/include/LVM2_PV_Info.h
@@ -33,9 +33,7 @@ namespace GParted
 class LVM2_PV_Info
 {
 public:
-       LVM2_PV_Info() ;
-       LVM2_PV_Info( bool do_refresh ) ;
-       ~LVM2_PV_Info() ;
+       static void load_cache();
        bool is_lvm2_pv_supported() ;
        Glib::ustring get_vg_name( const Glib::ustring & path ) ;
        Byte_Value get_size_bytes( const Glib::ustring & path ) ;
@@ -46,8 +44,8 @@ public:
        std::vector<Glib::ustring> get_error_messages( const Glib::ustring & path ) ;
 private:
        void initialize_if_required() ;
-       void set_command_found() ;
-       void load_lvm2_pv_info_cache() ;
+       static void set_command_found();
+       static void load_lvm2_pv_info_cache();
        Glib::ustring get_pv_attr_by_path( const Glib::ustring & path, unsigned int entry ) const ;
        Glib::ustring get_pv_attr_by_row( unsigned int row, unsigned int entry ) const ;
        Glib::ustring get_vg_attr_by_name( const Glib::ustring & vgname, unsigned int entry ) const ;
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 407e87a..cb6d2be 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -150,7 +150,7 @@ void GParted_Core::set_devices_thread( std::vector<Device> * pdevices )
        Proc_Partitions_Info pp_info( true ) ;  //Refresh cache of proc partition information
        FS_Info fs_info( true ) ;  //Refresh cache of file system information
        DMRaid dmraid( true ) ;    //Refresh cache of dmraid device information
-       LVM2_PV_Info lvm2_pv_info( true ) ;     //Refresh cache of LVM2 PV information
+       LVM2_PV_Info::load_cache();             // Refresh cache of LVM2 PV information
        btrfs::clear_cache() ;
 
        init_maps() ;
diff --git a/src/LVM2_PV_Info.cc b/src/LVM2_PV_Info.cc
index 1863a45..f43a258 100644
--- a/src/LVM2_PV_Info.cc
+++ b/src/LVM2_PV_Info.cc
@@ -84,22 +84,11 @@ std::vector<Glib::ustring> LVM2_PV_Info::lvm2_pv_cache ;
 std::vector<Glib::ustring> LVM2_PV_Info::lvm2_vg_cache ;
 std::vector<Glib::ustring> LVM2_PV_Info::error_messages ;
 
-LVM2_PV_Info::LVM2_PV_Info()
-{
-}
-
-LVM2_PV_Info::LVM2_PV_Info( bool do_refresh )
-{
-       if ( do_refresh )
-       {
-               set_command_found() ;
-               load_lvm2_pv_info_cache() ;
-               lvm2_pv_info_cache_initialized = true ;
-       }
-}
-
-LVM2_PV_Info::~LVM2_PV_Info()
+void LVM2_PV_Info::load_cache()
 {
+       set_command_found();
+       load_lvm2_pv_info_cache();
+       lvm2_pv_info_cache_initialized = true;
 }
 
 bool LVM2_PV_Info::is_lvm2_pv_supported()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]