xref: /illumos-gate/usr/src/cmd/lp/cmd/lpsched/disena.c (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
24*7c478bd9Sstevel@tonic-gate 
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate #ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.9.1.4	*/
27*7c478bd9Sstevel@tonic-gate /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include "lpsched.h"
30*7c478bd9Sstevel@tonic-gate #include <time.h>
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate /**
33*7c478bd9Sstevel@tonic-gate  ** disable() - DISABLE PRINTER
34*7c478bd9Sstevel@tonic-gate  **/
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate int
disable(PSTATUS * pps,char * reason,int when)37*7c478bd9Sstevel@tonic-gate disable(PSTATUS *pps, char *reason, int when)
38*7c478bd9Sstevel@tonic-gate {
39*7c478bd9Sstevel@tonic-gate 	if (pps->status & PS_DISABLED)
40*7c478bd9Sstevel@tonic-gate 		return (-1);
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate 	else {
43*7c478bd9Sstevel@tonic-gate 		pps->status |= PS_DISABLED;
44*7c478bd9Sstevel@tonic-gate 		time (&pps->dis_date);
45*7c478bd9Sstevel@tonic-gate 		load_str (&pps->dis_reason, reason);
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate 		dump_pstatus ();
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate 		if (pps->status & PS_BUSY)
50*7c478bd9Sstevel@tonic-gate 			switch (when) {
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate 			case DISABLE_STOP:
53*7c478bd9Sstevel@tonic-gate 				/*
54*7c478bd9Sstevel@tonic-gate 				 * Stop current job, requeue.
55*7c478bd9Sstevel@tonic-gate 				 */
56*7c478bd9Sstevel@tonic-gate 				if (pps->request)
57*7c478bd9Sstevel@tonic-gate 				    pps->request->request->outcome |= RS_STOPPED;
58*7c478bd9Sstevel@tonic-gate 				terminate (pps->exec);
59*7c478bd9Sstevel@tonic-gate 				break;
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate 			case DISABLE_FINISH:
62*7c478bd9Sstevel@tonic-gate 				/*
63*7c478bd9Sstevel@tonic-gate 				 * Let current job finish.
64*7c478bd9Sstevel@tonic-gate 				 */
65*7c478bd9Sstevel@tonic-gate 				break;
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate 			case DISABLE_CANCEL:
68*7c478bd9Sstevel@tonic-gate 				/*
69*7c478bd9Sstevel@tonic-gate 				 * Cancel current job outright.
70*7c478bd9Sstevel@tonic-gate 				 */
71*7c478bd9Sstevel@tonic-gate 				if (pps->request)
72*7c478bd9Sstevel@tonic-gate 				    cancel (pps->request, 1);
73*7c478bd9Sstevel@tonic-gate 				break;
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate 			}
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate 		/*
78*7c478bd9Sstevel@tonic-gate 		 * Need we check to see if requests assigned to
79*7c478bd9Sstevel@tonic-gate 		 * this printer should be assigned elsewhere?
80*7c478bd9Sstevel@tonic-gate 		 * No, if the "validate()" routine is properly
81*7c478bd9Sstevel@tonic-gate 		 * assigning requests. If another printer is available
82*7c478bd9Sstevel@tonic-gate 		 * for printing requests (that would otherwise be)
83*7c478bd9Sstevel@tonic-gate 		 * assigned to this printer, at least one of those
84*7c478bd9Sstevel@tonic-gate 		 * requests will be assigned to that other printer,
85*7c478bd9Sstevel@tonic-gate 		 * and should be currently printing. Once it is done
86*7c478bd9Sstevel@tonic-gate 		 * printing, the queue will be examined for the next
87*7c478bd9Sstevel@tonic-gate 		 * request, and the one(s) assigned this printer will
88*7c478bd9Sstevel@tonic-gate 		 * be picked up.
89*7c478bd9Sstevel@tonic-gate 		 */
90*7c478bd9Sstevel@tonic-gate /*		(void)queue_repel (pps, 0, (qchk_fnc_type)0);	*/
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate 		return (0);
93*7c478bd9Sstevel@tonic-gate 	}
94*7c478bd9Sstevel@tonic-gate }
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate /**
97*7c478bd9Sstevel@tonic-gate  ** enable() - ENABLE PRINTER
98*7c478bd9Sstevel@tonic-gate  **/
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate int
enable(register PSTATUS * pps)101*7c478bd9Sstevel@tonic-gate enable (register PSTATUS *pps)
102*7c478bd9Sstevel@tonic-gate {
103*7c478bd9Sstevel@tonic-gate 	/*
104*7c478bd9Sstevel@tonic-gate 	 * ``Enabling a printer'' includes clearing a fault and
105*7c478bd9Sstevel@tonic-gate 	 * clearing the do-it-later flag to allow the printer
106*7c478bd9Sstevel@tonic-gate 	 * to start up again.
107*7c478bd9Sstevel@tonic-gate 	 */
108*7c478bd9Sstevel@tonic-gate 	if (!(pps->status & (PS_FAULTED|PS_DISABLED|PS_LATER)))
109*7c478bd9Sstevel@tonic-gate 		return (-1);
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate 	else {
112*7c478bd9Sstevel@tonic-gate 		pps->status &= ~(PS_FAULTED|PS_DISABLED|PS_LATER);
113*7c478bd9Sstevel@tonic-gate 		(void) time (&pps->dis_date);
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate 		dump_pstatus ();
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate 		if (pps->alert->active)
118*7c478bd9Sstevel@tonic-gate 			cancel_alert (A_PRINTER, pps);
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate 		/*
121*7c478bd9Sstevel@tonic-gate 		 * Attract the FIRST request that is waiting to
122*7c478bd9Sstevel@tonic-gate 		 * print to this printer. In this regard we're acting
123*7c478bd9Sstevel@tonic-gate 		 * like the printer just finished printing a request
124*7c478bd9Sstevel@tonic-gate 		 * and is looking for another.
125*7c478bd9Sstevel@tonic-gate 		 */
126*7c478bd9Sstevel@tonic-gate 		queue_attract (pps, qchk_waiting, 1);
127*7c478bd9Sstevel@tonic-gate 		return (0);
128*7c478bd9Sstevel@tonic-gate 	}
129*7c478bd9Sstevel@tonic-gate }
130