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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
20 #include <thrift/c_glib/thrift.h>
21 #include <thrift/c_glib/transport/thrift_transport.h>
23 /* define the GError domain string */
24 #define THRIFT_TRANSPORT_ERROR_DOMAIN "thrift-transport-error-quark"
26 G_DEFINE_ABSTRACT_TYPE(ThriftTransport
, thrift_transport
, G_TYPE_OBJECT
)
29 thrift_transport_is_open (ThriftTransport
*transport
)
31 return THRIFT_TRANSPORT_GET_CLASS (transport
)->is_open (transport
);
35 thrift_transport_peek (ThriftTransport
*transport
, GError
**error
)
37 return THRIFT_TRANSPORT_GET_CLASS (transport
)->peek (transport
, error
);
41 thrift_transport_open (ThriftTransport
*transport
, GError
**error
)
43 return THRIFT_TRANSPORT_GET_CLASS (transport
)->open (transport
, error
);
47 thrift_transport_close (ThriftTransport
*transport
, GError
**error
)
49 return THRIFT_TRANSPORT_GET_CLASS (transport
)->close (transport
, error
);
53 thrift_transport_read (ThriftTransport
*transport
, gpointer buf
,
54 guint32 len
, GError
**error
)
56 return THRIFT_TRANSPORT_GET_CLASS (transport
)->read (transport
, buf
,
61 thrift_transport_read_end (ThriftTransport
*transport
, GError
**error
)
63 return THRIFT_TRANSPORT_GET_CLASS (transport
)->read_end (transport
,
68 thrift_transport_write (ThriftTransport
*transport
, const gpointer buf
,
69 const guint32 len
, GError
**error
)
71 return THRIFT_TRANSPORT_GET_CLASS (transport
)->write (transport
, buf
,
76 thrift_transport_write_end (ThriftTransport
*transport
, GError
**error
)
78 return THRIFT_TRANSPORT_GET_CLASS (transport
)->write_end (transport
,
83 thrift_transport_flush (ThriftTransport
*transport
, GError
**error
)
85 return THRIFT_TRANSPORT_GET_CLASS (transport
)->flush (transport
, error
);
89 thrift_transport_read_all (ThriftTransport
*transport
, gpointer buf
,
90 guint32 len
, GError
**error
)
92 return THRIFT_TRANSPORT_GET_CLASS (transport
)->read_all (transport
, buf
,
96 /* by default, peek returns true if and only if the transport is open */
98 thrift_transport_real_peek (ThriftTransport
*transport
, GError
**error
)
100 THRIFT_UNUSED_VAR (error
);
102 return THRIFT_TRANSPORT_GET_CLASS (transport
)->is_open (transport
);
106 thrift_transport_real_read_all (ThriftTransport
*transport
, gpointer buf
,
107 guint32 len
, GError
**error
)
109 ThriftTransportClass
*ttc
;
114 THRIFT_UNUSED_VAR (error
);
116 ttc
= THRIFT_TRANSPORT_GET_CLASS (transport
);
119 bytes
= (gint8
*) buf
;
122 if ((ret
= ttc
->read (transport
, (gpointer
) (bytes
+ have
), len
- have
,
132 /* define the GError domain for Thrift transports */
134 thrift_transport_error_quark (void)
136 return g_quark_from_static_string (THRIFT_TRANSPORT_ERROR_DOMAIN
);
139 /* class initializer for ThriftTransport */
141 thrift_transport_class_init (ThriftTransportClass
*cls
)
143 /* set these as virtual methods to be implemented by a subclass */
144 cls
->is_open
= thrift_transport_is_open
;
145 cls
->open
= thrift_transport_open
;
146 cls
->close
= thrift_transport_close
;
147 cls
->read
= thrift_transport_read
;
148 cls
->read_end
= thrift_transport_read_end
;
149 cls
->write
= thrift_transport_write
;
150 cls
->write_end
= thrift_transport_write_end
;
151 cls
->flush
= thrift_transport_flush
;
153 /* provide a default implementation for the peek and read_all methods */
154 cls
->peek
= thrift_transport_real_peek
;
155 cls
->read_all
= thrift_transport_real_read_all
;
159 thrift_transport_init (ThriftTransport
*transport
)
161 THRIFT_UNUSED_VAR (transport
);