1*355b4669Sjacobs /*
2*355b4669Sjacobs  * CDDL HEADER START
3*355b4669Sjacobs  *
4*355b4669Sjacobs  * The contents of this file are subject to the terms of the
5*355b4669Sjacobs  * Common Development and Distribution License (the "License").
6*355b4669Sjacobs  * You may not use this file except in compliance with the License.
7*355b4669Sjacobs  *
8*355b4669Sjacobs  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*355b4669Sjacobs  * or http://www.opensolaris.org/os/licensing.
10*355b4669Sjacobs  * See the License for the specific language governing permissions
11*355b4669Sjacobs  * and limitations under the License.
12*355b4669Sjacobs  *
13*355b4669Sjacobs  * When distributing Covered Code, include this CDDL HEADER in each
14*355b4669Sjacobs  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*355b4669Sjacobs  * If applicable, add the following below this CDDL HEADER, with the
16*355b4669Sjacobs  * fields enclosed by brackets "[]" replaced with your own identifying
17*355b4669Sjacobs  * information: Portions Copyright [yyyy] [name of copyright owner]
18*355b4669Sjacobs  *
19*355b4669Sjacobs  * CDDL HEADER END
20*355b4669Sjacobs  */
21*355b4669Sjacobs 
22*355b4669Sjacobs /*
23*355b4669Sjacobs  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24*355b4669Sjacobs  * Use is subject to license terms.
25*355b4669Sjacobs  *
26*355b4669Sjacobs  */
27*355b4669Sjacobs 
28*355b4669Sjacobs /* $Id: job.c 146 2006-03-24 00:26:54Z njacobs $ */
29*355b4669Sjacobs 
30*355b4669Sjacobs /*LINTLIBRARY*/
31*355b4669Sjacobs 
32*355b4669Sjacobs #include <stdlib.h>
33*355b4669Sjacobs #include <papi_impl.h>
34*355b4669Sjacobs 
35*355b4669Sjacobs void
papiJobFree(papi_job_t job)36*355b4669Sjacobs papiJobFree(papi_job_t job)
37*355b4669Sjacobs {
38*355b4669Sjacobs 	job_t *tmp = (job_t *)job;
39*355b4669Sjacobs 
40*355b4669Sjacobs 	if (tmp != NULL) {
41*355b4669Sjacobs 		void (*f)();
42*355b4669Sjacobs 
43*355b4669Sjacobs 		f = (void (*)())psm_sym(tmp->svc, "papiJobFree");
44*355b4669Sjacobs 		if (f != NULL)
45*355b4669Sjacobs 			f(tmp->job);
46*355b4669Sjacobs 		free(tmp);
47*355b4669Sjacobs 	}
48*355b4669Sjacobs }
49*355b4669Sjacobs 
50*355b4669Sjacobs void
papiJobListFree(papi_job_t * jobs)51*355b4669Sjacobs papiJobListFree(papi_job_t *jobs)
52*355b4669Sjacobs {
53*355b4669Sjacobs 	if (jobs != NULL) {
54*355b4669Sjacobs 		int i;
55*355b4669Sjacobs 
56*355b4669Sjacobs 		for (i = 0; jobs[i] != NULL; i++)
57*355b4669Sjacobs 			papiJobFree(jobs[i]);
58*355b4669Sjacobs 		free(jobs);
59*355b4669Sjacobs 	}
60*355b4669Sjacobs }
61*355b4669Sjacobs 
62*355b4669Sjacobs papi_attribute_t **
papiJobGetAttributeList(papi_job_t job)63*355b4669Sjacobs papiJobGetAttributeList(papi_job_t job)
64*355b4669Sjacobs {
65*355b4669Sjacobs 	papi_attribute_t **result = NULL;
66*355b4669Sjacobs 	job_t *j = job;
67*355b4669Sjacobs 
68*355b4669Sjacobs 	if (job != NULL) {
69*355b4669Sjacobs 		papi_attribute_t **(*f)();
70*355b4669Sjacobs 
71*355b4669Sjacobs 		f = (papi_attribute_t **(*)())psm_sym(j->svc,
72*355b4669Sjacobs 						"papiJobGetAttributeList");
73*355b4669Sjacobs 		if (f != NULL)
74*355b4669Sjacobs 			result = f(j->job);
75*355b4669Sjacobs 	}
76*355b4669Sjacobs 
77*355b4669Sjacobs 	return (result);
78*355b4669Sjacobs }
79*355b4669Sjacobs 
80*355b4669Sjacobs char *
papiJobGetPrinterName(papi_job_t job)81*355b4669Sjacobs papiJobGetPrinterName(papi_job_t job)
82*355b4669Sjacobs {
83*355b4669Sjacobs 	char *result = NULL;
84*355b4669Sjacobs 	job_t *j = job;
85*355b4669Sjacobs 
86*355b4669Sjacobs 	if (job != NULL) {
87*355b4669Sjacobs 		char *(*f)();
88*355b4669Sjacobs 
89*355b4669Sjacobs 		f = (char *(*)())psm_sym(j->svc, "papiJobGetPrinterName");
90*355b4669Sjacobs 		if (f != NULL)
91*355b4669Sjacobs 			result = f(j->job);
92*355b4669Sjacobs 	}
93*355b4669Sjacobs 
94*355b4669Sjacobs 	return (result);
95*355b4669Sjacobs }
96*355b4669Sjacobs 
97*355b4669Sjacobs int32_t
papiJobGetId(papi_job_t job)98*355b4669Sjacobs papiJobGetId(papi_job_t job)
99*355b4669Sjacobs {
100*355b4669Sjacobs 	int32_t result = -1;
101*355b4669Sjacobs 	job_t *j = job;
102*355b4669Sjacobs 
103*355b4669Sjacobs 	if (job != NULL) {
104*355b4669Sjacobs 		int32_t (*f)();
105*355b4669Sjacobs 
106*355b4669Sjacobs 		f = (int32_t (*)())psm_sym(j->svc, "papiJobGetId");
107*355b4669Sjacobs 		if (f != NULL)
108*355b4669Sjacobs 			result = f(j->job);
109*355b4669Sjacobs 	}
110*355b4669Sjacobs 
111*355b4669Sjacobs 	return (result);
112*355b4669Sjacobs }
113*355b4669Sjacobs 
114*355b4669Sjacobs papi_job_ticket_t *
papiJobGetJobTicket(papi_job_t job)115*355b4669Sjacobs papiJobGetJobTicket(papi_job_t job)
116*355b4669Sjacobs {
117*355b4669Sjacobs 	papi_job_ticket_t *result = NULL;
118*355b4669Sjacobs 	job_t *j = job;
119*355b4669Sjacobs 
120*355b4669Sjacobs 	if (job != NULL) {
121*355b4669Sjacobs 		papi_job_ticket_t *(*f)();
122*355b4669Sjacobs 
123*355b4669Sjacobs 		f = (papi_job_ticket_t *(*)())psm_sym(j->svc,
124*355b4669Sjacobs 						"papiJobGetJobTicket");
125*355b4669Sjacobs 		if (f != NULL)
126*355b4669Sjacobs 			result = f(j->job);
127*355b4669Sjacobs 	}
128*355b4669Sjacobs 
129*355b4669Sjacobs 	return (result);
130*355b4669Sjacobs }
131*355b4669Sjacobs 
132*355b4669Sjacobs /* common support for papiJob{Submit|SubmitByReference|Validate} */
133*355b4669Sjacobs static papi_status_t
_papi_job_submit_reference_or_validate(papi_service_t handle,char * printer,papi_attribute_t ** job_attributes,papi_job_ticket_t * job_ticket,char ** files,papi_job_t * job,char * function)134*355b4669Sjacobs _papi_job_submit_reference_or_validate(papi_service_t handle, char *printer,
135*355b4669Sjacobs 		papi_attribute_t **job_attributes,
136*355b4669Sjacobs 		papi_job_ticket_t *job_ticket, char **files, papi_job_t *job,
137*355b4669Sjacobs 		char *function)
138*355b4669Sjacobs {
139*355b4669Sjacobs 	papi_status_t result = PAPI_INTERNAL_ERROR;
140*355b4669Sjacobs 	service_t *svc = handle;
141*355b4669Sjacobs 	job_t *j = NULL;
142*355b4669Sjacobs 	papi_status_t (*f)();
143*355b4669Sjacobs 
144*355b4669Sjacobs 	if ((svc == NULL) || (printer == NULL) || (files == NULL) ||
145*355b4669Sjacobs 	    (job == NULL))
146*355b4669Sjacobs 		return (PAPI_BAD_ARGUMENT);
147*355b4669Sjacobs 
148*355b4669Sjacobs 	if ((result = service_connect(svc, printer)) != PAPI_OK)
149*355b4669Sjacobs 		return (result);
150*355b4669Sjacobs 
151*355b4669Sjacobs 	if ((*job = j = calloc(1, sizeof (*j))) == NULL)
152*355b4669Sjacobs 		return (PAPI_TEMPORARY_ERROR);
153*355b4669Sjacobs 
154*355b4669Sjacobs 	j->svc = svc;
155*355b4669Sjacobs 	f = (papi_status_t (*)())psm_sym(j->svc, function);
156*355b4669Sjacobs 	if (f != NULL)
157*355b4669Sjacobs 		result = f(svc->svc_handle, svc->name, job_attributes,
158*355b4669Sjacobs 				job_ticket, files, &j->job);
159*355b4669Sjacobs 
160*355b4669Sjacobs 	return (result);
161*355b4669Sjacobs }
162*355b4669Sjacobs 
163*355b4669Sjacobs papi_status_t
papiJobSubmit(papi_service_t handle,char * printer,papi_attribute_t ** job_attributes,papi_job_ticket_t * job_ticket,char ** files,papi_job_t * job)164*355b4669Sjacobs papiJobSubmit(papi_service_t handle, char *printer,
165*355b4669Sjacobs 		papi_attribute_t **job_attributes,
166*355b4669Sjacobs 		papi_job_ticket_t *job_ticket, char **files, papi_job_t *job)
167*355b4669Sjacobs {
168*355b4669Sjacobs 	return (_papi_job_submit_reference_or_validate(handle, printer,
169*355b4669Sjacobs 				job_attributes, job_ticket, files, job,
170*355b4669Sjacobs 				"papiJobSubmit"));
171*355b4669Sjacobs }
172*355b4669Sjacobs 
173*355b4669Sjacobs papi_status_t
papiJobSubmitByReference(papi_service_t handle,char * printer,papi_attribute_t ** job_attributes,papi_job_ticket_t * job_ticket,char ** files,papi_job_t * job)174*355b4669Sjacobs papiJobSubmitByReference(papi_service_t handle, char *printer,
175*355b4669Sjacobs 		papi_attribute_t **job_attributes,
176*355b4669Sjacobs 		papi_job_ticket_t *job_ticket, char **files, papi_job_t *job)
177*355b4669Sjacobs {
178*355b4669Sjacobs 	return (_papi_job_submit_reference_or_validate(handle, printer,
179*355b4669Sjacobs 				job_attributes, job_ticket, files, job,
180*355b4669Sjacobs 				"papiJobSubmitByReference"));
181*355b4669Sjacobs }
182*355b4669Sjacobs 
183*355b4669Sjacobs papi_status_t
papiJobValidate(papi_service_t handle,char * printer,papi_attribute_t ** job_attributes,papi_job_ticket_t * job_ticket,char ** files,papi_job_t * job)184*355b4669Sjacobs papiJobValidate(papi_service_t handle, char *printer,
185*355b4669Sjacobs 		papi_attribute_t **job_attributes,
186*355b4669Sjacobs 		papi_job_ticket_t *job_ticket, char **files, papi_job_t *job)
187*355b4669Sjacobs {
188*355b4669Sjacobs 	return (_papi_job_submit_reference_or_validate(handle, printer,
189*355b4669Sjacobs 				job_attributes, job_ticket, files, job,
190*355b4669Sjacobs 				"papiJobValidate"));
191*355b4669Sjacobs }
192*355b4669Sjacobs 
193*355b4669Sjacobs papi_status_t
papiJobStreamOpen(papi_service_t handle,char * printer,papi_attribute_t ** job_attributes,papi_job_ticket_t * job_ticket,papi_stream_t * stream)194*355b4669Sjacobs papiJobStreamOpen(papi_service_t handle, char *printer,
195*355b4669Sjacobs 		papi_attribute_t **job_attributes,
196*355b4669Sjacobs 		papi_job_ticket_t *job_ticket, papi_stream_t *stream)
197*355b4669Sjacobs {
198*355b4669Sjacobs 	papi_status_t result = PAPI_INTERNAL_ERROR;
199*355b4669Sjacobs 	service_t *svc = handle;
200*355b4669Sjacobs 	papi_status_t (*f)();
201*355b4669Sjacobs 
202*355b4669Sjacobs 	if ((svc == NULL) || (printer == NULL) || (stream == NULL))
203*355b4669Sjacobs 		return (PAPI_BAD_ARGUMENT);
204*355b4669Sjacobs 
205*355b4669Sjacobs 	if ((result = service_connect(svc, printer)) != PAPI_OK)
206*355b4669Sjacobs 		return (result);
207*355b4669Sjacobs 
208*355b4669Sjacobs 	f = (papi_status_t (*)())psm_sym(svc, "papiJobStreamOpen");
209*355b4669Sjacobs 	if (f != NULL)
210*355b4669Sjacobs 		result = f(svc->svc_handle, svc->name, job_attributes,
211*355b4669Sjacobs 				job_ticket, stream);
212*355b4669Sjacobs 
213*355b4669Sjacobs 	return (result);
214*355b4669Sjacobs }
215*355b4669Sjacobs 
216*355b4669Sjacobs papi_status_t
papiJobStreamWrite(papi_service_t handle,papi_stream_t stream,void * buffer,size_t buflen)217*355b4669Sjacobs papiJobStreamWrite(papi_service_t handle,
218*355b4669Sjacobs 		papi_stream_t stream, void *buffer, size_t buflen)
219*355b4669Sjacobs {
220*355b4669Sjacobs 	papi_status_t result = PAPI_INTERNAL_ERROR;
221*355b4669Sjacobs 	service_t *svc = handle;
222*355b4669Sjacobs 	papi_status_t (*f)();
223*355b4669Sjacobs 
224*355b4669Sjacobs 	if ((svc == NULL) || (stream == NULL) || (buffer == NULL) ||
225*355b4669Sjacobs 	    (buflen == 0))
226*355b4669Sjacobs 		return (PAPI_BAD_ARGUMENT);
227*355b4669Sjacobs 
228*355b4669Sjacobs 	f = (papi_status_t (*)())psm_sym(svc, "papiJobStreamWrite");
229*355b4669Sjacobs 	if (f != NULL)
230*355b4669Sjacobs 		result = f(svc->svc_handle, stream, buffer, buflen);
231*355b4669Sjacobs 
232*355b4669Sjacobs 	return (result);
233*355b4669Sjacobs }
234*355b4669Sjacobs 
235*355b4669Sjacobs papi_status_t
papiJobStreamClose(papi_service_t handle,papi_stream_t stream,papi_job_t * job)236*355b4669Sjacobs papiJobStreamClose(papi_service_t handle, papi_stream_t stream, papi_job_t *job)
237*355b4669Sjacobs {
238*355b4669Sjacobs 	papi_status_t result = PAPI_INTERNAL_ERROR;
239*355b4669Sjacobs 	service_t *svc = handle;
240*355b4669Sjacobs 	job_t *j = NULL;
241*355b4669Sjacobs 	papi_status_t (*f)();
242*355b4669Sjacobs 
243*355b4669Sjacobs 	if ((svc == NULL) || (stream == NULL) || (job == NULL))
244*355b4669Sjacobs 		return (PAPI_BAD_ARGUMENT);
245*355b4669Sjacobs 
246*355b4669Sjacobs 	if ((*job = j = calloc(1, sizeof (*j))) == NULL)
247*355b4669Sjacobs 		return (PAPI_TEMPORARY_ERROR);
248*355b4669Sjacobs 
249*355b4669Sjacobs 	j->svc = svc;
250*355b4669Sjacobs 	f = (papi_status_t (*)())psm_sym(j->svc, "papiJobStreamClose");
251*355b4669Sjacobs 	if (f != NULL)
252*355b4669Sjacobs 		result = f(svc->svc_handle, stream, &j->job);
253*355b4669Sjacobs 
254*355b4669Sjacobs 	return (result);
255*355b4669Sjacobs }
256*355b4669Sjacobs 
257*355b4669Sjacobs papi_status_t
papiJobQuery(papi_service_t handle,char * printer,int32_t job_id,char ** requested_attrs,papi_job_t * job)258*355b4669Sjacobs papiJobQuery(papi_service_t handle, char *printer, int32_t job_id,
259*355b4669Sjacobs 		char **requested_attrs, papi_job_t *job)
260*355b4669Sjacobs {
261*355b4669Sjacobs 	papi_status_t result = PAPI_INTERNAL_ERROR;
262*355b4669Sjacobs 	service_t *svc = handle;
263*355b4669Sjacobs 	job_t *j = NULL;
264*355b4669Sjacobs 	papi_status_t (*f)();
265*355b4669Sjacobs 
266*355b4669Sjacobs 	if ((svc == NULL) || (printer == NULL))
267*355b4669Sjacobs 		return (PAPI_BAD_ARGUMENT);
268*355b4669Sjacobs 
269*355b4669Sjacobs 	if ((result = service_connect(svc, printer)) != PAPI_OK)
270*355b4669Sjacobs 		return (result);
271*355b4669Sjacobs 
272*355b4669Sjacobs 	if ((*job = j = calloc(1, sizeof (*j))) == NULL)
273*355b4669Sjacobs 		return (PAPI_TEMPORARY_ERROR);
274*355b4669Sjacobs 
275*355b4669Sjacobs 	j->svc = svc;
276*355b4669Sjacobs 	f = (papi_status_t (*)())psm_sym(j->svc, "papiJobQuery");
277*355b4669Sjacobs 	if (f != NULL)
278*355b4669Sjacobs 		result = f(svc->svc_handle, svc->name, job_id,
279*355b4669Sjacobs 				requested_attrs, &j->job);
280*355b4669Sjacobs 
281*355b4669Sjacobs 	return (result);
282*355b4669Sjacobs }
283*355b4669Sjacobs 
284*355b4669Sjacobs papi_status_t
papiJobMove(papi_service_t handle,char * printer,int32_t job_id,char * destination)285*355b4669Sjacobs papiJobMove(papi_service_t handle, char *printer, int32_t job_id,
286*355b4669Sjacobs 		char *destination)
287*355b4669Sjacobs {
288*355b4669Sjacobs 	papi_status_t result = PAPI_INTERNAL_ERROR;
289*355b4669Sjacobs 	service_t *svc = handle;
290*355b4669Sjacobs 	papi_status_t (*f)();
291*355b4669Sjacobs 
292*355b4669Sjacobs 	if ((svc == NULL) || (printer == NULL) || (job_id < 0))
293*355b4669Sjacobs 		return (PAPI_BAD_ARGUMENT);
294*355b4669Sjacobs 
295*355b4669Sjacobs 	if ((result = service_connect(svc, printer)) != PAPI_OK)
296*355b4669Sjacobs 		return (result);
297*355b4669Sjacobs 
298*355b4669Sjacobs 	f = (papi_status_t (*)())psm_sym(svc, "papiJobMove");
299*355b4669Sjacobs 	if (f != NULL) {
300*355b4669Sjacobs 		papi_attribute_t **attrs = getprinterbyname(destination, NULL);
301*355b4669Sjacobs 
302*355b4669Sjacobs 		papiAttributeListGetString(attrs, NULL,
303*355b4669Sjacobs 				"printer-uri-supported", &destination);
304*355b4669Sjacobs 		result = f(svc->svc_handle, svc->name, job_id, destination);
305*355b4669Sjacobs 		papiAttributeListFree(attrs);
306*355b4669Sjacobs 	}
307*355b4669Sjacobs 
308*355b4669Sjacobs 	return (result);
309*355b4669Sjacobs }
310*355b4669Sjacobs 
311*355b4669Sjacobs /* common support for papiJob{Cancel|Release|Restart|Promote} */
312*355b4669Sjacobs static papi_status_t
_papi_job_handle_printer_id(papi_service_t handle,char * printer,int32_t job_id,char * function)313*355b4669Sjacobs _papi_job_handle_printer_id(papi_service_t handle,
314*355b4669Sjacobs 		char *printer, int32_t job_id, char *function)
315*355b4669Sjacobs {
316*355b4669Sjacobs 	papi_status_t result = PAPI_INTERNAL_ERROR;
317*355b4669Sjacobs 	service_t *svc = handle;
318*355b4669Sjacobs 	papi_status_t (*f)();
319*355b4669Sjacobs 
320*355b4669Sjacobs 	if ((svc == NULL) || (printer == NULL) || (job_id < 0))
321*355b4669Sjacobs 		return (PAPI_BAD_ARGUMENT);
322*355b4669Sjacobs 
323*355b4669Sjacobs 	if ((result = service_connect(svc, printer)) != PAPI_OK)
324*355b4669Sjacobs 		return (result);
325*355b4669Sjacobs 
326*355b4669Sjacobs 	f = (papi_status_t (*)())psm_sym(svc, function);
327*355b4669Sjacobs 	if (f != NULL)
328*355b4669Sjacobs 		result = f(svc->svc_handle, svc->name, job_id);
329*355b4669Sjacobs 
330*355b4669Sjacobs 	return (result);
331*355b4669Sjacobs }
332*355b4669Sjacobs 
333*355b4669Sjacobs papi_status_t
papiJobCancel(papi_service_t handle,char * printer,int32_t job_id)334*355b4669Sjacobs papiJobCancel(papi_service_t handle, char *printer, int32_t job_id)
335*355b4669Sjacobs {
336*355b4669Sjacobs 	return (_papi_job_handle_printer_id(handle, printer, job_id,
337*355b4669Sjacobs 				"papiJobCancel"));
338*355b4669Sjacobs }
339*355b4669Sjacobs 
340*355b4669Sjacobs papi_status_t
papiJobRelease(papi_service_t handle,char * printer,int32_t job_id)341*355b4669Sjacobs papiJobRelease(papi_service_t handle, char *printer, int32_t job_id)
342*355b4669Sjacobs {
343*355b4669Sjacobs 	return (_papi_job_handle_printer_id(handle, printer, job_id,
344*355b4669Sjacobs 				"papiJobRelease"));
345*355b4669Sjacobs }
346*355b4669Sjacobs 
347*355b4669Sjacobs papi_status_t
papiJobRestart(papi_service_t handle,char * printer,int32_t job_id)348*355b4669Sjacobs papiJobRestart(papi_service_t handle, char *printer, int32_t job_id)
349*355b4669Sjacobs {
350*355b4669Sjacobs 	return (_papi_job_handle_printer_id(handle, printer, job_id,
351*355b4669Sjacobs 				"papiJobRestart"));
352*355b4669Sjacobs }
353*355b4669Sjacobs 
354*355b4669Sjacobs papi_status_t
papiJobPromote(papi_service_t handle,char * printer,int32_t job_id)355*355b4669Sjacobs papiJobPromote(papi_service_t handle, char *printer, int32_t job_id)
356*355b4669Sjacobs {
357*355b4669Sjacobs 	return (_papi_job_handle_printer_id(handle, printer, job_id,
358*355b4669Sjacobs 				"papiJobPromote"));
359*355b4669Sjacobs }
360*355b4669Sjacobs 
361*355b4669Sjacobs papi_status_t
papiJobCommit(papi_service_t handle,char * printer,int32_t job_id)362*355b4669Sjacobs papiJobCommit(papi_service_t handle, char *printer, int32_t job_id)
363*355b4669Sjacobs {
364*355b4669Sjacobs 	return (_papi_job_handle_printer_id(handle, printer, job_id,
365*355b4669Sjacobs 				"papiJobCommit"));
366*355b4669Sjacobs }
367*355b4669Sjacobs 
368*355b4669Sjacobs papi_status_t
papiJobHold(papi_service_t handle,char * printer,int32_t job_id)369*355b4669Sjacobs papiJobHold(papi_service_t handle, char *printer, int32_t job_id)
370*355b4669Sjacobs {
371*355b4669Sjacobs 	return (_papi_job_handle_printer_id(handle, printer, job_id,
372*355b4669Sjacobs 				"papiJobHold"));
373*355b4669Sjacobs }
374*355b4669Sjacobs 
375*355b4669Sjacobs papi_status_t
papiJobModify(papi_service_t handle,char * printer,int32_t job_id,papi_attribute_t ** attributes,papi_job_t * job)376*355b4669Sjacobs papiJobModify(papi_service_t handle, char *printer, int32_t job_id,
377*355b4669Sjacobs 		papi_attribute_t **attributes, papi_job_t *job)
378*355b4669Sjacobs {
379*355b4669Sjacobs 	papi_status_t result = PAPI_INTERNAL_ERROR;
380*355b4669Sjacobs 	service_t *svc = handle;
381*355b4669Sjacobs 	job_t *j = NULL;
382*355b4669Sjacobs 	papi_status_t (*f)();
383*355b4669Sjacobs 
384*355b4669Sjacobs 	if ((svc == NULL) || (printer == NULL) || (job_id < 0) ||
385*355b4669Sjacobs 	    (attributes == NULL))
386*355b4669Sjacobs 		return (PAPI_BAD_ARGUMENT);
387*355b4669Sjacobs 
388*355b4669Sjacobs 	if ((result = service_connect(svc, printer)) != PAPI_OK)
389*355b4669Sjacobs 		return (result);
390*355b4669Sjacobs 
391*355b4669Sjacobs 	if ((*job = j = calloc(1, sizeof (*j))) == NULL)
392*355b4669Sjacobs 		return (PAPI_TEMPORARY_ERROR);
393*355b4669Sjacobs 
394*355b4669Sjacobs 	j->svc = svc;
395*355b4669Sjacobs 	f = (papi_status_t (*)())psm_sym(j->svc, "papiJobModify");
396*355b4669Sjacobs 	if (f != NULL)
397*355b4669Sjacobs 		result = f(svc->svc_handle, svc->name, job_id, attributes,
398*355b4669Sjacobs 				&j->job);
399*355b4669Sjacobs 
400*355b4669Sjacobs 	return (result);
401*355b4669Sjacobs }
402*355b4669Sjacobs 
403*355b4669Sjacobs /*
404*355b4669Sjacobs  * The functions defined below are private to Solaris.  They are here
405*355b4669Sjacobs  * temporarily, until equivalent functionality makes it's way into the PAPI
406*355b4669Sjacobs  * spec.  This is expected in the next minor version after v1.0.
407*355b4669Sjacobs  */
408*355b4669Sjacobs papi_status_t
papiJobCreate(papi_service_t handle,char * printer,papi_attribute_t ** job_attributes,papi_job_ticket_t * job_ticket,papi_job_t * job)409*355b4669Sjacobs papiJobCreate(papi_service_t handle, char *printer,
410*355b4669Sjacobs 		papi_attribute_t **job_attributes,
411*355b4669Sjacobs 		papi_job_ticket_t *job_ticket, papi_job_t *job)
412*355b4669Sjacobs {
413*355b4669Sjacobs 	papi_status_t result = PAPI_INTERNAL_ERROR;
414*355b4669Sjacobs 	service_t *svc = handle;
415*355b4669Sjacobs 	job_t *j = NULL;
416*355b4669Sjacobs 	papi_status_t (*f)();
417*355b4669Sjacobs 
418*355b4669Sjacobs 	if ((svc == NULL) || (printer == NULL) || (job == NULL))
419*355b4669Sjacobs 		return (PAPI_BAD_ARGUMENT);
420*355b4669Sjacobs 
421*355b4669Sjacobs 	if ((result = service_connect(svc, printer)) != PAPI_OK)
422*355b4669Sjacobs 		return (result);
423*355b4669Sjacobs 
424*355b4669Sjacobs 	if ((*job = j = calloc(1, sizeof (*j))) == NULL)
425*355b4669Sjacobs 		return (PAPI_TEMPORARY_ERROR);
426*355b4669Sjacobs 
427*355b4669Sjacobs 	j->svc = svc;
428*355b4669Sjacobs 	f = (papi_status_t (*)())psm_sym(j->svc, "papiJobCreate");
429*355b4669Sjacobs 	if (f != NULL)
430*355b4669Sjacobs 		result = f(svc->svc_handle, svc->name, job_attributes,
431*355b4669Sjacobs 				job_ticket, &j->job);
432*355b4669Sjacobs 
433*355b4669Sjacobs 	return (result);
434*355b4669Sjacobs }
435*355b4669Sjacobs 
436*355b4669Sjacobs papi_status_t
papiJobStreamAdd(papi_service_t handle,char * printer,int32_t id,papi_stream_t * stream)437*355b4669Sjacobs papiJobStreamAdd(papi_service_t handle, char *printer, int32_t id,
438*355b4669Sjacobs 		papi_stream_t *stream)
439*355b4669Sjacobs {
440*355b4669Sjacobs 	papi_status_t result = PAPI_INTERNAL_ERROR;
441*355b4669Sjacobs 	service_t *svc = handle;
442*355b4669Sjacobs 	papi_status_t (*f)();
443*355b4669Sjacobs 
444*355b4669Sjacobs 	if ((svc == NULL) || (printer == NULL))
445*355b4669Sjacobs 		return (PAPI_BAD_ARGUMENT);
446*355b4669Sjacobs 
447*355b4669Sjacobs 	if ((result = service_connect(svc, printer)) != PAPI_OK)
448*355b4669Sjacobs 		return (result);
449*355b4669Sjacobs 
450*355b4669Sjacobs 	f = (papi_status_t (*)())psm_sym(svc, "papiJobStreamAdd");
451*355b4669Sjacobs 	if (f != NULL)
452*355b4669Sjacobs 		result = f(svc->svc_handle, svc->name, id, stream);
453*355b4669Sjacobs 
454*355b4669Sjacobs 	return (result);
455*355b4669Sjacobs }
456