Imported Upstream version 3.2.0
[debian/amanda] / perl / Amanda / Application.pm
1 # This file was automatically generated by SWIG (http://www.swig.org).
2 # Version 1.3.39
3 #
4 # Do not make changes to this file unless you know what you are doing--modify
5 # the SWIG interface file instead.
6
7 package Amanda::Application;
8 use base qw(Exporter);
9 use base qw(DynaLoader);
10 package Amanda::Applicationc;
11 bootstrap Amanda::Application;
12 package Amanda::Application;
13 @EXPORT = qw();
14
15 # ---------- BASE METHODS -------------
16
17 package Amanda::Application;
18
19 sub TIEHASH {
20     my ($classname,$obj) = @_;
21     return bless $obj, $classname;
22 }
23
24 sub CLEAR { }
25
26 sub FIRSTKEY { }
27
28 sub NEXTKEY { }
29
30 sub FETCH {
31     my ($self,$field) = @_;
32     my $member_func = "swig_${field}_get";
33     $self->$member_func();
34 }
35
36 sub STORE {
37     my ($self,$field,$newval) = @_;
38     my $member_func = "swig_${field}_set";
39     $self->$member_func($newval);
40 }
41
42 sub this {
43     my $ptr = shift;
44     return tied(%$ptr);
45 }
46
47
48 # ------- FUNCTION WRAPPERS --------
49
50 package Amanda::Application;
51
52 *run_calcsize_C = *Amanda::Applicationc::run_calcsize_C;
53
54 # ------- VARIABLE STUBS --------
55
56 package Amanda::Application;
57
58
59 @EXPORT_OK = ();
60 %EXPORT_TAGS = ();
61
62
63 =head1 NAME
64
65 Amanda::Application - perl utility functions for Applications.
66
67 =head1 SYNOPSIS
68
69   package Amanda::Application::my_application;
70   use base qw(Amanda::Application);
71
72   sub new {
73     my ($class, $config, $foo) = @_;
74     my $self = $class->SUPER::new($config);
75
76     $self->{'foo'} = $foo;
77     $self->{'bar'} = $bar;
78
79     return $self;
80   }
81
82   # Define all command_* subs that you need, e.g.,
83   sub command_support {
84     my $self = shift;
85     # ...
86   }
87
88   package main;
89
90   # .. parse arguments ..
91
92   my $application = Amanda::Application::my_application->new($opt_foo, $opt_bar);
93   $application->do($cmd);
94
95 =head1 INTERFACE
96
97 =head2 write_magic_block
98
99   $self->write_magic_block($type)
100
101 Write a 512 bytes magic block to STDOUT.
102
103 =head2 read_magic_bloc
104
105   $type = $self->read_magic_block()
106
107 Read the 512 bytes magic block from STDIN and return the type.
108
109 =cut
110
111
112 push @ISA, qw(Amanda::Script_App);
113 require Amanda::Script_App;
114
115 use strict;
116 use warnings;
117 use Amanda::Config qw( :init :getconf  config_dir_relative );
118
119
120 sub new {
121     my $class = shift @_;
122     my $config_name = shift @_;
123
124     my $self = Amanda::Script_App::new($class, "client", "application", $config_name);
125
126     $self->{known_commands} = {
127         support   => 1,
128         selfcheck => 1,
129         estimate  => 1,
130         backup    => 1,
131         restore   => 1,
132         validate  => 1,
133     };
134     return $self;
135 }
136
137 sub run_calcsize {
138     my $self = shift;
139     my $program = shift;
140
141     run_calcsize_C($self->{config}, $program, $self->{disk}, $self->{device}, $self->{level}, undef, undef);
142
143 }
144
145 sub default_validate {
146     my $self = shift;
147     my $buffer;
148
149     do {
150         sysread STDIN, $buffer, 1048576;
151     } while (defined $buffer and length($buffer) > 0);
152 }
153
154 sub write_magic_block {
155     my $self = shift;
156     my $type = shift;
157
158     my $dump_str = pack("a512", $type);
159     print STDOUT $dump_str;
160 }
161
162 sub read_magic_block {
163     my $self = shift;
164
165     my $magic_block = Amanda::Util::full_read(0, 512);
166     #remove '\0' bytes
167     $magic_block =~ /^([^\0]*)/;
168     my $type = $1;
169
170     return $type;
171 }
172
173 sub _set_mesgout {
174     my $self = shift;
175
176     my $mesgout_fd;
177     open ($mesgout_fd, '>&=3') || die("Can't open mesgout_fd: $!");
178     $self->{mesgout} = $mesgout_fd;
179 }
180
181 1;