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.

job.h 4.2KB

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