6 * Job control interfaces
10 FILE_LICENCE ( GPL2_OR_LATER );
13 #include <gpxe/interface.h>
17 /** Amount of operation completed so far
19 * The units for this quantity are arbitrary. @c completed
20 * divded by @total should give something which approximately
21 * represents the progress through the operation. For a
22 * download operation, using byte counts would make sense.
24 unsigned long completed;
25 /** Total operation size
27 * See @c completed. A zero value means "total size unknown"
28 * and is explcitly permitted; users should take this into
29 * account before calculating @c completed/total.
36 /** Job control interface operations */
37 struct job_interface_operations {
40 * @v job Job control interface
41 * @v rc Overall job status code
43 void ( * done ) ( struct job_interface *job, int rc );
46 * @v job Job control interface
48 void ( * kill ) ( struct job_interface *job );
51 * @v job Job control interface
52 * @v progress Progress data to fill in
54 void ( * progress ) ( struct job_interface *job,
55 struct job_progress *progress );
58 /** A job control interface */
59 struct job_interface {
60 /** Generic object communication interface */
61 struct interface intf;
62 /** Operations for received messages */
63 struct job_interface_operations *op;
66 extern struct job_interface null_job;
67 extern struct job_interface_operations null_job_ops;
69 extern void job_done ( struct job_interface *job, int rc );
70 extern void job_kill ( struct job_interface *job );
72 extern void ignore_job_done ( struct job_interface *job, int rc );
73 extern void ignore_job_kill ( struct job_interface *job );
74 extern void ignore_job_progress ( struct job_interface *job,
75 struct job_progress *progress );
78 * Initialise a job control interface
80 * @v job Job control interface
81 * @v op Job control interface operations
82 * @v refcnt Containing object reference counter, or NULL
84 static inline void job_init ( struct job_interface *job,
85 struct job_interface_operations *op,
86 struct refcnt *refcnt ) {
87 job->intf.dest = &null_job.intf;
88 job->intf.refcnt = refcnt;
93 * Get job control interface from generic object communication interface
95 * @v intf Generic object communication interface
96 * @ret job Job control interface
98 static inline __attribute__ (( always_inline )) struct job_interface *
99 intf_to_job ( struct interface *intf ) {
100 return container_of ( intf, struct job_interface, intf );
104 * Get reference to destination job control interface
106 * @v job Job control interface
107 * @ret dest Destination interface
109 static inline __attribute__ (( always_inline )) struct job_interface *
110 job_get_dest ( struct job_interface *job ) {
111 return intf_to_job ( intf_get ( job->intf.dest ) );
115 * Drop reference to job control interface
117 * @v job Job control interface
119 static inline __attribute__ (( always_inline )) void
120 job_put ( struct job_interface *job ) {
121 intf_put ( &job->intf );
125 * Plug a job control interface into a new destination interface
127 * @v job Job control interface
128 * @v dest New destination interface
130 static inline void job_plug ( struct job_interface *job,
131 struct job_interface *dest ) {
132 plug ( &job->intf, &dest->intf );
136 * Plug two job control interfaces together
138 * @v a Job control interface A
139 * @v b Job control interface B
141 static inline void job_plug_plug ( struct job_interface *a,
142 struct job_interface *b ) {
143 plug_plug ( &a->intf, &b->intf );
147 * Unplug a job control interface
149 * @v job Job control interface
151 static inline void job_unplug ( struct job_interface *job ) {
152 plug ( &job->intf, &null_job.intf );
156 * Stop using a job control interface
158 * @v job Job control interface
160 * After calling this method, no further messages will be received via
163 static inline void job_nullify ( struct job_interface *job ) {
164 job->op = &null_job_ops;
167 #endif /* _GPXE_JOB_H */