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