job.h

Go to the documentation of this file.
00001 #ifndef _GPXE_JOB_H
00002 #define _GPXE_JOB_H
00003 
00004 /** @file
00005  *
00006  * Job control interfaces
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER );
00011 
00012 #include <stddef.h>
00013 #include <gpxe/interface.h>
00014 
00015 /** Job progress */
00016 struct job_progress {
00017         /** Amount of operation completed so far
00018          *
00019          * The units for this quantity are arbitrary.  @c completed
00020          * divded by @total should give something which approximately
00021          * represents the progress through the operation.  For a
00022          * download operation, using byte counts would make sense.
00023          */
00024         unsigned long completed;
00025         /** Total operation size
00026          *
00027          * See @c completed.  A zero value means "total size unknown"
00028          * and is explcitly permitted; users should take this into
00029          * account before calculating @c completed/total.
00030          */
00031         unsigned long total;
00032 };
00033 
00034 struct job_interface;
00035 
00036 /** Job control interface operations */
00037 struct job_interface_operations {
00038         /** Job completed
00039          *
00040          * @v job               Job control interface
00041          * @v rc                Overall job status code
00042          */
00043         void ( * done ) ( struct job_interface *job, int rc );
00044         /** Abort job
00045          *
00046          * @v job               Job control interface
00047          */
00048         void ( * kill ) ( struct job_interface *job );
00049         /** Get job progress
00050          *
00051          * @v job               Job control interface
00052          * @v progress          Progress data to fill in
00053          */
00054         void ( * progress ) ( struct job_interface *job,
00055                               struct job_progress *progress );
00056 };
00057 
00058 /** A job control interface */
00059 struct job_interface {
00060         /** Generic object communication interface */
00061         struct interface intf;
00062         /** Operations for received messages */
00063         struct job_interface_operations *op;
00064 };
00065 
00066 extern struct job_interface null_job;
00067 extern struct job_interface_operations null_job_ops;
00068 
00069 extern void job_done ( struct job_interface *job, int rc );
00070 extern void job_kill ( struct job_interface *job );
00071 extern void job_progress ( struct job_interface *job,
00072                            struct job_progress *progress );
00073 
00074 extern void ignore_job_done ( struct job_interface *job, int rc );
00075 extern void ignore_job_kill ( struct job_interface *job );
00076 extern void ignore_job_progress ( struct job_interface *job,
00077                                   struct job_progress *progress );
00078 
00079 /**
00080  * Initialise a job control interface
00081  *
00082  * @v job               Job control interface
00083  * @v op                Job control interface operations
00084  * @v refcnt            Containing object reference counter, or NULL
00085  */
00086 static inline void job_init ( struct job_interface *job,
00087                               struct job_interface_operations *op,
00088                               struct refcnt *refcnt ) {
00089         job->intf.dest = &null_job.intf;
00090         job->intf.refcnt = refcnt;
00091         job->op = op;
00092 }
00093 
00094 /**
00095  * Get job control interface from generic object communication interface
00096  *
00097  * @v intf              Generic object communication interface
00098  * @ret job             Job control interface
00099  */
00100 static inline __attribute__ (( always_inline )) struct job_interface *
00101 intf_to_job ( struct interface *intf ) {
00102         return container_of ( intf, struct job_interface, intf );
00103 }
00104 
00105 /**
00106  * Get reference to destination job control interface
00107  *
00108  * @v job               Job control interface
00109  * @ret dest            Destination interface
00110  */
00111 static inline __attribute__ (( always_inline )) struct job_interface *
00112 job_get_dest ( struct job_interface *job ) {
00113         return intf_to_job ( intf_get ( job->intf.dest ) );
00114 }
00115 
00116 /**
00117  * Drop reference to job control interface
00118  *
00119  * @v job               Job control interface
00120  */
00121 static inline __attribute__ (( always_inline )) void
00122 job_put ( struct job_interface *job ) {
00123         intf_put ( &job->intf );
00124 }
00125 
00126 /**
00127  * Plug a job control interface into a new destination interface
00128  *
00129  * @v job               Job control interface
00130  * @v dest              New destination interface
00131  */
00132 static inline void job_plug ( struct job_interface *job,
00133                                struct job_interface *dest ) {
00134         plug ( &job->intf, &dest->intf );
00135 }
00136 
00137 /**
00138  * Plug two job control interfaces together
00139  *
00140  * @v a                 Job control interface A
00141  * @v b                 Job control interface B
00142  */
00143 static inline void job_plug_plug ( struct job_interface *a,
00144                                     struct job_interface *b ) {
00145         plug_plug ( &a->intf, &b->intf );
00146 }
00147 
00148 /**
00149  * Unplug a job control interface
00150  *
00151  * @v job               Job control interface
00152  */
00153 static inline void job_unplug ( struct job_interface *job ) {
00154         plug ( &job->intf, &null_job.intf );
00155 }
00156 
00157 /**
00158  * Stop using a job control interface
00159  *
00160  * @v job               Job control interface
00161  *
00162  * After calling this method, no further messages will be received via
00163  * the interface.
00164  */
00165 static inline void job_nullify ( struct job_interface *job ) {
00166         job->op = &null_job_ops;
00167 };
00168 
00169 #endif /* _GPXE_JOB_H */

Generated on Tue Apr 6 20:01:08 2010 for gPXE by  doxygen 1.5.7.1