]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | /* |
2 | * Licensed to the Apache Software Foundation (ASF) under one | |
3 | * or more contributor license agreements. See the NOTICE file | |
4 | * distributed with this work for additional information | |
5 | * regarding copyright ownership. The ASF licenses this file | |
6 | * to you under the Apache License, Version 2.0 (the | |
7 | * "License"); you may not use this file except in compliance | |
8 | * with the License. You may obtain a copy of the License at | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, | |
13 | * software distributed under the License is distributed on an | |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
15 | * KIND, either express or implied. See the License for the | |
16 | * specific language governing permissions and limitations | |
17 | * under the License. | |
18 | */ | |
19 | ||
20 | #ifndef _THRIFT_TRANSPORT_H | |
21 | #define _THRIFT_TRANSPORT_H | |
22 | ||
23 | #include <glib-object.h> | |
24 | ||
25 | G_BEGIN_DECLS | |
26 | ||
27 | /*! \file thrift_transport.h | |
28 | * \brief Abstract class for Thrift transports. | |
29 | * | |
30 | * An abstract class is used instead of an interface because: | |
31 | * - interfaces can't seem to be used as properties. ThriftProtocol has | |
32 | * a ThriftTransport as an object property. | |
33 | * - if a method needs to be added that all subclasses can use, a class | |
34 | * is necessary. | |
35 | */ | |
36 | ||
37 | /* type macros */ | |
38 | #define THRIFT_TYPE_TRANSPORT (thrift_transport_get_type ()) | |
39 | #define THRIFT_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_TRANSPORT, ThriftTransport)) | |
40 | #define THRIFT_IS_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_TRANSPORT)) | |
41 | #define THRIFT_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_TRANSPORT, ThriftTransportClass)) | |
42 | #define THRIFT_IS_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_TRANSPORT)) | |
43 | #define THRIFT_TRANSPORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_TRANSPORT, ThriftTransportClass)) | |
44 | ||
45 | typedef struct _ThriftTransport ThriftTransport; | |
46 | ||
47 | /*! | |
48 | * Thrift Protocol object | |
49 | */ | |
50 | struct _ThriftTransport | |
51 | { | |
52 | GObject parent; | |
53 | }; | |
54 | ||
55 | typedef struct _ThriftTransportClass ThriftTransportClass; | |
56 | ||
57 | /*! | |
58 | * Thrift Transport class | |
59 | */ | |
60 | struct _ThriftTransportClass | |
61 | { | |
62 | GObjectClass parent; | |
63 | ||
64 | /* vtable */ | |
65 | gboolean (*is_open) (ThriftTransport *transport); | |
66 | gboolean (*peek) (ThriftTransport *transport, GError **error); | |
67 | gboolean (*open) (ThriftTransport *transport, GError **error); | |
68 | gboolean (*close) (ThriftTransport *transport, GError **error); | |
69 | gint32 (*read) (ThriftTransport *transport, gpointer buf, | |
70 | guint32 len, GError **error); | |
71 | gboolean (*read_end) (ThriftTransport *transport, GError **error); | |
72 | gboolean (*write) (ThriftTransport *transport, const gpointer buf, | |
73 | const guint32 len, GError **error); | |
74 | gboolean (*write_end) (ThriftTransport *transport, GError **error); | |
75 | gboolean (*flush) (ThriftTransport *transport, GError **error); | |
76 | gint32 (*read_all) (ThriftTransport *transport, gpointer buf, | |
77 | guint32 len, GError **error); | |
78 | }; | |
79 | ||
80 | /* used by THRIFT_TYPE_TRANSPORT */ | |
81 | GType thrift_transport_get_type (void); | |
82 | ||
83 | /* virtual public methods */ | |
84 | ||
85 | /*! | |
86 | * Checks if this transport is opened. | |
87 | * \public \memberof ThriftTransportInterface | |
88 | */ | |
89 | gboolean thrift_transport_is_open (ThriftTransport *transport); | |
90 | ||
91 | /*! | |
92 | * Open the transport for reading and writing. | |
93 | * \public \memberof ThriftTransportInterface | |
94 | */ | |
95 | gboolean thrift_transport_open (ThriftTransport *transport, GError **error); | |
96 | ||
97 | /*! | |
98 | * Tests whether there is more data to read or if the remote side is still | |
99 | * open. By default this is true whenever the transport is open, but | |
100 | * implementations should add logic to test for this condition where possible | |
101 | * (i.e. on a socket). | |
102 | * | |
103 | * This is used by a server to check if it should listen for another request. | |
104 | * \public \memberof ThriftTransportInterface | |
105 | */ | |
106 | gboolean thrift_transport_peek (ThriftTransport *transport, GError **error); | |
107 | ||
108 | /*! | |
109 | * Close the transport. | |
110 | * \public \memberof ThriftTransportInterface | |
111 | */ | |
112 | gboolean thrift_transport_close (ThriftTransport *transport, GError **error); | |
113 | ||
114 | /*! | |
115 | * Read some data into the buffer buf. | |
116 | * \public \memberof ThriftTransportInterface | |
117 | */ | |
118 | gint32 thrift_transport_read (ThriftTransport *transport, gpointer buf, | |
119 | guint32 len, GError **error); | |
120 | ||
121 | /*! | |
122 | * Called when read is completed. | |
123 | * \public \memberof ThriftTransportInterface | |
124 | */ | |
125 | gboolean thrift_transport_read_end (ThriftTransport *transport, GError **error); | |
126 | ||
127 | /*! | |
128 | * Writes data from a buffer to the transport. | |
129 | * \public \memberof ThriftTransportInterface | |
130 | */ | |
131 | gboolean thrift_transport_write (ThriftTransport *transport, const gpointer buf, | |
132 | const guint32 len, GError **error); | |
133 | ||
134 | /*! | |
135 | * Called when write is completed. | |
136 | * \public \memberof ThriftTransportInterface | |
137 | */ | |
138 | gboolean thrift_transport_write_end (ThriftTransport *transport, | |
139 | GError **error); | |
140 | ||
141 | /*! | |
142 | * Flushes any pending data to be written. Typically used with buffered | |
143 | * transport mechanisms. | |
144 | * \public \memberof ThriftTransportInterface | |
145 | */ | |
146 | gboolean thrift_transport_flush (ThriftTransport *transport, GError **error); | |
147 | ||
148 | /*! | |
149 | * Read len bytes of data into the buffer buf. | |
150 | * \public \memberof ThriftTransportInterface | |
151 | */ | |
152 | gint32 thrift_transport_read_all (ThriftTransport *transport, gpointer buf, | |
153 | guint32 len, GError **error); | |
154 | ||
155 | /* define error/exception types */ | |
156 | typedef enum | |
157 | { | |
158 | THRIFT_TRANSPORT_ERROR_UNKNOWN, | |
159 | THRIFT_TRANSPORT_ERROR_HOST, | |
160 | THRIFT_TRANSPORT_ERROR_SOCKET, | |
161 | THRIFT_TRANSPORT_ERROR_CONNECT, | |
162 | THRIFT_TRANSPORT_ERROR_SEND, | |
163 | THRIFT_TRANSPORT_ERROR_RECEIVE, | |
164 | THRIFT_TRANSPORT_ERROR_CLOSE | |
165 | } ThriftTransportError; | |
166 | ||
167 | /* define an error domain for GError to use */ | |
168 | GQuark thrift_transport_error_quark (void); | |
169 | #define THRIFT_TRANSPORT_ERROR (thrift_transport_error_quark ()) | |
170 | ||
171 | /* define macro for invalid socket */ | |
172 | #define THRIFT_INVALID_SOCKET (-1) | |
173 | ||
174 | G_END_DECLS | |
175 | ||
176 | #endif /* _THRIFT_TRANSPORT_H */ |