hw.c
Go to the documentation of this file.00001 #include <stddef.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include <errno.h>
00005 #include <gpxe/refcnt.h>
00006 #include <gpxe/process.h>
00007 #include <gpxe/xfer.h>
00008 #include <gpxe/open.h>
00009
00010
00011
00012
00013
00014
00015
00016 struct hw {
00017 struct refcnt refcnt;
00018 struct xfer_interface xfer;
00019 struct process process;
00020 };
00021
00022 static const char hw_msg[] = "Hello world!\n";
00023
00024 static void hw_finished ( struct hw *hw, int rc ) {
00025 xfer_nullify ( &hw->xfer );
00026 xfer_close ( &hw->xfer, rc );
00027 process_del ( &hw->process );
00028 }
00029
00030 static void hw_xfer_close ( struct xfer_interface *xfer, int rc ) {
00031 struct hw *hw = container_of ( xfer, struct hw, xfer );
00032
00033 hw_finished ( hw, rc );
00034 }
00035
00036 static struct xfer_interface_operations hw_xfer_operations = {
00037 .close = hw_xfer_close,
00038 .vredirect = ignore_xfer_vredirect,
00039 .window = unlimited_xfer_window,
00040 .alloc_iob = default_xfer_alloc_iob,
00041 .deliver_iob = xfer_deliver_as_raw,
00042 .deliver_raw = ignore_xfer_deliver_raw,
00043 };
00044
00045 static void hw_step ( struct process *process ) {
00046 struct hw *hw = container_of ( process, struct hw, process );
00047 int rc;
00048
00049 if ( xfer_window ( &hw->xfer ) ) {
00050 rc = xfer_deliver_raw ( &hw->xfer, hw_msg, sizeof ( hw_msg ) );
00051 hw_finished ( hw, rc );
00052 }
00053 }
00054
00055 static int hw_open ( struct xfer_interface *xfer, struct uri *uri __unused ) {
00056 struct hw *hw;
00057
00058
00059 hw = zalloc ( sizeof ( *hw ) );
00060 if ( ! hw )
00061 return -ENOMEM;
00062 xfer_init ( &hw->xfer, &hw_xfer_operations, &hw->refcnt );
00063 process_init ( &hw->process, hw_step, &hw->refcnt );
00064
00065
00066 xfer_plug_plug ( &hw->xfer, xfer );
00067 ref_put ( &hw->refcnt );
00068 return 0;
00069 }
00070
00071 struct uri_opener hw_uri_opener __uri_opener = {
00072 .scheme = "hw",
00073 .open = hw_open,
00074 };