Added netdev_nullify to natsemi_remove()
[gpxe.git] / src / core / hw.c
blob3502dbfbc5069126027b43cdad34791f3d15b6ff
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 .seek = ignore_xfer_seek,
40 .window = unlimited_xfer_window,
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 xfer_init ( &hw->xfer, &hw_xfer_operations, &hw->refcnt );
63 process_init ( &hw->process, hw_step, &hw->refcnt );
65 /* Attach parent interface, mortalise self, and return */
66 xfer_plug_plug ( &hw->xfer, xfer );
67 ref_put ( &hw->refcnt );
68 return 0;
71 struct uri_opener hw_uri_opener __uri_opener = {
72 .scheme = "hw",
73 .open = hw_open,