monojob.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020
00021 #include <string.h>
00022 #include <stdio.h>
00023 #include <errno.h>
00024 #include <gpxe/process.h>
00025 #include <console.h>
00026 #include <gpxe/keys.h>
00027 #include <gpxe/job.h>
00028 #include <gpxe/monojob.h>
00029 #include <gpxe/timer.h>
00030
00031
00032
00033
00034
00035
00036
00037 static int monojob_rc;
00038
00039 static void monojob_done ( struct job_interface *job __unused, int rc ) {
00040 monojob_rc = rc;
00041 }
00042
00043
00044 static struct job_interface_operations monojob_operations = {
00045 .done = monojob_done,
00046 .kill = ignore_job_kill,
00047 .progress = ignore_job_progress,
00048 };
00049
00050
00051 struct job_interface monojob = {
00052 .intf = {
00053 .dest = &null_job.intf,
00054 .refcnt = NULL,
00055 },
00056 .op = &monojob_operations,
00057 };
00058
00059
00060
00061
00062
00063
00064
00065 int monojob_wait ( const char *string ) {
00066 int key;
00067 int rc;
00068 unsigned long last_progress_dot;
00069 unsigned long elapsed;
00070
00071 printf ( "%s.", string );
00072 monojob_rc = -EINPROGRESS;
00073 last_progress_dot = currticks();
00074 while ( monojob_rc == -EINPROGRESS ) {
00075 step();
00076 if ( iskey() ) {
00077 key = getchar();
00078 switch ( key ) {
00079 case CTRL_C:
00080 job_kill ( &monojob );
00081 rc = -ECANCELED;
00082 goto done;
00083 default:
00084 break;
00085 }
00086 }
00087 elapsed = ( currticks() - last_progress_dot );
00088 if ( elapsed >= TICKS_PER_SEC ) {
00089 printf ( "." );
00090 last_progress_dot = currticks();
00091 }
00092 }
00093 rc = monojob_rc;
00094
00095 done:
00096 job_done ( &monojob, rc );
00097 if ( rc ) {
00098 printf ( " %s\n", strerror ( rc ) );
00099 } else {
00100 printf ( " ok\n" );
00101 }
00102 return rc;
00103 }