[gparted] Switch to a static interface for Proc_Partitions_Info
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Switch to a static interface for Proc_Partitions_Info
- Date: Sun, 7 Aug 2016 20:54:25 +0000 (UTC)
commit 912766c2e11aab2cecd916bdc2027cc14087c4a0
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Tue Jul 12 16:47:18 2016 +0100
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.
include/Proc_Partitions_Info.h | 9 ++++-----
src/GParted_Core.cc | 4 ++--
src/Proc_Partitions_Info.cc | 38 +++++++++++++-------------------------
3 files changed, 19 insertions(+), 32 deletions(-)
---
diff --git a/include/Proc_Partitions_Info.h b/include/Proc_Partitions_Info.h
index 8084492..23b4348 100644
--- a/include/Proc_Partitions_Info.h
+++ b/include/Proc_Partitions_Info.h
@@ -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 ;
};
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 38d4d9c..441614f 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -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
diff --git a/src/Proc_Partitions_Info.cc b/src/Proc_Partitions_Info.cc
index fd16fb6..4262ba3 100644
--- a/src/Proc_Partitions_Info.cc
+++ b/src/Proc_Partitions_Info.cc
@@ -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()
{
- //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 )
+const std::vector<Glib::ustring> & Proc_Partitions_Info::get_device_paths()
{
- //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() ;
+ initialize_if_required();
+ return device_paths_cache;
}
-Proc_Partitions_Info::~Proc_Partitions_Info()
-{
-}
+// Private Methods
-std::vector<Glib::ustring> Proc_Partitions_Info::get_device_paths()
+void Proc_Partitions_Info::initialize_if_required()
{
- return device_paths_cache ;
+ if ( ! proc_partitions_info_cache_initialized )
+ {
+ load_proc_partitions_info_cache();
+ proc_partitions_info_cache_initialized = true;
+ }
}
-//Private Methods
-
void Proc_Partitions_Info::load_proc_partitions_info_cache()
{
device_paths_cache .clear() ;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]