source: bootcd/isolinux/syslinux-6.03/gpxe/src/core/hw.c

Last change on this file was e16e8f2, checked in by Edwin Eefting <edwin@datux.nl>, 3 years ago

bootstuff

  • Property mode set to 100644
File size: 1.7 KB
Line 
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>
9
10/** @file
11 *
12 * "Hello World" data source
13 *
14 */
15
16struct hw {
17        struct refcnt refcnt;
18        struct xfer_interface xfer;
19        struct process process;
20};
21
22static const char hw_msg[] = "Hello world!\n";
23
24static void hw_finished ( struct hw *hw, int rc ) {
25        xfer_nullify ( &hw->xfer );
26        xfer_close ( &hw->xfer, rc );
27        process_del ( &hw->process );
28}
29
30static void hw_xfer_close ( struct xfer_interface *xfer, int rc ) {
31        struct hw *hw = container_of ( xfer, struct hw, xfer );
32
33        hw_finished ( hw, rc );
34}
35
36static 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,
43};
44
45static void hw_step ( struct process *process ) {
46        struct hw *hw = container_of ( process, struct hw, process );
47        int rc;
48
49        if ( xfer_window ( &hw->xfer ) ) {
50                rc = xfer_deliver_raw ( &hw->xfer, hw_msg, sizeof ( hw_msg ) );
51                hw_finished ( hw, rc );
52        }
53}
54
55static int hw_open ( struct xfer_interface *xfer, struct uri *uri __unused ) {
56        struct hw *hw;
57
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 );
64
65        /* Attach parent interface, mortalise self, and return */
66        xfer_plug_plug ( &hw->xfer, xfer );
67        ref_put ( &hw->refcnt );
68        return 0;
69}
70
71struct uri_opener hw_uri_opener __uri_opener = {
72        .scheme = "hw",
73        .open = hw_open,
74};
Note: See TracBrowser for help on using the repository browser.