1# This file was automatically generated by SWIG (http://www.swig.org).
2# Version 3.0.7
3#
4# Do not make changes to this file unless you know what you are doing--modify
5# the SWIG interface file instead.
6
7package Amanda::Application;
8use base qw(Exporter);
9use base qw(DynaLoader);
10package Amanda::Applicationc;
11bootstrap Amanda::Application;
12package Amanda::Application;
13@EXPORT = qw();
14
15# ---------- BASE METHODS -------------
16
17package Amanda::Application;
18
19sub TIEHASH {
20    my ($classname,$obj) = @_;
21    return bless $obj, $classname;
22}
23
24sub CLEAR { }
25
26sub FIRSTKEY { }
27
28sub NEXTKEY { }
29
30sub FETCH {
31    my ($self,$field) = @_;
32    my $member_func = "swig_${field}_get";
33    $self->$member_func();
34}
35
36sub STORE {
37    my ($self,$field,$newval) = @_;
38    my $member_func = "swig_${field}_set";
39    $self->$member_func($newval);
40}
41
42sub this {
43    my $ptr = shift;
44    return tied(%$ptr);
45}
46
47
48# ------- FUNCTION WRAPPERS --------
49
50package Amanda::Application;
51
52*run_calcsize_C = *Amanda::Applicationc::run_calcsize_C;
53
54# ------- VARIABLE STUBS --------
55
56package Amanda::Application;
57
58
59@EXPORT_OK = ();
60%EXPORT_TAGS = ();
61
62
63=head1 NAME
64
65Amanda::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
101Write a 512 bytes magic block to STDOUT.
102
103=head2 read_magic_bloc
104
105  $type = $self->read_magic_block()
106
107Read the 512 bytes magic block from STDIN and return the type.
108
109=cut
110
111
112push @ISA, qw(Amanda::Script_App);
113require Amanda::Script_App;
114
115use strict;
116use warnings;
117use IO::Handle;
118use Amanda::Config qw( :init :getconf  config_dir_relative );
119
120
121sub 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        discover  => 1,
130        selfcheck => 1,
131        estimate  => 1,
132        backup    => 1,
133        restore   => 1,
134        validate  => 1,
135    };
136    return $self;
137}
138
139sub run_calcsize {
140    my $self = shift;
141    my $program = shift;
142
143    run_calcsize_C($self->{config}, $program, $self->{disk}, $self->{device}, $self->{level}, undef, undef);
144
145}
146
147sub default_validate {
148    my $self = shift;
149    my $buffer;
150
151    do {
152	sysread STDIN, $buffer, 1048576;
153    } while (defined $buffer and length($buffer) > 0);
154}
155
156sub write_magic_block {
157    my $self = shift;
158    my $type = shift;
159
160    my $dump_str = pack("a512", $type);
161    print STDOUT $dump_str;
162}
163
164sub read_magic_block {
165    my $self = shift;
166
167    my $magic_block = Amanda::Util::full_read(0, 512);
168    #remove '\0' bytes
169    $magic_block =~ /^([^\0]*)/;
170    my $type = $1;
171
172    return $type;
173}
174
175sub _set_mesgout {
176    my $self = shift;
177
178    my $mesgout = IO::Handle->new();
179    $mesgout->fdopen(3,"a") || die("Can't open mesgout_fd: $!");
180    $mesgout->autoflush(1);
181    $self->{mesgout} = $mesgout;
182}
183
1841;
185