00001 /* 00002 ** mouse:~ppr/src/include/pprd.h 00003 ** Copyright 1995--2004, Trinity College Computing Center. 00004 ** Written by David Chappell. 00005 ** 00006 ** Redistribution and use in source and binary forms, with or without 00007 ** modification, are permitted provided that the following conditions are met: 00008 ** 00009 ** * Redistributions of source code must retain the above copyright notice, 00010 ** this list of conditions and the following disclaimer. 00011 ** 00012 ** * Redistributions in binary form must reproduce the above copyright 00013 ** notice, this list of conditions and the following disclaimer in the 00014 ** documentation and/or other materials provided with the distribution. 00015 ** 00016 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00017 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00018 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00019 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE 00020 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00021 ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00022 ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00023 ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00024 ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00025 ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00026 ** POSSIBILITY OF SUCH DAMAGE. 00027 ** 00028 ** Last modified 4 February 2004. 00029 */ 00030 00031 /* 00032 ** Values and structures used only by pprd and ppop. Both pprd.c 00033 ** and ppop.c include this file after they include global_defines.h. 00034 ** Ppop actually only uses a few of them. Hopefully, some day it 00035 ** will not use any. 00036 */ 00037 00038 /* This you might want to change */ 00039 #define TICK_INTERVAL 5 /* seconds between calls to tick() */ 00040 #define UPGRADE_INTERVAL 20 /* number of ticks to gain one pri point */ 00041 #define RETRY_MULTIPLIER 30 /* extra seconds per retry */ 00042 #define MIN_RETRY 600 /* retry at least this often (seconds) */ 00043 #define ENGAGED_RETRY 60 /* interval to retry ``otherwise engaged'' printers */ 00044 #define MAX_ACTIVE 15 /* maximum simultainiously active printers */ 00045 #define STARVING_RETRY_INTERVAL 5 /* how often to retry starving printers */ 00046 #define ENGAGED_NAG_TIME 20 /* Engaged time to qualify as "remaining printer problem" */ 00047 00048 #define QUEUE_SIZE_INITIAL 200 /* entries allocated at startup */ 00049 #define QUEUE_SIZE_GROWBY 50 /* additional entries allocated at each overflow */ 00050 #define QUEUE_SIZE_MAX 10000 /* absolute maximum size we will attempt to allocate */ 00051 00052 /* 00053 ** These are the pprd debugging options. Change "#if 0" to "#if 1" to turn 00054 ** debugging on. 00055 ** 00056 ** Note that we use C++ comments here to disable the ones we don't want. This 00057 ** OK only because it is inside a block that is normaly excluded by the #if 0. 00058 */ 00059 #if 0 00060 #define DEBUG 1 /* define function[] strings */ 00061 //#define DEBUG_STARTUP 1 /* initialization routines */ 00062 //#define DEBUG_MAINLOOP 1 /* main loop */ 00063 //#define DEBUG_RECOVER 1 /* reloading jobs and mounted media on restart */ 00064 //#define DEBUG_NEWJOBS 1 /* receipt of new jobs */ 00065 //#define DEBUG_PRNSTART 1 /* starting of printers */ 00066 //#define DEBUG_PRNSTART_GRITTY 1 /* details of starting printers */ 00067 //#define DEBUG_PRNSTOP 1 /* analysis of pprdrv exit */ 00068 //#define DEBUG_DEQUEUE 1 /* removal from the queue */ 00069 //#define DEBUG_MEDIA 1 /* media operations */ 00070 //#define DEBUG_TICK 1 /* debug timer tick routine */ 00071 //#define DEBUG_RESPOND 1 /* launching of responders */ 00072 //#define DEBUG_PPOPINT 1 /* interface to ppop */ 00073 //#define DEBUG_ALERTS 1 /* sending of operator alerts */ 00074 //#define DEBUG_NODEID 1 /* allocating and deallocating node id numbers */ 00075 #define DEBUG_REMOTE 1 /* sending of jobs to remote systems */ 00076 #define DEBUG_QUESTIONS 1 /* sending questions to job submitters */ 00077 #endif 00078 00079 /* 00080 ** The name of the debugging output file. Even if all of the above 00081 ** debugging options are turned off, some output will still be sent 00082 ** to this file. 00083 */ 00084 #define PPRD_LOGFILE LOGDIR"/pprd" 00085 00086 /*============ User: don't change anything below this line. ============*/ 00087 00088 /* A few global variables: */ 00089 extern gu_boolean lockfile_created; 00090 00091 /* A few critical declarations: */ 00092 void fatal(int exval, const char string[], ...) 00093 #ifdef __GNUC__ 00094 __attribute__ (( noreturn, format (printf, 2, 3) )) 00095 #endif 00096 ; 00097 void debug(const char format[],...) 00098 #ifdef __GNUC__ 00099 __attribute__ (( format (printf, 1, 2) )) 00100 #endif 00101 ; 00102 void error(const char *string, ... ) 00103 #ifdef __GNUC__ 00104 __attribute__ (( format (printf, 1, 2) )) 00105 #endif 00106 ; 00107 00108 /* 00109 ** Values which pprd uses as the first argument to fatal(). 00110 ** Ordinarily it uses ERROR_DIE, but if the value is 00111 ** ERROR_DUMPCORE, then fatal() tries to prevoke a core 00112 ** dump. This feature is available for some debugging 00113 ** purpose which I cannot now remember. 00114 */ 00115 #define ERROR_DIE 0 00116 #define ERROR_DUMPCORE 100 00117 00118 /* structure to describe a printer */ 00119 struct Printer 00120 { 00121 char name[MAX_DESTNAME+1]; /* name of the printer */ 00122 int alert_interval; /* every this many retries */ 00123 char *alert_method; /* means of communicating with operator */ 00124 char *alert_address; /* address of operator */ 00125 gu_boolean protect; /* TRUE if "Charge:" line in conf file */ 00126 int charge_per_duplex; /* per-sheet charge */ 00127 int charge_per_simplex; /* half-sheet charge */ 00128 gu_boolean accepting; /* TRUE if is accepting as destination */ 00129 int nbins; /* number of bins */ 00130 int bins[MAX_BINS]; /* binname id of each bin */ 00131 gu_boolean AutoSelect_exists; /* TRUE if any bin is named "AutoSelect" */ 00132 int media[MAX_BINS]; /* media id of media in each bin */ 00133 int previous_status; /* saved previous status */ 00134 int status; /* idle, disabled, etc */ 00135 gu_boolean cancel_job; /* cancel the job at pprdrv exit */ 00136 gu_boolean hold_job; /* hold the job at pprdrv exit */ 00137 int next_error_retry; /* number of next retry */ 00138 int next_engaged_retry; /* number of times otherwise engaged or off-line */ 00139 int countdown; /* seconds till next retry */ 00140 pid_t pid; /* pid of process driving the printer */ 00141 int jobdestid; /* dest id of the job we are printing */ 00142 int id; /* queue id of job being printed */ 00143 int subid; /* queue subid of job being printed */ 00144 int homenode_id; /* id number of node which submitted the job */ 00145 pid_t ppop_pid; /* send SIGUSR1 to this process when stopt */ 00146 } ; 00147 00148 /* a group */ 00149 struct Group 00150 { 00151 char name[MAX_DESTNAME+1]; /* name of group */ 00152 int printers[MAX_GROUPSIZE]; /* printer id's of members */ 00153 int members; /* number of members */ 00154 int last; /* member offset of member last used */ 00155 gu_boolean accepting; /* TRUE if accepting new jobs */ 00156 gu_boolean held; /* TRUE if jobs for group held */ 00157 gu_boolean rotate; /* TRUE if we should use in rotation */ 00158 gu_boolean protect; /* TRUE if we should restrict use */ 00159 gu_boolean deleted; /* TRUE if group has been deleted */ 00160 } ; 00161 00162 /* A queue entry as stored by pprd and passed back to ppop. 00163 Notice that this is shorter than struct QFileEntry. */ 00164 struct QEntry 00165 { 00166 SHORT_INT destnode_id; /* destination node by key number */ 00167 SHORT_INT destid; /* destination key number */ 00168 SHORT_INT id; /* queue id */ 00169 SHORT_INT subid; /* fractional queue id */ 00170 SHORT_INT homenode_id; /* id of node job come from */ 00171 00172 SHORT_INT status; /* printer id if printing, < 0 for other status */ 00173 unsigned short int flags; /* --keep, responding, etc. */ 00174 time_t resend_message_at; /* time at which to retry responder to questioner */ 00175 00176 SHORT_INT priority; /* priority number (0=highest, 39=lowest) */ 00177 unsigned char never; /* bitmap of group member which can't print */ 00178 unsigned char notnow; /* bitmap of group members without media mntd */ 00179 SHORT_INT media[MAX_DOCMEDIA]; /* list of id numbers of media types req. */ 00180 SHORT_INT pass; /* number of current pass thru printers in group */ 00181 } ; 00182 00183 /* 00184 ** Printer status values 00185 */ 00186 #define PRNSTATUS_IDLE 0 /* idle but ready to print */ 00187 #define PRNSTATUS_PRINTING 1 /* printing right now */ 00188 #define PRNSTATUS_CANCELING 2 /* canceling a job */ 00189 #define PRNSTATUS_SEIZING 3 /* stopping printing current job and holding it */ 00190 #define PRNSTATUS_FAULT 4 /* waiting for auto retry */ 00191 #define PRNSTATUS_ENGAGED 5 /* printer is printing for another computer */ 00192 #define PRNSTATUS_STARVED 6 /* starved for system resources */ 00193 #define PRNSTATUS_STOPT 7 /* stopt by user */ 00194 #define PRNSTATUS_STOPPING 8 /* will go to PRNSTATUS_STOPT at job end */ 00195 #define PRNSTATUS_HALTING 9 /* pprdrv being killed */ 00196 #define PRNSTATUS_DELETED 10 /* printer has been deleted */ 00197 #define PRNSTATUS_DELIBERATELY_DOWN 7 /* 1st non-printing value (stopt) */ 00198 00199 /* 00200 ** Structures for response to the "f" command. 00201 ** Used by pprd and ppop. These will have to go 00202 ** because the format is not network portable. 00203 */ 00204 struct fcommand1 00205 { 00206 int nbins; /* number of bins in this printer */ 00207 char prnname[MAX_DESTNAME+1]; /* name of the printer */ 00208 } ; 00209 struct fcommand2 00210 { 00211 char bin[MAX_BINNAME+1]; /* name of this bin */ 00212 char media[MAX_MEDIANAME+1]; /* name of mounted media */ 00213 } ; 00214 00215 /* 00216 ** Debugging macros. 00217 */ 00218 #ifdef DEBUG 00219 #define FUNCTION4DEBUG(a) const char function[] = a ; 00220 #else 00221 #define FUNCTION4DEBUG(a) 00222 #endif 00223 00224 #ifdef DEBUG_STARTUP 00225 #define DODEBUG_STARTUP(a) debug a 00226 #else 00227 #define DODEBUG_STARTUP(a) 00228 #endif 00229 00230 #ifdef DEBUG_MAINLOOP 00231 #define DODEBUG_MAINLOOP(a) debug a 00232 #else 00233 #define DODEBUG_MAINLOOP(a) 00234 #endif 00235 00236 #ifdef DEBUG_RECOVER 00237 #define DODEBUG_RECOVER(a) debug a 00238 #else 00239 #define DODEBUG_RECOVER(a) 00240 #endif 00241 00242 #ifdef DEBUG_NEWJOB 00243 #define DODEBUG_NEWJOB(a) debug a 00244 #else 00245 #define DODEBUG_NEWJOB(a) 00246 #endif 00247 00248 #ifdef DEBUG_DEQUEUE 00249 #define DODEBUG_DEQUEUE(a) debug a 00250 #else 00251 #define DODEBUG_DEQUEUE(a) 00252 #endif 00253 00254 #ifdef DEBUG_MEDIA 00255 #define DODEBUG_MEDIA(a) debug a 00256 #else 00257 #define DODEBUG_MEDIA(a) 00258 #endif 00259 00260 #ifdef DEBUG_PROGINIT 00261 #define DODEBUG_PROGINIT(a) debug a 00262 #else 00263 #define DODEBUG_PROGINIT(a) 00264 #endif 00265 00266 #ifdef DEBUG_RESPOND 00267 #define DODEBUG_RESPOND(a) debug a 00268 #else 00269 #define DODEBUG_RESPOND(a) 00270 #endif 00271 00272 #ifdef DEBUG_ALERTS 00273 #define DODEBUG_ALERTS(a) debug a 00274 #else 00275 #define DODEBUG_ALERTS(a) 00276 #endif 00277 00278 #ifdef DEBUG_PPOPINT 00279 #define DODEBUG_PPOPINT(a) debug a 00280 #else 00281 #define DODEBUG_PPOPINT(a) 00282 #endif 00283 00284 #ifdef DEBUG_PRNSTART 00285 #define DODEBUG_PRNSTART(a) debug a 00286 #else 00287 #define DODEBUG_PRNSTART(a) 00288 #endif 00289 00290 #ifdef DEBUG_PRNSTOP 00291 #define DODEBUG_PRNSTOP(a) debug a 00292 #else 00293 #define DODEBUG_PRNSTOP(a) 00294 #endif 00295 00296 #ifdef DEBUG_NOTNOW 00297 #define DODEBUG_NOTNOW(a) debug a 00298 #else 00299 #define DODEBUG_NOTNOW(a) 00300 #endif 00301 00302 #ifdef DEBUG_NEWJOBS 00303 #define DODEBUG_NEWJOBS(a) debug a 00304 #else 00305 #define DODEBUG_NEWJOBS(a) 00306 #endif 00307 00308 #ifdef DEBUG_TICK 00309 #define DODEBUG_TICK(a) debug a 00310 #else 00311 #define DODEBUG_TICK(a) 00312 #endif 00313 00314 #ifdef DEBUG_NODEID 00315 #define DODEBUG_NODEID(a) debug a 00316 #else 00317 #define DODEBUG_NODEID(a) 00318 #endif 00319 00320 #ifdef DEBUG_REMOTE 00321 #define DODEBUG_REMOTE(a) debug a 00322 #else 00323 #define DODEBUG_REMOTE(a) 00324 #endif 00325 00326 #ifdef DEBUG_QUESTIONS 00327 #define DODEBUG_QUESTIONS(a) debug a 00328 #else 00329 #define DODEBUG_QUESTIONS(a) 00330 #endif 00331 00332 /* end of file */