iPXE
hw.c
Go to the documentation of this file.
1#include <stddef.h>
2#include <stdlib.h>
3#include <string.h>
4#include <errno.h>
5#include <ipxe/refcnt.h>
6#include <ipxe/process.h>
7#include <ipxe/xfer.h>
8#include <ipxe/open.h>
9
10/** @file
11 *
12 * "Hello World" data source
13 *
14 */
15
16struct hw {
17 struct refcnt refcnt;
20};
21
22static const char hw_msg[] = "Hello world!\n";
23
24static void hw_finished ( struct hw *hw, int rc ) {
25 intf_shutdown ( &hw->xfer, rc );
27}
28
29static void hw_step ( struct hw *hw ) {
30 int rc;
31
32 if ( xfer_window ( &hw->xfer ) ) {
33 rc = xfer_deliver_raw ( &hw->xfer, hw_msg, sizeof ( hw_msg ) );
34 hw_finished ( hw, rc );
35 }
36}
37
40 INTF_OP ( intf_close, struct hw *, hw_finished ),
41};
42
44 INTF_DESC ( struct hw, xfer, hw_xfer_operations );
45
47 PROC_DESC_ONCE ( struct hw, process, hw_step );
48
49static int hw_open ( struct interface *xfer, struct uri *uri __unused ) {
50 struct hw *hw;
51
52 /* Allocate and initialise structure */
53 hw = zalloc ( sizeof ( *hw ) );
54 if ( ! hw )
55 return -ENOMEM;
56 ref_init ( &hw->refcnt, NULL );
59
60 /* Attach parent interface, mortalise self, and return */
62 ref_put ( &hw->refcnt );
63 return 0;
64}
65
66struct uri_opener hw_uri_opener __uri_opener = {
67 .scheme = "hw",
68 .open = hw_open,
69};
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
Error codes.
#define __unused
Declare a variable or data structure as unused.
Definition compiler.h:573
#define ENOMEM
Not enough space.
Definition errno.h:535
static const char hw_msg[]
Definition hw.c:22
static void hw_finished(struct hw *hw, int rc)
Definition hw.c:24
static struct interface_descriptor hw_xfer_desc
Definition hw.c:43
static struct process_descriptor hw_process_desc
Definition hw.c:46
static void hw_step(struct hw *hw)
Definition hw.c:29
static struct interface_operation hw_xfer_operations[]
Definition hw.c:38
static int hw_open(struct interface *xfer, struct uri *uri __unused)
Definition hw.c:49
String functions.
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition interface.c:250
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition interface.c:108
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition interface.c:279
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
Definition interface.h:81
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition interface.h:204
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition interface.h:33
void * zalloc(size_t size)
Allocate cleared memory.
Definition malloc.c:662
Data transfer interface opening.
#define __uri_opener
Register a URI opener.
Definition open.h:68
void process_del(struct process *process)
Remove process from process list.
Definition process.c:80
Processes.
#define PROC_DESC_ONCE(object_type, process, _step)
Define a process descriptor for a process that runs only once.
Definition process.h:98
static void process_init(struct process *process, struct process_descriptor *desc, struct refcnt *refcnt)
Initialise process and add to process list.
Definition process.h:162
Reference counting.
#define ref_put(refcnt)
Drop reference to object.
Definition refcnt.h:107
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition refcnt.h:65
Definition hw.c:16
struct refcnt refcnt
Definition hw.c:17
struct process process
Definition hw.c:19
struct interface xfer
Definition hw.c:18
An object interface descriptor.
Definition interface.h:56
An object interface operation.
Definition interface.h:18
An object interface.
Definition interface.h:125
A process descriptor.
Definition process.h:32
A process.
Definition process.h:18
A URI opener.
Definition open.h:48
A Uniform Resource Identifier.
Definition uri.h:65
size_t xfer_window(struct interface *intf)
Check flow control window.
Definition xfer.c:117
void xfer_window_changed(struct interface *intf)
Report change of flow control window.
Definition xfer.c:147
int xfer_deliver_raw(struct interface *intf, const void *data, size_t len)
Deliver datagram as raw data without metadata.
Definition xfer.c:289
Data transfer interfaces.