[gparted/psusi/refactor: 16/19] Refactor hfsplus to use execute_command_async



commit ec1150ade3fccf9fa0c84249934799ea3538c900
Author: Phillip Susi <psusi ubuntu com>
Date:   Mon Feb 20 20:11:26 2012 -0500

    Refactor hfsplus to use execute_command_async
    
    Instead of Filesystem::execute_command or Utils::execute_command, the
    hfsplus 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/hfsplus.h |   15 +++++++++
 src/hfsplus.cc    |   91 +++++++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 93 insertions(+), 13 deletions(-)
---
diff --git a/include/hfsplus.h b/include/hfsplus.h
index 4724ac2..e5684b8 100644
--- a/include/hfsplus.h
+++ b/include/hfsplus.h
@@ -30,20 +30,35 @@ class hfsplus : 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/hfsplus.cc b/src/hfsplus.cc
index 66c868b..1627813 100644
--- a/src/hfsplus.cc
+++ b/src/hfsplus.cc
@@ -52,23 +52,43 @@ void hfsplus::set_used_sectors( Partition & partition )
 {
 }
 
+void hfsplus::set_used_sectors( Partition & partition, sigc::slot<bool, double> slot )
+{
+}
+
 void hfsplus::read_label( Partition & partition )
 {
-	if ( ! Utils::execute_command( "vol_id " + partition .get_path(), output, error, true ) )
+	read_label( partition, unlock_mutex );
+	mutex.lock();
+}
+
+void hfsplus::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, &hfsplus::read_label2 ),
+				     &partition ) );
+}
+
+bool hfsplus::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 ; 
+			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 hfsplus::write_label( const Partition & partition, OperationDetail & operationdetail )
@@ -76,23 +96,43 @@ bool hfsplus::write_label( const Partition & partition, OperationDetail & operat
 	return true ;
 }
 
+void hfsplus::write_label( const Partition & partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+}
+
 void hfsplus::read_uuid( Partition & partition )
 {
 }
 
+void hfsplus::read_uuid( Partition & partition, sigc::slot<bool, double> slot )
+{
+}
+
 bool hfsplus::write_uuid( const Partition & partition, OperationDetail & operationdetail )
 {
 	return true ;
 }
 
+void hfsplus::write_uuid( const Partition & partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+}
+
 bool hfsplus::create( const Partition & new_partition, OperationDetail & operationdetail )
 {
+	create( new_partition, operationdetail, unlock_mutex );
+	mutex.lock();
+	return success;
+}
+
+void hfsplus::create( const Partition & new_partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+	this->slot = slot;
 	Glib::ustring cmd = "";
-	if( new_partition .label .empty() )
-		cmd = "mkfs.hfsplus " + new_partition .get_path() ;
+	if( new_partition.label.empty() )
+		cmd = "mkfs.hfsplus " + new_partition.get_path();
 	else
-		cmd = "mkfs.hfsplus -v \"" + new_partition .label + "\" " + new_partition .get_path() ;
-	return ! execute_command( cmd , operationdetail ) ;
+		cmd = "mkfs.hfsplus -v \"" + new_partition.label + "\" " + new_partition.get_path();
+	execute_command( cmd , operationdetail, set_success );
 }
 
 bool hfsplus::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
@@ -100,6 +140,11 @@ bool hfsplus::resize( const Partition & partition_new, OperationDetail & operati
 	return true ;
 }
 
+void hfsplus::resize( const Partition & partition_new, OperationDetail & operationdetail,
+		      bool fill_partition, sigc::slot<bool, double> slot )
+{
+}
+
 bool hfsplus::move( const Partition & partition_new
                   , const Partition & partition_old
                   , OperationDetail & operationdetail
@@ -108,6 +153,11 @@ bool hfsplus::move( const Partition & partition_new
 	return true ;
 }
 
+void hfsplus::move( const Partition & partition_new, const Partition & partition_old,
+		    OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+}
+
 bool hfsplus::copy( const Glib::ustring & src_part_path,
 		    const Glib::ustring & dest_part_path,
 		    OperationDetail & operationdetail )
@@ -115,9 +165,24 @@ bool hfsplus::copy( const Glib::ustring & src_part_path,
 	return true ;
 }
 
+void hfsplus::copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path,
+		    OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+}
+
 bool hfsplus::check_repair( const Partition & partition, OperationDetail & operationdetail )
 {
-	return ! execute_command( "fsck.hfsplus -f -y " + partition .get_path(), operationdetail ) ;
+	check_repair( partition, operationdetail, unlock_mutex );
+	mutex.lock();
+	return success;
+}
+
+void hfsplus::check_repair( const Partition & partition, OperationDetail & operationdetail, sigc::slot<bool, double> slot )
+{
+	this->slot = slot;
+	execute_command( "fsck.hfsplus -f -y " + partition.get_path(),
+			 operationdetail,
+			 set_success );
 }
 
 } //GParted



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