Switch to a static interface for Proc_Partitions_Info

The Proc_Partitions_Info has a pseudo multi-object interface and uses
the constructor to load the cache.  However all the data in the class is
static.  A Proc_Partitions_Info object doesn't contain any member
variables, yet was needed just to call the member functions.

Make all the member functions static removing the need to use any
Proc_Partitions_Info objects and provide and explicit load_cache()
method.
This commit is contained in:
Mike Fleetwood 2016-07-12 16:47:18 +01:00 committed by Curtis Gedak
parent 91e5a0960e
commit 912766c2e1
3 changed files with 23 additions and 36 deletions

View File

@ -33,13 +33,12 @@ namespace GParted
class Proc_Partitions_Info
{
public:
Proc_Partitions_Info() ;
Proc_Partitions_Info( bool do_refresh ) ;
~Proc_Partitions_Info() ;
std::vector<Glib::ustring> get_device_paths() ;
static void load_cache();
static const std::vector<Glib::ustring> & get_device_paths();
private:
void load_proc_partitions_info_cache() ;
static void initialize_if_required();
static void load_proc_partitions_info_cache();
static bool proc_partitions_info_cache_initialized ;
static std::vector<Glib::ustring> device_paths_cache ;
};

View File

@ -169,7 +169,7 @@ void GParted_Core::set_devices_thread( std::vector<Device> * pdevices )
BlockSpecial::clear_cache(); // MUST BE FIRST. Cache of name to major, minor
// numbers incrementally loaded when BlockSpecial
// objects are created in the following caches.
Proc_Partitions_Info pp_info( true ) ; // SHOULD BE SECOND. Caches /proc/partitions and
Proc_Partitions_Info::load_cache(); // SHOULD BE SECOND. Caches /proc/partitions and
// pre-populates BlockSpecial cache.
FS_Info fs_info( true ) ; //Refresh cache of file system information
DMRaid dmraid( true ) ; //Refresh cache of dmraid device information
@ -191,7 +191,7 @@ void GParted_Core::set_devices_thread( std::vector<Device> * pdevices )
// http://parted.alioth.debian.org/cgi-bin/trac.cgi/ticket/194
//
//try to find all available devices if devices exist in /proc/partitions
std::vector<Glib::ustring> temp_devices = pp_info .get_device_paths() ;
std::vector<Glib::ustring> temp_devices = Proc_Partitions_Info::get_device_paths();
if ( ! temp_devices .empty() )
{
//Try to find all devices in /proc/partitions

View File

@ -30,41 +30,29 @@ namespace GParted
bool Proc_Partitions_Info::proc_partitions_info_cache_initialized = false ;
std::vector<Glib::ustring> Proc_Partitions_Info::device_paths_cache ;
Proc_Partitions_Info::Proc_Partitions_Info()
void Proc_Partitions_Info::load_cache()
{
load_proc_partitions_info_cache();
proc_partitions_info_cache_initialized = true;
}
const std::vector<Glib::ustring> & Proc_Partitions_Info::get_device_paths()
{
initialize_if_required();
return device_paths_cache;
}
// Private Methods
void Proc_Partitions_Info::initialize_if_required()
{
//Ensure that cache has been loaded at least once
if ( ! proc_partitions_info_cache_initialized )
{
proc_partitions_info_cache_initialized = true ;
load_proc_partitions_info_cache() ;
load_proc_partitions_info_cache();
proc_partitions_info_cache_initialized = true;
}
}
Proc_Partitions_Info::Proc_Partitions_Info( bool do_refresh )
{
//Ensure that cache has been loaded at least once
if ( ! proc_partitions_info_cache_initialized )
{
proc_partitions_info_cache_initialized = true ;
if ( do_refresh == false )
load_proc_partitions_info_cache() ;
}
if ( do_refresh )
load_proc_partitions_info_cache() ;
}
Proc_Partitions_Info::~Proc_Partitions_Info()
{
}
std::vector<Glib::ustring> Proc_Partitions_Info::get_device_paths()
{
return device_paths_cache ;
}
//Private Methods
void Proc_Partitions_Info::load_proc_partitions_info_cache()
{
device_paths_cache .clear() ;