1 # Copyright (c) 2010 Zmanda, Inc. All Rights Reserved.
3 # This program is free software; you can redistribute it and/or modify it
4 # under the terms of the GNU General Public License version 2 as published
5 # by the Free Software Foundation.
7 # This program is distributed in the hope that it will be useful, but
8 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 # You should have received a copy of the GNU General Public License along
13 # with this program; if not, write to the Free Software Foundation, Inc.,
14 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
17 # Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
19 package Amanda::Interactive;
23 Amanda::Interactive -- Parent class for user interactivity modules
27 use Amanda::Interactive;
29 my $inter = Amanda::Interactive->new(name => 'stdin',
30 inter_conf => $inter_conf);
32 message => "Insert Volume labelled 'MY_LABEL-001'",
34 my ($err, $reply) = @_;
36 # error from the script
37 } elsif (!defined $reply) {
46 This package provides a way for Amanda programs to communicate interactively
47 with the user. The program can send a message to the user and await a textual
48 response. The package operates asynchronously (see L<Amanda::MainLoop>), so
49 the program may continue with other activities while waiting for an answer from
52 Several interactivity modules are (or soon will be) available, and can be
57 A new object is create with the C<new> function as follows:
59 my $inter = Amanda::Interactive->new(
60 name => $interactive_name,
61 inter_conf => $inter_conf);
63 Where C<$interactive_name> is the name of the desired interactivity module
66 =head2 INTERACTIVE OBJECTS
70 $inter->user_request(message => $message,
73 finished_cb => $finished_cb);
75 This method return immediately. It sends C<message> to the user and waits for a
76 reply. The C<label> and C<err> parameters .. well, what do they do? (TODO)
78 The C<user_request> method's C<finished_cb> as parameter is similar to the
79 callback of the same name in L<Amanda::Changer>. In the even of an error, it
80 is called with an C<Amanda::Changer::Error> object as first argument. If the
81 request is answered, then the second argument is the user's response. If the
82 request is aborted (see C<abort>, below), then both arguments are C<undef>.
88 This method will abort all pending C<user_request> invocations, invoking their
89 C<finished_cb> with C<(undef, undef)>.
94 shift eq 'Amanda::Interactive'
97 my $name = $params{'name'};
99 die("No name for Amanda::Interactive->(new)") if !defined $name;
101 my $pkgname = "Amanda::Interactive::$name";
102 my $filename = $pkgname;
103 $filename =~ s|::|/|g;
106 if (!exists $INC{$filename}) {
107 eval "use $pkgname;";
114 my $inter = $pkgname->new(%params);