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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 ignore_job_done ( struct job_interface *job, int rc );
  63. extern void ignore_job_kill ( struct job_interface *job );
  64. extern void ignore_job_progress ( struct job_interface *job,
  65. struct job_progress *progress );
  66. /**
  67. * Initialise a job control interface
  68. *
  69. * @v job Job control interface
  70. * @v op Job control interface operations
  71. * @v refcnt Containing object reference counter, or NULL
  72. */
  73. static inline void job_init ( struct job_interface *job,
  74. struct job_interface_operations *op,
  75. struct refcnt *refcnt ) {
  76. job->intf.dest = &null_job.intf;
  77. job->intf.refcnt = refcnt;
  78. job->op = op;
  79. }
  80. /**
  81. * Get job control interface from generic object communication interface
  82. *
  83. * @v intf Generic object communication interface
  84. * @ret job Job control interface
  85. */
  86. static inline __attribute__ (( always_inline )) struct job_interface *
  87. intf_to_job ( struct interface *intf ) {
  88. return container_of ( intf, struct job_interface, intf );
  89. }
  90. /**
  91. * Get reference to destination job control interface
  92. *
  93. * @v job Job control interface
  94. * @ret dest Destination interface
  95. */
  96. static inline __attribute__ (( always_inline )) struct job_interface *
  97. job_get_dest ( struct job_interface *job ) {
  98. return intf_to_job ( intf_get ( job->intf.dest ) );
  99. }
  100. /**
  101. * Drop reference to job control interface
  102. *
  103. * @v job Job control interface
  104. */
  105. static inline __attribute__ (( always_inline )) void
  106. job_put ( struct job_interface *job ) {
  107. intf_put ( &job->intf );
  108. }
  109. /**
  110. * Plug a job control interface into a new destination interface
  111. *
  112. * @v job Job control interface
  113. * @v dest New destination interface
  114. */
  115. static inline void job_plug ( struct job_interface *job,
  116. struct job_interface *dest ) {
  117. plug ( &job->intf, &dest->intf );
  118. }
  119. /**
  120. * Plug two job control interfaces together
  121. *
  122. * @v a Job control interface A
  123. * @v b Job control interface B
  124. */
  125. static inline void job_plug_plug ( struct job_interface *a,
  126. struct job_interface *b ) {
  127. plug_plug ( &a->intf, &b->intf );
  128. }
  129. /**
  130. * Unplug a job control interface
  131. *
  132. * @v job Job control interface
  133. */
  134. static inline void job_unplug ( struct job_interface *job ) {
  135. plug ( &job->intf, &null_job.intf );
  136. }
  137. /**
  138. * Stop using a job control interface
  139. *
  140. * @v job Job control interface
  141. *
  142. * After calling this method, no further messages will be received via
  143. * the interface.
  144. */
  145. static inline void job_nullify ( struct job_interface *job ) {
  146. job->op = &null_job_ops;
  147. };
  148. #endif /* _GPXE_JOB_H */