Imported Upstream version 3.3.2
[debian/amanda] / perl / Amanda / Application.swg
1 /*
2  * Copyright (c) 2008-2012 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 IO::Handle;
35 use Amanda::Config qw( :init :getconf  config_dir_relative );
36
37
38 sub new {
39     my $class = shift @_;
40     my $config_name = shift @_;
41
42     my $self = Amanda::Script_App::new($class, "client", "application", $config_name);
43
44     $self->{known_commands} = {
45         support   => 1,
46         selfcheck => 1,
47         estimate  => 1,
48         backup    => 1,
49         restore   => 1,
50         validate  => 1,
51     };
52     return $self;
53 }
54
55 sub run_calcsize {
56     my $self = shift;
57     my $program = shift;
58
59     run_calcsize_C($self->{config}, $program, $self->{disk}, $self->{device}, $self->{level}, undef, undef);
60
61 }
62
63 sub default_validate {
64     my $self = shift;
65     my $buffer;
66
67     do {
68         sysread STDIN, $buffer, 1048576;
69     } while (defined $buffer and length($buffer) > 0);
70 }
71
72 sub write_magic_block {
73     my $self = shift;
74     my $type = shift;
75
76     my $dump_str = pack("a512", $type);
77     print STDOUT $dump_str;
78 }
79
80 sub read_magic_block {
81     my $self = shift;
82
83     my $magic_block = Amanda::Util::full_read(0, 512);
84     #remove '\0' bytes
85     $magic_block =~ /^([^\0]*)/;
86     my $type = $1;
87
88     return $type;
89 }
90
91 sub _set_mesgout {
92     my $self = shift;
93
94     my $mesgout = IO::Handle->new();
95     $mesgout->fdopen(3,"a") || die("Can't open mesgout_fd: $!");
96     $mesgout->autoflush(1);
97     $self->{mesgout} = $mesgout;
98 }
99
100 %}
101
102 /* C interfaces used by the above */
103
104 %{
105 #include "amanda.h"
106 #include "client_util.h"
107 %}
108
109 %typemap(in) GSList *levels {
110     AV     *tempav;
111     GSList *level = NULL;
112     int     num;
113     int     i;
114     SV    **tv;
115
116     if (!SvROK($input))
117         croak("Argument $argnum is not a reference.");
118     if (SvTYPE(SvRV($input)) != SVt_PVAV)
119         croak("Argument $argnum is not an array.");
120     tempav = (AV*)SvRV($input);
121     num = av_len(tempav);
122     for (i=0; i <= num; i++) {
123         tv = av_fetch(tempav, i, 0);
124         /* (gint) cast is required because sizeof(IV) may not be sizeof(gint).
125          * Both will be >= 32 bits, though, and that's sufficient for a level. */
126         level = g_slist_append(level, GINT_TO_POINTER((gint)SvIV(*tv)));
127     }
128     $1 = level;
129 }
130 /* free the list */
131 %typemap(freearg) GSList *levels {
132     if($1)
133         g_slist_free($1);
134 }
135
136 %rename(run_calcsize_C) run_calcsize;
137 void
138 run_calcsize(char *config, char *program, char *disk, char *dirname,
139              GSList *levels, char *file_exclude, char *file_include);
140
141 %typemap(in) GSList *levels;
142 %typemap(freearg) GSList *levels;