summaryrefslogtreecommitdiff
path: root/xdelta1/libedsio/fh.c
diff options
context:
space:
mode:
Diffstat (limited to 'xdelta1/libedsio/fh.c')
-rw-r--r--xdelta1/libedsio/fh.c167
1 files changed, 0 insertions, 167 deletions
diff --git a/xdelta1/libedsio/fh.c b/xdelta1/libedsio/fh.c
deleted file mode 100644
index 6b27cbf..0000000
--- a/xdelta1/libedsio/fh.c
+++ /dev/null
@@ -1,167 +0,0 @@
1/* -*-Mode: C;-*-
2 * $Id: fh.c 1.1 Sun, 28 Jan 2007 10:02:26 -0800 jmacd $
3 *
4 * Copyright (C) 1998, 1999, Josh MacDonald.
5 * All Rights Reserved.
6 *
7 * Author: Josh MacDonald <jmacd@CS.Berkeley.EDU>
8 */
9
10#include "edsio.h"
11
12/* Handle source/sink impls
13 */
14typedef struct _HandleSerialSource HandleSerialSource;
15typedef struct _HandleSerialSink HandleSerialSink;
16
17struct _HandleSerialSource {
18 SerialSource source;
19
20 FileHandle* fh;
21};
22
23struct _HandleSerialSink {
24 SerialSink sink;
25
26 FileHandle* fh;
27 gpointer data1;
28 gpointer data2;
29 gpointer data3;
30 gboolean (* cont_onclose) (gpointer data1, gpointer data2, gpointer data3);
31};
32
33static SerialType handle_source_type (SerialSource* source, gboolean set_allocation);
34static gboolean handle_source_close (SerialSource* source);
35static gboolean handle_source_read (SerialSource* source, guint8 *ptr, guint32 len);
36static void handle_source_free (SerialSource* source);
37
38static gboolean handle_sink_type (SerialSink* sink, SerialType type, guint len, gboolean set_allocation);
39static gboolean handle_sink_close (SerialSink* sink);
40static gboolean handle_sink_write (SerialSink* sink, const guint8 *ptr, guint32 len);
41static void handle_sink_free (SerialSink* sink);
42
43SerialSource*
44handle_source (FileHandle* fh)
45{
46 HandleSerialSource* it = g_new0 (HandleSerialSource, 1);
47
48 serializeio_source_init (&it->source,
49 handle_source_type,
50 handle_source_close,
51 handle_source_read,
52 handle_source_free,
53 NULL,
54 NULL);
55
56 it->fh = fh;
57
58 return &it->source;
59}
60
61SerialSink*
62handle_sink (FileHandle* fh, gpointer data1, gpointer data2, gpointer data3, gboolean (* cont_onclose) (gpointer data1, gpointer data2, gpointer data3))
63{
64 HandleSerialSink* it = g_new0 (HandleSerialSink, 1);
65
66 serializeio_sink_init (&it->sink,
67 handle_sink_type,
68 handle_sink_close,
69 handle_sink_write,
70 handle_sink_free,
71 NULL);
72
73 it->fh = fh;
74 it->data1 = data1;
75 it->data2 = data2;
76 it->data3 = data3;
77 it->cont_onclose = cont_onclose;
78
79 return &it->sink;
80}
81
82SerialType
83handle_source_type (SerialSource* source, gboolean set_allocation)
84{
85 HandleSerialSource* ssource = (HandleSerialSource*) source;
86 guint32 x;
87
88 if (! ssource->fh->table->table_handle_getui (ssource->fh, &x))
89 return ST_Error;
90
91 if (set_allocation)
92 {
93 /* Note: set_allocation is deprecated in 1.1.4 */
94 guint32 bogus;
95 if (! ssource->fh->table->table_handle_getui (ssource->fh, &bogus))
96 return ST_Error;
97 }
98
99 return x;
100}
101
102gboolean
103handle_source_close (SerialSource* source)
104{
105 HandleSerialSource* ssource = (HandleSerialSource*) source;
106
107 return ssource->fh->table->table_handle_close (ssource->fh, 0);
108}
109
110gboolean
111handle_source_read (SerialSource* source, guint8 *ptr, guint32 len)
112{
113 HandleSerialSource* ssource = (HandleSerialSource*) source;
114
115 return ssource->fh->table->table_handle_read (ssource->fh, ptr, len) == len;
116}
117
118void
119handle_source_free (SerialSource* source)
120{
121 g_free (source);
122}
123
124gboolean
125handle_sink_type (SerialSink* sink, SerialType type, guint len, gboolean set_allocation)
126{
127 HandleSerialSink* ssink = (HandleSerialSink*) sink;
128
129 if (! ssink->fh->table->table_handle_putui (ssink->fh, type))
130 return FALSE;
131
132 /* Note: set_allocation is deprecated in 1.1.4 */
133 if (set_allocation && ! ssink->fh->table->table_handle_putui (ssink->fh, len))
134 return FALSE;
135
136 return TRUE;
137}
138
139gboolean
140handle_sink_close (SerialSink* sink)
141{
142 HandleSerialSink* ssink = (HandleSerialSink*) sink;
143
144 if (ssink->fh->table->table_handle_close (ssink->fh, 0))
145 {
146 if (ssink->cont_onclose)
147 return ssink->cont_onclose (ssink->data1, ssink->data2, ssink->data3);
148
149 return TRUE;
150 }
151
152 return FALSE;
153}
154
155gboolean
156handle_sink_write (SerialSink* sink, const guint8 *ptr, guint32 len)
157{
158 HandleSerialSink* ssink = (HandleSerialSink*) sink;
159
160 return ssink->fh->table->table_handle_write (ssink->fh, ptr, len);
161}
162
163void
164handle_sink_free (SerialSink* sink)
165{
166 g_free (sink);
167}