471cc33ba7c3b2b994f8d4cacbb213fffa647d7b
[debian/amanda] / perl / Amanda / Application.swg
1 /*
2  * Copyright (c) Zmanda, Inc.  All Rights Reserved.
3  *
4  * This library is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 2.1
6  * as published by the Free Software Foundation.
7  *
8  * This library 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 Lesser General Public
11  * License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this library; if not, write to the Free Software Foundation,
15  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA.
16  *
17  * Contact information: Zmanda Inc., 465 S Mathlida Ave, Suite 300
18  * Sunnyvale, CA 94086, 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 %perlcode %{
27 push @ISA, qw(Amanda::Script_App);
28 require Amanda::Script_App;
29
30 use strict;
31 use warnings;
32
33 =head1 NAME
34
35 Amanda::Application - perl utility functions for Applications.
36
37 =head1 SYNOPSIS
38
39   package Amanda::Application::my_application;
40   use base qw(Amanda::Application);
41
42   sub new {
43     my $class = shift;
44     my ($foo, $bar) = @_;
45     my $self = $class->SUPER::new();
46
47     $self->{'foo'} = $foo;
48     $self->{'bar'} = $bar;
49
50     return $self;
51   }
52
53   # Define all command_* subs that you need, e.g.,
54   sub command_support {
55     my $self = shift;
56     # ...
57   }
58
59   package main;
60
61   # .. parse arguments ..
62
63   my $application = Amanda::Application::my_application->new($opt_foo, $opt_bar);
64   $application->do($cmd);
65
66 =cut
67
68 sub new {
69     my $class = shift;
70
71     my $self = Amanda::Script_App::new($class, "client", "application", @_);
72
73     $self->{known_commands} = {
74         support   => 1,
75         selfcheck => 1,
76         estimate  => 1,
77         backup    => 1,
78         restore   => 1,
79         validate  => 1,
80     };
81     return $self;
82 }
83
84 sub run_calcsize {
85     my $self = shift;
86     my $program = shift;
87
88     run_calcsize_C($self->{config}, $program, $self->{disk}, $self->{device}, $self->{level}, undef, undef);
89
90 }
91 %}
92
93 /* C interfaces used by the above */
94
95 %{
96 #include "amanda.h"
97 #include "client_util.h"
98 %}
99
100 %typemap(in) GSList *levels {
101     AV     *tempav;
102     GSList *level = NULL;
103     int     num;
104     int     i;
105     SV    **tv;
106
107     if (!SvROK($input))
108         croak("Argument $argnum is not a reference.");
109     if (SvTYPE(SvRV($input)) != SVt_PVAV)
110         croak("Argument $argnum is not an array.");
111     tempav = (AV*)SvRV($input);
112     num = av_len(tempav);
113     for (i=0; i <= num; i++) {
114         tv = av_fetch(tempav, i, 0);
115         level = g_slist_append(level, GINT_TO_POINTER(SvIV(*tv)));
116     }
117     $1 = level;
118 }
119 /* free the list */
120 %typemap(freearg) GSList *levels {
121     if($1)
122         g_slist_free($1);
123 }
124
125 %rename(run_calcsize_C) run_calcsize;
126 void
127 run_calcsize(char *config, char *program, char *disk, char *dirname,
128              GSList *levels, char *file_exclude, char *file_include);
129
130 %typemap(in) GSList *levels;
131 %typemap(freearg) GSList *levels;