job.h 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #ifndef _GPXE_JOB_H
  2. #define _GPXE_JOB_H
  3. /** @file
  4. *
  5. * Job control interfaces
  6. *
  7. */
  8. #include <stddef.h>
  9. #include <gpxe/interface.h>
  10. /** Job progress */
  11. struct job_progress {
  12. /** Amount of operation completed so far
  13. *
  14. * The units for this quantity are arbitrary. @c completed
  15. * divded by @total should give something which approximately
  16. * represents the progress through the operation. For a
  17. * download operation, using byte counts would make sense.
  18. */
  19. unsigned long completed;
  20. /** Total operation size
  21. *
  22. * See @c completed. A zero value means "total size unknown"
  23. * and is explcitly permitted; users should take this into
  24. * account before calculating @c completed/total.
  25. */
  26. unsigned long total;
  27. };
  28. struct job_interface;
  29. /** Job control interface operations */
  30. struct job_interface_operations {
  31. /** Job completed
  32. *
  33. * @v job Job control interface
  34. * @v rc Overall job status code
  35. */
  36. void ( * done ) ( struct job_interface *job, int rc );
  37. /** Abort job
  38. *
  39. * @v job Job control interface
  40. */
  41. void ( * kill ) ( struct job_interface *job );
  42. /** Get job progress
  43. *
  44. * @v job Job control interface
  45. * @v progress Progress data to fill in
  46. */
  47. void ( * progress ) ( struct job_interface *job,
  48. struct job_progress *progress );
  49. };
  50. /** A job control interface */
  51. struct job_interface {
  52. /** Generic object communication interface */
  53. struct interface intf;
  54. /** Operations for received messages */
  55. struct job_interface_operations *op;
  56. };
  57. extern struct job_interface null_job;
  58. extern struct job_interface_operations null_job_ops;
  59. extern void job_done ( struct job_interface *job, int rc );
  60. extern void ignore_job_done ( struct job_interface *job, int rc );
  61. extern void ignore_job_kill ( struct job_interface *job );
  62. extern void ignore_job_progress ( struct job_interface *job,
  63. struct job_progress *progress );
  64. /**
  65. * Initialise a job control interface
  66. *
  67. * @v job Job control interface
  68. * @v op Job control interface operations
  69. * @v refcnt Containing object reference counter, or NULL
  70. */
  71. static inline void job_init ( struct job_interface *job,
  72. struct job_interface_operations *op,
  73. struct refcnt *refcnt ) {
  74. job->intf.dest = &null_job.intf;
  75. job->intf.refcnt = refcnt;
  76. job->op = op;
  77. }
  78. /**
  79. * Get job control interface from generic object communication interface
  80. *
  81. * @v intf Generic object communication interface
  82. * @ret job Job control interface
  83. */
  84. static inline __attribute__ (( always_inline )) struct job_interface *
  85. intf_to_job ( struct interface *intf ) {
  86. return container_of ( intf, struct job_interface, intf );
  87. }
  88. /**
  89. * Get reference to destination job control interface
  90. *
  91. * @v job Job control interface
  92. * @ret dest Destination interface
  93. */
  94. static inline __attribute__ (( always_inline )) struct job_interface *
  95. job_get_dest ( struct job_interface *job ) {
  96. return intf_to_job ( intf_get ( job->intf.dest ) );
  97. }
  98. /**
  99. * Drop reference to job control interface
  100. *
  101. * @v job Job control interface
  102. */
  103. static inline __attribute__ (( always_inline )) void
  104. job_put ( struct job_interface *job ) {
  105. intf_put ( &job->intf );
  106. }
  107. /**
  108. * Plug a job control interface into a new destination interface
  109. *
  110. * @v job Job control interface
  111. * @v dest New destination interface
  112. */
  113. static inline void job_plug ( struct job_interface *job,
  114. struct job_interface *dest ) {
  115. plug ( &job->intf, &dest->intf );
  116. }
  117. /**
  118. * Plug two job control interfaces together
  119. *
  120. * @v a Job control interface A
  121. * @v b Job control interface B
  122. */
  123. static inline void job_plug_plug ( struct job_interface *a,
  124. struct job_interface *b ) {
  125. plug_plug ( &a->intf, &b->intf );
  126. }
  127. /**
  128. * Unplug a job control interface
  129. *
  130. * @v job Job control interface
  131. */
  132. static inline void job_unplug ( struct job_interface *job ) {
  133. plug ( &job->intf, &null_job.intf );
  134. }
  135. /**
  136. * Stop using a job control interface
  137. *
  138. * @v job Job control interface
  139. *
  140. * After calling this method, no further messages will be received via
  141. * the interface.
  142. */
  143. static inline void job_nullify ( struct job_interface *job ) {
  144. job->op = &null_job_ops;
  145. };
  146. #endif /* _GPXE_JOB_H */