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 
16 struct hw {
17  struct refcnt refcnt;
18  struct interface xfer;
19  struct process process;
20 };
21 
22 static const char hw_msg[] = "Hello world!\n";
23 
24 static void hw_finished ( struct hw *hw, int rc ) {
25  intf_shutdown ( &hw->xfer, rc );
26  process_del ( &hw->process );
27 }
28 
29 static 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 
39  INTF_OP ( xfer_window_changed, struct hw *, hw_step ),
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 
49 static 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 */
61  intf_plug_plug ( &hw->xfer, xfer );
62  ref_put ( &hw->refcnt );
63  return 0;
64 }
65 
66 struct uri_opener hw_uri_opener __uri_opener = {
67  .scheme = "hw",
68  .open = hw_open,
69 };
A process.
Definition: process.h:17
An object interface operation.
Definition: interface.h:17
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void xfer_window_changed(struct interface *intf)
Report change of flow control window.
Definition: xfer.c:145
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:244
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition: interface.c:273
static struct interface_operation hw_xfer_operations[]
Definition: hw.c:38
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
Error codes.
static void process_init(struct process *process, struct process_descriptor *desc, struct refcnt *refcnt)
Initialise process and add to process list.
Definition: process.h:161
struct process process
Definition: hw.c:19
A process descriptor.
Definition: process.h:31
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:102
#define PROC_DESC_ONCE(object_type, process, _step)
Define a process descriptor for a process that runs only once.
Definition: process.h:97
void process_del(struct process *process)
Remove process from process list.
Definition: process.c:79
static struct interface_descriptor hw_xfer_desc
Definition: hw.c:43
Definition: hw.c:16
size_t xfer_window(struct interface *intf)
Check flow control window.
Definition: xfer.c:115
static const char hw_msg[]
Definition: hw.c:22
int xfer_deliver_raw(struct interface *intf, const void *data, size_t len)
Deliver datagram as raw data without metadata.
Definition: xfer.c:287
Data transfer interfaces.
A reference counter.
Definition: refcnt.h:26
#define ENOMEM
Not enough space.
Definition: errno.h:534
An object interface.
Definition: interface.h:109
const char * scheme
URI protocol name.
Definition: open.h:53
struct refcnt refcnt
Definition: hw.c:17
An object interface descriptor.
Definition: interface.h:40
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
static int hw_open(struct interface *xfer, struct uri *uri __unused)
Definition: hw.c:49
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
Processes.
Data transfer interface opening.
static void hw_finished(struct hw *hw, int rc)
Definition: hw.c:24
static void hw_step(struct hw *hw)
Definition: hw.c:29
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
Definition: interface.h:65
struct interface xfer
Definition: hw.c:18
static struct process_descriptor hw_process_desc
Definition: hw.c:46
struct uri_opener hw_uri_opener __uri_opener
Definition: hw.c:66
Reference counting.
A Uniform Resource Identifier.
Definition: uri.h:50
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:173
A URI opener.
Definition: open.h:47
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
String functions.
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106