Imported Upstream version 3.3.3
[debian/amanda] / perl / Amanda / Xfer.swg
index 6b980b1635d731d14c61858401cd51d7790ee7d9..cee0b154534a22be3e99bb5137d426b52ece8d8e 100644 (file)
@@ -1,9 +1,10 @@
 /*
- * Copyright (c) 2008, 2009, 2010 Zmanda, Inc.  All Rights Reserved.
+ * Copyright (c) 2008-2012 Zmanda, Inc.  All Rights Reserved.
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 as published
- * by the Free Software Foundation.
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
@@ -29,6 +30,8 @@
 %{
 #include "glib-util.h"
 #include "amxfer.h"
+#include "amanda.h"
+#include "sockaddr-util.h"
 %}
 
 /* The SWIGging of the transfer architecture.
@@ -228,7 +231,7 @@ Xfer *xfer_new(XferElement **elementlist, unsigned int nelements);
 void xfer_unref(Xfer *);
 xfer_status xfer_get_status(Xfer *xfer);
 char *xfer_repr(Xfer *xfer);
-void xfer_start(Xfer *xfer);
+void xfer_start(Xfer *xfer, gint64 offset, gint64 size);
 void xfer_cancel(Xfer *xfer);
 /* xfer_get_source is implemented below */
 
@@ -241,7 +244,7 @@ void xfer_cancel(Xfer *xfer);
  * passed to the GSource's set_callback */
 %perlcode %{
 sub xfer_start_with_callback {
-    my ($xfer, $cb) = @_;
+    my ($xfer, $cb, $offset, $size) = @_;
     if (defined $cb) {
        my $releasing_cb = sub {
            my ($src, $msg, $xfer) = @_;
@@ -252,7 +255,28 @@ sub xfer_start_with_callback {
        };
        $xfer->get_source()->set_callback($releasing_cb);
     }
-    xfer_start($xfer);
+    $offset = 0 if !defined $offset;
+    $size = 0 if !defined $size;
+    xfer_start($xfer, $offset, $size);
+}
+%}
+
+/* Change the callback */
+%perlcode %{
+sub xfer_set_callback {
+    my ($xfer, $cb) = @_;
+    if (defined $cb) {
+       my $releasing_cb = sub {
+           my ($src, $msg, $xfer) = @_;
+           my $done = $msg->{'type'} == $XMSG_DONE;
+           $src->remove() if $done;
+           $cb->(@_);
+           $cb = undef if $done; # break potential reference loop
+       };
+       $xfer->get_source()->set_callback($releasing_cb);
+    } else {
+       $xfer->get_source()->set_callback(undef);
+    }
 }
 %}
 
@@ -266,6 +290,7 @@ sub xfer_start_with_callback {
 void xfer_element_unref(XferElement *elt); /* (wrap the macro, above) */
 /* xfer_element_link_to -- private */
 char *xfer_element_repr(XferElement *elt);
+/* xfer_element_set_size -- private */
 /* xfer_element_start -- private */
 /* xfer_element_cancel -- private */
 
@@ -359,6 +384,8 @@ XferElement *xfer_filter_xor(
 XferElement *xfer_filter_process(
     gchar **argv,
     gboolean need_root);
+int get_err_fd(
+    XferElement *elt);
 
 %newobject xfer_dest_null;
 XferElement *xfer_dest_null(
@@ -534,6 +561,7 @@ DECLARE_METHOD(repr, Amanda::Xfer::xfer_repr);
 DECLARE_METHOD(get_status, Amanda::Xfer::xfer_get_status);
 DECLARE_METHOD(get_source, Amanda::Xfer::xfer_get_amglue_source);
 DECLARE_METHOD(start, Amanda::Xfer::xfer_start_with_callback);
+DECLARE_METHOD(set_callback, Amanda::Xfer::xfer_set_callback);
 DECLARE_METHOD(cancel, Amanda::Xfer::xfer_cancel);
 
 /* ---- */
@@ -592,6 +620,7 @@ DECLARE_CONSTRUCTOR(Amanda::Xfer::xfer_filter_xor)
 PACKAGE(Amanda::Xfer::Filter::Process)
 XFER_ELEMENT_SUBCLASS()
 DECLARE_CONSTRUCTOR(Amanda::Xfer::xfer_filter_process)
+DECLARE_METHOD(get_stderr_fd, Amanda::Xfer::get_err_fd)
 
 /* ---- */
 
@@ -665,6 +694,9 @@ PACKAGE(Amanda::Xfer)
 # try to load Amanda::XferServer, which is server-only.  If it's not found, then
 # its classes just remain undefined.
 BEGIN {
-    eval "use Amanda::XferServer;";
+    use Amanda::Util;
+    if (Amanda::Util::built_with_component("server")) {
+       eval "use Amanda::XferServer;";
+    }
 }
 %}