6 * Job control interfaces
11 #include <gpxe/interface.h>
15 /** Amount of operation completed so far
17 * The units for this quantity are arbitrary. @c completed
18 * divded by @total should give something which approximately
19 * represents the progress through the operation. For a
20 * download operation, using byte counts would make sense.
22 unsigned long completed;
23 /** Total operation size
25 * See @c completed. A zero value means "total size unknown"
26 * and is explcitly permitted; users should take this into
27 * account before calculating @c completed/total.
34 /** Job control interface operations */
35 struct job_interface_operations {
38 * @v job Job control interface
39 * @v rc Overall job status code
41 void ( * done ) ( struct job_interface *job, int rc );
44 * @v job Job control interface
46 void ( * kill ) ( struct job_interface *job );
49 * @v job Job control interface
50 * @v progress Progress data to fill in
52 void ( * progress ) ( struct job_interface *job,
53 struct job_progress *progress );
56 /** A job control interface */
57 struct job_interface {
58 /** Generic object communication interface */
59 struct interface intf;
60 /** Operations for received messages */
61 struct job_interface_operations *op;
64 extern struct job_interface null_job;
65 extern struct job_interface_operations null_job_ops;
67 extern void done ( struct job_interface *job, int rc );
69 extern void ignore_done ( struct job_interface *job, int rc );
70 extern void ignore_kill ( struct job_interface *job );
71 extern void ignore_progress ( struct job_interface *job,
72 struct job_progress *progress );
75 * Initialise a job control interface
77 * @v job Job control interface
78 * @v op Job control interface operations
79 * @v refcnt Job control interface reference counting method
81 static inline void job_init ( struct job_interface *job,
82 struct job_interface_operations *op,
83 void ( * refcnt ) ( struct interface *intf,
85 job->intf.dest = &null_job.intf;
86 job->intf.refcnt = refcnt;
91 * Get job control interface from generic object communication interface
93 * @v intf Generic object communication interface
94 * @ret job Job control interface
96 static inline struct job_interface *
97 intf_to_job ( struct interface *intf ) {
98 return container_of ( intf, struct job_interface, intf );
102 * Get destination job control interface
104 * @v job Job control interface
105 * @ret dest Destination interface
107 static inline struct job_interface *
108 job_dest ( struct job_interface *job ) {
109 return intf_to_job ( job->intf.dest );
113 * Stop using a job control interface
115 * @v job Job control interface
117 * After calling this method, no further messages will be received via
120 static inline void job_nullify ( struct job_interface *job ) {
121 job->op = &null_job_ops;
124 #endif /* _GPXE_JOB_H */