summaryrefslogtreecommitdiffstats
path: root/src/core/hw.c
diff options
context:
space:
mode:
authorMichael Brown2007-05-15 17:23:09 +0200
committerMichael Brown2007-05-15 17:23:09 +0200
commit5471bfbbbe9f49f7be7f2ca92b8c99a02c435458 (patch)
treeb2dcb5f373672a767336ddba8d7e25fcc3f0c554 /src/core/hw.c
parentAdd always_inline attribute to force gcc to inline single-instruction (diff)
downloadipxe-5471bfbbbe9f49f7be7f2ca92b8c99a02c435458.tar.gz
ipxe-5471bfbbbe9f49f7be7f2ca92b8c99a02c435458.tar.xz
ipxe-5471bfbbbe9f49f7be7f2ca92b8c99a02c435458.zip
Data-transfer interface should now be functionally complete.
Diffstat (limited to 'src/core/hw.c')
-rw-r--r--src/core/hw.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/core/hw.c b/src/core/hw.c
new file mode 100644
index 00000000..80cac99c
--- /dev/null
+++ b/src/core/hw.c
@@ -0,0 +1,68 @@
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <gpxe/refcnt.h>
+#include <gpxe/xfer.h>
+#include <gpxe/open.h>
+
+/** @file
+ *
+ * "Hello World" data source
+ *
+ */
+
+struct hw {
+ struct refcnt refcnt;
+ struct xfer_interface xfer;
+};
+
+static const char hw_msg[] = "Hello world!\n";
+
+static void hw_finished ( struct hw *hw, int rc ) {
+ xfer_nullify ( &hw->xfer );
+ xfer_close ( &hw->xfer, rc );
+ ref_put ( &hw->refcnt );
+}
+
+static void hw_xfer_close ( struct xfer_interface *xfer, int rc ) {
+ struct hw *hw = container_of ( xfer, struct hw, xfer );
+
+ hw_finished ( hw, rc );
+}
+
+static int hw_xfer_request ( struct xfer_interface *xfer, off_t start __unused,
+ int whence __unused, size_t len __unused ) {
+ struct hw *hw = container_of ( xfer, struct hw, xfer );
+
+ xfer_deliver_raw ( xfer, hw_msg, sizeof ( hw_msg ) );
+ hw_finished ( hw, 0 );
+ return 0;
+}
+
+static struct xfer_interface_operations hw_xfer_operations = {
+ .close = hw_xfer_close,
+ .vredirect = ignore_xfer_vredirect,
+ .request = hw_xfer_request,
+ .seek = ignore_xfer_seek,
+ .deliver_iob = xfer_deliver_as_raw,
+ .deliver_raw = ignore_xfer_deliver_raw,
+};
+
+static int hw_open ( struct xfer_interface *xfer, struct uri *uri __unused ) {
+ struct hw *hw;
+
+ hw = malloc ( sizeof ( *hw ) );
+ if ( ! hw )
+ return -ENOMEM;
+ memset ( hw, 0, sizeof ( *hw ) );
+ xfer_init ( &hw->xfer, &hw_xfer_operations, &hw->refcnt );
+
+ xfer_plug_plug ( &hw->xfer, xfer );
+ return 0;
+}
+
+struct uri_opener hw_uri_opener __uri_opener = {
+ .scheme = "hw",
+ .open = hw_open,
+};