You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hw.c 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. /** @file
  10. *
  11. * "Hello World" data source
  12. *
  13. */
  14. struct hw {
  15. struct refcnt refcnt;
  16. struct interface xfer;
  17. struct process process;
  18. };
  19. static const char hw_msg[] = "Hello world!\n";
  20. static void hw_finished ( struct hw *hw, int rc ) {
  21. intf_shutdown ( &hw->xfer, rc );
  22. process_del ( &hw->process );
  23. }
  24. static void hw_step ( struct hw *hw ) {
  25. int rc;
  26. if ( xfer_window ( &hw->xfer ) ) {
  27. rc = xfer_deliver_raw ( &hw->xfer, hw_msg, sizeof ( hw_msg ) );
  28. hw_finished ( hw, rc );
  29. }
  30. }
  31. static struct interface_operation hw_xfer_operations[] = {
  32. INTF_OP ( xfer_window_changed, struct hw *, hw_step ),
  33. INTF_OP ( intf_close, struct hw *, hw_finished ),
  34. };
  35. static struct interface_descriptor hw_xfer_desc =
  36. INTF_DESC ( struct hw, xfer, hw_xfer_operations );
  37. static struct process_descriptor hw_process_desc =
  38. PROC_DESC_ONCE ( struct hw, process, hw_step );
  39. static int hw_open ( struct interface *xfer, struct uri *uri __unused ) {
  40. struct hw *hw;
  41. /* Allocate and initialise structure */
  42. hw = zalloc ( sizeof ( *hw ) );
  43. if ( ! hw )
  44. return -ENOMEM;
  45. ref_init ( &hw->refcnt, NULL );
  46. intf_init ( &hw->xfer, &hw_xfer_desc, &hw->refcnt );
  47. process_init ( &hw->process, &hw_process_desc, &hw->refcnt );
  48. /* Attach parent interface, mortalise self, and return */
  49. intf_plug_plug ( &hw->xfer, xfer );
  50. ref_put ( &hw->refcnt );
  51. return 0;
  52. }
  53. struct uri_opener hw_uri_opener __uri_opener = {
  54. .scheme = "hw",
  55. .open = hw_open,
  56. };