2007-05-15 17:23:09 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2010-04-19 21:16:01 +02:00
|
|
|
#include <ipxe/refcnt.h>
|
|
|
|
#include <ipxe/process.h>
|
|
|
|
#include <ipxe/xfer.h>
|
|
|
|
#include <ipxe/open.h>
|
2007-05-15 17:23:09 +02:00
|
|
|
|
|
|
|
/** @file
|
|
|
|
*
|
|
|
|
* "Hello World" data source
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct hw {
|
|
|
|
struct refcnt refcnt;
|
2010-06-16 02:31:29 +02:00
|
|
|
struct interface xfer;
|
2007-05-26 17:04:36 +02:00
|
|
|
struct process process;
|
2007-05-15 17:23:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char hw_msg[] = "Hello world!\n";
|
|
|
|
|
|
|
|
static void hw_finished ( struct hw *hw, int rc ) {
|
2010-06-16 02:31:29 +02:00
|
|
|
intf_shutdown ( &hw->xfer, rc );
|
2007-05-26 17:04:36 +02:00
|
|
|
process_del ( &hw->process );
|
2007-05-15 17:23:09 +02:00
|
|
|
}
|
|
|
|
|
2011-06-24 15:14:41 +02:00
|
|
|
static void hw_step ( struct hw *hw ) {
|
2007-05-26 17:04:36 +02:00
|
|
|
int rc;
|
|
|
|
|
2007-07-08 15:11:07 +02:00
|
|
|
if ( xfer_window ( &hw->xfer ) ) {
|
2007-05-26 17:04:36 +02:00
|
|
|
rc = xfer_deliver_raw ( &hw->xfer, hw_msg, sizeof ( hw_msg ) );
|
|
|
|
hw_finished ( hw, rc );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-24 15:14:41 +02:00
|
|
|
static struct interface_operation hw_xfer_operations[] = {
|
2011-06-24 17:51:31 +02:00
|
|
|
INTF_OP ( xfer_window_changed, struct hw *, hw_step ),
|
2011-06-24 15:14:41 +02:00
|
|
|
INTF_OP ( intf_close, struct hw *, hw_finished ),
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct interface_descriptor hw_xfer_desc =
|
|
|
|
INTF_DESC ( struct hw, xfer, hw_xfer_operations );
|
|
|
|
|
|
|
|
static struct process_descriptor hw_process_desc =
|
2011-06-24 17:51:31 +02:00
|
|
|
PROC_DESC_ONCE ( struct hw, process, hw_step );
|
2011-06-24 15:14:41 +02:00
|
|
|
|
2010-06-16 02:31:29 +02:00
|
|
|
static int hw_open ( struct interface *xfer, struct uri *uri __unused ) {
|
2007-05-15 17:23:09 +02:00
|
|
|
struct hw *hw;
|
|
|
|
|
2007-05-15 18:53:46 +02:00
|
|
|
/* Allocate and initialise structure */
|
2007-06-18 01:24:44 +02:00
|
|
|
hw = zalloc ( sizeof ( *hw ) );
|
2007-05-15 17:23:09 +02:00
|
|
|
if ( ! hw )
|
|
|
|
return -ENOMEM;
|
2010-06-15 18:33:23 +02:00
|
|
|
ref_init ( &hw->refcnt, NULL );
|
2010-06-16 02:31:29 +02:00
|
|
|
intf_init ( &hw->xfer, &hw_xfer_desc, &hw->refcnt );
|
2011-06-24 15:14:41 +02:00
|
|
|
process_init ( &hw->process, &hw_process_desc, &hw->refcnt );
|
2007-05-15 17:23:09 +02:00
|
|
|
|
2007-05-15 18:53:46 +02:00
|
|
|
/* Attach parent interface, mortalise self, and return */
|
2010-06-16 02:31:29 +02:00
|
|
|
intf_plug_plug ( &hw->xfer, xfer );
|
2007-05-15 18:53:46 +02:00
|
|
|
ref_put ( &hw->refcnt );
|
2007-05-15 17:23:09 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct uri_opener hw_uri_opener __uri_opener = {
|
|
|
|
.scheme = "hw",
|
|
|
|
.open = hw_open,
|
|
|
|
};
|