[gparted/psusi/refactor: 15/19] Refactor hfs to use execute_command_async
- From: Phillip Susi <psusi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted/psusi/refactor: 15/19] Refactor hfs to use execute_command_async
- Date: Tue, 20 Mar 2012 00:03:41 +0000 (UTC)
commit c4bd6465a9c49fbbb29125bf96ab3f6f952940ab
Author: Phillip Susi <psusi ubuntu com>
Date: Mon Feb 20 19:22:39 2012 -0500
Refactor hfs to use execute_command_async
Instead of Filesystem::execute_command or Utils::execute_command, the
hfs methods now use Filesystem::execute_command_async, and block the
calling thread on a mutex until the job completes. Methods that invoked
multiple external utilities have been split into multiple functions that
are invoked as the callback when the previous command has completed.
include/hfs.h | 15 +++++++++
src/hfs.cc | 93 ++++++++++++++++++++++++++++++++++++++++++++++++--------
2 files changed, 94 insertions(+), 14 deletions(-)
---
diff --git a/include/hfs.h b/include/hfs.h
index fe495a9..de8b46d 100644
--- a/include/hfs.h
+++ b/include/hfs.h
@@ -30,20 +30,35 @@ class hfs : public FileSystem
public:
FS get_filesystem_support() ;
void set_used_sectors( Partition & partition ) ;
+ void set_used_sectors( Partition & partition, sigc::slot<bool, double> slot );
void read_label( Partition & partition ) ;
+ void read_label( Partition & partition, sigc::slot<bool, double> slot );
bool write_label( const Partition & partition, OperationDetail & operationdetail ) ;
+ void write_label( const Partition & partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot );
void read_uuid( Partition & partition ) ;
+ void read_uuid( Partition & partition, sigc::slot<bool, double> slot );
bool write_uuid( const Partition & partition, OperationDetail & operationdetail ) ;
+ void write_uuid( const Partition & partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot );
bool create( const Partition & new_partition, OperationDetail & operationdetail ) ;
+ void create( const Partition & new_partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot );
bool resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition = false ) ;
+ void resize( const Partition & partition_new, OperationDetail & operationdetail,
+ bool fill_partition, sigc::slot<bool, double> slot );
bool move( const Partition & partition_new
, const Partition & partition_old
, OperationDetail & operationdetail
) ;
+ void move( const Partition & partition_new, const Partition & partition_old,
+ OperationDetail & operationdetail, sigc::slot<bool, double> slot );
bool copy( const Glib::ustring & src_part_path,
const Glib::ustring & dest_part_path,
OperationDetail & operationdetail ) ;
+ void copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path,
+ OperationDetail & operationdetail, sigc::slot<bool, double> slot );
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
+ void check_repair( const Partition & partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot );
+private:
+ bool read_label2( double progress, Partition *partition );
};
} //GParted
diff --git a/src/hfs.cc b/src/hfs.cc
index 84e1b60..bec94e7 100644
--- a/src/hfs.cc
+++ b/src/hfs.cc
@@ -54,23 +54,43 @@ void hfs::set_used_sectors( Partition & partition )
{
}
+void hfs::set_used_sectors( Partition & partition, sigc::slot<bool, double> slot )
+{
+}
+
void hfs::read_label( Partition & partition )
{
- if ( ! Utils::execute_command( "vol_id " + partition .get_path(), output, error, true ) )
+ read_label( partition, unlock_mutex );
+ mutex.lock();
+}
+
+void hfs::read_label( Partition & partition, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
+ execute_command( "vol_id " + partition .get_path(),
+ sigc::bind( sigc::mem_fun( *this, &hfs::read_label2 ),
+ &partition ) );
+}
+
+bool hfs::read_label2( double progress, Partition *partition )
+{
+ if ( progress != 1.0 )
+ return false;
+ if ( !exit_status )
{
- Glib::ustring label = Utils::regexp_label( output, "ID_FS_LABEL=([^\n]*)" ) ;
+ Glib::ustring label = Utils::regexp_label( output, "ID_FS_LABEL=([^\n]*)" );
//FIXME: find a better way to see if label is empty.. imagine someone uses 'untitled' as label.... ;)
- if( label != "untitled" )
- partition .label = label ;
+ if( label != "untitled" )
+ partition->label = label;
}
else
{
- if ( ! output .empty() )
- partition .messages .push_back( output ) ;
-
- if ( ! error .empty() )
- partition .messages .push_back( error ) ;
+ if ( !output.empty() )
+ partition->messages.push_back( output );
+ if ( !error.empty() )
+ partition->messages.push_back( error );
}
+ return slot( 1.0 );
}
bool hfs::write_label( const Partition & partition, OperationDetail & operationdetail )
@@ -78,23 +98,43 @@ bool hfs::write_label( const Partition & partition, OperationDetail & operationd
return true ;
}
+void hfs::write_label( const Partition & partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+}
+
void hfs::read_uuid( Partition & partition )
{
}
+void hfs::read_uuid( Partition & partition, sigc::slot<bool, double> slot )
+{
+}
+
bool hfs::write_uuid( const Partition & partition, OperationDetail & operationdetail )
{
return true ;
}
+void hfs::write_uuid( const Partition & partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+}
+
bool hfs::create( const Partition & new_partition, OperationDetail & operationdetail )
{
+ create( new_partition, operationdetail, unlock_mutex );
+ mutex.lock();
+ return success;
+}
+
+void hfs::create( const Partition & new_partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
Glib::ustring cmd = "";
- if( new_partition .label .empty() )
- cmd = "hformat " + new_partition .get_path() ;
+ if( new_partition.label.empty() )
+ cmd = "hformat " + new_partition.get_path();
else
- cmd = "hformat -l \"" + new_partition .label + "\" " + new_partition .get_path() ;
- return ! execute_command( cmd , operationdetail ) ;
+ cmd = "hformat -l \"" + new_partition.label + "\" " + new_partition.get_path();
+ execute_command( cmd , operationdetail, set_success );
}
bool hfs::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
@@ -102,6 +142,11 @@ bool hfs::resize( const Partition & partition_new, OperationDetail & operationde
return true ;
}
+void hfs::resize( const Partition & partition_new, OperationDetail & operationdetail,
+ bool fill_partition, sigc::slot<bool, double> slot )
+{
+}
+
bool hfs::move( const Partition & partition_new
, const Partition & partition_old
, OperationDetail & operationdetail
@@ -110,6 +155,11 @@ bool hfs::move( const Partition & partition_new
return true ;
}
+void hfs::move( const Partition & partition_new, const Partition & partition_old,
+ OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+}
+
bool hfs::copy( const Glib::ustring & src_part_path,
const Glib::ustring & dest_part_path,
OperationDetail & operationdetail )
@@ -117,10 +167,25 @@ bool hfs::copy( const Glib::ustring & src_part_path,
return true ;
}
+void hfs::copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path,
+ OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+}
+
bool hfs::check_repair( const Partition & partition, OperationDetail & operationdetail )
{
+ check_repair( partition, operationdetail, unlock_mutex );
+ mutex.lock();
+ return success;
+}
+
+void hfs::check_repair( const Partition & partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+ this->slot = slot;
//FIXME: find out what the returnvalue is in case of modified.. also check what the -a flag does.. (there is no manpage)
- return ! execute_command( "hfsck -v " + partition .get_path(), operationdetail ) ;
+ execute_command( "hfsck -v " + partition .get_path(),
+ operationdetail,
+ set_success );
}
} //GParted
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]