[Tkabber-dev] r58 - trunk/plugins/now_playing

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sun Sep 30 19:04:52 MSD 2007


Author: kostix
Date: 2007-09-30 19:04:52 +0400 (Sun, 30 Sep 2007)
New Revision: 58

Modified:
   trunk/plugins/now_playing/mpd.tcl
Log:
now_playing/mpd.tcl:
 * Changed error handling: now ACK replies are just reported as errors.
 * Added convenience proc [1000x] to convert seconds to milliseconds.
 * Added convenience alias [die] to use instead of [return -code error].


Modified: trunk/plugins/now_playing/mpd.tcl
===================================================================
--- trunk/plugins/now_playing/mpd.tcl	2007-09-30 00:01:00 UTC (rev 57)
+++ trunk/plugins/now_playing/mpd.tcl	2007-09-30 15:04:52 UTC (rev 58)
@@ -53,6 +53,10 @@
 			lrange $values [llength $args] end
 		}
 	}
+
+	proc 1000x sec { expr {$sec * 1000} }
+
+	interp alias {} [mycmd die] {} return -code error
 }
 
 #### Polling:
@@ -88,7 +92,7 @@
 
 	if {$options(check_timeout) > 0} {
 		set repollid [after \
-			[expr {$options(check_timeout) * 1000}] [info level 0]]
+			[1000x $options(check_timeout)] [info level 0]]
 	}
 }
 
@@ -160,7 +164,9 @@
 	if {!$connected} { close $sock }
 
 	if {[info exists state(async)]} {
-		namespace eval :: $state(async) [list $sock $connected $error]
+		set async $state(async)
+		unset state
+		namespace eval :: $async [list $sock $connected $error]
 	} else {
 		set state(connected) $connected
 		set state(error)     $error
@@ -205,7 +211,7 @@
 	variable mpd
 
 	set mpd(sock) [sock_connect $options(sock_host) $options(sock_port) \
-		-timeout [expr {$options(sock_connect_timeout) * 1000}] \
+		-timeout [1000x $options(sock_connect_timeout)] \
 		-async [mycmd mpd_on_connected]]
 }
 
@@ -225,24 +231,18 @@
 	}
 }
 
-proc now_playing::mpd_error error {
+proc now_playing::mpd_handle_error {} {
 	mpd_cleanup
 	monitoring off
-	return -code error $error
 }
 
-proc now_playing::mpd_parse_ack {ack vcmd vmsg} {
-	upvar 1 $vcmd cmd $vmsg msg
-	regexp {^ACK.*{(\w+)} (.*)$} $s -> cmd msg
-}
-
 proc now_playing::mpd_schedule_reconnect {} {
 	debugmsg tune [info level 0]
 
 	variable options
 	variable repollid
 
-	set repollid [after [expr {$options(sock_reconnect_timeout) * 1000}] \
+	set repollid [after [1000x $options(sock_reconnect_timeout)] \
 		[mycmd mpd_connect]]
 }
 
@@ -292,7 +292,8 @@
 
 	switch -- $line {
 		ACK* {
-			mpd_error $line
+			mpd_handle_error
+			die $line
 		}
 		OK {
 			mpd_start_harvesting $sock
@@ -337,7 +338,7 @@
 	variable options
 	variable repollid
 
-	set repollid [after [expr $options(check_timeout) * 1000] \
+	set repollid [after [1000x $options(check_timeout)] \
 		[mycmd mpd_yield $sock]]
 }
 
@@ -363,7 +364,8 @@
 			set (songid)   [mpd_getval $line songid]
 		}
 		ACK*       {
-			mpd_error $line
+			mpd_handle_error
+			die $line
 		}
 		OK         {
 			switch -- [mpd_process_status $sock] {
@@ -461,7 +463,8 @@
 			set (source) [mpd_getval $line Album]
 		}
 		ACK*     {
-			mpd_error $line
+			mpd_handle_error
+			die $line
 		}
 		OK       {
 			mpd_process_songinfo $sock



More information about the Tkabber-dev mailing list