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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 struct interface_operation hw_xfer_operations[] = {
  25. INTF_OP ( intf_close, struct hw *, hw_finished ),
  26. };
  27. static struct interface_descriptor hw_xfer_desc =
  28. INTF_DESC ( struct hw, xfer, hw_xfer_operations );
  29. static void hw_step ( struct process *process ) {
  30. struct hw *hw = container_of ( process, struct hw, process );
  31. int rc;
  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. static int hw_open ( struct interface *xfer, struct uri *uri __unused ) {
  38. struct hw *hw;
  39. /* Allocate and initialise structure */
  40. hw = zalloc ( sizeof ( *hw ) );
  41. if ( ! hw )
  42. return -ENOMEM;
  43. ref_init ( &hw->refcnt, NULL );
  44. intf_init ( &hw->xfer, &hw_xfer_desc, &hw->refcnt );
  45. process_init ( &hw->process, hw_step, &hw->refcnt );
  46. /* Attach parent interface, mortalise self, and return */
  47. intf_plug_plug ( &hw->xfer, xfer );
  48. ref_put ( &hw->refcnt );
  49. return 0;
  50. }
  51. struct uri_opener hw_uri_opener __uri_opener = {
  52. .scheme = "hw",
  53. .open = hw_open,
  54. };