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