Imported Upstream version 3.3.2
[debian/amanda] / perl / Amanda / Taper / Controller.pm
index cb0e85cfb18ac1822f261324e1398454f2f89fa0..a1a6c091000cb494eb5233bd3b12b3bed7df63b1 100644 (file)
@@ -1,5 +1,4 @@
-#! @PERL@
-# Copyright (c) 2009, 2010 Zmanda Inc.  All Rights Reserved.
+# Copyright (c) 2009-2012 Zmanda Inc.  All Rights Reserved.
 #
 # This program is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License version 2 as published
@@ -51,6 +50,7 @@ use Amanda::MainLoop;
 use Amanda::Taper::Protocol;
 use Amanda::Taper::Scan;
 use Amanda::Taper::Worker;
+use Amanda::Interactivity;
 use Amanda::Logfile qw( :logtype_t log_add );
 use Amanda::Xfer qw( :constants );
 use Amanda::Util qw( quote_string );
@@ -59,11 +59,13 @@ use File::Temp;
 
 sub new {
     my $class = shift;
+    my %params = @_;
 
     my $self = bless {
 
        # filled in at start
        proto => undef,
+       tapelist => $params{'tapelist'},
 
        worker => {},
     }, $class;
@@ -102,7 +104,7 @@ sub start {
        } else {
            $msg = $params{'error'};
        }
-       log_add($L_ERROR, $msg);
+       log_add($L_ERROR, "$msg");
        print STDERR "$msg\n";
        $self->{'proto'}->send(Amanda::Taper::Protocol::BAD_COMMAND,
            message => $msg);
@@ -115,7 +117,7 @@ sub start {
        debug => $Amanda::Config::debug_taper?'driver/taper':'',
     );
 
-    my $changer = Amanda::Changer->new();
+    my $changer = Amanda::Changer->new(undef, tapelist => $self->{'tapelist'});
     if ($changer->isa("Amanda::Changer::Error")) {
        # send a TAPE_ERROR right away
        $self->{'proto'}->send(Amanda::Taper::Protocol::TAPE_ERROR,
@@ -134,7 +136,13 @@ sub start {
        return;
     }
 
-    $self->{'taperscan'} = Amanda::Taper::Scan->new(changer => $changer);
+    my $interactivity = Amanda::Interactivity->new(
+                                       name => getconf($CNF_INTERACTIVITY));
+    my $scan_name = getconf($CNF_TAPERSCAN);
+    $self->{'taperscan'} = Amanda::Taper::Scan->new(algorithm => $scan_name,
+                                           changer => $changer,
+                                           interactivity => $interactivity,
+                                           tapelist => $self->{'tapelist'});
 }
 
 sub quit {
@@ -176,6 +184,7 @@ sub quit {
     };
 
     step done => sub {
+       $self->{'taperscan'}->quit() if defined $self->{'taperscan'};
        if (@errors) {
            $params{'finished_cb'}->(join("; ", @errors));
        } else {
@@ -256,6 +265,14 @@ sub msg_FAILED {
     $worker->FAILED(@_);
 }
 
+sub msg_CLOSE_VOLUME {
+    my $self = shift;
+    my ($msgtype, %params) = @_;
+
+    my $worker = $self->{'worker'}->{$params{'worker_name'}};
+    $worker->CLOSE_VOLUME(@_);
+}
+
 sub msg_TAKE_SCRIBE_FROM {
     my $self = shift;
     my ($msgtype, %params) = @_;