Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

job.h 4.1KB

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