[contrib] Allow Network Protocol header to display in rom-o-matic
[gpxe.git] / src / core / hw.c
blob60bf4511683aeb8a41902041497cc86c5f82b3b2
1 #include <stddef.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <errno.h>
5 #include <gpxe/refcnt.h>
6 #include <gpxe/process.h>
7 #include <gpxe/xfer.h>
8 #include <gpxe/open.h>
10 /** @file
12 * "Hello World" data source
16 struct hw {
17 struct refcnt refcnt;
18 struct xfer_interface xfer;
19 struct process process;
22 static const char hw_msg[] = "Hello world!\n";
24 static void hw_finished ( struct hw *hw, int rc ) {
25 xfer_nullify ( &hw->xfer );
26 xfer_close ( &hw->xfer, rc );
27 process_del ( &hw->process );
30 static void hw_xfer_close ( struct xfer_interface *xfer, int rc ) {
31 struct hw *hw = container_of ( xfer, struct hw, xfer );
33 hw_finished ( hw, rc );
36 static struct xfer_interface_operations hw_xfer_operations = {
37 .close = hw_xfer_close,
38 .vredirect = ignore_xfer_vredirect,
39 .window = unlimited_xfer_window,
40 .alloc_iob = default_xfer_alloc_iob,
41 .deliver_iob = xfer_deliver_as_raw,
42 .deliver_raw = ignore_xfer_deliver_raw,
45 static void hw_step ( struct process *process ) {
46 struct hw *hw = container_of ( process, struct hw, process );
47 int rc;
49 if ( xfer_window ( &hw->xfer ) ) {
50 rc = xfer_deliver_raw ( &hw->xfer, hw_msg, sizeof ( hw_msg ) );
51 hw_finished ( hw, rc );
55 static int hw_open ( struct xfer_interface *xfer, struct uri *uri __unused ) {
56 struct hw *hw;
58 /* Allocate and initialise structure */
59 hw = zalloc ( sizeof ( *hw ) );
60 if ( ! hw )
61 return -ENOMEM;
62 ref_init ( &hw->refcnt, NULL );
63 xfer_init ( &hw->xfer, &hw_xfer_operations, &hw->refcnt );
64 process_init ( &hw->process, hw_step, &hw->refcnt );
66 /* Attach parent interface, mortalise self, and return */
67 xfer_plug_plug ( &hw->xfer, xfer );
68 ref_put ( &hw->refcnt );
69 return 0;
72 struct uri_opener hw_uri_opener __uri_opener = {
73 .scheme = "hw",
74 .open = hw_open,