Bläddra i källkod

Re-load the config periodically and on-demand

Zachary Kotlarek 13 år sedan
förälder
incheckning
b3e210dc87
1 ändrade filer med 17 tillägg och 0 borttagningar
  1. 17 0
      dmx/rifftrax.pl

+ 17 - 0
dmx/rifftrax.pl

@@ -21,6 +21,7 @@ my $JUMP_THRESHOLD = 5;
 my $VOLUME_RIFF    = 65;
 my $VOLUME_RIFF    = 65;
 my $VOLUME_STD     = 40;
 my $VOLUME_STD     = 40;
 my $VOL_STEP       = 1 / 20;
 my $VOL_STEP       = 1 / 20;
+my $CONFIG_DELAY   = 300;
 
 
 # Prototypes
 # Prototypes
 sub playRiff();
 sub playRiff();
@@ -90,6 +91,19 @@ while (1) {
 		die('No update on state socket in past ' . $PULL_TIMEOUT . " seconds. Exiting...\n");
 		die('No update on state socket in past ' . $PULL_TIMEOUT . " seconds. Exiting...\n");
 	}
 	}
 
 
+	# Re-read the config on-demand
+	if ($state eq 'HUP') {
+		parseConfig($CONFIG_PATH, \%RIFFS);
+
+		# Skip further processing this loop -- the exists hash is useless
+		next;
+	}
+
+	# Re-read the config periodically (unless we are currently playing)
+	if (!$riff && time() > $RIFFS{'_LAST_CONFIG_UPDATE'} + $CONFIG_DELAY) {
+		parseConfig($CONFIG_PATH, \%RIFFS);
+	}
+
 	# Handle volume changes
 	# Handle volume changes
 	if ($riff) {
 	if ($riff) {
 		if ($state eq 'VOL+' || $state eq 'VOL-') {
 		if ($state eq 'VOL+' || $state eq 'VOL-') {
@@ -406,4 +420,7 @@ sub parseConfig($$) {
 		}
 		}
 	}
 	}
 	closedir(CONF);
 	closedir(CONF);
+
+	# Record the last update time
+	$riffs->{'_LAST_CONFIG_UPDATE'} = time();
 }
 }