Home | History | Annotate | Download | only in core
      1 /*
      2  * Copyright (C) 2007 Michael Brown <mbrown (at) fensystems.co.uk>.
      3  *
      4  * This program is free software; you can redistribute it and/or
      5  * modify it under the terms of the GNU General Public License as
      6  * published by the Free Software Foundation; either version 2 of the
      7  * License, or any later version.
      8  *
      9  * This program is distributed in the hope that it will be useful, but
     10  * WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12  * General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU General Public License
     15  * along with this program; if not, write to the Free Software
     16  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     17  */
     18 
     19 FILE_LICENCE ( GPL2_OR_LATER );
     20 
     21 #include <string.h>
     22 #include <errno.h>
     23 #include <gpxe/job.h>
     24 
     25 /** @file
     26  *
     27  * Job control interfaces
     28  *
     29  */
     30 
     31 void job_done ( struct job_interface *job, int rc ) {
     32 	struct job_interface *dest = job_get_dest ( job );
     33 
     34 	job_unplug ( job );
     35 	dest->op->done ( dest, rc );
     36 	job_put ( dest );
     37 }
     38 
     39 void job_kill ( struct job_interface *job ) {
     40 	struct job_interface *dest = job_get_dest ( job );
     41 
     42 	job_unplug ( job );
     43 	dest->op->kill ( dest );
     44 	job_put ( dest );
     45 }
     46 
     47 void job_progress ( struct job_interface *job,
     48 		    struct job_progress *progress ) {
     49 	struct job_interface *dest = job_get_dest ( job );
     50 
     51 	dest->op->progress ( dest, progress );
     52 	job_put ( dest );
     53 }
     54 
     55 /****************************************************************************
     56  *
     57  * Helper methods
     58  *
     59  * These functions are designed to be used as methods in the
     60  * job_interface_operations table.
     61  *
     62  */
     63 
     64 void ignore_job_done ( struct job_interface *job __unused, int rc __unused ) {
     65 	/* Nothing to do */
     66 }
     67 
     68 void ignore_job_kill ( struct job_interface *job __unused ) {
     69 	/* Nothing to do */
     70 }
     71 
     72 void ignore_job_progress ( struct job_interface *job __unused,
     73 			   struct job_progress *progress ) {
     74 	memset ( progress, 0, sizeof ( *progress ) );
     75 }
     76 
     77 /** Null job control interface operations */
     78 struct job_interface_operations null_job_ops = {
     79 	.done		= ignore_job_done,
     80 	.kill		= ignore_job_kill,
     81 	.progress	= ignore_job_progress,
     82 };
     83 
     84 /**
     85  * Null job control interface
     86  *
     87  * This is the interface to which job control interfaces are connected
     88  * when unplugged.  It will never generate messages, and will silently
     89  * absorb all received messages.
     90  */
     91 struct job_interface null_job = {
     92 	.intf = {
     93 		.dest = &null_job.intf,
     94 		.refcnt = NULL,
     95 	},
     96 	.op = &null_job_ops,
     97 };
     98