Imported Upstream version 3.3.2
[debian/amanda] / perl / Amanda / Application.pm
1 # This file was automatically generated by SWIG (http://www.swig.org).
2 # Version 2.0.4
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 IO::Handle;
118 use Amanda::Config qw( :init :getconf  config_dir_relative );
119
120
121 sub new {
122     my $class = shift @_;
123     my $config_name = shift @_;
124
125     my $self = Amanda::Script_App::new($class, "client", "application", $config_name);
126
127     $self->{known_commands} = {
128         support   => 1,
129         selfcheck => 1,
130         estimate  => 1,
131         backup    => 1,
132         restore   => 1,
133         validate  => 1,
134     };
135     return $self;
136 }
137
138 sub run_calcsize {
139     my $self = shift;
140     my $program = shift;
141
142     run_calcsize_C($self->{config}, $program, $self->{disk}, $self->{device}, $self->{level}, undef, undef);
143
144 }
145
146 sub default_validate {
147     my $self = shift;
148     my $buffer;
149
150     do {
151         sysread STDIN, $buffer, 1048576;
152     } while (defined $buffer and length($buffer) > 0);
153 }
154
155 sub write_magic_block {
156     my $self = shift;
157     my $type = shift;
158
159     my $dump_str = pack("a512", $type);
160     print STDOUT $dump_str;
161 }
162
163 sub read_magic_block {
164     my $self = shift;
165
166     my $magic_block = Amanda::Util::full_read(0, 512);
167     #remove '\0' bytes
168     $magic_block =~ /^([^\0]*)/;
169     my $type = $1;
170
171     return $type;
172 }
173
174 sub _set_mesgout {
175     my $self = shift;
176
177     my $mesgout = IO::Handle->new();
178     $mesgout->fdopen(3,"a") || die("Can't open mesgout_fd: $!");
179     $mesgout->autoflush(1);
180     $self->{mesgout} = $mesgout;
181 }
182
183 1;