1 /*
2  * GNetwork Library: libgnetwork/gnetwork-connection.h
3  *
4  * Copyright (c) 2003 James M. Cape.
5  * All Rights Reserved.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; version 2.1 of the
10  * License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20  * USA
21  */
22 
23 #ifndef __GNETWORK_CONNECTION_H__
24 #define __GNETWORK_CONNECTION_H__
25 
26 #include "gnetwork-macros.h"
27 
28 G_BEGIN_DECLS
29 
30 
31 #define GNETWORK_TYPE_CONNECTION		(gnetwork_connection_get_type ())
32 #define GNETWORK_CONNECTION(obj)		(G_TYPE_CHECK_INSTANCE_CAST ((obj), GNETWORK_TYPE_CONNECTION, GNetworkConnection))
33 #define GNETWORK_IS_CONNECTION(obj)		(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNETWORK_TYPE_CONNECTION))
34 #define GNETWORK_CONNECTION_GET_IFACE(obj)	(G_TYPE_INSTANCE_GET_INTERFACE ((obj), GNETWORK_TYPE_CONNECTION, GNetworkConnectionIface))
35 #define GNETWORK_CONNECTION_CALL_PARENT(obj,method,args) \
36   (GNETWORK_INTERFACE_CALL_PARENT (GNETWORK_CONNECTION_GET_IFACE, GNetworkConnectionIface, obj, method, args))
37 
38 #define GNETWORK_CONNECTION_ERROR		(gnetwork_connection_error_get_quark ())
39 
40 
41 typedef enum /* <prefix=GNETWORK_CONNECTION> */
42 {
43   GNETWORK_CONNECTION_INVALID,
44 
45   GNETWORK_CONNECTION_CLIENT,
46   GNETWORK_CONNECTION_SERVER
47 }
48 GNetworkConnectionType;
49 
50 
51 typedef enum /* <prefix=GNETWORK_CONNECTION> */
52 {
53   GNETWORK_CONNECTION_CLOSING,
54   GNETWORK_CONNECTION_CLOSED,
55   GNETWORK_CONNECTION_OPENING,
56   GNETWORK_CONNECTION_OPEN
57 }
58 GNetworkConnectionStatus;
59 
60 
61 typedef enum /* <prefix=GNETWORK_CONNECTION_ERROR> */
62 {
63   GNETWORK_CONNECTION_ERROR_INTERNAL,
64 
65   GNETWORK_CONNECTION_ERROR_REFUSED,
66   GNETWORK_CONNECTION_ERROR_TIMEOUT,
67   GNETWORK_CONNECTION_ERROR_UNREACHABLE,
68   GNETWORK_CONNECTION_ERROR_PERMISSIONS
69 }
70 GNetworkConnectionError;
71 
72 
73 typedef struct _GNetworkConnection GNetworkConnection;
74 typedef struct _GNetworkConnectionIface GNetworkConnectionIface;
75 
76 
77 typedef void (*GNetworkConnectionFunc) (GNetworkConnection * connection);
78 typedef void (*GNetworkConnectionSendFunc) (GNetworkConnection * connection,
79 					    gconstpointer data,
80 					    gsize length);
81 
82 
83 struct _GNetworkConnectionIface
84 {
85   /* < private > */
86   GTypeInterface g_iface;
87 
88   /* < public > */
89   /* Signals */
90   void (*received)           (GNetworkConnection * connection,
91 			      gconstpointer data,
92 			      gulong length);
93   void (*sent)		     (GNetworkConnection * connection,
94 			      gconstpointer data,
95 			      gulong length);
96   void (*error)		     (GNetworkConnection * connection,
97 			      GError * error);
98 
99   /* Methods */
100   GNetworkConnectionFunc      open;
101   GNetworkConnectionFunc      close;
102   GNetworkConnectionSendFunc  send;
103 
104   /* < private > */
105   void (*__gnetwork_reserved_1);
106   void (*__gnetwork_reserved_2);
107   void (*__gnetwork_reserved_3);
108   void (*__gnetwork_reserved_4);
109 };
110 
111 
112 GType gnetwork_connection_get_type (void) G_GNUC_CONST;
113 
114 /* Methods */
115 void gnetwork_connection_open (GNetworkConnection * connection);
116 void gnetwork_connection_close (GNetworkConnection * connection);
117 void gnetwork_connection_send (GNetworkConnection * connection, gconstpointer data, glong length);
118 
119 /* Signals */
120 void gnetwork_connection_received (GNetworkConnection * connection, gconstpointer data,
121 				   gulong length);
122 void gnetwork_connection_sent (GNetworkConnection * connection, gconstpointer data, gulong length);
123 void gnetwork_connection_error (GNetworkConnection * connection, const GError * error);
124 
125 /* Error Reporting */
126 GQuark gnetwork_connection_error_get_quark (void) G_GNUC_CONST;
127 G_CONST_RETURN gchar *gnetwork_connection_strerror (GNetworkConnectionError error);
128 
129 
130 G_END_DECLS
131 
132 #endif /* __GNETWORK_CONNECTION_H__ */
133