Imported Upstream version 3.2.0
[debian/amanda] / perl / Amanda / Application.swg
1 /*
2  * Copyright (c) 2008, 2009, 2010 Zmanda, Inc.  All Rights Reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 2 as published
6  * by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11  * for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16  *
17  * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
18  * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
19  */
20
21 %module "Amanda::Application"
22 %include "amglue/amglue.swg"
23 %include "exception.i"
24 %include "cstring.i"
25
26 %include "Amanda/Application.pod"
27
28 %perlcode %{
29 push @ISA, qw(Amanda::Script_App);
30 require Amanda::Script_App;
31
32 use strict;
33 use warnings;
34 use Amanda::Config qw( :init :getconf  config_dir_relative );
35
36
37 sub new {
38     my $class = shift @_;
39     my $config_name = shift @_;
40
41     my $self = Amanda::Script_App::new($class, "client", "application", $config_name);
42
43     $self->{known_commands} = {
44         support   => 1,
45         selfcheck => 1,
46         estimate  => 1,
47         backup    => 1,
48         restore   => 1,
49         validate  => 1,
50     };
51     return $self;
52 }
53
54 sub run_calcsize {
55     my $self = shift;
56     my $program = shift;
57
58     run_calcsize_C($self->{config}, $program, $self->{disk}, $self->{device}, $self->{level}, undef, undef);
59
60 }
61
62 sub default_validate {
63     my $self = shift;
64     my $buffer;
65
66     do {
67         sysread STDIN, $buffer, 1048576;
68     } while (defined $buffer and length($buffer) > 0);
69 }
70
71 sub write_magic_block {
72     my $self = shift;
73     my $type = shift;
74
75     my $dump_str = pack("a512", $type);
76     print STDOUT $dump_str;
77 }
78
79 sub read_magic_block {
80     my $self = shift;
81
82     my $magic_block = Amanda::Util::full_read(0, 512);
83     #remove '\0' bytes
84     $magic_block =~ /^([^\0]*)/;
85     my $type = $1;
86
87     return $type;
88 }
89
90 sub _set_mesgout {
91     my $self = shift;
92
93     my $mesgout_fd;
94     open ($mesgout_fd, '>&=3') || die("Can't open mesgout_fd: $!");
95     $self->{mesgout} = $mesgout_fd;
96 }
97
98 %}
99
100 /* C interfaces used by the above */
101
102 %{
103 #include "amanda.h"
104 #include "client_util.h"
105 %}
106
107 %typemap(in) GSList *levels {
108     AV     *tempav;
109     GSList *level = NULL;
110     int     num;
111     int     i;
112     SV    **tv;
113
114     if (!SvROK($input))
115         croak("Argument $argnum is not a reference.");
116     if (SvTYPE(SvRV($input)) != SVt_PVAV)
117         croak("Argument $argnum is not an array.");
118     tempav = (AV*)SvRV($input);
119     num = av_len(tempav);
120     for (i=0; i <= num; i++) {
121         tv = av_fetch(tempav, i, 0);
122         /* (gint) cast is required because sizeof(IV) may not be sizeof(gint).
123          * Both will be >= 32 bits, though, and that's sufficient for a level. */
124         level = g_slist_append(level, GINT_TO_POINTER((gint)SvIV(*tv)));
125     }
126     $1 = level;
127 }
128 /* free the list */
129 %typemap(freearg) GSList *levels {
130     if($1)
131         g_slist_free($1);
132 }
133
134 %rename(run_calcsize_C) run_calcsize;
135 void
136 run_calcsize(char *config, char *program, char *disk, char *dirname,
137              GSList *levels, char *file_exclude, char *file_include);
138
139 %typemap(in) GSList *levels;
140 %typemap(freearg) GSList *levels;