1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
#include "decode_converter.h"
#include <gio/gio.h>
static void decode_converter_interface_init(GConverterIface *iface);
static void decode_converter_finalize(GObject *object);
static GConverterResult decoder_converter_convert(GConverter *converter,
const void *inbuf, gsize inbuf_size, void *outbuf, gsize outbuf_size,
GConverterFlags flags, gsize *bytes_read, gsize *bytes_written,
GError **error);
static void decode_converter_reset(GConverter *converter);
static GObjectClass *parent_class = NULL;
G_DEFINE_TYPE_WITH_CODE(DecodeConverter, decode_converter, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE(G_TYPE_CONVERTER,
decode_converter_interface_init));
static void decode_converter_class_init(DecodeConverterClass *klass) {
GObjectClass *object_class;
parent_class = (GObjectClass*)g_type_class_peek_parent(klass);
object_class = (GObjectClass*)klass;
object_class->finalize = decode_converter_finalize;
}
static void decode_converter_interface_init(GConverterIface *iface) {
iface->convert = decoder_converter_convert;
iface->reset = decode_converter_reset;
}
static void decode_converter_init(DecodeConverter *self) {
}
static void decode_converter_finalize(GObject *object) {
DecodeConverter *dc;
g_assert(CONVERTER_IS_DECODE(object));
dc = DECODE_CONVERTER(object);
dc->decoder.decoder->close(dc->decoder.data);
}
static GConverterResult decoder_converter_convert(GConverter *converter,
const void *inbuf, gsize inbuf_size, void *outbuf, gsize outbuf_size,
GConverterFlags flags, gsize *bytes_read, gsize *bytes_written,
GError **error) {
DecodeConverter *dc;
dc = (DecodeConverter*)converter;
gssize size = dc->decoder.decoder->decode(dc->decoder.data, inbuf, inbuf_size, outbuf, outbuf_size);
if(size < 0) {
*error = g_error_new(g_quark_from_string("DecodeConverter"),
size, "decode() returned %ld", size);
return G_CONVERTER_ERROR;
} else if(size == 0) {
return G_CONVERTER_FINISHED;
}
*bytes_read = inbuf_size;
*bytes_written = size;
return G_CONVERTER_CONVERTED;
}
static void decode_converter_reset(GConverter *converter) {
DecodeConverter *dc;
dc = (DecodeConverter*)converter;
dc->decoder.decoder->close(&dc->decoder.data);
}
DecodeConverter *decode_converter_new(const struct decoder_plugin *decoder_plugin) {
DecodeConverter *dc;
dc = (DecodeConverter*)g_object_new(CONVERTER_TYPE_DECODE, NULL);
g_assert(dc != NULL);
dc->decoder.decoder = decoder_plugin;
dc->decoder.decoder->init(&dc->decoder.data);
return dc;
}
|