Przeglądaj źródła

Added a simple pass-through filter layer for data transfer interfaces.

tags/v0.9.3
Michael Brown 17 lat temu
rodzic
commit
a6467c99a0
2 zmienionych plików z 153 dodań i 0 usunięć
  1. 78
    0
      src/core/filter.c
  2. 75
    0
      src/include/gpxe/filter.h

+ 78
- 0
src/core/filter.c Wyświetl plik

@@ -0,0 +1,78 @@
1
+/*
2
+ * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+#include <gpxe/xfer.h>
20
+#include <gpxe/filter.h>
21
+
22
+/** @file
23
+ *
24
+ * Data transfer filters
25
+ *
26
+ */
27
+
28
+/*
29
+ * Pass-through methods to be used by filters which don't want to
30
+ * intercept all events.
31
+ *
32
+ */
33
+
34
+void filter_close ( struct xfer_interface *xfer, int rc ) {
35
+	struct xfer_interface *other = filter_other_half ( xfer );
36
+
37
+	xfer_close ( other, rc );
38
+}
39
+
40
+int filter_vredirect ( struct xfer_interface *xfer, int type,
41
+			va_list args ) {
42
+	struct xfer_interface *other = filter_other_half ( xfer );
43
+
44
+	return xfer_vredirect ( other, type, args );
45
+}
46
+
47
+int filter_seek ( struct xfer_interface *xfer, off_t offset, int whence ) {
48
+	struct xfer_interface *other = filter_other_half ( xfer );
49
+
50
+	return xfer_seek ( other, offset, whence );
51
+}
52
+
53
+size_t filter_window ( struct xfer_interface *xfer ) {
54
+	struct xfer_interface *other = filter_other_half ( xfer );
55
+
56
+	return xfer_window ( other );
57
+}
58
+
59
+struct io_buffer * filter_alloc_iob ( struct xfer_interface *xfer,
60
+				      size_t len ) {
61
+	struct xfer_interface *other = filter_other_half ( xfer );
62
+
63
+	return xfer_alloc_iob ( other, len );
64
+}
65
+
66
+int filter_deliver_iob ( struct xfer_interface *xfer, struct io_buffer *iobuf,
67
+			 struct xfer_metadata *meta ) {
68
+	struct xfer_interface *other = filter_other_half ( xfer );
69
+
70
+	return xfer_deliver_iob_meta ( other, iobuf, meta );
71
+}
72
+
73
+int filter_deliver_raw ( struct xfer_interface *xfer, const void *data,
74
+			 size_t len ) {
75
+	struct xfer_interface *other = filter_other_half ( xfer );
76
+
77
+	return xfer_deliver_raw ( other, data, len );
78
+}

+ 75
- 0
src/include/gpxe/filter.h Wyświetl plik

@@ -0,0 +1,75 @@
1
+#ifndef _GPXE_FILTER_H
2
+#define _GPXE_FILTER_H
3
+
4
+/** @file
5
+ *
6
+ * Data transfer filters
7
+ *
8
+ */
9
+
10
+#include <stddef.h>
11
+#include <gpxe/xfer.h>
12
+
13
+/**
14
+ * Half of a data transfer filter
15
+ *
16
+ * Embed two of these structures within a structure implementing a
17
+ * data transfer filter, and intialise with filter_init().  You can
18
+ * then use the filter_xxx() methods as the data transfer interface
19
+ * methods as required.
20
+ */
21
+struct xfer_filter_half {
22
+	/** Data transfer interface */
23
+	struct xfer_interface xfer;
24
+	/** Other half of the data transfer filter */
25
+	struct xfer_filter_half *other;
26
+};
27
+
28
+/**
29
+ * Get data transfer interface for the other half of a data transfer filter
30
+ *
31
+ * @v xfer		Data transfer interface
32
+ * @ret other		Other half's data transfer interface
33
+ */
34
+static inline __attribute__ (( always_inline )) struct xfer_interface *
35
+filter_other_half ( struct xfer_interface *xfer ) {
36
+	struct xfer_filter_half *half = 
37
+		container_of ( xfer, struct xfer_filter_half, xfer );
38
+	return &half->other->xfer;
39
+}
40
+
41
+extern void filter_close ( struct xfer_interface *xfer, int rc );
42
+extern int filter_vredirect ( struct xfer_interface *xfer, int type,
43
+			      va_list args );
44
+extern int filter_seek ( struct xfer_interface *xfer, off_t offset,
45
+			 int whence );
46
+extern size_t filter_window ( struct xfer_interface *xfer );
47
+extern struct io_buffer * filter_alloc_iob ( struct xfer_interface *xfer,
48
+					     size_t len );
49
+extern int filter_deliver_iob ( struct xfer_interface *xfer,
50
+				struct io_buffer *iobuf,
51
+				struct xfer_metadata *meta );
52
+extern int filter_deliver_raw ( struct xfer_interface *xfer, const void *data,
53
+				size_t len );
54
+
55
+/**
56
+ * Initialise a data transfer filter
57
+ *
58
+ * @v left		"Left" half of the filter
59
+ * @v left_op		Data transfer interface operations for "left" half
60
+ * @v right		"Right" half of the filter
61
+ * @v right_op		Data transfer interface operations for "right" half
62
+ * @v refcnt		Containing object reference counter, or NULL
63
+ */
64
+static inline void filter_init ( struct xfer_filter_half *left,
65
+				 struct xfer_interface_operations *left_op,
66
+				 struct xfer_filter_half *right,
67
+				 struct xfer_interface_operations *right_op,
68
+				 struct refcnt *refcnt ) {
69
+	xfer_init ( &left->xfer, left_op, refcnt );
70
+	xfer_init ( &right->xfer, right_op, refcnt );
71
+	left->other = right;
72
+	right->other = left;
73
+}
74
+
75
+#endif /* _GPXE_FILTER_H */

Ładowanie…
Anuluj
Zapisz