Imported Upstream version 3.3.3
[debian/amanda] / xfer-src / source-directtcp-listen.c
1 /*
2  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3  * Copyright (c) 2008-2012 Zmanda, Inc.  All Rights Reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13  * for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18  *
19  * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
20  * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
21  */
22
23 #include "amanda.h"
24 #include "sockaddr-util.h"
25 #include "amxfer.h"
26
27 /*
28  * Class declaration
29  *
30  * This declaration is entirely private; nothing but xfer_source_directtcp_listen() references
31  * it directly.
32  */
33
34 static GType xfer_source_directtcp_listen_get_type(void);
35 #define XFER_SOURCE_DIRECTTCP_LISTEN_TYPE (xfer_source_directtcp_listen_get_type())
36 #define XFER_SOURCE_DIRECTTCP_LISTEN(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), xfer_source_directtcp_listen_get_type(), XferSourceDirectTCPListen)
37 #define XFER_SOURCE_DIRECTTCP_LISTEN_CONST(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), xfer_source_directtcp_listen_get_type(), XferSourceDirectTCPListen const)
38 #define XFER_SOURCE_DIRECTTCP_LISTEN_CLASS(klass) G_TYPE_CHECK_CLASS_CAST((klass), xfer_source_directtcp_listen_get_type(), XferSourceDirectTCPListenClass)
39 #define IS_XFER_SOURCE_DIRECTTCP_LISTEN(obj) G_TYPE_CHECK_INSTANCE_TYPE((obj), xfer_source_directtcp_listen_get_type ())
40 #define XFER_SOURCE_DIRECTTCP_LISTEN_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS((obj), xfer_source_directtcp_listen_get_type(), XferSourceDirectTCPListenClass)
41
42 static GObjectClass *parent_class = NULL;
43
44 /*
45  * Main object structure
46  */
47
48 typedef struct XferSourceDirectTCPListen {
49     XferElement __parent__;
50 } XferSourceDirectTCPListen;
51
52 /*
53  * Class definition
54  */
55
56 typedef struct {
57     XferElementClass __parent__;
58 } XferSourceDirectTCPListenClass;
59
60 /*
61  * Implementation
62  */
63
64 static gboolean
65 start_impl(
66     XferElement *elt)
67 {
68     /* this is really all we do -- copy the input addresses from our downstream
69      * neighbor.  This seems trivial, but downstream may be a glue element, which
70      * means we get the listening socket for free. */
71     elt->input_listen_addrs = elt->downstream->input_listen_addrs;
72
73     return FALSE;
74 }
75
76 static void
77 instance_init(
78     XferElement *elt)
79 {
80     elt->can_generate_eof = FALSE;
81 }
82
83 static void
84 class_init(
85     XferSourceDirectTCPListenClass * selfc)
86 {
87     XferElementClass *klass = XFER_ELEMENT_CLASS(selfc);
88     static xfer_element_mech_pair_t mech_pairs[] = {
89         { XFER_MECH_NONE, XFER_MECH_DIRECTTCP_LISTEN, XFER_NROPS(1), XFER_NTHREADS(0) },
90         { XFER_MECH_NONE, XFER_MECH_NONE, XFER_NROPS(0), XFER_NTHREADS(0) },
91     };
92
93     klass->start = start_impl;
94     klass->perl_class = "Amanda::Xfer::Source::DirectTCPListen";
95     klass->mech_pairs = mech_pairs;
96
97     parent_class = g_type_class_peek_parent(selfc);
98 }
99
100 GType
101 xfer_source_directtcp_listen_get_type (void)
102 {
103     static GType type = 0;
104
105     if G_UNLIKELY(type == 0) {
106         static const GTypeInfo info = {
107             sizeof (XferSourceDirectTCPListenClass),
108             (GBaseInitFunc) NULL,
109             (GBaseFinalizeFunc) NULL,
110             (GClassInitFunc) class_init,
111             (GClassFinalizeFunc) NULL,
112             NULL /* class_data */,
113             sizeof (XferSourceDirectTCPListen),
114             0 /* n_preallocs */,
115             (GInstanceInitFunc) instance_init,
116             NULL
117         };
118
119         type = g_type_register_static (XFER_ELEMENT_TYPE, "XferSourceDirectTCPListen", &info, 0);
120     }
121
122     return type;
123 }
124
125 /* create an element of this class; prototype is in xfer-element.h */
126 XferElement *
127 xfer_source_directtcp_listen(void)
128 {
129     XferSourceDirectTCPListen *xsr = (XferSourceDirectTCPListen *)g_object_new(XFER_SOURCE_DIRECTTCP_LISTEN_TYPE, NULL);
130     XferElement *elt = XFER_ELEMENT(xsr);
131
132     return elt;
133 }