89c089434605fde311867c110af4cf0313dfdb6e
[debian/amanda] / device-src / directtcp-connection.h
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 N Mathlida Ave, Suite 300
18  * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
19  */
20
21 #ifndef DIRECTTCP_CONNECTION_H
22 #define DIRECTTCP_CONNECTION_H
23
24 #include <glib.h>
25 #include <glib-object.h>
26
27 GType   directtcp_connection_get_type   (void);
28 #define TYPE_DIRECTTCP_CONNECTION       (directtcp_connection_get_type())
29 #define DIRECTTCP_CONNECTION(obj)       G_TYPE_CHECK_INSTANCE_CAST((obj), directtcp_connection_get_type(), DirectTCPConnection)
30 #define IS_DIRECTTCP_CONNECTION(obj) G_TYPE_CHECK_INSTANCE_TYPE((obj), directtcp_connection_get_type ())
31 #define DIRECTTCP_CONNECTION_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS((obj), directtcp_connection_get_type(), DirectTCPConnectionClass)
32
33 /*
34  * Parent class for connections
35  */
36
37 typedef struct DirectTCPConnection_ {
38     GObject __parent__;
39
40     gboolean closed;
41 } DirectTCPConnection;
42
43 typedef struct DirectTCPConnectionClass_ {
44     GObjectClass __parent__;
45
46     /* The DirectTCPConnection object allows a particular connection to "span"
47      * multiple devices -- the caller gets the connection from one device,
48      * reads or writes as desired, then creates a new device and passes the
49      * connection to that device.  If the new device cannot use the old
50      * connection, then it generates a suitable error message.
51      */
52
53     /* call this to close the connection (even if the Device that created
54      * it is long gone).  Note that this will be called automatically by
55      * finalize, but it is a programming error to allow this to happen as
56      * any error will be fatal.
57      *
58      * @param self: object
59      * @returns: error message on error, NULL for no error (caller should
60      *  free the error message)
61      */
62     char *(* close)(struct DirectTCPConnection_ *self);
63 } DirectTCPConnectionClass;
64
65 /* Method Stubs */
66
67 char *directtcp_connection_close(
68     DirectTCPConnection *self);
69
70 /*
71  * A simple connection subclass containing a local TCP socket, useful for testing
72  */
73
74 #define TYPE_DIRECTTCP_CONNECTION_SOCKET        (directtcp_connection_socket_get_type())
75 #define DIRECTTCP_CONNECTION_SOCKET(obj)        G_TYPE_CHECK_INSTANCE_CAST((obj), directtcp_connection_socket_get_type(), DirectTCPConnectionSocket)
76 #define DIRECTTCP_CONNECTION_SOCKET_CONST(obj)  G_TYPE_CHECK_INSTANCE_CAST((obj), directtcp_connection_socket_get_type(), DirectTCPConnectionSocket const)
77 #define DIRECTTCP_CONNECTION_SOCKET_CLASS(klass)        G_TYPE_CHECK_CLASS_CAST((klass), directtcp_connection_socket_get_type(), DirectTCPConnectionSocketClass)
78 #define IS_DIRECTTCP_CONNECTION_SOCKET(obj)     G_TYPE_CHECK_INSTANCE_TYPE((obj), directtcp_connection_socket_get_type ())
79 #define DIRECTTCP_CONNECTION_SOCKET_GET_CLASS(obj)      G_TYPE_INSTANCE_GET_CLASS((obj), directtcp_connection_socket_get_type(), DirectTCPConnectionSocketClass)
80 GType directtcp_connection_socket_get_type(void);
81
82 typedef struct DirectTCPConnectionSocket_ {
83     DirectTCPConnection __parent__;
84     int socket;
85 } DirectTCPConnectionSocket;
86
87 typedef struct DirectTCPConnectionSocketClass_ {
88     DirectTCPConnectionClass __parent__;
89 } DirectTCPConnectionSocketClass;
90
91 /* Method Stubs */
92
93 DirectTCPConnectionSocket *directtcp_connection_socket_new(int socket);
94
95 #endif /* DIRECTTCP_CONNECTION_H */