Imported Upstream version 3.3.3
[debian/amanda] / perl / amglue / xferwrap.c
1 /*
2  * Copyright (c) 2009-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 /* Utility functions for packages that create Amanda::Xfer objects */
23
24 #include "amglue.h"
25 #include "amxfer.h"
26
27 SV *
28 new_sv_for_xfer(
29     Xfer *xfer)
30 {
31     if (!xfer) return &PL_sv_undef;
32
33     xfer_ref(xfer);
34     return new_sv_for_c_obj(xfer, "Amanda::Xfer::Xfer");
35 }
36
37 SV *
38 new_sv_for_xfer_element(
39     XferElement *xe)
40 {
41     const char *perl_class;
42
43     if (!xe) return &PL_sv_undef;
44
45     perl_class = XFER_ELEMENT_GET_CLASS(xe)->perl_class;
46     if (!perl_class) die("Attempt to wrap an XferElementClass with no perl class!");
47     g_object_ref(xe);
48     return new_sv_for_c_obj(xe, perl_class);
49 }
50
51 Xfer *
52 xfer_from_sv(
53     SV *sv)
54 {
55     return (Xfer *)c_obj_from_sv(sv, "Amanda::Xfer::Xfer");
56 }
57
58 XferElement *
59 xfer_element_from_sv(
60     SV *sv)
61 {
62     return (XferElement *)c_obj_from_sv(sv, "Amanda::Xfer::Element");
63 }