iPXE
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 <ipxe/refcnt.h>
00006 #include <ipxe/process.h>
00007 #include <ipxe/xfer.h>
00008 #include <ipxe/open.h>
00009 
00010 /** @file
00011  *
00012  * "Hello World" data source
00013  *
00014  */
00015 
00016 struct hw {
00017         struct refcnt refcnt;
00018         struct 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         intf_shutdown ( &hw->xfer, rc );
00026         process_del ( &hw->process );
00027 }
00028 
00029 static void hw_step ( struct hw *hw ) {
00030         int rc;
00031 
00032         if ( xfer_window ( &hw->xfer ) ) {
00033                 rc = xfer_deliver_raw ( &hw->xfer, hw_msg, sizeof ( hw_msg ) );
00034                 hw_finished ( hw, rc );
00035         }
00036 }
00037 
00038 static struct interface_operation hw_xfer_operations[] = {
00039         INTF_OP ( xfer_window_changed, struct hw *, hw_step ),
00040         INTF_OP ( intf_close, struct hw *, hw_finished ),
00041 };
00042 
00043 static struct interface_descriptor hw_xfer_desc =
00044         INTF_DESC ( struct hw, xfer, hw_xfer_operations );
00045 
00046 static struct process_descriptor hw_process_desc =
00047         PROC_DESC_ONCE ( struct hw, process, hw_step );
00048 
00049 static int hw_open ( struct interface *xfer, struct uri *uri __unused ) {
00050         struct hw *hw;
00051 
00052         /* Allocate and initialise structure */
00053         hw = zalloc ( sizeof ( *hw ) );
00054         if ( ! hw )
00055                 return -ENOMEM;
00056         ref_init ( &hw->refcnt, NULL );
00057         intf_init ( &hw->xfer, &hw_xfer_desc, &hw->refcnt );
00058         process_init ( &hw->process, &hw_process_desc, &hw->refcnt );
00059 
00060         /* Attach parent interface, mortalise self, and return */
00061         intf_plug_plug ( &hw->xfer, xfer );
00062         ref_put ( &hw->refcnt );
00063         return 0;
00064 }
00065 
00066 struct uri_opener hw_uri_opener __uri_opener = {
00067         .scheme = "hw",
00068         .open = hw_open,
00069 };