[Xfce4-commits] <eatmonkey:aria2-xml-rpc> Thread the shutdown method of Aria2

Mike Massonnet noreply at xfce.org
Wed Feb 3 14:44:01 CET 2010


Updating branch refs/heads/aria2-xml-rpc
         to 24422b4e953a6b05f112debf91c14c22e8552a3b (commit)
       from 24cadb5a63db003efb16ed100a8fbd0a4887b5b7 (commit)

commit 24422b4e953a6b05f112debf91c14c22e8552a3b
Author: Mike Massonnet <mmassonnet at xfce.org>
Date:   Wed Feb 3 14:39:53 2010 +0100

    Thread the shutdown method of Aria2
    
    The shutdown method is now threaded and the GUI code has been updated to
    quit once the server has safely quit. The new signal "shutdown" has been
    introduced just for this purpose on the Aria2 class.

 src/eataria2.rb   |   35 ++++++++++++++++++++++-------------
 src/eatmanager.rb |   10 +++++++---
 2 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/src/eataria2.rb b/src/eataria2.rb
index fe8edc1..6c6fcf2 100644
--- a/src/eataria2.rb
+++ b/src/eataria2.rb
@@ -43,6 +43,8 @@ class Eat::Aria2 < GLib::Object
 			nil)					# Return type: void
 	signal_new("disconnected", GLib::Signal::RUN_FIRST, nil,
 			nil)					# Return type: void
+	signal_new("shutdown", GLib::Signal::RUN_FIRST, nil,
+			nil)					# Return type: void
 	signal_new("download_status", GLib::Signal::RUN_FIRST, nil,
 			nil,					# Return type: void
 			String)					# Parameters: gid
@@ -60,6 +62,8 @@ class Eat::Aria2 < GLib::Object
 	end
 	def signal_do_disconnected()
 	end
+	def signal_do_shutdown()
+	end
 	def signal_do_download_status(gid)
 	end
 	def signal_do_download_completed(gid)
@@ -83,6 +87,7 @@ class Eat::Aria2 < GLib::Object
 		@use_local_server = true
 		@version = "n/a"
 		@@client = nil if !defined? @@client
+		@shutdown_thread = nil
 
 		if !defined? @@pid
 			begin
@@ -192,6 +197,7 @@ class Eat::Aria2 < GLib::Object
 		return if @@client and force == false
 		@is_connected = false
 		Thread.new do
+			@shutdown_thread.join if @shutdown_thread != nil
 			begin
 				debug("connect")
 				@@client = XMLRPC::Client.new3({:host => @hostname, :path => "/rpc",
@@ -243,21 +249,24 @@ class Eat::Aria2 < GLib::Object
 	Disconnect and terminates the local server if it exists.
 =end
 	def shutdown()
-		debug("shutdown", @@pid)
-		begin
-			if @@pid > 0
-				FileUtils.rm(@confdir+"/aria2.pid", :force => true)
-				Process.kill("TERM", @@pid)
-				sleep 1 while Process.kill("CONT", @@pid)
+		@shutdown_thread = Thread.new do
+			debug("shutdown", @@pid)
+			@is_connected = false
+			begin
+				if @@pid > 0
+					FileUtils.rm(@confdir+"/aria2.pid", :force => true)
+					Process.kill("TERM", @@pid)
+					sleep 1 while Process.kill("CONT", @@pid)
+				end
+			rescue Errno::ESRCH
+				# Process does no more exist
+			rescue
+				p $!
 			end
-		rescue Errno::ESRCH
-			# Process does no more exist
-		rescue
-			p $!
+			@@pid = 0
+			@@client = nil
+			signal_emit("shutdown")
 		end
-		@@pid = 0
-		@@client = nil
-		@is_connected = false
 	end
 
 	# Adds new HTTP(S)/FTP/BitTorrent/Magnet URI.
diff --git a/src/eatmanager.rb b/src/eatmanager.rb
index 154cdf3..a919951 100644
--- a/src/eatmanager.rb
+++ b/src/eatmanager.rb
@@ -45,13 +45,14 @@ class Eat::Manager
 		@action_pause = builder["action-pause"]
 		@action_resume = builder["action-resume"]
 		@action_remove = builder["action-remove"]
+		@action_settings = builder["action-settings"]
 
 		# Setup actions
 		@action_add.signal_connect("activate") { action_add }
 		@action_pause.signal_connect("activate") { action_pause }
 		@action_resume.signal_connect("activate") { action_resume }
 		@action_remove.signal_connect("activate") { action_remove }
-		builder["action-settings"].signal_connect("activate") { show_settings_dialog }
+		@action_settings.signal_connect("activate") { show_settings_dialog }
 		builder["action-quit"].signal_connect("activate") { action_quit }
 		builder["action-about"].signal_connect("activate") { show_about_dialog }
 
@@ -263,8 +264,11 @@ class Eat::Manager
 	private
 
 	def action_quit()
-		@aria2.shutdown # TODO make this optional
-		main_quit
+		# TODO make this optional e.g. keep active downloads running
+		set_sensitive(false)
+		@action_settings.set_sensitive(false)
+		@aria2.signal_connect("shutdown") { main_quit }
+		@aria2.shutdown
 	end
 
 	def action_add()



More information about the Xfce4-commits mailing list