summaryrefslogtreecommitdiff
path: root/xdelta1/libedsio/fh.c
diff options
context:
space:
mode:
authordotdotisdead <dotdotisdead@a3eca27d-f21b-0410-9b4a-6511e771f64e>2006-09-30 04:47:47 +0000
committerdotdotisdead <dotdotisdead@a3eca27d-f21b-0410-9b4a-6511e771f64e>2006-09-30 04:47:47 +0000
commitad85653ca73c8126de516b9a4294e8f08577c00d (patch)
tree79fb4d644ccf6a4fe8dac146b801a21d63537b23 /xdelta1/libedsio/fh.c
parent5a7c245871879325d7b05c06e0b2011203986ee8 (diff)
import 1.1.3
Diffstat (limited to 'xdelta1/libedsio/fh.c')
-rwxr-xr-xxdelta1/libedsio/fh.c164
1 files changed, 164 insertions, 0 deletions
diff --git a/xdelta1/libedsio/fh.c b/xdelta1/libedsio/fh.c
new file mode 100755
index 0000000..9135f8b
--- /dev/null
+++ b/xdelta1/libedsio/fh.c
@@ -0,0 +1,164 @@
1/* -*-Mode: C;-*-
2 * $Id: fh.c 1.3 Wed, 31 Mar 1999 17:39:58 -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 if (! ssource->fh->table->table_handle_getui (ssource->fh, &source->alloc_total))
94 return ST_Error;
95 }
96
97 return x;
98}
99
100gboolean
101handle_source_close (SerialSource* source)
102{
103 HandleSerialSource* ssource = (HandleSerialSource*) source;
104
105 return ssource->fh->table->table_handle_close (ssource->fh, 0);
106}
107
108gboolean
109handle_source_read (SerialSource* source, guint8 *ptr, guint32 len)
110{
111 HandleSerialSource* ssource = (HandleSerialSource*) source;
112
113 return ssource->fh->table->table_handle_read (ssource->fh, ptr, len) == len;
114}
115
116void
117handle_source_free (SerialSource* source)
118{
119 g_free (source);
120}
121
122gboolean
123handle_sink_type (SerialSink* sink, SerialType type, guint len, gboolean set_allocation)
124{
125 HandleSerialSink* ssink = (HandleSerialSink*) sink;
126
127 if (! ssink->fh->table->table_handle_putui (ssink->fh, type))
128 return FALSE;
129
130 if (set_allocation && ! ssink->fh->table->table_handle_putui (ssink->fh, len))
131 return FALSE;
132
133 return TRUE;
134}
135
136gboolean
137handle_sink_close (SerialSink* sink)
138{
139 HandleSerialSink* ssink = (HandleSerialSink*) sink;
140
141 if (ssink->fh->table->table_handle_close (ssink->fh, 0))
142 {
143 if (ssink->cont_onclose)
144 return ssink->cont_onclose (ssink->data1, ssink->data2, ssink->data3);
145
146 return TRUE;
147 }
148
149 return FALSE;
150}
151
152gboolean
153handle_sink_write (SerialSink* sink, const guint8 *ptr, guint32 len)
154{
155 HandleSerialSink* ssink = (HandleSerialSink*) sink;
156
157 return ssink->fh->table->table_handle_write (ssink->fh, ptr, len);
158}
159
160void
161handle_sink_free (SerialSink* sink)
162{
163 g_free (sink);
164}